mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-26 09:07:30 +09:00
Make sure nsNSSCertList handling checks for valid certs.
This commit is contained in:
parent
a9b20e6dc7
commit
6c4b9ec3ce
2 changed files with 36 additions and 3 deletions
|
|
@ -1208,6 +1208,10 @@ void nsNSSCertList::destructorSafeDestroyNSSReference()
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsNSSCertList::AddCert(nsIX509Cert* aCert)
|
nsNSSCertList::AddCert(nsIX509Cert* aCert)
|
||||||
{
|
{
|
||||||
|
if (!aCert) {
|
||||||
|
return NS_ERROR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
nsNSSShutDownPreventionLock locker;
|
nsNSSShutDownPreventionLock locker;
|
||||||
if (isAlreadyShutDown()) {
|
if (isAlreadyShutDown()) {
|
||||||
return NS_ERROR_NOT_AVAILABLE;
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
@ -1369,17 +1373,20 @@ nsNSSCertList::Read(nsIObjectInputStream* aStream)
|
||||||
nsCOMPtr<nsISupports> certSupports;
|
nsCOMPtr<nsISupports> certSupports;
|
||||||
rv = aStream->ReadObject(true, getter_AddRefs(certSupports));
|
rv = aStream->ReadObject(true, getter_AddRefs(certSupports));
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
break;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIX509Cert> cert = do_QueryInterface(certSupports);
|
nsCOMPtr<nsIX509Cert> cert = do_QueryInterface(certSupports);
|
||||||
|
if (!cert) {
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
rv = AddCert(cert);
|
rv = AddCert(cert);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
break;
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,30 @@ function test_cert_equals() {
|
||||||
" should return false");
|
" should return false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_bad_cert_list_serialization() {
|
||||||
|
// Normally the serialization of an nsIX509CertList consists of some header
|
||||||
|
// junk (IIDs and whatnot), 4 bytes representing how many nsIX509Cert follow,
|
||||||
|
// and then the serialization of each nsIX509Cert. This serialization consists
|
||||||
|
// of the header junk for an nsIX509CertList with 1 "nsIX509Cert", but then
|
||||||
|
// instead of an nsIX509Cert, the subsequent bytes represent the serialization
|
||||||
|
// of another nsIX509CertList (with 0 nsIX509Cert). This test ensures that
|
||||||
|
// nsIX509CertList safely handles this unexpected input when deserializing.
|
||||||
|
const badCertListSerialization =
|
||||||
|
"lZ+xZWUXSH+rm9iRO+UxlwAAAAAAAAAAwAAAAAAAAEYAAAABlZ+xZWUXSH+rm9iRO+UxlwAAAAAA" +
|
||||||
|
"AAAAwAAAAAAAAEYAAAAA";
|
||||||
|
let serHelper = Cc["@mozilla.org/network/serialization-helper;1"]
|
||||||
|
.getService(Ci.nsISerializationHelper);
|
||||||
|
throws(() => serHelper.deserializeObject(badCertListSerialization),
|
||||||
|
/NS_ERROR_UNEXPECTED/,
|
||||||
|
"deserializing a bogus nsIX509CertList should throw NS_ERROR_UNEXPECTED");
|
||||||
|
}
|
||||||
|
|
||||||
function test_cert_list_serialization() {
|
function test_cert_list_serialization() {
|
||||||
let certList = build_cert_chain(['default-ee', 'expired-ee']);
|
let certList = build_cert_chain(['default-ee', 'expired-ee']);
|
||||||
|
|
||||||
|
throws(() => certList.addCert(null), /NS_ERROR_ILLEGAL_VALUE/,
|
||||||
|
"trying to add a null cert to an nsIX509CertList should throw");
|
||||||
|
|
||||||
// Serialize the cert list to a string
|
// Serialize the cert list to a string
|
||||||
let serHelper = Cc["@mozilla.org/network/serialization-helper;1"]
|
let serHelper = Cc["@mozilla.org/network/serialization-helper;1"]
|
||||||
.getService(Ci.nsISerializationHelper);
|
.getService(Ci.nsISerializationHelper);
|
||||||
|
|
@ -77,6 +98,11 @@ function run_test() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test serialization of nsIX509CertList
|
// Test serialization of nsIX509CertList
|
||||||
|
add_test(function() {
|
||||||
|
test_bad_cert_list_serialization();
|
||||||
|
run_next_test();
|
||||||
|
});
|
||||||
|
|
||||||
add_test(function() {
|
add_test(function() {
|
||||||
test_cert_list_serialization();
|
test_cert_list_serialization();
|
||||||
run_next_test();
|
run_next_test();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue