Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
Bug 1527242 - Guarantee onHandshakeDone is called even it's set after…
Browse files Browse the repository at this point in the history
… handshake, r=michal

We set a `securityObserver` in `onSocketAccepted` on the main thread to observe `onHandshakeDone`, which might be too late since handshake could complete off main thread. Therefore, when we set `securityObserver` after handshake is completed, call `onHandshakeDone`.

Differential Revision: https://phabricator.services.mozilla.com/D56483

--HG--
extra : moz-landing-system : lando
  • Loading branch information
JuniorHsu committed Dec 24, 2019
1 parent bc6a80e commit 2f1ac17
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion netwerk/base/TLSServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,19 @@ TLSServerConnectionInfo::SetSecurityObserver(
nsITLSServerSecurityObserver* aObserver) {
{
MutexAutoLock lock(mLock);
if (!aObserver) {
mSecurityObserver = nullptr;
return NS_OK;
}

mSecurityObserver = new TLSServerSecurityObserverProxy(aObserver);
// Call `OnHandshakeDone` if TLS handshake is already completed.
if (mTlsVersionUsed != TLS_VERSION_UNKNOWN) {
nsCOMPtr<nsITLSServerSocket> serverSocket;
GetServerSocket(getter_AddRefs(serverSocket));
mSecurityObserver->OnHandshakeDone(serverSocket, this);
mSecurityObserver = nullptr;
}
}
return NS_OK;
}
Expand Down Expand Up @@ -405,7 +417,6 @@ nsresult TLSServerConnectionInfo::HandshakeCallback(PRFileDesc* aFD) {
if (NS_FAILED(rv)) {
return rv;
}
mTlsVersionUsed = channelInfo.protocolVersion;

SSLCipherSuiteInfo cipherInfo;
rv = MapSECStatus(SSL_GetCipherSuiteInfo(channelInfo.cipherSuite, &cipherInfo,
Expand All @@ -421,6 +432,7 @@ nsresult TLSServerConnectionInfo::HandshakeCallback(PRFileDesc* aFD) {
nsCOMPtr<nsITLSServerSecurityObserver> observer;
{
MutexAutoLock lock(mLock);
mTlsVersionUsed = channelInfo.protocolVersion;
if (!mSecurityObserver) {
return NS_OK;
}
Expand Down

0 comments on commit 2f1ac17

Please sign in to comment.