Skip to content

Commit

Permalink
bug 1166976 - generate some PSM xpcshell test certificates at build t…
Browse files Browse the repository at this point in the history
…ime r=Cykesiopka,mgoodwin,froydnj
  • Loading branch information
mozkeeler committed May 20, 2015
1 parent 9cd2669 commit 3a0944a
Show file tree
Hide file tree
Showing 54 changed files with 564 additions and 133 deletions.
2 changes: 2 additions & 0 deletions build/virtualenv_packages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ packages.txt:testing/mozbase/packages.txt
objdir:build
gyp.pth:media/webrtc/trunk/tools/gyp/pylib
pyasn1.pth:python/pyasn1
pyasn1_modules.pth:python/pyasn1-modules
bitstring.pth:python/bitstring
redo.pth:python/redo
requests.pth:python/requests
rsa.pth:python/rsa
29 changes: 27 additions & 2 deletions security/manager/ssl/tests/unit/head_psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ const certificateUsageStatusResponder = 0x0400;

const NO_FLAGS = 0;

// Commonly certificates are represented as PEM. The format is roughly as
// follows:
//
// -----BEGIN CERTIFICATE-----
// [some lines of base64, each typically 64 characters long]
// -----END CERTIFICATE-----
//
// However, nsIX509CertDB.constructX509FromBase64 and related functions do not
// handle input of this form. Instead, they require a single string of base64
// with no newlines or BEGIN/END headers. This is a helper function to convert
// PEM to the format that nsIX509CertDB requires.
function pemToBase64(pem) {
return pem.replace(/-----BEGIN CERTIFICATE-----/, "")
.replace(/-----END CERTIFICATE-----/, "")
.replace(/[\r\n]/g, "");
}

function readFile(file) {
let fstream = Cc["@mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream);
Expand All @@ -99,8 +116,16 @@ function readFile(file) {

function addCertFromFile(certdb, filename, trustString) {
let certFile = do_get_file(filename, false);
let der = readFile(certFile);
certdb.addCert(der, trustString, null);
let certBytes = readFile(certFile);
let successful = false;
try {
certdb.addCert(certBytes, trustString, null);
successful = true;
} catch (e) {}
if (!successful) {
// It might be PEM instead of DER.
certdb.addCertFromBase64(pemToBase64(certBytes), trustString, null);
}
}

function constructCertFromFile(filename) {
Expand Down
1 change: 1 addition & 0 deletions security/manager/ssl/tests/unit/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

DIRS += ['tlsserver']
TEST_DIRS += ['test_intermediate_basic_usage_constraints']

if not CONFIG['MOZ_NO_SMART_CARDS']:
DIRS += ['pkcs11testmodule']
Loading

0 comments on commit 3a0944a

Please sign in to comment.