1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 /* 21 * XSEC 22 * 23 * OpenSSLCryptoX509:= OpenSSL based class for handling X509 (V3) certificates 24 * 25 * Author(s): Berin Lautenbach 26 * 27 * $Id: OpenSSLCryptoX509.hpp 1808174 2017-09-12 21:50:30Z scantor $ 28 * 29 */ 30 31 #ifndef OPENSSLCRYPTOX509_INCLUDE 32 #define OPENSSLCRYPTOX509_INCLUDE 33 34 #include <xsec/framework/XSECDefs.hpp> 35 #include <xsec/enc/XSECCryptoX509.hpp> 36 37 #if defined (XSEC_HAVE_OPENSSL) 38 #include <openssl/x509.h> 39 #include <openssl/bio.h> 40 41 /** 42 * \brief Implementation class for interface for X509 certificates. 43 * @ingroup opensslcrypto 44 * 45 * The library uses classes derived from this to process X509 Certificates. 46 * 47 */ 48 49 class XSEC_EXPORT OpenSSLCryptoX509 : public XSECCryptoX509 { 50 51 public : 52 53 /** @name Constructors and Destructors */ 54 //@{ 55 56 OpenSSLCryptoX509(); 57 virtual ~OpenSSLCryptoX509(); 58 59 //@} 60 61 62 //@} 63 /** @name Key Interface methods */ 64 //@{ 65 66 /** 67 * \brief Return the type of the key stored in the certificate. 68 * 69 * Will extract the key from the certificate to return the appropriate 70 * type 71 * 72 */ 73 74 virtual XSECCryptoKey::KeyType getPublicKeyType() const; 75 76 /** 77 * \brief Returns a string that identifies the crypto owner of this library. 78 */ 79 80 virtual const XMLCh * getProviderName() const; 81 82 /** 83 * \brief Get a copy of the public key. 84 * 85 * Extracts the public key from the certificate and returns the appropriate 86 * OpenSSLCryrptoKey (DSA or RSA) object 87 * 88 */ 89 90 virtual XSECCryptoKey * clonePublicKey() const; 91 92 //@} 93 94 /** @name Load and Get the certificate */ 95 //@{ 96 97 /** 98 * \brief Load a certificate into the object. 99 * 100 * Take a base64 DER encoded certificate and load. 101 * 102 * @param buf A buffer containing the Base64 encoded certificate 103 * @param len The number of bytes of data in the certificate. 104 */ 105 106 virtual void loadX509Base64Bin(const char * buf, unsigned int len); 107 108 /** 109 * \brief Get a Base64 DER encoded copy of the certificate 110 * 111 * @returns A safeBuffer containing the DER encoded certificate 112 */ 113 getDEREncodingSB(void)114 virtual safeBuffer &getDEREncodingSB(void) {return m_DERX509;} 115 116 /** 117 * \brief Get a Base64 DER encoded copy of the certificate 118 * 119 * @returns A safeBuffer containing the DER encoded certificate 120 */ 121 getDEREncodingSB(void) const122 virtual const safeBuffer &getDEREncodingSB(void) const {return m_DERX509;} 123 124 //@} 125 126 /** @name OpenSSL Library Specific functions */ 127 //@{ 128 129 /** 130 * \brief OpenSSL specific constructor 131 * 132 * Construct the object around an existing X509 certificate 133 */ 134 135 OpenSSLCryptoX509(X509 * x); 136 137 /** 138 * \brief Get OpenSSL certificate structure 139 */ 140 getOpenSSLX509(void)141 X509 * getOpenSSLX509(void) {return mp_X509;} 142 143 /** 144 * \brief Get OpenSSL certificate structure 145 */ 146 getOpenSSLX509(void) const147 const X509 * getOpenSSLX509(void) const {return mp_X509;} 148 149 //@} 150 151 private: 152 153 X509 * mp_X509; // The X509 structure 154 safeBuffer m_DERX509; 155 }; 156 157 #endif /* XSEC_HAVE_OPENSSL */ 158 #endif /* OPENSSLCRYPTOX509_INCLUDE */ 159 160