diff --git a/netwerk/base/TLSServerSocket.cpp b/netwerk/base/TLSServerSocket.cpp index 8d8f2e6643c86..6918b80b955b8 100644 --- a/netwerk/base/TLSServerSocket.cpp +++ b/netwerk/base/TLSServerSocket.cpp @@ -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 serverSocket; + GetServerSocket(getter_AddRefs(serverSocket)); + mSecurityObserver->OnHandshakeDone(serverSocket, this); + mSecurityObserver = nullptr; + } } return NS_OK; } @@ -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, @@ -421,6 +432,7 @@ nsresult TLSServerConnectionInfo::HandshakeCallback(PRFileDesc* aFD) { nsCOMPtr observer; { MutexAutoLock lock(mLock); + mTlsVersionUsed = channelInfo.protocolVersion; if (!mSecurityObserver) { return NS_OK; }