mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 08:29:55 +00:00
ref(frontend): update to absolute import
This commit is contained in:
@@ -1,29 +1,27 @@
|
||||
import token from "../../pages/api/auth/Token"
|
||||
import { PATH } from '../../const';
|
||||
import token from "~/pages/api/auth/Token";
|
||||
import { PATH } from "../../const";
|
||||
|
||||
export default class SecurityClient {
|
||||
static authOrigins = [PATH]
|
||||
static #token = '';
|
||||
static authOrigins = [PATH];
|
||||
static #token = "";
|
||||
|
||||
contructor() {
|
||||
contructor() {}
|
||||
|
||||
}
|
||||
static setToken(token) {
|
||||
this.#token = token;
|
||||
}
|
||||
|
||||
static setToken(token) {
|
||||
this.#token = token;
|
||||
}
|
||||
static async fetchCall(resource, options) {
|
||||
let req = new Request(resource, options);
|
||||
const destOrigin = new URL(req.url).origin;
|
||||
|
||||
static async fetchCall(resource, options) {
|
||||
let req = new Request(resource, options);
|
||||
const destOrigin = new URL(req.url).origin;
|
||||
if (this.#token == "") {
|
||||
this.setToken(await token());
|
||||
}
|
||||
|
||||
if (this.#token == "") {
|
||||
this.setToken(await token())
|
||||
}
|
||||
|
||||
if (this.#token && this.authOrigins.includes(destOrigin)) {
|
||||
req.headers.set('Authorization', "Bearer " + this.#token);
|
||||
return fetch(req);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.#token && this.authOrigins.includes(destOrigin)) {
|
||||
req.headers.set("Authorization", "Bearer " + this.#token);
|
||||
return fetch(req);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import login1 from "../../pages/api/auth/Login1";
|
||||
import login2 from "../../pages/api/auth/Login2";
|
||||
import Aes256Gcm from "../../components/aes-256-gcm";
|
||||
import login1 from "~/pages/api/auth/Login1";
|
||||
import login2 from "~/pages/api/auth/Login2";
|
||||
import Aes256Gcm from "~/components/aes-256-gcm";
|
||||
import pushKeys from "./pushKeys";
|
||||
import { initPostHog } from "../analytics/posthog";
|
||||
import getOrganizations from "../../pages/api/organization/getOrgs";
|
||||
import getOrganizationUserProjects from "../../pages/api/organization/GetOrgUserProjects";
|
||||
import getOrganizations from "~/pages/api/organization/getOrgs";
|
||||
import getOrganizationUserProjects from "~/pages/api/organization/GetOrgUserProjects";
|
||||
import SecurityClient from "./SecurityClient";
|
||||
import { ENV } from "./config";
|
||||
|
||||
@@ -77,7 +77,14 @@ const attemptLogin = async (
|
||||
encryptedPrivateKey,
|
||||
iv,
|
||||
tag,
|
||||
password.slice(0, 32).padStart(32 + (password.slice(0, 32).length - new Blob([password]).size), "0")
|
||||
password
|
||||
.slice(0, 32)
|
||||
.padStart(
|
||||
32 +
|
||||
(password.slice(0, 32).length -
|
||||
new Blob([password]).size),
|
||||
"0"
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -101,10 +108,14 @@ const attemptLogin = async (
|
||||
}
|
||||
|
||||
const userOrgs = await getOrganizations();
|
||||
const userOrgsData = userOrgs.map(org => org._id);
|
||||
|
||||
const userOrgsData = userOrgs.map((org) => org._id);
|
||||
|
||||
let orgToLogin;
|
||||
if (userOrgsData.includes(localStorage.getItem("orgData.id"))) {
|
||||
if (
|
||||
userOrgsData.includes(
|
||||
localStorage.getItem("orgData.id")
|
||||
)
|
||||
) {
|
||||
orgToLogin = localStorage.getItem("orgData.id");
|
||||
} else {
|
||||
orgToLogin = userOrgsData[0];
|
||||
@@ -114,17 +125,29 @@ const attemptLogin = async (
|
||||
let orgUserProjects = await getOrganizationUserProjects({
|
||||
orgId: orgToLogin,
|
||||
});
|
||||
|
||||
orgUserProjects = orgUserProjects?.map(project => project._id);
|
||||
|
||||
orgUserProjects = orgUserProjects?.map(
|
||||
(project) => project._id
|
||||
);
|
||||
let projectToLogin;
|
||||
if (orgUserProjects.includes(localStorage.getItem("projectData.id"))) {
|
||||
if (
|
||||
orgUserProjects.includes(
|
||||
localStorage.getItem("projectData.id")
|
||||
)
|
||||
) {
|
||||
projectToLogin = localStorage.getItem("projectData.id");
|
||||
} else {
|
||||
try {
|
||||
projectToLogin = orgUserProjects[0];
|
||||
localStorage.setItem("projectData.id", projectToLogin);
|
||||
localStorage.setItem(
|
||||
"projectData.id",
|
||||
projectToLogin
|
||||
);
|
||||
} catch (error) {
|
||||
console.log("ERROR: User likely has no projects. ", error)
|
||||
console.log(
|
||||
"ERROR: User likely has no projects. ",
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Aes256Gcm from "../aes-256-gcm";
|
||||
import SRP1 from "../../pages/api/auth/SRP1";
|
||||
import changePassword2 from "../../pages/api/auth/ChangePassword2";
|
||||
import SRP1 from "~/pages/api/auth/SRP1";
|
||||
import changePassword2 from "~/pages/api/auth/ChangePassword2";
|
||||
|
||||
const nacl = require("tweetnacl");
|
||||
nacl.util = require("tweetnacl-util");
|
||||
@@ -41,7 +41,7 @@ const changePassword = async (
|
||||
let serverPublicKey, salt;
|
||||
try {
|
||||
const res = await SRP1({
|
||||
clientPublicKey: clientPublicKey
|
||||
clientPublicKey: clientPublicKey,
|
||||
});
|
||||
serverPublicKey = res.serverPublicKey;
|
||||
salt = res.salt;
|
||||
@@ -54,54 +54,70 @@ const changePassword = async (
|
||||
clientOldPassword.setServerPublicKey(serverPublicKey);
|
||||
const clientProof = clientOldPassword.getProof(); // called M1
|
||||
|
||||
clientNewPassword.init({
|
||||
username: email,
|
||||
password: newPassword
|
||||
}, async () => {
|
||||
clientNewPassword.createVerifier(async (err, result) => {
|
||||
|
||||
let { ciphertext, iv, tag } = Aes256Gcm.encrypt(
|
||||
localStorage.getItem("PRIVATE_KEY"),
|
||||
newPassword.slice(0, 32).padStart(32 + (newPassword.slice(0, 32).length - new Blob([newPassword]).size), "0")
|
||||
);
|
||||
clientNewPassword.init(
|
||||
{
|
||||
username: email,
|
||||
password: newPassword,
|
||||
},
|
||||
async () => {
|
||||
clientNewPassword.createVerifier(
|
||||
async (err, result) => {
|
||||
let { ciphertext, iv, tag } = Aes256Gcm.encrypt(
|
||||
localStorage.getItem("PRIVATE_KEY"),
|
||||
newPassword
|
||||
.slice(0, 32)
|
||||
.padStart(
|
||||
32 +
|
||||
(newPassword.slice(0, 32)
|
||||
.length -
|
||||
new Blob([newPassword])
|
||||
.size),
|
||||
"0"
|
||||
)
|
||||
);
|
||||
|
||||
if (ciphertext) {
|
||||
localStorage.setItem(
|
||||
"encryptedPrivateKey",
|
||||
ciphertext
|
||||
);
|
||||
localStorage.setItem("iv", iv);
|
||||
localStorage.setItem("tag", tag);
|
||||
|
||||
let res;
|
||||
try {
|
||||
res = await changePassword2({
|
||||
encryptedPrivateKey: ciphertext,
|
||||
iv,
|
||||
tag,
|
||||
salt: result.salt,
|
||||
verifier: result.verifier,
|
||||
clientProof
|
||||
});
|
||||
if (res.status == 400) {
|
||||
setCurrentPasswordError(true);
|
||||
} else if (res.status == 200) {
|
||||
setPasswordChanged(true);
|
||||
setCurrentPassword("");
|
||||
setNewPassword("");
|
||||
if (ciphertext) {
|
||||
localStorage.setItem(
|
||||
"encryptedPrivateKey",
|
||||
ciphertext
|
||||
);
|
||||
localStorage.setItem("iv", iv);
|
||||
localStorage.setItem("tag", tag);
|
||||
|
||||
let res;
|
||||
try {
|
||||
res = await changePassword2({
|
||||
encryptedPrivateKey: ciphertext,
|
||||
iv,
|
||||
tag,
|
||||
salt: result.salt,
|
||||
verifier: result.verifier,
|
||||
clientProof,
|
||||
});
|
||||
if (res.status == 400) {
|
||||
setCurrentPasswordError(true);
|
||||
} else if (res.status == 200) {
|
||||
setPasswordChanged(true);
|
||||
setCurrentPassword("");
|
||||
setNewPassword("");
|
||||
}
|
||||
} catch (err) {
|
||||
setCurrentPasswordError(true);
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
setCurrentPasswordError(true)
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
console.log("Something went wrong during changing the password", slat, serverPublicKey);
|
||||
console.log(
|
||||
"Something went wrong during changing the password",
|
||||
slat,
|
||||
serverPublicKey
|
||||
);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import getSecrets from "../../pages/api/files/GetSecrets";
|
||||
import getSecrets from "~/pages/api/files/GetSecrets";
|
||||
import guidGenerator from "./randomId";
|
||||
|
||||
|
||||
const {
|
||||
decryptAssymmetric,
|
||||
decryptSymmetric,
|
||||
@@ -21,15 +20,12 @@ const getSecretsForProject = async ({
|
||||
setFileState,
|
||||
setIsKeyAvailable,
|
||||
setData,
|
||||
workspaceId
|
||||
workspaceId,
|
||||
}) => {
|
||||
try {
|
||||
let file;
|
||||
try {
|
||||
file = await getSecrets(
|
||||
workspaceId,
|
||||
envMapping[env]
|
||||
);
|
||||
file = await getSecrets(workspaceId, envMapping[env]);
|
||||
|
||||
setFileState(file);
|
||||
} catch (error) {
|
||||
@@ -98,7 +94,9 @@ const getSecretsForProject = async ({
|
||||
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,6 +1,6 @@
|
||||
import Aes256Gcm from "../aes-256-gcm";
|
||||
import SRP1 from "../../pages/api/auth/SRP1";
|
||||
import issueBackupPrivateKey from "../../pages/api/auth/IssueBackupPrivateKey";
|
||||
import SRP1 from "~/pages/api/auth/SRP1";
|
||||
import issueBackupPrivateKey from "~/pages/api/auth/IssueBackupPrivateKey";
|
||||
import generateBackupPDF from "./generateBackupPDF";
|
||||
|
||||
const nacl = require("tweetnacl");
|
||||
@@ -24,7 +24,7 @@ const issueBackupKey = async ({
|
||||
password,
|
||||
personalName,
|
||||
setBackupKeyError,
|
||||
setBackupKeyIssued
|
||||
setBackupKeyIssued,
|
||||
}) => {
|
||||
try {
|
||||
setBackupKeyError(false);
|
||||
@@ -40,7 +40,7 @@ const issueBackupKey = async ({
|
||||
let serverPublicKey, salt;
|
||||
try {
|
||||
const res = await SRP1({
|
||||
clientPublicKey: clientPublicKey
|
||||
clientPublicKey: clientPublicKey,
|
||||
});
|
||||
serverPublicKey = res.serverPublicKey;
|
||||
salt = res.salt;
|
||||
@@ -55,35 +55,40 @@ const issueBackupKey = async ({
|
||||
|
||||
const generatedKey = crypto.randomBytes(16).toString("hex");
|
||||
|
||||
clientKey.init({
|
||||
username: email,
|
||||
password: generatedKey
|
||||
}, async () => {
|
||||
clientKey.createVerifier(async (err, result) => {
|
||||
clientKey.init(
|
||||
{
|
||||
username: email,
|
||||
password: generatedKey,
|
||||
},
|
||||
async () => {
|
||||
clientKey.createVerifier(async (err, result) => {
|
||||
let { ciphertext, iv, tag } = Aes256Gcm.encrypt(
|
||||
localStorage.getItem("PRIVATE_KEY"),
|
||||
generatedKey
|
||||
);
|
||||
|
||||
const res = await issueBackupPrivateKey({
|
||||
encryptedPrivateKey: ciphertext,
|
||||
iv,
|
||||
tag,
|
||||
salt: result.salt,
|
||||
verifier: result.verifier,
|
||||
clientProof,
|
||||
});
|
||||
|
||||
let { ciphertext, iv, tag } = Aes256Gcm.encrypt(
|
||||
localStorage.getItem("PRIVATE_KEY"),
|
||||
generatedKey
|
||||
);
|
||||
|
||||
const res = await issueBackupPrivateKey({
|
||||
encryptedPrivateKey: ciphertext,
|
||||
iv,
|
||||
tag,
|
||||
salt: result.salt,
|
||||
verifier: result.verifier,
|
||||
clientProof
|
||||
if (res.status == 400) {
|
||||
setBackupKeyError(true);
|
||||
} else if (res.status == 200) {
|
||||
generateBackupPDF(
|
||||
personalName,
|
||||
email,
|
||||
generatedKey
|
||||
);
|
||||
setBackupKeyIssued(true);
|
||||
}
|
||||
});
|
||||
|
||||
if (res.status == 400) {
|
||||
setBackupKeyError(true);
|
||||
} else if (res.status == 200) {
|
||||
generateBackupPDF(personalName, email, generatedKey);
|
||||
setBackupKeyIssued(true);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import getLatestFileKey from "../../pages/api/workspace/getLatestFileKey";
|
||||
import getWorkspaceKeys from "../../pages/api/workspace/getWorkspaceKeys";
|
||||
import uploadSecrets from "../../pages/api/files/UploadSecrets";
|
||||
import getLatestFileKey from "~/pages/api/workspace/getLatestFileKey";
|
||||
import getWorkspaceKeys from "~/pages/api/workspace/getWorkspaceKeys";
|
||||
import uploadSecrets from "~/pages/api/files/UploadSecrets";
|
||||
|
||||
const crypto = require("crypto");
|
||||
const {
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import publicKeyInfical from "../../pages/api/auth/publicKeyInfisical"
|
||||
import changeHerokuConfigVars from "../../pages/api/integrations/ChangeHerokuConfigVars";
|
||||
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("./crypto");
|
||||
const nacl = require("tweetnacl");
|
||||
nacl.util = require("tweetnacl-util");
|
||||
|
||||
@@ -71,7 +68,7 @@ const pushKeysIntegration = async ({ obj, integrationId }) => {
|
||||
nonce,
|
||||
};
|
||||
|
||||
changeHerokuConfigVars({integrationId, key, secrets})
|
||||
changeHerokuConfigVars({ integrationId, key, secrets });
|
||||
};
|
||||
|
||||
export default pushKeysIntegration;
|
||||
|
||||
Reference in New Issue
Block a user