mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-08 23:35:01 -04:00
Create ParseCSR.mjs
This commit is contained in:
parent
ec9dfd2918
commit
ea1a1f00d0
1 changed files with 56 additions and 0 deletions
56
src/core/operations/ParseCSR.mjs
Normal file
56
src/core/operations/ParseCSR.mjs
Normal file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* @author arnydo [arnydo@protonmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import forge from "node-forge/dist/forge.min.js";
|
||||
|
||||
/**
|
||||
* ParseCSR operation
|
||||
*/
|
||||
class ParseCSR extends Operation {
|
||||
|
||||
/**
|
||||
* ParseCSR constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Parse CSR";
|
||||
this.module = "PublicKey";
|
||||
this.description = "Parses a Base64 encoded Certificate Signing Request (CSR).<br><br>In public key infrastructure (PKI) systems, a certificate signing request (also CSR or certification request) is a message sent from an applicant to a certificate authority in order to apply for a digital identity certificate. It usually contains the public key for which the certificate should be issued, identifying information (such as a domain name) and integrity protection (e.g., a digital signature). The most common format for CSRs is the PKCS #10 specification and another is the Signed Public Key and Challenge SPKAC format generated by some web browsers.<br><br>This operation displays the contents of a certificate signing request in a human readable format, similar to the openssl command line tool.";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/Certificate_signing_request";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input) {
|
||||
if (!input.length) {
|
||||
return "No input";
|
||||
}
|
||||
const csr = forge.pki.certificationRequestFromPem(input);
|
||||
const extInfo = csr.getAttribute({ name: "extensionRequest" }).extensions;
|
||||
const subjectAltNames = extInfo[0].altNames.map(function(name){
|
||||
return name.value;
|
||||
});
|
||||
return `CommonName: ${csr.subject.getField("CN").value}
|
||||
Locality: ${csr.subject.getField("L").value}
|
||||
State: ${csr.subject.getField("ST").value}
|
||||
Country: ${csr.subject.getField("C").value}
|
||||
EmailAddress: ${csr.subject.getField("E").value}
|
||||
Subject Alternative Names: ${subjectAltNames.map(function (name) {
|
||||
return name;
|
||||
})}`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ParseCSR;
|
Loading…
Add table
Add a link
Reference in a new issue