Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

frameworks-av: Commit

frameworks/av


Commit MetaInfo

Revisionba91a998f4bc0c69650954bfcd85cbc27afb1d41 (tree)
Time2018-01-14 05:37:30
AuthorEdwin Wong <edwinwong@goog...>
CommiterMoritz Horstmann

Log Message

Validate decryption key length to decrypt function.

Cherry picked from http://go/ag/3038278.

AesCtrDecryptor::decrypt() doesn't check whether the size of "key"
is equal to 16 bytes, which may lead to an OOB read problem in the
context of mediadrmserver.

Add DecryptsWithEmptyKey and DecryptsWithKeyTooLong unit tests.

Test: ClearKeyDrmUnitTest

adb shell LD_LIBRARY_PATH="/vendor/lib/mediadrm"
/data/nativetest/ClearKeyDrmUnitTest/ClearKeyDrmUnitTest

bug: 63982768
Change-Id: I1f22c9df2b051972b2c532608b7f203e3ce77926
(cherry picked from commit 379b672b189aa72ce0103b485019022f3e292c36)

Change Summary

Incremental Difference

--- a/drm/mediadrm/plugins/clearkey/AesCtrDecryptor.cpp
+++ b/drm/mediadrm/plugins/clearkey/AesCtrDecryptor.cpp
@@ -36,6 +36,11 @@ android::status_t AesCtrDecryptor::decrypt(const android::Vector<uint8_t>& key,
3636 uint8_t previousEncryptedCounter[kBlockSize];
3737 memset(previousEncryptedCounter, 0, kBlockSize);
3838
39+ if (key.size() != kBlockSize || (sizeof(Iv) / sizeof(uint8_t)) != kBlockSize) {
40+ android_errorWriteLog(0x534e4554, "63982768");
41+ return android::ERROR_DRM_DECRYPT;
42+ }
43+
3944 size_t offset = 0;
4045 AES_KEY opensslKey;
4146 AES_set_encrypt_key(key.array(), kBlockBitCount, &opensslKey);
--- a/drm/mediadrm/plugins/clearkey/AesCtrDecryptor.h
+++ b/drm/mediadrm/plugins/clearkey/AesCtrDecryptor.h
@@ -18,6 +18,7 @@
1818 #define CLEARKEY_AES_CTR_DECRYPTOR_H_
1919
2020 #include <media/stagefright/foundation/ABase.h>
21+#include <media/stagefright/MediaErrors.h>
2122 #include <Utils.h>
2223 #include <utils/Errors.h>
2324 #include <utils/Vector.h>
--- a/drm/mediadrm/plugins/clearkey/tests/AesCtrDecryptorUnittest.cpp
+++ b/drm/mediadrm/plugins/clearkey/tests/AesCtrDecryptorUnittest.cpp
@@ -34,7 +34,7 @@ class AesCtrDecryptorTest : public ::testing::Test {
3434 uint8_t* destination, const SubSample* subSamples,
3535 size_t numSubSamples, size_t* bytesDecryptedOut) {
3636 Vector<uint8_t> keyVector;
37- keyVector.appendArray(key, kBlockSize);
37+ keyVector.appendArray(key, sizeof(key) / sizeof(uint8_t));
3838
3939 AesCtrDecryptor decryptor;
4040 return decryptor.decrypt(keyVector, iv, source, destination, subSamples,
@@ -57,6 +57,67 @@ class AesCtrDecryptorTest : public ::testing::Test {
5757 }
5858 };
5959
60+TEST_F(AesCtrDecryptorTest, DecryptsWithEmptyKey) {
61+ const size_t kTotalSize = 64;
62+ const size_t kNumSubsamples = 1;
63+
64+ // Test vectors from NIST-800-38A
65+ Iv iv = {
66+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
67+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
68+ };
69+
70+ uint8_t source[kTotalSize] = { 0 };
71+ uint8_t destination[kTotalSize] = { 0 };
72+ SubSample subSamples[kNumSubsamples] = {
73+ {0, 64}
74+ };
75+
76+ size_t bytesDecrypted = 0;
77+ Vector<uint8_t> keyVector;
78+ keyVector.clear();
79+
80+ AesCtrDecryptor decryptor;
81+ ASSERT_EQ(android::ERROR_DRM_DECRYPT, decryptor.decrypt(keyVector, iv,
82+ &source[0], &destination[0],
83+ &subSamples[0], kNumSubsamples, &bytesDecrypted));
84+ ASSERT_EQ(0u, bytesDecrypted);
85+}
86+
87+TEST_F(AesCtrDecryptorTest, DecryptsWithKeyTooLong) {
88+ const size_t kTotalSize = 64;
89+ const size_t kNumSubsamples = 1;
90+
91+ // Test vectors from NIST-800-38A
92+ uint8_t key[kBlockSize * 2] = {
93+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
94+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
95+ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
96+ 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
97+ };
98+
99+ Iv iv = {
100+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
101+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
102+ };
103+
104+ uint8_t source[kTotalSize] = { 0 };
105+ uint8_t destination[kTotalSize] = { 0 };
106+ SubSample subSamples[kNumSubsamples] = {
107+ {0, 64}
108+ };
109+
110+ size_t bytesDecrypted = 0;
111+ Vector<uint8_t> keyVector;
112+ keyVector.appendArray(key, sizeof(key) / sizeof(uint8_t));
113+
114+ AesCtrDecryptor decryptor;
115+ ASSERT_EQ(android::ERROR_DRM_DECRYPT, decryptor.decrypt(keyVector, iv,
116+ &source[0], &destination[0],
117+ &subSamples[0], kNumSubsamples, &bytesDecrypted));
118+ ASSERT_EQ(0u, bytesDecrypted);
119+}
120+
60121 TEST_F(AesCtrDecryptorTest, DecryptsContiguousEncryptedBlock) {
61122 const size_t kTotalSize = 64;
62123 const size_t kNumSubsamples = 1;
Show on old repository browser