-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: expose Finished messages in TLSSocket
Exposes SSL_get_finished and SSL_get_peer_finished routines in OpenSSL as tlsSocket.getFinished and tlsSocket.getPeerFinished, respectively. PR-URL: #19102 Fixes: #19055 Refs: XRPLF/rippled#2413 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
729dbc5
commit f4e8bf5
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
// This test ensures that tlsSocket.getFinished() and | ||
// tlsSocket.getPeerFinished() return undefined before | ||
// secure connection is established, and return non-empty | ||
// Buffer objects with Finished messages afterwards, also | ||
// verifying alice.getFinished() == bob.getPeerFinished() | ||
// and alice.getPeerFinished() == bob.getFinished(). | ||
|
||
const assert = require('assert'); | ||
const tls = require('tls'); | ||
|
||
const msg = {}; | ||
const pem = (n) => fixtures.readKey(`${n}.pem`); | ||
const server = tls.createServer({ | ||
key: pem('agent1-key'), | ||
cert: pem('agent1-cert') | ||
}, common.mustCall((alice) => { | ||
msg.server = { | ||
alice: alice.getFinished(), | ||
bob: alice.getPeerFinished() | ||
}; | ||
server.close(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const bob = tls.connect({ | ||
port: server.address().port, | ||
rejectUnauthorized: false | ||
}, common.mustCall(() => { | ||
msg.client = { | ||
alice: bob.getPeerFinished(), | ||
bob: bob.getFinished() | ||
}; | ||
bob.end(); | ||
})); | ||
|
||
msg.before = { | ||
alice: bob.getPeerFinished(), | ||
bob: bob.getFinished() | ||
}; | ||
})); | ||
|
||
process.on('exit', () => { | ||
assert.strictEqual(undefined, msg.before.alice); | ||
assert.strictEqual(undefined, msg.before.bob); | ||
|
||
assert(Buffer.isBuffer(msg.server.alice)); | ||
assert(Buffer.isBuffer(msg.server.bob)); | ||
assert(Buffer.isBuffer(msg.client.alice)); | ||
assert(Buffer.isBuffer(msg.client.bob)); | ||
|
||
assert(msg.server.alice.length > 0); | ||
assert(msg.server.bob.length > 0); | ||
assert(msg.client.alice.length > 0); | ||
assert(msg.client.bob.length > 0); | ||
|
||
assert(msg.server.alice.equals(msg.client.alice)); | ||
assert(msg.server.bob.equals(msg.client.bob)); | ||
}); |