OpenDDS  Snapshot(2023/04/28-20:55)
Public Member Functions | Private Attributes | List of all members
OpenDDS::Security::SSL::sign_implementation Class Reference

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 67 of file PrivateKey.cpp.

Constructor & Destructor Documentation

◆ sign_implementation()

OpenDDS::Security::SSL::sign_implementation::sign_implementation ( EVP_PKEY pkey)
inlineexplicit

Definition at line 70 of file PrivateKey.cpp.

◆ ~sign_implementation()

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

Definition at line 75 of file PrivateKey.cpp.

References EVP_MD_CTX_free.

76  {
77  if (md_ctx) {
79  }
80  }
#define EVP_MD_CTX_free

Member Function Documentation

◆ operator()()

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

Definition at line 82 of file PrivateKey.cpp.

References EVP_MD_CTX_new, and OPENDDS_SSL_LOG_ERR.

84  {
85  if (!private_key) return 1;
86 
87  std::vector<const DDS::OctetSeq*>::const_iterator i, n;
88  size_t len = 0u;
89 
91  if (!md_ctx) {
92  OPENDDS_SSL_LOG_ERR("EVP_MD_CTX_new failed");
93  return 1;
94  }
95 
96  EVP_MD_CTX_init(md_ctx);
97 
98  if (1 != EVP_DigestSignInit(md_ctx, &pkey_ctx, EVP_sha256(), 0,
99  private_key)) {
100  OPENDDS_SSL_LOG_ERR("EVP_DigestSignInit failed");
101  return 1;
102  }
103 
104  // Determine which signature type is being signed
105  int pk_id = EVP_PKEY_id(private_key);
106 
107  if (pk_id == EVP_PKEY_RSA) {
108  if (1 !=
109  EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING)) {
110  OPENDDS_SSL_LOG_ERR("EVP_PKEY_CTX_set_rsa_padding failed");
111  return 1;
112  }
113 
114  if (1 != EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha256())) {
115  OPENDDS_SSL_LOG_ERR("EVP_PKEY_CTX_set_rsa_mgf1_md failed");
116  return 1;
117  }
118  }
119 
120  n = src.end();
121  for (i = src.begin(); i != n; ++i) {
122  if ((*i)->length() > 0) {
123  if (1 != EVP_DigestSignUpdate(md_ctx, (*i)->get_buffer(),
124  (*i)->length())) {
125  OPENDDS_SSL_LOG_ERR("EVP_DigestSignUpdate failed");
126  return 1;
127  }
128  }
129  }
130 
131  // First call with 0 to extract size
132  if (1 != EVP_DigestSignFinal(md_ctx, 0, &len)) {
133  OPENDDS_SSL_LOG_ERR("EVP_DigestSignFinal failed");
134  return 1;
135  }
136 
137  // Second call to extract the data
138  dst.length(static_cast<unsigned int>(len));
139  if (1 != EVP_DigestSignFinal(md_ctx, dst.get_buffer(), &len)) {
140  OPENDDS_SSL_LOG_ERR("EVP_DigestSignFinal failed");
141  return 1;
142  }
143 
144  // The last call to EVP_DigestSignFinal can change the value of len so
145  // reassign the value to len to dst.length. This happens when using EC
146  dst.length(static_cast<unsigned int>(len));
147 
148  return 0;
149  }
#define EVP_MD_CTX_new
#define OPENDDS_SSL_LOG_ERR(MSG)
Definition: Err.h:12

Member Data Documentation

◆ md_ctx

EVP_MD_CTX* OpenDDS::Security::SSL::sign_implementation::md_ctx
private

Definition at line 153 of file PrivateKey.cpp.

◆ pkey_ctx

EVP_PKEY_CTX* OpenDDS::Security::SSL::sign_implementation::pkey_ctx
private

Definition at line 154 of file PrivateKey.cpp.

◆ private_key

EVP_PKEY* OpenDDS::Security::SSL::sign_implementation::private_key
private

Definition at line 152 of file PrivateKey.cpp.


The documentation for this class was generated from the following file: