Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-872482: Fix getPeerCertificate #645

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/agent/socket_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const ocspFailOpenWarning =
'without OCSP based Certificated Revocation checking as it could not obtain a valid OCSP Response to use from ' +
'the CA OCSP responder. Details: ';

const socketSecuredEvent = 'secureConnect';

const rawOcspFlag =
process.env.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED;

Expand Down Expand Up @@ -72,7 +74,7 @@ exports.secureSocket = function (socket, host, agent, mock)
const validate = function ()
{
// stop listening for the secure event
socket.removeListener('secure', validate);
socket.removeListener(socketSecuredEvent, validate);

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

Expand All @@ -86,10 +88,11 @@ exports.secureSocket = function (socket, host, agent, mock)
{
if (!socket.authorized)
{
return socket;
Logger.getInstance().warn('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 +114,7 @@ exports.secureSocket = function (socket, host, agent, mock)
};

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

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