mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 22:51:53 +00:00
Convert TS to JS
This commit is contained in:
+33
-27
@@ -1,22 +1,30 @@
|
||||
import getSecrets from "~/pages/api/files/GetSecrets";
|
||||
import getSecrets from '~/pages/api/files/GetSecrets';
|
||||
|
||||
import { envMapping } from "../../../public/data/frequentConstants";
|
||||
import guidGenerator from "../randomId";
|
||||
import { envMapping } from '../../../public/data/frequentConstants';
|
||||
import guidGenerator from '../randomId';
|
||||
|
||||
const {
|
||||
decryptAssymmetric,
|
||||
decryptSymmetric,
|
||||
} = require("../cryptography/crypto");
|
||||
const nacl = require("tweetnacl");
|
||||
nacl.util = require("tweetnacl-util");
|
||||
decryptSymmetric
|
||||
} = require('../cryptography/crypto');
|
||||
const nacl = require('tweetnacl');
|
||||
nacl.util = require('tweetnacl-util');
|
||||
|
||||
interface Props {
|
||||
env: keyof typeof envMapping;
|
||||
setFileState: any;
|
||||
setIsKeyAvailable: any;
|
||||
setData: any;
|
||||
workspaceId: string;
|
||||
}
|
||||
|
||||
const getSecretsForProject = async ({
|
||||
env,
|
||||
setFileState,
|
||||
setIsKeyAvailable,
|
||||
setData,
|
||||
workspaceId,
|
||||
}) => {
|
||||
workspaceId
|
||||
}: Props) => {
|
||||
try {
|
||||
let file;
|
||||
try {
|
||||
@@ -24,44 +32,42 @@ const getSecretsForProject = async ({
|
||||
|
||||
setFileState(file);
|
||||
} catch (error) {
|
||||
console.log("ERROR: Not able to access the latest file");
|
||||
console.log('ERROR: Not able to access the latest file');
|
||||
}
|
||||
// This is called isKeyAvilable but what it really means is if a person is able to create new key pairs
|
||||
setIsKeyAvailable(
|
||||
!file.key ? (file.secrets.length == 0 ? true : false) : true
|
||||
);
|
||||
setIsKeyAvailable(!file.key ? file.secrets.length == 0 : true);
|
||||
|
||||
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY");
|
||||
const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY');
|
||||
|
||||
let tempFileState = [];
|
||||
const tempFileState: { key: string; value: string; type: string }[] = [];
|
||||
if (file.key) {
|
||||
// assymmetrically decrypt symmetric key with local private key
|
||||
const key = decryptAssymmetric({
|
||||
ciphertext: file.key.encryptedKey,
|
||||
nonce: file.key.nonce,
|
||||
publicKey: file.key.sender.publicKey,
|
||||
privateKey: PRIVATE_KEY,
|
||||
privateKey: PRIVATE_KEY
|
||||
});
|
||||
|
||||
file.secrets.map((secretPair) => {
|
||||
file.secrets.map((secretPair: any) => {
|
||||
// decrypt .env file with symmetric key
|
||||
const plainTextKey = decryptSymmetric({
|
||||
ciphertext: secretPair.secretKey.ciphertext,
|
||||
iv: secretPair.secretKey.iv,
|
||||
tag: secretPair.secretKey.tag,
|
||||
key,
|
||||
key
|
||||
});
|
||||
|
||||
const plainTextValue = decryptSymmetric({
|
||||
ciphertext: secretPair.secretValue.ciphertext,
|
||||
iv: secretPair.secretValue.iv,
|
||||
tag: secretPair.secretValue.tag,
|
||||
key,
|
||||
key
|
||||
});
|
||||
tempFileState.push({
|
||||
key: plainTextKey,
|
||||
value: plainTextValue,
|
||||
type: secretPair.type,
|
||||
type: secretPair.type
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -71,9 +77,9 @@ const getSecretsForProject = async ({
|
||||
tempFileState.map((line, index) => [
|
||||
guidGenerator(),
|
||||
index,
|
||||
line["key"],
|
||||
line["value"],
|
||||
line["type"],
|
||||
line['key'],
|
||||
line['value'],
|
||||
line['type']
|
||||
])
|
||||
// .sort((a, b) =>
|
||||
// sortMethod == "alphabetical"
|
||||
@@ -84,12 +90,12 @@ const getSecretsForProject = async ({
|
||||
return tempFileState.map((line, index) => [
|
||||
guidGenerator(),
|
||||
index,
|
||||
line["key"],
|
||||
line["value"],
|
||||
line["type"],
|
||||
line['key'],
|
||||
line['value'],
|
||||
line['type']
|
||||
]);
|
||||
} catch (error) {
|
||||
console.log("Something went wrong during accessing or decripting secrets.");
|
||||
console.log('Something went wrong during accessing or decripting secrets.');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
@@ -1,74 +0,0 @@
|
||||
import publicKeyInfical from "~/pages/api/auth/publicKeyInfisical";
|
||||
import changeHerokuConfigVars from "~/pages/api/integrations/ChangeHerokuConfigVars";
|
||||
|
||||
const crypto = require("crypto");
|
||||
const {
|
||||
encryptSymmetric,
|
||||
encryptAssymmetric,
|
||||
} = require("../cryptography/crypto");
|
||||
const nacl = require("tweetnacl");
|
||||
nacl.util = require("tweetnacl-util");
|
||||
|
||||
const pushKeysIntegration = async ({ obj, integrationId }) => {
|
||||
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY");
|
||||
|
||||
let randomBytes = crypto.randomBytes(16).toString("hex");
|
||||
|
||||
const secrets = Object.keys(obj).map((key) => {
|
||||
// encrypt key
|
||||
const {
|
||||
ciphertext: ciphertextKey,
|
||||
iv: ivKey,
|
||||
tag: tagKey,
|
||||
} = encryptSymmetric({
|
||||
plaintext: key,
|
||||
key: randomBytes,
|
||||
});
|
||||
|
||||
// encrypt value
|
||||
const {
|
||||
ciphertext: ciphertextValue,
|
||||
iv: ivValue,
|
||||
tag: tagValue,
|
||||
} = encryptSymmetric({
|
||||
plaintext: obj[key],
|
||||
key: randomBytes,
|
||||
});
|
||||
|
||||
const visibility = "shared";
|
||||
|
||||
return {
|
||||
ciphertextKey,
|
||||
ivKey,
|
||||
tagKey,
|
||||
hashKey: crypto.createHash("sha256").update(key).digest("hex"),
|
||||
ciphertextValue,
|
||||
ivValue,
|
||||
tagValue,
|
||||
hashValue: crypto.createHash("sha256").update(obj[key]).digest("hex"),
|
||||
type: visibility,
|
||||
};
|
||||
});
|
||||
|
||||
// obtain public keys of all receivers (i.e. members in workspace)
|
||||
let publicKeyInfisical = await publicKeyInfical();
|
||||
|
||||
publicKeyInfisical = (await publicKeyInfisical.json()).publicKey;
|
||||
|
||||
// assymmetrically encrypt key with each receiver public keys
|
||||
|
||||
const { ciphertext, nonce } = encryptAssymmetric({
|
||||
plaintext: randomBytes,
|
||||
publicKey: publicKeyInfisical,
|
||||
privateKey: PRIVATE_KEY,
|
||||
});
|
||||
|
||||
const key = {
|
||||
encryptedKey: ciphertext,
|
||||
nonce,
|
||||
};
|
||||
|
||||
changeHerokuConfigVars({ integrationId, key, secrets });
|
||||
};
|
||||
|
||||
export default pushKeysIntegration;
|
||||
@@ -0,0 +1,79 @@
|
||||
import publicKeyInfical from '~/pages/api/auth/publicKeyInfisical';
|
||||
import changeHerokuConfigVars from '~/pages/api/integrations/ChangeHerokuConfigVars';
|
||||
|
||||
const crypto = require('crypto');
|
||||
const {
|
||||
encryptSymmetric,
|
||||
encryptAssymmetric
|
||||
} = require('../cryptography/crypto');
|
||||
const nacl = require('tweetnacl');
|
||||
nacl.util = require('tweetnacl-util');
|
||||
|
||||
interface Props {
|
||||
obj: Record<string, string>;
|
||||
integrationId: string;
|
||||
}
|
||||
|
||||
const pushKeysIntegration = async ({ obj, integrationId }: Props) => {
|
||||
const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY');
|
||||
|
||||
const randomBytes = crypto.randomBytes(16).toString('hex');
|
||||
|
||||
const secrets = Object.keys(obj).map((key) => {
|
||||
// encrypt key
|
||||
const {
|
||||
ciphertext: ciphertextKey,
|
||||
iv: ivKey,
|
||||
tag: tagKey
|
||||
} = encryptSymmetric({
|
||||
plaintext: key,
|
||||
key: randomBytes
|
||||
});
|
||||
|
||||
// encrypt value
|
||||
const {
|
||||
ciphertext: ciphertextValue,
|
||||
iv: ivValue,
|
||||
tag: tagValue
|
||||
} = encryptSymmetric({
|
||||
plaintext: obj[key],
|
||||
key: randomBytes
|
||||
});
|
||||
|
||||
const visibility = 'shared';
|
||||
|
||||
return {
|
||||
ciphertextKey,
|
||||
ivKey,
|
||||
tagKey,
|
||||
hashKey: crypto.createHash('sha256').update(key).digest('hex'),
|
||||
ciphertextValue,
|
||||
ivValue,
|
||||
tagValue,
|
||||
hashValue: crypto.createHash('sha256').update(obj[key]).digest('hex'),
|
||||
type: visibility
|
||||
};
|
||||
});
|
||||
|
||||
// obtain public keys of all receivers (i.e. members in workspace)
|
||||
const publicKeyInfisical = await publicKeyInfical();
|
||||
|
||||
const publicKey = (await publicKeyInfisical.json()).publicKey;
|
||||
|
||||
// assymmetrically encrypt key with each receiver public keys
|
||||
|
||||
const { ciphertext, nonce } = encryptAssymmetric({
|
||||
plaintext: randomBytes,
|
||||
publicKey,
|
||||
privateKey: PRIVATE_KEY
|
||||
});
|
||||
|
||||
const key = {
|
||||
encryptedKey: ciphertext,
|
||||
nonce
|
||||
};
|
||||
|
||||
changeHerokuConfigVars({ integrationId, key, secrets });
|
||||
};
|
||||
|
||||
export default pushKeysIntegration;
|
||||
Reference in New Issue
Block a user