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
@ -19,6 +19,7 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
const crypto = require('crypto')
|
||||
const debug = require('debug')('elasticsearch-test')
|
||||
const stoppable = require('stoppable')
|
||||
|
||||
@ -35,6 +36,13 @@ const secureOpts = {
|
||||
cert: readFileSync(join(__dirname, '..', 'fixtures', 'https.cert'), 'utf8')
|
||||
}
|
||||
|
||||
const caFingerprint = getFingerprint(secureOpts.cert
|
||||
.split('\n')
|
||||
.slice(1, -1)
|
||||
.map(line => line.trim())
|
||||
.join('')
|
||||
)
|
||||
|
||||
let id = 0
|
||||
function buildServer (handler, opts, cb) {
|
||||
const serverId = id++
|
||||
@ -58,7 +66,7 @@ function buildServer (handler, opts, cb) {
|
||||
server.listen(0, () => {
|
||||
const port = server.address().port
|
||||
debug(`Server '${serverId}' booted on port ${port}`)
|
||||
resolve([Object.assign({}, secureOpts, { port }), server])
|
||||
resolve([Object.assign({}, secureOpts, { port, caFingerprint }), server])
|
||||
})
|
||||
})
|
||||
} else {
|
||||
@ -70,4 +78,11 @@ function buildServer (handler, opts, cb) {
|
||||
}
|
||||
}
|
||||
|
||||
function getFingerprint (content, inputEncoding = 'base64', outputEncoding = 'hex') {
|
||||
const shasum = crypto.createHash('sha256')
|
||||
shasum.update(content, inputEncoding)
|
||||
const res = shasum.digest(outputEncoding)
|
||||
return res.toUpperCase().match(/.{1,2}/g).join(':')
|
||||
}
|
||||
|
||||
module.exports = buildServer
|
||||
|
||||
Reference in New Issue
Block a user