Allow RSA 4096 key in package verification
The RSA_verify sitll works for 4096 bits keys. And we just need to loose the check on modulus. Sample commands to generate the key & package: 1. openssl genrsa -out keypair.pem 4096 2. openssl pkcs8 -topk8 -inform PEM -outform DER -nocrypt \ -in keypair.pem -out private.pk8 3. openssl req -new -x509 -key keypair.pem -out public.x509.pem \ -days 365 4. java -Djava.library.path=prebuilts/sdk/tools/linux/lib64 -jar \ prebuilts/sdk/tools/lib/signapk.jar -w public.x509.pem private.pk8 \ unsigned.zip signed.zip Bug: 129163830 Test: unit tests pass Change-Id: I5a5ff539c9ff1955c02ec2ce4b17563cb92808a4
This commit is contained in:
parent
6287253eb4
commit
908ad77af8
5 changed files with 50 additions and 3 deletions
|
@ -158,6 +158,17 @@ TEST(VerifierTest, LoadCertificateFromBuffer_sha256_ec256bits) {
|
|||
VerifyPackageWithSingleCertificate("otasigned_v5.zip", std::move(cert));
|
||||
}
|
||||
|
||||
TEST(VerifierTest, LoadCertificateFromBuffer_sha256_rsa4096_bits) {
|
||||
Certificate cert(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr);
|
||||
LoadKeyFromFile(from_testdata_base("testkey_4096bits.x509.pem"), &cert);
|
||||
|
||||
ASSERT_EQ(SHA256_DIGEST_LENGTH, cert.hash_len);
|
||||
ASSERT_EQ(Certificate::KEY_TYPE_RSA, cert.key_type);
|
||||
ASSERT_EQ(nullptr, cert.ec);
|
||||
|
||||
VerifyPackageWithSingleCertificate("otasigned_4096bits.zip", std::move(cert));
|
||||
}
|
||||
|
||||
TEST(VerifierTest, LoadCertificateFromBuffer_check_rsa_keys) {
|
||||
std::unique_ptr<RSA, RSADeleter> rsa(RSA_new());
|
||||
std::unique_ptr<BIGNUM, decltype(&BN_free)> exponent(BN_new(), BN_free);
|
||||
|
|
BIN
tests/testdata/otasigned_4096bits.zip
vendored
Normal file
BIN
tests/testdata/otasigned_4096bits.zip
vendored
Normal file
Binary file not shown.
35
tests/testdata/testkey_4096bits.x509.pem
vendored
Normal file
35
tests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52gVkQuUAX1+xB6wKLSDizQJw8SNiUGXl5+2vwV6+0BI3/CXlQ8I/nRPBC1
|
||||
oqOIkRSbE+IF7DP9QvYuNG/3bZZQ8LUVeHxqI5Mq8K2VIJZd95AIwPNMH34SaDGz
|
||||
9xjG28Fq4ZkuDP0pCsHM9d2XEwK5PEVS18WW5fJ/QcJKMno4IPTB70ZBBjVzv6Y+
|
||||
MYjOrw==
|
||||
-----END CERTIFICATE-----
|
|
@ -373,8 +373,8 @@ bool CheckRSAKey(const std::unique_ptr<RSA, RSADeleter>& rsa) {
|
|||
const BIGNUM* out_e;
|
||||
RSA_get0_key(rsa.get(), &out_n, &out_e, nullptr /* private exponent */);
|
||||
auto modulus_bits = BN_num_bits(out_n);
|
||||
if (modulus_bits != 2048) {
|
||||
LOG(ERROR) << "Modulus should be 2048 bits long, actual: " << modulus_bits;
|
||||
if (modulus_bits != 2048 && modulus_bits != 4096) {
|
||||
LOG(ERROR) << "Modulus should be 2048 or 4096 bits long, actual: " << modulus_bits;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,8 @@ class VerifierInterface {
|
|||
// VERIFY_FAILURE (if any error is encountered or no key matches the signature).
|
||||
int verify_file(VerifierInterface* package, const std::vector<Certificate>& keys);
|
||||
|
||||
// Checks that the RSA key has a modulus of 2048 bits long, and public exponent is 3 or 65537.
|
||||
// Checks that the RSA key has a modulus of 2048 or 4096 bits long, and public exponent is 3 or
|
||||
// 65537.
|
||||
bool CheckRSAKey(const std::unique_ptr<RSA, RSADeleter>& rsa);
|
||||
|
||||
// Checks that the field size of the curve for the EC key is 256 bits.
|
||||
|
|
Loading…
Reference in a new issue