diff --git a/provisioner/rkp_factory_extraction_tool.cpp b/provisioner/rkp_factory_extraction_tool.cpp index c439b990..2e59dbdf 100644 --- a/provisioner/rkp_factory_extraction_tool.cpp +++ b/provisioner/rkp_factory_extraction_tool.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -49,6 +50,26 @@ constexpr std::string_view kBuildPlusCsr = "build+csr"; // Text-encoded (JSON) constexpr size_t kChallengeSize = 16; +std::string toBase64(const std::vector& buffer) { + size_t base64Length; + int rc = EVP_EncodedLength(&base64Length, buffer.size()); + if (!rc) { + std::cerr << "Error getting base64 length. Size overflow?" << std::endl; + exit(-1); + } + + std::string base64(base64Length, ' '); + rc = EVP_EncodeBlock(reinterpret_cast(base64.data()), buffer.data(), buffer.size()); + ++rc; // Account for NUL, which BoringSSL does not for some reason. + if (rc != base64Length) { + std::cerr << "Error writing base64. Expected " << base64Length + << " bytes to be written, but " << rc << " bytes were actually written." + << std::endl; + exit(-1); + } + return base64; +} + std::vector generateChallenge() { std::vector challenge(kChallengeSize); @@ -96,7 +117,10 @@ std::vector getEekChain() { std::cerr << "Failed to generate test EEK somehow: " << eekOrErr.message() << std::endl; exit(-1); } - auto [eek, ignored_pubkey, ignored_privkey] = eekOrErr.moveValue(); + auto [eek, pubkey, privkey] = eekOrErr.moveValue(); + std::cout << "EEK raw keypair:" << std::endl; + std::cout << " pub: " << toBase64(pubkey) << std::endl; + std::cout << " priv: " << toBase64(privkey) << std::endl; return eek; }