MCPcopy Create free account
hub / github.com/Icinga/icinga2 / GetRsaPrivateKey

Function GetRsaPrivateKey

test/base-tlsutility.cpp:59–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59static std::shared_ptr<EVP_PKEY> GetRsaPrivateKey(const String& keyfile)
60{
61 std::shared_ptr<BIO> cakeybio(BIO_new_file(keyfile.CStr(), "r"), BIO_free);
62 BOOST_REQUIRE_MESSAGE(cakeybio, "BIO_new_file() for private key from '" << keyfile << "': " << GetOpenSSLError());
63
64 RSA* rsa = PEM_read_bio_RSAPrivateKey(cakeybio.get(), nullptr, nullptr, nullptr);
65 BOOST_REQUIRE_MESSAGE(rsa, "PEM read bio RSA key from private key file '" << keyfile << "': " << GetOpenSSLError());
66 BOOST_CHECK_EQUAL(1, RSA_check_key(rsa)); // 1 == valid, 0 == invalid
67
68 std::shared_ptr<EVP_PKEY> rsaKey(EVP_PKEY_new(), EVP_PKEY_free);
69 EVP_PKEY_assign_RSA(rsaKey.get(), rsa);
70 BOOST_CHECK_EQUAL(EVP_PKEY_RSA, EVP_PKEY_id(rsaKey.get()));
71
72 return rsaKey;
73}
74
75/**
76 * Creates a new certificate based on an existing one, with modified validity period.

Callers 1

Calls 3

GetOpenSSLErrorFunction · 0.85
CStrMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected