Add extra RSA private keys to unit tests
There have been some failures with various RSA private keys. We add them to the unit tests to make sure that OEMCrypto is able to load these types of keys: * Shorter than normal private exponents. This seems to occur occasionally even with Euler totients. But it occurs more with Carmichael totients. * 0-leading-byte private exponents. This also occurs naturally for both Euler and Carmichael totients. * Carmichael vs Euler totients. I think we may already have tests for this. But just in case. Bug: 190450051
This commit is contained in:
1054
oemcrypto/test/oec_extra_test_keys.h
Normal file
1054
oemcrypto/test/oec_extra_test_keys.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -50,6 +50,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "oec_decrypt_fallback_chain.h"
|
#include "oec_decrypt_fallback_chain.h"
|
||||||
#include "oec_device_features.h"
|
#include "oec_device_features.h"
|
||||||
|
#include "oec_extra_test_keys.h"
|
||||||
#include "oec_session_util.h"
|
#include "oec_session_util.h"
|
||||||
#include "oec_test_data.h"
|
#include "oec_test_data.h"
|
||||||
#include "oemcrypto_session_tests_helper.h"
|
#include "oemcrypto_session_tests_helper.h"
|
||||||
@@ -4984,47 +4985,77 @@ TEST_F(
|
|||||||
TestHugeLengthDoesNotCrashAPI(oemcrypto_function, !kCheckStatus);
|
TestHugeLengthDoesNotCrashAPI(oemcrypto_function, !kCheckStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test a 3072 bit RSA key certificate.
|
class OEMCryptoLoadsCertVariousKeys : public OEMCryptoLoadsCertificate {
|
||||||
TEST_F(OEMCryptoLoadsCertificate, TestLargeRSAKey3072) {
|
public:
|
||||||
encoded_rsa_key_.assign(kTestRSAPKCS8PrivateKeyInfo3_3072,
|
void TestKey(const uint8_t* key, size_t key_length) {
|
||||||
kTestRSAPKCS8PrivateKeyInfo3_3072 +
|
encoded_rsa_key_.assign(key, key + key_length);
|
||||||
sizeof(kTestRSAPKCS8PrivateKeyInfo3_3072));
|
ASSERT_NO_FATAL_FAILURE(CreateWrappedRSAKey());
|
||||||
ASSERT_NO_FATAL_FAILURE(CreateWrappedRSAKey());
|
Session s;
|
||||||
Session s;
|
ASSERT_NO_FATAL_FAILURE(s.open());
|
||||||
ASSERT_NO_FATAL_FAILURE(s.open());
|
ASSERT_NO_FATAL_FAILURE(
|
||||||
ASSERT_NO_FATAL_FAILURE(
|
s.PreparePublicKey(encoded_rsa_key_.data(), encoded_rsa_key_.size()));
|
||||||
s.PreparePublicKey(encoded_rsa_key_.data(), encoded_rsa_key_.size()));
|
ASSERT_NO_FATAL_FAILURE(s.InstallRSASessionTestKey(wrapped_rsa_key_));
|
||||||
ASSERT_NO_FATAL_FAILURE(s.InstallRSASessionTestKey(wrapped_rsa_key_));
|
|
||||||
|
|
||||||
LicenseRoundTrip license_messages(&s);
|
LicenseRoundTrip license_messages(&s);
|
||||||
ASSERT_NO_FATAL_FAILURE(s.GenerateNonce());
|
ASSERT_NO_FATAL_FAILURE(s.GenerateNonce());
|
||||||
ASSERT_NO_FATAL_FAILURE(license_messages.SignAndVerifyRequest());
|
ASSERT_NO_FATAL_FAILURE(license_messages.SignAndVerifyRequest());
|
||||||
ASSERT_NO_FATAL_FAILURE(license_messages.CreateDefaultResponse());
|
ASSERT_NO_FATAL_FAILURE(license_messages.CreateDefaultResponse());
|
||||||
ASSERT_NO_FATAL_FAILURE(license_messages.EncryptAndSignResponse());
|
ASSERT_NO_FATAL_FAILURE(license_messages.EncryptAndSignResponse());
|
||||||
ASSERT_EQ(OEMCrypto_SUCCESS, license_messages.LoadResponse());
|
ASSERT_EQ(OEMCrypto_SUCCESS, license_messages.LoadResponse());
|
||||||
ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR());
|
ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Test a 3072 bit RSA key certificate.
|
||||||
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestLargeRSAKey3072) {
|
||||||
|
TestKey(kTestRSAPKCS8PrivateKeyInfo3_3072,
|
||||||
|
sizeof(kTestRSAPKCS8PrivateKeyInfo3_3072));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test an RSA key certificate which has a private key generated using the
|
// Test an RSA key certificate which has a private key generated using the
|
||||||
// Carmichael totient.
|
// Carmichael totient.
|
||||||
TEST_F(OEMCryptoLoadsCertificate, TestCarmichaelRSAKey) {
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestCarmichaelRSAKey) {
|
||||||
encoded_rsa_key_.assign(
|
TestKey(kTestKeyRSACarmichael_2048, sizeof(kTestKeyRSACarmichael_2048));
|
||||||
kTestKeyRSACarmichael_2048,
|
}
|
||||||
kTestKeyRSACarmichael_2048 + sizeof(kTestKeyRSACarmichael_2048));
|
|
||||||
ASSERT_NO_FATAL_FAILURE(CreateWrappedRSAKey());
|
|
||||||
Session s;
|
|
||||||
ASSERT_NO_FATAL_FAILURE(s.open());
|
|
||||||
ASSERT_NO_FATAL_FAILURE(
|
|
||||||
s.PreparePublicKey(encoded_rsa_key_.data(), encoded_rsa_key_.size()));
|
|
||||||
ASSERT_NO_FATAL_FAILURE(s.InstallRSASessionTestKey(wrapped_rsa_key_));
|
|
||||||
|
|
||||||
LicenseRoundTrip license_messages(&s);
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestCarmichaelNonZeroNormalDer) {
|
||||||
ASSERT_NO_FATAL_FAILURE(s.GenerateNonce());
|
TestKey(kCarmichaelNonZeroNormalDer, kCarmichaelNonZeroNormalDerLen);
|
||||||
ASSERT_NO_FATAL_FAILURE(license_messages.SignAndVerifyRequest());
|
}
|
||||||
ASSERT_NO_FATAL_FAILURE(license_messages.CreateDefaultResponse());
|
|
||||||
ASSERT_NO_FATAL_FAILURE(license_messages.EncryptAndSignResponse());
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestCarmichaelNonZeroShortDer) {
|
||||||
ASSERT_EQ(OEMCrypto_SUCCESS, license_messages.LoadResponse());
|
TestKey(kCarmichaelNonZeroShortDer, kCarmichaelNonZeroShortDerLen);
|
||||||
ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR());
|
}
|
||||||
|
|
||||||
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestCarmichaelZeroNormalDer) {
|
||||||
|
TestKey(kCarmichaelZeroNormalDer, kCarmichaelZeroNormalDerLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestCarmichaelZeroShortDer) {
|
||||||
|
TestKey(kCarmichaelZeroShortDer, kCarmichaelZeroShortDerLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestDualNonZeroNormalDer) {
|
||||||
|
TestKey(kDualNonZeroNormalDer, kDualNonZeroNormalDerLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestDualNonZeroShortDer) {
|
||||||
|
TestKey(kDualNonZeroShortDer, kDualNonZeroShortDerLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestDualZeroNormalDer) {
|
||||||
|
TestKey(kDualZeroNormalDer, kDualZeroNormalDerLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestDualZeroShortDer) {
|
||||||
|
TestKey(kDualZeroShortDer, kDualZeroShortDerLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestEulerNonZeroNormalDer) {
|
||||||
|
TestKey(kEulerNonZeroNormalDer, kEulerNonZeroNormalDerLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OEMCryptoLoadsCertVariousKeys, TestEulerZeroNormalDer) {
|
||||||
|
TestKey(kEulerZeroNormalDer, kEulerZeroNormalDerLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This tests that two sessions can use different RSA keys simultaneously.
|
// This tests that two sessions can use different RSA keys simultaneously.
|
||||||
|
|||||||
Reference in New Issue
Block a user