cyberchef/src/core/operations/GenerateEMVMAC.mjs

53 lines
2.8 KiB
JavaScript

/**
* @license Apache-2.0
* @author Jacob Marks [https://jacobmarks.com]
*/
import Operation from "../Operation.mjs";
import { generateEmvMac } from "../lib/EmvMac.mjs";
/**
* Generate EMV MAC operation.
*/
class GenerateEMVMAC extends Operation {
/**
* GenerateEMVMAC constructor.
*/
constructor() {
super();
this.name = "Generate EMV MAC";
this.module = "Payment";
this.description = "Paste the issuer-script or EMV command payload into the input field as hex and generate an EMV MAC.<br><br><b>Input:</b> message data as hex.<br><b>Arguments:</b> provide the already-derived EMV session integrity key and choose how many leftmost MAC bytes to return.<br><br><b>Validation:</b> Partially verified. This implements a retail-MAC style EMV helper with a supplied session key, not full EMV session derivation or brand-specific issuer processing.<br><br><b>Key context:</b> In a full issuer implementation, the session integrity key used here corresponds to the secure-messaging integrity key (distinct from the confidentiality key used to encrypt data and the PIN encryption key used for PIN blocks). This operation accepts any key you supply and does not enforce that separation.<br><br><b>Security:</b> Clear session keys in the recipe are test-use only.";
this.inlineHelp = "<strong>Input:</strong> issuer-script message data as hex.<br><strong>Args:</strong> provide the derived EMV session integrity key.<br><strong>Validation:</strong> supplied-key EMV MAC helper, not full EMV derivation.";
this.testDataSamples = [
{
name: "EMV MAC sample",
input: "8424000008999E57FD0F47CACE0007",
args: ["0123456789ABCDEFFEDCBA9876543210", 8, false]
}
];
this.infoURL = "https://en.wikipedia.org/wiki/EMV";
this.inputType = "string";
this.outputType = "string";
this.args = [
{ name: "Session integrity key (hex)", type: "string", value: "", comment: "Provide the already-derived EMV integrity session key in hex. This op does not derive EMV keys for you." },
{ name: "Output bytes", type: "number", value: 8, min: 1, max: 8, comment: "Number of leftmost MAC bytes to return. EMV issuer scripts commonly use 8 bytes." },
{ name: "Output as JSON", type: "boolean", value: false, comment: "When enabled, returns the issuer-script input and full retail-MAC details." },
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [sessionKeyHex, outputBytes, outputJson] = args;
const result = generateEmvMac(input, sessionKeyHex, outputBytes);
return outputJson ? JSON.stringify(result, null, 4) : result.macHex;
}
}
export default GenerateEMVMAC;