Skip to content

Commit

Permalink
Merge pull request #343 from Infisical/mfa
Browse files Browse the repository at this point in the history
MFA
  • Loading branch information
dangtony98 authored Feb 21, 2023
2 parents 0b356e0 + baaa924 commit c38ccdb
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 deletions.
3 changes: 0 additions & 3 deletions frontend/src/components/signup/UserInfoStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ export default function UserInfoStep({
SecurityClient.setToken(response.token);

saveTokenToLocalStorage({
protectedKey,
protectedKeyIV,
protectedKeyTag,
publicKey,
encryptedPrivateKey,
iv: encryptedPrivateKeyIV,
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/utilities/attemptLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ const attemptLogin = async (
});

saveTokenToLocalStorage({
protectedKey,
protectedKeyIV,
protectedKeyTag,
publicKey,
encryptedPrivateKey,
iv,
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/utilities/attemptLoginMfa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ const attemptLoginMfa = async ({
});

saveTokenToLocalStorage({
protectedKey,
protectedKeyIV,
protectedKeyTag,
publicKey,
encryptedPrivateKey,
iv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ const changePassword = async (
});

saveTokenToLocalStorage({
protectedKey,
protectedKeyIV,
protectedKeyTag,
encryptedPrivateKey,
iv: encryptedPrivateKeyIV,
tag: encryptedPrivateKeyTag
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/helpers/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ let privateKey;
return privateKey;
}

export { decryptPrivateKeyHelper };
export {
decryptPrivateKeyHelper
};
3 changes: 0 additions & 3 deletions frontend/src/pages/signupinvite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ export default function SignupInvite() {
SecurityClient.setToken(jwtToken);

saveTokenToLocalStorage({
protectedKey,
protectedKeyIV,
protectedKeyTag,
publicKey,
encryptedPrivateKey,
iv: encryptedPrivateKeyIV,
Expand Down
57 changes: 56 additions & 1 deletion frontend/src/services/KeyService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { decryptPrivateKeyHelper } from '@app/helpers/key';
import {
decryptAssymmetric,
encryptAssymmetric} from '@app/components/utilities/cryptography/crypto';
import {
decryptPrivateKeyHelper
} from '@app/helpers/key';

/**
* Class to handle key actions
* TODO: in future, all private key-related encryption operations
* must pass through this class
*/
class KeyService {
private static privateKey: string = '';

static setPrivateKey(privateKey: string) {
KeyService.privateKey = privateKey;
}

/** Return the user's decrypted private key
* @param {Object} obj
Expand Down Expand Up @@ -51,6 +63,49 @@ class KeyService {
protectedKeyTag
});
}

/**
* Return [plaintext] encrypted by the user's private key
* @param {Object} obj
* @param {String} obj.plaintext - plaintext to encrypt
*/
static encryptWithPrivateKey({
plaintext,
publicKey,
}: {
plaintext: string;
publicKey: string;
}) {
return encryptAssymmetric({
plaintext,
publicKey,
privateKey: KeyService.privateKey
});
}

/**
* Return [ciphertext] decrypted by the user's private key
* @param {Object} obj
* @param {String} obj.ciphertext - ciphertext to decrypt
* @param {String} obj.ciphertext - iv of ciphertext
* @param {String} obj.ciphertext - tag of ciphertext
*/
static decryptWithPrivateKey({
ciphertext,
nonce,
publicKey
}: {
ciphertext: string;
nonce: string;
publicKey: string;
}) {
return decryptAssymmetric({
ciphertext,
nonce,
publicKey,
privateKey: KeyService.privateKey
});
}
}

export default KeyService;
7 changes: 7 additions & 0 deletions frontend/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import KeyService from './KeyService';
import ProjectService from './ProjectService';

export {
KeyService,
ProjectService
}

0 comments on commit c38ccdb

Please sign in to comment.