2012-04-30 08:00:22 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-31 13:33:35 +04: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/. */
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
#include "TransportSecurityInfo.h"
|
2014-01-23 05:13:19 +04:00
|
|
|
|
2016-11-22 02:58:37 +03:00
|
|
|
#include "DateTimeFormat.h"
|
2016-05-19 07:20:56 +03:00
|
|
|
#include "PSMRunnable.h"
|
|
|
|
#include "mozilla/Casting.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsIArray.h"
|
2012-04-30 08:00:22 +04:00
|
|
|
#include "nsICertOverrideService.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
2016-05-19 07:20:56 +03:00
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
#include "nsIX509CertValidity.h"
|
2012-04-30 08:00:22 +04:00
|
|
|
#include "nsNSSCertHelper.h"
|
2016-05-19 07:20:56 +03:00
|
|
|
#include "nsNSSCertificate.h"
|
|
|
|
#include "nsNSSComponent.h"
|
2018-07-13 20:30:16 +03:00
|
|
|
#include "nsNSSHelper.h"
|
2014-06-02 20:04:39 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2013-06-23 02:57:15 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2015-01-16 15:48:38 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
2018-10-02 15:59:34 +03:00
|
|
|
#include "mozpkix/pkixtypes.h"
|
2012-04-30 08:00:22 +04:00
|
|
|
#include "secerr.h"
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
//#define DEBUG_SSL_VERBOSE //Enable this define to get minimal
|
2012-04-30 08:00:22 +04:00
|
|
|
// reports when doing SSL read/write
|
2016-05-19 07:20:56 +03:00
|
|
|
|
2012-04-30 08:00:22 +04:00
|
|
|
//#define DUMP_BUFFER //Enable this define along with
|
|
|
|
// DEBUG_SSL_VERBOSE to dump SSL
|
|
|
|
// read/write buffer to a log.
|
|
|
|
// Uses PR_LOG except on Mac where
|
|
|
|
// we always write out to our own
|
|
|
|
// file.
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace psm {
|
|
|
|
|
|
|
|
TransportSecurityInfo::TransportSecurityInfo()
|
2018-09-11 03:07:30 +03:00
|
|
|
: mCipherSuite(0),
|
|
|
|
mProtocolVersion(0),
|
|
|
|
mCertificateTransparencyStatus(
|
|
|
|
nsITransportSecurityInfo::CERTIFICATE_TRANSPARENCY_NOT_APPLICABLE),
|
|
|
|
mKeaGroup(),
|
|
|
|
mSignatureSchemeName(),
|
|
|
|
mIsDomainMismatch(false),
|
|
|
|
mIsNotValidAtThisTime(false),
|
|
|
|
mIsUntrusted(false),
|
|
|
|
mIsEV(false),
|
|
|
|
mHasIsEVStatus(false),
|
|
|
|
mHaveCipherSuiteAndProtocol(false),
|
|
|
|
mHaveCertErrorBits(false),
|
2018-10-18 23:08:02 +03:00
|
|
|
mCanceled(false),
|
2018-09-11 03:07:30 +03:00
|
|
|
mMutex("TransportSecurityInfo::mMutex"),
|
2017-06-03 08:36:41 +03:00
|
|
|
mSecurityState(nsIWebProgressListener::STATE_IS_INSECURE),
|
|
|
|
mErrorCode(0),
|
|
|
|
mPort(0) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(TransportSecurityInfo, nsITransportSecurityInfo,
|
|
|
|
nsIInterfaceRequestor, nsISerializable, nsIClassInfo)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-30 08:00:22 +04:00
|
|
|
void TransportSecurityInfo::SetHostName(const char* host) {
|
2017-03-28 17:57:15 +03:00
|
|
|
mHostName.Assign(host);
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void TransportSecurityInfo::SetPort(int32_t aPort) { mPort = aPort; }
|
2012-04-30 08:00:22 +04:00
|
|
|
|
2016-11-14 13:26:15 +03:00
|
|
|
void TransportSecurityInfo::SetOriginAttributes(
|
2017-01-12 19:38:48 +03:00
|
|
|
const OriginAttributes& aOriginAttributes) {
|
2016-11-14 13:26:15 +03:00
|
|
|
mOriginAttributes = aOriginAttributes;
|
2016-10-18 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
2018-10-18 23:08:02 +03:00
|
|
|
// NB: GetErrorCode may be called before an error code is set (if ever). In that
|
|
|
|
// case, this returns (by pointer) 0, which is treated as a successful value.
|
2017-09-23 04:43:18 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetErrorCode(int32_t* state) {
|
2012-04-30 08:00:22 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
2018-10-18 23:08:02 +03:00
|
|
|
// We're in an inconsistent state if we think we've been canceled but no error
|
|
|
|
// code was set or we haven't been canceled but an error code was set.
|
|
|
|
MOZ_ASSERT(
|
|
|
|
!((mCanceled && mErrorCode == 0) || (!mCanceled && mErrorCode != 0)));
|
|
|
|
if ((mCanceled && mErrorCode == 0) || (!mCanceled && mErrorCode != 0)) {
|
|
|
|
mCanceled = true;
|
|
|
|
mErrorCode = SEC_ERROR_LIBRARY_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-09-23 04:43:18 +03:00
|
|
|
*state = mErrorCode;
|
|
|
|
return NS_OK;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
|
|
|
|
2018-03-27 14:31:52 +03:00
|
|
|
void TransportSecurityInfo::SetCanceled(PRErrorCode errorCode) {
|
2018-10-18 23:08:02 +03:00
|
|
|
MOZ_ASSERT(errorCode != 0);
|
|
|
|
if (errorCode == 0) {
|
|
|
|
errorCode = SEC_ERROR_LIBRARY_FAILURE;
|
|
|
|
}
|
2012-04-30 08:00:22 +04:00
|
|
|
|
2018-10-18 23:08:02 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
2012-04-30 08:00:22 +04:00
|
|
|
mErrorCode = errorCode;
|
2018-10-18 23:08:02 +03:00
|
|
|
mCanceled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TransportSecurityInfo::IsCanceled() { return mCanceled; }
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
TransportSecurityInfo::GetSecurityState(uint32_t* state) {
|
2012-04-30 08:00:22 +04:00
|
|
|
*state = mSecurityState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void TransportSecurityInfo::SetSecurityState(uint32_t aState) {
|
2012-04-30 08:00:22 +04:00
|
|
|
mSecurityState = aState;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-03-27 14:31:52 +03:00
|
|
|
TransportSecurityInfo::GetErrorCodeString(nsAString& aErrorString) {
|
2012-08-28 17:32:34 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
2012-04-30 08:00:22 +04:00
|
|
|
|
2018-03-27 14:31:52 +03:00
|
|
|
const char* codeName = PR_ErrorToName(mErrorCode);
|
|
|
|
aErrorString.Truncate();
|
|
|
|
if (codeName) {
|
|
|
|
aErrorString = NS_ConvertASCIItoUTF16(codeName);
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
|
|
|
|
2018-03-27 14:31:52 +03:00
|
|
|
return NS_OK;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetInterface(const nsIID& uuid, void** result) {
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_ERROR("nsNSSSocketInfo::GetInterface called off the main thread");
|
|
|
|
return NS_ERROR_NOT_SAME_THREAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (!mCallbacks) {
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> ir = new PipUIContext();
|
|
|
|
rv = ir->GetInterface(uuid, result);
|
|
|
|
} else {
|
|
|
|
rv = mCallbacks->GetInterface(uuid, result);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-01-10 23:13:03 +04:00
|
|
|
// This is a new magic value. However, it re-uses the first 4 bytes
|
|
|
|
// of the previous value. This is so when older versions attempt to
|
|
|
|
// read a newer serialized TransportSecurityInfo, they will actually
|
|
|
|
// fail and return NS_ERROR_FAILURE instead of silently failing.
|
2015-01-16 15:48:38 +03:00
|
|
|
#define TRANSPORTSECURITYINFOMAGIC \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2015-01-16 15:48:38 +03:00
|
|
|
0xa9863a23, 0x1faa, 0x4169, { \
|
|
|
|
0xb0, 0xd2, 0x81, 0x29, 0xec, 0x7c, 0xb1, 0xde \
|
|
|
|
} \
|
|
|
|
}
|
2012-04-30 08:00:22 +04:00
|
|
|
static NS_DEFINE_CID(kTransportSecurityInfoMagic, TRANSPORTSECURITYINFOMAGIC);
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-09-11 03:07:30 +03:00
|
|
|
TransportSecurityInfo::Write(nsIObjectOutputStream* aStream) {
|
|
|
|
nsresult rv = aStream->WriteID(kTransportSecurityInfoMagic);
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
rv = aStream->Write32(mSecurityState);
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
2018-09-13 20:13:43 +03:00
|
|
|
// mSubRequestsBrokenSecurity was removed in bug 748809
|
|
|
|
rv = aStream->Write32(0);
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2018-09-13 20:13:43 +03:00
|
|
|
// mSubRequestsNoSecurity was removed in bug 748809
|
|
|
|
rv = aStream->Write32(0);
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
2018-09-11 03:07:30 +03:00
|
|
|
rv = aStream->Write32(static_cast<uint32_t>(mErrorCode));
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2018-09-11 03:07:30 +03:00
|
|
|
|
|
|
|
// Re-purpose mErrorMessageCached to represent serialization version
|
|
|
|
// If string doesn't match exact version it will be treated as older
|
|
|
|
// serialization.
|
|
|
|
rv = aStream->WriteWStringZ(NS_ConvertUTF8toUTF16("1").get());
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-10-16 23:11:19 +04:00
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
// moved from nsISSLStatus
|
|
|
|
rv = NS_WriteOptionalCompoundObject(aStream, mServerCert,
|
|
|
|
NS_GET_IID(nsIX509Cert), true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->Write16(mCipherSuite);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->Write16(mProtocolVersion);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->WriteBoolean(mIsDomainMismatch);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->WriteBoolean(mIsNotValidAtThisTime);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->WriteBoolean(mIsUntrusted);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->WriteBoolean(mIsEV);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->WriteBoolean(mHasIsEVStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->WriteBoolean(mHaveCipherSuiteAndProtocol);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->WriteBoolean(mHaveCertErrorBits);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->Write16(mCertificateTransparencyStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->WriteStringZ(mKeaGroup.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->WriteStringZ(mSignatureSchemeName.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-09-08 01:50:17 +03:00
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
rv = NS_WriteOptionalCompoundObject(aStream, mSucceededCertChain,
|
|
|
|
NS_GET_IID(nsIX509CertList), true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
// END moved from nsISSLStatus
|
|
|
|
|
|
|
|
rv = NS_WriteOptionalCompoundObject(aStream, mFailedCertChain,
|
2014-08-15 22:27:22 +04:00
|
|
|
NS_GET_IID(nsIX509CertList), true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-04-30 08:00:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-02-20 01:22:35 +03:00
|
|
|
#define CHILD_DIAGNOSTIC_ASSERT(condition, message) \
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) { \
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(condition, message); \
|
|
|
|
}
|
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
// This is for backward compatability to be able to read nsISSLStatus
|
|
|
|
// serialized object.
|
|
|
|
nsresult TransportSecurityInfo::ReadSSLStatus(nsIObjectInputStream* aStream) {
|
|
|
|
bool nsISSLStatusPresent;
|
|
|
|
nsresult rv = aStream->ReadBoolean(&nsISSLStatusPresent);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!nsISSLStatusPresent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// nsISSLStatus present. Prepare to read elements.
|
|
|
|
// Throw away cid, validate iid
|
|
|
|
nsCID cid;
|
|
|
|
nsIID iid;
|
|
|
|
rv = aStream->ReadID(&cid);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadID(&iid);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
static const nsIID nsSSLStatusIID = {
|
|
|
|
0xfa9ba95b,
|
|
|
|
0xca3b,
|
|
|
|
0x498a,
|
|
|
|
{0xb8, 0x89, 0x7c, 0x79, 0xcf, 0x28, 0xfe, 0xe8}};
|
|
|
|
if (!iid.Equals(nsSSLStatusIID)) {
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(false, "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> cert;
|
|
|
|
rv = aStream->ReadObject(true, getter_AddRefs(cert));
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (cert) {
|
|
|
|
mServerCert = do_QueryInterface(cert);
|
|
|
|
if (!mServerCert) {
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(false, "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aStream->Read16(&mCipherSuite);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// The code below is a workaround to allow serializing new fields
|
|
|
|
// while preserving binary compatibility with older streams. For more details
|
|
|
|
// on the binary compatibility requirement, refer to bug 1248628.
|
|
|
|
// Here, we take advantage of the fact that mProtocolVersion was originally
|
|
|
|
// stored as a 16 bits integer, but the highest 8 bits were never used.
|
|
|
|
// These bits are now used for stream versioning.
|
|
|
|
uint16_t protocolVersionAndStreamFormatVersion;
|
|
|
|
rv = aStream->Read16(&protocolVersionAndStreamFormatVersion);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mProtocolVersion = protocolVersionAndStreamFormatVersion & 0xFF;
|
|
|
|
const uint8_t streamFormatVersion =
|
|
|
|
(protocolVersionAndStreamFormatVersion >> 8) & 0xFF;
|
|
|
|
|
|
|
|
rv = aStream->ReadBoolean(&mIsDomainMismatch);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mIsNotValidAtThisTime);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mIsUntrusted);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mIsEV);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->ReadBoolean(&mHasIsEVStatus);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mHaveCipherSuiteAndProtocol);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mHaveCertErrorBits);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Added in version 1 (see bug 1305289).
|
|
|
|
if (streamFormatVersion >= 1) {
|
|
|
|
rv = aStream->Read16(&mCertificateTransparencyStatus);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Added in version 2 (see bug 1304923).
|
|
|
|
if (streamFormatVersion >= 2) {
|
|
|
|
rv = aStream->ReadCString(mKeaGroup);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->ReadCString(mSignatureSchemeName);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Added in version 3 (see bug 1406856).
|
|
|
|
if (streamFormatVersion >= 3) {
|
|
|
|
nsCOMPtr<nsISupports> succeededCertChainSupports;
|
|
|
|
rv = NS_ReadOptionalObject(aStream, true,
|
|
|
|
getter_AddRefs(succeededCertChainSupports));
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mSucceededCertChain = do_QueryInterface(succeededCertChainSupports);
|
|
|
|
|
|
|
|
// Read only to consume bytes from the stream.
|
|
|
|
nsCOMPtr<nsISupports> failedCertChainSupports;
|
|
|
|
rv = NS_ReadOptionalObject(aStream, true,
|
|
|
|
getter_AddRefs(failedCertChainSupports));
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-04-30 08:00:22 +04:00
|
|
|
NS_IMETHODIMP
|
2018-09-11 03:07:30 +03:00
|
|
|
TransportSecurityInfo::Read(nsIObjectInputStream* aStream) {
|
2014-01-10 23:13:03 +04:00
|
|
|
nsID id;
|
2018-09-11 03:07:30 +03:00
|
|
|
nsresult rv = aStream->ReadID(&id);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
2014-01-10 23:13:03 +04:00
|
|
|
if (!id.Equals(kTransportSecurityInfoMagic)) {
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(false, "Deserialization should not fail");
|
2014-01-10 23:13:03 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
|
|
|
|
2014-01-10 23:13:03 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
2012-04-30 08:00:22 +04:00
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
rv = aStream->Read32(&mSecurityState);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
2018-09-13 20:13:43 +03:00
|
|
|
// mSubRequestsBrokenSecurity was removed in bug 748809
|
|
|
|
uint32_t unusedSubRequestsBrokenSecurity;
|
|
|
|
rv = aStream->Read32(&unusedSubRequestsBrokenSecurity);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
2018-09-13 20:13:43 +03:00
|
|
|
// mSubRequestsNoSecurity was removed in bug 748809
|
|
|
|
uint32_t unusedSubRequestsNoSecurity;
|
|
|
|
rv = aStream->Read32(&unusedSubRequestsNoSecurity);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
2015-01-16 15:48:38 +03:00
|
|
|
uint32_t errorCode;
|
2018-09-11 03:07:30 +03:00
|
|
|
rv = aStream->Read32(&errorCode);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2014-01-10 23:13:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
2015-01-16 15:48:38 +03:00
|
|
|
// PRErrorCode will be a negative value
|
|
|
|
mErrorCode = static_cast<PRErrorCode>(errorCode);
|
2018-10-18 23:08:02 +03:00
|
|
|
// If mErrorCode is non-zero, SetCanceled was called on the
|
|
|
|
// TransportSecurityInfo that was serialized.
|
|
|
|
if (mErrorCode != 0) {
|
|
|
|
mCanceled = true;
|
|
|
|
}
|
2014-10-16 23:11:19 +04:00
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
// Re-purpose mErrorMessageCached to represent serialization version
|
|
|
|
// If string doesn't match exact version it will be treated as older
|
|
|
|
// serialization.
|
|
|
|
nsAutoString serVersion;
|
|
|
|
rv = aStream->ReadString(serVersion);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2015-01-16 15:48:38 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-10-16 23:11:19 +04:00
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
// moved from nsISSLStatus
|
|
|
|
if (!serVersion.EqualsASCII("1")) {
|
|
|
|
// nsISSLStatus may be present
|
|
|
|
rv = ReadSSLStatus(aStream);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsISupports> cert;
|
|
|
|
rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(cert));
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (cert != nullptr) {
|
|
|
|
mServerCert = do_QueryInterface(cert);
|
|
|
|
if (!mServerCert) {
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(false, "Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aStream->Read16(&mCipherSuite);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->Read16(&mProtocolVersion);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->ReadBoolean(&mIsDomainMismatch);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mIsNotValidAtThisTime);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mIsUntrusted);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mIsEV);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->ReadBoolean(&mHasIsEVStatus);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mHaveCipherSuiteAndProtocol);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadBoolean(&mHaveCertErrorBits);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->Read16(&mCertificateTransparencyStatus);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->ReadCString(mKeaGroup);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->ReadCString(mSignatureSchemeName);
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> succeededCertChainSupports;
|
|
|
|
rv = NS_ReadOptionalObject(aStream, true,
|
|
|
|
getter_AddRefs(succeededCertChainSupports));
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Deserialization should not fail");
|
2018-09-11 03:07:30 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mSucceededCertChain = do_QueryInterface(succeededCertChainSupports);
|
2014-01-10 23:13:03 +04:00
|
|
|
}
|
2018-09-11 03:07:30 +03:00
|
|
|
// END moved from nsISSLStatus
|
2014-08-15 22:27:22 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> failedCertChainSupports;
|
2018-09-11 03:07:30 +03:00
|
|
|
rv = NS_ReadOptionalObject(aStream, true,
|
|
|
|
getter_AddRefs(failedCertChainSupports));
|
2019-02-20 01:22:35 +03:00
|
|
|
CHILD_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
|
2014-08-15 22:27:22 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mFailedCertChain = do_QueryInterface(failedCertChainSupports);
|
|
|
|
|
2012-04-30 08:00:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-02-20 01:22:35 +03:00
|
|
|
#undef CHILD_DIAGNOSTIC_ASSERT
|
|
|
|
|
2012-04-30 08:00:22 +04:00
|
|
|
NS_IMETHODIMP
|
2019-02-14 00:42:08 +03:00
|
|
|
TransportSecurityInfo::GetInterfaces(nsTArray<nsIID>& array) {
|
|
|
|
array.Clear();
|
2012-04-30 08:00:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-03-29 17:52:54 +03:00
|
|
|
TransportSecurityInfo::GetScriptableHelper(nsIXPCScriptable** _retval) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2012-04-30 08:00:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-10-18 05:17:26 +03:00
|
|
|
TransportSecurityInfo::GetContractID(nsACString& aContractID) {
|
|
|
|
aContractID.SetIsVoid(true);
|
2012-04-30 08:00:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-10-18 05:17:26 +03:00
|
|
|
TransportSecurityInfo::GetClassDescription(nsACString& aClassDescription) {
|
|
|
|
aClassDescription.SetIsVoid(true);
|
2012-04-30 08:00:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetClassID(nsCID** aClassID) {
|
2015-03-27 03:01:12 +03:00
|
|
|
*aClassID = (nsCID*)moz_xmalloc(sizeof(nsCID));
|
2012-04-30 08:00:22 +04:00
|
|
|
return GetClassIDNoAlloc(*aClassID);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
TransportSecurityInfo::GetFlags(uint32_t* aFlags) {
|
2012-04-30 08:00:22 +04:00
|
|
|
*aFlags = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kNSSSocketInfoCID, TRANSPORTSECURITYINFO_CID);
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetClassIDNoAlloc(nsCID* aClassIDNoAlloc) {
|
|
|
|
*aClassIDNoAlloc = kNSSSocketInfoCID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// RememberCertErrorsTable
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
/*static*/ RememberCertErrorsTable* RememberCertErrorsTable::sInstance =
|
|
|
|
nullptr;
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
RememberCertErrorsTable::RememberCertErrorsTable()
|
2013-09-02 12:41:57 +04:00
|
|
|
: mErrorHosts(), mMutex("RememberCertErrorsTable::mMutex") {}
|
2012-04-30 08:00:22 +04:00
|
|
|
|
2017-03-28 17:57:15 +03:00
|
|
|
static nsresult GetHostPortKey(TransportSecurityInfo* infoObject,
|
|
|
|
/*out*/ nsCString& result) {
|
|
|
|
MOZ_ASSERT(infoObject);
|
|
|
|
NS_ENSURE_ARG(infoObject);
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
result.Truncate();
|
|
|
|
|
2017-03-28 17:57:15 +03:00
|
|
|
result.Assign(infoObject->GetHostName());
|
2012-04-30 08:00:22 +04:00
|
|
|
result.Append(':');
|
2017-06-03 08:36:04 +03:00
|
|
|
result.AppendInt(infoObject->GetPort());
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RememberCertErrorsTable::RememberCertHasError(
|
|
|
|
TransportSecurityInfo* infoObject, SECStatus certVerificationResult) {
|
|
|
|
nsresult rv;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString hostPortKey;
|
2012-04-30 08:00:22 +04:00
|
|
|
rv = GetHostPortKey(infoObject, hostPortKey);
|
2018-09-11 03:07:30 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-04-30 08:00:22 +04:00
|
|
|
return;
|
2018-09-11 03:07:30 +03:00
|
|
|
}
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
if (certVerificationResult != SECSuccess) {
|
2018-09-11 03:07:30 +03:00
|
|
|
MOZ_ASSERT(infoObject->mHaveCertErrorBits,
|
|
|
|
"Must have error bits when remembering flags");
|
|
|
|
if (!infoObject->mHaveCertErrorBits) {
|
2012-04-30 08:00:22 +04:00
|
|
|
return;
|
2018-09-11 03:07:30 +03:00
|
|
|
}
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
CertStateBits bits;
|
2018-09-11 03:07:30 +03:00
|
|
|
bits.mIsDomainMismatch = infoObject->mIsDomainMismatch;
|
|
|
|
bits.mIsNotValidAtThisTime = infoObject->mIsNotValidAtThisTime;
|
|
|
|
bits.mIsUntrusted = infoObject->mIsUntrusted;
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
mErrorHosts.Put(hostPortKey, bits);
|
2018-09-11 03:07:30 +03:00
|
|
|
} else {
|
2012-04-30 08:00:22 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
mErrorHosts.Remove(hostPortKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
void RememberCertErrorsTable::LookupCertErrorBits(
|
|
|
|
TransportSecurityInfo* infoObject) {
|
2012-04-30 08:00:22 +04:00
|
|
|
// Get remembered error bits from our cache, because of SSL session caching
|
|
|
|
// the NSS library potentially hasn't notified us for this socket.
|
2018-09-11 03:07:30 +03:00
|
|
|
if (infoObject->mHaveCertErrorBits) {
|
2012-04-30 08:00:22 +04:00
|
|
|
// Rather do not modify bits if already set earlier
|
|
|
|
return;
|
2018-09-11 03:07:30 +03:00
|
|
|
}
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString hostPortKey;
|
2012-04-30 08:00:22 +04:00
|
|
|
rv = GetHostPortKey(infoObject, hostPortKey);
|
2018-09-11 03:07:30 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-04-30 08:00:22 +04:00
|
|
|
return;
|
2018-09-11 03:07:30 +03:00
|
|
|
}
|
2012-04-30 08:00:22 +04:00
|
|
|
|
|
|
|
CertStateBits bits;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
2018-09-11 03:07:30 +03:00
|
|
|
if (!mErrorHosts.Get(hostPortKey, &bits)) {
|
2012-04-30 08:00:22 +04:00
|
|
|
// No record was found, this host had no cert errors
|
|
|
|
return;
|
2018-09-11 03:07:30 +03:00
|
|
|
}
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This host had cert errors, update the bits correctly
|
2018-09-11 03:07:30 +03:00
|
|
|
infoObject->mHaveCertErrorBits = true;
|
|
|
|
infoObject->mIsDomainMismatch = bits.mIsDomainMismatch;
|
|
|
|
infoObject->mIsNotValidAtThisTime = bits.mIsNotValidAtThisTime;
|
|
|
|
infoObject->mIsUntrusted = bits.mIsUntrusted;
|
2012-04-30 08:00:22 +04:00
|
|
|
}
|
|
|
|
|
2015-02-27 22:33:36 +03:00
|
|
|
void TransportSecurityInfo::SetStatusErrorBits(nsNSSCertificate* cert,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t collected_errors) {
|
2012-04-30 08:00:22 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
SetServerCert(cert, EVStatus::NotEV);
|
2012-04-30 08:00:22 +04:00
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
mHaveCertErrorBits = true;
|
2012-04-30 08:00:22 +04:00
|
|
|
mIsDomainMismatch = collected_errors & nsICertOverrideService::ERROR_MISMATCH;
|
|
|
|
mIsNotValidAtThisTime = collected_errors & nsICertOverrideService::ERROR_TIME;
|
|
|
|
mIsUntrusted = collected_errors & nsICertOverrideService::ERROR_UNTRUSTED;
|
|
|
|
|
|
|
|
RememberCertErrorsTable::GetInstance().RememberCertHasError(this, SECFailure);
|
|
|
|
}
|
|
|
|
|
2014-08-15 22:27:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetFailedCertChain(nsIX509CertList** _result) {
|
2017-01-02 09:11:39 +03:00
|
|
|
MOZ_ASSERT(_result);
|
2014-08-15 22:27:22 +04:00
|
|
|
|
|
|
|
*_result = mFailedCertChain;
|
|
|
|
NS_IF_ADDREF(*_result);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-06 00:56:36 +03:00
|
|
|
nsresult TransportSecurityInfo::SetFailedCertChain(
|
|
|
|
UniqueCERTCertList certList) {
|
2014-08-15 22:27:22 +04:00
|
|
|
// nsNSSCertList takes ownership of certList
|
2018-05-30 22:15:35 +03:00
|
|
|
mFailedCertChain = new nsNSSCertList(std::move(certList));
|
2014-08-15 22:27:22 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-09-11 03:07:30 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetServerCert(nsIX509Cert** aServerCert) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aServerCert);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIX509Cert> cert = mServerCert;
|
|
|
|
cert.forget(aServerCert);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransportSecurityInfo::SetServerCert(nsNSSCertificate* aServerCert,
|
|
|
|
EVStatus aEVStatus) {
|
|
|
|
MOZ_ASSERT(aServerCert);
|
|
|
|
|
|
|
|
mServerCert = aServerCert;
|
|
|
|
mIsEV = (aEVStatus == EVStatus::EV);
|
|
|
|
mHasIsEVStatus = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetSucceededCertChain(nsIX509CertList** _result) {
|
|
|
|
NS_ENSURE_ARG_POINTER(_result);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIX509CertList> tmpList = mSucceededCertChain;
|
|
|
|
tmpList.forget(_result);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult TransportSecurityInfo::SetSucceededCertChain(
|
|
|
|
UniqueCERTCertList aCertList) {
|
|
|
|
// nsNSSCertList takes ownership of certList
|
|
|
|
mSucceededCertChain = new nsNSSCertList(std::move(aCertList));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetCipherName(nsACString& aCipherName) {
|
|
|
|
if (!mHaveCipherSuiteAndProtocol) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SSLCipherSuiteInfo cipherInfo;
|
|
|
|
if (SSL_GetCipherSuiteInfo(mCipherSuite, &cipherInfo, sizeof(cipherInfo)) !=
|
|
|
|
SECSuccess) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aCipherName.Assign(cipherInfo.cipherSuiteName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetKeyLength(uint32_t* aKeyLength) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aKeyLength);
|
|
|
|
if (!mHaveCipherSuiteAndProtocol) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SSLCipherSuiteInfo cipherInfo;
|
|
|
|
if (SSL_GetCipherSuiteInfo(mCipherSuite, &cipherInfo, sizeof(cipherInfo)) !=
|
|
|
|
SECSuccess) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aKeyLength = cipherInfo.symKeyBits;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetSecretKeyLength(uint32_t* aSecretKeyLength) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aSecretKeyLength);
|
|
|
|
if (!mHaveCipherSuiteAndProtocol) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SSLCipherSuiteInfo cipherInfo;
|
|
|
|
if (SSL_GetCipherSuiteInfo(mCipherSuite, &cipherInfo, sizeof(cipherInfo)) !=
|
|
|
|
SECSuccess) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSecretKeyLength = cipherInfo.effectiveKeyBits;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetKeaGroupName(nsACString& aKeaGroup) {
|
|
|
|
if (!mHaveCipherSuiteAndProtocol) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aKeaGroup.Assign(mKeaGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetSignatureSchemeName(nsACString& aSignatureScheme) {
|
|
|
|
if (!mHaveCipherSuiteAndProtocol) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSignatureScheme.Assign(mSignatureSchemeName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetProtocolVersion(uint16_t* aProtocolVersion) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aProtocolVersion);
|
|
|
|
if (!mHaveCipherSuiteAndProtocol) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aProtocolVersion = mProtocolVersion;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetCertificateTransparencyStatus(
|
|
|
|
uint16_t* aCertificateTransparencyStatus) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aCertificateTransparencyStatus);
|
|
|
|
|
|
|
|
*aCertificateTransparencyStatus = mCertificateTransparencyStatus;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransportSecurityInfo::SetCertificateTransparencyInfo(
|
|
|
|
const mozilla::psm::CertificateTransparencyInfo& info) {
|
|
|
|
using mozilla::ct::CTPolicyCompliance;
|
|
|
|
|
|
|
|
mCertificateTransparencyStatus =
|
|
|
|
nsITransportSecurityInfo::CERTIFICATE_TRANSPARENCY_NOT_APPLICABLE;
|
|
|
|
|
|
|
|
if (!info.enabled) {
|
|
|
|
// CT disabled.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (info.policyCompliance) {
|
|
|
|
case CTPolicyCompliance::Compliant:
|
|
|
|
mCertificateTransparencyStatus =
|
|
|
|
nsITransportSecurityInfo::CERTIFICATE_TRANSPARENCY_POLICY_COMPLIANT;
|
|
|
|
break;
|
|
|
|
case CTPolicyCompliance::NotEnoughScts:
|
|
|
|
mCertificateTransparencyStatus = nsITransportSecurityInfo ::
|
|
|
|
CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS;
|
|
|
|
break;
|
|
|
|
case CTPolicyCompliance::NotDiverseScts:
|
|
|
|
mCertificateTransparencyStatus = nsITransportSecurityInfo ::
|
|
|
|
CERTIFICATE_TRANSPARENCY_POLICY_NOT_DIVERSE_SCTS;
|
|
|
|
break;
|
|
|
|
case CTPolicyCompliance::Unknown:
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected CTPolicyCompliance type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetIsDomainMismatch(bool* aIsDomainMismatch) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsDomainMismatch);
|
|
|
|
|
|
|
|
*aIsDomainMismatch = mHaveCertErrorBits && mIsDomainMismatch;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetIsNotValidAtThisTime(bool* aIsNotValidAtThisTime) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsNotValidAtThisTime);
|
|
|
|
|
|
|
|
*aIsNotValidAtThisTime = mHaveCertErrorBits && mIsNotValidAtThisTime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetIsUntrusted(bool* aIsUntrusted) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsUntrusted);
|
|
|
|
|
|
|
|
*aIsUntrusted = mHaveCertErrorBits && mIsUntrusted;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TransportSecurityInfo::GetIsExtendedValidation(bool* aIsEV) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsEV);
|
|
|
|
*aIsEV = false;
|
|
|
|
|
|
|
|
// Never allow bad certs for EV, regardless of overrides.
|
|
|
|
if (mHaveCertErrorBits) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHasIsEVStatus) {
|
|
|
|
*aIsEV = mIsEV;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-04-30 08:00:22 +04:00
|
|
|
} // namespace psm
|
|
|
|
} // namespace mozilla
|