mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-24 22:11:38 +02:00
Merge pull request #617 from panda7789/bugfix/client-cert-collections
fix collection client certs
This commit is contained in:
commit
fe1e260e92
@ -662,6 +662,10 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
const timeout = get(preferences, 'request.timeout', 0);
|
const timeout = get(preferences, 'request.timeout', 0);
|
||||||
request.timeout = timeout;
|
request.timeout = timeout;
|
||||||
const sslVerification = get(preferences, 'request.sslVerification', true);
|
const sslVerification = get(preferences, 'request.sslVerification', true);
|
||||||
|
const httpsAgentRequestFields = {};
|
||||||
|
if (!sslVerification) {
|
||||||
|
httpsAgentRequestFields['rejectUnauthorized'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
// run pre-request script
|
// run pre-request script
|
||||||
const requestScript = compact([get(collectionRoot, 'request.script.req'), get(request, 'script.req')]).join(
|
const requestScript = compact([get(collectionRoot, 'request.script.req'), get(request, 'script.req')]).join(
|
||||||
@ -704,17 +708,43 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
...eventData
|
...eventData
|
||||||
});
|
});
|
||||||
|
|
||||||
// proxy configuration
|
const interpolationOptions = {
|
||||||
|
envVars,
|
||||||
|
collectionVariables,
|
||||||
|
processEnvVars
|
||||||
|
};
|
||||||
const brunoConfig = getBrunoConfig(collectionUid);
|
const brunoConfig = getBrunoConfig(collectionUid);
|
||||||
|
|
||||||
|
// client certificate config
|
||||||
|
const clientCertConfig = get(brunoConfig, 'clientCertificates.certs', []);
|
||||||
|
|
||||||
|
for (clientCert of clientCertConfig) {
|
||||||
|
const domain = interpolateString(clientCert.domain, interpolationOptions);
|
||||||
|
const certFilePath = interpolateString(clientCert.certFilePath, interpolationOptions);
|
||||||
|
const keyFilePath = interpolateString(clientCert.keyFilePath, interpolationOptions);
|
||||||
|
if (domain && certFilePath && keyFilePath) {
|
||||||
|
const hostRegex = '^https:\\/\\/' + domain.replaceAll('.', '\\.').replaceAll('*', '.*');
|
||||||
|
|
||||||
|
if (request.url.match(hostRegex)) {
|
||||||
|
try {
|
||||||
|
httpsAgentRequestFields['cert'] = fs.readFileSync(certFilePath);
|
||||||
|
httpsAgentRequestFields['key'] = fs.readFileSync(keyFilePath);
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Error reading cert/key file', err);
|
||||||
|
}
|
||||||
|
httpsAgentRequestFields['passphrase'] = interpolateString(
|
||||||
|
clientCert.passphrase,
|
||||||
|
interpolationOptions
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// proxy configuration
|
||||||
const proxyEnabled = get(brunoConfig, 'proxy.enabled', false);
|
const proxyEnabled = get(brunoConfig, 'proxy.enabled', false);
|
||||||
if (proxyEnabled) {
|
if (proxyEnabled) {
|
||||||
let proxyUri;
|
let proxyUri;
|
||||||
const interpolationOptions = {
|
|
||||||
envVars,
|
|
||||||
collectionVariables,
|
|
||||||
processEnvVars
|
|
||||||
};
|
|
||||||
|
|
||||||
const proxyProtocol = interpolateString(get(brunoConfig, 'proxy.protocol'), interpolationOptions);
|
const proxyProtocol = interpolateString(get(brunoConfig, 'proxy.protocol'), interpolationOptions);
|
||||||
const proxyHostname = interpolateString(get(brunoConfig, 'proxy.hostname'), interpolationOptions);
|
const proxyHostname = interpolateString(get(brunoConfig, 'proxy.hostname'), interpolationOptions);
|
||||||
const proxyPort = interpolateString(get(brunoConfig, 'proxy.port'), interpolationOptions);
|
const proxyPort = interpolateString(get(brunoConfig, 'proxy.port'), interpolationOptions);
|
||||||
@ -743,15 +773,16 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
request.httpsAgent = socksProxyAgent;
|
request.httpsAgent = socksProxyAgent;
|
||||||
request.httpAgent = socksProxyAgent;
|
request.httpAgent = socksProxyAgent;
|
||||||
} else {
|
} else {
|
||||||
request.httpsAgent = new HttpsProxyAgent(proxyUri, {
|
request.httpsAgent = new HttpsProxyAgent(
|
||||||
rejectUnauthorized: sslVerification
|
proxyUri,
|
||||||
});
|
Object.keys(httpsAgentRequestFields).length > 0 ? { ...httpsAgentRequestFields } : undefined
|
||||||
|
);
|
||||||
|
|
||||||
request.httpAgent = new HttpProxyAgent(proxyUri);
|
request.httpAgent = new HttpProxyAgent(proxyUri);
|
||||||
}
|
}
|
||||||
} else if (!sslVerification) {
|
} else if (Object.keys(httpsAgentRequestFields).length > 0) {
|
||||||
request.httpsAgent = new https.Agent({
|
request.httpsAgent = new https.Agent({
|
||||||
rejectUnauthorized: false
|
...httpsAgentRequestFields
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user