Support CA fingerprint validation (#1499)

Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>
Co-authored-by: Ioannis Kakavas <ioannis@elastic.co>
This commit is contained in:
Tomas Della Vedova
2021-08-02 11:20:31 +02:00
committed by GitHub
parent b0a7a21f72
commit 2d1505eb2b
12 changed files with 337 additions and 4 deletions

View File

@ -102,6 +102,7 @@ class Client extends ESAPI {
suggestCompression: false,
compression: false,
ssl: null,
caFingerprint: null,
agent: null,
headers: {},
nodeFilter: null,
@ -116,6 +117,10 @@ class Client extends ESAPI {
disablePrototypePoisoningProtection: false
}, opts)
if (options.caFingerprint !== null && isHttpConnection(opts.node || opts.nodes)) {
throw new ConfigurationError('You can\'t configure the caFingerprint with a http connection')
}
if (process.env.ELASTIC_CLIENT_APIVERSIONING === 'true') {
options.headers = Object.assign({ accept: 'application/vnd.elasticsearch+json; compatible-with=7' }, options.headers)
}
@ -146,6 +151,7 @@ class Client extends ESAPI {
Connection: options.Connection,
auth: options.auth,
emit: this[kEventEmitter].emit.bind(this[kEventEmitter]),
caFingerprint: options.caFingerprint,
sniffEnabled: options.sniffInterval !== false ||
options.sniffOnStart !== false ||
options.sniffOnConnectionFault !== false
@ -315,6 +321,14 @@ function getAuth (node) {
}
}
function isHttpConnection (node) {
if (Array.isArray(node)) {
return node.some((n) => new URL(n).protocol === 'http:')
} else {
return new URL(node).protocol === 'http:'
}
}
const events = {
RESPONSE: 'response',
REQUEST: 'request',