|
|
|
|
@@ -6,9 +6,6 @@
|
|
|
|
|
#include "oemcrypto_provisioning_test.h"
|
|
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
|
#include "oemcrypto_basic_test.h"
|
|
|
|
|
#include "oemcrypto_resource_test.h"
|
|
|
|
|
#include "oemcrypto_session_tests_helper.h"
|
|
|
|
|
#include "platform.h"
|
|
|
|
|
|
|
|
|
|
namespace wvoec {
|
|
|
|
|
@@ -623,5 +620,250 @@ TEST_F(OEMCryptoProv40Test, ProvisionDrmCert) {
|
|
|
|
|
ASSERT_EQ(s.IsPublicKeySet(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, PrepAndSignLicenseRequestCounterAPI18) {
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(CreateWrappedDRMKey());
|
|
|
|
|
Session s;
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(s.open());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(s.LoadWrappedRsaDrmKey(wrapped_drm_key_));
|
|
|
|
|
s.GenerateNonce();
|
|
|
|
|
|
|
|
|
|
size_t core_message_length = 100;
|
|
|
|
|
std::vector<uint8_t> message(128, 0);
|
|
|
|
|
std::vector<uint8_t> signature(256, 0);
|
|
|
|
|
size_t signature_length = signature.size();
|
|
|
|
|
|
|
|
|
|
OEMCryptoResult result = OEMCrypto_PrepAndSignLicenseRequest(
|
|
|
|
|
s.session_id(), message.data(), message.size(), &core_message_length,
|
|
|
|
|
signature.data(), &signature_length);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(OEMCrypto_SUCCESS, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This test verifies that we can create a wrapped RSA key, and then reload it.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, LoadRSASessionKey) {
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(CreateWrappedDRMKey());
|
|
|
|
|
Session s;
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(s.open());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(s.LoadWrappedRsaDrmKey(wrapped_drm_key_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, SignProvisioningRequest) {
|
|
|
|
|
Session s;
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(s.open());
|
|
|
|
|
if (global_features.provisioning_method == OEMCrypto_OEMCertificate) {
|
|
|
|
|
s.LoadOEMCert(true);
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_EQ(global_features.provisioning_method, OEMCrypto_Keybox);
|
|
|
|
|
s.GenerateDerivedKeysFromKeybox(keybox_);
|
|
|
|
|
}
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This tests a large message size. The size is larger than we required in v15.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, SignLargeProvisioningRequestAPI16) {
|
|
|
|
|
Session s;
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(s.open());
|
|
|
|
|
if (global_features.provisioning_method == OEMCrypto_OEMCertificate) {
|
|
|
|
|
s.LoadOEMCert(true);
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_EQ(global_features.provisioning_method, OEMCrypto_Keybox);
|
|
|
|
|
s.GenerateDerivedKeysFromKeybox(keybox_);
|
|
|
|
|
}
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
const size_t max_size = GetResourceValue(kLargeMessageSize);
|
|
|
|
|
provisioning_messages.set_message_size(max_size);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This creates a wrapped RSA key, and then does the sanity check that the
|
|
|
|
|
// unencrypted key is not found in the wrapped key. The wrapped key should be
|
|
|
|
|
// encrypted.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, CertificateProvision) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
ASSERT_EQ(OEMCrypto_SUCCESS, provisioning_messages.LoadResponse());
|
|
|
|
|
// We should not be able to find the rsa key in the wrapped key. It should
|
|
|
|
|
// be encrypted.
|
|
|
|
|
EXPECT_EQ(nullptr, find(provisioning_messages.wrapped_rsa_key(),
|
|
|
|
|
provisioning_messages.encoded_rsa_key()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify that RewrapDeviceRSAKey checks pointers are within the provisioning
|
|
|
|
|
// message.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionBadRange1_API16) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
// Encrypt and sign once, so that we can use the size of the response.
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
provisioning_messages.core_response().enc_private_key.offset =
|
|
|
|
|
provisioning_messages.encrypted_response_buffer().size() + 1;
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
ASSERT_NE(OEMCrypto_SUCCESS, provisioning_messages.LoadResponse());
|
|
|
|
|
provisioning_messages.VerifyLoadFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify that RewrapDeviceRSAKey checks pointers are within the provisioning
|
|
|
|
|
// message.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionBadRange2_API16) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
// Encrypt and sign once, so that we can use the size of the response.
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
provisioning_messages.core_response().enc_private_key_iv.offset =
|
|
|
|
|
provisioning_messages.encrypted_response_buffer().size() + 1;
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
ASSERT_NE(OEMCrypto_SUCCESS, provisioning_messages.LoadResponse());
|
|
|
|
|
provisioning_messages.VerifyLoadFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify that RewrapDeviceRSAKey checks pointers are within the provisioning
|
|
|
|
|
// message.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionBadRange3_API16) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
// Encrypt and sign once, so that we can use the size of the response.
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
// If the offset is before the end, but the offset+length is bigger, then
|
|
|
|
|
// the message should be rejected.
|
|
|
|
|
provisioning_messages.core_response().enc_private_key.offset =
|
|
|
|
|
provisioning_messages.encrypted_response_buffer().size() - 5;
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
ASSERT_NE(OEMCrypto_SUCCESS, provisioning_messages.LoadResponse());
|
|
|
|
|
provisioning_messages.VerifyLoadFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify that RewrapDeviceRSAKey checks pointers are within the provisioning
|
|
|
|
|
// message.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionBadRange4_API16) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
// Encrypt and sign once, so that we can use the size of the response.
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
// If the offset is before the end, but the offset+length is bigger, then
|
|
|
|
|
// the message should be rejected.
|
|
|
|
|
provisioning_messages.core_response().enc_private_key_iv.offset =
|
|
|
|
|
provisioning_messages.encrypted_response_buffer().size() - 5;
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
ASSERT_NE(OEMCrypto_SUCCESS, provisioning_messages.LoadResponse());
|
|
|
|
|
provisioning_messages.VerifyLoadFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify that RewrapDeviceRSAKey checks pointers are within the provisioning
|
|
|
|
|
// message.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionBadRange5Prov30_API16) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
// Encrypt and sign once, so that we can use the size of the response.
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
// If the offset is before the end, but the offset+length is bigger, then
|
|
|
|
|
// the message should be rejected.
|
|
|
|
|
provisioning_messages.core_response().encrypted_message_key.offset =
|
|
|
|
|
provisioning_messages.encrypted_response_buffer().size() + 1;
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
ASSERT_NE(OEMCrypto_SUCCESS, provisioning_messages.LoadResponse());
|
|
|
|
|
provisioning_messages.VerifyLoadFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that RewrapDeviceRSAKey verifies the message signature.
|
|
|
|
|
// TODO(b/144186970): This test should also run on Prov 3.0 devices.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate,
|
|
|
|
|
CertificateProvisionBadSignatureKeyboxTestAPI16) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
provisioning_messages.response_signature()[4] ^= 42; // bad signature.
|
|
|
|
|
ASSERT_EQ(OEMCrypto_ERROR_SIGNATURE_FAILURE,
|
|
|
|
|
provisioning_messages.LoadResponse());
|
|
|
|
|
provisioning_messages.VerifyLoadFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that RewrapDeviceRSAKey verifies the nonce is current.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionBadNonce_API16) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
provisioning_messages.core_request().nonce ^= 42; // bad nonce.
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
ASSERT_EQ(OEMCrypto_ERROR_INVALID_NONCE,
|
|
|
|
|
provisioning_messages.LoadResponse());
|
|
|
|
|
provisioning_messages.VerifyLoadFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that RewrapDeviceRSAKey verifies the RSA key is valid.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionBadRSAKey) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
provisioning_messages.response_data().rsa_key[4] ^= 42; // bad key.
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
ASSERT_NE(OEMCrypto_SUCCESS, provisioning_messages.LoadResponse());
|
|
|
|
|
provisioning_messages.VerifyLoadFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that RewrapDeviceRSAKey verifies the RSA key is valid.
|
|
|
|
|
// TODO(b/144186970): This test should also run on Prov 3.0 devices.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate,
|
|
|
|
|
CertificateProvisionBadRSAKeyKeyboxTestAPI16) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
size_t rsa_offset =
|
|
|
|
|
provisioning_messages.core_response().enc_private_key.offset;
|
|
|
|
|
// Offsets are relative to the message body, after the core message.
|
|
|
|
|
rsa_offset += provisioning_messages.serialized_core_message().size();
|
|
|
|
|
rsa_offset += 4; // Change the middle of the key.
|
|
|
|
|
provisioning_messages.encrypted_response_buffer()[rsa_offset] ^= 42;
|
|
|
|
|
ASSERT_EQ(OEMCrypto_ERROR_SIGNATURE_FAILURE,
|
|
|
|
|
provisioning_messages.LoadResponse());
|
|
|
|
|
provisioning_messages.VerifyLoadFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that RewrapDeviceRSAKey accepts the maximum message size.
|
|
|
|
|
TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionLargeBuffer) {
|
|
|
|
|
Session s;
|
|
|
|
|
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
|
|
|
|
|
const size_t max_size = GetResourceValue(kLargeMessageSize);
|
|
|
|
|
provisioning_messages.set_message_size(max_size);
|
|
|
|
|
provisioning_messages.PrepareSession(keybox_);
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.SignAndVerifyRequest());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.CreateDefaultResponse());
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(provisioning_messages.EncryptAndSignResponse());
|
|
|
|
|
ASSERT_EQ(OEMCrypto_SUCCESS, provisioning_messages.LoadResponse());
|
|
|
|
|
// We should not be able to find the rsa key in the wrapped key. It should
|
|
|
|
|
// be encrypted.
|
|
|
|
|
EXPECT_EQ(nullptr, find(provisioning_messages.wrapped_rsa_key(),
|
|
|
|
|
provisioning_messages.encoded_rsa_key()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
|
} // namespace wvoec
|