_410-cdn-plugin.js
Summary
Plug-In to request certificate for CardContact Developer Network
function CDNRequester(km) {
this.km = km;
}
exports.Plugin = CDNRequester;
CDNRequester.REQUEST_CDN_CERTIFICATE = "Request CDN Certificate";
CDNRequester.prototype.addDeviceContextMenu = function(contextMenu, isInitialized, authenticationState) {
if (isInitialized && (authenticationState == 0x9000)) {
contextMenu.push(CDNRequester.REQUEST_CDN_CERTIFICATE);
}
}
CDNRequester.prototype.actionListener = function(source, action) {
if (!action.equals(CDNRequester.REQUEST_CDN_CERTIFICATE)) {
return false;
}
var url = Dialog.prompt("Please enter URL of Online CA", KeyManager.DEVNETCA_URL);
if (!url) {
return;
}
var label = url.match(/\w+:\/\/([\w.]+)/)[1];
print("Using label \"" + label + "\" for key");
if (this.km.ks.hasKey(label)) {
Dialog.prompt("Please remove existing key first");
return;
}
var commonName = "Joe Doe";
commonName = Dialog.prompt("Please enter name or pseudonym for entry into the common name field of the certificate", commonName);
if (!commonName) {
return;
}
var eMailAddress = " joe.doe@openscdp.org";
do {
var eMailAddress = Dialog.prompt("Please enter a valid e-mail address for entry into the subjectAlternativeName field of the certificate", eMailAddress);
if (!eMailAddress) {
return;
}
} while (eMailAddress.match(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+/)[0] != eMailAddress);
if (eMailAddress.length > 0) {
print("The CA will send an activation code to " + eMailAddress);
}
print("Generating a 2048 bit RSA key pair can take up to 60 seconds. Please wait...");
var req = this.km.ks.generateRSAKeyPair(label, 2048);
var devAutCert = this.km.sc.readBinary(SmartCardHSM.C_DevAut);
var activationCode;
do {
var cacon = new CAConnection(url);
var certs = cacon.requestCertificate(req.getBytes(), devAutCert, commonName, eMailAddress, activationCode);
cacon.close();
if (certs == null) {
var rc = cacon.getLastReturnCode();
if (rc == "activation_code_wrong") {
assert(Dialog.prompt("Wrong activation code - Press OK to retry"));
}
if ((rc == "activation_code_required") || (rc == "activation_code_wrong")) {
activationCode = Dialog.prompt("Please check your e-mail and enter activation code", "");
assert(activationCode != null);
} else {
print("Online CA returned " + cacon.getLastReturnCode());
break;
}
} else {
var cert = new X509(certs[0]);
print(cert);
print("Received certificate from CA, now storing it on the device...");
this.km.ks.storeEndEntityCertificate(label, cert);
}
} while (!certs);
this.km.createOutline();
return true;
}
CDNRequester.prototype.toString = function() {
return "CDN Certificate Requester";
}
Documentation generated by
JSDoc on Sat Feb 24 15:17:19 2024