Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit 47c70df

Browse files
committed
argon2 replaced with native crypto
1 parent 5474042 commit 47c70df

File tree

5 files changed

+25
-182
lines changed

5 files changed

+25
-182
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"@nestjs/core": "^8.0.6",
2727
"@nestjs/platform-express": "^8.0.6",
2828
"@nestjs/platform-ws": "^8.0.6",
29-
"argon2": "^0.28.2",
3029
"crypto-js": "^4.1.1",
3130
"faker": "^5.5.3",
3231
"get-port": "^5.1.1",

src/helpers/app-logs/dto/create-log-record.dto.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
LogOperationTypeEnum,
3-
OperationResultStatusEnum,
4-
} from '../../../enums';
1+
import { LogOperationTypeEnum, OperationResultStatusEnum } from '../../../enums';
52

63
export class CreateLogRecordDto {
74
table_name: string;
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as CryptoJS from 'crypto-js';
2-
import * as argon2 from 'argon2';
3-
import { Messages } from '../../text/messages';
2+
import * as crypto from 'crypto';
43

54
export class Encryptor {
65
public static encryptDataMasterPwd(data: string, masterPwd: string): string {
@@ -13,15 +12,22 @@ export class Encryptor {
1312
}
1413

1514
public static async hashPassword(password: string): Promise<string> {
16-
return await argon2.hash(password);
15+
return new Promise((resolve, reject) => {
16+
const salt = crypto.randomBytes(8).toString('hex');
17+
crypto.scrypt(password, salt, 64, (err, derivedKey) => {
18+
if (err) reject(err);
19+
resolve(salt + ':' + derivedKey.toString('hex'));
20+
});
21+
});
1722
}
1823

19-
public static async verifyPassword(hash: string, password: string): Promise<boolean> {
20-
try {
21-
return await argon2.verify(hash, password);
22-
} catch (err) {
23-
console.log(Messages.CORRUPTED_DATA);
24-
process.exit(0);
25-
}
24+
public static async verifyPassword(password: string, hash: string): Promise<boolean> {
25+
return new Promise((resolve, reject) => {
26+
const [salt, key] = hash.split(':');
27+
crypto.scrypt(password, salt, 64, (err, derivedKey) => {
28+
if (err) reject(err);
29+
resolve(key == derivedKey.toString('hex'));
30+
});
31+
});
2632
}
2733
}

src/shared/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class Config {
113113
encryptionPassword = CLIQuestionUtility.askConnectionPassword(
114114
Messages.INTRO_MESSAGES.ASK_ENCRYPTION_PASSWORD_MESSAGE,
115115
);
116-
if (!(await Encryptor.verifyPassword(appConfig.hash, encryptionPassword))) {
116+
if (!(await Encryptor.verifyPassword(encryptionPassword, appConfig.hash))) {
117117
console.log(Messages.CORRUPTED_DATA_OR_PASSWORD);
118118
if (i === 2) {
119119
console.log(Messages.INTRO_MESSAGES.APPLICATION_ATTEMPTS_QUIT);

0 commit comments

Comments
 (0)