Merge pull request #2482 from Infisical/daniel/shorter-share-url

feat(secret-sharing): server-side encryption
This commit is contained in:
Daniel Hougaard
2024-10-03 17:48:12 +04:00
committed by GitHub
15 changed files with 193 additions and 122 deletions
@@ -3,13 +3,21 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { secretSharingKeys } from "./queries";
import { TCreateSharedSecretRequest, TDeleteSharedSecretRequest, TSharedSecret } from "./types";
import {
TCreatedSharedSecret,
TCreateSharedSecretRequest,
TDeleteSharedSecretRequest,
TSharedSecret
} from "./types";
export const useCreateSharedSecret = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (inputData: TCreateSharedSecretRequest) => {
const { data } = await apiRequest.post<TSharedSecret>("/api/v1/secret-sharing", inputData);
const { data } = await apiRequest.post<TCreatedSharedSecret>(
"/api/v1/secret-sharing",
inputData
);
return data;
},
onSuccess: () => queryClient.invalidateQueries(secretSharingKeys.allSharedSecrets())
@@ -20,7 +28,7 @@ export const useCreatePublicSharedSecret = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (inputData: TCreateSharedSecretRequest) => {
const { data } = await apiRequest.post<TSharedSecret>(
const { data } = await apiRequest.post<TCreatedSharedSecret>(
"/api/v1/secret-sharing/public",
inputData
);
@@ -8,7 +8,7 @@ export const secretSharingKeys = {
allSharedSecrets: () => ["sharedSecrets"] as const,
specificSharedSecrets: ({ offset, limit }: { offset: number; limit: number }) =>
[...secretSharingKeys.allSharedSecrets(), { offset, limit }] as const,
getSecretById: (arg: { id: string; hashedHex: string; password?: string }) => [
getSecretById: (arg: { id: string; hashedHex: string | null; password?: string }) => [
"shared-secret",
arg
]
@@ -46,7 +46,7 @@ export const useGetActiveSharedSecretById = ({
password
}: {
sharedSecretId: string;
hashedHex: string;
hashedHex: string | null;
password?: string;
}) => {
return useQuery<TViewSharedSecretResponse>(
@@ -55,7 +55,7 @@ export const useGetActiveSharedSecretById = ({
const { data } = await apiRequest.post<TViewSharedSecretResponse>(
`/api/v1/secret-sharing/public/${sharedSecretId}`,
{
hashedHex,
...(hashedHex && { hashedHex }),
password
}
);
@@ -63,7 +63,7 @@ export const useGetActiveSharedSecretById = ({
return data;
},
{
enabled: Boolean(sharedSecretId) && Boolean(hashedHex)
enabled: Boolean(sharedSecretId)
}
);
};
@@ -13,13 +13,14 @@ export type TSharedSecret = {
tag: string;
};
export type TCreatedSharedSecret = {
id: string;
};
export type TCreateSharedSecretRequest = {
name?: string;
password?: string;
encryptedValue: string;
hashedHex: string;
iv: string;
tag: string;
secretValue: string;
expiresAt: Date;
expiresAfterViews?: number;
accessType?: SecretSharingAccessType;
@@ -28,6 +29,7 @@ export type TCreateSharedSecretRequest = {
export type TViewSharedSecretResponse = {
isPasswordProtected: boolean;
secret: {
secretValue?: string;
encryptedValue: string;
iv: string;
tag: string;
@@ -44,4 +46,3 @@ export enum SecretSharingAccessType {
Anyone = "anyone",
Organization = "organization"
}