From 7d289d518008e02c7e64a887485638f09b05c267 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Fri, 25 Nov 2022 17:51:28 -0500 Subject: [PATCH 1/3] rough imp, unable to debug further recursion --- cli/packages/models/error.go | 14 ++++ cli/packages/util/secrets.go | 73 ++++++++++++++++++ cli/packages/util/secrets_test.go | 122 ++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 cli/packages/models/error.go create mode 100644 cli/packages/util/secrets_test.go diff --git a/cli/packages/models/error.go b/cli/packages/models/error.go new file mode 100644 index 000000000..28e48d54d --- /dev/null +++ b/cli/packages/models/error.go @@ -0,0 +1,14 @@ +package models + +import log "github.com/sirupsen/logrus" + +// Custom error type so that we can give helpful messages in CLI +type Error struct { + Err error + DebugMessage string + FriendlyMessage string +} + +func (e *Error) printFriendlyMessage() { + log.Infoln(e.FriendlyMessage) +} diff --git a/cli/packages/util/secrets.go b/cli/packages/util/secrets.go index 475640713..d38ec5805 100644 --- a/cli/packages/util/secrets.go +++ b/cli/packages/util/secrets.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "errors" "fmt" + "regexp" "strings" "github.com/Infisical/infisical-merge/packages/models" @@ -205,3 +206,75 @@ func GetWorkSpacesFromAPI(userCreds models.UserCredentials) (workspaces []models return getWorkSpacesResponse.Workspaces, nil } + +func getExpandedEnvVariable(secrets []models.SingleEnvironmentVariable, variableWeAreLookingFor string, hashMapOfCompleteVariables map[string]string, hashMapOfSelfRefs map[string]string) string { + if value, found := hashMapOfCompleteVariables[variableWeAreLookingFor]; found { + return value + } + + for _, secret := range secrets { + if secret.Key == variableWeAreLookingFor { + regex := regexp.MustCompile(`\${([^\}]*)}`) + variablesToPopulate := regex.FindAllString(secret.Value, -1) + + // case: variable is a constant so return its value + if len(variablesToPopulate) == 0 { + return secret.Value + } + + fullyReplacedValue := secret.Value + fmt.Println("variablesToPopulate", variablesToPopulate) + for _, variableWithSign := range variablesToPopulate { + variableWithoutSign := strings.Trim(variableWithSign, "}") + variableWithoutSign = strings.Trim(variableWithoutSign, "${") + + // case: reference to self + if variableWithoutSign == secret.Key { + hashMapOfSelfRefs[variableWithoutSign] = variableWithoutSign + continue + } else { + var expandedVariableValue string + + if preComputedVariable, found := hashMapOfCompleteVariables[variableWithoutSign]; found { + fmt.Println("precompute for varable: ", variableWithoutSign) + expandedVariableValue = preComputedVariable + } else { + fmt.Println("compute for varable: ", variableWithoutSign) + expandedVariableValue = getExpandedEnvVariable(secrets, variableWithoutSign, hashMapOfCompleteVariables, hashMapOfSelfRefs) + hashMapOfCompleteVariables[variableWithoutSign] = expandedVariableValue + } + + // If after expanding all the vars above, is the current var a self ref? if so no replacement needed for it + if _, found := hashMapOfSelfRefs[variableWithoutSign]; found { + continue + } else { + fullyReplacedValue = strings.ReplaceAll(fullyReplacedValue, variableWithSign, expandedVariableValue) + } + } + + return fullyReplacedValue + } + } else { + continue + } + } + + return "${" + variableWeAreLookingFor + "}" +} + +func SubstituteSecrets(secrets []models.SingleEnvironmentVariable) []models.SingleEnvironmentVariable { + hashMapOfCompleteVariables := make(map[string]string) + hashMapOfSelfRefs := make(map[string]string) + expandedSecrets := []models.SingleEnvironmentVariable{} + for _, secret := range secrets { + expandedVariable := getExpandedEnvVariable(secrets, secret.Key, hashMapOfCompleteVariables, hashMapOfSelfRefs) + fmt.Println(secret.Key, "=", expandedVariable) + expandedSecrets = append(expandedSecrets, models.SingleEnvironmentVariable{ + Key: secret.Key, + Value: expandedVariable, + }) + + } + + return expandedSecrets +} diff --git a/cli/packages/util/secrets_test.go b/cli/packages/util/secrets_test.go new file mode 100644 index 000000000..02e0c0a83 --- /dev/null +++ b/cli/packages/util/secrets_test.go @@ -0,0 +1,122 @@ +package util + +import ( + "testing" + + "github.com/Infisical/infisical-merge/packages/models" +) + +// References to self should return the value unaltered +// func Test_SubstituteSecrets_When_ReferenceToSelf(t *testing.T) { + +// var tests = []struct { +// Key string +// Value string +// ExpectedValue string +// }{ +// {Key: "A", Value: "${A}", ExpectedValue: "${A}"}, +// {Key: "A", Value: "${A} ${A}", ExpectedValue: "${A} ${A}"}, +// {Key: "A", Value: "${A}${A}", ExpectedValue: "${A}${A}"}, +// } + +// for _, test := range tests { +// secret := models.SingleEnvironmentVariable{ +// Key: test.Key, +// Value: test.Value, +// } + +// secrets := []models.SingleEnvironmentVariable{secret} +// result := SubstituteSecrets(secrets) + +// if result[0].Value != test.ExpectedValue { +// t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) +// } + +// } +// } + +// func Test_SubstituteSecrets_When_ReferenceDoesNotExist(t *testing.T) { + +// var tests = []struct { +// Key string +// Value string +// ExpectedValue string +// }{ +// {Key: "A", Value: "${X}", ExpectedValue: "${X}"}, +// {Key: "A", Value: "${H}HELLO", ExpectedValue: "${H}HELLO"}, +// {Key: "A", Value: "${L}${S}", ExpectedValue: "${L}${S}"}, +// } + +// for _, test := range tests { +// secret := models.SingleEnvironmentVariable{ +// Key: test.Key, +// Value: test.Value, +// } + +// secrets := []models.SingleEnvironmentVariable{secret} +// result := SubstituteSecrets(secrets) + +// if result[0].Value != test.ExpectedValue { +// t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) +// } + +// } +// } + +func Test_SubstituteSecrets_When_ReferenceDoesNotExist_And_Self_Referencing(t *testing.T) { + + tests := []struct { + Key string + Value string + ExpectedValue string + }{ + { + Key: "A", + Value: "*${A}* ${X}", + ExpectedValue: "*${A}*", + }, + { + Key: "H", + Value: "${X} >>>", + ExpectedValue: "*${A}*", + }, + { + Key: "X", + Value: "DOMAIN", + ExpectedValue: "DOMAIN", + }, + { + Key: "P", + Value: "${X} === ${A} ${H}", + ExpectedValue: "DOMAIN", + }, + // { + // Key: "B", + // Value: "*${A}*TOKEN*${X}*", + // ExpectedValue: "*${A}*TOKEN*DOMAIN*", + // }, + // { + // Key: "C", + // Value: "*${A}* *${X}* *${B}* *${UNKNOWN}*", + // ExpectedValue: "*${A}* *DOMAIN* **${A}*TOKEN*DOMAIN** *${UNKNOWN}*", + // }, + // { + // Key: "W", + // Value: "*${W}* ${LOL $JK} *${C}* *${C}*", + // ExpectedValue: "*${W}* ${LOL $JK} **${A}* *DOMAIN* **${A}*TOKEN*DOMAIN** *${UNKNOWN}** **${A}* *DOMAIN* **${A}*TOKEN*DOMAIN** *${UNKNOWN}**", + // }, + } + + secrets := []models.SingleEnvironmentVariable{} + for _, test := range tests { + secrets = append(secrets, models.SingleEnvironmentVariable{Key: test.Key, Value: test.Value}) + } + + SubstituteSecrets(secrets) + + // if result[0].Value != test.ExpectedValue { + // t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) + // } + + // fmt.Println(result) +} From 746ded9a539b141273cfd678afeb8975631bbdce Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Sat, 26 Nov 2022 16:54:36 -0500 Subject: [PATCH 2/3] Add substitute flag for run --- cli/packages/cmd/run.go | 16 ++- cli/packages/util/secrets.go | 14 +-- cli/packages/util/secrets_test.go | 190 ++++++++++++++++++------------ 3 files changed, 135 insertions(+), 85 deletions(-) diff --git a/cli/packages/cmd/run.go b/cli/packages/cmd/run.go index 1c07f06c8..d9ed47a36 100644 --- a/cli/packages/cmd/run.go +++ b/cli/packages/cmd/run.go @@ -33,6 +33,13 @@ var runCmd = &cobra.Command{ return } + substitute, err := cmd.Flags().GetBool("substitute") + if err != nil { + log.Errorln("Unable to parse the substitute flag") + log.Debugln(err) + return + } + projectId, err := cmd.Flags().GetString("projectId") if err != nil { log.Errorln("Unable to parse the project id flag") @@ -82,7 +89,13 @@ var runCmd = &cobra.Command{ } } - execCmd(args[0], args[1:], envsFromApi) + if substitute { + substitutions := util.SubstituteSecrets(envsFromApi) + execCmd(args[0], args[1:], substitutions) + } else { + execCmd(args[0], args[1:], envsFromApi) + } + }, } @@ -90,6 +103,7 @@ func init() { rootCmd.AddCommand(runCmd) runCmd.Flags().StringP("env", "e", "dev", "Set the environment (dev, prod, etc.) from which your secrets should be pulled from") runCmd.Flags().String("projectId", "", "The project ID from which your secrets should be pulled from") + runCmd.Flags().Bool("substitute", true, "Parse shell variable substitutions in your secrets") } // Credit: inspired by AWS Valut diff --git a/cli/packages/util/secrets.go b/cli/packages/util/secrets.go index d38ec5805..5cf76d48e 100644 --- a/cli/packages/util/secrets.go +++ b/cli/packages/util/secrets.go @@ -222,8 +222,7 @@ func getExpandedEnvVariable(secrets []models.SingleEnvironmentVariable, variable return secret.Value } - fullyReplacedValue := secret.Value - fmt.Println("variablesToPopulate", variablesToPopulate) + valueToEdit := secret.Value for _, variableWithSign := range variablesToPopulate { variableWithoutSign := strings.Trim(variableWithSign, "}") variableWithoutSign = strings.Trim(variableWithoutSign, "${") @@ -236,10 +235,8 @@ func getExpandedEnvVariable(secrets []models.SingleEnvironmentVariable, variable var expandedVariableValue string if preComputedVariable, found := hashMapOfCompleteVariables[variableWithoutSign]; found { - fmt.Println("precompute for varable: ", variableWithoutSign) expandedVariableValue = preComputedVariable } else { - fmt.Println("compute for varable: ", variableWithoutSign) expandedVariableValue = getExpandedEnvVariable(secrets, variableWithoutSign, hashMapOfCompleteVariables, hashMapOfSelfRefs) hashMapOfCompleteVariables[variableWithoutSign] = expandedVariableValue } @@ -248,12 +245,13 @@ func getExpandedEnvVariable(secrets []models.SingleEnvironmentVariable, variable if _, found := hashMapOfSelfRefs[variableWithoutSign]; found { continue } else { - fullyReplacedValue = strings.ReplaceAll(fullyReplacedValue, variableWithSign, expandedVariableValue) + valueToEdit = strings.ReplaceAll(valueToEdit, variableWithSign, expandedVariableValue) } } - - return fullyReplacedValue } + + return valueToEdit + } else { continue } @@ -266,9 +264,9 @@ func SubstituteSecrets(secrets []models.SingleEnvironmentVariable) []models.Sing hashMapOfCompleteVariables := make(map[string]string) hashMapOfSelfRefs := make(map[string]string) expandedSecrets := []models.SingleEnvironmentVariable{} + for _, secret := range secrets { expandedVariable := getExpandedEnvVariable(secrets, secret.Key, hashMapOfCompleteVariables, hashMapOfSelfRefs) - fmt.Println(secret.Key, "=", expandedVariable) expandedSecrets = append(expandedSecrets, models.SingleEnvironmentVariable{ Key: secret.Key, Value: expandedVariable, diff --git a/cli/packages/util/secrets_test.go b/cli/packages/util/secrets_test.go index 02e0c0a83..513e4f7e3 100644 --- a/cli/packages/util/secrets_test.go +++ b/cli/packages/util/secrets_test.go @@ -7,61 +7,61 @@ import ( ) // References to self should return the value unaltered -// func Test_SubstituteSecrets_When_ReferenceToSelf(t *testing.T) { +func Test_SubstituteSecrets_When_ReferenceToSelf(t *testing.T) { -// var tests = []struct { -// Key string -// Value string -// ExpectedValue string -// }{ -// {Key: "A", Value: "${A}", ExpectedValue: "${A}"}, -// {Key: "A", Value: "${A} ${A}", ExpectedValue: "${A} ${A}"}, -// {Key: "A", Value: "${A}${A}", ExpectedValue: "${A}${A}"}, -// } + var tests = []struct { + Key string + Value string + ExpectedValue string + }{ + {Key: "A", Value: "${A}", ExpectedValue: "${A}"}, + {Key: "A", Value: "${A} ${A}", ExpectedValue: "${A} ${A}"}, + {Key: "A", Value: "${A}${A}", ExpectedValue: "${A}${A}"}, + } -// for _, test := range tests { -// secret := models.SingleEnvironmentVariable{ -// Key: test.Key, -// Value: test.Value, -// } + for _, test := range tests { + secret := models.SingleEnvironmentVariable{ + Key: test.Key, + Value: test.Value, + } -// secrets := []models.SingleEnvironmentVariable{secret} -// result := SubstituteSecrets(secrets) + secrets := []models.SingleEnvironmentVariable{secret} + result := SubstituteSecrets(secrets) -// if result[0].Value != test.ExpectedValue { -// t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) -// } + if result[0].Value != test.ExpectedValue { + t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) + } -// } -// } + } +} -// func Test_SubstituteSecrets_When_ReferenceDoesNotExist(t *testing.T) { +func Test_SubstituteSecrets_When_ReferenceDoesNotExist(t *testing.T) { -// var tests = []struct { -// Key string -// Value string -// ExpectedValue string -// }{ -// {Key: "A", Value: "${X}", ExpectedValue: "${X}"}, -// {Key: "A", Value: "${H}HELLO", ExpectedValue: "${H}HELLO"}, -// {Key: "A", Value: "${L}${S}", ExpectedValue: "${L}${S}"}, -// } + var tests = []struct { + Key string + Value string + ExpectedValue string + }{ + {Key: "A", Value: "${X}", ExpectedValue: "${X}"}, + {Key: "A", Value: "${H}HELLO", ExpectedValue: "${H}HELLO"}, + {Key: "A", Value: "${L}${S}", ExpectedValue: "${L}${S}"}, + } -// for _, test := range tests { -// secret := models.SingleEnvironmentVariable{ -// Key: test.Key, -// Value: test.Value, -// } + for _, test := range tests { + secret := models.SingleEnvironmentVariable{ + Key: test.Key, + Value: test.Value, + } -// secrets := []models.SingleEnvironmentVariable{secret} -// result := SubstituteSecrets(secrets) + secrets := []models.SingleEnvironmentVariable{secret} + result := SubstituteSecrets(secrets) -// if result[0].Value != test.ExpectedValue { -// t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) -// } + if result[0].Value != test.ExpectedValue { + t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) + } -// } -// } + } +} func Test_SubstituteSecrets_When_ReferenceDoesNotExist_And_Self_Referencing(t *testing.T) { @@ -71,14 +71,9 @@ func Test_SubstituteSecrets_When_ReferenceDoesNotExist_And_Self_Referencing(t *t ExpectedValue string }{ { - Key: "A", - Value: "*${A}* ${X}", - ExpectedValue: "*${A}*", - }, - { - Key: "H", - Value: "${X} >>>", - ExpectedValue: "*${A}*", + Key: "O", + Value: "${P} ==$$ ${X} ${UNKNOWN} ${A}", + ExpectedValue: "DOMAIN === ${A} DOMAIN >>> ==$$ DOMAIN ${UNKNOWN} ${A}", }, { Key: "X", @@ -86,25 +81,30 @@ func Test_SubstituteSecrets_When_ReferenceDoesNotExist_And_Self_Referencing(t *t ExpectedValue: "DOMAIN", }, { - Key: "P", - Value: "${X} === ${A} ${H}", - ExpectedValue: "DOMAIN", + Key: "A", + Value: "*${A}* ${X}", + ExpectedValue: "*${A}* DOMAIN", + }, + { + Key: "H", + Value: "${X} >>>", + ExpectedValue: "DOMAIN >>>", + }, + { + Key: "P", + Value: "DOMAIN === ${A} ${H}", + ExpectedValue: "DOMAIN === ${A} DOMAIN >>>", + }, + { + Key: "T", + Value: "${P} ==$$ ${X} ${UNKNOWN} ${A} ${P} ==$$ ${X} ${UNKNOWN} ${A}", + ExpectedValue: "DOMAIN === ${A} DOMAIN >>> ==$$ DOMAIN ${UNKNOWN} ${A} DOMAIN === ${A} DOMAIN >>> ==$$ DOMAIN ${UNKNOWN} ${A}", + }, + { + Key: "S", + Value: "${ SSS$$ ${HEY}", + ExpectedValue: "${ SSS$$ ${HEY}", }, - // { - // Key: "B", - // Value: "*${A}*TOKEN*${X}*", - // ExpectedValue: "*${A}*TOKEN*DOMAIN*", - // }, - // { - // Key: "C", - // Value: "*${A}* *${X}* *${B}* *${UNKNOWN}*", - // ExpectedValue: "*${A}* *DOMAIN* **${A}*TOKEN*DOMAIN** *${UNKNOWN}*", - // }, - // { - // Key: "W", - // Value: "*${W}* ${LOL $JK} *${C}* *${C}*", - // ExpectedValue: "*${W}* ${LOL $JK} **${A}* *DOMAIN* **${A}*TOKEN*DOMAIN** *${UNKNOWN}** **${A}* *DOMAIN* **${A}*TOKEN*DOMAIN** *${UNKNOWN}**", - // }, } secrets := []models.SingleEnvironmentVariable{} @@ -112,11 +112,49 @@ func Test_SubstituteSecrets_When_ReferenceDoesNotExist_And_Self_Referencing(t *t secrets = append(secrets, models.SingleEnvironmentVariable{Key: test.Key, Value: test.Value}) } - SubstituteSecrets(secrets) + results := SubstituteSecrets(secrets) - // if result[0].Value != test.ExpectedValue { - // t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) - // } - - // fmt.Println(result) + for index, expanded := range results { + if expanded.Value != tests[index].ExpectedValue { + t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected [%s] but got [%s] for input [%s]", tests[index].ExpectedValue, expanded.Value, tests[index].Value) + } + } +} + +func Test_SubstituteSecrets_When_No_SubstituteNeeded(t *testing.T) { + + tests := []struct { + Key string + Value string + ExpectedValue string + }{ + { + Key: "DOMAIN", + Value: "infisical.com", + ExpectedValue: "infisical.com", + }, + { + Key: "API_KEY", + Value: "hdgsvjshcgkdckhevdkd", + ExpectedValue: "hdgsvjshcgkdckhevdkd", + }, + { + Key: "ENV", + Value: "PROD", + ExpectedValue: "PROD", + }, + } + + secrets := []models.SingleEnvironmentVariable{} + for _, test := range tests { + secrets = append(secrets, models.SingleEnvironmentVariable{Key: test.Key, Value: test.Value}) + } + + results := SubstituteSecrets(secrets) + + for index, expanded := range results { + if expanded.Value != tests[index].ExpectedValue { + t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected [%s] but got [%s] for input [%s]", tests[index].ExpectedValue, expanded.Value, tests[index].Value) + } + } } From c1089497b7c0c48903ad53b3fe07eaf9804f217d Mon Sep 17 00:00:00 2001 From: Vladyslav Matsiiako Date: Sat, 26 Nov 2022 16:55:25 -0500 Subject: [PATCH 3/3] Update folder structure --- README.md | 2 +- .../basic/dialog/AddServiceTokenDialog.js | 2 +- frontend/components/basic/layout.js | 2 +- frontend/components/basic/table/UserTable.js | 2 +- frontend/components/billing/Card.js | 75 ------------------- .../components/navigation/NavBarDashboard.js | 4 +- frontend/components/utilities/attemptLogin.js | 4 +- .../cryptography}/aes-256-gcm.js | 0 .../{ => cryptography}/changePassword.js | 3 +- .../utilities/{ => cryptography}/crypto.js | 2 +- .../{ => cryptography}/issueBackupKey.js | 4 +- frontend/components/utilities/csp.js | 0 .../{ => secrets}/getSecretsForProject.js | 4 +- .../utilities/{ => secrets}/pushKeys.js | 2 +- .../{ => secrets}/pushKeysIntegration.js | 2 +- frontend/pages/dashboard/[id].js | 8 +- frontend/pages/integrations/[id].js | 4 +- frontend/pages/settings/personal/[id].js | 4 +- frontend/pages/signup.js | 4 +- frontend/pages/signupinvite.js | 4 +- frontend/pages/users/[id].js | 2 +- 21 files changed, 30 insertions(+), 104 deletions(-) delete mode 100644 frontend/components/billing/Card.js rename frontend/components/{ => utilities/cryptography}/aes-256-gcm.js (100%) rename frontend/components/utilities/{ => cryptography}/changePassword.js (95%) rename frontend/components/utilities/{ => cryptography}/crypto.js (98%) rename frontend/components/utilities/{ => cryptography}/issueBackupKey.js (96%) delete mode 100644 frontend/components/utilities/csp.js rename frontend/components/utilities/{ => secrets}/getSecretsForProject.js (96%) rename frontend/components/utilities/{ => secrets}/pushKeys.js (98%) rename frontend/components/utilities/{ => secrets}/pushKeysIntegration.js (95%) diff --git a/README.md b/README.md index 64e051ac5..761f6135a 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Not sure where to get started? [Book a free, non-pressure pairing sessions with - [GitHub Discussions](https://github.com/Infisical/infisical/discussions) for help with building and discussion. - [GitHub Issues](https://github.com/Infisical/infisical-cli/issues) for any bugs and errors you encounter using Infisical. -- [Community Slack](https://join.slack.com/t/infisical/shared_invite/zt-1dgg63ln8-G7PCNJdCymAT9YF3j1ewVA) for hanging out with the community and quick communication with the team. +- [Community Slack](https://join.slack.com/t/infisical-users/shared_invite/zt-1kdbk07ro-RtoyEt_9E~fyzGo_xQYP6g) for hanging out with the community and quick communication with the team. ## Status diff --git a/frontend/components/basic/dialog/AddServiceTokenDialog.js b/frontend/components/basic/dialog/AddServiceTokenDialog.js index 0e084d29d..8f5419502 100644 --- a/frontend/components/basic/dialog/AddServiceTokenDialog.js +++ b/frontend/components/basic/dialog/AddServiceTokenDialog.js @@ -8,7 +8,7 @@ import nacl from "tweetnacl"; import addServiceToken from "~/pages/api/serviceToken/addServiceToken"; import getLatestFileKey from "~/pages/api/workspace/getLatestFileKey"; -import { decryptAssymmetric, encryptAssymmetric } from "../../utilities/crypto"; +import { decryptAssymmetric, encryptAssymmetric } from "../../utilities/cryptography/crypto"; import Button from "../buttons/Button"; import InputField from "../InputField"; import ListBox from "../Listbox"; diff --git a/frontend/components/basic/layout.js b/frontend/components/basic/layout.js index 382eb2777..edac0dc9b 100644 --- a/frontend/components/basic/layout.js +++ b/frontend/components/basic/layout.js @@ -20,7 +20,7 @@ import createWorkspace from "~/pages/api/workspace/createWorkspace"; import getWorkspaces from "~/pages/api/workspace/getWorkspaces"; import NavBarDashboard from "../navigation/NavBarDashboard"; -import { decryptAssymmetric, encryptAssymmetric } from "../utilities/crypto"; +import { decryptAssymmetric, encryptAssymmetric } from "../utilities/cryptography/crypto"; import Button from "./buttons/Button"; import AddWorkspaceDialog from "./dialog/AddWorkspaceDialog"; import Listbox from "./Listbox"; diff --git a/frontend/components/basic/table/UserTable.js b/frontend/components/basic/table/UserTable.js index a09ff6e16..4d364b4a5 100644 --- a/frontend/components/basic/table/UserTable.js +++ b/frontend/components/basic/table/UserTable.js @@ -15,7 +15,7 @@ import Listbox from "../Listbox"; const { decryptAssymmetric, encryptAssymmetric, -} = require("../../utilities/crypto"); +} = require("../../utilities/cryptography/crypto"); const nacl = require("tweetnacl"); nacl.util = require("tweetnacl-util"); diff --git a/frontend/components/billing/Card.js b/frontend/components/billing/Card.js deleted file mode 100644 index 07f91b07a..000000000 --- a/frontend/components/billing/Card.js +++ /dev/null @@ -1,75 +0,0 @@ -import React from "react"; -import { faCcMastercard, faCcVisa } from "@fortawesome/free-brands-svg-icons"; -import { faCheck, faQuestionCircle } from "@fortawesome/free-solid-svg-icons"; -import { faCircle } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; - -export default function Card({ card, changeSelectedCard, selected }) { - function creditCardBrandIcon(cc) { - if (cc == "visa") { - return faCcVisa; - } else if ((cc = "mastercard")) { - return faCcMastercard; - } else return faQuestionCircle; - } - - return ( - - ); -} diff --git a/frontend/components/navigation/NavBarDashboard.js b/frontend/components/navigation/NavBarDashboard.js index 154bf0a55..d4f0c704a 100644 --- a/frontend/components/navigation/NavBarDashboard.js +++ b/frontend/components/navigation/NavBarDashboard.js @@ -27,8 +27,8 @@ import guidGenerator from "../utilities/randomId"; const supportOptions = [ [ , - "[NEW] Join Slack Forum", - "https://join.slack.com/t/infisical/shared_invite/zt-1dgg63ln8-G7PCNJdCymAT9YF3j1ewVA", + "Join Slack Forum", + "https://join.slack.com/t/infisical-users/shared_invite/zt-1kdbk07ro-RtoyEt_9E~fyzGo_xQYP6g", ], [ , diff --git a/frontend/components/utilities/attemptLogin.js b/frontend/components/utilities/attemptLogin.js index bbf0ba72c..53c56789b 100644 --- a/frontend/components/utilities/attemptLogin.js +++ b/frontend/components/utilities/attemptLogin.js @@ -1,4 +1,4 @@ -import Aes256Gcm from "~/components/aes-256-gcm"; +import Aes256Gcm from "~/components/utilities/cryptography/aes-256-gcm"; import login1 from "~/pages/api/auth/Login1"; import login2 from "~/pages/api/auth/Login2"; import getOrganizations from "~/pages/api/organization/getOrgs"; @@ -6,7 +6,7 @@ import getOrganizationUserProjects from "~/pages/api/organization/GetOrgUserProj import { initPostHog } from "../analytics/posthog"; import { ENV } from "./config"; -import pushKeys from "./pushKeys"; +import pushKeys from "./secrets/pushKeys"; import SecurityClient from "./SecurityClient"; const nacl = require("tweetnacl"); diff --git a/frontend/components/aes-256-gcm.js b/frontend/components/utilities/cryptography/aes-256-gcm.js similarity index 100% rename from frontend/components/aes-256-gcm.js rename to frontend/components/utilities/cryptography/aes-256-gcm.js diff --git a/frontend/components/utilities/changePassword.js b/frontend/components/utilities/cryptography/changePassword.js similarity index 95% rename from frontend/components/utilities/changePassword.js rename to frontend/components/utilities/cryptography/changePassword.js index 4e2b375aa..1951d5885 100644 --- a/frontend/components/utilities/changePassword.js +++ b/frontend/components/utilities/cryptography/changePassword.js @@ -1,7 +1,7 @@ import changePassword2 from "~/pages/api/auth/ChangePassword2"; import SRP1 from "~/pages/api/auth/SRP1"; -import Aes256Gcm from "../aes-256-gcm"; +import Aes256Gcm from "./aes-256-gcm"; const nacl = require("tweetnacl"); nacl.util = require("tweetnacl-util"); @@ -63,6 +63,7 @@ const changePassword = async ( async () => { clientNewPassword.createVerifier( async (err, result) => { + // The Blob part here is needed to account for symbols that count as 2+ bytes (e.g., é, å, ø) let { ciphertext, iv, tag } = Aes256Gcm.encrypt( localStorage.getItem("PRIVATE_KEY"), newPassword diff --git a/frontend/components/utilities/crypto.js b/frontend/components/utilities/cryptography/crypto.js similarity index 98% rename from frontend/components/utilities/crypto.js rename to frontend/components/utilities/cryptography/crypto.js index eac908e29..f7c0388fa 100644 --- a/frontend/components/utilities/crypto.js +++ b/frontend/components/utilities/cryptography/crypto.js @@ -1,6 +1,6 @@ const nacl = require("tweetnacl"); nacl.util = require("tweetnacl-util"); -const aes = require("../aes-256-gcm"); +const aes = require("./aes-256-gcm"); /** * Return assymmetrically encrypted [plaintext] using [publicKey] where diff --git a/frontend/components/utilities/issueBackupKey.js b/frontend/components/utilities/cryptography/issueBackupKey.js similarity index 96% rename from frontend/components/utilities/issueBackupKey.js rename to frontend/components/utilities/cryptography/issueBackupKey.js index cd2bc6a2d..570c8bc1a 100644 --- a/frontend/components/utilities/issueBackupKey.js +++ b/frontend/components/utilities/cryptography/issueBackupKey.js @@ -1,8 +1,8 @@ import issueBackupPrivateKey from "~/pages/api/auth/IssueBackupPrivateKey"; import SRP1 from "~/pages/api/auth/SRP1"; -import Aes256Gcm from "../aes-256-gcm"; -import generateBackupPDF from "./generateBackupPDF"; +import Aes256Gcm from "./aes-256-gcm"; +import generateBackupPDF from "../generateBackupPDF"; const nacl = require("tweetnacl"); nacl.util = require("tweetnacl-util"); diff --git a/frontend/components/utilities/csp.js b/frontend/components/utilities/csp.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/frontend/components/utilities/getSecretsForProject.js b/frontend/components/utilities/secrets/getSecretsForProject.js similarity index 96% rename from frontend/components/utilities/getSecretsForProject.js rename to frontend/components/utilities/secrets/getSecretsForProject.js index bec41b15f..4087e72d0 100644 --- a/frontend/components/utilities/getSecretsForProject.js +++ b/frontend/components/utilities/secrets/getSecretsForProject.js @@ -1,11 +1,11 @@ import getSecrets from "~/pages/api/files/GetSecrets"; -import guidGenerator from "./randomId"; +import guidGenerator from "../randomId"; const { decryptAssymmetric, decryptSymmetric, -} = require("../../components/utilities/crypto"); +} = require("../cryptography/crypto"); const nacl = require("tweetnacl"); nacl.util = require("tweetnacl-util"); diff --git a/frontend/components/utilities/pushKeys.js b/frontend/components/utilities/secrets/pushKeys.js similarity index 98% rename from frontend/components/utilities/pushKeys.js rename to frontend/components/utilities/secrets/pushKeys.js index c43b1cc1d..16b095632 100644 --- a/frontend/components/utilities/pushKeys.js +++ b/frontend/components/utilities/secrets/pushKeys.js @@ -8,7 +8,7 @@ const { decryptSymmetric, encryptSymmetric, encryptAssymmetric, -} = require("../../components/utilities/crypto"); +} = require("../cryptography/crypto"); const nacl = require("tweetnacl"); nacl.util = require("tweetnacl-util"); diff --git a/frontend/components/utilities/pushKeysIntegration.js b/frontend/components/utilities/secrets/pushKeysIntegration.js similarity index 95% rename from frontend/components/utilities/pushKeysIntegration.js rename to frontend/components/utilities/secrets/pushKeysIntegration.js index 06ad8c0e6..3f1bc6ee4 100644 --- a/frontend/components/utilities/pushKeysIntegration.js +++ b/frontend/components/utilities/secrets/pushKeysIntegration.js @@ -2,7 +2,7 @@ import publicKeyInfical from "~/pages/api/auth/publicKeyInfisical"; import changeHerokuConfigVars from "~/pages/api/integrations/ChangeHerokuConfigVars"; const crypto = require("crypto"); -const { encryptSymmetric, encryptAssymmetric } = require("./crypto"); +const { encryptSymmetric, encryptAssymmetric } = require("../cryptography/crypto"); const nacl = require("tweetnacl"); nacl.util = require("tweetnacl-util"); diff --git a/frontend/pages/dashboard/[id].js b/frontend/pages/dashboard/[id].js index 50db8a45e..a8195bb27 100644 --- a/frontend/pages/dashboard/[id].js +++ b/frontend/pages/dashboard/[id].js @@ -29,9 +29,9 @@ import BottonRightPopup from "~/components/basic/popups/BottomRightPopup"; import DashboardInputField from "~/components/dashboard/DashboardInputField"; import DropZone from "~/components/dashboard/DropZone"; import NavHeader from "~/components/navigation/NavHeader"; -import getSecretsForProject from "~/utilities/getSecretsForProject"; -import pushKeys from "~/utilities/pushKeys"; -import pushKeysIntegration from "~/utilities/pushKeysIntegration"; +import getSecretsForProject from "~/components/utilities/secrets/getSecretsForProject"; +import pushKeys from "~/components/utilities/secrets/pushKeys"; +import pushKeysIntegration from "~/components/utilities/secrets/pushKeysIntegration"; import guidGenerator from "~/utilities/randomId"; import getWorkspaceIntegrations from "../api/integrations/getWorkspaceIntegrations"; @@ -699,7 +699,7 @@ export default function Dashboard() { data?.length > 8 ? "h-3/4" : "h-min" }`} > -
+
{/* */}

