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:
committed by
GitHub
parent
b0a7a21f72
commit
2d1505eb2b
14
index.js
14
index.js
@ -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',
|
||||
|
||||
Reference in New Issue
Block a user