Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support custom cacert file #187

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions packages/bruno-cli/src/runner/run-single-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,29 @@ const runSingleRequest = async function (filename, bruJson, collectionPath, coll

const options = getOptions();
const insecure = get(options, 'insecure', false);
const httpsAgentRequestFields = {};
if(insecure) {
request.httpsAgent = new https.Agent({
rejectUnauthorized: false
});
httpsAgentRequestFields['rejectUnauthorized'] = false;
}
else {
const cacert = options['cacert'];
if (cacert && cacert.length > 1) {
const cacertArray = [options['cacert'], process.env.SSL_CERT_FILE, process.env.NODE_EXTRA_CA_CERTS];
const cacert = cacertArray.find(el => el);
if(cacert && cacert.length > 1) {
try {
caCrt = fs.readFileSync(cacert)
request.httpsAgent = new https.Agent({
ca: caCrt
});
caCrt = fs.readFileSync(cacert);
httpsAgentRequestFields['ca'] = caCrt;
} catch(err) {
console.log('Error reading CA cert file:' + cacert, err);
}
}
}

if(Object.keys(httpsAgentRequestFields).length > 0) {
request.httpsAgent = new https.Agent({
...httpsAgentRequestFields
});
}

// stringify the request url encoded params
if(request.headers['content-type'] === 'application/x-www-form-urlencoded') {
request.data = qs.stringify(request.data);
Expand Down
21 changes: 19 additions & 2 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,27 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => {

const preferences = getPreferences();
const sslVerification = get(preferences, 'request.sslVerification', true);

const httpsAgentRequestFields = {};
if(!sslVerification) {
httpsAgentRequestFields['rejectUnauthorized'] = false;
}
else {
const cacertArray = [preferences['cacert'], process.env.SSL_CERT_FILE, process.env.NODE_EXTRA_CA_CERTS];
cacertFile = cacertArray.find(el => el);
if(cacertFile && cacertFile.length > 1) {
try {
const fs = require('fs');
caCrt = fs.readFileSync(cacertFile);
httpsAgentRequestFields['ca'] = caCrt;
} catch(err) {
console.log('Error reading CA cert file:' + cacertFile, err);
}
}
}

if(Object.keys(httpsAgentRequestFields).length > 0) {
request.httpsAgent = new https.Agent({
rejectUnauthorized: false
...httpsAgentRequestFields
});
}

Expand Down