OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "bindings/modules/v8/serialization/V8ScriptValueSerializerForModules.h" | 5 #include "bindings/modules/v8/serialization/V8ScriptValueSerializerForModules.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
8 #include "bindings/core/v8/ToV8.h" | 8 #include "bindings/core/v8/ToV8.h" |
9 #include "bindings/core/v8/V8ArrayBuffer.h" | 9 #include "bindings/core/v8/V8ArrayBuffer.h" |
10 #include "bindings/core/v8/V8BindingForTesting.h" | 10 #include "bindings/core/v8/V8BindingForTesting.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 ScopedEnableV8BasedStructuredClone enable; | 148 ScopedEnableV8BasedStructuredClone enable; |
149 V8TestingScope scope; | 149 V8TestingScope scope; |
150 | 150 |
151 // Make a certificate with the existing key above. | 151 // Make a certificate with the existing key above. |
152 std::unique_ptr<WebRTCCertificateGenerator> certificateGenerator( | 152 std::unique_ptr<WebRTCCertificateGenerator> certificateGenerator( |
153 Platform::current()->createRTCCertificateGenerator()); | 153 Platform::current()->createRTCCertificateGenerator()); |
154 std::unique_ptr<WebRTCCertificate> webCertificate = | 154 std::unique_ptr<WebRTCCertificate> webCertificate = |
155 certificateGenerator->fromPEM( | 155 certificateGenerator->fromPEM( |
156 WebString::fromUTF8(kEcdsaPrivateKey, sizeof(kEcdsaPrivateKey)), | 156 WebString::fromUTF8(kEcdsaPrivateKey, sizeof(kEcdsaPrivateKey)), |
157 WebString::fromUTF8(kEcdsaCertificate, sizeof(kEcdsaCertificate))); | 157 WebString::fromUTF8(kEcdsaCertificate, sizeof(kEcdsaCertificate))); |
| 158 ASSERT_TRUE(webCertificate); |
158 RTCCertificate* certificate = new RTCCertificate(std::move(webCertificate)); | 159 RTCCertificate* certificate = new RTCCertificate(std::move(webCertificate)); |
159 | 160 |
160 // Round trip test. | 161 // Round trip test. |
161 v8::Local<v8::Value> wrapper = | 162 v8::Local<v8::Value> wrapper = |
162 toV8(certificate, scope.context()->Global(), scope.isolate()); | 163 toV8(certificate, scope.context()->Global(), scope.isolate()); |
163 v8::Local<v8::Value> result = roundTrip(wrapper, scope); | 164 v8::Local<v8::Value> result = roundTrip(wrapper, scope); |
164 ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.isolate())); | 165 ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.isolate())); |
165 RTCCertificate* newCertificate = | 166 RTCCertificate* newCertificate = |
166 V8RTCCertificate::toImpl(result.As<v8::Object>()); | 167 V8RTCCertificate::toImpl(result.As<v8::Object>()); |
167 WebRTCCertificatePEM pem = newCertificate->certificate().toPEM(); | 168 WebRTCCertificatePEM pem = newCertificate->certificate().toPEM(); |
(...skipping 16 matching lines...) Expand all Loading... |
184 v8::Local<v8::Value> result = | 185 v8::Local<v8::Value> result = |
185 V8ScriptValueDeserializerForModules(scriptState, input).deserialize(); | 186 V8ScriptValueDeserializerForModules(scriptState, input).deserialize(); |
186 ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.isolate())); | 187 ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.isolate())); |
187 RTCCertificate* newCertificate = | 188 RTCCertificate* newCertificate = |
188 V8RTCCertificate::toImpl(result.As<v8::Object>()); | 189 V8RTCCertificate::toImpl(result.As<v8::Object>()); |
189 WebRTCCertificatePEM pem = newCertificate->certificate().toPEM(); | 190 WebRTCCertificatePEM pem = newCertificate->certificate().toPEM(); |
190 EXPECT_EQ(kEcdsaPrivateKey, pem.privateKey()); | 191 EXPECT_EQ(kEcdsaPrivateKey, pem.privateKey()); |
191 EXPECT_EQ(kEcdsaCertificate, pem.certificate()); | 192 EXPECT_EQ(kEcdsaCertificate, pem.certificate()); |
192 } | 193 } |
193 | 194 |
| 195 TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidRTCCertificate) { |
| 196 ScopedEnableV8BasedStructuredClone enable; |
| 197 V8TestingScope scope; |
| 198 |
| 199 // This is valid, except that "private" is not a valid private key PEM and |
| 200 // "certificate" is not a valid certificate PEM. This checks what happens if |
| 201 // these fail validation inside WebRTC. |
| 202 ScriptState* scriptState = scope.getScriptState(); |
| 203 RefPtr<SerializedScriptValue> input = serializedValue( |
| 204 {0xff, 0x09, 0x3f, 0x00, 0x6b, 0x07, 'p', 'r', 'i', 'v', 'a', 't', 'e', |
| 205 0x0b, 'c', 'e', 'r', 't', 'i', 'f', 'i', 'c', 'a', 't', 'e', 0x00}); |
| 206 |
| 207 // Decode test. |
| 208 v8::Local<v8::Value> result = |
| 209 V8ScriptValueDeserializerForModules(scriptState, input).deserialize(); |
| 210 EXPECT_TRUE(result->IsNull()); |
| 211 } |
| 212 |
194 // A bunch of voodoo which allows the asynchronous WebCrypto operations to be | 213 // A bunch of voodoo which allows the asynchronous WebCrypto operations to be |
195 // called synchronously, with the resulting JavaScript values extracted. | 214 // called synchronously, with the resulting JavaScript values extracted. |
196 | 215 |
197 using CryptoKeyPair = std::pair<CryptoKey*, CryptoKey*>; | 216 using CryptoKeyPair = std::pair<CryptoKey*, CryptoKey*>; |
198 | 217 |
199 template <typename T> | 218 template <typename T> |
200 T convertCryptoResult(const ScriptValue&); | 219 T convertCryptoResult(const ScriptValue&); |
201 template <> | 220 template <> |
202 CryptoKey* convertCryptoResult<CryptoKey*>(const ScriptValue& value) { | 221 CryptoKey* convertCryptoResult<CryptoKey*>(const ScriptValue& value) { |
203 return V8CryptoKey::toImplWithTypeCheck(value.isolate(), value.v8Value()); | 222 return V8CryptoKey::toImplWithTypeCheck(value.isolate(), value.v8Value()); |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 EXPECT_TRUE( | 851 EXPECT_TRUE( |
833 V8ScriptValueDeserializerForModules( | 852 V8ScriptValueDeserializerForModules( |
834 scriptState, serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04, | 853 scriptState, serializedValue({0xff, 0x09, 0x3f, 0x00, 0x4b, 0x04, |
835 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01})) | 854 0x0d, 0x01, 0x80, 0x08, 0x03, 0x01})) |
836 .deserialize() | 855 .deserialize() |
837 ->IsNull()); | 856 ->IsNull()); |
838 } | 857 } |
839 | 858 |
840 } // namespace | 859 } // namespace |
841 } // namespace blink | 860 } // namespace blink |
OLD | NEW |