2001-01-10 01:32:29 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-31 09:33:35 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-01-10 01:32:29 +00:00
|
|
|
|
|
|
|
#ifndef _NSNSSIOLAYER_H
|
|
|
|
#define _NSNSSIOLAYER_H
|
|
|
|
|
2012-04-30 04:00:22 +00:00
|
|
|
#include "TransportSecurityInfo.h"
|
2001-01-19 01:12:10 +00:00
|
|
|
#include "nsISSLSocketControl.h"
|
2009-05-20 22:21:51 +00:00
|
|
|
#include "nsIClientAuthDialogs.h"
|
2007-08-23 21:28:15 +00:00
|
|
|
#include "nsNSSCertificate.h"
|
2009-05-20 08:23:41 +00:00
|
|
|
#include "nsDataHashtable.h"
|
2011-11-08 20:24:09 +00:00
|
|
|
#include "nsTHashtable.h"
|
2012-11-22 20:36:59 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-10-11 07:17:19 +00:00
|
|
|
#include "sslt.h"
|
2001-01-30 02:12:53 +00:00
|
|
|
|
2012-12-07 03:05:27 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace psm {
|
|
|
|
class SharedSSLState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsIObserver;
|
|
|
|
|
2014-08-27 18:26:48 +00:00
|
|
|
class nsNSSSocketInfo MOZ_FINAL : public mozilla::psm::TransportSecurityInfo,
|
|
|
|
public nsISSLSocketControl,
|
|
|
|
public nsIClientAuthUserDecision
|
2001-01-19 01:12:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-12-07 03:05:27 +00:00
|
|
|
nsNSSSocketInfo(mozilla::psm::SharedSSLState& aState, uint32_t providerFlags);
|
2014-01-22 01:30:44 +00:00
|
|
|
|
2012-04-30 04:00:22 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2001-01-19 01:12:10 +00:00
|
|
|
NS_DECL_NSISSLSOCKETCONTROL
|
2009-05-20 22:21:51 +00:00
|
|
|
NS_DECL_NSICLIENTAUTHUSERDECISION
|
2014-01-22 01:30:44 +00:00
|
|
|
|
2014-02-20 23:14:32 +00:00
|
|
|
void SetForSTARTTLS(bool aForSTARTTLS);
|
|
|
|
bool GetForSTARTTLS();
|
2001-02-05 21:46:24 +00:00
|
|
|
|
|
|
|
nsresult GetFileDescPtr(PRFileDesc** aFilePtr);
|
|
|
|
nsresult SetFileDescPtr(PRFileDesc* aFilePtr);
|
2001-06-08 00:50:32 +00:00
|
|
|
|
2013-10-15 08:14:50 +00:00
|
|
|
bool IsHandshakePending() const { return mHandshakePending; }
|
|
|
|
void SetHandshakeNotPending() { mHandshakePending = false; }
|
2001-06-08 00:50:32 +00:00
|
|
|
|
2011-11-03 04:01:47 +00:00
|
|
|
void GetPreviousCert(nsIX509Cert** _result);
|
2014-01-22 01:30:44 +00:00
|
|
|
|
2013-10-11 07:17:19 +00:00
|
|
|
void SetTLSVersionRange(SSLVersionRange range) { mTLSVersionRange = range; }
|
|
|
|
SSLVersionRange GetTLSVersionRange() const { return mTLSVersionRange; };
|
|
|
|
|
2011-12-01 22:37:57 +00:00
|
|
|
PRStatus CloseSocketAndDestroy(
|
2014-01-22 01:30:44 +00:00
|
|
|
const nsNSSShutDownPreventionLock& proofOfLock);
|
|
|
|
|
|
|
|
void SetNegotiatedNPN(const char* value, uint32_t length);
|
2013-11-20 21:49:33 +00:00
|
|
|
|
|
|
|
void SetHandshakeCompleted();
|
2013-06-28 20:58:28 +00:00
|
|
|
void NoteTimeUntilReady();
|
2011-12-13 15:55:50 +00:00
|
|
|
|
2013-11-20 21:49:33 +00:00
|
|
|
|
|
|
|
void SetFalseStartCallbackCalled() { mFalseStartCallbackCalled = true; }
|
|
|
|
void SetFalseStarted() { mFalseStarted = true; }
|
|
|
|
|
2013-10-15 08:14:50 +00:00
|
|
|
// Note that this is only valid *during* a handshake; at the end of the handshake,
|
|
|
|
// it gets reset back to false.
|
|
|
|
void SetFullHandshake() { mIsFullHandshake = true; }
|
|
|
|
bool IsFullHandshake() const { return mIsFullHandshake; }
|
|
|
|
|
2011-12-13 15:55:50 +00:00
|
|
|
bool GetJoined() { return mJoined; }
|
|
|
|
void SetSentClientCert() { mSentClientCert = true; }
|
2012-12-07 22:57:53 +00:00
|
|
|
|
|
|
|
uint32_t GetProviderFlags() const { return mProviderFlags; }
|
|
|
|
|
2012-12-07 03:05:27 +00:00
|
|
|
mozilla::psm::SharedSSLState& SharedState();
|
|
|
|
|
2011-12-01 22:37:57 +00:00
|
|
|
// XXX: These are only used on for diagnostic purposes
|
|
|
|
enum CertVerificationState {
|
|
|
|
before_cert_verification,
|
|
|
|
waiting_for_cert_verification,
|
|
|
|
after_cert_verification
|
|
|
|
};
|
|
|
|
void SetCertVerificationWaiting();
|
|
|
|
// Use errorCode == 0 to indicate success; in that case, errorMessageType is
|
|
|
|
// ignored.
|
|
|
|
void SetCertVerificationResult(PRErrorCode errorCode,
|
|
|
|
::mozilla::psm::SSLErrorMessageType errorMessageType);
|
2014-01-22 01:30:44 +00:00
|
|
|
|
2011-12-01 22:37:57 +00:00
|
|
|
// for logging only
|
|
|
|
PRBool IsWaitingForCertVerification() const
|
|
|
|
{
|
|
|
|
return mCertVerificationState == waiting_for_cert_verification;
|
|
|
|
}
|
2013-03-27 00:06:15 +00:00
|
|
|
void AddPlaintextBytesRead(uint64_t val) { mPlaintextBytesRead += val; }
|
2013-06-28 20:58:28 +00:00
|
|
|
|
|
|
|
bool IsPreliminaryHandshakeDone() const { return mPreliminaryHandshakeDone; }
|
|
|
|
void SetPreliminaryHandshakeDone() { mPreliminaryHandshakeDone = true; }
|
|
|
|
|
2013-08-02 16:09:54 +00:00
|
|
|
void SetKEAUsed(uint16_t kea) { mKEAUsed = kea; }
|
2013-06-28 20:58:28 +00:00
|
|
|
inline int16_t GetKEAExpected() // infallible in nsISSLSocketControl
|
|
|
|
{
|
|
|
|
int16_t result;
|
|
|
|
mozilla::DebugOnly<nsresult> rv = GetKEAExpected(&result);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-05-06 21:22:25 +00:00
|
|
|
void SetKEAKeyBits(uint32_t keaBits) { mKEAKeyBits = keaBits; }
|
|
|
|
|
2013-10-10 00:21:48 +00:00
|
|
|
void SetSSLVersionUsed(int16_t version)
|
|
|
|
{
|
|
|
|
mSSLVersionUsed = version;
|
|
|
|
}
|
|
|
|
|
2014-08-04 20:54:10 +00:00
|
|
|
void SetMACAlgorithmUsed(int16_t mac) { mMACAlgorithmUsed = mac; }
|
|
|
|
|
2014-07-08 21:23:18 +00:00
|
|
|
protected:
|
|
|
|
virtual ~nsNSSSocketInfo();
|
|
|
|
|
2012-04-30 04:00:22 +00:00
|
|
|
private:
|
2001-02-05 21:46:24 +00:00
|
|
|
PRFileDesc* mFd;
|
2012-04-30 04:00:22 +00:00
|
|
|
|
2011-12-01 22:37:57 +00:00
|
|
|
CertVerificationState mCertVerificationState;
|
2011-12-01 22:36:41 +00:00
|
|
|
|
2012-12-07 03:05:27 +00:00
|
|
|
mozilla::psm::SharedSSLState& mSharedState;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mForSTARTTLS;
|
2013-10-11 07:17:19 +00:00
|
|
|
SSLVersionRange mTLSVersionRange;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mHandshakePending;
|
|
|
|
bool mRememberClientAuthCertificate;
|
2013-06-28 20:58:28 +00:00
|
|
|
bool mPreliminaryHandshakeDone; // after false start items are complete
|
2001-05-03 00:36:48 +00:00
|
|
|
|
2002-08-14 23:43:28 +00:00
|
|
|
nsresult ActivateSSL();
|
2006-04-04 13:14:40 +00:00
|
|
|
|
2011-12-13 15:55:50 +00:00
|
|
|
nsCString mNegotiatedNPN;
|
|
|
|
bool mNPNCompleted;
|
2013-11-20 21:49:33 +00:00
|
|
|
bool mFalseStartCallbackCalled;
|
|
|
|
bool mFalseStarted;
|
2013-10-15 08:14:50 +00:00
|
|
|
bool mIsFullHandshake;
|
2011-12-13 15:55:50 +00:00
|
|
|
bool mHandshakeCompleted;
|
|
|
|
bool mJoined;
|
|
|
|
bool mSentClientCert;
|
2013-06-28 20:58:28 +00:00
|
|
|
bool mNotedTimeUntilReady;
|
|
|
|
|
2014-05-06 21:22:25 +00:00
|
|
|
// mKEA* are used in false start and http/2 detetermination
|
2013-11-25 23:12:40 +00:00
|
|
|
// Values are from nsISSLSocketControl
|
2013-08-02 16:09:54 +00:00
|
|
|
int16_t mKEAUsed;
|
|
|
|
int16_t mKEAExpected;
|
2014-05-06 21:22:25 +00:00
|
|
|
uint32_t mKEAKeyBits;
|
2013-10-10 00:21:48 +00:00
|
|
|
int16_t mSSLVersionUsed;
|
2014-08-04 20:54:10 +00:00
|
|
|
int16_t mMACAlgorithmUsed;
|
2012-06-30 14:34:17 +00:00
|
|
|
|
|
|
|
uint32_t mProviderFlags;
|
2012-11-22 20:36:59 +00:00
|
|
|
mozilla::TimeStamp mSocketCreationTimestamp;
|
2013-03-27 00:06:15 +00:00
|
|
|
uint64_t mPlaintextBytesRead;
|
2014-08-07 20:32:00 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIX509Cert> mClientCert;
|
2009-05-20 08:23:41 +00:00
|
|
|
};
|
|
|
|
|
2006-04-04 13:14:40 +00:00
|
|
|
class nsSSLIOLayerHelpers
|
|
|
|
{
|
|
|
|
public:
|
2012-12-07 03:05:27 +00:00
|
|
|
nsSSLIOLayerHelpers();
|
|
|
|
~nsSSLIOLayerHelpers();
|
|
|
|
|
|
|
|
nsresult Init();
|
|
|
|
void Cleanup();
|
2006-04-04 13:14:40 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool nsSSLIOLayerInitialized;
|
2006-04-04 13:14:40 +00:00
|
|
|
static PRDescIdentity nsSSLIOLayerIdentity;
|
2013-03-27 00:06:15 +00:00
|
|
|
static PRDescIdentity nsSSLPlaintextLayerIdentity;
|
2006-04-04 13:14:40 +00:00
|
|
|
static PRIOMethods nsSSLIOLayerMethods;
|
2013-03-27 00:06:15 +00:00
|
|
|
static PRIOMethods nsSSLPlaintextLayerMethods;
|
2006-04-04 13:14:40 +00:00
|
|
|
|
2014-01-22 01:30:44 +00:00
|
|
|
nsTHashtable<nsCStringHashKey>* mRenegoUnrestrictedSites;
|
2012-12-07 03:05:27 +00:00
|
|
|
bool mTreatUnsafeNegotiationAsBroken;
|
|
|
|
int32_t mWarnLevelMissingRFC5746;
|
2010-02-07 12:09:51 +00:00
|
|
|
|
2012-12-07 03:05:27 +00:00
|
|
|
void setTreatUnsafeNegotiationAsBroken(bool broken);
|
|
|
|
bool treatUnsafeNegotiationAsBroken();
|
|
|
|
void setWarnLevelMissingRFC5746(int32_t level);
|
|
|
|
int32_t getWarnLevelMissingRFC5746();
|
2010-05-03 11:34:16 +00:00
|
|
|
|
2013-10-11 07:17:19 +00:00
|
|
|
private:
|
|
|
|
struct IntoleranceEntry
|
|
|
|
{
|
|
|
|
uint16_t tolerant;
|
|
|
|
uint16_t intolerant;
|
2012-12-07 03:05:27 +00:00
|
|
|
|
2013-10-11 07:17:19 +00:00
|
|
|
void AssertInvariant() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(intolerant == 0 || tolerant < intolerant);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
nsDataHashtable<nsCStringHashKey, IntoleranceEntry> mTLSIntoleranceInfo;
|
|
|
|
public:
|
2014-01-22 01:30:44 +00:00
|
|
|
void rememberTolerantAtVersion(const nsACString& hostname, int16_t port,
|
2013-10-11 07:17:19 +00:00
|
|
|
uint16_t tolerant);
|
2014-01-22 01:30:44 +00:00
|
|
|
bool rememberIntolerantAtVersion(const nsACString& hostname, int16_t port,
|
2013-10-11 07:17:19 +00:00
|
|
|
uint16_t intolerant, uint16_t minVersion);
|
2014-01-22 01:30:44 +00:00
|
|
|
void adjustForTLSIntolerance(const nsACString& hostname, int16_t port,
|
|
|
|
/*in/out*/ SSLVersionRange& range);
|
2012-12-07 03:05:27 +00:00
|
|
|
|
2014-01-22 01:30:44 +00:00
|
|
|
void setRenegoUnrestrictedSites(const nsCString& str);
|
|
|
|
bool isRenegoUnrestrictedSite(const nsCString& str);
|
2012-12-07 03:05:27 +00:00
|
|
|
void clearStoredData();
|
2013-06-28 20:58:28 +00:00
|
|
|
|
|
|
|
bool mFalseStartRequireNPN;
|
|
|
|
bool mFalseStartRequireForwardSecrecy;
|
2012-12-07 03:05:27 +00:00
|
|
|
private:
|
2013-10-11 07:17:19 +00:00
|
|
|
mozilla::Mutex mutex;
|
2012-12-07 03:05:27 +00:00
|
|
|
nsCOMPtr<nsIObserver> mPrefObserver;
|
2001-01-19 01:12:10 +00:00
|
|
|
};
|
2001-01-10 01:32:29 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult nsSSLIOLayerNewSocket(int32_t family,
|
2014-01-22 01:30:44 +00:00
|
|
|
const char* host,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t port,
|
2014-01-22 01:30:44 +00:00
|
|
|
const char* proxyHost,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t proxyPort,
|
2014-01-22 01:30:44 +00:00
|
|
|
PRFileDesc** fd,
|
|
|
|
nsISupports** securityInfo,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool forSTARTTLS,
|
2012-06-30 14:34:17 +00:00
|
|
|
uint32_t flags);
|
2001-01-10 01:32:29 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult nsSSLIOLayerAddToSocket(int32_t family,
|
2014-01-22 01:30:44 +00:00
|
|
|
const char* host,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t port,
|
2014-01-22 01:30:44 +00:00
|
|
|
const char* proxyHost,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t proxyPort,
|
2014-01-22 01:30:44 +00:00
|
|
|
PRFileDesc* fd,
|
|
|
|
nsISupports** securityInfo,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool forSTARTTLS,
|
2012-06-30 14:34:17 +00:00
|
|
|
uint32_t flags);
|
2001-07-24 00:42:52 +00:00
|
|
|
|
|
|
|
nsresult nsSSLIOLayerFreeTLSIntolerantSites();
|
2014-01-22 01:30:44 +00:00
|
|
|
nsresult displayUnknownCertErrorAlert(nsNSSSocketInfo* infoObject, int error);
|
2007-11-30 18:05:54 +00:00
|
|
|
|
2001-01-10 01:32:29 +00:00
|
|
|
#endif /* _NSNSSIOLAYER_H */
|