Skip to content

Commit

Permalink
Fix getPeerCertificate
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa committed Sep 22, 2023
1 parent 48d2049 commit 2991409
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/agent/socket_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ exports.secureSocket = function (socket, host, agent, mock)
const validate = function ()
{
// stop listening for the secure event
socket.removeListener('secure', validate);
socket.removeListener('secureConnect', validate);

Logger.getInstance().trace('socket reused = %s', socket.isSessionReused());

Expand All @@ -86,10 +86,11 @@ exports.secureSocket = function (socket, host, agent, mock)
{
if (!socket.authorized)
{
return socket;
Logger.getInstance().error('Socket is not authorized: %s', socket.authorizationError);
return socket.destroy(socket.authorizationError);
}
// use ocsp to make sure the entire certificate chain can be trusted
const certChain = socket.ssl.getPeerCertificate(true);
const certChain = socket.getPeerCertificate(true);
const vcc = mock ? mock.validateCertChain : validateCertChain;

vcc(certChain, function (err)
Expand All @@ -111,7 +112,7 @@ exports.secureSocket = function (socket, host, agent, mock)
};

// when the socket is secure, perform additional validation
socket.on('secure', validate);
socket.on('secureConnect', validate);

// block all writes until validation is complete
socket.cork();
Expand Down

0 comments on commit 2991409

Please sign in to comment.