Bug 1590709 - Fix crash in TransportSecurityInfo::ReadCertList r=keeler

Differential Revision: https://phabricator.services.mozilla.com/D50557

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Sean Feng 2019-10-25 18:20:53 +00:00
Родитель 4d0bd40e2e
Коммит ce3169b453
2 изменённых файлов: 170 добавлений и 15 удалений

Просмотреть файл

@ -449,7 +449,8 @@ nsresult TransportSecurityInfo::ReadCertificatesFromStream(
if (!cert) {
return NS_ERROR_UNEXPECTED;
}
aCertList.AppendElement(cert);
RefPtr<nsIX509Cert> castedCert(cert.get());
aCertList.AppendElement(castedCert);
}
return NS_OK;
}
@ -655,16 +656,6 @@ TransportSecurityInfo::Read(nsIObjectInputStream* aStream) {
}
}
// END moved from nsISSLStatus
// mIsDelegatedCredential added in bug 1562773
if (serVersion.EqualsASCII("2")) {
rv = aStream->ReadBoolean(&mIsDelegatedCredential);
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
"Deserialization should not fail");
if (NS_FAILED(rv)) {
return rv;
}
}
if (!serVersion.EqualsASCII("3")) {
// The old data structure of certList(nsIX509CertList) presents
rv = ReadCertList(aStream, mFailedCertChain);
@ -682,6 +673,16 @@ TransportSecurityInfo::Read(nsIObjectInputStream* aStream) {
NS_ENSURE_SUCCESS(rv, rv);
}
// mIsDelegatedCredential added in bug 1562773
if (serVersion.EqualsASCII("2") || serVersion.EqualsASCII("3")) {
rv = aStream->ReadBoolean(&mIsDelegatedCredential);
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
"Deserialization should not fail");
if (NS_FAILED(rv)) {
return rv;
}
}
return NS_OK;
}

Просмотреть файл

