1 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 // Checks that RSA certs with key sizes below 1024 bits are rejected.
8 // Checks that ECC certs using curves other than the NIST P-256, P-384 or P-521
9 // curves are rejected.
11 do_get_profile(); // must be called before getting nsIX509CertDB
12 const certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
19 * @param {string} rootKeyType
20 * The key type of the root certificate, or the name of an elliptic
21 * curve, as output by the 'openssl ecparam -list_curves' command.
22 * @param {number} rootKeySize
23 * @param {string} intKeyType
24 * @param {number} intKeySize
25 * @param {string} eeKeyType
26 * @param {number} eeKeySize
27 * @param {PRErrorCode} eeExpectedError
28 * @returns {Promise} a promise that will resolve when the verification has
40 let rootName = "root_" + rootKeyType + "_" + rootKeySize;
41 let intName = "int_" + intKeyType + "_" + intKeySize;
42 let eeName = "ee_" + eeKeyType + "_" + eeKeySize;
44 let intFullName = intName + "-" + rootName;
45 let eeFullName = eeName + "-" + intName + "-" + rootName;
47 addCertFromFile(certdb, `test_keysize/${rootName}.pem`, "CTu,CTu,CTu");
48 addCertFromFile(certdb, `test_keysize/${intFullName}.pem`, ",,");
49 let eeCert = constructCertFromFile(`test_keysize/${eeFullName}.pem`);
51 info("cert o=" + eeCert.organization);
52 info("cert issuer o=" + eeCert.issuerOrganization);
53 return checkCertErrorGeneric(
57 certificateUsageSSLServer
62 * Tests various RSA chains.
64 * @param {number} inadequateKeySize
65 * @param {number} adequateKeySize
67 async function checkRSAChains(inadequateKeySize, adequateKeySize) {
68 // Chain with certs that have adequate sizes for DV
79 // Chain with a root cert that has an inadequate size for DV
87 MOZILLA_PKIX_ERROR_INADEQUATE_KEY_SIZE
90 // Chain with an intermediate cert that has an inadequate size for DV
98 MOZILLA_PKIX_ERROR_INADEQUATE_KEY_SIZE
101 // Chain with an end entity cert that has an inadequate size for DV
109 MOZILLA_PKIX_ERROR_INADEQUATE_KEY_SIZE
113 async function checkECCChains() {
130 SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE
139 SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE
148 SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE
157 SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE
166 SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE
170 async function checkCombinationChains() {
187 SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE
196 MOZILLA_PKIX_ERROR_INADEQUATE_KEY_SIZE
200 add_task(async function () {
201 await checkRSAChains(1016, 1024);
202 await checkECCChains();
203 await checkCombinationChains();