Source release 17.1.2
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
// would do. They verify that policies specified on UAT are honored on the
|
||||
// device.
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -16,9 +19,9 @@
|
||||
#include "license_holder.h"
|
||||
#include "log.h"
|
||||
#include "oec_device_features.h"
|
||||
#include "provisioning_holder.h"
|
||||
#include "test_base.h"
|
||||
#include "test_printers.h"
|
||||
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
namespace wvcdm {
|
||||
@@ -109,4 +112,69 @@ TEST_F(CorePIGTest, OfflineHWSecureRequired) {
|
||||
ASSERT_NO_FATAL_FAILURE(holder.CloseSession());
|
||||
}
|
||||
|
||||
TEST_F(CorePIGTest, CastReceiverProvisioningUsingCdm) {
|
||||
const std::string digest_hex_str =
|
||||
// digest info header
|
||||
"3021300906052b0e03021a05000414"
|
||||
// sha1 of kMessage
|
||||
"d2662f893aaec72f3ca6decc2aa942f3949e8b21";
|
||||
const auto digest = wvutil::a2b_hex(digest_hex_str);
|
||||
|
||||
if (!wvoec::global_features.cast_receiver) {
|
||||
GTEST_SKIP() << "OEMCrypto does not support CAST Receiver functionality";
|
||||
}
|
||||
|
||||
// Provision x509 cert for CAST Receiver.
|
||||
ProvisioningHolder provisioner(&cdm_engine_, config_);
|
||||
provisioner.Provision(kCertificateX509, binary_provisioning_);
|
||||
|
||||
// cdm_engine_.SignRsa
|
||||
std::string signature_str;
|
||||
const std::string digest_str(digest.begin(), digest.end());
|
||||
ASSERT_EQ(NO_ERROR, cdm_engine_.SignRsa(provisioner.wrapped_key(), digest_str,
|
||||
&signature_str, kSign_PKCS1_Block1));
|
||||
|
||||
// Verify the generated signature
|
||||
const std::vector<uint8_t> signature(signature_str.begin(), signature_str.end());
|
||||
LOGI("digest.size(): %zu, signature.size(): %zu", digest.size(),
|
||||
signature.size());
|
||||
|
||||
const std::string cert = provisioner.certificate();
|
||||
const char* const cert_str_ptr = cert.c_str();
|
||||
LOGI("cert: %s", cert_str_ptr);
|
||||
|
||||
// Extract the public key from the x509 cert chain
|
||||
std::unique_ptr<BIO, void (*)(BIO*)> bio(BIO_new(BIO_s_mem()), BIO_free_all);
|
||||
ASSERT_NE(bio, nullptr);
|
||||
ASSERT_GT(BIO_puts(bio.get(), cert_str_ptr), 0);
|
||||
std::unique_ptr<X509, void (*)(X509*)> x509(
|
||||
PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr), X509_free);
|
||||
ASSERT_NE(x509, nullptr);
|
||||
std::unique_ptr<EVP_PKEY, void (*)(EVP_PKEY*)> pubkey(
|
||||
X509_get_pubkey(x509.get()), EVP_PKEY_free);
|
||||
ASSERT_NE(pubkey, nullptr);
|
||||
|
||||
// remove digest info header for verification
|
||||
// SHA1 is 20 bytes long
|
||||
const std::vector<uint8_t> sha1_digest(digest.begin() + digest.size() - 20, digest.end());
|
||||
|
||||
// Modified from openssl example
|
||||
// https://www.openssl.org/docs/man3.0/man3/EVP_PKEY_verify_init.html
|
||||
// Set RSA padding as RSA_PKCS1_PADDING and digest algo to SHA1.
|
||||
const unsigned char* const md = sha1_digest.data();
|
||||
const unsigned char* const sig = signature.data();
|
||||
const size_t mdlen = sha1_digest.size();
|
||||
const size_t siglen = signature.size();
|
||||
|
||||
std::unique_ptr<EVP_PKEY_CTX, void (*)(EVP_PKEY_CTX*)> ctx(
|
||||
EVP_PKEY_CTX_new(pubkey.get(), nullptr /* no engine */), EVP_PKEY_CTX_free);
|
||||
|
||||
ASSERT_NE(ctx, nullptr);
|
||||
ASSERT_GT(EVP_PKEY_verify_init(ctx.get()), 0);
|
||||
ASSERT_GT(EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_PADDING), 0);
|
||||
ASSERT_GT(EVP_PKEY_CTX_set_signature_md(ctx.get(), EVP_sha1()), 0);
|
||||
|
||||
/* Perform operation */
|
||||
EXPECT_EQ(1, EVP_PKEY_verify(ctx.get(), sig, siglen, md, mdlen));
|
||||
}
|
||||
} // namespace wvcdm
|
||||
|
||||
Reference in New Issue
Block a user