393 const EVP_CIPHER* pCipher =
397 OpenSSL_BIO bmem = BIO_new(BIO_s_mem());
400 EVP_PKEY* pReturnKey =
nullptr;
404 OTPasswordData thePWDataWrite(
"OTAsymmetricKey_OpenSSL::CopyPrivateKey is "
405 "calling PEM_write_bio_PrivateKey...");
413 int32_t nWriteBio =
false;
415 if (
nullptr == pImportPassword)
416 nWriteBio = PEM_write_bio_PrivateKey(
417 bmem, &theKey, pCipher,
nullptr, 0,
419 nullptr == pPWData ? &thePWDataWrite
420 : const_cast<OTPasswordData*>(pPWData));
422 nWriteBio = PEM_write_bio_PrivateKey(
423 bmem, &theKey, pCipher,
nullptr, 0, 0,
425 reinterpret_cast<const void*>(pImportPassword->getPassword())));
427 if (0 == nWriteBio) {
428 otErr << __FUNCTION__
429 <<
": Failed writing EVP_PKEY to memory buffer.\n";
433 <<
": Success writing EVP_PKEY to memory buffer.\n";
435 char* pChar =
nullptr;
441 const int64_t lSize = BIO_get_mem_data(bmem, &pChar);
442 const uint32_t nSize =
static_cast<uint32_t
>(lSize);
448 theData.SetPayloadSize(nSize);
451 (static_cast<char*>(const_cast<void*>(
452 theData.GetPayloadPointer()))),
465 BIO_new_mem_buf(static_cast<char*>(const_cast<void*>(
466 theData.GetPayloadPointer())),
469 "OTAsymmetricKey_OpenSSL::"
470 "CopyPrivateKey: Assert: nullptr != "
476 OTPasswordData thePWData(
"OTAsymmetricKey_OpenSSL::"
477 "CopyPrivateKey is calling "
478 "PEM_read_bio_PUBKEY...");
480 if (
nullptr == pImportPassword)
481 pReturnKey = PEM_read_bio_PrivateKey(
485 : const_cast<OTPasswordData*>(pPWData));
487 pReturnKey = PEM_read_bio_PrivateKey(
489 const_cast<void*>(reinterpret_cast<const void*>(
490 pImportPassword->getPassword())));
494 otErr << __FUNCTION__ <<
": Error: Failed copying memory from "
495 "BIO into OTPayload.\n";
499 otErr << __FUNCTION__
500 <<
": Failed copying private key into memory.\n";
#define OT_ASSERT_MSG(x, s)
OTLOG_IMPORT OTLogStream otErr
static EXPORT OT_OPENSSL_CALLBACK * GetPasswordCallback()
static EXPORT void * safe_memcpy(void *dest, uint32_t dsize, const void *src, uint32_t ssize, bool zeroSource=false)
OTLOG_IMPORT OTLogStream otLog5