-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify frontend to be compatible with full-loop for bot-based integra…
…tions
- Loading branch information
1 parent
436f408
commit c2eaea2
Showing
13 changed files
with
411 additions
and
156 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
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,91 @@ | ||
import { Fragment } from "react"; | ||
import { Dialog, Transition } from "@headlessui/react"; | ||
import getLatestFileKey from "../../../pages/api/workspace/getLatestFileKey"; | ||
import setBotActiveStatus from "../../../pages/api/bot/setBotActiveStatus"; | ||
import { | ||
decryptAssymmetric, | ||
encryptAssymmetric | ||
} from "../../utilities/cryptography/crypto"; | ||
import Button from "../buttons/Button"; | ||
|
||
const ActivateBotDialog = ({ | ||
isOpen, | ||
closeModal, | ||
selectedIntegrationOption, | ||
handleBotActivate, | ||
handleIntegrationOption | ||
}) => { | ||
|
||
const submit = async () => { | ||
try { | ||
// 1. activate bot | ||
await handleBotActivate(); | ||
|
||
// 2. start integration | ||
await handleIntegrationOption({ | ||
integrationOption: selectedIntegrationOption | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
|
||
closeModal(); | ||
} | ||
|
||
return ( | ||
<div> | ||
<Transition appear show={isOpen} as={Fragment}> | ||
<Dialog as="div" className="relative z-10" onClose={closeModal}> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
<div className="fixed inset-0 bg-black bg-opacity-70" /> | ||
</Transition.Child> | ||
<div className="fixed inset-0 overflow-y-auto"> | ||
<div className="flex min-h-full items-center justify-center p-4 text-center"> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0 scale-95" | ||
enterTo="opacity-100 scale-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100 scale-100" | ||
leaveTo="opacity-0 scale-95" | ||
> | ||
<Dialog.Panel className="w-full max-w-md transform overflow-hidden rounded-md bg-bunker-800 border border-gray-700 p-6 text-left align-middle shadow-xl transition-all"> | ||
<Dialog.Title | ||
as="h3" | ||
className="text-lg font-medium leading-6 text-gray-400" | ||
> | ||
Grant Infisical access to your secrets | ||
</Dialog.Title> | ||
<div className="mt-2 mb-2"> | ||
<p className="text-sm text-gray-500"> | ||
Enabling platform integrations lets Infisical decrypt your secrets so they can be forwarded to the platforms. | ||
</p> | ||
</div> | ||
<div className="mt-6 max-w-max"> | ||
<Button | ||
onButtonPressed={submit} | ||
color="mineshaft" | ||
text="Grant access" | ||
size="md" | ||
/> | ||
</div> | ||
</Dialog.Panel> | ||
</Transition.Child> | ||
</div> | ||
</div> | ||
</Dialog> | ||
</Transition> | ||
</div> | ||
); | ||
} | ||
|
||
export default ActivateBotDialog; |
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
74 changes: 74 additions & 0 deletions
74
frontend/components/utilities/secrets/pushKeysIntegration.js
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,74 @@ | ||
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; |
Oops, something went wrong.