diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/test/resources/smimeUtils.jsm | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | comm/mailnews/test/resources/smimeUtils.jsm | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/comm/mailnews/test/resources/smimeUtils.jsm b/comm/mailnews/test/resources/smimeUtils.jsm new file mode 100644 index 0000000000..db7cf2e5c9 --- /dev/null +++ b/comm/mailnews/test/resources/smimeUtils.jsm @@ -0,0 +1,71 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * This file provides some utilities for helping run S/MIME tests. + */ + +var EXPORTED_SYMBOLS = ["SmimeUtils"]; + +var { MockRegistrar } = ChromeUtils.importESModule( + "resource://testing-common/MockRegistrar.sys.mjs" +); + +const gCertDialogs = { + confirmDownloadCACert: (ctx, cert, trust) => { + dump("Requesting certificate download\n"); + trust.value = Ci.nsIX509CertDB.TRUSTED_EMAIL; + return true; + }, + setPKCS12FilePassword: (ctx, password) => { + throw new Error("Not implemented"); + }, + getPKCS12FilePassword: (ctx, password) => { + password.value = ""; + return true; + }, + viewCert: (ctx, cert) => { + throw new Error("Not implemented"); + }, + QueryInterface: ChromeUtils.generateQI(["nsICertificateDialogs"]), +}; + +var SmimeUtils = { + ensureNSS() { + // Ensure NSS is initialized. + Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports); + + // Set up the internal key token so that subsequent code doesn't fail. If + // this isn't done, we'll fail to work if the NSS databases didn't already + // exist. + let keydb = Cc["@mozilla.org/security/pk11tokendb;1"].getService( + Ci.nsIPK11TokenDB + ); + try { + keydb.getInternalKeyToken().initPassword(""); + } catch (e) { + // In this scenario, the key token already had its password initialized. + // Therefore, we don't need to do anything (assuming its password is + // empty). + } + + MockRegistrar.register("@mozilla.org/nsCertificateDialogs;1", gCertDialogs); + }, + + loadPEMCertificate(file, certType, loadKey = false) { + dump("Loading certificate from " + file.path + "\n"); + let certDB = Cc["@mozilla.org/security/x509certdb;1"].getService( + Ci.nsIX509CertDB + ); + certDB.importCertsFromFile(file, certType); + }, + + loadCertificateAndKey(file, pw) { + dump("Loading key from " + file.path + "\n"); + let certDB = Cc["@mozilla.org/security/x509certdb;1"].getService( + Ci.nsIX509CertDB + ); + certDB.importPKCS12File(file, pw); + }, +}; |