diff --git a/frontend/pages/integrations/[id].js b/frontend/pages/integrations/[id].js index 35a9a6f06..9ae9c1c7c 100644 --- a/frontend/pages/integrations/[id].js +++ b/frontend/pages/integrations/[id].js @@ -13,8 +13,8 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import Button from "~/components/basic/buttons/Button"; import ListBox from "~/components/basic/Listbox"; import NavHeader from "~/components/navigation/NavHeader"; -import getSecretsForProject from "~/utilities/getSecretsForProject"; -import pushKeysIntegration from "~/utilities/pushKeysIntegration"; +import getSecretsForProject from "~/components/utilities/secrets/getSecretsForProject"; +import pushKeysIntegration from "~/components/utilities/secrets/pushKeysIntegration"; import guidGenerator from "~/utilities/randomId"; import deleteIntegration from "../api/integrations/DeleteIntegration"; diff --git a/frontend/pages/settings/personal/[id].js b/frontend/pages/settings/personal/[id].js index 2b5b90a35..9c4ad59bd 100644 --- a/frontend/pages/settings/personal/[id].js +++ b/frontend/pages/settings/personal/[id].js @@ -6,9 +6,9 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import Button from "~/components/basic/buttons/Button"; import InputField from "~/components/basic/InputField"; import NavHeader from "~/components/navigation/NavHeader"; -import changePassword from "~/utilities/changePassword"; +import changePassword from "~/components/utilities/cryptography/changePassword"; import passwordCheck from "~/utilities/checks/PasswordCheck"; -import issueBackupKey from "~/utilities/issueBackupKey"; +import issueBackupKey from "~/components/utilities/cryptography/issueBackupKey"; import getUser from "../../api/user/getUser"; diff --git a/frontend/pages/signup.js b/frontend/pages/signup.js index 3998bcf42..e9f000ed2 100644 --- a/frontend/pages/signup.js +++ b/frontend/pages/signup.js @@ -7,13 +7,13 @@ import { useRouter } from "next/router"; import { faCheck, faWarning, faX } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import Aes256Gcm from "~/components/aes-256-gcm"; +import Aes256Gcm from "~/components/utilities/cryptography/aes-256-gcm"; import Button from "~/components/basic/buttons/Button"; import Error from "~/components/basic/Error"; import InputField from "~/components/basic/InputField"; import attemptLogin from "~/utilities/attemptLogin"; import passwordCheck from "~/utilities/checks/PasswordCheck"; -import issueBackupKey from "~/utilities/issueBackupKey"; +import issueBackupKey from "~/components/utilities/cryptography/issueBackupKey"; import checkEmailVerificationCode from "./api/auth/CheckEmailVerificationCode"; import completeAccountInformationSignup from "./api/auth/CompleteAccountInformationSignup"; diff --git a/frontend/pages/signupinvite.js b/frontend/pages/signupinvite.js index 0f6a5c1c4..256bbb83f 100644 --- a/frontend/pages/signupinvite.js +++ b/frontend/pages/signupinvite.js @@ -6,12 +6,12 @@ import { useRouter } from "next/router"; import { faCheck, faWarning,faX } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import Aes256Gcm from "~/components/aes-256-gcm"; +import Aes256Gcm from "~/components/utilities/cryptography/aes-256-gcm"; import Button from "~/components/basic/buttons/Button"; import InputField from "~/components/basic/InputField"; import attemptLogin from "~/utilities/attemptLogin"; import passwordCheck from "~/utilities/checks/PasswordCheck"; -import issueBackupKey from "~/utilities/issueBackupKey"; +import issueBackupKey from "~/components/utilities/cryptography/issueBackupKey"; import completeAccountInformationSignupInvite from "./api/auth/CompleteAccountInformationSignupInvite"; import verifySignupInvite from "./api/auth/VerifySignupInvite"; diff --git a/frontend/pages/users/[id].js b/frontend/pages/users/[id].js index 0d1fd7d3d..f46abdf1d 100644 --- a/frontend/pages/users/[id].js +++ b/frontend/pages/users/[id].js @@ -23,7 +23,7 @@ const crypto = require("crypto"); const { decryptAssymmetric, encryptAssymmetric, -} = require("../../components/utilities/crypto"); +} = require("../../components/utilities/cryptography/crypto"); const nacl = require("tweetnacl"); nacl.util = require("tweetnacl-util");