forked from servo/servo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfd746b
commit 524331d
Showing
10 changed files
with
8,260 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// XPCShell script for generating a single file containing all certificates in PEM | ||
// format. You may run this in the browser toolbox's console | ||
// (Firefox -> devtools -> settings -> enable remote/chrome debugging, | ||
// followed by settings -> devtools menu -> browser toolbox) or the | ||
// xpcshell runner that comes with a built Firefox (./run-mozilla.sh ./xpcshell). | ||
// The variable `certstring` contains the final pem file. You can use `save(path)` to | ||
// save it to a file. `certlist` contains an array with the PEM certs as well as their names if you | ||
// want to filter them. | ||
|
||
|
||
// http://mxr.mozilla.org/mozilla-central/source/security/manager/pki/resources/content/pippki.js | ||
function getDERString(cert) | ||
{ | ||
var length = {}; | ||
var derArray = cert.getRawDER(length); | ||
var derString = ''; | ||
for (var i = 0; i < derArray.length; i++) { | ||
derString += String.fromCharCode(derArray[i]); | ||
} | ||
return derString; | ||
} | ||
|
||
// http://mxr.mozilla.org/mozilla-central/source/security/manager/pki/resources/content/pippki.js | ||
function getPEMString(cert) | ||
{ | ||
var derb64 = btoa(getDERString(cert)); | ||
// Wrap the Base64 string into lines of 64 characters, | ||
// with CRLF line breaks (as specified in RFC 1421). | ||
var wrapped = derb64.replace(/(\S{64}(?!$))/g, "$1\r\n"); | ||
return "-----BEGIN CERTIFICATE-----\r\n" | ||
+ wrapped | ||
+ "\r\n-----END CERTIFICATE-----\r\n"; | ||
} | ||
|
||
let certcache = Components.classes["@mozilla.org/security/nsscertcache;1"].createInstance(Ci.nsINSSCertCache); | ||
certcache.cacheAllCerts(); | ||
let enumerator = certcache.getX509CachedCerts().getEnumerator(); | ||
let certlist = []; | ||
let certstring=""; | ||
while(enumerator.hasMoreElements()){ | ||
let cert = enumerator.getNext().QueryInterface(Ci.nsIX509Cert); | ||
let pem = getPEMString(cert); | ||
certlist.push({name: cert.commonName, pem: pem}); | ||
certstring+=pem; | ||
} | ||
|
||
function save(path) { | ||
// https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O | ||
Components.utils.import("resource://gre/modules/FileUtils.jsm"); | ||
var file = new FileUtils.File(path); | ||
Components.utils.import("resource://gre/modules/NetUtil.jsm"); | ||
|
||
// file is nsIFile, data is a string | ||
|
||
// You can also optionally pass a flags parameter here. It defaults to | ||
// FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE; | ||
var ostream = FileUtils.openSafeFileOutputStream(file); | ||
|
||
var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]. | ||
createInstance(Components.interfaces.nsIScriptableUnicodeConverter); | ||
converter.charset = "UTF-8"; | ||
var istream = converter.convertToInputStream(certstring); | ||
|
||
// The last argument (the callback) is optional. | ||
NetUtil.asyncCopy(istream, ostream, function(status) { | ||
if (!Components.isSuccessCode(status)) { | ||
// Handle error! | ||
return; | ||
} | ||
|
||
// Data has been written to the file. | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.