From c58a0c62feab3b0df89890654509bcab05f56364 Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Mon, 22 Jan 2018 09:48:57 -0800 Subject: [PATCH] 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 --- libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index 99a7906d..f88518ec 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -579,20 +579,24 @@ TEST_F(OEMCryptoProv30Test, OEMCertForbiddenPaddingScheme) { vector data(500); GetRandBytes(&data[0], data.size()); size_t signature_length = 0; - vector signature(1); + // We need a size one vector to pass as a pointer. + vector signature(1, 0); + vector 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 zero(signature_length, 0); ASSERT_EQ(zero, signature); // signature should not be computed. }