Skip to content

Commit

Permalink
Merge pull request #33 from Cosmian/feat/encrypt_findex_db
Browse files Browse the repository at this point in the history
feat:update findex
  • Loading branch information
HatemMn authored Nov 22, 2024
2 parents df7545d + a324212 commit 5895d06
Show file tree
Hide file tree
Showing 29 changed files with 1,691 additions and 1,020 deletions.
2,063 changes: 1,226 additions & 837 deletions package-lock.json

Large diffs are not rendered by default.

Binary file added public/Logo_C_Cosmian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions public/actions/javascript/encryptDatabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AesGcm } from "cloudproof_js";
import { findexClearEmployeesDatabase, encryptedEmployeesDatabase } from "../../utils/findexConfig";

export const encryptDatabase = async (
clearDatabase: findexClearEmployeesDatabase[],
key: Uint8Array,
nonce: Uint8Array,
authData: Uint8Array
): Promise<encryptedEmployeesDatabase[]> => {
const { Aes256Gcm } = await AesGcm();

return Promise.all(
clearDatabase.map((e) =>
Object.keys(e)
.filter((k) => k !== "uuid")
.reduce(
(acc, k) => {
const index = k as keyof Omit<typeof e, "uuid">;
return {
...acc,
[index]: Aes256Gcm.encrypt(e[index].toString(), key, nonce, authData),
};
},
{ uuid: e.uuid } as encryptedEmployeesDatabase
)
)
);
};
2 changes: 1 addition & 1 deletion public/actions/javascript/sendDocumentContent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RUNNER_URL } from "./backendConfig"
import { RUNNER_URL } from "./backendConfig";

export const summarizeDocumentContent = async (textInput: string): Promise<{ summary: string } | Error> => {
const formData = new FormData();
Expand Down
4 changes: 2 additions & 2 deletions public/actions/javascript/sendEncryptedDocument.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import aes from "js-crypto-aes"
import { RUNNER_URL } from "./backendConfig"
import aes from "js-crypto-aes";
import { RUNNER_URL } from "./backendConfig";

export const sendEncryptedDocument = async (
textInput: Uint8Array,
Expand Down
2 changes: 1 addition & 1 deletion public/actions/javascript/summarizeDocumentContent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RUNNER_URL } from "./backendConfig"
import { RUNNER_URL } from "./backendConfig";

export const summarizeDocumentContent = async (textInput: string, userToken: string): Promise<{ summary: string } | Error> => {
const formData = new FormData();
Expand Down
28 changes: 28 additions & 0 deletions src/actions/javascript/encryptDatabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AesGcm } from "cloudproof_js";
import { findexClearEmployeesDatabase, encryptedEmployeesDatabase } from "../../utils/findexConfig";

export const encryptDatabase = async (
clearDatabase: findexClearEmployeesDatabase[],
key: Uint8Array,
nonce: Uint8Array,
authData: Uint8Array
): Promise<encryptedEmployeesDatabase[]> => {
const { Aes256Gcm } = await AesGcm();

return Promise.all(
clearDatabase.map((e) =>
Object.keys(e)
.filter((k) => k !== "uuid")
.reduce(
(acc, k) => {
const index = k as keyof Omit<typeof e, "uuid">;
return {
...acc,
[index]: Aes256Gcm.encrypt(e[index].toString(), key, nonce, authData),
};
},
{ uuid: e.uuid } as encryptedEmployeesDatabase
)
)
);
};
2 changes: 1 addition & 1 deletion src/actions/javascript/summarizeDocumentContent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RUNNER_URL } from "./backendConfig"
import { RUNNER_URL } from "./backendConfig";

