OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "media/base/decoder_buffer.h" | 10 #include "media/base/decoder_buffer.h" |
11 #include "media/base/decrypt_config.h" | 11 #include "media/base/decrypt_config.h" |
12 #include "media/base/mock_filters.h" | 12 #include "media/base/mock_filters.h" |
13 #include "media/cdm/aes_decryptor.h" | 13 #include "media/cdm/aes_decryptor.h" |
14 #include "media/webm/webm_constants.h" | 14 #include "media/webm/webm_constants.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 using ::testing::_; | 18 using ::testing::_; |
19 using ::testing::Gt; | 19 using ::testing::Gt; |
20 using ::testing::IsNull; | 20 using ::testing::IsNull; |
21 using ::testing::NotNull; | 21 using ::testing::NotNull; |
22 using ::testing::SaveArg; | 22 using ::testing::SaveArg; |
23 using ::testing::StrNe; | 23 using ::testing::StrNe; |
24 | 24 |
25 MATCHER(IsEmpty, "") { return arg.empty(); } | 25 MATCHER(IsEmpty, "") { return arg.empty(); } |
26 | 26 |
27 namespace media { | 27 namespace media { |
28 | 28 |
29 static const char kClearKeySystem[] = "org.w3.clearkey"; | 29 const uint8 kOriginalData[] = "Original subsample data."; |
| 30 const int kOriginalDataSize = 24; |
30 | 31 |
31 static const uint8 kOriginalData[] = "Original subsample data."; | 32 const uint8 kKeyId[] = { |
32 static const int kOriginalDataSize = 24; | |
33 | |
34 static const uint8 kKeyId[] = { | |
35 // base64 equivalent is AAECAw== | 33 // base64 equivalent is AAECAw== |
36 0x00, 0x01, 0x02, 0x03 | 34 0x00, 0x01, 0x02, 0x03 |
37 }; | 35 }; |
38 | 36 |
39 static const uint8 kKey[] = { | 37 const uint8 kKey[] = { |
40 // base64 equivalent is BAUGBwgJCgsMDQ4PEBESEw== | 38 // base64 equivalent is BAUGBwgJCgsMDQ4PEBESEw== |
41 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, | 39 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, |
42 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 | 40 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 |
43 }; | 41 }; |
44 | 42 |
45 static const char kKeyAsJWK[] = | 43 const char kKeyAsJWK[] = |
46 "{" | 44 "{" |
47 " \"keys\": [" | 45 " \"keys\": [" |
48 " {" | 46 " {" |
49 " \"kty\": \"oct\"," | 47 " \"kty\": \"oct\"," |
50 " \"kid\": \"AAECAw==\"," | 48 " \"kid\": \"AAECAw==\"," |
51 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw==\"" | 49 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw==\"" |
52 " }" | 50 " }" |
53 " ]" | 51 " ]" |
54 "}"; | 52 "}"; |
55 | 53 |
56 static const char kWrongKeyAsJWK[] = | 54 const char kWrongKeyAsJWK[] = |
57 "{" | 55 "{" |
58 " \"keys\": [" | 56 " \"keys\": [" |
59 " {" | 57 " {" |
60 " \"kty\": \"oct\"," | 58 " \"kty\": \"oct\"," |
61 " \"kid\": \"AAECAw==\"," | 59 " \"kid\": \"AAECAw==\"," |
62 " \"k\": \"7u7u7u7u7u7u7u7u7u7u7g==\"" | 60 " \"k\": \"7u7u7u7u7u7u7u7u7u7u7g==\"" |
63 " }" | 61 " }" |
64 " ]" | 62 " ]" |
65 "}"; | 63 "}"; |
66 | 64 |
67 static const char kWrongSizedKeyAsJWK[] = | 65 const char kWrongSizedKeyAsJWK[] = |
68 "{" | 66 "{" |
69 " \"keys\": [" | 67 " \"keys\": [" |
70 " {" | 68 " {" |
71 " \"kty\": \"oct\"," | 69 " \"kty\": \"oct\"," |
72 " \"kid\": \"AAECAw==\"," | 70 " \"kid\": \"AAECAw==\"," |
73 " \"k\": \"AAECAw==\"" | 71 " \"k\": \"AAECAw==\"" |
74 " }" | 72 " }" |
75 " ]" | 73 " ]" |
76 "}"; | 74 "}"; |
77 | 75 |
78 static const uint8 kIv[] = { | 76 const uint8 kIv[] = { |
79 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | 77 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, |
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
81 }; | 79 }; |
82 | 80 |
83 // kOriginalData encrypted with kKey and kIv but without any subsamples (or | 81 // kOriginalData encrypted with kKey and kIv but without any subsamples (or |
84 // equivalently using kSubsampleEntriesCypherOnly). | 82 // equivalently using kSubsampleEntriesCypherOnly). |
85 static const uint8 kEncryptedData[] = { | 83 const uint8 kEncryptedData[] = { |
86 0x2f, 0x03, 0x09, 0xef, 0x71, 0xaf, 0x31, 0x16, | 84 0x2f, 0x03, 0x09, 0xef, 0x71, 0xaf, 0x31, 0x16, |
87 0xfa, 0x9d, 0x18, 0x43, 0x1e, 0x96, 0x71, 0xb5, | 85 0xfa, 0x9d, 0x18, 0x43, 0x1e, 0x96, 0x71, 0xb5, |
88 0xbf, 0xf5, 0x30, 0x53, 0x9a, 0x20, 0xdf, 0x95 | 86 0xbf, 0xf5, 0x30, 0x53, 0x9a, 0x20, 0xdf, 0x95 |
89 }; | 87 }; |
90 | 88 |
91 // kOriginalData encrypted with kSubsampleKey and kSubsampleIv using | 89 // kOriginalData encrypted with kSubsampleKey and kSubsampleIv using |
92 // kSubsampleEntriesNormal. | 90 // kSubsampleEntriesNormal. |
93 static const uint8 kSubsampleEncryptedData[] = { | 91 const uint8 kSubsampleEncryptedData[] = { |
94 0x4f, 0x72, 0x09, 0x16, 0x09, 0xe6, 0x79, 0xad, | 92 0x4f, 0x72, 0x09, 0x16, 0x09, 0xe6, 0x79, 0xad, |
95 0x70, 0x73, 0x75, 0x62, 0x09, 0xbb, 0x83, 0x1d, | 93 0x70, 0x73, 0x75, 0x62, 0x09, 0xbb, 0x83, 0x1d, |
96 0x4d, 0x08, 0xd7, 0x78, 0xa4, 0xa7, 0xf1, 0x2e | 94 0x4d, 0x08, 0xd7, 0x78, 0xa4, 0xa7, 0xf1, 0x2e |
97 }; | 95 }; |
98 | 96 |
99 static const uint8 kOriginalData2[] = "Changed Original data."; | 97 const uint8 kOriginalData2[] = "Changed Original data."; |
100 | 98 |
101 static const uint8 kIv2[] = { | 99 const uint8 kIv2[] = { |
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
103 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
104 }; | 102 }; |
105 | 103 |
106 static const uint8 kKeyId2[] = { | 104 const uint8 kKeyId2[] = { |
107 // base64 equivalent is AAECAwQFBgcICQoLDA0ODxAREhM= | 105 // base64 equivalent is AAECAwQFBgcICQoLDA0ODxAREhM= |
108 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 106 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
109 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | 107 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
110 0x10, 0x11, 0x12, 0x13 | 108 0x10, 0x11, 0x12, 0x13 |
111 }; | 109 }; |
112 | 110 |
113 static const char kKey2AsJWK[] = | 111 const char kKey2AsJWK[] = |
114 "{" | 112 "{" |
115 " \"keys\": [" | 113 " \"keys\": [" |
116 " {" | 114 " {" |
117 " \"kty\": \"oct\"," | 115 " \"kty\": \"oct\"," |
118 " \"kid\": \"AAECAwQFBgcICQoLDA0ODxAREhM=\"," | 116 " \"kid\": \"AAECAwQFBgcICQoLDA0ODxAREhM=\"," |
119 " \"k\": \"FBUWFxgZGhscHR4fICEiIw==\"" | 117 " \"k\": \"FBUWFxgZGhscHR4fICEiIw==\"" |
120 " }" | 118 " }" |
121 " ]" | 119 " ]" |
122 "}"; | 120 "}"; |
123 | 121 |
124 // 'k' in bytes is x14x15x16x17x18x19x1ax1bx1cx1dx1ex1fx20x21x22x23 | 122 // 'k' in bytes is x14x15x16x17x18x19x1ax1bx1cx1dx1ex1fx20x21x22x23 |
125 | 123 |
126 static const uint8 kEncryptedData2[] = { | 124 const uint8 kEncryptedData2[] = { |
127 0x57, 0x66, 0xf4, 0x12, 0x1a, 0xed, 0xb5, 0x79, | 125 0x57, 0x66, 0xf4, 0x12, 0x1a, 0xed, 0xb5, 0x79, |
128 0x1c, 0x8e, 0x25, 0xd7, 0x17, 0xe7, 0x5e, 0x16, | 126 0x1c, 0x8e, 0x25, 0xd7, 0x17, 0xe7, 0x5e, 0x16, |
129 0xe3, 0x40, 0x08, 0x27, 0x11, 0xe9 | 127 0xe3, 0x40, 0x08, 0x27, 0x11, 0xe9 |
130 }; | 128 }; |
131 | 129 |
132 // Subsample entries for testing. The sum of |cypher_bytes| and |clear_bytes| of | 130 // Subsample entries for testing. The sum of |cypher_bytes| and |clear_bytes| of |
133 // all entries must be equal to kOriginalDataSize to make the subsample entries | 131 // all entries must be equal to kOriginalDataSize to make the subsample entries |
134 // valid. | 132 // valid. |
135 | 133 |
136 static const SubsampleEntry kSubsampleEntriesNormal[] = { | 134 const SubsampleEntry kSubsampleEntriesNormal[] = { |
137 { 2, 7 }, | 135 { 2, 7 }, |
138 { 3, 11 }, | 136 { 3, 11 }, |
139 { 1, 0 } | 137 { 1, 0 } |
140 }; | 138 }; |
141 | 139 |
142 static const SubsampleEntry kSubsampleEntriesWrongSize[] = { | 140 const SubsampleEntry kSubsampleEntriesWrongSize[] = { |
143 { 3, 6 }, // This entry doesn't match the correct entry. | 141 { 3, 6 }, // This entry doesn't match the correct entry. |
144 { 3, 11 }, | 142 { 3, 11 }, |
145 { 1, 0 } | 143 { 1, 0 } |
146 }; | 144 }; |
147 | 145 |
148 static const SubsampleEntry kSubsampleEntriesInvalidTotalSize[] = { | 146 const SubsampleEntry kSubsampleEntriesInvalidTotalSize[] = { |
149 { 1, 1000 }, // This entry is too large. | 147 { 1, 1000 }, // This entry is too large. |
150 { 3, 11 }, | 148 { 3, 11 }, |
151 { 1, 0 } | 149 { 1, 0 } |
152 }; | 150 }; |
153 | 151 |
154 static const SubsampleEntry kSubsampleEntriesClearOnly[] = { | 152 const SubsampleEntry kSubsampleEntriesClearOnly[] = { |
155 { 7, 0 }, | 153 { 7, 0 }, |
156 { 8, 0 }, | 154 { 8, 0 }, |
157 { 9, 0 } | 155 { 9, 0 } |
158 }; | 156 }; |
159 | 157 |
160 static const SubsampleEntry kSubsampleEntriesCypherOnly[] = { | 158 const SubsampleEntry kSubsampleEntriesCypherOnly[] = { |
161 { 0, 6 }, | 159 { 0, 6 }, |
162 { 0, 8 }, | 160 { 0, 8 }, |
163 { 0, 10 } | 161 { 0, 10 } |
164 }; | 162 }; |
165 | 163 |
166 static scoped_refptr<DecoderBuffer> CreateEncryptedBuffer( | 164 static scoped_refptr<DecoderBuffer> CreateEncryptedBuffer( |
167 const std::vector<uint8>& data, | 165 const std::vector<uint8>& data, |
168 const std::vector<uint8>& key_id, | 166 const std::vector<uint8>& key_id, |
169 const std::vector<uint8>& iv, | 167 const std::vector<uint8>& iv, |
170 int offset, | 168 int offset, |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 // 16 bytes long. Use the undecoded value of |kKey|. | 630 // 16 bytes long. Use the undecoded value of |kKey|. |
633 GenerateKeyRequest(key_id_); | 631 GenerateKeyRequest(key_id_); |
634 AddRawKeyAndExpect( | 632 AddRawKeyAndExpect( |
635 key_id_, std::vector<uint8>(kKey, kKey + arraysize(kKey)), KEY_ADDED); | 633 key_id_, std::vector<uint8>(kKey, kKey + arraysize(kKey)), KEY_ADDED); |
636 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( | 634 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( |
637 encrypted_data_, key_id_, iv_, 0, no_subsample_entries_); | 635 encrypted_data_, key_id_, iv_, 0, no_subsample_entries_); |
638 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS); | 636 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS); |
639 } | 637 } |
640 | 638 |
641 } // namespace media | 639 } // namespace media |
OLD | NEW |