996 OpenSSL_BIO b64 = BIO_new(BIO_f_base64());
997 OpenSSL_BIO bio = BIO_new_mem_buf((
void*)strKey.Get(), -1);
998 OpenSSL_BIO bio_out = BIO_new(BIO_s_mem());
999 OpenSSL_BIO bioJoin = BIO_push(b64, bio);
1003 while ((len = BIO_read(bioJoin, buffer, 512)) > 0)
1004 BIO_write(bio_out, buffer, len);
1006 BIO_get_mem_ptr(bio_out, &bptr);
1007 bio_out.setFreeOnly();
1010 ExportRsaKey((uint8_t*)bptr->data, static_cast<int32_t>(bptr->length));
1012 if (!pgpKeys.pRsa) {
1013 otLog5 <<
"\nNo RSA public key found.\n\n";
1016 char* szModulusHex = BN_bn2hex(pgpKeys.pRsa->n);
1017 char* szExponentHex = BN_bn2hex(pgpKeys.pRsa->e);
1018 otLog5 <<
"RSA public key found : \n Modulus ("
1019 << BN_num_bits(pgpKeys.pRsa->n) <<
" bits)\n";
1020 otLog5 <<
" Exponent : 0x" << szExponentHex <<
"\n\n";
1021 otLog5 <<
"RSA public key found : \nModulus ("
1022 << BN_num_bits(pgpKeys.pRsa->n) <<
" bits) : 0x" << szModulusHex
1024 otLog5 <<
"Exponent : 0x" << szExponentHex <<
"\n\n";
1026 CRYPTO_free(szModulusHex);
1027 CRYPTO_free(szExponentHex);
1030 if (!pgpKeys.pDsa) {
1031 otLog5 <<
"No DSA public key found.\n\n";
1034 char* szPHex = BN_bn2hex(pgpKeys.pDsa->p);
1035 char* szQHex = BN_bn2hex(pgpKeys.pDsa->q);
1036 char* szGHex = BN_bn2hex(pgpKeys.pDsa->g);
1037 char* szYHex = BN_bn2hex(pgpKeys.pDsa->pub_key);
1038 otLog5 <<
"DSA public key found : \n p ("
1039 << BN_num_bits(pgpKeys.pDsa->p) <<
" bits)\n";
1040 otLog5 <<
" q (" << BN_num_bits(pgpKeys.pDsa->q) <<
" bits)\n";
1041 otLog5 <<
" g (" << BN_num_bits(pgpKeys.pDsa->g) <<
" bits)\n";
1042 otLog5 <<
"public key (" << BN_num_bits(pgpKeys.pDsa->pub_key)
1044 otLog5 <<
"DSA public key found : \np (" << BN_num_bits(pgpKeys.pDsa->p)
1045 <<
" bits) : 0x" << szPHex <<
"\n";
1046 otLog5 <<
"q (" << BN_num_bits(pgpKeys.pDsa->q) <<
" bits) : 0x"
1048 otLog5 <<
"g (" << BN_num_bits(pgpKeys.pDsa->g) <<
" bits) : 0x"
1050 otLog5 <<
"public key (" << BN_num_bits(pgpKeys.pDsa->pub_key)
1051 <<
" bits) : 0x" << szYHex <<
"\n\n";
1053 CRYPTO_free(szPHex);
1054 CRYPTO_free(szQHex);
1055 CRYPTO_free(szGHex);
1056 CRYPTO_free(szYHex);
1059 if (!pgpKeys.pElgamal) {
1060 otLog5 <<
"No Elgamal public key found.\n\n";
1063 char* szPHex = BN_bn2hex(pgpKeys.pElgamal->p);
1064 char* szGHex = BN_bn2hex(pgpKeys.pElgamal->g);
1065 char* szYHex = BN_bn2hex(pgpKeys.pElgamal->pub_key);
1066 otLog5 <<
"Elgamal public key found : \n p ("
1067 << BN_num_bits(pgpKeys.pElgamal->p) <<
" bits) : 0x" << szPHex
1069 otLog5 <<
" g (" << BN_num_bits(pgpKeys.pElgamal->g) <<
" bits) : 0x"
1071 otLog5 <<
" public key (" << BN_num_bits(pgpKeys.pElgamal->pub_key)
1072 <<
" bits) : 0x" << szYHex <<
"\n\n";
1074 CRYPTO_free(szPHex);
1075 CRYPTO_free(szGHex);
1076 CRYPTO_free(szYHex);
1079 bool bReturnValue =
false;
1080 EVP_PKEY* pkey = EVP_PKEY_new();
1084 if (EVP_PKEY_assign_RSA(pkey, pgpKeys.pRsa)) {
1085 bReturnValue =
true;
1087 otLog4 <<
"Successfully extracted RSA public key from PGP public "
1091 RSA_free(pgpKeys.pRsa);
1092 otOut <<
"Extracted RSA public key from PGP public key block, but "
1093 "unable to convert to EVP_PKEY.\n";
1096 pgpKeys.pRsa =
nullptr;
1098 else if (pgpKeys.pDsa) {
1099 if (EVP_PKEY_assign_DSA(pkey, pgpKeys.pDsa)) {
1100 bReturnValue =
true;
1102 otLog4 <<
"Successfully extracted DSA public key from PGP public "
1106 DSA_free(pgpKeys.pDsa);
1107 otOut <<
"Extracted DSA public key from PGP public key block, but "
1108 "unable to convert to EVP_PKEY.\n";
1111 pgpKeys.pDsa =
nullptr;
1113 else if (pgpKeys.pElgamal) {
1114 otOut <<
"Extracted ElGamal Key from PGP public key block, but "
1115 "currently do not support it (sorry))\n";
1122 free(pgpKeys.pElgamal);
1123 pgpKeys.pElgamal =
nullptr;
1129 dp->SetKeyAsCopyOf(*pkey,
false);
1130 EVP_PKEY_free(pkey);
1136 EVP_PKEY_free(pkey);
1142 return bReturnValue;
OTLOG_IMPORT OTLogStream otLog4
OTLOG_IMPORT OTLogStream otOut
PgpKeys ExportRsaKey(uint8_t *pbData, int32_t dataLength)
OTAsymmetricKey_OpenSSLPrivdp * dp
OTLOG_IMPORT OTLogStream otLog5