bug 867473 - (1/4) refactor certificate chain utility functions in certViewer.js r?jcj,fkiefer
MozReview-Commit-ID: EvDtrr4t1ZO
--- a/security/manager/pki/resources/content/certViewer.js
+++ b/security/manager/pki/resources/content/certViewer.js
@@ -74,22 +74,23 @@ function setWindowName() {
document.title = bundle.getFormattedString("certViewerTitle",
[cert.displayName]);
//
// Set the cert attributes for viewing
//
// Set initial dummy chain of just the cert itself. A more complete chain (if
- // one can be found), will be set when asyncDetermineUsages finishes.
+ // one can be found), will be set when the promise chain beginning at
+ // asyncDetermineUsages finishes.
AddCertChain("treesetDump", [cert]);
DisplayGeneralDataFromCert(cert);
BuildPrettyPrint(cert);
- asyncDetermineUsages(cert);
+ asyncDetermineUsages(cert).then(displayUsages);
}
// Certificate usages we care about in the certificate viewer.
const certificateUsageSSLClient = 0x0001;
const certificateUsageSSLServer = 0x0002;
const certificateUsageSSLCA = 0x0008;
const certificateUsageEmailSigner = 0x0010;
const certificateUsageEmailRecipient = 0x0020;
@@ -121,22 +122,24 @@ const SEC_ERROR_EXPIRED_CERTIFICATE
const SEC_ERROR_REVOKED_CERTIFICATE = SEC_ERROR_BASE + 12;
const SEC_ERROR_UNKNOWN_ISSUER = SEC_ERROR_BASE + 13;
const SEC_ERROR_UNTRUSTED_ISSUER = SEC_ERROR_BASE + 20;
const SEC_ERROR_UNTRUSTED_CERT = SEC_ERROR_BASE + 21;
const SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE = SEC_ERROR_BASE + 30;
const SEC_ERROR_CERT_SIGNATURE_ALGORITHM_DISABLED = SEC_ERROR_BASE + 176;
/**
- * Kicks off asynchronous verifications of the given certificate to determine
- * what usages it is currently valid for. Updates the usage display area when
- * complete.
+ * Returns a promise that will resolve with a results array (see
+ * `displayUsages`) consisting of what usages the given certificate successfully
+ * verified for.
*
* @param {nsIX509Cert} cert
* The certificate to determine valid usages for.
+ * @return {Promise}
+ * A promise that will resolve with the results of the verifications.
*/
function asyncDetermineUsages(cert) {
let promises = [];
let now = Date.now() / 1000;
let certdb = Cc["@mozilla.org/security/x509certdb;1"]
.getService(Ci.nsIX509CertDB);
Object.keys(certificateUsages).forEach(usageString => {
promises.push(new Promise((resolve, reject) => {
@@ -144,17 +147,17 @@ function asyncDetermineUsages(cert) {
certdb.asyncVerifyCertAtTime(cert, usage, 0, null, now,
(aPRErrorCode, aVerifiedChain, aHasEVPolicy) => {
resolve({ usageString,
errorCode: aPRErrorCode,
chain: aVerifiedChain });
});
}));
});
- Promise.all(promises).then(displayUsages);
+ return Promise.all(promises);
}
/**
* Given a results array (see displayUsages), returns the chain corresponding to
* the desired usage, if verifying for that usage succeeded. Returns null
* otherwise.
*
* @param {Array} results