Fix InstallTestRSAKey() for provision 4 tests

[ Merge of http://go/wvgerrit/153589 ]

Some unit tests call InstallTestRSAKey() a few times. In current
provision 2 with Keybox, the test RSA DRM key is hard coded. But for
provision 4, it will be generated by OEMCrypto.

When a test calls multiple times of InstallTestRSAKey(), we don't want
the key to be generated during each call, and we want to use the same
key in order for the decrytion to work.

The fix to cache the drm key once it is created for prov 4 tests.

Bug: 180530495
Bug: 236317198
Test: oemcrypto_test
Change-Id: I1b2d96a89e0619861492e6d9bc56862e2c440c86
This commit is contained in:
Alex Dale
2022-06-21 16:20:17 -07:00
parent 073f478239
commit 4455aeceed
2 changed files with 50 additions and 41 deletions

View File

@@ -75,6 +75,9 @@ void SessionUtil::EnsureTestKeys() {
// are installed in OEMCrypto and in the test session.
void SessionUtil::InstallTestRSAKey(Session* s) {
if (global_features.provisioning_method == OEMCrypto_BootCertificateChain) {
if (wrapped_rsa_key_.size() == 0) {
// If we don't have a wrapped key yet, create one.
// This wrapped key will be shared by all sessions in the test.
const size_t buffer_size = 5000; // Make sure it is large enough.
std::vector<uint8_t> public_key(buffer_size);
size_t public_key_size = buffer_size;
@@ -84,19 +87,23 @@ void SessionUtil::InstallTestRSAKey(Session* s) {
size_t wrapped_private_key_size = buffer_size;
OEMCrypto_PrivateKeyType key_type;
// Assume OEM cert has been loaded.
ASSERT_EQ(
OEMCrypto_SUCCESS,
ASSERT_EQ(OEMCrypto_SUCCESS,
OEMCrypto_GenerateCertificateKeyPair(
s->session_id(), public_key.data(), &public_key_size,
public_key_signature.data(), &public_key_signature_size,
wrapped_private_key.data(), &wrapped_private_key_size, &key_type));
// Assume the public key has been verified by the server and the DRM cert is
// returned.
wrapped_private_key.data(), &wrapped_private_key_size,
&key_type));
// Assume the public key has been verified by the server and the DRM cert
// is returned.
wrapped_private_key.resize(wrapped_private_key_size);
ASSERT_NO_FATAL_FAILURE(
s->LoadWrappedDrmKey(key_type, wrapped_private_key));
public_key.resize(public_key_size);
wrapped_rsa_key_ = wrapped_private_key;
drm_public_key_ = public_key;
key_type_ = key_type;
}
ASSERT_NO_FATAL_FAILURE(s->LoadWrappedDrmKey(key_type_, wrapped_rsa_key_));
ASSERT_NO_FATAL_FAILURE(s->SetPublicKeyFromSubjectPublicKey(
key_type, public_key.data(), public_key_size));
key_type_, drm_public_key_.data(), drm_public_key_.size()));
return;
}

View File

@@ -1,12 +1,12 @@
#include <assert.h>
#include <algorithm>
#include <iostream>
#include <openssl/aes.h>
#include <openssl/rand.h>
#include <algorithm>
#include <iostream>
#include "OEMCryptoCENC.h"
#include "oec_session_util.h"
#include "oec_test_data.h"
#include "OEMCryptoCENC.h"
namespace wvoec {
@@ -32,6 +32,8 @@ public:
std::vector<uint8_t> encoded_rsa_key_;
std::vector<uint8_t> wrapped_rsa_key_;
OEMCrypto_PrivateKeyType key_type_;
std::vector<uint8_t> drm_public_key_;
wvoec::WidevineKeybox keybox_;
};