Fix formatting and trailing whitespace
This commit is contained in:
parent
da59efa23a
commit
f784e45d86
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import OperationError from "../errors/OperationError.mjs";
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import { fromBase64 } from "../lib/Base64.mjs"
|
import { fromBase64 } from "../lib/Base64.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flask Session Decode operation
|
* Flask Session Decode operation
|
||||||
@ -17,9 +17,9 @@ class FlaskSessionDecode extends Operation {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.name = "Flask Session Decode";
|
this.name = "Flask Session Decode";
|
||||||
this.module = "Crypto";
|
this.module = "Crypto";
|
||||||
this.description = "Decodes the payload of a Flask session cookie (itsdangerous) into JSON.";
|
this.description = "Decodes the payload of a Flask session cookie (itsdangerous) into JSON.";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "JSON";
|
this.outputType = "JSON";
|
||||||
this.args = [];
|
this.args = [];
|
||||||
@ -34,7 +34,7 @@ class FlaskSessionDecode extends Operation {
|
|||||||
input = input.trim();
|
input = input.trim();
|
||||||
const parts = input.split(".");
|
const parts = input.split(".");
|
||||||
if (parts.length !== 3) {
|
if (parts.length !== 3) {
|
||||||
throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature");
|
throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature");
|
||||||
}
|
}
|
||||||
|
|
||||||
const payloadB64 = parts[0];
|
const payloadB64 = parts[0];
|
||||||
|
|||||||
@ -69,13 +69,13 @@ class FlaskSessionSign extends Operation {
|
|||||||
const view = new DataView(buffer);
|
const view = new DataView(buffer);
|
||||||
view.setInt32(0, currentTimeStamp, false);
|
view.setInt32(0, currentTimeStamp, false);
|
||||||
const bytes = new Uint8Array(buffer);
|
const bytes = new Uint8Array(buffer);
|
||||||
let binary = '';
|
let binary = "";
|
||||||
bytes.forEach(b => binary += String.fromCharCode(b));
|
bytes.forEach(b => binary += String.fromCharCode(b));
|
||||||
const timeB64 = toBase64(Utils.strToByteArray(binary));
|
const timeB64 = toBase64(Utils.strToByteArray(binary));
|
||||||
const time = timeB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
const time = timeB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
||||||
|
|
||||||
const data = Utils.convertToByteString(payload + "." + time, "utf8");
|
const data = Utils.convertToByteString(payload + "." + time, "utf8");
|
||||||
const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm));
|
const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm));
|
||||||
sign.update(data);
|
sign.update(data);
|
||||||
|
|
||||||
const signB64 = toBase64(sign.finalize());
|
const signB64 = toBase64(sign.finalize());
|
||||||
|
|||||||
@ -53,9 +53,9 @@ class FlaskSessionVerify extends Operation {
|
|||||||
run(input, args) {
|
run(input, args) {
|
||||||
|
|
||||||
if (!args[0].string) {
|
if (!args[0].string) {
|
||||||
throw new OperationError("Secret key required");
|
throw new OperationError("Secret key required");
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = Utils.convertToByteString(args[0].string, args[0].option);
|
const key = Utils.convertToByteString(args[0].string, args[0].option);
|
||||||
const salt = Utils.convertToByteString(args[1].string || "cookie-session", args[1].option);
|
const salt = Utils.convertToByteString(args[1].string || "cookie-session", args[1].option);
|
||||||
const algorithm = args[2] || "sha1";
|
const algorithm = args[2] || "sha1";
|
||||||
@ -65,7 +65,7 @@ class FlaskSessionVerify extends Operation {
|
|||||||
const parts = input.split(".");
|
const parts = input.split(".");
|
||||||
|
|
||||||
if (parts.length !== 3) {
|
if (parts.length !== 3) {
|
||||||
throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature");
|
throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature");
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = Utils.convertToByteString(parts[0] + "." + parts[1], "utf8");
|
const data = Utils.convertToByteString(parts[0] + "." + parts[1], "utf8");
|
||||||
@ -73,8 +73,8 @@ class FlaskSessionVerify extends Operation {
|
|||||||
|
|
||||||
const derivedKey = CryptoApi.getHmac(key, CryptoApi.getHasher(algorithm));
|
const derivedKey = CryptoApi.getHmac(key, CryptoApi.getHasher(algorithm));
|
||||||
derivedKey.update(salt);
|
derivedKey.update(salt);
|
||||||
|
|
||||||
const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm));
|
const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm));
|
||||||
sign.update(data);
|
sign.update(data);
|
||||||
|
|
||||||
const payloadB64 = parts[0];
|
const payloadB64 = parts[0];
|
||||||
@ -91,10 +91,10 @@ class FlaskSessionVerify extends Operation {
|
|||||||
const signB64 = toBase64(sign.finalize());
|
const signB64 = toBase64(sign.finalize());
|
||||||
const sign64 = signB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
const sign64 = signB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
||||||
|
|
||||||
if (sign64 !== parts[2]){
|
if (sign64 !== parts[2]) {
|
||||||
throw new OperationError("Invalid signature!");
|
throw new OperationError("Invalid signature!");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const decoded = JSON.parse(payloadJson);
|
const decoded = JSON.parse(payloadJson);
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -13,12 +13,12 @@ const validKey = "mysecretkey";
|
|||||||
const outputObject = {
|
const outputObject = {
|
||||||
user: "admin",
|
user: "admin",
|
||||||
role: "superuser",
|
role: "superuser",
|
||||||
}
|
};
|
||||||
|
|
||||||
const outputVerify = {
|
const outputVerify = {
|
||||||
valid: true,
|
valid: true,
|
||||||
payload: outputObject,
|
payload: outputObject,
|
||||||
}
|
};
|
||||||
|
|
||||||
TestRegister.addTests([
|
TestRegister.addTests([
|
||||||
{
|
{
|
||||||
@ -41,9 +41,9 @@ TestRegister.addTests([
|
|||||||
op: "Flask Session Verify",
|
op: "Flask Session Verify",
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
string: validKey,
|
string: validKey,
|
||||||
option: "UTF8"
|
option: "UTF8"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
string: "cookie-session",
|
string: "cookie-session",
|
||||||
option: "UTF8"
|
option: "UTF8"
|
||||||
@ -53,4 +53,4 @@ TestRegister.addTests([
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
])
|
]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user