OpenDDS::Security::SSL::PrivateKey Class Reference

#include <PrivateKey.h>

List of all members.

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 ()
PrivateKeyoperator= (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_PKEYEVP_PKEY_from_pem (const std::string &path, const std::string &password="")
static EVP_PKEYEVP_PKEY_from_pem_data (const std::string &data, const std::string &password)

Private Attributes

EVP_PKEYk_

Friends

DdsSecurity_Export bool operator== (const PrivateKey &lhs, const PrivateKey &rhs)

Detailed Description

Definition at line 20 of file PrivateKey.h.


Member Typedef Documentation

Definition at line 23 of file PrivateKey.h.


Constructor & Destructor Documentation

OpenDDS::Security::SSL::PrivateKey::PrivateKey ( const std::string &  uri,
const std::string  password = "" 
)

Definition at line 18 of file PrivateKey.cpp.

References load().

00019     : k_(NULL)
00020   {
00021     load(uri, password);
00022   }

Here is the call graph for this function:

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  ) 

Definition at line 30 of file PrivateKey.cpp.

References k_.

00031     : k_(NULL)
00032   {
00033     if (other.k_) {
00034       k_ = other.k_;
00035 
00036 #ifndef OPENSSL_V_1_0
00037       EVP_PKEY_up_ref(k_);
00038 #endif
00039 
00040     }
00041   }

OpenDDS::Security::SSL::PrivateKey::~PrivateKey (  )  [virtual]

Definition at line 43 of file PrivateKey.cpp.

References k_.

00044   {
00045     if (k_) EVP_PKEY_free(k_);
00046   }


Member Function Documentation

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   }

Here is the caller graph for this function:

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   }

Here is the caller graph for this function:

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   }

Here is the call graph for this function:

Here is the caller graph for this function:

PrivateKey & OpenDDS::Security::SSL::PrivateKey::operator= ( const PrivateKey rhs  ) 

Definition at line 48 of file PrivateKey.cpp.

References k_.

00049   {
00050     if (this != &rhs) {
00051       if (rhs.k_) {
00052         k_ = rhs.k_;
00053 
00054 #ifndef OPENSSL_V_1_0
00055         EVP_PKEY_up_ref(k_);
00056 #endif
00057 
00058       } else {
00059         k_ = NULL;
00060       }
00061     }
00062     return *this;
00063   }

int OpenDDS::Security::SSL::PrivateKey::sign ( const std::vector< const DDS::OctetSeq * > &  src,
DDS::OctetSeq dst 
) const

Definition at line 180 of file PrivateKey.cpp.

References k_.

00182   {
00183     sign_implementation sign(k_);
00184     return sign(src, dst);
00185   }


Friends And Related Function Documentation

DdsSecurity_Export bool operator== ( const PrivateKey lhs,
const PrivateKey rhs 
) [friend]

Member Data Documentation

Definition at line 50 of file PrivateKey.h.

Referenced by load(), operator=(), PrivateKey(), sign(), and ~PrivateKey().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1