Add PKCS#12 creation
This commit is contained in:
		
							parent
							
								
									5c3f0ea942
								
							
						
					
					
						commit
						d0e41cc9a9
					
				
					 1 changed files with 28 additions and 2 deletions
				
			
		|  | @ -23,6 +23,11 @@ | ||||||
|                     <small id="nameHelp" class="form-text text-muted">Please input your name as it should be added to |                     <small id="nameHelp" class="form-text text-muted">Please input your name as it should be added to | ||||||
|                         your certificate</small> |                         your certificate</small> | ||||||
|                 </div> |                 </div> | ||||||
|  |                 <div class="form-group"> | ||||||
|  |                     <label for="passwordInput">Password for your client certificate</label> | ||||||
|  |                     <input type="password" class="form-control" id="passwordInput" aria-describedby="nameHelp" required | ||||||
|  |                            minlength="8"> | ||||||
|  |                 </div> | ||||||
|                 <fieldset class="form-group"> |                 <fieldset class="form-group"> | ||||||
|                     <legend>RSA Key Size</legend> |                     <legend>RSA Key Size</legend> | ||||||
|                     <div class="form-check"> |                     <div class="form-check"> | ||||||
|  | @ -53,10 +58,16 @@ | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|     </div> |     </div> | ||||||
|  |     <div class="row"> | ||||||
|  |         <div class="col-12"> | ||||||
|  |             <div id="result"> | ||||||
|  |                 <button type="button" disabled id="send-button" class="btn btn-default disabled">Send signing request</button> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|     <pre id="key"></pre> |     <pre id="key"></pre> | ||||||
|     <pre id="csr"></pre> |     <pre id="csr"></pre> | ||||||
|     <pre id="crt"></pre> |     <pre id="crt"></pre> | ||||||
|     <button type="button" disabled id="send-button" class="btn btn-default disabled">Send signing request</button> |  | ||||||
| </div> | </div> | ||||||
| <script src="../public/js/jquery.slim.min.js"></script> | <script src="../public/js/jquery.slim.min.js"></script> | ||||||
| <script src="../public/js/forge.all.min.js"></script> | <script src="../public/js/forge.all.min.js"></script> | ||||||
|  | @ -82,6 +93,7 @@ | ||||||
|         const keyElement = document.getElementById('key'); |         const keyElement = document.getElementById('key'); | ||||||
|         document.getElementById('csr-form').onsubmit = function (event) { |         document.getElementById('csr-form').onsubmit = function (event) { | ||||||
|             const subject = event.target["nameInput"].value; |             const subject = event.target["nameInput"].value; | ||||||
|  |             const password = event.target["passwordInput"].value; | ||||||
|             const keySize = parseInt(event.target["keySize"].value); |             const keySize = parseInt(event.target["keySize"].value); | ||||||
|             if (isNaN(keySize)) { |             if (isNaN(keySize)) { | ||||||
|                 return false; |                 return false; | ||||||
|  | @ -127,8 +139,22 @@ | ||||||
|                                 .then(data => { |                                 .then(data => { | ||||||
|                                     console.log(data); |                                     console.log(data); | ||||||
|                                     document.getElementById("crt").innerHTML = data["certificate"]; |                                     document.getElementById("crt").innerHTML = data["certificate"]; | ||||||
|  |                                     const certificate = forge.pki.certificateFromPem(data["certificate"]); | ||||||
|  |                                     // browsers have trouble importing anything but 3des encrypted PKCS#12 | ||||||
|  |                                     const p12asn1 = forge.pkcs12.toPkcs12Asn1( | ||||||
|  |                                         keys.privateKey, certificate, password, | ||||||
|  |                                         {algorithm: '3des'} | ||||||
|  |                                     ); | ||||||
|  |                                     const p12Der = forge.asn1.toDer(p12asn1).getBytes(); | ||||||
|  |                                     const p12B64 = forge.util.encode64(p12Der); | ||||||
|  | 
 | ||||||
|  |                                     const a = document.createElement('a'); | ||||||
|  |                                     a.download = 'client_certificate.p12'; | ||||||
|  |                                     a.setAttribute('href', 'data:application/x-pkcs12;base64,' + p12B64); | ||||||
|  |                                     a.appendChild(document.createTextNode("Download")); | ||||||
|  |                                     document.getElementById('result').appendChild(a); | ||||||
|                                 }); |                                 }); | ||||||
|                         }) |                         }); | ||||||
|                         sendButton.removeAttribute("disabled"); |                         sendButton.removeAttribute("disabled"); | ||||||
|                         sendButton.classList.remove("disabled"); |                         sendButton.classList.remove("disabled"); | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
		Reference in a new issue