Skip to content

Commit

Permalink
New operation: Generate SSHA Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
git-commit-amen committed Nov 5, 2024
1 parent 3822c6c commit 843e652
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@
"CRC-8 Checksum",
"CRC-16 Checksum",
"CRC-32 Checksum",
"TCP/IP Checksum"
"TCP/IP Checksum",
"Generate SSHA Hash"
]
},
{
Expand Down
46 changes: 46 additions & 0 deletions src/core/operations/GenerateSSHAHash.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @author git-commit-amen [[email protected]]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/

import Operation from "../Operation.mjs";
import CryptoJS from "crypto-js";

/**
* Generate SSHA Hash operation
*/
class GenerateSSHAHash extends Operation {

/**
* GenerateSSHAHash constructor
*/
constructor() {
super();

this.name = "Generate SSHA Hash";
this.module = "Crypto";
this.description = "Generates an RFC 2307-compliant, cryptographically-secure SSHA (Salted SHA1) password hash - commonly used for storing passwords in systems such as OpenLDAP.";
this.infoURL = "https://www.openldap.org/faq/data/cache/347.html";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}

/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
if (!input) return "";

const salt = CryptoJS.lib.WordArray.random(128/8).toString().substr(0, 4);
const hash = CryptoJS.SHA1(input + salt);
const result = CryptoJS.enc.Latin1.parse(hash.toString(CryptoJS.enc.Latin1) + salt).toString(CryptoJS.enc.Base64);
return `{SSHA}${result}`;
}

}

export default GenerateSSHAHash;

0 comments on commit 843e652

Please sign in to comment.