Now uses RSA keys for firefox browser.

This commit is contained in:
John Shaver 2018-11-09 13:57:59 -08:00
parent bddf85dfe6
commit 6f188cefb8
1 changed files with 20 additions and 8 deletions

View File

@ -1,6 +1,7 @@
(function () { (function () {
'use strict'; 'use strict';
var BROWSER_SUPPORTS_ECDSA = navigator.userAgent.toLowerCase().indexOf('firefox') === -1;
var $qs = function (s) { return window.document.querySelector(s); }; var $qs = function (s) { return window.document.querySelector(s); };
var $qsa = function (s) { return window.document.querySelectorAll(s); }; var $qsa = function (s) { return window.document.querySelectorAll(s); };
var info = {}; var info = {};
@ -321,7 +322,7 @@
}); });
}).catch(function (err) { }).catch(function (err) {
console.error('Step \'' + i + '\' Error:'); console.error('Step \'' + i + '\' Error:');
console.error(err); console.error(err, err.stack);
}); });
}; };
@ -423,10 +424,21 @@
var p; var p;
function createKeypair() { function createKeypair() {
return BACME.accounts.generateKeypair({ let opts;
type: 'ECDSA'
, bitlength: '256' if(BROWSER_SUPPORTS_ECDSA) {
}).then(function (serverJwk) { opts = {
type: 'ECDSA'
, bitlength: '256'
};
} else {
opts = {
type: 'RSA'
, bitlength: '2048'
};
}
return BACME.accounts.generateKeypair(opts).then(function (serverJwk) {
localStorage.setItem('server:' + key, JSON.stringify(serverJwk)); localStorage.setItem('server:' + key, JSON.stringify(serverJwk));
return serverJwk; return serverJwk;
}) })
@ -532,15 +544,15 @@
, true , true
, ["sign"] , ["sign"]
).then(function (privateKey) { ).then(function (privateKey) {
return window.crypto.subtle.exportKey("pkcs8", privateKey); return window.crypto.subtle.exportKey("pkcs8", privateKey);
}).then (function (keydata) { }).then (function (keydata) {
var pem = spkiToPEM(keydata); var pem = spkiToPEM(keydata);
$qs('#js-privkey').innerHTML = pem; $qs('#js-privkey').innerHTML = pem;
$qs("#js-download-privkey-link").href = $qs("#js-download-privkey-link").href =
"data:text/octet-stream;base64," + window.btoa(pem); "data:text/octet-stream;base64," + window.btoa(pem);
steps[i](); steps[i]();
}).catch(function(err){ }).catch(function(err){
console.error(err); console.error(err.toString());
}); });
}); });
}); });