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

Public Member Functions

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

Private Attributes

EVP_PKEYpublic_key
 
EVP_MD_CTX * md_ctx
 
EVP_PKEY_CTX * pkey_ctx
 

Detailed Description

Definition at line 171 of file Certificate.cpp.

Constructor & Destructor Documentation

◆ verify_implementation()

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

◆ ~verify_implementation()

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

Definition at line 179 of file Certificate.cpp.

References EVP_MD_CTX_free.

Member Function Documentation

◆ operator()()

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

Definition at line 181 of file Certificate.cpp.

References EVP_MD_CTX_new, and OPENDDS_SSL_LOG_ERR.

183  {
184  if (!public_key) return 1;
185 
186  int pk_id = 0;
187  std::vector<const DDS::OctetSeq*>::const_iterator i, n;
188 
190  if (!md_ctx) {
191  OPENDDS_SSL_LOG_ERR("EVP_MD_CTX_new failed");
192  return 1;
193  }
194 
195  EVP_MD_CTX_init(md_ctx);
196 
197  if (1 != EVP_DigestVerifyInit(md_ctx, &pkey_ctx, EVP_sha256(), 0,
198  public_key)) {
199  OPENDDS_SSL_LOG_ERR("EVP_DigestVerifyInit failed");
200  return 1;
201  }
202 
203  // Determine which signature type is being verified
204  pk_id = EVP_PKEY_id(public_key);
205 
206  if (pk_id == EVP_PKEY_RSA) {
207  if (1 !=
208  EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING)) {
209  OPENDDS_SSL_LOG_ERR("EVP_PKEY_CTX_set_rsa_padding failed");
210  return 1;
211  }
212 
213  if (1 != EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha256())) {
214  OPENDDS_SSL_LOG_ERR("EVP_PKEY_CTX_set_rsa_mgf1_md failed");
215  return 1;
216  }
217  }
218 
219  n = expected_contents.end();
220  for (i = expected_contents.begin(); i != n; ++i) {
221  if ((*i)->length() > 0) {
222  if (1 != EVP_DigestVerifyUpdate(md_ctx, (*i)->get_buffer(),
223  (*i)->length())) {
224  OPENDDS_SSL_LOG_ERR("EVP_DigestVerifyUpdate failed");
225  return 1;
226  }
227  }
228  }
229 
230 #ifdef OPENSSL_V_1_0
231  // some versions of OpenSSL take a pointer to non-const
232  unsigned char* buffer = const_cast<unsigned char*>(src.get_buffer());
233 #else
234  const unsigned char* buffer = src.get_buffer();
235 #endif
236  const int err = EVP_DigestVerifyFinal(md_ctx, buffer, src.length());
237  if (0 == err) {
238  return 1; // Verification failed, but no error occurred
239 
240  } else if (1 != err) {
241  OPENDDS_SSL_LOG_ERR("EVP_DigestVerifyFinal failed");
242  return 1;
243  }
244 
245  return 0;
246  }
#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::verify_implementation::md_ctx
private

Definition at line 250 of file Certificate.cpp.

◆ pkey_ctx

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

Definition at line 251 of file Certificate.cpp.

◆ public_key

EVP_PKEY* OpenDDS::Security::SSL::verify_implementation::public_key
private

Definition at line 249 of file Certificate.cpp.


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