@ -399,7 +399,7 @@ function test_security_info_serialization(securityInfo, expectedErrorCode) {
// Array<nsIX509Cert>, so the serialization of the certList changed. This
// test is used to make sure we can still deserialize the transportSecurityInfo
// binary string which has the old certList binary.
function test_old_succeeded_certlist_deseralization() {
function test_old_succeeded_certlist_deseralization_v1() {
// This was the serialized output of test "good.include-subdomains.pinning.example.com"
// in security/manager/ssl/tests/unit/test_cert_chains.js
// The serialized output was generated before we replace nsIX509CertList with
@ -478,11 +478,88 @@ function test_old_succeeded_certlist_deseralization() {
);
}
// Same as the above test, however, this is the v2 version of the
// serialization.
function test_old_succeeded_certlist_deseralization_v2() {
const serialized =
"FnhllAKWRHGAlo+ESXykKAAAAAAAAAAAwAAAAAAAAEaphjojH6pBabDSgSnsfLHeAAAAAgA" +
"AAAAAAAAAAAAAAAAAAAEAMgFmCjImkVxP+7sgiYWmMt8FvcOXmlQiTNWFiWlrbpbqgwAAAA" +
"AAAAONMIIDiTCCAnGgAwIBAgIUDUo/9G0rz7fJiWTw0hY6TIyPRSIwDQYJKoZIhvcNAQELB" +
"QAwEjEQMA4GA1UEAwwHVGVzdCBDQTAiGA8yMDE3MTEyNzAwMDAwMFoYDzIwMjAwMjA1MDAw" +
"MDAwWjAaMRgwFgYDVQQDDA9UZXN0IEVuZC1lbnRpdHkwggEiMA0GCSqGSIb3DQEBAQUAA4I" +
"BDwAwggEKAoIBAQC6iFGoRI4W1kH9braIBjYQPTwT2erkNUq07PVoV2wke8HHJajg2B+9sZ" +
"wGm24ahvJr4q9adWtqZHEIeqVap0WH9xzVJJwCfs1D/B5p0DggKZOrIMNJ5Nu5TMJrbA7tF" +
"YIP8X6taRqx0wI6iypB7qdw4A8Njf1mCyuwJJKkfbmIYXmQsVeQPdI7xeC4SB+oN9OIQ+8n" +
"FthVt2Zaqn4CkC86exCABiTMHGyXrZZhW7filhLAdTGjDJHdtMr3/K0dJdMJ77kXDqdo4bN" +
"7LyJvaeO0ipVhHe4m1iWdq5EITjbLHCQELL8Wiy/l8Y+ZFzG4s/5JI/pyUcQx1QOs2hgKNe" +
"2NAgMBAAGjgcowgccwgZAGA1UdEQSBiDCBhYIJbG9jYWxob3N0gg0qLmV4YW1wbGUuY29tg" +
"hUqLnBpbm5pbmcuZXhhbXBsZS5jb22CKCouaW5jbHVkZS1zdWJkb21haW5zLnBpbm5pbmcu" +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MTI3MDAwMDAwWhgPMjAyMDA" +
"yMDUwMDAwMDBaMBIxEDAOBgNVBAMMB1Rlc3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDw" +
"AwggEKAoIBAQC6iFGoRI4W1kH9braIBjYQPTwT2erkNUq07PVoV2wke8HHJajg2B+9sZwGm" +
"24ahvJr4q9adWtqZHEIeqVap0WH9xzVJJwCfs1D/B5p0DggKZOrIMNJ5Nu5TMJrbA7tFYIP" +
"8X6taRqx0wI6iypB7qdw4A8Njf1mCyuwJJKkfbmIYXmQsVeQPdI7xeC4SB+oN9OIQ+8nFth" +
"Vt2Zaqn4CkC86exCABiTMHGyXrZZhW7filhLAdTGjDJHdtMr3/K0dJdMJ77kXDqdo4bN7Ly" +
"JvaeO0ipVhHe4m1iWdq5EITjbLHCQELL8Wiy/l8Y+ZFzG4s/5JI/pyUcQx1QOs2hgKNe2NA" +
"gMBAAGjHTAbMAwGA1UdEwQFMAMBAf8wCwYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBCwUAA4IB" +
"AQAgyCfLAcVs/MkERxunH9pZA4ja1QWWjsxSg9KgAIfOgj8c5RPHbl4oeWk0raNKWMu5+FR" +
"3/94IJeD45C3h/Y3+1HDyC6ZuzdgMXv63dk0a36JDFlPA3swqwYhnL7pHnbdcfDyWnMVfmL" +
"NeAhL7QA+Vf5fJmTsxEJwFaHo9JpKoQ469RdWno6aHeK3TfiQFaebzT1MRabCJXDeyw8Oal" +
"QICt0M0wx29B6HNof3px2NxKyC6qlf01wwNSaaIbsctDaLL5ZLN6T1LjpJsooMvDwRt69+S" +
"Xo8SmD4YO6Wr4Q9drI3cCwVeQXwxoUuB96muQQ2M3WDiMz5ZLI3oMLu8KSPsAAA=";
let serHelper = Cc["@mozilla.org/network/serialization-helper;1"].getService(
Ci.nsISerializationHelper
);
// deserialize from the string and compare to the original object
let deserialized = serHelper.deserializeObject(serialized);
deserialized.QueryInterface(Ci.nsITransportSecurityInfo);
equal(
deserialized.failedCertChain,
null,
"failedCertChain for a successful connection should be null"
);
let certChain = build_cert_chain(["default-ee", "test-ca"]);
ok(
certChain.equals(deserialized.succeededCertChain),
"succeededCertChain should be deserialized correctly"
);
}
// In Bug 1580315, nsNSSCertList/nsIX509CertList was replaced by
// Array<nsIX509Cert>, so the serialization of the certList changed. This
// test is used to make sure we can still deserialize the TransportSecurityInfo
// binary string which has the old certList binary.
function test_old_failed_certlist_deseralization() {
function test_old_failed_certlist_deseralization_v1() {
// This was the serialized output of test "expired.example.com"
// in security/manager/ssl/tests/unit/test_cert_chains.js
// The serialized output was generated before we replace nsIX509CertList with
@ -557,6 +634,73 @@ function test_old_failed_certlist_deseralization() {
);
}
// Same as the above test, however, this is the v2 version of the
// serialization.
function test_old_failed_certlist_deseralization_v2() {
const serialized =
"FnhllAKWRHGAlo+ESXykKAAAAAAAAAAAwAAAAAAAAEaphjojH6pBabDSgSnsfLHeAAAABAA" +
"AAAAAAAAA///gCwAAAAEAMgFmCjImkVxP+7sgiYWmMt8FvcOXmlQiTNWFiWlrbpbqgwAAAA" +
"AAAAMgMIIDHDCCAgSgAwIBAgIUY9ERAIKj0js/YbhJoMrcLnj++uowDQYJKoZIhvcNAQELB" +
"QAwEjEQMA4GA1UEAwwHVGVzdCBDQTAiGA8yMDEzMDEwMTAwMDAwMFoYDzIwMTQwMTAxMDAw" +
"MDAwWjAiMSAwHgYDVQQDDBdFeHBpcmVkIFRlc3QgRW5kLWVudGl0eTCCASIwDQYJKoZIhvc" +
"NAQEBBQADggEPADCCAQoCggEBALqIUahEjhbWQf1utogGNhA9PBPZ6uQ1SrTs9WhXbCR7wc" +
"clqODYH72xnAabbhqG8mvir1p1a2pkcQh6pVqnRYf3HNUknAJ+zUP8HmnQOCApk6sgw0nk2" +
"7lMwmtsDu0Vgg/xfq1pGrHTAjqLKkHup3DgDw2N/WYLK7AkkqR9uYhheZCxV5A90jvF4LhI" +
"H6g304hD7ycW2FW3ZlqqfgKQLzp7EIAGJMwcbJetlmFbt+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ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC6iFGoRI4W1kH9braIBj" +
"YQPTwT2erkNUq07PVoV2wke8HHJajg2B+9sZwGm24ahvJr4q9adWtqZHEIeqVap0WH9xzVJ" +
"JwCfs1D/B5p0DggKZOrIMNJ5Nu5TMJrbA7tFYIP8X6taRqx0wI6iypB7qdw4A8Njf1mCyuw" +
"JJKkfbmIYXmQsVeQPdI7xeC4SB+oN9OIQ+8nFthVt2Zaqn4CkC86exCABiTMHGyXrZZhW7f" +
"ilhLAdTGjDJHdtMr3/K0dJdMJ77kXDqdo4bN7LyJvaeO0ipVhHe4m1iWdq5EITjbLHCQELL" +
"8Wiy/l8Y+ZFzG4s/5JI/pyUcQx1QOs2hgKNe2NAgMBAAGjHTAbMAwGA1UdEwQFMAMBAf8wC" +
"wYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBCwUAA4IBAQAgyCfLAcVs/MkERxunH9pZA4ja1QWW" +
"jsxSg9KgAIfOgj8c5RPHbl4oeWk0raNKWMu5+FR3/94IJeD45C3h/Y3+1HDyC6ZuzdgMXv6" +
"3dk0a36JDFlPA3swqwYhnL7pHnbdcfDyWnMVfmLNeAhL7QA+Vf5fJmTsxEJwFaHo9JpKoQ4" +
"69RdWno6aHeK3TfiQFaebzT1MRabCJXDeyw8OalQICt0M0wx29B6HNof3px2NxKyC6qlf01" +
"wwNSaaIbsctDaLL5ZLN6T1LjpJsooMvDwRt69+SXo8SmD4YO6Wr4Q9drI3cCwVeQXwxoUuB" +
"96muQQ2M3WDiMz5ZLI3oMLu8KSPsAA==";
let serHelper = Cc["@mozilla.org/network/serialization-helper;1"].getService(
Ci.nsISerializationHelper
);
// Deserialize from the string and compare to the original object
let deserialized = serHelper.deserializeObject(serialized);
deserialized.QueryInterface(Ci.nsITransportSecurityInfo);
let certChain = build_cert_chain(["expired-ee", "test-ca"]);
ok(
certChain.equals(deserialized.failedCertChain),
"failedCertChain should be deserialized correctly"
);
}
function run_test() {
do_get_profile();
add_tls_server_setup("BadCertAndPinningServer", "bad_certs");
@ -589,12 +733,22 @@ function run_test() {
});
add_test(function() {
test_old_succeeded_certlist_deseralization();
test_old_succeeded_certlist_deseralization_v2();
run_next_test();
});
add_test(function() {
test_old_failed_certlist_deseralization();
test_old_failed_certlist_deseralization_v2();
run_next_test();
});
add_test(function() {
test_old_succeeded_certlist_deseralization_v1();
run_next_test();
});
add_test(function() {
test_old_failed_certlist_deseralization_v1();
run_next_test();
});