#include <PrivateKey.h>
Public Types | |
typedef DCPS::unique_ptr < PrivateKey > | unique_ptr |
Public Member Functions | |
PrivateKey (const std::string &uri, const std::string password="") | |
PrivateKey () | |
PrivateKey (const PrivateKey &other) | |
virtual | ~PrivateKey () |
PrivateKey & | operator= (const PrivateKey &rhs) |
void | load (const std::string &uri, const std::string &password="") |
int | sign (const std::vector< const DDS::OctetSeq * > &src, DDS::OctetSeq &dst) const |
Static Private Member Functions | |
static EVP_PKEY * | EVP_PKEY_from_pem (const std::string &path, const std::string &password="") |
static EVP_PKEY * | EVP_PKEY_from_pem_data (const std::string &data, const std::string &password) |
Private Attributes | |
EVP_PKEY * | k_ |
Friends | |
DdsSecurity_Export bool | operator== (const PrivateKey &lhs, const PrivateKey &rhs) |
Definition at line 20 of file PrivateKey.h.
Definition at line 23 of file PrivateKey.h.
OpenDDS::Security::SSL::PrivateKey::PrivateKey | ( | const std::string & | uri, | |
const std::string | password = "" | |||
) |
Definition at line 18 of file PrivateKey.cpp.
References load().
OpenDDS::Security::SSL::PrivateKey::PrivateKey | ( | ) |
Definition at line 24 of file PrivateKey.cpp.
00025 : k_(NULL) 00026 { 00027 00028 }
OpenDDS::Security::SSL::PrivateKey::PrivateKey | ( | const PrivateKey & | other | ) |
OpenDDS::Security::SSL::PrivateKey::~PrivateKey | ( | ) | [virtual] |
Definition at line 43 of file PrivateKey.cpp.
References k_.
EVP_PKEY * OpenDDS::Security::SSL::PrivateKey::EVP_PKEY_from_pem | ( | const std::string & | path, | |
const std::string & | password = "" | |||
) | [static, private] |
Definition at line 187 of file PrivateKey.cpp.
References OPENDDS_SSL_LOG_ERR.
Referenced by load().
00189 { 00190 EVP_PKEY* result = NULL; 00191 00192 BIO* filebuf = BIO_new_file(path.c_str(), "r"); 00193 if (filebuf) { 00194 if (password != "") { 00195 result = PEM_read_bio_PrivateKey(filebuf, NULL, NULL, 00196 (void*)password.c_str()); 00197 if (!result) { 00198 OPENDDS_SSL_LOG_ERR("PEM_read_bio_PrivateKey failed"); 00199 } 00200 00201 } else { 00202 result = PEM_read_bio_PrivateKey(filebuf, NULL, NULL, NULL); 00203 if (!result) { 00204 OPENDDS_SSL_LOG_ERR("PEM_read_bio_PrivateKey failed"); 00205 } 00206 } 00207 00208 BIO_free(filebuf); 00209 00210 } else { 00211 std::stringstream errmsg; 00212 errmsg << "failed to read file '" << path << "' using BIO_new_file"; 00213 OPENDDS_SSL_LOG_ERR(errmsg.str().c_str()); 00214 } 00215 00216 return result; 00217 }
EVP_PKEY * OpenDDS::Security::SSL::PrivateKey::EVP_PKEY_from_pem_data | ( | const std::string & | data, | |
const std::string & | password | |||
) | [static, private] |
Definition at line 219 of file PrivateKey.cpp.
References OPENDDS_SSL_LOG_ERR.
Referenced by load().
00221 { 00222 DDS::OctetSeq original_bytes; 00223 00224 // The minus 1 is because path contains a comma in element 0 and that 00225 // comma is not included in the cert string 00226 original_bytes.length(data.size() - 1); 00227 std::memcpy(original_bytes.get_buffer(), &data[1], 00228 original_bytes.length()); 00229 00230 // To appease the other DDS security implementations which 00231 // append a null byte at the end of the cert. 00232 original_bytes.length(original_bytes.length() + 1); 00233 original_bytes[original_bytes.length() - 1] = 0; 00234 00235 EVP_PKEY* result = NULL; 00236 BIO* filebuf = BIO_new(BIO_s_mem()); 00237 00238 if (filebuf) { 00239 if (0 >= BIO_write(filebuf, original_bytes.get_buffer(), 00240 original_bytes.length())) { 00241 OPENDDS_SSL_LOG_ERR("BIO_write failed"); 00242 } 00243 00244 if (password != "") { 00245 result = PEM_read_bio_PrivateKey(filebuf, NULL, NULL, 00246 (void*)password.c_str()); 00247 00248 if (!result) { 00249 OPENDDS_SSL_LOG_ERR("PEM_read_bio_PrivateKey failed"); 00250 } 00251 } else { 00252 result = PEM_read_bio_PrivateKey(filebuf, NULL, NULL, NULL); 00253 00254 if (!result) { 00255 OPENDDS_SSL_LOG_ERR("PEM_read_bio_PrivateKey failed"); 00256 } 00257 } 00258 00259 BIO_free(filebuf); 00260 } else { 00261 std::stringstream errmsg; 00262 errmsg << "failed to create data '" << data << "' using BIO_new"; 00263 OPENDDS_SSL_LOG_ERR(errmsg.str().c_str()); 00264 } 00265 00266 return result; 00267 }
void OpenDDS::Security::SSL::PrivateKey::load | ( | const std::string & | uri, | |
const std::string & | password = "" | |||
) |
Definition at line 65 of file PrivateKey.cpp.
References ACE_TEXT(), OpenDDS::Security::CommonUtilities::URI::everything_else, EVP_PKEY_from_pem(), EVP_PKEY_from_pem_data(), k_, LM_WARNING, OpenDDS::Security::CommonUtilities::URI::scheme, OpenDDS::Security::CommonUtilities::URI::URI_DATA, OpenDDS::Security::CommonUtilities::URI::URI_FILE, OpenDDS::Security::CommonUtilities::URI::URI_PKCS11, and OpenDDS::Security::CommonUtilities::URI::URI_UNKNOWN.
Referenced by PrivateKey().
00066 { 00067 using namespace CommonUtilities; 00068 00069 if (k_) return; 00070 00071 URI uri_info(uri); 00072 00073 switch (uri_info.scheme) { 00074 case URI::URI_FILE: 00075 k_ = EVP_PKEY_from_pem(uri_info.everything_else, password); 00076 break; 00077 00078 case URI::URI_DATA: 00079 k_ = EVP_PKEY_from_pem_data(uri_info.everything_else, password); 00080 break; 00081 00082 case URI::URI_PKCS11: 00083 case URI::URI_UNKNOWN: 00084 default: 00085 ACE_ERROR((LM_WARNING, 00086 ACE_TEXT("(%P|%t) SSL::PrivateKey::load: WARNING: Unsupported URI scheme in cert path '%C'\n"), 00087 uri.c_str())); 00088 00089 break; 00090 } 00091 }
PrivateKey & OpenDDS::Security::SSL::PrivateKey::operator= | ( | const PrivateKey & | rhs | ) |
int OpenDDS::Security::SSL::PrivateKey::sign | ( | const std::vector< const DDS::OctetSeq * > & | src, | |
DDS::OctetSeq & | dst | |||
) | const |
DdsSecurity_Export bool operator== | ( | const PrivateKey & | lhs, | |
const PrivateKey & | rhs | |||
) | [friend] |
EVP_PKEY* OpenDDS::Security::SSL::PrivateKey::k_ [private] |
Definition at line 50 of file PrivateKey.h.
Referenced by load(), operator=(), PrivateKey(), sign(), and ~PrivateKey().