Skip to content

Commit

Permalink
have "Parse X.509 certificate" emit user-friendly message on certific…
Browse files Browse the repository at this point in the history
…ate load error
  • Loading branch information
mikecat committed Oct 29, 2022
1 parent ed8bd34 commit 5a507aa
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/core/operations/ParseX509Certificate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,29 @@ class ParseX509Certificate extends Operation {
const cert = new r.X509(),
inputFormat = args[0];

switch (inputFormat) {
case "DER Hex":
input = input.replace(/\s/g, "");
cert.readCertHex(input);
break;
case "PEM":
cert.readCertPEM(input);
break;
case "Base64":
cert.readCertHex(toHex(fromBase64(input, null, "byteArray"), ""));
break;
case "Raw":
cert.readCertHex(toHex(Utils.strToByteArray(input), ""));
break;
default:
throw "Undefined input format";
let undefinedInputFormat = false;
try {
switch (inputFormat) {
case "DER Hex":
input = input.replace(/\s/g, "");
cert.readCertHex(input);
break;
case "PEM":
cert.readCertPEM(input);
break;
case "Base64":
cert.readCertHex(toHex(fromBase64(input, null, "byteArray"), ""));
break;
case "Raw":
cert.readCertHex(toHex(Utils.strToByteArray(input), ""));
break;
default:
undefinedInputFormat = true;
}
} catch (e) {
throw "Certificate load error (non-certificate input?)";
}
if (undefinedInputFormat) throw "Undefined input format";

const sn = cert.getSerialNumberHex(),
issuer = cert.getIssuer(),
Expand Down

0 comments on commit 5a507aa

Please sign in to comment.