Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Parse CSR" #381

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"ops": [
"Parse X.509 certificate",
"Parse ASN.1 hex string",
"Parse CSR",
"PEM to Hex",
"Hex to PEM",
"Hex to Object Identifier",
Expand Down
56 changes: 56 additions & 0 deletions src/core/operations/ParseCSR.mjs
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this map return benefit from some formatting? Rather than having all subjectAltNames being listed with no separator.

})}`;
}

}

export default ParseCSR;