2001-01-10 01:32:29 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2004-04-25 15:03:26 +00:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-01-10 01:32:29 +00:00
|
|
|
*
|
2004-04-25 15:03:26 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2001-01-10 01:32:29 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-25 15:03:26 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-01-10 01:32:29 +00:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Hubbie Shaw
|
|
|
|
* Doug Turner <dougt@netscape.com>
|
2003-09-29 06:04:02 +00:00
|
|
|
* Brian Ryner <bryner@brianryner.com>
|
2001-11-29 23:36:34 +00:00
|
|
|
* Kai Engert <kaie@netscape.com>
|
2006-04-04 13:14:40 +00:00
|
|
|
* Kai Engert <kengert@redhat.com>
|
2004-04-25 15:03:26 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-01-10 01:32:29 +00:00
|
|
|
|
2001-01-19 01:12:10 +00:00
|
|
|
#ifndef _nsNSSComponent_h_
|
|
|
|
#define _nsNSSComponent_h_
|
|
|
|
|
2001-02-06 20:09:27 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-01-10 01:32:29 +00:00
|
|
|
#include "nsISignatureVerifier.h"
|
2001-02-26 21:50:54 +00:00
|
|
|
#include "nsIURIContentListener.h"
|
2001-12-06 22:36:45 +00:00
|
|
|
#include "nsIStreamListener.h"
|
2001-01-25 01:14:23 +00:00
|
|
|
#include "nsIEntropyCollector.h"
|
|
|
|
#include "nsString.h"
|
2001-02-06 20:09:27 +00:00
|
|
|
#include "nsIStringBundle.h"
|
2005-06-02 01:17:35 +00:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2004-09-07 18:54:02 +00:00
|
|
|
#include "nsIPrefBranch.h"
|
2001-10-19 22:48:01 +00:00
|
|
|
#include "nsIObserver.h"
|
2001-03-13 21:50:23 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsWeakReference.h"
|
2001-05-23 22:06:43 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2005-06-02 01:17:35 +00:00
|
|
|
#include "nsSmartCardMonitor.h"
|
2007-02-17 03:47:59 +00:00
|
|
|
#include "nsINSSErrorsService.h"
|
2001-12-06 22:36:45 +00:00
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "prlock.h"
|
2005-06-01 16:06:53 +00:00
|
|
|
#include "nsICryptoHash.h"
|
|
|
|
#include "hasht.h"
|
2006-04-04 13:14:40 +00:00
|
|
|
#include "nsNSSCallbacks.h"
|
2001-01-10 01:32:29 +00:00
|
|
|
|
2001-02-10 02:53:10 +00:00
|
|
|
#include "nsNSSHelper.h"
|
|
|
|
|
2001-01-10 01:32:29 +00:00
|
|
|
#define NS_NSSCOMPONENT_CID \
|
|
|
|
{0xa277189c, 0x1dd1, 0x11b2, {0xa8, 0xc9, 0xe4, 0xe8, 0xbf, 0xb1, 0x33, 0x8e}}
|
|
|
|
|
2002-09-17 19:09:11 +00:00
|
|
|
#define PSM_COMPONENT_CONTRACTID "@mozilla.org/psm;1"
|
|
|
|
#define PSM_COMPONENT_CLASSNAME "Mozilla PSM Component"
|
|
|
|
|
2001-02-07 19:00:52 +00:00
|
|
|
//Define an interface that we can use to look up from the
|
|
|
|
//callbacks passed to NSS.
|
|
|
|
|
|
|
|
#define NS_INSSCOMPONENT_IID_STR "d4b49dd6-1dd1-11b2-b6fe-b14cfaf69cbd"
|
|
|
|
#define NS_INSSCOMPONENT_IID \
|
|
|
|
{0xd4b49dd6, 0x1dd1, 0x11b2, \
|
|
|
|
{ 0xb6, 0xfe, 0xb1, 0x4c, 0xfa, 0xf6, 0x9c, 0xbd }}
|
|
|
|
|
2001-05-19 01:20:18 +00:00
|
|
|
#define NS_PSMCONTENTLISTEN_CID {0xc94f4a30, 0x64d7, 0x11d4, {0x99, 0x60, 0x00, 0xb0, 0xd0, 0x23, 0x54, 0xa0}}
|
|
|
|
#define NS_PSMCONTENTLISTEN_CONTRACTID "@mozilla.org/security/psmdownload;1"
|
2001-02-26 21:50:54 +00:00
|
|
|
|
2005-06-01 16:06:53 +00:00
|
|
|
#define NS_CRYPTO_HASH_CLASSNAME "Mozilla Cryto Hash Function Component"
|
|
|
|
#define NS_CRYPTO_HASH_CID {0x36a1d3b3, 0xd886, 0x4317, {0x96, 0xff, 0x87, 0xb0, 0x00, 0x5c, 0xfe, 0xf7}}
|
|
|
|
|
2001-12-06 22:36:45 +00:00
|
|
|
//--------------------------------------------
|
|
|
|
// Now we need a content listener to register
|
|
|
|
//--------------------------------------------
|
|
|
|
class PSMContentDownloader : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PSMContentDownloader() {NS_ASSERTION(PR_FALSE, "don't use this constructor."); }
|
|
|
|
PSMContentDownloader(PRUint32 type);
|
|
|
|
virtual ~PSMContentDownloader();
|
|
|
|
void setSilentDownload(PRBool flag);
|
|
|
|
void setCrlAutodownloadKey(nsAutoString key);
|
|
|
|
|
|
|
|
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};
|
|
|
|
enum {PKCS7_CRL = 5};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
char* mByteData;
|
|
|
|
PRInt32 mBufferOffset;
|
2002-05-07 09:29:23 +00:00
|
|
|
PRInt32 mBufferSize;
|
2001-12-06 22:36:45 +00:00
|
|
|
PRUint32 mType;
|
|
|
|
PRBool mDoSilentDownload;
|
|
|
|
nsAutoString mCrlAutoDownloadKey;
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
nsresult handleContentDownloadError(nsresult errCode);
|
|
|
|
};
|
2001-02-26 21:50:54 +00:00
|
|
|
|
2001-02-07 19:00:52 +00:00
|
|
|
class NS_NO_VTABLE nsINSSComponent : public nsISupports {
|
|
|
|
public:
|
2005-11-11 14:36:26 +00:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INSSCOMPONENT_IID)
|
2001-02-07 19:00:52 +00:00
|
|
|
|
2004-02-26 04:07:23 +00:00
|
|
|
NS_IMETHOD GetPIPNSSBundleString(const char *name,
|
2001-12-21 06:16:24 +00:00
|
|
|
nsAString &outString) = 0;
|
2004-02-26 04:07:23 +00:00
|
|
|
NS_IMETHOD PIPBundleFormatStringFromName(const char *name,
|
2001-02-07 19:00:52 +00:00
|
|
|
const PRUnichar **params,
|
|
|
|
PRUint32 numParams,
|
2004-02-26 04:07:23 +00:00
|
|
|
nsAString &outString) = 0;
|
2001-02-07 19:00:52 +00:00
|
|
|
|
2001-08-10 01:05:57 +00:00
|
|
|
// This method will just disable OCSP in NSS, it will not
|
|
|
|
// alter the respective pref values.
|
2002-11-14 00:50:02 +00:00
|
|
|
NS_IMETHOD SkipOcsp() = 0;
|
2001-08-10 01:05:57 +00:00
|
|
|
|
|
|
|
// This method will set the OCSP value according to the
|
|
|
|
// values in the preferences.
|
2002-11-14 00:50:02 +00:00
|
|
|
NS_IMETHOD SkipOcspOff() = 0;
|
2001-08-10 01:05:57 +00:00
|
|
|
|
2001-10-01 14:57:35 +00:00
|
|
|
NS_IMETHOD RememberCert(CERTCertificate *cert) = 0;
|
2001-12-06 22:36:45 +00:00
|
|
|
|
|
|
|
NS_IMETHOD RemoveCrlFromList(nsAutoString) = 0;
|
|
|
|
|
|
|
|
NS_IMETHOD DefineNextTimer() = 0;
|
|
|
|
|
|
|
|
NS_IMETHOD DownloadCRLDirectly(nsAutoString, nsAutoString) = 0;
|
2002-05-14 20:42:54 +00:00
|
|
|
|
2003-01-18 14:03:00 +00:00
|
|
|
NS_IMETHOD LogoutAuthenticatedPK11() = 0;
|
2005-06-02 01:17:35 +00:00
|
|
|
|
|
|
|
NS_IMETHOD LaunchSmartCardThread(SECMODModule *module) = 0;
|
|
|
|
|
|
|
|
NS_IMETHOD ShutdownSmartCardThread(SECMODModule *module) = 0;
|
|
|
|
|
|
|
|
NS_IMETHOD PostEvent(const nsAString &eventType, const nsAString &token) = 0;
|
|
|
|
|
|
|
|
NS_IMETHOD DispatchEvent(const nsAString &eventType, const nsAString &token) = 0;
|
2003-01-18 14:03:00 +00:00
|
|
|
|
2001-02-07 19:00:52 +00:00
|
|
|
};
|
|
|
|
|
2005-11-11 14:36:26 +00:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsINSSComponent, NS_INSSCOMPONENT_IID)
|
|
|
|
|
2005-06-01 16:06:53 +00:00
|
|
|
class nsCryptoHash : public nsICryptoHash
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICRYPTOHASH
|
|
|
|
|
|
|
|
nsCryptoHash();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsCryptoHash();
|
|
|
|
HASHContext* mHashContext;
|
|
|
|
};
|
|
|
|
|
2001-11-29 23:36:34 +00:00
|
|
|
struct PRLock;
|
2003-01-18 14:03:00 +00:00
|
|
|
class nsNSSShutDownList;
|
2006-04-04 13:14:40 +00:00
|
|
|
class nsSSLThread;
|
|
|
|
class nsCertVerificationThread;
|
2001-02-07 19:00:52 +00:00
|
|
|
|
2001-01-10 01:32:29 +00:00
|
|
|
// Implementation of the PSM component interface.
|
2002-09-17 19:09:11 +00:00
|
|
|
class nsNSSComponent : public nsISignatureVerifier,
|
2001-02-07 19:00:52 +00:00
|
|
|
public nsIEntropyCollector,
|
2001-03-13 21:50:23 +00:00
|
|
|
public nsINSSComponent,
|
|
|
|
public nsIObserver,
|
2001-12-06 22:36:45 +00:00
|
|
|
public nsSupportsWeakReference,
|
2007-02-17 03:47:59 +00:00
|
|
|
public nsITimerCallback,
|
|
|
|
public nsINSSErrorsService
|
2001-01-10 01:32:29 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-04-23 14:21:53 +00:00
|
|
|
NS_DEFINE_STATIC_CID_ACCESSOR( NS_NSSCOMPONENT_CID )
|
2001-01-25 01:14:23 +00:00
|
|
|
|
2001-01-10 01:32:29 +00:00
|
|
|
nsNSSComponent();
|
|
|
|
virtual ~nsNSSComponent();
|
2001-01-19 01:12:10 +00:00
|
|
|
|
2001-01-10 01:32:29 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISIGNATUREVERIFIER
|
2001-01-25 01:14:23 +00:00
|
|
|
NS_DECL_NSIENTROPYCOLLECTOR
|
2001-03-13 21:50:23 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
2002-09-07 05:38:16 +00:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2007-02-17 03:47:59 +00:00
|
|
|
NS_DECL_NSINSSERRORSSERVICE
|
2001-01-19 01:12:10 +00:00
|
|
|
|
|
|
|
NS_METHOD Init();
|
2001-02-06 20:09:27 +00:00
|
|
|
|
2004-02-26 04:07:23 +00:00
|
|
|
NS_IMETHOD GetPIPNSSBundleString(const char *name,
|
2001-12-21 06:16:24 +00:00
|
|
|
nsAString &outString);
|
2004-02-26 04:07:23 +00:00
|
|
|
NS_IMETHOD PIPBundleFormatStringFromName(const char *name,
|
2001-02-07 19:00:52 +00:00
|
|
|
const PRUnichar **params,
|
|
|
|
PRUint32 numParams,
|
2004-02-26 04:07:23 +00:00
|
|
|
nsAString &outString);
|
2002-11-14 00:50:02 +00:00
|
|
|
NS_IMETHOD SkipOcsp();
|
|
|
|
NS_IMETHOD SkipOcspOff();
|
2001-12-06 22:36:45 +00:00
|
|
|
nsresult InitializeCRLUpdateTimer();
|
|
|
|
nsresult StopCRLUpdateTimer();
|
|
|
|
NS_IMETHOD RemoveCrlFromList(nsAutoString);
|
|
|
|
NS_IMETHOD DefineNextTimer();
|
2003-01-18 14:03:00 +00:00
|
|
|
NS_IMETHOD LogoutAuthenticatedPK11();
|
2001-12-06 22:36:45 +00:00
|
|
|
NS_IMETHOD DownloadCRLDirectly(nsAutoString, nsAutoString);
|
2001-10-01 14:57:35 +00:00
|
|
|
NS_IMETHOD RememberCert(CERTCertificate *cert);
|
2003-01-07 00:58:24 +00:00
|
|
|
static nsresult GetNSSCipherIDFromPrefString(const nsACString &aPrefString, PRUint16 &aCipherId);
|
2002-09-07 05:38:16 +00:00
|
|
|
|
2005-06-02 01:17:35 +00:00
|
|
|
NS_IMETHOD LaunchSmartCardThread(SECMODModule *module);
|
|
|
|
NS_IMETHOD ShutdownSmartCardThread(SECMODModule *module);
|
|
|
|
NS_IMETHOD PostEvent(const nsAString &eventType, const nsAString &token);
|
|
|
|
NS_IMETHOD DispatchEvent(const nsAString &eventType, const nsAString &token);
|
|
|
|
|
2001-01-25 01:14:23 +00:00
|
|
|
private:
|
2001-02-06 20:09:27 +00:00
|
|
|
|
2003-05-08 13:39:35 +00:00
|
|
|
nsresult InitializeNSS(PRBool showWarningBox);
|
2001-11-29 23:36:34 +00:00
|
|
|
nsresult ShutdownNSS();
|
2003-02-20 00:19:45 +00:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
void TryCFM2MachOMigration(nsIFile *cfmPath, nsIFile *machoPath);
|
|
|
|
#endif
|
2003-01-06 22:23:49 +00:00
|
|
|
|
|
|
|
enum AlertIdentifier {
|
|
|
|
ai_nss_init_problem,
|
|
|
|
ai_sockets_still_active,
|
|
|
|
ai_crypto_ui_active,
|
|
|
|
ai_incomplete_logout
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowAlert(AlertIdentifier ai);
|
2001-01-25 01:14:23 +00:00
|
|
|
void InstallLoadableRoots();
|
2006-12-06 15:42:39 +00:00
|
|
|
void UnloadLoadableRoots();
|
2005-06-02 01:17:35 +00:00
|
|
|
void LaunchSmartCardThreads();
|
|
|
|
void ShutdownSmartCardThreads();
|
2001-02-06 20:09:27 +00:00
|
|
|
nsresult InitializePIPNSSBundle();
|
2001-02-14 22:15:53 +00:00
|
|
|
nsresult ConfigureInternalPKCS11Token();
|
2001-05-19 01:20:18 +00:00
|
|
|
nsresult RegisterPSMContentListener();
|
2001-11-29 23:36:34 +00:00
|
|
|
nsresult RegisterObservers();
|
2001-12-06 22:36:45 +00:00
|
|
|
nsresult DownloadCrlSilently();
|
2006-05-10 17:30:15 +00:00
|
|
|
nsresult PostCRLImportEvent(const nsCSubstring &urlString, nsIStreamListener *psmDownloader);
|
2001-12-06 22:36:45 +00:00
|
|
|
nsresult getParamsForNextCrlToDownload(nsAutoString *url, PRTime *time, nsAutoString *key);
|
2005-06-02 01:17:35 +00:00
|
|
|
nsresult DispatchEventToWindow(nsIDOMWindow *domWin, const nsAString &eventType, const nsAString &token);
|
2001-11-29 23:36:34 +00:00
|
|
|
PRLock *mutex;
|
|
|
|
|
2001-05-23 22:06:43 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> mScriptSecurityManager;
|
2001-02-06 20:09:27 +00:00
|
|
|
nsCOMPtr<nsIStringBundle> mPIPNSSBundle;
|
2001-05-19 01:20:18 +00:00
|
|
|
nsCOMPtr<nsIURIContentListener> mPSMContentListener;
|
2004-09-07 18:54:02 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> mPrefBranch;
|
2001-12-06 22:36:45 +00:00
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2001-11-29 23:36:34 +00:00
|
|
|
PRBool mNSSInitialized;
|
|
|
|
PRBool mObserversRegistered;
|
2001-10-01 14:57:35 +00:00
|
|
|
PLHashTable *hashTableCerts;
|
2001-12-06 22:36:45 +00:00
|
|
|
nsAutoString mDownloadURL;
|
|
|
|
nsAutoString mCrlUpdateKey;
|
|
|
|
PRLock *mCrlTimerLock;
|
|
|
|
nsHashtable *crlsScheduledForDownload;
|
|
|
|
PRBool crlDownloadTimerOn;
|
|
|
|
PRBool mUpdateTimerInitialized;
|
2001-11-29 23:36:34 +00:00
|
|
|
static int mInstanceCount;
|
2003-01-18 14:03:00 +00:00
|
|
|
nsNSSShutDownList *mShutdownObjectList;
|
2005-06-02 01:17:35 +00:00
|
|
|
SmartCardThreadList *mThreadList;
|
2006-04-04 13:14:40 +00:00
|
|
|
PRBool mIsNetworkDown;
|
|
|
|
nsSSLThread *mSSLThread;
|
|
|
|
nsCertVerificationThread *mCertVerificationThread;
|
|
|
|
nsNSSHttpInterface mHttpForNSS;
|
2001-01-10 01:32:29 +00:00
|
|
|
};
|
2001-01-19 01:12:10 +00:00
|
|
|
|
2001-05-19 01:20:18 +00:00
|
|
|
class PSMContentListener : public nsIURIContentListener,
|
2001-04-04 23:30:05 +00:00
|
|
|
public nsSupportsWeakReference {
|
2001-02-26 21:50:54 +00:00
|
|
|
public:
|
2001-05-19 01:20:18 +00:00
|
|
|
PSMContentListener();
|
|
|
|
virtual ~PSMContentListener();
|
2001-02-26 21:50:54 +00:00
|
|
|
nsresult init();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIURICONTENTLISTENER
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mLoadCookie;
|
|
|
|
nsCOMPtr<nsIURIContentListener> mParentContentListener;
|
|
|
|
};
|
|
|
|
|
2007-02-17 03:47:59 +00:00
|
|
|
class nsNSSErrors
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const char *getDefaultErrorStringName(PRInt32 err);
|
|
|
|
static const char *getOverrideErrorStringName(PRInt32 aErrorCode);
|
|
|
|
static nsresult getErrorMessageFromCode(PRInt32 err,
|
|
|
|
nsINSSComponent *component,
|
|
|
|
nsString &returnedMessage);
|
|
|
|
};
|
|
|
|
|
2001-01-19 01:12:10 +00:00
|
|
|
#endif // _nsNSSComponent_h_
|
|
|
|
|