Skip to content

Commit

Permalink
Allow to keep the default truststore, when using a custom CA (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
slowjoe007 authored Mar 22, 2024
1 parent 9b7cdb2 commit 8503752
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/bruno-app/src/components/Preferences/General/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const General = ({ close }) => {
enabled: Yup.boolean(),
filePath: Yup.string().nullable()
}),
keepDefaultCaCertificates: Yup.object({
enabled: Yup.boolean()
}),
storeCookies: Yup.boolean(),
sendCookies: Yup.boolean(),
timeout: Yup.mixed()
Expand All @@ -43,6 +46,9 @@ const General = ({ close }) => {
enabled: get(preferences, 'request.customCaCertificate.enabled', false),
filePath: get(preferences, 'request.customCaCertificate.filePath', null)
},
keepDefaultCaCertificates: {
enabled: get(preferences, 'request.keepDefaultCaCertificates.enabled', false)
},
timeout: preferences.request.timeout,
storeCookies: get(preferences, 'request.storeCookies', true),
sendCookies: get(preferences, 'request.sendCookies', true)
Expand All @@ -68,6 +74,9 @@ const General = ({ close }) => {
enabled: newPreferences.customCaCertificate.enabled,
filePath: newPreferences.customCaCertificate.filePath
},
keepDefaultCaCertificates: {
enabled: newPreferences.keepDefaultCaCertificates.enabled
},
timeout: newPreferences.timeout,
storeCookies: newPreferences.storeCookies,
sendCookies: newPreferences.sendCookies
Expand Down Expand Up @@ -158,6 +167,23 @@ const General = ({ close }) => {
</button>
</div>
)}
<div className="flex items-center mt-2">
<input
id="keepDefaultCaCertificatesEnabled"
type="checkbox"
name="keepDefaultCaCertificates.enabled"
checked={formik.values.keepDefaultCaCertificates.enabled}
onChange={formik.handleChange}
className={`mousetrap mr-0 ${formik.values.customCaCertificate.enabled ? '' : 'opacity-25'}`}
disabled={formik.values.customCaCertificate.enabled ? false : true}
/>
<label
className={`block ml-2 select-none ${formik.values.customCaCertificate.enabled ? '' : 'opacity-25'}`}
htmlFor="keepDefaultCaCertificatesEnabled"
>
Keep default CA Certificates
</label>
</div>
<div className="flex items-center mt-2">
<input
id="storeCookies"
Expand Down
3 changes: 3 additions & 0 deletions packages/bruno-app/src/providers/ReduxStore/slices/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const initialState = {
enabled: false,
filePath: null
},
keepDefaultCaCertificates: {
enabled: false
},
timeout: 0
},
font: {
Expand Down
7 changes: 6 additions & 1 deletion packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const os = require('os');
const fs = require('fs');
const qs = require('qs');
const https = require('https');
const tls = require('tls');
const axios = require('axios');
const path = require('path');
const decomment = require('decomment');
Expand Down Expand Up @@ -105,7 +106,11 @@ const configureRequest = async (
if (preferencesUtil.shouldUseCustomCaCertificate()) {
const caCertFilePath = preferencesUtil.getCustomCaCertificateFilePath();
if (caCertFilePath) {
httpsAgentRequestFields['ca'] = fs.readFileSync(caCertFilePath);
let caCertBuffer = fs.readFileSync(caCertFilePath);
if (preferencesUtil.shouldKeepDefaultCaCertificates()) {
caCertBuffer += '\n' + tls.rootCertificates.join('\n'); // Augment default truststore with custom CA certificates
}
httpsAgentRequestFields['ca'] = caCertBuffer;
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/bruno-electron/src/store/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const defaultPreferences = {
enabled: false,
filePath: null
},
keepDefaultCaCertificates: {
enabled: false
},
storeCookies: true,
sendCookies: true,
timeout: 0
Expand Down Expand Up @@ -43,6 +46,9 @@ const preferencesSchema = Yup.object().shape({
enabled: Yup.boolean(),
filePath: Yup.string().nullable()
}),
keepDefaultCaCertificates: Yup.object({
enabled: Yup.boolean()
}),
storeCookies: Yup.boolean(),
sendCookies: Yup.boolean(),
timeout: Yup.number()
Expand Down Expand Up @@ -111,6 +117,9 @@ const preferencesUtil = {
shouldUseCustomCaCertificate: () => {
return get(getPreferences(), 'request.customCaCertificate.enabled', false);
},
shouldKeepDefaultCaCertificates: () => {
return get(getPreferences(), 'request.keepDefaultCaCertificates.enabled', false);
},
getCustomCaCertificateFilePath: () => {
return get(getPreferences(), 'request.customCaCertificate.filePath', null);
},
Expand Down

0 comments on commit 8503752

Please sign in to comment.