Web PKI - Issue Software Certificate

by Lacuna Software

HTML

<script type="text/javascript" src="https://cdn.lacunasoftware.com/libs/web-pki/lacuna-web-pki-2.14.3.min.js"
  integrity="sha256-P92LF1ePw0qwnmbefDpDiMcr8rmwFkcxVX+utanmlek="
  crossorigin="anonymous"></script>

<h2>Web PKI - Issue Software Certificate Example</h2>
<h4>
  If you need a complete Certificate Chain Managing Solution, please visit: 
  <a href=https://www.lacunasoftware.com/en/amplia target="_blank">https://www.lacunasoftware.com/amplia/</a>
</h4>
<label><input id='saveBackup' type="checkbox"> Save backup file (.pfx)</label>
<br/><br/>
<button id="issueSoftCertificate" type="button">Issue Certificate</button>
<h4>Logs:</h4>
<div id="logPanel"></div>

CSS

@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
  font-family: 'Open Sans', sans-serif;
  font-style: normal;
  font-weight: 400;
  font-size: 14px;
}

#logPanel {
  font-family: monospace;
}

JavaScript

// ------------------------------------------------------------------------------------------
// Lacuna Web PKI - Issue Software Certificate

var webPkiLicense = 'AiEAKi5sYWN1bmFzb2Z0d2FyZS5jb20sanNmaWRkbGUubmV0AAACAENBCAAAGD8P6XvgCAABL3ZCfMfZGteSXNb2XNHBws9WZcTv0FCVe4qlxUXgaMzx4iymA73nVrD55o+S83b/alfQHs2xoIoPd6qiBDqbefk4GDnc84efZAX4UV7sHYr5x6+IRZ+RjW1DVZkJ9vo2/3/JeSRnj1Yvn3jtDf77jz2osQkFC5jSLABzCMAC/LXqPhOdZcK8hoyWOaghcsGvb5eezEFeJl+nkjDgZ6PsggdDpyWwLBFru4IeSRLE1HeP6TE6g5RQFjFHqNNCFRpP23/FQGD9/YDi2mR07lUxznt92z8GYygkp6O0Nv3ltj3eDGzN89LlgTBgsA2upsm0tTIgkWTDsKvqY6TwfsQ5tA==';

var pki = new LacunaWebPKI(webPkiLicense);

function start() {
  log('Initializing component...');
  
  pki.init({
    ready: onWebPkiReady,
    defaultFail: onWebPkiError,
    requiredApiVersion: pki.apiVersions.v1_5_2,
    notInstalled: onNotInstalled
  });
}

function onWebPkiReady() {
  log("Ready");
}

function onWebPkiError(ex) {
  log('Error: ' + ex.userMessage + ' (' + ex.code + ')');
}

function onNotInstalled(state) {
	var status = state === pki.installationStates.OUTDATED ? 'update' : 'install';
	alert('You need to ' + status + ' Web PKI plugin in order to continue');
  pki.redirectToInstallPage();
}

// ------------------------------------------
// Generate key pair and CSR

function startIssueCertificate() {
  log('Generating Key Pair...');
  
  pki.generateSoftwareRsaKeyPair({
    keySize: 2048,
    
    // Optional
    // CRL Subject Distinguished Names option
    subjectName: 'CN=Test Certificate ' + new Date().getTime()
    
  }).success(function(result) {
    issueCertificate(result);
  });
}

// ------------------------------------------
// Issue certificate on backend with CSR

// If you need a complete Certificate chain managing solution,
// please visit: https://www.lacunasoftware.com/amplia/

function issueCertificate(keyPairResult) {
	log ('Issuing certificate...');
  
  $.ajax({
  	type: 'POST',
  	url:...