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

Public Member Functions

 ecdh_pubkey_as_octets (EVP_PKEY *pkey)
 
int operator() (DDS::OctetSeq &dst)
 

Private Attributes

EVP_PKEYkeypair
 

Detailed Description

Definition at line 439 of file DiffieHellman.cpp.

Constructor & Destructor Documentation

◆ ecdh_pubkey_as_octets()

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

Definition at line 442 of file DiffieHellman.cpp.

443  : keypair(pkey)
444 #ifdef OPENSSL_V_3_0
445  , params(0)
446 #endif
447  {
448  }

Member Function Documentation

◆ operator()()

int OpenDDS::Security::SSL::ecdh_pubkey_as_octets::operator() ( DDS::OctetSeq dst)
inline

Definition at line 457 of file DiffieHellman.cpp.

References OPENDDS_SSL_LOG_ERR, and ACE_OS::strcasecmp().

458  {
459  if (!keypair) return 1;
460 
461 #ifndef OPENSSL_V_3_0
462  EC_Handle keypair_ecdh(keypair);
463  if (!keypair_ecdh) {
464  OPENDDS_SSL_LOG_ERR("EVP_PKEY_get0_EC_KEY failed");
465  return 1;
466  }
467 
468  const EC_POINT* pubkey = EC_KEY_get0_public_key(keypair_ecdh);
469  if (!pubkey) {
470  OPENDDS_SSL_LOG_ERR("EC_KEY_get0_public_key failed");
471  return 1;
472  }
473 
474  size_t len = EC_POINT_point2oct(EC_KEY_get0_group(keypair_ecdh), pubkey,
475  EC_KEY_get_conv_form(keypair_ecdh), 0,
476  0u, 0);
477  if (!len) {
478  OPENDDS_SSL_LOG_ERR("EC_POINT_point2oct failed");
479  return 1;
480  }
481 
482  dst.length(static_cast<unsigned int>(len));
483  if (0 == EC_POINT_point2oct(EC_KEY_get0_group(keypair_ecdh), pubkey,
484  EC_KEY_get_conv_form(keypair_ecdh),
485  dst.get_buffer(), len, 0)) {
486  OPENDDS_SSL_LOG_ERR("EC_POINT_point2oct failed");
487  return 1;
488  }
489 #else
490  if (EVP_PKEY_todata(keypair, EVP_PKEY_KEYPAIR, &params) <= 0) {
491  OPENDDS_SSL_LOG_ERR("pkey to data failed");
492  return 1;
493  } else {
494  const char* gname = 0;
495  const unsigned char* pubbuf = 0;
496  size_t pubbuflen = 0;
497  for (OSSL_PARAM* p = params; p != 0 && p->key != 0; ++p) {
498  if (ACE_OS::strcasecmp(p->key, "group") == 0) {
499  gname = static_cast<const char*>(p->data);
500  } else if (ACE_OS::strcasecmp(p->key, "pub") == 0) {
501  pubbuf = static_cast<const unsigned char*>(p->data);
502  pubbuflen = p->data_size;
503  }
504  }
505 
506  const int nid = OBJ_txt2nid(gname);
507  if (nid == 0) {
508  OPENDDS_SSL_LOG_ERR("failed to find Nid");
509  return 1;
510  }
511  EC_GROUP* const ecg = EC_GROUP_new_by_curve_name(nid);
512  const point_conversion_form_t cf = EC_GROUP_get_point_conversion_form(ecg);
513  EC_POINT* const ec = EC_POINT_new(ecg);
514  if (!EC_POINT_oct2point(ecg, ec, pubbuf, pubbuflen, 0)) {
515  OPENDDS_SSL_LOG_ERR("failed to extract ec point from octet sequence");
516  EC_POINT_free(ec);
517  EC_GROUP_free(ecg);
518  return 1;
519  }
520  const size_t eclen = EC_POINT_point2oct(ecg, ec, cf, 0, 0u, 0);
521  dst.length(static_cast<ACE_CDR::ULong>(eclen));
522  EC_POINT_point2oct(ecg, ec, cf, dst.get_buffer(), eclen, 0);
523  EC_POINT_free(ec);
524  EC_GROUP_free(ecg);
525  }
526 #endif
527  return 0;
528  }
int strcasecmp(const char *s, const char *t)
#define OPENDDS_SSL_LOG_ERR(MSG)
Definition: Err.h:12

Member Data Documentation

◆ keypair

EVP_PKEY* OpenDDS::Security::SSL::ecdh_pubkey_as_octets::keypair
private

Definition at line 531 of file DiffieHellman.cpp.


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