Begin frontend for blinded indices

This commit is contained in:
Tuan Dang
2023-04-15 17:39:30 +03:00
parent fcb677d990
commit d9afe90885
11 changed files with 186 additions and 29 deletions
+35 -16
View File
@@ -4,6 +4,8 @@ import {
Secret
} from '../../models';
import crypto from 'crypto';
import { SecretService } from '../../services';
// TODO: modularize argon2id
import * as argon2 from 'argon2';
@@ -50,30 +52,47 @@ export const createSecret = async (req: Request, res: Response) => {
workspaceId,
environment,
value,
type
type,
secretKeyCiphertext,
secretKeyIV,
secretKeyTag,
secretValueCiphertext,
secretValueIV,
secretValueTag
} = req.body;
// use workspace salt
const randomBytes = crypto.randomBytes(16);
const secretBlindIndex = await SecretService.createSecretBlindIndex({
secretName,
workspaceId: new Types.ObjectId(workspaceId)
});
// generate blind index
// TODO 1: abstract away into create blind index function
// TODO 2: create a get blind index function
const secretBlindIndex = (await argon2.hash(secretName, {
type: argon2.argon2id,
salt: randomBytes,
saltLength: 16, // default 16 bytes
memoryCost: 65536, // default pool of 64 MiB per thread.
hashLength: 32,
parallelism: 1,
raw: true
})).toString('base64');
// // use workspace salt
// const randomBytes = crypto.randomBytes(16);
// // generate blind index
// // TODO 1: abstract away into create blind index function
// // TODO 2: create a get blind index function
// const secretBlindIndex = (await argon2.hash(secretName, {
// type: argon2.argon2id,
// salt: randomBytes,
// saltLength: 16, // default 16 bytes
// memoryCost: 65536, // default pool of 64 MiB per thread.
// hashLength: 32,
// parallelism: 1,
// raw: true
// })).toString('base64');
// const secret = await new Secret({
// workspace: new Types.ObjectId(workspaceId),
// environment,
// type,
// secretBlindIndex
// secretBlindIndex,
// secretKeyCiphertext,
// secretKeyIV,
// secretKeyTag,
// secretValueCiphertext,
// secretValueIV,
// secretValueTag
// }).save();
return res.status(200).send({