export const summarizeDocumentContent = async (textInput: string, userToken: string): Promise<{ summary: string } | Error> => {
const formData = new FormData();
Expand Down
16 changes: 13 additions & 3 deletions src/component/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { ColumnsType } from "antd/es/table";
import { IndexedEntry } from "cloudproof_js";
import { Employee } from "../utils/covercryptConfig";
import { EncryptedResult } from "../utils/types";
import { findexClearEmployeesDatabase } from "../utils/findexConfig";

const { Column, ColumnGroup } = Table;

type EmployeeTablePros = {
data: Employee[];
data: (Employee | findexClearEmployeesDatabase)[];
covercrypt?: boolean;
className?: string;
style?: React.CSSProperties;
Expand Down Expand Up @@ -69,13 +70,22 @@ export const EmployeeTable: React.FC<EmployeeTablePros> = ({ data, covercrypt, .
);

return (
<Table dataSource={data} pagination={false} {...rest} rowKey={"uuid"} scroll={{ x: 550 }}>
<Table
dataSource={data}
pagination={false}
{...rest}
rowKey={"uuid"}
scroll={{ x: 550 }}
style={{
wordBreak: "break-word",
}}
>
{covercrypt ? (
<>
<ColumnGroup
key={"marketing"}
title={
<Tag icon={<LockFilled />} color="cyan" style={{ width: "100%", textAlign: "center" }}>
<Tag icon={<LockFilled />} color="cyan" style={{ width: "100%", textAlign: "center", wordBreak: "break-word" }}>
Marketing
</Tag>
}
Expand Down
10 changes: 8 additions & 2 deletions src/hooks/useFetchCodeContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { useEffect, useState } from "react";
import { getLanguageExtension } from "../utils/languageConfig";
import { CodeContent, Language } from "../utils/types";

/**
* Custom hook to fetch code content for a given filename and active language list.
*
* @param {string} filename - The name of the file to fetch code content for. Must be placed like following : actions/${language}/${filename}${extension}
* @param {Language[]} activeLanguageList - The list of active languages to fetch code content for.
*/
export const useFetchCodeContent = (
filename: string,
activeLanguageList: Language[]
): { loadingCode: boolean; codeContent: CodeContent } => {
const [loadingCode, setLoadingcode] = useState(true);
const [loadingCode, setLoadingCode] = useState(true);
const [codeContent, setCodeContent] = useState<CodeContent>({
java: undefined,
javascript: undefined,
Expand All @@ -27,7 +33,7 @@ export const useFetchCodeContent = (
tempContent[language] = text;
}
setCodeContent(tempContent);
setLoadingcode(false);
setLoadingCode(false);
};
return { loadingCode, codeContent };
};
12 changes: 6 additions & 6 deletions src/pages/confidentialVm/AuditSnapshot.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect } from "react"
import { useNavigate } from "react-router-dom"
import { CodeBackground, VmCode } from "../../component/Code"
import Split from "../../component/Split"
import { useBoundStore, useConfidentialVmStore } from "../../store/store"
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions"
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { CodeBackground, VmCode } from "../../component/Code";
import Split from "../../component/Split";
import { useBoundStore, useConfidentialVmStore } from "../../store/store";
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions";

const AuditSnapshot = (): JSX.Element => {
const { snapshot } = useConfidentialVmStore((state) => state);
Expand Down
22 changes: 11 additions & 11 deletions src/pages/confidentialVm/DeployApplication.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CheckCircleOutlined } from "@ant-design/icons/lib/icons"
import { Button } from "cosmian_ui"
import { useNavigate } from "react-router-dom"
import SyntaxHighlighter from "react-syntax-highlighter"
import { atelierSulphurpoolDark } from "react-syntax-highlighter/dist/esm/styles/hljs"
import HelloWorldGithub from "../../assets//helloworld_app.png"
import { CodeBackground, VmCode } from "../../component/Code"
import { ImageWrapper } from "../../component/Layout"
import Split from "../../component/Split"
import { useBoundStore, useConfidentialVmStore } from "../../store/store"
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions"
import { CheckCircleOutlined } from "@ant-design/icons/lib/icons";
import { Button } from "cosmian_ui";
import { useNavigate } from "react-router-dom";
import SyntaxHighlighter from "react-syntax-highlighter";
import { atelierSulphurpoolDark } from "react-syntax-highlighter/dist/esm/styles/hljs";
import HelloWorldGithub from "../../assets//helloworld_app.png";
import { CodeBackground, VmCode } from "../../component/Code";
import { ImageWrapper } from "../../component/Layout";
import Split from "../../component/Split";
import { useBoundStore, useConfidentialVmStore } from "../../store/store";
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions";

const DeployApplication = (): JSX.Element => {
const { helloWorld, setHelloWorld } = useConfidentialVmStore((state) => state);
Expand Down
18 changes: 9 additions & 9 deletions src/pages/confidentialVm/DetectMalware.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CloseCircleOutlined } from "@ant-design/icons/lib/icons"
import { Button } from "cosmian_ui"
import { useNavigate } from "react-router-dom"
import SyntaxHighlighter from "react-syntax-highlighter"
import { atelierSulphurpoolDark } from "react-syntax-highlighter/dist/esm/styles/hljs"
import { CodeBackground, VmCode } from "../../component/Code"
import Split from "../../component/Split"
import { useBoundStore, useConfidentialVmStore } from "../../store/store"
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions"
import { CloseCircleOutlined } from "@ant-design/icons/lib/icons";
import { Button } from "cosmian_ui";
import { useNavigate } from "react-router-dom";
import SyntaxHighlighter from "react-syntax-highlighter";
import { atelierSulphurpoolDark } from "react-syntax-highlighter/dist/esm/styles/hljs";
import { CodeBackground, VmCode } from "../../component/Code";
import Split from "../../component/Split";
import { useBoundStore, useConfidentialVmStore } from "../../store/store";
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions";

const DetectMalware = (): JSX.Element => {
const { malware, setMalware } = useConfidentialVmStore((state) => state);
Expand Down
14 changes: 7 additions & 7 deletions src/pages/confidentialVm/SnapshotVm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CheckCircleOutlined } from "@ant-design/icons/lib/icons"
import { Button } from "cosmian_ui"
import { useNavigate } from "react-router-dom"
import { CodeBackground, VmCode } from "../../component/Code"
import Split from "../../component/Split"
import { useBoundStore, useConfidentialVmStore } from "../../store/store"
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions"
import { CheckCircleOutlined } from "@ant-design/icons/lib/icons";
import { Button } from "cosmian_ui";
import { useNavigate } from "react-router-dom";
import { CodeBackground, VmCode } from "../../component/Code";
import Split from "../../component/Split";
import { useBoundStore, useConfidentialVmStore } from "../../store/store";
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions";

const SnapshotVm = (): JSX.Element => {
const { snapshot, setSnapshot } = useConfidentialVmStore((state) => state);
Expand Down
14 changes: 7 additions & 7 deletions src/pages/confidentialVm/VerifyIntegrity.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CheckCircleOutlined } from "@ant-design/icons/lib/icons"
import { Button } from "cosmian_ui"
import { useNavigate } from "react-router-dom"
import { CodeBackground, VmCode } from "../../component/Code"
import Split from "../../component/Split"
import { useBoundStore, useConfidentialVmStore } from "../../store/store"
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions"
import { CheckCircleOutlined } from "@ant-design/icons/lib/icons";
import { Button } from "cosmian_ui";
import { useNavigate } from "react-router-dom";
import { CodeBackground, VmCode } from "../../component/Code";
import Split from "../../component/Split";
import { useBoundStore, useConfidentialVmStore } from "../../store/store";
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions";

const VerifyIntegrity = (): JSX.Element => {
const { integrity, setIntegrity } = useConfidentialVmStore((state) => state);
Expand Down
16 changes: 8 additions & 8 deletions src/pages/covercrypt/CreateEncryptionPolicy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const CreateEncryptionPolicy = (): JSX.Element => {
// custom hooks
const { loadingCode, codeContent } = useFetchCodeContent("createPolicy", activeLanguageList);
// states
const covercryptState = useCovercryptStore((state) => state);
const { clearEmployees, policy, setPolicy } = useCovercryptStore((state) => state);
const { steps, setSteps } = useBoundStore((state) => state);
const navigate = useNavigate();
const currentItem = findCurrentNavigationItem(steps);

const handleCreatePolicy = async (): Promise<void> => {
try {
covercryptState.setPolicy(await createPolicy(POLICY_AXIS));
setPolicy(await createPolicy(POLICY_AXIS));
updateNavigationSteps(steps, setSteps);
navigate("#");
} catch (error) {
Expand Down Expand Up @@ -54,13 +54,13 @@ const CreateEncryptionPolicy = (): JSX.Element => {
</p>
<p>An access policy is defined by a set of partitions. It can be written as a boolean expression of axis attributes:</p>
<pre>(Department::Marketing || Department::HR) && Country::France</pre>
<EmployeeTable data={covercryptState.clearEmployees} covercrypt />
<EmployeeTable data={clearEmployees} covercrypt />
<br />
<p>
In the following demo, we will create a policy that combines two axes, a security level, and a department. A user will be able to
decrypt data only if it possesses a key with a sufficient security level and the correct department.
</p>
{covercryptState.policy && <pre>{POLICY_AXIS_TEXT}</pre>}
{policy && <pre>{POLICY_AXIS_TEXT}</pre>}
</Split.Content>

<Split.Code>
Expand All @@ -69,11 +69,11 @@ const CreateEncryptionPolicy = (): JSX.Element => {
codeInputList={codeContent}
runCode={handleCreatePolicy}
codeOutputList={
covercryptState.policy
policy
? {
java: JSON.stringify(covercryptState.policy, undefined, 2),
javascript: JSON.stringify(covercryptState.policy, undefined, 2),
python: JSON.stringify(covercryptState.policy, undefined, 2),
java: JSON.stringify(policy, undefined, 2),
javascript: JSON.stringify(policy, undefined, 2),
python: JSON.stringify(policy, undefined, 2),
}
: undefined
}
Expand Down
10 changes: 5 additions & 5 deletions src/pages/covercrypt/SetupCovercrypt.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import Code from "../../component/Code";
import Split from "../../component/Split";
import { useBoundStore } from "../../store/store";
import { useBoundStore, useCovercryptStore } from "../../store/store";
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions";
import { Language } from "../../utils/types";

const activeLanguageList: Language[] = ["java", "javascript", "python"];

const SetupCovercrypt = (): JSX.Element => {
const [serviceSetup, setServiceSetup] = useState(false);
const { covercryptService, setCovercryptService } = useCovercryptStore((state) => state);

const { steps, setSteps } = useBoundStore((state) => state);
const navigate = useNavigate();
const currentItem = findCurrentNavigationItem(steps);

const handleSetupService = (): void => {
setServiceSetup(true);
setCovercryptService(true);
updateNavigationSteps(steps, setSteps);
navigate("#");
};
Expand Down Expand Up @@ -78,7 +78,7 @@ const SetupCovercrypt = (): JSX.Element => {
python: PYTHON_CODE,
}}
codeOutputList={
serviceSetup
covercryptService
? {
java: "# successfully installed",
javascript: "# successfully installed",
Expand Down
10 changes: 5 additions & 5 deletions src/pages/cse/AboutCse.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Link } from "react-router-dom"
import CseSchema from "../../assets/cse_schema.drawio.svg"
import { ImageWrapper, SingleContent } from "../../component/Layout"
import { useBoundStore } from "../../store/store"
import { findCurrentNavigationItem } from "../../utils/navigationActions"
import { Link } from "react-router-dom";
import CseSchema from "../../assets/cse_schema.drawio.svg";
import { ImageWrapper, SingleContent } from "../../component/Layout";
import { useBoundStore } from "../../store/store";
import { findCurrentNavigationItem } from "../../utils/navigationActions";

const AboutCse = (): JSX.Element => {
const steps = useBoundStore((state) => state.steps);
Expand Down
18 changes: 9 additions & 9 deletions src/pages/cse/ConfigureCse.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { message } from "antd"
import { Link, useNavigate } from "react-router-dom"
import CseAdmin from "../../assets/admin_cse.png"
import Code from "../../component/Code"
import { ImageWrapper } from "../../component/Layout"
import Split from "../../component/Split"
import { useBoundStore, useCseStore } from "../../store/store"
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions"
import { Language } from "../../utils/types"
import { message } from "antd";
import { Link, useNavigate } from "react-router-dom";
import CseAdmin from "../../assets/admin_cse.png";
import Code from "../../component/Code";
import { ImageWrapper } from "../../component/Layout";
import Split from "../../component/Split";
import { useBoundStore, useCseStore } from "../../store/store";
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions";
import { Language } from "../../utils/types";


const activeLanguageList: Language[] = [];
Expand Down
20 changes: 10 additions & 10 deletions src/pages/cse/ConfigureDke.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { message } from "antd"
import { Link, useNavigate } from "react-router-dom"
import DkeAdminScope from "../../assets/label_scope.png"
import DkeAdminLabel from "../../assets/sensitivity_label.png"
import Code from "../../component/Code"
import { ImageWrapper } from "../../component/Layout"
import Split from "../../component/Split"
import { useBoundStore, useCseStore } from "../../store/store"
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions"
import { Language } from "../../utils/types"
import { message } from "antd";
import { Link, useNavigate } from "react-router-dom";
import DkeAdminScope from "../../assets/label_scope.png";
import DkeAdminLabel from "../../assets/sensitivity_label.png";
import Code from "../../component/Code";
import { ImageWrapper } from "../../component/Layout";
import Split from "../../component/Split";
import { useBoundStore, useCseStore } from "../../store/store";
import { findCurrentNavigationItem, updateNavigationSteps } from "../../utils/navigationActions";
import { Language } from "../../utils/types";


const activeLanguageList: Language[] = [];
Expand Down
Loading

0 comments on commit 5895d06

Please sign in to comment.