mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 879137, Part 3: Move PSMContentListener to its own source file, r=keeler
This commit is contained in:
parent
0fbea9b50c
commit
5c29f5b10e
@ -4,6 +4,7 @@
|
||||
|
||||
#include "CertVerifier.h"
|
||||
#include "nsNSSComponent.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "cert.h"
|
||||
#include "secerr.h"
|
||||
|
||||
|
320
security/manager/ssl/src/PSMContentListener.cpp
Normal file
320
security/manager/ssl/src/PSMContentListener.cpp
Normal file
@ -0,0 +1,320 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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/. */
|
||||
|
||||
#ifdef MOZ_LOGGING
|
||||
#define FORCE_PR_LOG 1
|
||||
#endif
|
||||
|
||||
#include "PSMContentListener.h"
|
||||
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIX509CertDB.h"
|
||||
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsNSSHelper.h"
|
||||
#include "nsNSSShutDown.h"
|
||||
|
||||
#include "prlog.h"
|
||||
|
||||
#ifdef MOZ_LOGGING
|
||||
extern PRLogModuleInfo* gPIPNSSLog;
|
||||
#endif
|
||||
|
||||
namespace mozilla { namespace psm {
|
||||
|
||||
namespace {
|
||||
|
||||
class PSMContentDownloader : public nsIStreamListener
|
||||
{
|
||||
public:
|
||||
PSMContentDownloader() {NS_ASSERTION(false, "don't use this constructor."); }
|
||||
PSMContentDownloader(uint32_t type);
|
||||
virtual ~PSMContentDownloader();
|
||||
void setSilentDownload(bool flag);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
|
||||
enum {UNKNOWN_TYPE = 0};
|
||||
enum {X509_CA_CERT = 1};
|
||||
enum {X509_USER_CERT = 2};
|
||||
enum {X509_EMAIL_CERT = 3};
|
||||
enum {X509_SERVER_CERT = 4};
|
||||
|
||||
protected:
|
||||
char* mByteData;
|
||||
int32_t mBufferOffset;
|
||||
int32_t mBufferSize;
|
||||
uint32_t mType;
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
};
|
||||
|
||||
PSMContentDownloader::PSMContentDownloader(uint32_t type)
|
||||
: mByteData(nullptr),
|
||||
mType(type)
|
||||
{
|
||||
}
|
||||
|
||||
PSMContentDownloader::~PSMContentDownloader()
|
||||
{
|
||||
if (mByteData)
|
||||
nsMemory::Free(mByteData);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(PSMContentDownloader, nsIStreamListener, nsIRequestObserver)
|
||||
|
||||
const int32_t kDefaultCertAllocLength = 2048;
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentDownloader::OnStartRequest(nsIRequest* request, nsISupports* context)
|
||||
{
|
||||
nsresult rv;
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("CertDownloader::OnStartRequest\n"));
|
||||
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
|
||||
if (!channel) return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the URI //
|
||||
channel->GetURI(getter_AddRefs(mURI));
|
||||
|
||||
int64_t contentLength;
|
||||
rv = channel->GetContentLength(&contentLength);
|
||||
if (NS_FAILED(rv) || contentLength <= 0)
|
||||
contentLength = kDefaultCertAllocLength;
|
||||
if (contentLength > INT32_MAX)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mBufferOffset = 0;
|
||||
mBufferSize = 0;
|
||||
mByteData = (char*) nsMemory::Alloc(contentLength);
|
||||
if (!mByteData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mBufferSize = int32_t(contentLength);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentDownloader::OnDataAvailable(nsIRequest* request,
|
||||
nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
uint64_t aSourceOffset,
|
||||
uint32_t aLength)
|
||||
{
|
||||
if (!mByteData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
uint32_t amt;
|
||||
nsresult err;
|
||||
//Do a check to see if we need to allocate more memory.
|
||||
if ((mBufferOffset + (int32_t)aLength) > mBufferSize) {
|
||||
size_t newSize = (mBufferOffset + aLength) *2; // grow some more than needed
|
||||
char *newBuffer;
|
||||
newBuffer = (char*)nsMemory::Realloc(mByteData, newSize);
|
||||
if (!newBuffer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
mByteData = newBuffer;
|
||||
mBufferSize = newSize;
|
||||
}
|
||||
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("CertDownloader::OnDataAvailable\n"));
|
||||
do {
|
||||
err = aIStream->Read(mByteData+mBufferOffset,
|
||||
aLength, &amt);
|
||||
if (NS_FAILED(err)) return err;
|
||||
if (amt == 0) break;
|
||||
|
||||
aLength -= amt;
|
||||
mBufferOffset += amt;
|
||||
|
||||
} while (aLength > 0);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentDownloader::OnStopRequest(nsIRequest* request,
|
||||
nsISupports* context,
|
||||
nsresult aStatus)
|
||||
{
|
||||
nsNSSShutDownPreventionLock locker;
|
||||
//Check if the download succeeded - it might have failed due to
|
||||
//network issues, etc.
|
||||
if (NS_FAILED(aStatus)){
|
||||
return aStatus;
|
||||
}
|
||||
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("CertDownloader::OnStopRequest\n"));
|
||||
|
||||
nsCOMPtr<nsIX509CertDB> certdb;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext();
|
||||
|
||||
switch (mType) {
|
||||
case PSMContentDownloader::X509_CA_CERT:
|
||||
case PSMContentDownloader::X509_USER_CERT:
|
||||
case PSMContentDownloader::X509_EMAIL_CERT:
|
||||
certdb = do_GetService(NS_X509CERTDB_CONTRACTID);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (mType) {
|
||||
case PSMContentDownloader::X509_CA_CERT:
|
||||
return certdb->ImportCertificates((uint8_t*)mByteData, mBufferOffset, mType, ctx);
|
||||
case PSMContentDownloader::X509_USER_CERT:
|
||||
return certdb->ImportUserCertificate((uint8_t*)mByteData, mBufferOffset, ctx);
|
||||
case PSMContentDownloader::X509_EMAIL_CERT:
|
||||
return certdb->ImportEmailCertificate((uint8_t*)mByteData, mBufferOffset, ctx);
|
||||
default:
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* other mime types that we should handle sometime:
|
||||
|
||||
application/x-pkcs7-mime
|
||||
application/pkcs7-signature
|
||||
application/pre-encrypted
|
||||
|
||||
*/
|
||||
|
||||
uint32_t
|
||||
getPSMContentType(const char * aContentType)
|
||||
{
|
||||
// Don't forget to update the registration of content listeners in nsNSSModule.cpp
|
||||
// for every supported content type.
|
||||
|
||||
if (!nsCRT::strcasecmp(aContentType, "application/x-x509-ca-cert"))
|
||||
return PSMContentDownloader::X509_CA_CERT;
|
||||
else if (!nsCRT::strcasecmp(aContentType, "application/x-x509-server-cert"))
|
||||
return PSMContentDownloader::X509_SERVER_CERT;
|
||||
else if (!nsCRT::strcasecmp(aContentType, "application/x-x509-user-cert"))
|
||||
return PSMContentDownloader::X509_USER_CERT;
|
||||
else if (!nsCRT::strcasecmp(aContentType, "application/x-x509-email-cert"))
|
||||
return PSMContentDownloader::X509_EMAIL_CERT;
|
||||
|
||||
return PSMContentDownloader::UNKNOWN_TYPE;
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
NS_IMPL_ISUPPORTS2(PSMContentListener,
|
||||
nsIURIContentListener,
|
||||
nsISupportsWeakReference)
|
||||
|
||||
PSMContentListener::PSMContentListener()
|
||||
{
|
||||
mLoadCookie = nullptr;
|
||||
mParentContentListener = nullptr;
|
||||
}
|
||||
|
||||
PSMContentListener::~PSMContentListener()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
PSMContentListener::init()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::OnStartURIOpen(nsIURI *aURI, bool *aAbortOpen)
|
||||
{
|
||||
//if we don't want to handle the URI, return true in
|
||||
//*aAbortOpen
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::IsPreferred(const char * aContentType,
|
||||
char ** aDesiredContentType,
|
||||
bool * aCanHandleContent)
|
||||
{
|
||||
return CanHandleContent(aContentType, true,
|
||||
aDesiredContentType, aCanHandleContent);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::CanHandleContent(const char * aContentType,
|
||||
bool aIsContentPreferred,
|
||||
char ** aDesiredContentType,
|
||||
bool * aCanHandleContent)
|
||||
{
|
||||
uint32_t type;
|
||||
type = getPSMContentType(aContentType);
|
||||
if (type == PSMContentDownloader::UNKNOWN_TYPE) {
|
||||
*aCanHandleContent = false;
|
||||
} else {
|
||||
*aCanHandleContent = true;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::DoContent(const char * aContentType,
|
||||
bool aIsContentPreferred,
|
||||
nsIRequest * aRequest,
|
||||
nsIStreamListener ** aContentHandler,
|
||||
bool * aAbortProcess)
|
||||
{
|
||||
PSMContentDownloader *downLoader;
|
||||
uint32_t type;
|
||||
type = getPSMContentType(aContentType);
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("PSMContentListener::DoContent\n"));
|
||||
if (type != PSMContentDownloader::UNKNOWN_TYPE) {
|
||||
downLoader = new PSMContentDownloader(type);
|
||||
if (downLoader) {
|
||||
downLoader->QueryInterface(NS_GET_IID(nsIStreamListener),
|
||||
(void **)aContentHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::GetLoadCookie(nsISupports * *aLoadCookie)
|
||||
{
|
||||
*aLoadCookie = mLoadCookie;
|
||||
NS_IF_ADDREF(*aLoadCookie);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::SetLoadCookie(nsISupports * aLoadCookie)
|
||||
{
|
||||
mLoadCookie = aLoadCookie;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::GetParentContentListener(nsIURIContentListener ** aContentListener)
|
||||
{
|
||||
*aContentListener = mParentContentListener;
|
||||
NS_IF_ADDREF(*aContentListener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::SetParentContentListener(nsIURIContentListener * aContentListener)
|
||||
{
|
||||
mParentContentListener = aContentListener;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} } // namespace mozilla::psm
|
35
security/manager/ssl/src/PSMContentListener.h
Normal file
35
security/manager/ssl/src/PSMContentListener.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_psm_PSMCOntentListener_h_
|
||||
#define mozilla_psm_PSMCOntentListener_h_
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIURIContentListener.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
#define NS_PSMCONTENTLISTEN_CID {0xc94f4a30, 0x64d7, 0x11d4, {0x99, 0x60, 0x00, 0xb0, 0xd0, 0x23, 0x54, 0xa0}}
|
||||
#define NS_PSMCONTENTLISTEN_CONTRACTID "@mozilla.org/security/psmdownload;1"
|
||||
|
||||
namespace mozilla { namespace psm {
|
||||
|
||||
class PSMContentListener : public nsIURIContentListener,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
PSMContentListener();
|
||||
virtual ~PSMContentListener();
|
||||
nsresult init();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIURICONTENTLISTENER
|
||||
private:
|
||||
nsCOMPtr<nsISupports> mLoadCookie;
|
||||
nsCOMPtr<nsIURIContentListener> mParentContentListener;
|
||||
};
|
||||
|
||||
} } // namespace mozilla::psm
|
||||
|
||||
#endif // mozilla_psm_PSMCOntentListener_h
|
@ -109,6 +109,7 @@
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "nsIThreadPool.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsXPCOMCIDInternal.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "nsNSSCertHelper.h"
|
||||
#include "nsIProgrammingLanguage.h"
|
||||
#include "nsIArray.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "PSMRunnable.h"
|
||||
#include "ScopedNSSTypes.h"
|
||||
|
||||
|
@ -66,6 +66,7 @@ CPP_SOURCES += [
|
||||
'nsStreamCipher.cpp',
|
||||
'nsTLSSocketProvider.cpp',
|
||||
'nsUsageArrayHelper.cpp',
|
||||
'PSMContentListener.cpp',
|
||||
'PSMRunnable.cpp',
|
||||
'SharedSSLState.cpp',
|
||||
'SSLServerCertVerification.cpp',
|
||||
|
@ -12,9 +12,9 @@
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsISaveAsCharset.h"
|
||||
#include "nsNativeCharsetUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
||||
#include "nsNSSComponent.h"
|
||||
#include "nsKeygenHandler.h"
|
||||
#include "nsKeygenThread.h"
|
||||
#include "nsNSSCertificate.h"
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "nsIConsoleService.h"
|
||||
#include "nsIHttpChannelInternal.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "SharedSSLState.h"
|
||||
|
||||
#include "ssl.h"
|
||||
|
@ -10,12 +10,14 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNSSCertificate.h"
|
||||
#include "secder.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsNSSCertValidity.h"
|
||||
#include "nsNSSASN1Object.h"
|
||||
#include "nsNSSComponent.h"
|
||||
#include "nsNSSCertTrust.h"
|
||||
#include "nsIDateTimeFormat.h"
|
||||
#include "nsDateTimeFormatCID.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace mozilla;
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "CertVerifier.h"
|
||||
#include "nsCertVerificationThread.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsICertOverrideService.h"
|
||||
#include "nsIPrefService.h"
|
||||
@ -35,12 +35,14 @@
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsNTLMAuthModule.h"
|
||||
|
||||
#include "nsIFile.h"
|
||||
#include "nsIProperties.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsCertificatePrincipal.h"
|
||||
#include "nsIBufEntropyCollector.h"
|
||||
#include "nsITokenPasswordDialogs.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsNSSShutDown.h"
|
||||
#include "GeneratedEvents.h"
|
||||
#include "SharedSSLState.h"
|
||||
@ -1958,264 +1960,3 @@ setPassword(PK11SlotInfo *slot, nsIInterfaceRequestor *ctx)
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
PSMContentDownloader::PSMContentDownloader(uint32_t type)
|
||||
: mByteData(nullptr),
|
||||
mType(type)
|
||||
{
|
||||
}
|
||||
|
||||
PSMContentDownloader::~PSMContentDownloader()
|
||||
{
|
||||
if (mByteData)
|
||||
nsMemory::Free(mByteData);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(PSMContentDownloader, nsIStreamListener, nsIRequestObserver)
|
||||
|
||||
const int32_t kDefaultCertAllocLength = 2048;
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentDownloader::OnStartRequest(nsIRequest* request, nsISupports* context)
|
||||
{
|
||||
nsresult rv;
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("CertDownloader::OnStartRequest\n"));
|
||||
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
|
||||
if (!channel) return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the URI //
|
||||
channel->GetURI(getter_AddRefs(mURI));
|
||||
|
||||
int64_t contentLength;
|
||||
rv = channel->GetContentLength(&contentLength);
|
||||
if (NS_FAILED(rv) || contentLength <= 0)
|
||||
contentLength = kDefaultCertAllocLength;
|
||||
if (contentLength > INT32_MAX)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mBufferOffset = 0;
|
||||
mBufferSize = 0;
|
||||
mByteData = (char*) nsMemory::Alloc(contentLength);
|
||||
if (!mByteData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mBufferSize = int32_t(contentLength);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentDownloader::OnDataAvailable(nsIRequest* request,
|
||||
nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
uint64_t aSourceOffset,
|
||||
uint32_t aLength)
|
||||
{
|
||||
if (!mByteData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
uint32_t amt;
|
||||
nsresult err;
|
||||
//Do a check to see if we need to allocate more memory.
|
||||
if ((mBufferOffset + (int32_t)aLength) > mBufferSize) {
|
||||
size_t newSize = (mBufferOffset + aLength) *2; // grow some more than needed
|
||||
char *newBuffer;
|
||||
newBuffer = (char*)nsMemory::Realloc(mByteData, newSize);
|
||||
if (!newBuffer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
mByteData = newBuffer;
|
||||
mBufferSize = newSize;
|
||||
}
|
||||
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("CertDownloader::OnDataAvailable\n"));
|
||||
do {
|
||||
err = aIStream->Read(mByteData+mBufferOffset,
|
||||
aLength, &amt);
|
||||
if (NS_FAILED(err)) return err;
|
||||
if (amt == 0) break;
|
||||
|
||||
aLength -= amt;
|
||||
mBufferOffset += amt;
|
||||
|
||||
} while (aLength > 0);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentDownloader::OnStopRequest(nsIRequest* request,
|
||||
nsISupports* context,
|
||||
nsresult aStatus)
|
||||
{
|
||||
nsNSSShutDownPreventionLock locker;
|
||||
//Check if the download succeeded - it might have failed due to
|
||||
//network issues, etc.
|
||||
if (NS_FAILED(aStatus)){
|
||||
return aStatus;
|
||||
}
|
||||
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("CertDownloader::OnStopRequest\n"));
|
||||
|
||||
nsCOMPtr<nsIX509CertDB> certdb;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext();
|
||||
|
||||
switch (mType) {
|
||||
case PSMContentDownloader::X509_CA_CERT:
|
||||
case PSMContentDownloader::X509_USER_CERT:
|
||||
case PSMContentDownloader::X509_EMAIL_CERT:
|
||||
certdb = do_GetService(NS_X509CERTDB_CONTRACTID);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (mType) {
|
||||
case PSMContentDownloader::X509_CA_CERT:
|
||||
return certdb->ImportCertificates((uint8_t*)mByteData, mBufferOffset, mType, ctx);
|
||||
case PSMContentDownloader::X509_USER_CERT:
|
||||
return certdb->ImportUserCertificate((uint8_t*)mByteData, mBufferOffset, ctx);
|
||||
case PSMContentDownloader::X509_EMAIL_CERT:
|
||||
return certdb->ImportEmailCertificate((uint8_t*)mByteData, mBufferOffset, ctx);
|
||||
default:
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* other mime types that we should handle sometime:
|
||||
|
||||
application/x-pkcs7-mime
|
||||
application/pkcs7-signature
|
||||
application/pre-encrypted
|
||||
|
||||
*/
|
||||
|
||||
uint32_t
|
||||
getPSMContentType(const char * aContentType)
|
||||
{
|
||||
// Don't forget to update the registration of content listeners in nsNSSModule.cpp
|
||||
// for every supported content type.
|
||||
|
||||
if (!nsCRT::strcasecmp(aContentType, "application/x-x509-ca-cert"))
|
||||
return PSMContentDownloader::X509_CA_CERT;
|
||||
else if (!nsCRT::strcasecmp(aContentType, "application/x-x509-server-cert"))
|
||||
return PSMContentDownloader::X509_SERVER_CERT;
|
||||
else if (!nsCRT::strcasecmp(aContentType, "application/x-x509-user-cert"))
|
||||
return PSMContentDownloader::X509_USER_CERT;
|
||||
else if (!nsCRT::strcasecmp(aContentType, "application/x-x509-email-cert"))
|
||||
return PSMContentDownloader::X509_EMAIL_CERT;
|
||||
|
||||
return PSMContentDownloader::UNKNOWN_TYPE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS2(PSMContentListener,
|
||||
nsIURIContentListener,
|
||||
nsISupportsWeakReference)
|
||||
|
||||
PSMContentListener::PSMContentListener()
|
||||
{
|
||||
mLoadCookie = nullptr;
|
||||
mParentContentListener = nullptr;
|
||||
}
|
||||
|
||||
PSMContentListener::~PSMContentListener()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
PSMContentListener::init()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::OnStartURIOpen(nsIURI *aURI, bool *aAbortOpen)
|
||||
{
|
||||
//if we don't want to handle the URI, return true in
|
||||
//*aAbortOpen
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::IsPreferred(const char * aContentType,
|
||||
char ** aDesiredContentType,
|
||||
bool * aCanHandleContent)
|
||||
{
|
||||
return CanHandleContent(aContentType, true,
|
||||
aDesiredContentType, aCanHandleContent);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::CanHandleContent(const char * aContentType,
|
||||
bool aIsContentPreferred,
|
||||
char ** aDesiredContentType,
|
||||
bool * aCanHandleContent)
|
||||
{
|
||||
uint32_t type;
|
||||
type = getPSMContentType(aContentType);
|
||||
if (type == PSMContentDownloader::UNKNOWN_TYPE) {
|
||||
*aCanHandleContent = false;
|
||||
} else {
|
||||
*aCanHandleContent = true;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::DoContent(const char * aContentType,
|
||||
bool aIsContentPreferred,
|
||||
nsIRequest * aRequest,
|
||||
nsIStreamListener ** aContentHandler,
|
||||
bool * aAbortProcess)
|
||||
{
|
||||
PSMContentDownloader *downLoader;
|
||||
uint32_t type;
|
||||
type = getPSMContentType(aContentType);
|
||||
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("PSMContentListener::DoContent\n"));
|
||||
if (type != PSMContentDownloader::UNKNOWN_TYPE) {
|
||||
downLoader = new PSMContentDownloader(type);
|
||||
if (downLoader) {
|
||||
downLoader->QueryInterface(NS_GET_IID(nsIStreamListener),
|
||||
(void **)aContentHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::GetLoadCookie(nsISupports * *aLoadCookie)
|
||||
{
|
||||
*aLoadCookie = mLoadCookie;
|
||||
NS_IF_ADDREF(*aLoadCookie);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::SetLoadCookie(nsISupports * aLoadCookie)
|
||||
{
|
||||
mLoadCookie = aLoadCookie;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::GetParentContentListener(nsIURIContentListener ** aContentListener)
|
||||
{
|
||||
*aContentListener = mParentContentListener;
|
||||
NS_IF_ADDREF(*aContentListener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PSMContentListener::SetParentContentListener(nsIURIContentListener * aContentListener)
|
||||
{
|
||||
mParentContentListener = aContentListener;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -11,19 +11,15 @@
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISignatureVerifier.h"
|
||||
#include "nsIURIContentListener.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIEntropyCollector.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsWeakReference.h"
|
||||
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#endif
|
||||
#include "nsINSSErrorsService.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsNSSCallbacks.h"
|
||||
#include "ScopedNSSTypes.h"
|
||||
#include "nsNSSHelper.h"
|
||||
@ -53,9 +49,6 @@ class CertVerifier;
|
||||
{ 0x6ffbb526, 0x205b, 0x49c5, \
|
||||
{ 0xae, 0x3f, 0x59, 0x59, 0xc0, 0x84, 0x7, 0x5e } }
|
||||
|
||||
#define NS_PSMCONTENTLISTEN_CID {0xc94f4a30, 0x64d7, 0x11d4, {0x99, 0x60, 0x00, 0xb0, 0xd0, 0x23, 0x54, 0xa0}}
|
||||
#define NS_PSMCONTENTLISTEN_CONTRACTID "@mozilla.org/security/psmdownload;1"
|
||||
|
||||
enum EnsureNSSOperator
|
||||
{
|
||||
nssLoadingComponent = 0,
|
||||
@ -68,35 +61,6 @@ enum EnsureNSSOperator
|
||||
|
||||
extern bool EnsureNSSInitialized(EnsureNSSOperator op);
|
||||
|
||||
//--------------------------------------------
|
||||
// Now we need a content listener to register
|
||||
//--------------------------------------------
|
||||
class PSMContentDownloader : public nsIStreamListener
|
||||
{
|
||||
public:
|
||||
PSMContentDownloader() {NS_ASSERTION(false, "don't use this constructor."); }
|
||||
PSMContentDownloader(uint32_t type);
|
||||
virtual ~PSMContentDownloader();
|
||||
void setSilentDownload(bool flag);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
|
||||
enum {UNKNOWN_TYPE = 0};
|
||||
enum {X509_CA_CERT = 1};
|
||||
enum {X509_USER_CERT = 2};
|
||||
enum {X509_EMAIL_CERT = 3};
|
||||
enum {X509_SERVER_CERT = 4};
|
||||
|
||||
protected:
|
||||
char* mByteData;
|
||||
int32_t mBufferOffset;
|
||||
int32_t mBufferSize;
|
||||
uint32_t mType;
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
};
|
||||
|
||||
class nsNSSComponent;
|
||||
|
||||
class NS_NO_VTABLE nsINSSComponent : public nsISupports {
|
||||
@ -264,20 +228,6 @@ public:
|
||||
static bool globalConstFlagUsePKIXVerification;
|
||||
};
|
||||
|
||||
class PSMContentListener : public nsIURIContentListener,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
PSMContentListener();
|
||||
virtual ~PSMContentListener();
|
||||
nsresult init();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIURICONTENTLISTENER
|
||||
private:
|
||||
nsCOMPtr<nsISupports> mLoadCookie;
|
||||
nsCOMPtr<nsIURIContentListener> mParentContentListener;
|
||||
};
|
||||
|
||||
class nsNSSErrors
|
||||
{
|
||||
public:
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "nsClientAuthRemember.h"
|
||||
#include "nsISSLErrorListener.h"
|
||||
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "SSLServerCertVerification.h"
|
||||
#include "nsNSSCertHelper.h"
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "nsCryptoHash.h"
|
||||
//For the NS_CRYPTO_CONTRACTID define
|
||||
#include "nsDOMCID.h"
|
||||
|
||||
#include "nsNetCID.h"
|
||||
#include "nsCMSSecureMessage.h"
|
||||
#include "nsCertPicker.h"
|
||||
#include "nsCURILoader.h"
|
||||
@ -44,6 +44,9 @@
|
||||
#include "nsNSSVersion.h"
|
||||
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
#include "PSMContentListener.h"
|
||||
|
||||
#define NS_IS_PROCESS_DEFAULT \
|
||||
(GeckoProcessType_Default == XRE_GetProcessType())
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "secerr.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsNSSComponent.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
#include "nsPK11TokenDB.h"
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "plstr.h"
|
||||
#include "plbase64.h"
|
||||
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
@ -18,6 +19,7 @@
|
||||
#include "nsITokenPasswordDialogs.h"
|
||||
|
||||
#include "nsISecretDecoderRing.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsSDR.h"
|
||||
#include "nsNSSComponent.h"
|
||||
#include "nsNSSShutDown.h"
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "nsNSSComponent.h"
|
||||
#include "nsSmartCardMonitor.h"
|
||||
#include "nsIDOMSmartCardEvent.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsNSSCertificate.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
#include "nspr.h"
|
||||
#include "secerr.h"
|
||||
|
Loading…
Reference in New Issue
Block a user