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:
@@ -75,28 +75,35 @@ void SessionUtil::EnsureTestKeys() {
|
||||
// are installed in OEMCrypto and in the test session.
|
||||
void SessionUtil::InstallTestRSAKey(Session* s) {
|
||||
if (global_features.provisioning_method == OEMCrypto_BootCertificateChain) {
|
||||
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;
|
||||
std::vector<uint8_t> public_key_signature(buffer_size);
|
||||
size_t public_key_signature_size = buffer_size;
|
||||
std::vector<uint8_t> wrapped_private_key(buffer_size);
|
||||
size_t wrapped_private_key_size = buffer_size;
|
||||
OEMCrypto_PrivateKeyType key_type;
|
||||
// Assume OEM cert has been loaded.
|
||||
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.resize(wrapped_private_key_size);
|
||||
ASSERT_NO_FATAL_FAILURE(
|
||||
s->LoadWrappedDrmKey(key_type, wrapped_private_key));
|
||||
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;
|
||||
std::vector<uint8_t> public_key_signature(buffer_size);
|
||||
size_t public_key_signature_size = buffer_size;
|
||||
std::vector<uint8_t> wrapped_private_key(buffer_size);
|
||||
size_t wrapped_private_key_size = buffer_size;
|
||||
OEMCrypto_PrivateKeyType key_type;
|
||||
// Assume OEM cert has been loaded.
|
||||
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.resize(wrapped_private_key_size);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +1,40 @@
|
||||
#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 {
|
||||
|
||||
class SessionUtil {
|
||||
public:
|
||||
SessionUtil()
|
||||
: encoded_rsa_key_(kTestRSAPKCS8PrivateKeyInfo2_2048,
|
||||
kTestRSAPKCS8PrivateKeyInfo2_2048 +
|
||||
sizeof(kTestRSAPKCS8PrivateKeyInfo2_2048)) {}
|
||||
public:
|
||||
SessionUtil()
|
||||
: encoded_rsa_key_(kTestRSAPKCS8PrivateKeyInfo2_2048,
|
||||
kTestRSAPKCS8PrivateKeyInfo2_2048 +
|
||||
sizeof(kTestRSAPKCS8PrivateKeyInfo2_2048)) {}
|
||||
|
||||
// Create a new wrapped DRM Certificate.
|
||||
void CreateWrappedRSAKey();
|
||||
// Create a new wrapped DRM Certificate.
|
||||
void CreateWrappedRSAKey();
|
||||
|
||||
// This is used to force installation of a keybox. This overwrites the
|
||||
// production keybox -- it does NOT use OEMCrypto_LoadTestKeybox.
|
||||
void InstallKeybox(const wvoec::WidevineKeybox& keybox, bool good);
|
||||
// This is used to force installation of a keybox. This overwrites the
|
||||
// production keybox -- it does NOT use OEMCrypto_LoadTestKeybox.
|
||||
void InstallKeybox(const wvoec::WidevineKeybox& keybox, bool good);
|
||||
|
||||
// This loads the test keybox or the test RSA key, using LoadTestKeybox or
|
||||
// LoadTestRSAKey as needed.
|
||||
void EnsureTestKeys();
|
||||
// This loads the test keybox or the test RSA key, using LoadTestKeybox or
|
||||
// LoadTestRSAKey as needed.
|
||||
void EnsureTestKeys();
|
||||
|
||||
void InstallTestRSAKey(Session* s);
|
||||
void InstallTestRSAKey(Session* s);
|
||||
|
||||
std::vector<uint8_t> encoded_rsa_key_;
|
||||
std::vector<uint8_t> wrapped_rsa_key_;
|
||||
wvoec::WidevineKeybox keybox_;
|
||||
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_;
|
||||
};
|
||||
|
||||
} // namespace wvoec
|
||||
|
||||
Reference in New Issue
Block a user