Skip to content

Commit

Permalink
fix: save only cert/key path
Browse files Browse the repository at this point in the history
  • Loading branch information
phoval committed Oct 12, 2023
1 parent e29549d commit e589184
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const ClientCertSettings = ({ clientCertConfig, onUpdate, onRemove }) => {
const formik = useFormik({
initialValues: {
domain: '',
cert: '',
key: '',
certPath: '',
keyPath: '',
passphrase: ''
},
validationSchema: Yup.object({
domain: Yup.string().required(),
cert: Yup.string().required(),
key: Yup.string().required(),
certPath: Yup.string().required(),
keyPath: Yup.string().required(),
passphrase: Yup.string()
}),
onSubmit: (values) => {
Expand All @@ -24,11 +24,7 @@ const ClientCertSettings = ({ clientCertConfig, onUpdate, onRemove }) => {
});

const getFile = (e) => {
var reader = new FileReader();
reader.readAsDataURL(e.files[0]);
reader.onloadend = () => {
formik.values[e.name] = reader.result.split(',').pop();
};
formik.values[e.name] = e.files[0].path;
};

return (
Expand Down Expand Up @@ -66,21 +62,21 @@ const ClientCertSettings = ({ clientCertConfig, onUpdate, onRemove }) => {
) : null}
</div>
<div className="mb-3 flex items-center">
<label className="settings-label" htmlFor="cert">
<label className="settings-label" htmlFor="certPath">
Cert file
</label>
<input id="cert" type="file" name="cert" className="block" onChange={(e) => getFile(e.target)} />
{formik.touched.cert && formik.errors.cert ? (
<div className="ml-1 text-red-500">{formik.errors.cert}</div>
<input id="certPath" type="file" name="certPath" className="block" onChange={(e) => getFile(e.target)} />
{formik.touched.certPath && formik.errors.certPath ? (
<div className="ml-1 text-red-500">{formik.errors.certPath}</div>
) : null}
</div>
<div className="mb-3 flex items-center">
<label className="settings-label" htmlFor="key">
<label className="settings-label" htmlFor="keyPath">
Key file
</label>
<input id="key" type="file" name="key" className="block" onChange={(e) => getFile(e.target)} />
{formik.touched.key && formik.errors.key ? (
<div className="ml-1 text-red-500">{formik.errors.key}</div>
<input id="keyPath" type="file" name="keyPath" className="block" onChange={(e) => getFile(e.target)} />
{formik.touched.keyPath && formik.errors.keyPath ? (
<div className="ml-1 text-red-500">{formik.errors.keyPath}</div>
) : null}
</div>
<div className="mb-3 flex items-center">
Expand Down
12 changes: 8 additions & 4 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const os = require('os');
const fs = require('fs');
const qs = require('qs');
const https = require('https');
const axios = require('axios');
Expand Down Expand Up @@ -212,7 +213,6 @@ const registerNetworkIpc = (mainWindow) => {
cacertFile = cacertArray.find((el) => el);
if (cacertFile && cacertFile.length > 1) {
try {
const fs = require('fs');
caCrt = fs.readFileSync(cacertFile);
httpsAgentRequestFields['ca'] = caCrt;
} catch (err) {
Expand All @@ -227,12 +227,16 @@ const registerNetworkIpc = (mainWindow) => {
const clientCertConfig = get(brunoConfig, 'clientCert', []);

for (clientCert of clientCertConfig) {
if (clientCert.domain && clientCert.cert && clientCert.key) {
if (clientCert.domain && clientCert.certPath && clientCert.keyPath) {
const hostRegex = '^https:\\/\\/' + clientCert.domain.replaceAll('.', '\\.').replaceAll('*', '.*');

if (request.url.match(hostRegex)) {
httpsAgentRequestFields['cert'] = Buffer.from(clientCert.cert, 'base64');
httpsAgentRequestFields['key'] = Buffer.from(clientCert.key, 'base64');
try {
httpsAgentRequestFields['cert'] = fs.readFileSync(clientCert.certPath);
httpsAgentRequestFields['key'] = fs.readFileSync(clientCert.keyPath);
} catch (err) {
console.log('Error reading cert/key file', err);
}
httpsAgentRequestFields['passphrase'] = clientCert.passphrase;
break;
}
Expand Down

0 comments on commit e589184

Please sign in to comment.