mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
make the ECDSA JSON signature parsing more robust
also rename the format to "Raw JSON" as I will later introduce "JSON Web Signature"
This commit is contained in:
parent
7b54d9e873
commit
1fbc7e03f0
4 changed files with 70 additions and 19 deletions
|
@ -33,7 +33,7 @@ class ECDSAVerify extends Operation {
|
|||
"Auto",
|
||||
"ASN.1 HEX",
|
||||
"P1363 HEX",
|
||||
"JSON"
|
||||
"Raw JSON"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -74,11 +74,19 @@ class ECDSAVerify extends Operation {
|
|||
}
|
||||
|
||||
// detect input format
|
||||
let inputJson;
|
||||
if (inputFormat === "Auto") {
|
||||
if (input.substr(0, 2) === "30" && r.ASN1HEX.isASN1HEX(input)) {
|
||||
try {
|
||||
inputJson = JSON.parse(input);
|
||||
if (typeof(inputJson) === "object") {
|
||||
inputFormat = "Raw JSON";
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
if (inputFormat === "Auto") {
|
||||
if (input.substring(0, 2) === "30" && r.ASN1HEX.isASN1HEX(input)) {
|
||||
inputFormat = "ASN.1 HEX";
|
||||
} else if (input.indexOf("{") !== -1) {
|
||||
inputFormat = "JSON";
|
||||
} else {
|
||||
inputFormat = "P1363 HEX";
|
||||
}
|
||||
|
@ -93,8 +101,14 @@ class ECDSAVerify extends Operation {
|
|||
case "P1363 HEX":
|
||||
signatureASN1Hex = r.KJUR.crypto.ECDSA.concatSigToASN1Sig(input);
|
||||
break;
|
||||
case "JSON": {
|
||||
const inputJson = JSON.parse(input);
|
||||
case "Raw JSON": {
|
||||
if (!inputJson) inputJson = JSON.parse(input);
|
||||
if (!inputJson.r) {
|
||||
throw new OperationError('No "r" value in the signature JSON');
|
||||
}
|
||||
if (!inputJson.s) {
|
||||
throw new OperationError('No "s" value in the signature JSON');
|
||||
}
|
||||
signatureASN1Hex = r.KJUR.crypto.ECDSA.hexRSSigToASN1Sig(inputJson.r, inputJson.s);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue