Make OEMCrypto test error-order agnostic

Bug: b/72320670
Test: Verified by unit/integration tests on sailfish

Merge from Widevine master of http://go/wvgerrit/41240

Previously, OEMCertForbiddenPaddingScheme checks to see if the OEMCrypto
returns a short buffer error on GenerateRSASignature and then resizes it
accordingly if so. If the OEMCrypto does not return this error first
(and instead complains about the padding scheme), the assertion will
return false since the signature has size 1. This CL changes that so it
doesn't matter which error the OEMCrypto returns first.

Change-Id: I2fd3a3814ff3722fd40ae6a3bcbd65293c9baed7
This commit is contained in:
Srujan Gaddam
2018-01-22 09:48:57 -08:00
parent f8d114ad11
commit c58a0c62fe

View File

@@ -579,20 +579,24 @@ TEST_F(OEMCryptoProv30Test, OEMCertForbiddenPaddingScheme) {
vector<uint8_t> data(500);
GetRandBytes(&data[0], data.size());
size_t signature_length = 0;
vector<uint8_t> signature(1);
// We need a size one vector to pass as a pointer.
vector<uint8_t> signature(1, 0);
vector<uint8_t> zero(1, 0);
sts = OEMCrypto_GenerateRSASignature(s.session_id(), &data[0], data.size(),
&signature[0], &signature_length,
kSign_PKCS1_Block1);
if (OEMCrypto_ERROR_SHORT_BUFFER == sts) {
// The OEMCrypto could complain about buffer length first, so let's
// resize and check if it's writing to the signature again.
signature.resize(signature_length, 0);
zero.resize(signature_length, 0);
sts = OEMCrypto_GenerateRSASignature(s.session_id(), &data[0], data.size(),
&signature[0], &signature_length,
kSign_PKCS1_Block1);
}
EXPECT_NE(OEMCrypto_SUCCESS, sts)
<< "OEM Cert Signed with forbidden kSign_PKCS1_Block1.";
vector<uint8_t> zero(signature_length, 0);
ASSERT_EQ(zero, signature); // signature should not be computed.
}