feat: add CSR parsing
This commit is contained in:
		
							parent
							
								
									5732ce7a4f
								
							
						
					
					
						commit
						2f64b7e53d
					
				
							
								
								
									
										1
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -33,6 +33,7 @@ declare module '@vue/runtime-core' { | |||||||
|     CCollapse: typeof import('./src/ui/c-collapse/c-collapse.vue')['default'] |     CCollapse: typeof import('./src/ui/c-collapse/c-collapse.vue')['default'] | ||||||
|     'CCollapse.demo': typeof import('./src/ui/c-collapse/c-collapse.demo.vue')['default'] |     'CCollapse.demo': typeof import('./src/ui/c-collapse/c-collapse.demo.vue')['default'] | ||||||
|     CDiffEditor: typeof import('./src/ui/c-diff-editor/c-diff-editor.vue')['default'] |     CDiffEditor: typeof import('./src/ui/c-diff-editor/c-diff-editor.vue')['default'] | ||||||
|  |     CertificateKeyParser: typeof import('./src/tools/certificate-key-parser/certificate-key-parser.vue')['default'] | ||||||
|     CFileUpload: typeof import('./src/ui/c-file-upload/c-file-upload.vue')['default'] |     CFileUpload: typeof import('./src/ui/c-file-upload/c-file-upload.vue')['default'] | ||||||
|     'CFileUpload.demo': typeof import('./src/ui/c-file-upload/c-file-upload.demo.vue')['default'] |     'CFileUpload.demo': typeof import('./src/ui/c-file-upload/c-file-upload.demo.vue')['default'] | ||||||
|     ChmodCalculator: typeof import('./src/tools/chmod-calculator/chmod-calculator.vue')['default'] |     ChmodCalculator: typeof import('./src/tools/chmod-calculator/chmod-calculator.vue')['default'] | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ import type { | |||||||
| } from 'sshpk'; | } from 'sshpk'; | ||||||
| import { Base64 } from 'js-base64'; | import { Base64 } from 'js-base64'; | ||||||
| import * as openpgp from 'openpgp'; | import * as openpgp from 'openpgp'; | ||||||
|  | import * as forge from 'node-forge'; | ||||||
| import { useDownloadFileFromBase64 } from '@/composable/downloadBase64'; | import { useDownloadFileFromBase64 } from '@/composable/downloadBase64'; | ||||||
| 
 | 
 | ||||||
| function buf2Hex(buffer: ArrayBuffer) { // buffer is an ArrayBuffer | function buf2Hex(buffer: ArrayBuffer) { // buffer is an ArrayBuffer | ||||||
| @ -254,6 +255,67 @@ const parsedSections = computedAsync<LabelValue[]>(async () => { | |||||||
|       ] as LabelValue[]; |       ] as LabelValue[]; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     const csr = canParse(inputKeyOrCertificateValue, (value) => { | ||||||
|  |       return forge.pki.certificationRequestFromPem(value.toString(), true, false); | ||||||
|  |     }) as forge.pki.Certificate; | ||||||
|  |     if (csr) { | ||||||
|  |       return [ | ||||||
|  |         { | ||||||
|  |           label: 'Type: ', | ||||||
|  |           value: 'Certificate Signing Request', | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Subject: ', | ||||||
|  |           value: csr.subject.attributes.map(a => JSON.stringify(a, null, 2)).join('\n'), | ||||||
|  |           multiline: true, | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Issuer: ', | ||||||
|  |           value: csr.issuer?.toString(), | ||||||
|  |           multiline: true, | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Validity: ', | ||||||
|  |           value: JSON.stringify(csr.validity, null, 2), | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Signature: ', | ||||||
|  |           value: csr.signature, | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Signature Oid: ', | ||||||
|  |           value: csr.signatureOid?.toString(), | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Signature parameters: ', | ||||||
|  |           value: JSON.stringify(csr.signatureParameters, null, 2), | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Signing info: ', | ||||||
|  |           value: JSON.stringify(csr.siginfo, null, 2), | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Serial: ', | ||||||
|  |           value: csr.serialNumber?.toString(), | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Extensions: ', | ||||||
|  |           value: JSON.stringify(csr.extensions, null, 2), | ||||||
|  |           multiline: true, | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Public Key: ', | ||||||
|  |           value: onErrorReturnErrorMessage(() => forge.pki.publicKeyToPem(csr.publicKey)), | ||||||
|  |           multiline: true, | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           label: 'Public Key Fingerprint:', | ||||||
|  |           value: onErrorReturnErrorMessage(() => forge.pki.getPublicKeyFingerprint(csr.publicKey)?.toHex()), | ||||||
|  |           multiline: true, | ||||||
|  |         }, | ||||||
|  |       ] as LabelValue[]; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     const fingerprint = canParse(inputKeyOrCertificateValue, value => parseFingerprint(value.toString())) as Fingerprint; |     const fingerprint = canParse(inputKeyOrCertificateValue, value => parseFingerprint(value.toString())) as Fingerprint; | ||||||
|     if (fingerprint) { |     if (fingerprint) { | ||||||
|       return [ |       return [ | ||||||
| @ -280,11 +342,11 @@ const parsedSections = computedAsync<LabelValue[]>(async () => { | |||||||
|           value: 'PGP Private Key', |           value: 'PGP Private Key', | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           label: ': ', |           label: 'Creation Time: ', | ||||||
|           value: pgpPrivateKey.getCreationTime().toString(), |           value: pgpPrivateKey.getCreationTime().toString(), | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           label: ': ', |           label: 'Expiration Time: ', | ||||||
|           value: (await pgpPrivateKey.getExpirationTime())?.toString() || '', |           value: (await pgpPrivateKey.getExpirationTime())?.toString() || '', | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
| @ -301,7 +363,7 @@ const parsedSections = computedAsync<LabelValue[]>(async () => { | |||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           label: 'Key ID(s): ', |           label: 'Key ID(s): ', | ||||||
|           value: pgpPrivateKey.getKeyIDs().map(k => k.toString()).join(' ; '), |           value: pgpPrivateKey.getKeyIDs().map(k => k.toHex()).join(' ; '), | ||||||
|         }, |         }, | ||||||
|       ] as LabelValue[]; |       ] as LabelValue[]; | ||||||
|     } |     } | ||||||
| @ -314,11 +376,11 @@ const parsedSections = computedAsync<LabelValue[]>(async () => { | |||||||
|           value: 'PGP Public Key', |           value: 'PGP Public Key', | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           label: ': ', |           label: 'Creation Time: ', | ||||||
|           value: pgpPublicKey.getCreationTime().toString(), |           value: pgpPublicKey.getCreationTime().toString(), | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           label: ': ', |           label: 'Expiration Time: ', | ||||||
|           value: (await pgpPublicKey.getExpirationTime())?.toString() || '', |           value: (await pgpPublicKey.getExpirationTime())?.toString() || '', | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
| @ -335,7 +397,7 @@ const parsedSections = computedAsync<LabelValue[]>(async () => { | |||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           label: 'Key ID(s): ', |           label: 'Key ID(s): ', | ||||||
|           value: pgpPublicKey.getKeyIDs().map(k => k.toString()).join(' ; '), |           value: pgpPublicKey.getKeyIDs().map(k => k.toHex()).join(' ; '), | ||||||
|         }, |         }, | ||||||
|       ] as LabelValue[]; |       ] as LabelValue[]; | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user