-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3822c6c
commit 843e652
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |