-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve self-hosted licence generation (#467)
- Loading branch information
1 parent
41f75fb
commit 50f4e1a
Showing
13 changed files
with
78 additions
and
46 deletions.
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,2 @@ | ||
#!/usr/bin/env sh | ||
./node_modules/.bin/ts-node --esm src/hardcoded.ts $1 $2 |
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
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
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,31 @@ | ||
import bcryptjs from 'bcryptjs'; | ||
import crypto from 'crypto-js'; | ||
|
||
const aes = crypto.AES; | ||
const stringify = crypto.enc.Utf8.stringify; | ||
const { compare, genSalt, hash } = bcryptjs; | ||
|
||
export async function hashPassword(clearTextPassword: string): Promise<string> { | ||
const salt = await genSalt(); | ||
const hashedPassword = await hash(clearTextPassword, salt); | ||
return hashedPassword; | ||
} | ||
|
||
export async function comparePassword( | ||
clearTextPassword: string, | ||
hashedPassword: string | ||
): Promise<boolean> { | ||
const match = await compare(clearTextPassword, hashedPassword); | ||
return match; | ||
} | ||
|
||
export function encrypt(clear: string, key: string): string { | ||
const encrypted = aes.encrypt(clear, key).toString(); | ||
return encrypted; | ||
} | ||
|
||
export function decrypt(encrypted: string, key: string): string { | ||
const bytes = aes.decrypt(encrypted, key); | ||
const clear = stringify(bytes); | ||
return clear; | ||
} |
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 |
---|---|---|
@@ -1,11 +1,33 @@ | ||
import { encrypt, hashPassword } from './utils.js'; | ||
import { encrypt, hashPassword } from './encryption.js'; | ||
import { v4 as uuid } from 'uuid'; | ||
import chalk from 'chalk-template'; | ||
|
||
if (!process.argv[2]) { | ||
console.log( | ||
chalk`No company name provided. {red Please provide the company name as the first argument}.` | ||
); | ||
process.exit(1); | ||
} | ||
|
||
const company = process.argv[2].trim(); | ||
const key = process.argv[3] ? process.argv[3].trim() : uuid(); | ||
|
||
buildHardcodedLicence(key, company); | ||
|
||
export async function buildHardcodedLicence( | ||
licenceKey: string, | ||
company: string | ||
): Promise<void> { | ||
console.log('Building hardcoded licence for: ', licenceKey); | ||
console.log( | ||
chalk`Building hardcoded licence for company: {yellow ${company}}` | ||
); | ||
console.log(chalk`Licence key to communicate to them: {yellow ${key}}`); | ||
const hash = await hashPassword(licenceKey); | ||
console.log('Hash: ', hash); | ||
console.log('Encrypted company name: ', encrypt(company, licenceKey)); | ||
const encryptedOwner = encrypt(company, licenceKey); | ||
const obj = { | ||
hash, | ||
encryptedOwner, | ||
}; | ||
console.log('Copy the following object to the hardcodedLicences array:'); | ||
console.log(chalk`{red ${JSON.stringify(obj, null, 2)}}`); | ||
} |
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
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