Commit abfc7f7c authored by jbroman's avatar jbroman Committed by Commit bot

Handle RTCCertificate::fromPEM returning nullptr, with a unit test.

BUG=148757,webrtc:6488

Review-Url: https://codereview.chromium.org/2432493002
Cr-Commit-Position: refs/heads/master@{#427235}
parent 3995eb71
...@@ -166,8 +166,9 @@ std::unique_ptr<blink::WebRTCCertificate> RTCCertificateGenerator::fromPEM( ...@@ -166,8 +166,9 @@ std::unique_ptr<blink::WebRTCCertificate> RTCCertificateGenerator::fromPEM(
rtc::RTCCertificate::FromPEM( rtc::RTCCertificate::FromPEM(
rtc::RTCCertificatePEM(pem_private_key.utf8(), rtc::RTCCertificatePEM(pem_private_key.utf8(),
pem_certificate.utf8())); pem_certificate.utf8()));
return std::unique_ptr<blink::WebRTCCertificate>( if (!certificate)
new RTCCertificate(certificate)); return nullptr;
return base::MakeUnique<RTCCertificate>(certificate);
} }
} // namespace content } // namespace content
...@@ -330,9 +330,12 @@ class TestWebRTCCertificateGenerator ...@@ -330,9 +330,12 @@ class TestWebRTCCertificateGenerator
std::unique_ptr<blink::WebRTCCertificate> fromPEM( std::unique_ptr<blink::WebRTCCertificate> fromPEM(
blink::WebString pem_private_key, blink::WebString pem_private_key,
blink::WebString pem_certificate) override { blink::WebString pem_certificate) override {
return base::MakeUnique<RTCCertificate>( rtc::scoped_refptr<rtc::RTCCertificate> certificate =
rtc::RTCCertificate::FromPEM(rtc::RTCCertificatePEM( rtc::RTCCertificate::FromPEM(rtc::RTCCertificatePEM(
pem_private_key.utf8(), pem_certificate.utf8()))); pem_private_key.utf8(), pem_certificate.utf8()));
if (!certificate)
return nullptr;
return base::MakeUnique<RTCCertificate>(certificate);
} }
}; };
......
...@@ -412,6 +412,8 @@ bool SerializedScriptValueReaderForModules::readRTCCertificate( ...@@ -412,6 +412,8 @@ bool SerializedScriptValueReaderForModules::readRTCCertificate(
std::unique_ptr<WebRTCCertificate> certificate( std::unique_ptr<WebRTCCertificate> certificate(
certificateGenerator->fromPEM(pemPrivateKey, pemCertificate)); certificateGenerator->fromPEM(pemPrivateKey, pemCertificate));
if (!certificate)
return false;
RTCCertificate* jsCertificate = new RTCCertificate(std::move(certificate)); RTCCertificate* jsCertificate = new RTCCertificate(std::move(certificate));
*value = *value =
......
...@@ -47,6 +47,8 @@ ScriptWrappable* V8ScriptValueDeserializerForModules::readDOMObject( ...@@ -47,6 +47,8 @@ ScriptWrappable* V8ScriptValueDeserializerForModules::readDOMObject(
Platform::current()->createRTCCertificateGenerator()); Platform::current()->createRTCCertificateGenerator());
std::unique_ptr<WebRTCCertificate> certificate = std::unique_ptr<WebRTCCertificate> certificate =
certificateGenerator->fromPEM(pemPrivateKey, pemCertificate); certificateGenerator->fromPEM(pemPrivateKey, pemCertificate);
if (!certificate)
return nullptr;
return new RTCCertificate(std::move(certificate)); return new RTCCertificate(std::move(certificate));
} }
default: default:
......
...@@ -174,6 +174,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripRTCCertificate) { ...@@ -174,6 +174,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripRTCCertificate) {
certificateGenerator->fromPEM( certificateGenerator->fromPEM(
WebString::fromUTF8(kEcdsaPrivateKey, sizeof(kEcdsaPrivateKey)), WebString::fromUTF8(kEcdsaPrivateKey, sizeof(kEcdsaPrivateKey)),
WebString::fromUTF8(kEcdsaCertificate, sizeof(kEcdsaCertificate))); WebString::fromUTF8(kEcdsaCertificate, sizeof(kEcdsaCertificate)));
ASSERT_TRUE(webCertificate);
RTCCertificate* certificate = new RTCCertificate(std::move(webCertificate)); RTCCertificate* certificate = new RTCCertificate(std::move(webCertificate));
// Round trip test. // Round trip test.
...@@ -210,6 +211,24 @@ TEST(V8ScriptValueSerializerForModulesTest, DecodeRTCCertificate) { ...@@ -210,6 +211,24 @@ TEST(V8ScriptValueSerializerForModulesTest, DecodeRTCCertificate) {
EXPECT_EQ(kEcdsaCertificate, pem.certificate()); EXPECT_EQ(kEcdsaCertificate, pem.certificate());
} }
TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidRTCCertificate) {
ScopedEnableV8BasedStructuredClone enable;
V8TestingScope scope;
// This is valid, except that "private" is not a valid private key PEM and
// "certificate" is not a valid certificate PEM. This checks what happens if
// these fail validation inside WebRTC.
ScriptState* scriptState = scope.getScriptState();
RefPtr<SerializedScriptValue> input = serializedValue(
{0xff, 0x09, 0x3f, 0x00, 0x6b, 0x07, 'p', 'r', 'i', 'v', 'a', 't', 'e',
0x0b, 'c', 'e', 'r', 't', 'i', 'f', 'i', 'c', 'a', 't', 'e', 0x00});
// Decode test.
v8::Local<v8::Value> result =
V8ScriptValueDeserializerForModules(scriptState, input).deserialize();
EXPECT_TRUE(result->IsNull());
}
// A bunch of voodoo which allows the asynchronous WebCrypto operations to be // A bunch of voodoo which allows the asynchronous WebCrypto operations to be
// called synchronously, with the resulting JavaScript values extracted. // called synchronously, with the resulting JavaScript values extracted.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment