community-website/clientcert/js/app.min.js

1 line
8.4 KiB
JavaScript
Raw Normal View History

2023-05-20 10:47:04 +00:00
document.addEventListener("DOMContentLoaded",function(){const e=document.getElementById("csr-form");var t=document.getElementById("crt-input");const r={keyPair:void 0,certificate:void 0,progressBar:document.getElementById("progress-bar"),keyOutput:document.getElementById("key-output"),csrOutput:document.getElementById("csr-output"),prepareButton:document.getElementById("generate-p12"),downloadButton:document.getElementById("download-link"),updateProgress(e,t,n,...r){this.progressBar.classList.add(...r),this.progressBar.style.width=e+"%",this.progressBar.setAttribute("aria-valuenow",""+t),this.progressBar.innerHTML=n},generateKeyPair(e){this.updateProgress(40,2,"Started key generation","progress-bar-striped","progress-bar-animated");const s=forge.pki.rsa.createKeyPairGenerationState(e,65537),a=new Date;return new Promise(n=>{const r=()=>{var e,t=(new Date).getTime()-a.getTime(),t=Math.floor(t/100)/10;forge.pki.rsa.stepKeyPairGenerationState(s,100)?(this.progressBar.classList.remove("progress-bar-animated","progress-bar-striped"),this.progressBar.innerHTML="Key pair generated",e=s.keys,document.getElementById("key-wrapper").classList.remove("d-none"),this.keyOutput.innerHTML=forge.pki.privateKeyToPem(e.privateKey),this.keyPair=s.keys,n()):(setTimeout(r,1),this.progressBar.innerHTML=`Key pair generation running for ${t} seconds`)};r()})},generateCSR(e){var n=forge.pki.createCertificationRequest(),e=(n.publicKey=this.keyPair.publicKey,n.setSubject([{name:"commonName",value:e,valueTagClass:forge.asn1.Type.UTF8}]),n.sign(this.keyPair.privateKey,forge.md.sha256.create()),n.verify());if(e){let t=forge.pki.certificationRequestToPem(n);this.updateProgress(60,3,"CSR generated"),document.getElementById("csr-output").innerHTML=t;e=document.getElementById("csr-wrapper");e.classList.remove("d-none"),e.scrollIntoView(),document.getElementById("copy-csr-to-clipboard").addEventListener("click",e=>{e.preventDefault(),navigator.clipboard.writeText(t);e=document.getElementById("crt-input-wrapper");e.classList.remove("d-none"),e.scrollIntoView(),this.updateProgress(80,4,"CSR copied to clipboard, waiting for certificate")})}},handleCertificate(e){this.certificate=e;e=document.getElementById("prepare-download-wrapper");e.classList.remove("d-none"),e.scrollIntoView(),this.progressBar.innerHTML="Certificate pasted",this.prepareButton.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation();e=document.getElementById("passwordInput").value;if(""===e||e.length<8)return!1;this.buildKeyStore(e)})},buildKeyStore(e){this.updateProgress(100,5,"Building keystore");var t=[],n=(t.push(this.certificate),[]);n.push(forge.pki.certificateFromPem("-----BEGIN CERTIFICATE-----\nMIIGPTCCBCWgAwIBAgIDFOIoMA0GCSqGSIb3DQEBDQUAMHkxEDAOBgNVBAoTB1Jv\nb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEiMCAGA1UEAxMZ\nQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJARYSc3VwcG9y\ndEBjYWNlcnQub3JnMB4XDTIxMDQxOTEyMTgzMFoXDTMxMDQxNzEyMTgzMFowVDEU\nMBIGA1UEChMLQ0FjZXJ0IEluYy4xHjAcBgNVBAsTFWh0dHA6Ly93d3cuQ0FjZXJ0\nLm9yZzEcMBoGA1UEAxMTQ0FjZXJ0IENsYXNzIDMgUm9vdDCCAiIwDQYJKoZIhvcN\nAQEBBQADggIPADCCAgoCggIBAKtJNRFIfNImflOUz0Op3SjXQiqL84d4GVh8D57a\niX3h++tykA10oZZkq5+gJJlz2uJVdscXe/UErEa4w75/ZI0QbCTzYZzA8pD6Ueb1\naQFjww9W4kpCz+JEjCUoqMV5CX1GuYrz6fM0KQhF5Byfy5QEHIGoFLOYZcRD7E6C\njQnRvapbjZLQ7N6QxX8KwuPr5jFaXnQ+lzNZ6MMDPWAzv/fRb0fEze5ig1JuLgia\npNkVGJGmhZJHsK5I6223IeyFGmhyNav/8BBdwPSUp2rVO5J+TJAFfpPBLIukjmJ0\nFXFuC3ED6q8VOJrU0gVyb4z5K+taciX5OUbjchs+BMNkJyIQKopPWKcDrb60Lh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