OpenDDS::Security::SSL::sign_implementation Class Reference

List of all members.

Public Member Functions

 sign_implementation (EVP_PKEY *pkey)
 ~sign_implementation ()
int operator() (const std::vector< const DDS::OctetSeq * > &src, DDS::OctetSeq &dst)

Private Attributes

EVP_PKEYprivate_key
EVP_MD_CTX * md_ctx
EVP_PKEY_CTX * pkey_ctx

Detailed Description

Definition at line 93 of file PrivateKey.cpp.


Constructor & Destructor Documentation

OpenDDS::Security::SSL::sign_implementation::sign_implementation ( EVP_PKEY pkey  )  [inline]

Definition at line 96 of file PrivateKey.cpp.

00097       : private_key(pkey), md_ctx(NULL), pkey_ctx(NULL)
00098     {
00099     }

OpenDDS::Security::SSL::sign_implementation::~sign_implementation (  )  [inline]

Definition at line 100 of file PrivateKey.cpp.

References EVP_MD_CTX_free, and md_ctx.

00101     {
00102       if (md_ctx) EVP_MD_CTX_free(md_ctx);
00103     }


Member Function Documentation

int OpenDDS::Security::SSL::sign_implementation::operator() ( const std::vector< const DDS::OctetSeq * > &  src,
DDS::OctetSeq dst 
) [inline]

Definition at line 105 of file PrivateKey.cpp.

References EVP_MD_CTX_new, len, md_ctx, OPENDDS_SSL_LOG_ERR, pkey_ctx, and private_key.

00107     {
00108       if (!private_key) return 1;
00109 
00110       std::vector<const DDS::OctetSeq*>::const_iterator i, n;
00111       size_t len = 0u;
00112 
00113       md_ctx = EVP_MD_CTX_new();
00114       if (!md_ctx) {
00115         OPENDDS_SSL_LOG_ERR("EVP_MD_CTX_new failed");
00116         return 1;
00117       }
00118 
00119       EVP_MD_CTX_init(md_ctx);
00120 
00121       if (1 != EVP_DigestSignInit(md_ctx, &pkey_ctx, EVP_sha256(), NULL,
00122                                   private_key)) {
00123         OPENDDS_SSL_LOG_ERR("EVP_DigestSignInit failed");
00124         return 1;
00125       }
00126 
00127       // Determine which signature type is being signed
00128       int pk_id = EVP_PKEY_id(private_key);
00129 
00130       if (pk_id == EVP_PKEY_RSA) {
00131         if (1 !=
00132             EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING)) {
00133           OPENDDS_SSL_LOG_ERR("EVP_PKEY_CTX_set_rsa_padding failed");
00134           return 1;
00135         }
00136 
00137         if (1 != EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha256())) {
00138           OPENDDS_SSL_LOG_ERR("EVP_PKEY_CTX_set_rsa_mgf1_md failed");
00139           return 1;
00140         }
00141       }
00142 
00143       n = src.end();
00144       for (i = src.begin(); i != n; ++i) {
00145         if ((*i)->length() > 0) {
00146           if (1 != EVP_DigestSignUpdate(md_ctx, (*i)->get_buffer(),
00147                                         (*i)->length())) {
00148             OPENDDS_SSL_LOG_ERR("EVP_DigestSignUpdate failed");
00149             return 1;
00150           }
00151         }
00152       }
00153 
00154       // First call with NULL to extract size
00155       if (1 != EVP_DigestSignFinal(md_ctx, NULL, &len)) {
00156         OPENDDS_SSL_LOG_ERR("EVP_DigestSignFinal failed");
00157         return 1;
00158       }
00159 
00160       // Second call to extract the data
00161       dst.length(static_cast<unsigned int>(len));
00162       if (1 != EVP_DigestSignFinal(md_ctx, dst.get_buffer(), &len)) {
00163         OPENDDS_SSL_LOG_ERR("EVP_DigestSignFinal failed");
00164         return 1;
00165       }
00166 
00167       // The last call to EVP_DigestSignFinal can change the value of len so
00168       // reassign the value to len to dst.length.  This happens when using EC
00169       dst.length(static_cast<unsigned int>(len));
00170 
00171       return 0;
00172     }


Member Data Documentation

Definition at line 176 of file PrivateKey.cpp.

Referenced by operator()(), and ~sign_implementation().

Definition at line 177 of file PrivateKey.cpp.

Referenced by operator()().

Definition at line 175 of file PrivateKey.cpp.

Referenced by operator()().


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

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1