From a60f3517369fbddb14c136ada7972982607c1c46 Mon Sep 17 00:00:00 2001 From: Brandon Gillis Date: Wed, 6 Dec 2023 01:04:35 +0100 Subject: [PATCH] feat: add custom CA Certificate preference --- .../components/Preferences/General/index.js | 80 ++++++++++++++++++- .../src/providers/ReduxStore/slices/app.js | 4 + .../bruno-electron/src/ipc/network/index.js | 13 ++- .../bruno-electron/src/store/preferences.js | 14 ++++ 4 files changed, 109 insertions(+), 2 deletions(-) diff --git a/packages/bruno-app/src/components/Preferences/General/index.js b/packages/bruno-app/src/components/Preferences/General/index.js index da2e69ab..bfdbbb3b 100644 --- a/packages/bruno-app/src/components/Preferences/General/index.js +++ b/packages/bruno-app/src/components/Preferences/General/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useRef } from 'react'; import get from 'lodash/get'; import { useFormik } from 'formik'; import { useSelector, useDispatch } from 'react-redux'; @@ -6,13 +6,21 @@ import { savePreferences } from 'providers/ReduxStore/slices/app'; import StyledWrapper from './StyledWrapper'; import * as Yup from 'yup'; import toast from 'react-hot-toast'; +import path from 'path'; +import slash from 'utils/common/slash'; +import { IconTrash } from '@tabler/icons'; const General = ({ close }) => { const preferences = useSelector((state) => state.app.preferences); const dispatch = useDispatch(); + const inputFileCaCertificateRef = useRef(); const preferencesSchema = Yup.object().shape({ sslVerification: Yup.boolean(), + customCaCertificate: Yup.object({ + enabled: Yup.boolean(), + filePath: Yup.string().nullable() + }), storeCookies: Yup.boolean(), sendCookies: Yup.boolean(), timeout: Yup.mixed() @@ -31,6 +39,10 @@ const General = ({ close }) => { const formik = useFormik({ initialValues: { sslVerification: preferences.request.sslVerification, + customCaCertificate: { + enabled: get(preferences, 'request.customCaCertificate.enabled', false), + filePath: get(preferences, 'request.customCaCertificate.filePath', null) + }, timeout: preferences.request.timeout, storeCookies: get(preferences, 'request.storeCookies', true), sendCookies: get(preferences, 'request.sendCookies', true) @@ -52,6 +64,10 @@ const General = ({ close }) => { ...preferences, request: { sslVerification: newPreferences.sslVerification, + customCaCertificate: { + enabled: newPreferences.customCaCertificate.enabled, + filePath: newPreferences.customCaCertificate.filePath + }, timeout: newPreferences.timeout, storeCookies: newPreferences.storeCookies, sendCookies: newPreferences.sendCookies @@ -64,6 +80,14 @@ const General = ({ close }) => { .catch((err) => console.log(err) && toast.error('Failed to update preferences')); }; + const addCaCertificate = (e) => { + formik.setFieldValue('customCaCertificate.filePath', e.target.files[0]?.path); + }; + + const deleteCaCertificate = () => { + formik.setFieldValue('customCaCertificate.filePath', null); + }; + return (
@@ -80,6 +104,60 @@ const General = ({ close }) => { SSL/TLS Certificate Verification +
+ + +
+ {formik.values.customCaCertificate.filePath ? ( +
+ + {path.basename(slash(formik.values.customCaCertificate.filePath))} + + +
+ ) : ( +
+ +
+ )}
{ return get(getPreferences(), 'request.sslVerification', true); }, + shouldUseCustomCaCertificate: () => { + return get(getPreferences(), 'request.customCaCertificate.enabled', false); + }, + getCustomCaCertificateFilePath: () => { + return get(getPreferences(), 'request.customCaCertificate.filePath', null); + }, getRequestTimeout: () => { return get(getPreferences(), 'request.timeout', 0); },