b=189205 Implement early shutdown of NSS resources

r=javi sr=darin
This commit is contained in:
kaie%netscape.com 2003-01-18 14:03:00 +00:00
Родитель 1d5c6eb40e
Коммит d007c347bc
36 изменённых файлов: 1675 добавлений и 352 удалений

Просмотреть файл

@ -319,7 +319,7 @@ function doLogout()
// here's the workaround - login functions are with token // here's the workaround - login functions are with token
var selected_token = selected_slot.getToken(); var selected_token = selected_slot.getToken();
try { try {
selected_token.logout(false); selected_token.logoutAndDropAuthenticatedResources();
var tok_status = document.getElementById("tok_status"); var tok_status = document.getElementById("tok_status");
if (selected_token.isLoggedIn()) { if (selected_token.isLoggedIn()) {
tok_status.setAttribute("label", tok_status.setAttribute("label",

Просмотреть файл

@ -1070,7 +1070,7 @@
</FILE> </FILE>
<FILE> <FILE>
<PATHTYPE>Name</PATHTYPE> <PATHTYPE>Name</PATHTYPE>
<PATH>nsPSMTracker.cpp</PATH> <PATH>nsNSSShutDown.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT> <PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND> <FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS> <FILEFLAGS></FILEFLAGS>
@ -1340,7 +1340,7 @@
</FILEREF> </FILEREF>
<FILEREF> <FILEREF>
<PATHTYPE>Name</PATHTYPE> <PATHTYPE>Name</PATHTYPE>
<PATH>nsPSMTracker.cpp</PATH> <PATH>nsNSSShutDown.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT> <PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF> </FILEREF>
<FILEREF> <FILEREF>
@ -2495,7 +2495,7 @@
</FILE> </FILE>
<FILE> <FILE>
<PATHTYPE>Name</PATHTYPE> <PATHTYPE>Name</PATHTYPE>
<PATH>nsPSMTracker.cpp</PATH> <PATH>nsNSSShutDown.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT> <PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND> <FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS> <FILEFLAGS></FILEFLAGS>
@ -2767,7 +2767,7 @@
</FILEREF> </FILEREF>
<FILEREF> <FILEREF>
<PATHTYPE>Name</PATHTYPE> <PATHTYPE>Name</PATHTYPE>
<PATH>nsPSMTracker.cpp</PATH> <PATH>nsNSSShutDown.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT> <PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF> </FILEREF>
<FILEREF> <FILEREF>
@ -3163,7 +3163,7 @@
<FILEREF> <FILEREF>
<TARGETNAME>PIPNSS.shlb</TARGETNAME> <TARGETNAME>PIPNSS.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE> <PATHTYPE>Name</PATHTYPE>
<PATH>nsPSMTracker.cpp</PATH> <PATH>nsNSSShutDown.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT> <PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF> </FILEREF>
<FILEREF> <FILEREF>

Просмотреть файл

@ -46,7 +46,8 @@ interface nsIPK11Token : nsISupports
*/ */
boolean isLoggedIn(); boolean isLoggedIn();
void login(in boolean force); void login(in boolean force);
void logout(); void logoutSimple();
void logoutAndDropAuthenticatedResources();
/* /*
* Reset password * Reset password

Просмотреть файл

@ -79,7 +79,7 @@ CPPSRCS = \
nsOCSPResponder.cpp \ nsOCSPResponder.cpp \
nsUsageArrayHelper.cpp \ nsUsageArrayHelper.cpp \
nsCRLManager.cpp \ nsCRLManager.cpp \
nsPSMTracker.cpp \ nsNSSShutDown.cpp \
$(NULL) $(NULL)
REQUIRES = nspr \ REQUIRES = nspr \

Просмотреть файл

@ -58,9 +58,26 @@ nsHash::nsHash() : m_ctxt(nsnull)
{ {
} }
nsHash::~nsHash() nsHash::~nsHash()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsHash::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsHash::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (m_ctxt) { if (m_ctxt) {
HASH_Destroy(m_ctxt); HASH_Destroy(m_ctxt);
m_ctxt = nsnull; m_ctxt = nsnull;
@ -75,6 +92,10 @@ NS_IMETHODIMP nsHash::ResultLen(PRInt16 aAlg, PRUint32 * aLen)
NS_IMETHODIMP nsHash::Create(PRInt16 aAlg) NS_IMETHODIMP nsHash::Create(PRInt16 aAlg)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
m_ctxt = HASH_Create((HASH_HashType)aAlg); m_ctxt = HASH_Create((HASH_HashType)aAlg);
if (m_ctxt == nsnull) { if (m_ctxt == nsnull) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -84,18 +105,30 @@ NS_IMETHODIMP nsHash::Create(PRInt16 aAlg)
NS_IMETHODIMP nsHash::Begin() NS_IMETHODIMP nsHash::Begin()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
HASH_Begin(m_ctxt); HASH_Begin(m_ctxt);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsHash::Update(unsigned char* aBuf, PRUint32 aLen) NS_IMETHODIMP nsHash::Update(unsigned char* aBuf, PRUint32 aLen)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
HASH_Update(m_ctxt, (const unsigned char*)aBuf, aLen); HASH_Update(m_ctxt, (const unsigned char*)aBuf, aLen);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsHash::End(unsigned char* aBuf, PRUint32* aResultLen, PRUint32 aMaxResultLen) NS_IMETHODIMP nsHash::End(unsigned char* aBuf, PRUint32* aResultLen, PRUint32 aMaxResultLen)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
HASH_End(m_ctxt, aBuf, aResultLen, aMaxResultLen); HASH_End(m_ctxt, aBuf, aResultLen, aMaxResultLen);
return NS_OK; return NS_OK;
} }
@ -113,6 +146,24 @@ nsCMSMessage::nsCMSMessage(NSSCMSMessage *aCMSMsg)
nsCMSMessage::~nsCMSMessage() nsCMSMessage::~nsCMSMessage()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsCMSMessage::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsCMSMessage::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (m_cmsMsg) { if (m_cmsMsg) {
NSS_CMSMessage_Destroy(m_cmsMsg); NSS_CMSMessage_Destroy(m_cmsMsg);
} }
@ -125,6 +176,10 @@ NS_IMETHODIMP nsCMSMessage::VerifySignature()
NSSCMSSignerInfo* nsCMSMessage::GetTopLevelSignerInfo() NSSCMSSignerInfo* nsCMSMessage::GetTopLevelSignerInfo()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return nsnull;
if (!m_cmsMsg) if (!m_cmsMsg)
return nsnull; return nsnull;
@ -145,6 +200,10 @@ NSSCMSSignerInfo* nsCMSMessage::GetTopLevelSignerInfo()
NS_IMETHODIMP nsCMSMessage::GetSignerEmailAddress(char * * aEmail) NS_IMETHODIMP nsCMSMessage::GetSignerEmailAddress(char * * aEmail)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::GetSignerEmailAddress\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::GetSignerEmailAddress\n"));
NS_ENSURE_ARG(aEmail); NS_ENSURE_ARG(aEmail);
@ -158,6 +217,10 @@ NS_IMETHODIMP nsCMSMessage::GetSignerEmailAddress(char * * aEmail)
NS_IMETHODIMP nsCMSMessage::GetSignerCommonName(char ** aName) NS_IMETHODIMP nsCMSMessage::GetSignerCommonName(char ** aName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::GetSignerCommonName\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::GetSignerCommonName\n"));
NS_ENSURE_ARG(aName); NS_ENSURE_ARG(aName);
@ -171,6 +234,10 @@ NS_IMETHODIMP nsCMSMessage::GetSignerCommonName(char ** aName)
NS_IMETHODIMP nsCMSMessage::ContentIsEncrypted(PRBool *isEncrypted) NS_IMETHODIMP nsCMSMessage::ContentIsEncrypted(PRBool *isEncrypted)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::ContentIsEncrypted\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::ContentIsEncrypted\n"));
NS_ENSURE_ARG(isEncrypted); NS_ENSURE_ARG(isEncrypted);
@ -184,6 +251,10 @@ NS_IMETHODIMP nsCMSMessage::ContentIsEncrypted(PRBool *isEncrypted)
NS_IMETHODIMP nsCMSMessage::ContentIsSigned(PRBool *isSigned) NS_IMETHODIMP nsCMSMessage::ContentIsSigned(PRBool *isSigned)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::ContentIsSigned\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::ContentIsSigned\n"));
NS_ENSURE_ARG(isSigned); NS_ENSURE_ARG(isSigned);
@ -197,6 +268,10 @@ NS_IMETHODIMP nsCMSMessage::ContentIsSigned(PRBool *isSigned)
NS_IMETHODIMP nsCMSMessage::GetSignerCert(nsIX509Cert **scert) NS_IMETHODIMP nsCMSMessage::GetSignerCert(nsIX509Cert **scert)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
NSSCMSSignerInfo *si = GetTopLevelSignerInfo(); NSSCMSSignerInfo *si = GetTopLevelSignerInfo();
if (!si) if (!si)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -221,11 +296,19 @@ NS_IMETHODIMP nsCMSMessage::GetSignerCert(nsIX509Cert **scert)
NS_IMETHODIMP nsCMSMessage::GetEncryptionCert(nsIX509Cert **ecert) NS_IMETHODIMP nsCMSMessage::GetEncryptionCert(nsIX509Cert **ecert)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHODIMP nsCMSMessage::VerifyDetachedSignature(unsigned char* aDigestData, PRUint32 aDigestDataLen) NS_IMETHODIMP nsCMSMessage::VerifyDetachedSignature(unsigned char* aDigestData, PRUint32 aDigestDataLen)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
if (!aDigestData || !aDigestDataLen) if (!aDigestData || !aDigestDataLen)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -234,6 +317,10 @@ NS_IMETHODIMP nsCMSMessage::VerifyDetachedSignature(unsigned char* aDigestData,
nsresult nsCMSMessage::CommonVerifySignature(unsigned char* aDigestData, PRUint32 aDigestDataLen) nsresult nsCMSMessage::CommonVerifySignature(unsigned char* aDigestData, PRUint32 aDigestDataLen)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature, content level count %d\n", NSS_CMSMessage_ContentLevelCount(m_cmsMsg))); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature, content level count %d\n", NSS_CMSMessage_ContentLevelCount(m_cmsMsg)));
NSSCMSContentInfo *cinfo = nsnull; NSSCMSContentInfo *cinfo = nsnull;
NSSCMSSignedData *sigd = nsnull; NSSCMSSignedData *sigd = nsnull;
@ -334,7 +421,7 @@ loser:
return rv; return rv;
} }
class nsZeroTerminatedCertArray class nsZeroTerminatedCertArray : public nsNSSShutDownObject
{ {
public: public:
nsZeroTerminatedCertArray() nsZeroTerminatedCertArray()
@ -344,6 +431,24 @@ public:
~nsZeroTerminatedCertArray() ~nsZeroTerminatedCertArray()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (mCerts) if (mCerts)
{ {
for (PRUint32 i=0; i < mSize; i++) { for (PRUint32 i=0; i < mSize; i++) {
@ -388,6 +493,10 @@ public:
void set(PRUint32 i, CERTCertificate *c) void set(PRUint32 i, CERTCertificate *c)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
if (i >= mSize) if (i >= mSize)
return; return;
@ -400,6 +509,10 @@ public:
CERTCertificate *get(PRUint32 i) CERTCertificate *get(PRUint32 i)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return nsnull;
if (i >= mSize) if (i >= mSize)
return nsnull; return nsnull;
@ -408,6 +521,10 @@ public:
CERTCertificate **getRawArray() CERTCertificate **getRawArray()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return nsnull;
return mCerts; return mCerts;
} }
@ -419,6 +536,10 @@ private:
NS_IMETHODIMP nsCMSMessage::CreateEncrypted(nsIArray * aRecipientCerts) NS_IMETHODIMP nsCMSMessage::CreateEncrypted(nsIArray * aRecipientCerts)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateEncrypted\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateEncrypted\n"));
NSSCMSContentInfo *cinfo; NSSCMSContentInfo *cinfo;
NSSCMSEnvelopedData *envd; NSSCMSEnvelopedData *envd;
@ -449,7 +570,9 @@ NS_IMETHODIMP nsCMSMessage::CreateEncrypted(nsIArray * aRecipientCerts)
if (!nssRecipientCert) if (!nssRecipientCert)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
recipientCerts.set(i, nssRecipientCert->GetCert()); CERTCertificate *c = nssRecipientCert->GetCert();
CERTCertificateCleaner rcCleaner(c);
recipientCerts.set(i, c);
} }
// Find a bulk key algorithm // // Find a bulk key algorithm //
@ -510,6 +633,10 @@ loser:
NS_IMETHODIMP nsCMSMessage::CreateSigned(nsIX509Cert* aSigningCert, nsIX509Cert* aEncryptCert, unsigned char* aDigestData, PRUint32 aDigestDataLen) NS_IMETHODIMP nsCMSMessage::CreateSigned(nsIX509Cert* aSigningCert, nsIX509Cert* aEncryptCert, unsigned char* aDigestData, PRUint32 aDigestDataLen)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateSigned\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateSigned\n"));
NSSCMSContentInfo *cinfo; NSSCMSContentInfo *cinfo;
NSSCMSSignedData *sigd; NSSCMSSignedData *sigd;
@ -647,6 +774,24 @@ nsCMSDecoder::nsCMSDecoder()
nsCMSDecoder::~nsCMSDecoder() nsCMSDecoder::~nsCMSDecoder()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsCMSDecoder::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsCMSDecoder::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (m_dcx) { if (m_dcx) {
NSS_CMSDecoder_Cancel(m_dcx); NSS_CMSDecoder_Cancel(m_dcx);
m_dcx = nsnull; m_dcx = nsnull;
@ -656,6 +801,10 @@ nsCMSDecoder::~nsCMSDecoder()
/* void start (in NSSCMSContentCallback cb, in voidPtr arg); */ /* void start (in NSSCMSContentCallback cb, in voidPtr arg); */
NS_IMETHODIMP nsCMSDecoder::Start(NSSCMSContentCallback cb, void * arg) NS_IMETHODIMP nsCMSDecoder::Start(NSSCMSContentCallback cb, void * arg)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSDecoder::Start\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSDecoder::Start\n"));
m_ctx = new PipUIContext(); m_ctx = new PipUIContext();
@ -670,6 +819,10 @@ NS_IMETHODIMP nsCMSDecoder::Start(NSSCMSContentCallback cb, void * arg)
/* void update (in string bug, in long len); */ /* void update (in string bug, in long len); */
NS_IMETHODIMP nsCMSDecoder::Update(const char *buf, PRInt32 len) NS_IMETHODIMP nsCMSDecoder::Update(const char *buf, PRInt32 len)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSDecoder::Update\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSDecoder::Update\n"));
NSS_CMSDecoder_Update(m_dcx, (char *)buf, len); NSS_CMSDecoder_Update(m_dcx, (char *)buf, len);
return NS_OK; return NS_OK;
@ -678,6 +831,10 @@ NS_IMETHODIMP nsCMSDecoder::Update(const char *buf, PRInt32 len)
/* void finish (); */ /* void finish (); */
NS_IMETHODIMP nsCMSDecoder::Finish(nsICMSMessage ** aCMSMsg) NS_IMETHODIMP nsCMSDecoder::Finish(nsICMSMessage ** aCMSMsg)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSDecoder::Finish\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSDecoder::Finish\n"));
NSSCMSMessage *cmsMsg; NSSCMSMessage *cmsMsg;
cmsMsg = NSS_CMSDecoder_Finish(m_dcx); cmsMsg = NSS_CMSDecoder_Finish(m_dcx);
@ -702,6 +859,25 @@ nsCMSEncoder::nsCMSEncoder()
nsCMSEncoder::~nsCMSEncoder() nsCMSEncoder::~nsCMSEncoder()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsCMSEncoder::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsCMSEncoder::destructorSafeDestroyNSSReference()
{
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
if (m_ecx) if (m_ecx)
NSS_CMSEncoder_Cancel(m_ecx); NSS_CMSEncoder_Cancel(m_ecx);
} }
@ -709,6 +885,10 @@ nsCMSEncoder::~nsCMSEncoder()
/* void start (); */ /* void start (); */
NS_IMETHODIMP nsCMSEncoder::Start(nsICMSMessage *aMsg, NSSCMSContentCallback cb, void * arg) NS_IMETHODIMP nsCMSEncoder::Start(nsICMSMessage *aMsg, NSSCMSContentCallback cb, void * arg)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Start\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Start\n"));
nsCMSMessage *cmsMsg = NS_STATIC_CAST(nsCMSMessage*, aMsg); nsCMSMessage *cmsMsg = NS_STATIC_CAST(nsCMSMessage*, aMsg);
m_ctx = new PipUIContext(); m_ctx = new PipUIContext();
@ -724,6 +904,10 @@ NS_IMETHODIMP nsCMSEncoder::Start(nsICMSMessage *aMsg, NSSCMSContentCallback cb,
/* void update (in string aBuf, in long aLen); */ /* void update (in string aBuf, in long aLen); */
NS_IMETHODIMP nsCMSEncoder::Update(const char *aBuf, PRInt32 aLen) NS_IMETHODIMP nsCMSEncoder::Update(const char *aBuf, PRInt32 aLen)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Update\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Update\n"));
if (!m_ecx || NSS_CMSEncoder_Update(m_ecx, aBuf, aLen) != SECSuccess) { if (!m_ecx || NSS_CMSEncoder_Update(m_ecx, aBuf, aLen) != SECSuccess) {
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Update - can't update encoder\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Update - can't update encoder\n"));
@ -735,6 +919,10 @@ NS_IMETHODIMP nsCMSEncoder::Update(const char *aBuf, PRInt32 aLen)
/* void finish (); */ /* void finish (); */
NS_IMETHODIMP nsCMSEncoder::Finish() NS_IMETHODIMP nsCMSEncoder::Finish()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv = NS_OK; nsresult rv = NS_OK;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Finish\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Finish\n"));
if (!m_ecx || NSS_CMSEncoder_Finish(m_ecx) != SECSuccess) { if (!m_ecx || NSS_CMSEncoder_Finish(m_ecx) != SECSuccess) {
@ -748,6 +936,10 @@ NS_IMETHODIMP nsCMSEncoder::Finish()
/* void encode (in nsICMSMessage aMsg); */ /* void encode (in nsICMSMessage aMsg); */
NS_IMETHODIMP nsCMSEncoder::Encode(nsICMSMessage *aMsg) NS_IMETHODIMP nsCMSEncoder::Encode(nsICMSMessage *aMsg)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Encode\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Encode\n"));
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }

Просмотреть файл

@ -47,12 +47,14 @@
#include "nsICMSDecoder.h" #include "nsICMSDecoder.h"
#include "sechash.h" #include "sechash.h"
#include "cms.h" #include "cms.h"
#include "nsNSSShutDown.h"
#define NS_HASH_CLASSNAME "Hash Object" #define NS_HASH_CLASSNAME "Hash Object"
#define NS_HASH_CID \ #define NS_HASH_CID \
{ 0xa31a3028, 0xae28, 0x11d5, { 0xba, 0x4b, 0x00, 0x10, 0x83, 0x03, 0xb1, 0x17 } } { 0xa31a3028, 0xae28, 0x11d5, { 0xba, 0x4b, 0x00, 0x10, 0x83, 0x03, 0xb1, 0x17 } }
class nsHash : public nsIHash class nsHash : public nsIHash,
public nsNSSShutDownObject
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -63,13 +65,16 @@ public:
private: private:
HASHContext * m_ctxt; HASHContext * m_ctxt;
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
#define NS_CMSMESSAGE_CLASSNAME "CMS Message Object" #define NS_CMSMESSAGE_CLASSNAME "CMS Message Object"
#define NS_CMSMESSAGE_CID \ #define NS_CMSMESSAGE_CID \
{ 0xa4557478, 0xae16, 0x11d5, { 0xba,0x4b,0x00,0x10,0x83,0x03,0xb1,0x17 } } { 0xa4557478, 0xae16, 0x11d5, { 0xba,0x4b,0x00,0x10,0x83,0x03,0xb1,0x17 } }
class nsCMSMessage : public nsICMSMessage class nsCMSMessage : public nsICMSMessage,
public nsNSSShutDownObject
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -86,6 +91,8 @@ private:
NSSCMSMessage * m_cmsMsg; NSSCMSMessage * m_cmsMsg;
NSSCMSSignerInfo* GetTopLevelSignerInfo(); NSSCMSSignerInfo* GetTopLevelSignerInfo();
nsresult CommonVerifySignature(unsigned char* aDigestData, PRUint32 aDigestDataLen); nsresult CommonVerifySignature(unsigned char* aDigestData, PRUint32 aDigestDataLen);
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
@ -97,7 +104,8 @@ private:
#define NS_CMSDECODER_CID \ #define NS_CMSDECODER_CID \
{ 0x9dcef3a4, 0xa3bc, 0x11d5, { 0xba, 0x47, 0x00, 0x10, 0x83, 0x03, 0xb1, 0x17 } } { 0x9dcef3a4, 0xa3bc, 0x11d5, { 0xba, 0x47, 0x00, 0x10, 0x83, 0x03, 0xb1, 0x17 } }
class nsCMSDecoder : public nsICMSDecoder class nsCMSDecoder : public nsICMSDecoder,
public nsNSSShutDownObject
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -109,6 +117,8 @@ public:
private: private:
nsCOMPtr<nsIInterfaceRequestor> m_ctx; nsCOMPtr<nsIInterfaceRequestor> m_ctx;
NSSCMSDecoderContext *m_dcx; NSSCMSDecoderContext *m_dcx;
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
// =============================================== // ===============================================
@ -118,7 +128,8 @@ private:
#define NS_CMSENCODER_CLASSNAME "CMS Decoder Object" #define NS_CMSENCODER_CLASSNAME "CMS Decoder Object"
#define NS_CMSENCODER_CID \ #define NS_CMSENCODER_CID \
{ 0xa15789aa, 0x8903, 0x462b, { 0x81, 0xe9, 0x4a, 0xa2, 0xcf, 0xf4, 0xd5, 0xcb } } { 0xa15789aa, 0x8903, 0x462b, { 0x81, 0xe9, 0x4a, 0xa2, 0xcf, 0xf4, 0xd5, 0xcb } }
class nsCMSEncoder : public nsICMSEncoder class nsCMSEncoder : public nsICMSEncoder,
public nsNSSShutDownObject
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -130,6 +141,8 @@ public:
private: private:
nsCOMPtr<nsIInterfaceRequestor> m_ctx; nsCOMPtr<nsIInterfaceRequestor> m_ctx;
NSSCMSEncoderContext *m_ecx; NSSCMSEncoderContext *m_ecx;
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
#endif #endif

Просмотреть файл

@ -47,6 +47,7 @@
#include "nsCMSSecureMessage.h" #include "nsCMSSecureMessage.h"
#include "nsNSSCertificate.h" #include "nsNSSCertificate.h"
#include "nsNSSHelper.h" #include "nsNSSHelper.h"
#include "nsNSSShutDown.h"
#include <string.h> #include <string.h>
#include "plbase64.h" #include "plbase64.h"
@ -86,6 +87,7 @@ nsCMSSecureMessage::~nsCMSSecureMessage()
NS_IMETHODIMP nsCMSSecureMessage:: NS_IMETHODIMP nsCMSSecureMessage::
GetCertByPrefID(const char *certID, char **_retval) GetCertByPrefID(const char *certID, char **_retval)
{ {
nsNSSShutDownPreventionLock locker;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::GetCertByPrefID\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::GetCertByPrefID\n"));
nsresult rv = NS_OK; nsresult rv = NS_OK;
CERTCertificate *cert = 0; CERTCertificate *cert = 0;
@ -127,6 +129,7 @@ done:
nsresult nsCMSSecureMessage:: nsresult nsCMSSecureMessage::
DecodeCert(const char *value, nsIX509Cert ** _retval) DecodeCert(const char *value, nsIX509Cert ** _retval)
{ {
nsNSSShutDownPreventionLock locker;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::DecodeCert\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::DecodeCert\n"));
nsresult rv = NS_OK; nsresult rv = NS_OK;
PRInt32 length; PRInt32 length;
@ -160,6 +163,7 @@ DecodeCert(const char *value, nsIX509Cert ** _retval)
nsresult nsCMSSecureMessage:: nsresult nsCMSSecureMessage::
SendMessage(const char *msg, const char *base64Cert, char ** _retval) SendMessage(const char *msg, const char *base64Cert, char ** _retval)
{ {
nsNSSShutDownPreventionLock locker;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::SendMessage\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::SendMessage\n"));
nsresult rv = NS_OK; nsresult rv = NS_OK;
CERTCertificate *cert = 0; CERTCertificate *cert = 0;
@ -289,6 +293,7 @@ done:
nsresult nsCMSSecureMessage:: nsresult nsCMSSecureMessage::
ReceiveMessage(const char *msg, char **_retval) ReceiveMessage(const char *msg, char **_retval)
{ {
nsNSSShutDownPreventionLock locker;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::ReceiveMessage\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::ReceiveMessage\n"));
nsresult rv = NS_OK; nsresult rv = NS_OK;
NSSCMSDecoderContext *dcx; NSSCMSDecoderContext *dcx;

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsNSSShutDown.h"
#include "nspr.h" #include "nspr.h"
extern "C" { extern "C" {
@ -65,6 +66,7 @@ nsCRLInfo::nsCRLInfo()
nsCRLInfo::nsCRLInfo(CERTSignedCrl *signedCrl) nsCRLInfo::nsCRLInfo(CERTSignedCrl *signedCrl)
{ {
nsNSSShutDownPreventionLock locker;
CERTCrl *crl = &(signedCrl->crl); CERTCrl *crl = &(signedCrl->crl);
nsAutoString org; nsAutoString org;
nsAutoString orgUnit; nsAutoString orgUnit;

Просмотреть файл

@ -46,7 +46,7 @@
#include "nsIPrompt.h" #include "nsIPrompt.h"
#include "nsICertificateDialogs.h" #include "nsICertificateDialogs.h"
#include "nsArray.h" #include "nsArray.h"
#include "nsPSMTracker.h" #include "nsNSSShutDown.h"
#include "nsNSSCertHeader.h" #include "nsNSSCertHeader.h"
@ -80,6 +80,7 @@ nsCRLManager::~nsCRLManager()
NS_IMETHODIMP NS_IMETHODIMP
nsCRLManager::ImportCrl (PRUint8 *aData, PRUint32 aLength, nsIURI * aURI, PRUint32 aType, PRBool doSilentDonwload, const PRUnichar* crlKey) nsCRLManager::ImportCrl (PRUint8 *aData, PRUint32 aLength, nsIURI * aURI, PRUint32 aType, PRBool doSilentDonwload, const PRUnichar* crlKey)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
PRArenaPool *arena = NULL; PRArenaPool *arena = NULL;
CERTCertificate *caCert; CERTCertificate *caCert;
@ -350,6 +351,7 @@ nsCRLManager::RescheduleCRLAutoUpdate(void)
NS_IMETHODIMP NS_IMETHODIMP
nsCRLManager::GetCrls(nsIArray ** aCrls) nsCRLManager::GetCrls(nsIArray ** aCrls)
{ {
nsNSSShutDownPreventionLock locker;
SECStatus sec_rv; SECStatus sec_rv;
CERTCrlHeadNode *head = nsnull; CERTCrlHeadNode *head = nsnull;
CERTCrlNode *node = nsnull; CERTCrlNode *node = nsnull;
@ -390,6 +392,7 @@ loser:
NS_IMETHODIMP NS_IMETHODIMP
nsCRLManager::DeleteCrl(PRUint32 aCrlIndex) nsCRLManager::DeleteCrl(PRUint32 aCrlIndex)
{ {
nsNSSShutDownPreventionLock locker;
CERTSignedCrl *realCrl = nsnull; CERTSignedCrl *realCrl = nsnull;
CERTCrlHeadNode *head = nsnull; CERTCrlHeadNode *head = nsnull;
CERTCrlNode *node = nsnull; CERTCrlNode *node = nsnull;

Просмотреть файл

@ -45,7 +45,7 @@
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsNSSCleaner.h" #include "nsNSSCleaner.h"
#include "nsICertPickDialogs.h" #include "nsICertPickDialogs.h"
#include "nsPSMTracker.h" #include "nsNSSShutDown.h"
NSSCleanupAutoPtrClass(CERTCertNicknames, CERT_FreeNicknames) NSSCleanupAutoPtrClass(CERTCertNicknames, CERT_FreeNicknames)
NSSCleanupAutoPtrClass(CERTCertList, CERT_DestroyCertList) NSSCleanupAutoPtrClass(CERTCertList, CERT_DestroyCertList)
@ -75,6 +75,7 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
PRBool *canceled, PRBool *canceled,
nsIX509Cert **_retval) nsIX509Cert **_retval)
{ {
nsNSSShutDownPreventionLock locker;
PRInt32 selectedIndex = -1; PRInt32 selectedIndex = -1;
PRBool selectionFound = PR_FALSE; PRBool selectionFound = PR_FALSE;
PRUnichar **certNicknameList = nsnull; PRUnichar **certNicknameList = nsnull;

Просмотреть файл

@ -327,6 +327,7 @@ nsCertTree::GetCertsByType(PRUint32 aType,
void *aCertCmpFnArg, void *aCertCmpFnArg,
nsISupportsArray **_certs) nsISupportsArray **_certs)
{ {
nsNSSShutDownPreventionLock locker;
CERTCertList *certList = NULL; CERTCertList *certList = NULL;
nsCOMPtr<nsIInterfaceRequestor> cxt = new PipUIContext(); nsCOMPtr<nsIInterfaceRequestor> cxt = new PipUIContext();
certList = PK11_ListCerts(PK11CertListUnique, cxt); certList = PK11_ListCerts(PK11CertListUnique, cxt);

Просмотреть файл

@ -21,7 +21,6 @@
* Javier Delgadillo <javi@netscape.com> * Javier Delgadillo <javi@netscape.com>
*/ */
#include "nsNSSComponent.h" #include "nsNSSComponent.h"
#include "nsPSMTracker.h"
#include "nsCrypto.h" #include "nsCrypto.h"
#include "nsKeygenHandler.h" #include "nsKeygenHandler.h"
#include "nsKeygenThread.h" #include "nsKeygenThread.h"
@ -77,6 +76,8 @@ extern "C" {
NSSCleanupAutoPtrClass(SECKEYPrivateKey, SECKEY_DestroyPrivateKey) NSSCleanupAutoPtrClass(SECKEYPrivateKey, SECKEY_DestroyPrivateKey)
NSSCleanupAutoPtrClass(PK11SlotInfo, PK11_FreeSlot) NSSCleanupAutoPtrClass(PK11SlotInfo, PK11_FreeSlot)
#include "nsNSSShutDown.h"
/* /*
* These are the most common error strings that are returned * These are the most common error strings that are returned
* by the JavaScript methods in case of error. * by the JavaScript methods in case of error.
@ -554,6 +555,7 @@ nsConvertToActualKeyGenParams(PRUint32 keyGenMech, char *params,
static PK11SlotInfo* static PK11SlotInfo*
nsGetSlotForKeyGen(nsKeyGenType keyGenType, nsIInterfaceRequestor *ctx) nsGetSlotForKeyGen(nsKeyGenType keyGenType, nsIInterfaceRequestor *ctx)
{ {
nsNSSShutDownPreventionLock locker;
PRUint32 mechanism = cryptojs_convert_to_mechanism(keyGenType); PRUint32 mechanism = cryptojs_convert_to_mechanism(keyGenType);
PK11SlotInfo *slot = nsnull; PK11SlotInfo *slot = nsnull;
nsresult rv = GetSlotWithMechanism(mechanism,ctx, &slot); nsresult rv = GetSlotWithMechanism(mechanism,ctx, &slot);
@ -1370,6 +1372,7 @@ loser:
NS_IMETHODIMP NS_IMETHODIMP
nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn) nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
{ {
nsNSSShutDownPreventionLock locker;
*aReturn = nsnull; *aReturn = nsnull;
nsresult nrv; nsresult nrv;
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &nrv)); nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &nrv));
@ -1657,6 +1660,7 @@ alertUser(const PRUnichar *message)
NS_IMETHODIMP NS_IMETHODIMP
nsP12Runnable::Run() nsP12Runnable::Run()
{ {
nsNSSShutDownPreventionLock locker;
NS_ASSERTION(mCertArr, "certArr is NULL while trying to back up"); NS_ASSERTION(mCertArr, "certArr is NULL while trying to back up");
nsString final; nsString final;
@ -1724,6 +1728,7 @@ nsCryptoRunArgs::~nsCryptoRunArgs() {}
nsCryptoRunnable::nsCryptoRunnable(nsCryptoRunArgs *args) nsCryptoRunnable::nsCryptoRunnable(nsCryptoRunArgs *args)
{ {
nsNSSShutDownPreventionLock locker;
NS_ASSERTION(args,"Passed nsnull to nsCryptoRunnable constructor."); NS_ASSERTION(args,"Passed nsnull to nsCryptoRunnable constructor.");
m_args = args; m_args = args;
NS_IF_ADDREF(m_args); NS_IF_ADDREF(m_args);
@ -1732,6 +1737,7 @@ nsCryptoRunnable::nsCryptoRunnable(nsCryptoRunArgs *args)
nsCryptoRunnable::~nsCryptoRunnable() nsCryptoRunnable::~nsCryptoRunnable()
{ {
nsNSSShutDownPreventionLock locker;
JS_RemoveRoot(m_args->m_cx, &m_args->m_scope); JS_RemoveRoot(m_args->m_cx, &m_args->m_scope);
NS_IF_RELEASE(m_args); NS_IF_RELEASE(m_args);
} }
@ -1741,6 +1747,7 @@ nsCryptoRunnable::~nsCryptoRunnable()
NS_IMETHODIMP NS_IMETHODIMP
nsCryptoRunnable::Run() nsCryptoRunnable::Run()
{ {
nsNSSShutDownPreventionLock locker;
JSPrincipals *principals; JSPrincipals *principals;
nsresult rv = m_args->m_principals->GetJSPrincipals(&principals); nsresult rv = m_args->m_principals->GetJSPrincipals(&principals);
@ -1810,6 +1817,7 @@ nsCrypto::ImportUserCertificates(const nsAString& aNickname,
PRBool aDoForcedBackup, PRBool aDoForcedBackup,
nsAString& aReturn) nsAString& aReturn)
{ {
nsNSSShutDownPreventionLock locker;
char *nickname=nsnull, *cmmfResponse=nsnull; char *nickname=nsnull, *cmmfResponse=nsnull;
char *retString=nsnull; char *retString=nsnull;
char *freeString=nsnull; char *freeString=nsnull;
@ -2045,8 +2053,17 @@ nsCrypto::Alert(const nsAString& aMessage)
NS_IMETHODIMP NS_IMETHODIMP
nsCrypto::Logout() nsCrypto::Logout()
{ {
nsresult rv;
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
if (NS_FAILED(rv))
return rv;
{
nsNSSShutDownPreventionLock locker;
PK11_LogoutAll(); PK11_LogoutAll();
return NS_OK; }
return nssComponent->LogoutAuthenticatedPK11();
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -2115,6 +2132,7 @@ confirm_user(const PRUnichar *message)
NS_IMETHODIMP NS_IMETHODIMP
nsPkcs11::Deletemodule(const nsAString& aModuleName, PRInt32* aReturn) nsPkcs11::Deletemodule(const nsAString& aModuleName, PRInt32* aReturn)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
nsString errorMessage; nsString errorMessage;
@ -2173,6 +2191,7 @@ nsPkcs11::Addmodule(const nsAString& aModuleName,
PRInt32 aCryptoMechanismFlags, PRInt32 aCryptoMechanismFlags,
PRInt32 aCipherFlags, PRInt32* aReturn) PRInt32 aCipherFlags, PRInt32* aReturn)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv)); nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
nsString final; nsString final;

Просмотреть файл

@ -45,7 +45,7 @@ extern "C" {
#include "nsCRT.h" #include "nsCRT.h"
#include "nsITokenDialogs.h" #include "nsITokenDialogs.h"
#include "nsIGenKeypairInfoDlg.h" #include "nsIGenKeypairInfoDlg.h"
#include "nsPSMTracker.h" #include "nsNSSShutDown.h"
//These defines are taken from the PKCS#11 spec //These defines are taken from the PKCS#11 spec
#define CKM_RSA_PKCS_KEY_PAIR_GEN 0x00000000 #define CKM_RSA_PKCS_KEY_PAIR_GEN 0x00000000
@ -269,6 +269,7 @@ GetSlotWithMechanism(PRUint32 aMechanism,
nsIInterfaceRequestor *m_ctx, nsIInterfaceRequestor *m_ctx,
PK11SlotInfo** aSlot) PK11SlotInfo** aSlot)
{ {
nsNSSShutDownPreventionLock locker;
PK11SlotList * slotList = nsnull; PK11SlotList * slotList = nsnull;
PRUnichar** tokenNameList = nsnull; PRUnichar** tokenNameList = nsnull;
nsITokenDialogs * dialogs; nsITokenDialogs * dialogs;
@ -363,6 +364,7 @@ nsKeygenFormProcessor::GetPublicKey(nsString& aValue, nsString& aChallenge,
nsString& aKeyType, nsString& aKeyType,
nsString& aOutPublicKey, nsString& aPqg) nsString& aOutPublicKey, nsString& aPqg)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
char *keystring = nsnull; char *keystring = nsnull;
char *pqgString = nsnull, *str = nsnull; char *pqgString = nsnull, *str = nsnull;

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsProxiedService.h" #include "nsProxiedService.h"
#include "nsKeygenThread.h" #include "nsKeygenThread.h"
#include "nsIDOMWindowInternal.h" #include "nsIDOMWindowInternal.h"
#include "nsNSSShutDown.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsKeygenThread, nsIKeygenThread) NS_IMPL_THREADSAFE_ISUPPORTS1(nsKeygenThread, nsIKeygenThread)
@ -66,6 +67,7 @@ void nsKeygenThread::SetParams(
PRBool a_isSensitive, PRBool a_isSensitive,
void *a_wincx ) void *a_wincx )
{ {
nsNSSShutDownPreventionLock locker;
PR_Lock(mutex); PR_Lock(mutex);
if (!alreadyReceivedParams) { if (!alreadyReceivedParams) {
@ -195,6 +197,7 @@ nsresult nsKeygenThread::UserCanceled(PRBool *threadAlreadyClosedDialog)
void nsKeygenThread::Run(void) void nsKeygenThread::Run(void)
{ {
nsNSSShutDownPreventionLock locker;
PRBool canGenerate = PR_FALSE; PRBool canGenerate = PR_FALSE;
PR_Lock(mutex); PR_Lock(mutex);

Просмотреть файл

@ -37,7 +37,7 @@
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h" #include "nsIInterfaceRequestorUtils.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsPSMTracker.h" #include "nsNSSShutDown.h"
#include "ssl.h" #include "ssl.h"
#include "cert.h" #include "cert.h"
@ -118,6 +118,7 @@ nsSSLStatus::~nsSSLStatus()
char* PR_CALLBACK char* PR_CALLBACK
PK11PasswordPrompt(PK11SlotInfo* slot, PRBool retry, void* arg) { PK11PasswordPrompt(PK11SlotInfo* slot, PRBool retry, void* arg) {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
PRUnichar *password = nsnull; PRUnichar *password = nsnull;
PRBool value = PR_FALSE; PRBool value = PR_FALSE;
@ -198,6 +199,7 @@ PK11PasswordPrompt(PK11SlotInfo* slot, PRBool retry, void* arg) {
} }
void PR_CALLBACK HandshakeCallback(PRFileDesc* fd, void* client_data) { void PR_CALLBACK HandshakeCallback(PRFileDesc* fd, void* client_data) {
nsNSSShutDownPreventionLock locker;
PRInt32 sslStatus; PRInt32 sslStatus;
char* signer = nsnull; char* signer = nsnull;
char* cipherName = nsnull; char* cipherName = nsnull;
@ -277,6 +279,8 @@ void PR_CALLBACK HandshakeCallback(PRFileDesc* fd, void* client_data) {
SECStatus PR_CALLBACK AuthCertificateCallback(void* client_data, PRFileDesc* fd, SECStatus PR_CALLBACK AuthCertificateCallback(void* client_data, PRFileDesc* fd,
PRBool checksig, PRBool isServer) { PRBool checksig, PRBool isServer) {
nsNSSShutDownPreventionLock locker;
// first the default action // first the default action
SECStatus rv = SSL_AuthCertificate(CERT_GetDefaultCertDB(), fd, checksig, isServer); SECStatus rv = SSL_AuthCertificate(CERT_GetDefaultCertDB(), fd, checksig, isServer);

Просмотреть файл

@ -49,6 +49,24 @@ nsNSSCertCache::nsNSSCertCache()
nsNSSCertCache::~nsNSSCertCache() nsNSSCertCache::~nsNSSCertCache()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsNSSCertCache::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsNSSCertCache::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (mCertList) { if (mCertList) {
CERT_DestroyCertList(mCertList); CERT_DestroyCertList(mCertList);
} }
@ -61,6 +79,10 @@ nsNSSCertCache::~nsNSSCertCache()
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertCache::CacheAllCerts() nsNSSCertCache::CacheAllCerts()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
{ {
nsAutoLock lock(mutex); nsAutoLock lock(mutex);
if (mCertList) { if (mCertList) {
@ -83,6 +105,9 @@ nsNSSCertCache::CacheAllCerts()
void* nsNSSCertCache::GetCachedCerts() void* nsNSSCertCache::GetCachedCerts()
{ {
if (isAlreadyShutDown())
return nsnull;
nsAutoLock lock(mutex); nsAutoLock lock(mutex);
return mCertList; return mCertList;
} }

Просмотреть файл

@ -37,8 +37,10 @@
#include "nsINSSCertCache.h" #include "nsINSSCertCache.h"
#include "certt.h" #include "certt.h"
#include "nsNSSShutDown.h"
class nsNSSCertCache : public nsINSSCertCache class nsNSSCertCache : public nsINSSCertCache,
public nsNSSShutDownObject
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -50,6 +52,8 @@ public:
private: private:
PRLock *mutex; PRLock *mutex;
CERTCertList *mCertList; CERTCertList *mCertList;
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
#endif #endif

Просмотреть файл

@ -41,6 +41,7 @@
#include "nsDateTimeFormatCID.h" #include "nsDateTimeFormatCID.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsNSSShutDown.h"
static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID); static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
@ -55,6 +56,7 @@ nsX509CertValidity::nsX509CertValidity() : mTimesInitialized(PR_FALSE)
nsX509CertValidity::nsX509CertValidity(CERTCertificate *cert) : nsX509CertValidity::nsX509CertValidity(CERTCertificate *cert) :
mTimesInitialized(PR_FALSE) mTimesInitialized(PR_FALSE)
{ {
nsNSSShutDownPreventionLock locker;
if (cert) { if (cert) {
SECStatus rv = CERT_GetCertTimes(cert, &mNotBefore, &mNotAfter); SECStatus rv = CERT_GetCertTimes(cert, &mNotBefore, &mNotAfter);
if (rv == SECSuccess) if (rv == SECSuccess)

Просмотреть файл

@ -94,6 +94,8 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsNSSCertificate, nsIX509Cert,
nsNSSCertificate* nsNSSCertificate*
nsNSSCertificate::ConstructFromDER(char *certDER, int derLen) nsNSSCertificate::ConstructFromDER(char *certDER, int derLen)
{ {
nsNSSShutDownPreventionLock locker;
if (!certDER || !derLen) if (!certDER || !derLen)
return nsnull; return nsnull;
@ -117,28 +119,49 @@ nsNSSCertificate::nsNSSCertificate(CERTCertificate *cert) :
mPermDelete(PR_FALSE), mPermDelete(PR_FALSE),
mCertType(nsIX509Cert::UNKNOWN_CERT) mCertType(nsIX509Cert::UNKNOWN_CERT)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
if (cert) if (cert)
mCert = CERT_DupCertificate(cert); mCert = CERT_DupCertificate(cert);
else
mCert = nsnull;
} }
nsNSSCertificate::~nsNSSCertificate() nsNSSCertificate::~nsNSSCertificate()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsNSSCertificate::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsNSSCertificate::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (mPermDelete) { if (mPermDelete) {
if (mCertType == nsNSSCertificate::USER_CERT) { if (mCertType == nsNSSCertificate::USER_CERT) {
nsCOMPtr<nsIInterfaceRequestor> cxt = new PipUIContext(); nsCOMPtr<nsIInterfaceRequestor> cxt = new PipUIContext();
PK11_DeleteTokenCertAndKey(mCert, cxt); PK11_DeleteTokenCertAndKey(mCert, cxt);
} else if (!PK11_IsReadOnly(mCert->slot)) { } else if (!PK11_IsReadOnly(mCert->slot)) {
// If the cert isn't a user cert and it is on an external token, // If the list of built-ins does contain a non-removable
// then we'll just leave it as untrusted, but won't delete it // copy of this certificate, our call will not remove
// from the cert db. // the certificate permanently, but rather remove all trust.
SEC_DeletePermCertificate(mCert); SEC_DeletePermCertificate(mCert);
} }
} }
if (mCert) { if (mCert) {
CERT_DestroyCertificate(mCert); CERT_DestroyCertificate(mCert);
mCert = nsnull;
} }
} }
@ -159,6 +182,10 @@ nsNSSCertificate::GetCertType(PRUint32 *aCertType)
nsresult nsresult
nsNSSCertificate::MarkForPermDeletion() nsNSSCertificate::MarkForPermDeletion()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
// make sure user is logged in to the token // make sure user is logged in to the token
nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext(); nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext();
@ -330,6 +357,10 @@ nsNSSCertificate::FormatUIStrings(const nsAutoString &nickname, nsAutoString &ni
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetDbKey(char * *aDbKey) nsNSSCertificate::GetDbKey(char * *aDbKey)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
SECItem key; SECItem key;
NS_ENSURE_ARG(aDbKey); NS_ENSURE_ARG(aDbKey);
@ -354,6 +385,10 @@ nsNSSCertificate::GetDbKey(char * *aDbKey)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetWindowTitle(char * *aWindowTitle) nsNSSCertificate::GetWindowTitle(char * *aWindowTitle)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
NS_ENSURE_ARG(aWindowTitle); NS_ENSURE_ARG(aWindowTitle);
if (mCert) { if (mCert) {
if (mCert->nickname) { if (mCert->nickname) {
@ -374,6 +409,10 @@ nsNSSCertificate::GetWindowTitle(char * *aWindowTitle)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetNickname(nsAString &_nickname) nsNSSCertificate::GetNickname(nsAString &_nickname)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
const char *nickname = (mCert->nickname) ? mCert->nickname : "(no nickname)"; const char *nickname = (mCert->nickname) ? mCert->nickname : "(no nickname)";
_nickname = NS_ConvertUTF8toUCS2(nickname); _nickname = NS_ConvertUTF8toUCS2(nickname);
return NS_OK; return NS_OK;
@ -382,6 +421,10 @@ nsNSSCertificate::GetNickname(nsAString &_nickname)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetEmailAddress(nsAString &_emailAddress) nsNSSCertificate::GetEmailAddress(nsAString &_emailAddress)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
const char *email = (mCert->emailAddr) ? mCert->emailAddr : "(no email address)"; const char *email = (mCert->emailAddr) ? mCert->emailAddr : "(no email address)";
_emailAddress = NS_ConvertUTF8toUCS2(email); _emailAddress = NS_ConvertUTF8toUCS2(email);
return NS_OK; return NS_OK;
@ -390,6 +433,10 @@ nsNSSCertificate::GetEmailAddress(nsAString &_emailAddress)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetCommonName(nsAString &aCommonName) nsNSSCertificate::GetCommonName(nsAString &aCommonName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
aCommonName.Truncate(); aCommonName.Truncate();
if (mCert) { if (mCert) {
char *commonName = CERT_GetCommonName(&mCert->subject); char *commonName = CERT_GetCommonName(&mCert->subject);
@ -406,6 +453,10 @@ nsNSSCertificate::GetCommonName(nsAString &aCommonName)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetOrganization(nsAString &aOrganization) nsNSSCertificate::GetOrganization(nsAString &aOrganization)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
aOrganization.Truncate(); aOrganization.Truncate();
if (mCert) { if (mCert) {
char *organization = CERT_GetOrgName(&mCert->subject); char *organization = CERT_GetOrgName(&mCert->subject);
@ -422,6 +473,10 @@ nsNSSCertificate::GetOrganization(nsAString &aOrganization)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetIssuerCommonName(nsAString &aCommonName) nsNSSCertificate::GetIssuerCommonName(nsAString &aCommonName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
aCommonName.Truncate(); aCommonName.Truncate();
if (mCert) { if (mCert) {
char *commonName = CERT_GetCommonName(&mCert->issuer); char *commonName = CERT_GetCommonName(&mCert->issuer);
@ -436,6 +491,10 @@ nsNSSCertificate::GetIssuerCommonName(nsAString &aCommonName)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetIssuerOrganization(nsAString &aOrganization) nsNSSCertificate::GetIssuerOrganization(nsAString &aOrganization)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
aOrganization.Truncate(); aOrganization.Truncate();
if (mCert) { if (mCert) {
char *organization = CERT_GetOrgName(&mCert->issuer); char *organization = CERT_GetOrgName(&mCert->issuer);
@ -450,6 +509,10 @@ nsNSSCertificate::GetIssuerOrganization(nsAString &aOrganization)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetIssuerOrganizationUnit(nsAString &aOrganizationUnit) nsNSSCertificate::GetIssuerOrganizationUnit(nsAString &aOrganizationUnit)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
aOrganizationUnit.Truncate(); aOrganizationUnit.Truncate();
if (mCert) { if (mCert) {
char *organizationUnit = CERT_GetOrgUnitName(&mCert->issuer); char *organizationUnit = CERT_GetOrgUnitName(&mCert->issuer);
@ -465,6 +528,10 @@ nsNSSCertificate::GetIssuerOrganizationUnit(nsAString &aOrganizationUnit)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetIssuer(nsIX509Cert * *aIssuer) nsNSSCertificate::GetIssuer(nsIX509Cert * *aIssuer)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
NS_ENSURE_ARG(aIssuer); NS_ENSURE_ARG(aIssuer);
*aIssuer = nsnull; *aIssuer = nsnull;
CERTCertificate *issuer; CERTCertificate *issuer;
@ -481,6 +548,10 @@ nsNSSCertificate::GetIssuer(nsIX509Cert * *aIssuer)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetOrganizationalUnit(nsAString &aOrganizationalUnit) nsNSSCertificate::GetOrganizationalUnit(nsAString &aOrganizationalUnit)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
aOrganizationalUnit.Truncate(); aOrganizationalUnit.Truncate();
if (mCert) { if (mCert) {
char *orgunit = CERT_GetOrgUnitName(&mCert->subject); char *orgunit = CERT_GetOrgUnitName(&mCert->subject);
@ -500,6 +571,10 @@ nsNSSCertificate::GetOrganizationalUnit(nsAString &aOrganizationalUnit)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetChain(nsIArray **_rvChain) nsNSSCertificate::GetChain(nsIArray **_rvChain)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
NS_ENSURE_ARG(_rvChain); NS_ENSURE_ARG(_rvChain);
nsresult rv; nsresult rv;
/* Get the cert chain from NSS */ /* Get the cert chain from NSS */
@ -565,6 +640,10 @@ done:
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetSubjectName(nsAString &_subjectName) nsNSSCertificate::GetSubjectName(nsAString &_subjectName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
_subjectName.Truncate(); _subjectName.Truncate();
if (mCert->subjectName) { if (mCert->subjectName) {
_subjectName = NS_ConvertUTF8toUCS2(mCert->subjectName); _subjectName = NS_ConvertUTF8toUCS2(mCert->subjectName);
@ -576,6 +655,10 @@ nsNSSCertificate::GetSubjectName(nsAString &_subjectName)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetIssuerName(nsAString &_issuerName) nsNSSCertificate::GetIssuerName(nsAString &_issuerName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
_issuerName.Truncate(); _issuerName.Truncate();
if (mCert->issuerName) { if (mCert->issuerName) {
_issuerName = NS_ConvertUTF8toUCS2(mCert->issuerName); _issuerName = NS_ConvertUTF8toUCS2(mCert->issuerName);
@ -587,6 +670,10 @@ nsNSSCertificate::GetIssuerName(nsAString &_issuerName)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetSerialNumber(nsAString &_serialNumber) nsNSSCertificate::GetSerialNumber(nsAString &_serialNumber)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
_serialNumber.Truncate(); _serialNumber.Truncate();
nsXPIDLCString tmpstr; tmpstr.Adopt(CERT_Hexify(&mCert->serialNumber, 1)); nsXPIDLCString tmpstr; tmpstr.Adopt(CERT_Hexify(&mCert->serialNumber, 1));
if (tmpstr.get()) { if (tmpstr.get()) {
@ -599,6 +686,10 @@ nsNSSCertificate::GetSerialNumber(nsAString &_serialNumber)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetSha1Fingerprint(nsAString &_sha1Fingerprint) nsNSSCertificate::GetSha1Fingerprint(nsAString &_sha1Fingerprint)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
_sha1Fingerprint.Truncate(); _sha1Fingerprint.Truncate();
unsigned char fingerprint[20]; unsigned char fingerprint[20];
SECItem fpItem; SECItem fpItem;
@ -618,6 +709,10 @@ nsNSSCertificate::GetSha1Fingerprint(nsAString &_sha1Fingerprint)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetMd5Fingerprint(nsAString &_md5Fingerprint) nsNSSCertificate::GetMd5Fingerprint(nsAString &_md5Fingerprint)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
_md5Fingerprint.Truncate(); _md5Fingerprint.Truncate();
unsigned char fingerprint[20]; unsigned char fingerprint[20];
SECItem fpItem; SECItem fpItem;
@ -637,6 +732,10 @@ nsNSSCertificate::GetMd5Fingerprint(nsAString &_md5Fingerprint)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetTokenName(nsAString &aTokenName) nsNSSCertificate::GetTokenName(nsAString &aTokenName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
aTokenName.Truncate(); aTokenName.Truncate();
if (mCert) { if (mCert) {
// HACK alert // HACK alert
@ -669,6 +768,10 @@ nsNSSCertificate::GetTokenName(nsAString &aTokenName)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetRawDER(PRUint32 *aLength, PRUint8 **aArray) nsNSSCertificate::GetRawDER(PRUint32 *aLength, PRUint8 **aArray)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
if (mCert) { if (mCert) {
*aArray = (PRUint8 *)mCert->derCert.data; *aArray = (PRUint8 *)mCert->derCert.data;
*aLength = mCert->derCert.len; *aLength = mCert->derCert.len;
@ -681,12 +784,20 @@ nsNSSCertificate::GetRawDER(PRUint32 *aLength, PRUint8 **aArray)
CERTCertificate * CERTCertificate *
nsNSSCertificate::GetCert() nsNSSCertificate::GetCert()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return nsnull;
return (mCert) ? CERT_DupCertificate(mCert) : nsnull; return (mCert) ? CERT_DupCertificate(mCert) : nsnull;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetValidity(nsIX509CertValidity **aValidity) nsNSSCertificate::GetValidity(nsIX509CertValidity **aValidity)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
NS_ENSURE_ARG(aValidity); NS_ENSURE_ARG(aValidity);
nsX509CertValidity *validity = new nsX509CertValidity(mCert); nsX509CertValidity *validity = new nsX509CertValidity(mCert);
if (nsnull == validity) if (nsnull == validity)
@ -700,6 +811,10 @@ nsNSSCertificate::GetValidity(nsIX509CertValidity **aValidity)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::VerifyForUsage(PRUint32 usage, PRUint32 *verificationResult) nsNSSCertificate::VerifyForUsage(PRUint32 usage, PRUint32 *verificationResult)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
NS_ENSURE_ARG(verificationResult); NS_ENSURE_ARG(verificationResult);
SECCertUsage nss_usage; SECCertUsage nss_usage;
@ -819,6 +934,10 @@ nsNSSCertificate::GetUsagesArray(PRBool ignoreOcsp,
PRUint32 *_count, PRUint32 *_count,
PRUnichar ***_usages) PRUnichar ***_usages)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv; nsresult rv;
const int max_usages = 13; const int max_usages = 13;
PRUnichar *tmpUsages[max_usages]; PRUnichar *tmpUsages[max_usages];
@ -844,6 +963,10 @@ nsNSSCertificate::GetUsagesString(PRBool ignoreOcsp,
PRUint32 *_verified, PRUint32 *_verified,
nsAString &_usages) nsAString &_usages)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv; nsresult rv;
const int max_usages = 13; const int max_usages = 13;
PRUnichar *tmpUsages[max_usages]; PRUnichar *tmpUsages[max_usages];
@ -1092,6 +1215,10 @@ nsresult
nsNSSCertificate::CreateTBSCertificateASN1Struct(nsIASN1Sequence **retSequence, nsNSSCertificate::CreateTBSCertificateASN1Struct(nsIASN1Sequence **retSequence,
nsINSSComponent *nssComponent) nsINSSComponent *nssComponent)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
// //
// TBSCertificate ::= SEQUENCE { // TBSCertificate ::= SEQUENCE {
// version [0] EXPLICIT Version DEFAULT v1, // version [0] EXPLICIT Version DEFAULT v1,
@ -1300,6 +1427,10 @@ DumpASN1Object(nsIASN1Object *object, unsigned int level)
nsresult nsresult
nsNSSCertificate::CreateASN1Struct() nsNSSCertificate::CreateASN1Struct()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsCOMPtr<nsIASN1Sequence> sequence = new nsNSSASN1Sequence(); nsCOMPtr<nsIASN1Sequence> sequence = new nsNSSASN1Sequence();
mASN1Structure = sequence; mASN1Structure = sequence;
@ -1359,6 +1490,7 @@ nsNSSCertificate::CreateASN1Struct()
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::GetASN1Structure(nsIASN1Object * *aASN1Structure) nsNSSCertificate::GetASN1Structure(nsIASN1Object * *aASN1Structure)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(aASN1Structure); NS_ENSURE_ARG_POINTER(aASN1Structure);
if (mASN1Structure == nsnull) { if (mASN1Structure == nsnull) {
@ -1380,6 +1512,10 @@ nsNSSCertificate::GetASN1Structure(nsIASN1Object * *aASN1Structure)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::Equals(nsIX509Cert *other, PRBool *result) nsNSSCertificate::Equals(nsIX509Cert *other, PRBool *result)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
NS_ENSURE_ARG(other); NS_ENSURE_ARG(other);
NS_ENSURE_ARG(result); NS_ENSURE_ARG(result);
@ -1394,6 +1530,10 @@ nsNSSCertificate::Equals(nsIX509Cert *other, PRBool *result)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificate::SaveSMimeProfile() nsNSSCertificate::SaveSMimeProfile()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
if (SECSuccess != CERT_SaveSMimeProfile(mCert, nsnull, nsnull)) if (SECSuccess != CERT_SaveSMimeProfile(mCert, nsnull, nsnull))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
else else
@ -1403,6 +1543,7 @@ nsNSSCertificate::SaveSMimeProfile()
char* nsNSSCertificate::defaultServerNickname(CERTCertificate* cert) char* nsNSSCertificate::defaultServerNickname(CERTCertificate* cert)
{ {
nsNSSShutDownPreventionLock locker;
char* nickname = nsnull; char* nickname = nsnull;
int count; int count;
PRBool conflict; PRBool conflict;

Просмотреть файл

@ -41,6 +41,7 @@
#include "nsIX509CertDB.h" #include "nsIX509CertDB.h"
#include "nsIASN1Object.h" #include "nsIASN1Object.h"
#include "nsISMimeCert.h" #include "nsISMimeCert.h"
#include "nsNSSShutDown.h"
#include "nsNSSCertHeader.h" #include "nsNSSCertHeader.h"
@ -49,7 +50,8 @@ class nsIASN1Sequence;
/* Certificate */ /* Certificate */
class nsNSSCertificate : public nsIX509Cert, class nsNSSCertificate : public nsIX509Cert,
public nsISMimeCert public nsISMimeCert,
public nsNSSShutDownObject
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -77,6 +79,8 @@ private:
nsresult CreateTBSCertificateASN1Struct(nsIASN1Sequence **retSequence, nsresult CreateTBSCertificateASN1Struct(nsIASN1Sequence **retSequence,
nsINSSComponent *nssComponent); nsINSSComponent *nssComponent);
nsresult GetSortableDate(PRTime aTime, nsAString &_aSortableDate); nsresult GetSortableDate(PRTime aTime, nsAString &_aSortableDate);
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
#define NS_NSS_LONG 4 #define NS_NSS_LONG 4

Просмотреть файл

@ -50,7 +50,7 @@
#include "nsOCSPResponder.h" #include "nsOCSPResponder.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsArray.h" #include "nsArray.h"
#include "nsPSMTracker.h" #include "nsNSSShutDown.h"
#include "nspr.h" #include "nspr.h"
extern "C" { extern "C" {
@ -92,6 +92,7 @@ nsNSSCertificateDB::FindCertByNickname(nsISupports *aToken,
const nsAString &nickname, const nsAString &nickname,
nsIX509Cert **_rvCert) nsIX509Cert **_rvCert)
{ {
nsNSSShutDownPreventionLock locker;
CERTCertificate *cert = NULL; CERTCertificate *cert = NULL;
char *asciiname = NULL; char *asciiname = NULL;
NS_ConvertUCS2toUTF8 aUtf8Nickname(nickname); NS_ConvertUCS2toUTF8 aUtf8Nickname(nickname);
@ -125,6 +126,7 @@ NS_IMETHODIMP
nsNSSCertificateDB::FindCertByDBKey(const char *aDBkey, nsISupports *aToken, nsNSSCertificateDB::FindCertByDBKey(const char *aDBkey, nsISupports *aToken,
nsIX509Cert **_cert) nsIX509Cert **_cert)
{ {
nsNSSShutDownPreventionLock locker;
SECItem keyItem = {siBuffer, nsnull, 0}; SECItem keyItem = {siBuffer, nsnull, 0};
SECItem *dummy; SECItem *dummy;
CERTIssuerAndSN issuerSN; CERTIssuerAndSN issuerSN;
@ -165,6 +167,7 @@ nsNSSCertificateDB::FindCertNicknames(nsISupports *aToken,
PRUint32 *_count, PRUint32 *_count,
PRUnichar ***_certNames) PRUnichar ***_certNames)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
/* /*
* obtain the cert list from NSS * obtain the cert list from NSS
@ -229,6 +232,7 @@ CERTDERCerts*
nsNSSCertificateDB::getCertsFromPackage(PRArenaPool *arena, PRUint8 *data, nsNSSCertificateDB::getCertsFromPackage(PRArenaPool *arena, PRUint8 *data,
PRUint32 length) PRUint32 length)
{ {
nsNSSShutDownPreventionLock locker;
CERTDERCerts *collectArgs = CERTDERCerts *collectArgs =
(CERTDERCerts *)PORT_ArenaZAlloc(arena, sizeof(CERTDERCerts)); (CERTDERCerts *)PORT_ArenaZAlloc(arena, sizeof(CERTDERCerts));
if ( collectArgs == nsnull ) if ( collectArgs == nsnull )
@ -260,6 +264,9 @@ nsNSSCertificateDB::handleCACertDownload(nsIArray *x509Certs,
// cert was signed by the first cert, then we assume the first cert // cert was signed by the first cert, then we assume the first cert
// is the root and the last cert in the array is the leaf. In this // is the root and the last cert in the array is the leaf. In this
// case we display the last cert. // case we display the last cert.
nsNSSShutDownPreventionLock locker;
PRUint32 numCerts; PRUint32 numCerts;
x509Certs->GetLength(&numCerts); x509Certs->GetLength(&numCerts);
@ -420,6 +427,7 @@ nsNSSCertificateDB::ImportCertificates(PRUint8 * data, PRUint32 length,
nsIInterfaceRequestor *ctx) nsIInterfaceRequestor *ctx)
{ {
nsNSSShutDownPreventionLock locker;
nsresult nsrv; nsresult nsrv;
PRArenaPool *arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); PRArenaPool *arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
@ -473,6 +481,7 @@ nsNSSCertificateDB::ImportEmailCertificate(PRUint8 * data, PRUint32 length,
nsIInterfaceRequestor *ctx) nsIInterfaceRequestor *ctx)
{ {
nsNSSShutDownPreventionLock locker;
SECStatus srv = SECFailure; SECStatus srv = SECFailure;
nsresult nsrv = NS_OK; nsresult nsrv = NS_OK;
CERTCertificate * cert; CERTCertificate * cert;
@ -528,6 +537,7 @@ nsNSSCertificateDB::ImportServerCertificate(PRUint8 * data, PRUint32 length,
nsIInterfaceRequestor *ctx) nsIInterfaceRequestor *ctx)
{ {
nsNSSShutDownPreventionLock locker;
SECStatus srv = SECFailure; SECStatus srv = SECFailure;
nsresult nsrv = NS_OK; nsresult nsrv = NS_OK;
CERTCertificate * cert; CERTCertificate * cert;
@ -591,6 +601,7 @@ loser:
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificateDB::ImportUserCertificate(PRUint8 *data, PRUint32 length, nsIInterfaceRequestor *ctx) nsNSSCertificateDB::ImportUserCertificate(PRUint8 *data, PRUint32 length, nsIInterfaceRequestor *ctx)
{ {
nsNSSShutDownPreventionLock locker;
PK11SlotInfo *slot; PK11SlotInfo *slot;
char * nickname = NULL; char * nickname = NULL;
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
@ -664,6 +675,7 @@ loser:
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificateDB::DeleteCertificate(nsIX509Cert *aCert) nsNSSCertificateDB::DeleteCertificate(nsIX509Cert *aCert)
{ {
nsNSSShutDownPreventionLock locker;
nsNSSCertificate *nssCert = NS_STATIC_CAST(nsNSSCertificate*, aCert); nsNSSCertificate *nssCert = NS_STATIC_CAST(nsNSSCertificate*, aCert);
CERTCertificate *cert = nssCert->GetCert(); CERTCertificate *cert = nssCert->GetCert();
if (!cert) return NS_ERROR_FAILURE; if (!cert) return NS_ERROR_FAILURE;
@ -703,6 +715,7 @@ nsNSSCertificateDB::SetCertTrust(nsIX509Cert *cert,
PRUint32 type, PRUint32 type,
PRUint32 trusted) PRUint32 trusted)
{ {
nsNSSShutDownPreventionLock locker;
SECStatus srv; SECStatus srv;
nsNSSCertTrust trust; nsNSSCertTrust trust;
nsNSSCertificate *pipCert = NS_STATIC_CAST(nsNSSCertificate *, cert); nsNSSCertificate *pipCert = NS_STATIC_CAST(nsNSSCertificate *, cert);
@ -744,6 +757,7 @@ nsNSSCertificateDB::IsCertTrusted(nsIX509Cert *cert,
PRUint32 trustType, PRUint32 trustType,
PRBool *_isTrusted) PRBool *_isTrusted)
{ {
nsNSSShutDownPreventionLock locker;
SECStatus srv; SECStatus srv;
nsNSSCertificate *pipCert = NS_STATIC_CAST(nsNSSCertificate *, cert); nsNSSCertificate *pipCert = NS_STATIC_CAST(nsNSSCertificate *, cert);
CERTCertificate *nsscert = pipCert->GetCert(); CERTCertificate *nsscert = pipCert->GetCert();
@ -872,6 +886,7 @@ nsNSSCertificateDB::ExportPKCS12File(nsISupports *aToken,
nsIX509Cert **certs) nsIX509Cert **certs)
//const PRUnichar **aCertNames) //const PRUnichar **aCertNames)
{ {
nsNSSShutDownPreventionLock locker;
NS_ENSURE_ARG(aFile); NS_ENSURE_ARG(aFile);
nsPKCS12Blob blob; nsPKCS12Blob blob;
if (count == 0) return NS_OK; if (count == 0) return NS_OK;
@ -949,6 +964,7 @@ GetOCSPResponders (CERTCertificate *aCert,
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificateDB::GetOCSPResponders(nsIArray ** aResponders) nsNSSCertificateDB::GetOCSPResponders(nsIArray ** aResponders)
{ {
nsNSSShutDownPreventionLock locker;
SECStatus sec_rv; SECStatus sec_rv;
nsCOMPtr<nsIMutableArray> respondersArray; nsCOMPtr<nsIMutableArray> respondersArray;
nsresult rv = NS_NewArray(getter_AddRefs(respondersArray)); nsresult rv = NS_NewArray(getter_AddRefs(respondersArray));
@ -987,6 +1003,7 @@ nsNSSCertificateDB::getCertNames(CERTCertList *certList,
PRUint32 *_count, PRUint32 *_count,
PRUnichar ***_certNames) PRUnichar ***_certNames)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
CERTCertListNode *node; CERTCertListNode *node;
PRUint32 numcerts = 0, i=0; PRUint32 numcerts = 0, i=0;
@ -1060,6 +1077,7 @@ nsNSSCertificateDB::FindEmailEncryptionCert(const nsAString &aNickname, nsIX509C
if (aNickname.IsEmpty()) if (aNickname.IsEmpty())
return NS_OK; return NS_OK;
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
CERTCertificate *cert = 0; CERTCertificate *cert = 0;
nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext(); nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext();
@ -1099,6 +1117,7 @@ nsNSSCertificateDB::FindEmailSigningCert(const nsAString &aNickname, nsIX509Cert
if (aNickname.IsEmpty()) if (aNickname.IsEmpty())
return NS_OK; return NS_OK;
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
CERTCertificate *cert = 0; CERTCertificate *cert = 0;
nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext(); nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext();
@ -1129,6 +1148,7 @@ loser:
NS_IMETHODIMP NS_IMETHODIMP
nsNSSCertificateDB::FindCertByEmailAddress(nsISupports *aToken, const char *aEmailAddress, nsIX509Cert **_retval) nsNSSCertificateDB::FindCertByEmailAddress(nsISupports *aToken, const char *aEmailAddress, nsIX509Cert **_retval)
{ {
nsNSSShutDownPreventionLock locker;
CERTCertificate *any_cert = CERT_FindCertByNicknameOrEmailAddr(CERT_GetDefaultCertDB(), (char*)aEmailAddress); CERTCertificate *any_cert = CERT_FindCertByNicknameOrEmailAddr(CERT_GetDefaultCertDB(), (char*)aEmailAddress);
if (!any_cert) if (!any_cert)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -1166,6 +1186,7 @@ nsNSSCertificateDB::ConstructX509FromBase64(const char * base64, nsIX509Cert **_
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsNSSShutDownPreventionLock locker;
PRUint32 len = PL_strlen(base64); PRUint32 len = PL_strlen(base64);
int adjust = 0; int adjust = 0;
@ -1225,6 +1246,7 @@ nsNSSCertificateDB::ConstructX509FromBase64(const char * base64, nsIX509Cert **_
char * char *
nsNSSCertificateDB::default_nickname(CERTCertificate *cert, nsIInterfaceRequestor* ctx) nsNSSCertificateDB::default_nickname(CERTCertificate *cert, nsIInterfaceRequestor* ctx)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
char *username = NULL; char *username = NULL;
char *caname = NULL; char *caname = NULL;

Просмотреть файл

@ -70,7 +70,7 @@
#include "nsILocalFile.h" #include "nsILocalFile.h"
#include "nsITokenPasswordDialogs.h" #include "nsITokenPasswordDialogs.h"
#include "nsICRLManager.h" #include "nsICRLManager.h"
#include "nsPSMTracker.h" #include "nsNSSShutDown.h"
#include "nss.h" #include "nss.h"
#include "pk11func.h" #include "pk11func.h"
@ -226,7 +226,7 @@ nsNSSComponent::nsNSSComponent()
NS_ASSERTION( (0 == mInstanceCount), "nsNSSComponent is a singleton, but instantiated multiple times!"); NS_ASSERTION( (0 == mInstanceCount), "nsNSSComponent is a singleton, but instantiated multiple times!");
++mInstanceCount; ++mInstanceCount;
hashTableCerts = nsnull; hashTableCerts = nsnull;
mPSMTracker = nsPSMTracker::construct(); mShutdownObjectList = nsNSSShutDownList::construct();
} }
nsNSSComponent::~nsNSSComponent() nsNSSComponent::~nsNSSComponent()
@ -255,7 +255,7 @@ nsNSSComponent::~nsNSSComponent()
ShutdownNSS(); ShutdownNSS();
nsSSLIOLayerFreeTLSIntolerantSites(); nsSSLIOLayerFreeTLSIntolerantSites();
--mInstanceCount; --mInstanceCount;
delete mPSMTracker; delete mShutdownObjectList;
if (mutex) { if (mutex) {
PR_DestroyLock(mutex); PR_DestroyLock(mutex);
@ -324,6 +324,7 @@ nsNSSComponent::GetPIPNSSBundleString(const PRUnichar *name,
NS_IMETHODIMP NS_IMETHODIMP
nsNSSComponent::SkipOcsp() nsNSSComponent::SkipOcsp()
{ {
nsNSSShutDownPreventionLock locker;
CERTCertDBHandle *certdb = CERT_GetDefaultCertDB(); CERTCertDBHandle *certdb = CERT_GetDefaultCertDB();
SECStatus rv = CERT_DisableOCSPChecking(certdb); SECStatus rv = CERT_DisableOCSPChecking(certdb);
@ -340,6 +341,7 @@ nsNSSComponent::SkipOcspOff()
void void
nsNSSComponent::InstallLoadableRoots() nsNSSComponent::InstallLoadableRoots()
{ {
nsNSSShutDownPreventionLock locker;
SECMODModule *RootsModule = nsnull; SECMODModule *RootsModule = nsnull;
{ {
@ -442,6 +444,7 @@ nsNSSComponent::InstallLoadableRoots()
nsresult nsresult
nsNSSComponent::ConfigureInternalPKCS11Token() nsNSSComponent::ConfigureInternalPKCS11Token()
{ {
nsNSSShutDownPreventionLock locker;
nsXPIDLString manufacturerID; nsXPIDLString manufacturerID;
nsXPIDLString libraryDescription; nsXPIDLString libraryDescription;
nsXPIDLString tokenDescription; nsXPIDLString tokenDescription;
@ -591,6 +594,7 @@ nsresult nsNSSComponent::GetNSSCipherIDFromPrefString(const nsACString &aPrefStr
static void setOCSPOptions(nsIPref * pref) static void setOCSPOptions(nsIPref * pref)
{ {
nsNSSShutDownPreventionLock locker;
// Set up OCSP // // Set up OCSP //
PRInt32 ocspEnabled; PRInt32 ocspEnabled;
pref->GetIntPref("security.OCSP.enabled", &ocspEnabled); pref->GetIntPref("security.OCSP.enabled", &ocspEnabled);
@ -976,7 +980,9 @@ nsNSSComponent::InitializeNSS()
ConfigureInternalPKCS11Token(); ConfigureInternalPKCS11Token();
if (::NSS_InitReadWrite(profileStr.get()) != SECSuccess) { SECStatus init_rv = ::NSS_InitReadWrite(profileStr.get());
if (init_rv != SECSuccess) {
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init NSS r/w in %s\n", profileStr.get())); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init NSS r/w in %s\n", profileStr.get()));
if (supress_warning_preference) { if (supress_warning_preference) {
@ -987,7 +993,9 @@ nsNSSComponent::InitializeNSS()
} }
// try to init r/o // try to init r/o
if (NSS_Init(profileStr.get()) != SECSuccess) { init_rv = NSS_Init(profileStr.get());
if (init_rv != SECSuccess) {
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init in r/o either\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init in r/o either\n"));
which_nss_problem = problem_no_security_at_all; which_nss_problem = problem_no_security_at_all;
@ -1092,15 +1100,14 @@ nsNSSComponent::ShutdownNSS()
} }
SSL_ClearSessionCache(); SSL_ClearSessionCache();
#if 0 PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("evaporating psm resources\n"));
// temporarily disable this call until bug 181230 gets fixed mShutdownObjectList->evaporateAllNSSResources();
if (SECSuccess != ::NSS_Shutdown()) { if (SECSuccess != ::NSS_Shutdown()) {
PR_LOG(gPIPNSSLog, PR_LOG_ALWAYS, ("NSS SHUTDOWN FAILURE\n")); PR_LOG(gPIPNSSLog, PR_LOG_ALWAYS, ("NSS SHUTDOWN FAILURE\n"));
} }
else { else {
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("NSS shutdown =====>> OK <<=====\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("NSS shutdown =====>> OK <<=====\n"));
} }
#endif
} }
return NS_OK; return NS_OK;
@ -1225,6 +1232,7 @@ nsNSSComponent::VerifySignature(const char* aRSABuf, PRUint32 aRSABufLen,
PRInt32* aErrorCode, PRInt32* aErrorCode,
nsIPrincipal** aPrincipal) nsIPrincipal** aPrincipal)
{ {
nsNSSShutDownPreventionLock locker;
SEC_PKCS7DecoderContext * p7_ctxt = nsnull; SEC_PKCS7DecoderContext * p7_ctxt = nsnull;
SEC_PKCS7ContentInfo * p7_info = nsnull; SEC_PKCS7ContentInfo * p7_info = nsnull;
unsigned char hash[SHA1_LENGTH]; unsigned char hash[SHA1_LENGTH];
@ -1322,6 +1330,8 @@ nsNSSComponent::VerifySignature(const char* aRSABuf, PRUint32 aRSABufLen,
NS_IMETHODIMP NS_IMETHODIMP
nsNSSComponent::RandomUpdate(void *entropy, PRInt32 bufLen) nsNSSComponent::RandomUpdate(void *entropy, PRInt32 bufLen)
{ {
nsNSSShutDownPreventionLock locker;
// Asynchronous event happening often, // Asynchronous event happening often,
// must not interfere with initialization or profile switch. // must not interfere with initialization or profile switch.
@ -1346,6 +1356,7 @@ nsNSSComponent::PrefChangedCallback(const char* aPrefName, void* data)
void void
nsNSSComponent::PrefChanged(const char* prefName) nsNSSComponent::PrefChanged(const char* prefName)
{ {
nsNSSShutDownPreventionLock locker;
PRBool enabled; PRBool enabled;
if (!nsCRT::strcmp(prefName, "security.enable_ssl2")) { if (!nsCRT::strcmp(prefName, "security.enable_ssl2")) {
@ -1371,7 +1382,9 @@ nsNSSComponent::PrefChanged(const char* prefName)
} }
} }
#ifdef DEBUG #define DEBUG_PSM_PROFILE
#ifdef DEBUG_PSM_PROFILE
#define PROFILE_CHANGE_NET_TEARDOWN_TOPIC NS_LITERAL_CSTRING("profile-change-net-teardown").get() #define PROFILE_CHANGE_NET_TEARDOWN_TOPIC NS_LITERAL_CSTRING("profile-change-net-teardown").get()
#define PROFILE_CHANGE_NET_RESTORE_TOPIC NS_LITERAL_CSTRING("profile-change-net-restore").get() #define PROFILE_CHANGE_NET_RESTORE_TOPIC NS_LITERAL_CSTRING("profile-change-net-restore").get()
#endif #endif
@ -1392,7 +1405,7 @@ nsNSSComponent::Observe(nsISupports *aSubject, const char *aTopic,
#endif #endif
if (nsCRT::strcmp(aTopic, PROFILE_APPROVE_CHANGE_TOPIC) == 0) { if (nsCRT::strcmp(aTopic, PROFILE_APPROVE_CHANGE_TOPIC) == 0) {
if (mPSMTracker->isUIActive()) { if (mShutdownObjectList->isUIActive()) {
ShowAlert(ai_crypto_ui_active); ShowAlert(ai_crypto_ui_active);
nsCOMPtr<nsIProfileChangeStatus> status = do_QueryInterface(aSubject); nsCOMPtr<nsIProfileChangeStatus> status = do_QueryInterface(aSubject);
if (status) { if (status) {
@ -1405,11 +1418,11 @@ nsNSSComponent::Observe(nsISupports *aSubject, const char *aTopic,
PRBool callVeto = PR_FALSE; PRBool callVeto = PR_FALSE;
if (!mPSMTracker->ifPossibleDisallowUI()) { if (!mShutdownObjectList->ifPossibleDisallowUI()) {
callVeto = PR_TRUE; callVeto = PR_TRUE;
ShowAlert(ai_crypto_ui_active); ShowAlert(ai_crypto_ui_active);
} }
else if (mPSMTracker->areSSLSocketsActive()) { else if (mShutdownObjectList->areSSLSocketsActive()) {
callVeto = PR_TRUE; callVeto = PR_TRUE;
ShowAlert(ai_sockets_still_active); ShowAlert(ai_sockets_still_active);
} }
@ -1422,7 +1435,7 @@ nsNSSComponent::Observe(nsISupports *aSubject, const char *aTopic,
} }
} }
else if (nsCRT::strcmp(aTopic, PROFILE_CHANGE_TEARDOWN_VETO_TOPIC) == 0) { else if (nsCRT::strcmp(aTopic, PROFILE_CHANGE_TEARDOWN_VETO_TOPIC) == 0) {
mPSMTracker->allowUI(); mShutdownObjectList->allowUI();
} }
else if (nsCRT::strcmp(aTopic, PROFILE_BEFORE_CHANGE_TOPIC) == 0) { else if (nsCRT::strcmp(aTopic, PROFILE_BEFORE_CHANGE_TOPIC) == 0) {
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("receiving profile change topic\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("receiving profile change topic\n"));
@ -1448,8 +1461,8 @@ nsNSSComponent::Observe(nsISupports *aSubject, const char *aTopic,
if (needsCleanup) { if (needsCleanup) {
ShutdownNSS(); ShutdownNSS();
} }
mShutdownObjectList->allowUI();
mPSMTracker->allowUI();
} }
else if (nsCRT::strcmp(aTopic, PROFILE_AFTER_CHANGE_TOPIC) == 0) { else if (nsCRT::strcmp(aTopic, PROFILE_AFTER_CHANGE_TOPIC) == 0) {
@ -1501,7 +1514,9 @@ nsNSSComponent::Observe(nsISupports *aSubject, const char *aTopic,
} }
} }
else if ((nsCRT::strcmp(aTopic, SESSION_LOGOUT_TOPIC) == 0) && mNSSInitialized) { else if ((nsCRT::strcmp(aTopic, SESSION_LOGOUT_TOPIC) == 0) && mNSSInitialized) {
nsNSSShutDownPreventionLock locker;
PK11_LogoutAll(); PK11_LogoutAll();
LogoutAuthenticatedPK11();
} }
@ -1574,6 +1589,11 @@ void nsNSSComponent::ShowAlert(AlertIdentifier ai)
} }
} }
nsresult nsNSSComponent::LogoutAuthenticatedPK11()
{
return mShutdownObjectList->doPK11Logout();
}
nsresult nsresult
nsNSSComponent::RegisterObservers() nsNSSComponent::RegisterObservers()
{ {
@ -1611,6 +1631,8 @@ nsNSSComponent::RegisterObservers()
NS_IMETHODIMP NS_IMETHODIMP
nsNSSComponent::RememberCert(CERTCertificate *cert) nsNSSComponent::RememberCert(CERTCertificate *cert)
{ {
nsNSSShutDownPreventionLock locker;
// Must not interfere with init / shutdown / profile switch. // Must not interfere with init / shutdown / profile switch.
nsAutoLock lock(mutex); nsAutoLock lock(mutex);
@ -1713,6 +1735,7 @@ getNSSDialogs(void **_result, REFNSIID aIID, const char *contract)
nsresult nsresult
setPassword(PK11SlotInfo *slot, nsIInterfaceRequestor *ctx) setPassword(PK11SlotInfo *slot, nsIInterfaceRequestor *ctx)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (PK11_NeedUserInit(slot)) { if (PK11_NeedUserInit(slot)) {
@ -1835,6 +1858,7 @@ PSMContentDownloader::OnStopRequest(nsIRequest* request,
nsISupports* context, nsISupports* context,
nsresult aStatus) nsresult aStatus)
{ {
nsNSSShutDownPreventionLock locker;
//Check if the download succeeded - it might have failed due to //Check if the download succeeded - it might have failed due to
//network issues, etc. //network issues, etc.
if (NS_FAILED(aStatus)){ if (NS_FAILED(aStatus)){

Просмотреть файл

@ -126,10 +126,12 @@ class NS_NO_VTABLE nsINSSComponent : public nsISupports {
NS_IMETHOD DownloadCRLDirectly(nsAutoString, nsAutoString) = 0; NS_IMETHOD DownloadCRLDirectly(nsAutoString, nsAutoString) = 0;
NS_IMETHOD LogoutAuthenticatedPK11() = 0;
}; };
struct PRLock; struct PRLock;
class nsPSMTracker; class nsNSSShutDownList;
// Implementation of the PSM component interface. // Implementation of the PSM component interface.
class nsNSSComponent : public nsISignatureVerifier, class nsNSSComponent : public nsISignatureVerifier,
@ -167,6 +169,7 @@ public:
nsresult StopCRLUpdateTimer(); nsresult StopCRLUpdateTimer();
NS_IMETHOD RemoveCrlFromList(nsAutoString); NS_IMETHOD RemoveCrlFromList(nsAutoString);
NS_IMETHOD DefineNextTimer(); NS_IMETHOD DefineNextTimer();
NS_IMETHOD LogoutAuthenticatedPK11();
NS_IMETHOD DownloadCRLDirectly(nsAutoString, nsAutoString); NS_IMETHOD DownloadCRLDirectly(nsAutoString, nsAutoString);
NS_IMETHOD RememberCert(CERTCertificate *cert); NS_IMETHOD RememberCert(CERTCertificate *cert);
static nsresult GetNSSCipherIDFromPrefString(const nsACString &aPrefString, PRUint16 &aCipherId); static nsresult GetNSSCipherIDFromPrefString(const nsACString &aPrefString, PRUint16 &aCipherId);
@ -211,7 +214,7 @@ private:
PRBool crlDownloadTimerOn; PRBool crlDownloadTimerOn;
PRBool mUpdateTimerInitialized; PRBool mUpdateTimerInitialized;
static int mInstanceCount; static int mInstanceCount;
nsPSMTracker *mPSMTracker; nsNSSShutDownList *mShutdownObjectList;
}; };
class PSMContentListener : public nsIURIContentListener, class PSMContentListener : public nsIURIContentListener,

Просмотреть файл

@ -59,7 +59,7 @@
#include "nsHashSets.h" #include "nsHashSets.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
#include "nsPSMTracker.h" #include "nsNSSShutDown.h"
#include "ssl.h" #include "ssl.h"
#include "secerr.h" #include "secerr.h"
@ -151,8 +151,27 @@ nsNSSSocketInfo::nsNSSSocketInfo()
nsNSSSocketInfo::~nsNSSSocketInfo() nsNSSSocketInfo::~nsNSSSocketInfo()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsNSSSocketInfo::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsNSSSocketInfo::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (mCAChain) { if (mCAChain) {
CERT_DestroyCertList(mCAChain); CERT_DestroyCertList(mCAChain);
mCAChain = nsnull;
} }
} }
@ -340,6 +359,10 @@ nsNSSSocketInfo::StartTLS()
nsresult nsNSSSocketInfo::ActivateSSL() nsresult nsNSSSocketInfo::ActivateSSL()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
if (SECSuccess != SSL_OptionSet(mFd, SSL_SECURITY, PR_TRUE)) if (SECSuccess != SSL_OptionSet(mFd, SSL_SECURITY, PR_TRUE))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -375,6 +398,10 @@ nsresult nsNSSSocketInfo::GetSSLStatus(nsISupports** _result)
nsresult nsNSSSocketInfo::RememberCAChain(CERTCertList *aCertList) nsresult nsNSSSocketInfo::RememberCAChain(CERTCertList *aCertList)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
if (mCAChain) { if (mCAChain) {
CERT_DestroyCertList(mCAChain); CERT_DestroyCertList(mCAChain);
} }
@ -823,6 +850,7 @@ nsSSLIOLayerConnect(PRFileDesc* fd, const PRNetAddr* addr,
PRIntervalTime timeout) PRIntervalTime timeout)
{ {
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("[%p] connecting SSL socket\n", (void*)fd)); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("[%p] connecting SSL socket\n", (void*)fd));
nsNSSShutDownPreventionLock locker;
if (!fd || !fd->lower) if (!fd || !fd->lower)
return PR_FAILURE; return PR_FAILURE;
@ -875,6 +903,7 @@ nsSSLIOLayerConnect(PRFileDesc* fd, const PRNetAddr* addr,
static PRInt32 PR_CALLBACK static PRInt32 PR_CALLBACK
nsSSLIOLayerAvailable(PRFileDesc *fd) nsSSLIOLayerAvailable(PRFileDesc *fd)
{ {
nsNSSShutDownPreventionLock locker;
if (!fd || !fd->lower) if (!fd || !fd->lower)
return PR_FAILURE; return PR_FAILURE;
@ -909,11 +938,13 @@ rememberPossibleTLSProblemSite(PRFileDesc* fd, nsNSSSocketInfo *socketInfo)
static PRStatus PR_CALLBACK static PRStatus PR_CALLBACK
nsSSLIOLayerClose(PRFileDesc *fd) nsSSLIOLayerClose(PRFileDesc *fd)
{ {
nsNSSShutDownPreventionLock locker;
if (!fd) if (!fd)
return PR_FAILURE; return PR_FAILURE;
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("[%p] Shutting down socket\n", (void*)fd)); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("[%p] Shutting down socket\n", (void*)fd));
nsPSMTracker::decreaseSSLSocketCounter();
nsNSSShutDownList::trackSSLSocketClose();
PRFileDesc* popped = PR_PopIOLayer(fd, PR_TOP_IO_LAYER); PRFileDesc* popped = PR_PopIOLayer(fd, PR_TOP_IO_LAYER);
nsNSSSocketInfo *infoObject = (nsNSSSocketInfo *)popped->secret; nsNSSSocketInfo *infoObject = (nsNSSSocketInfo *)popped->secret;
@ -926,7 +957,6 @@ nsSSLIOLayerClose(PRFileDesc *fd)
if (status != PR_SUCCESS) return status; if (status != PR_SUCCESS) return status;
popped->identity = PR_INVALID_IO_LAYER; popped->identity = PR_INVALID_IO_LAYER;
NS_RELEASE(infoObject); NS_RELEASE(infoObject);
popped->dtor(popped); popped->dtor(popped);
@ -1094,6 +1124,7 @@ checkHandshake(PRBool calledFromRead, PRInt32 bytesTransfered,
static PRInt32 PR_CALLBACK static PRInt32 PR_CALLBACK
nsSSLIOLayerRead(PRFileDesc* fd, void* buf, PRInt32 amount) nsSSLIOLayerRead(PRFileDesc* fd, void* buf, PRInt32 amount)
{ {
nsNSSShutDownPreventionLock locker;
if (!fd || !fd->lower) { if (!fd || !fd->lower) {
return PR_FAILURE; return PR_FAILURE;
} }
@ -1102,6 +1133,11 @@ nsSSLIOLayerRead(PRFileDesc* fd, void* buf, PRInt32 amount)
socketInfo = (nsNSSSocketInfo*)fd->secret; socketInfo = (nsNSSSocketInfo*)fd->secret;
NS_ASSERTION(socketInfo,"nsNSSSocketInfo was null for an fd"); NS_ASSERTION(socketInfo,"nsNSSSocketInfo was null for an fd");
if (socketInfo->isPK11LoggedOut() || socketInfo->isAlreadyShutDown()) {
PR_SetError(PR_SOCKET_SHUTDOWN_ERROR, 0);
return -1;
}
if (socketInfo->GetCanceled()) { if (socketInfo->GetCanceled()) {
return PR_FAILURE; return PR_FAILURE;
} }
@ -1118,6 +1154,7 @@ nsSSLIOLayerRead(PRFileDesc* fd, void* buf, PRInt32 amount)
static PRInt32 PR_CALLBACK static PRInt32 PR_CALLBACK
nsSSLIOLayerWrite(PRFileDesc* fd, const void* buf, PRInt32 amount) nsSSLIOLayerWrite(PRFileDesc* fd, const void* buf, PRInt32 amount)
{ {
nsNSSShutDownPreventionLock locker;
if (!fd || !fd->lower) { if (!fd || !fd->lower) {
return PR_FAILURE; return PR_FAILURE;
} }
@ -1129,6 +1166,11 @@ nsSSLIOLayerWrite(PRFileDesc* fd, const void* buf, PRInt32 amount)
socketInfo = (nsNSSSocketInfo*)fd->secret; socketInfo = (nsNSSSocketInfo*)fd->secret;
NS_ASSERTION(socketInfo,"nsNSSSocketInfo was null for an fd"); NS_ASSERTION(socketInfo,"nsNSSSocketInfo was null for an fd");
if (socketInfo->isPK11LoggedOut() || socketInfo->isAlreadyShutDown()) {
PR_SetError(PR_SOCKET_SHUTDOWN_ERROR, 0);
return -1;
}
if (socketInfo->GetCanceled()) { if (socketInfo->GetCanceled()) {
return PR_FAILURE; return PR_FAILURE;
} }
@ -1835,6 +1877,7 @@ SECStatus nsNSS_SSLGetClientAuthData(void* arg, PRFileDesc* socket,
CERTCertificate** pRetCert, CERTCertificate** pRetCert,
SECKEYPrivateKey** pRetKey) SECKEYPrivateKey** pRetKey)
{ {
nsNSSShutDownPreventionLock locker;
void* wincx = NULL; void* wincx = NULL;
SECStatus ret = SECFailure; SECStatus ret = SECFailure;
nsresult rv; nsresult rv;
@ -2033,6 +2076,8 @@ SECStatus nsNSS_SSLGetClientAuthData(void* arg, PRFileDesc* socket,
NS_ConvertUTF8toUCS2 issuer(cissuer); NS_ConvertUTF8toUCS2 issuer(cissuer);
if (cissuer) PORT_Free(cissuer); if (cissuer) PORT_Free(cissuer);
CERT_DestroyCertificate(serverCert);
certNicknameList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames); certNicknameList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames);
certDetailsList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames); certDetailsList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames);
@ -2163,6 +2208,7 @@ done:
static SECStatus static SECStatus
nsNSSBadCertHandler(void *arg, PRFileDesc *sslSocket) nsNSSBadCertHandler(void *arg, PRFileDesc *sslSocket)
{ {
nsNSSShutDownPreventionLock locker;
SECStatus rv = SECFailure; SECStatus rv = SECFailure;
int error; int error;
nsNSSSocketInfo* infoObject = (nsNSSSocketInfo *)arg; nsNSSSocketInfo* infoObject = (nsNSSSocketInfo *)arg;
@ -2200,6 +2246,7 @@ nsSSLIOLayerImportFD(PRFileDesc *fd,
nsNSSSocketInfo *infoObject, nsNSSSocketInfo *infoObject,
const char *host) const char *host)
{ {
nsNSSShutDownPreventionLock locker;
PRFileDesc* sslSock = SSL_ImportFD(nsnull, fd); PRFileDesc* sslSock = SSL_ImportFD(nsnull, fd);
if (!sslSock) { if (!sslSock) {
NS_ASSERTION(PR_FALSE, "NSS: Error importing socket"); NS_ASSERTION(PR_FALSE, "NSS: Error importing socket");
@ -2230,6 +2277,7 @@ nsSSLIOLayerSetOptions(PRFileDesc *fd, PRBool forSTARTTLS,
const char *proxyHost, const char *host, PRInt32 port, const char *proxyHost, const char *host, PRInt32 port,
nsNSSSocketInfo *infoObject) nsNSSSocketInfo *infoObject)
{ {
nsNSSShutDownPreventionLock locker;
if (forSTARTTLS || proxyHost) { if (forSTARTTLS || proxyHost) {
if (SECSuccess != SSL_OptionSet(fd, SSL_SECURITY, PR_FALSE)) { if (SECSuccess != SSL_OptionSet(fd, SSL_SECURITY, PR_FALSE)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -2283,6 +2331,7 @@ nsSSLIOLayerAddToSocket(const char* host,
nsISupports** info, nsISupports** info,
PRBool forSTARTTLS) PRBool forSTARTTLS)
{ {
nsNSSShutDownPreventionLock locker;
PRFileDesc* layer = nsnull; PRFileDesc* layer = nsnull;
nsresult rv; nsresult rv;
@ -2331,7 +2380,7 @@ nsSSLIOLayerAddToSocket(const char* host,
goto loser; goto loser;
} }
nsPSMTracker::increaseSSLSocketCounter(); nsNSSShutDownList::trackSSLSocketCreate();
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("[%p] Socket set up\n", (void*)sslSock)); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("[%p] Socket set up\n", (void*)sslSock));
infoObject->QueryInterface(NS_GET_IID(nsISupports), (void**) (info)); infoObject->QueryInterface(NS_GET_IID(nsISupports), (void**) (info));

Просмотреть файл

@ -35,13 +35,16 @@
#include "nsISSLStatus.h" #include "nsISSLStatus.h"
#include "nsISSLStatusProvider.h" #include "nsISSLStatusProvider.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsNSSShutDown.h"
class nsIChannel; class nsIChannel;
class nsNSSSocketInfo : public nsITransportSecurityInfo, class nsNSSSocketInfo : public nsITransportSecurityInfo,
public nsISSLSocketControl, public nsISSLSocketControl,
public nsIInterfaceRequestor, public nsIInterfaceRequestor,
public nsISSLStatusProvider public nsISSLStatusProvider,
public nsNSSShutDownObject,
public nsOnPK11LogoutCancelObject
{ {
public: public:
nsNSSSocketInfo(); nsNSSSocketInfo();
@ -103,6 +106,9 @@ protected:
nsCOMPtr<nsISSLStatus> mSSLStatus; nsCOMPtr<nsISSLStatus> mSSLStatus;
nsresult ActivateSSL(); nsresult ActivateSSL();
private:
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
nsresult nsSSLIOLayerNewSocket(const char *host, nsresult nsSSLIOLayerNewSocket(const char *host,

Просмотреть файл

@ -0,0 +1,505 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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.
*
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Kai Engert <kaie@netscape.com>
*
* 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 ***** */
#include "nsNSSShutDown.h"
#include "nsCOMPtr.h"
#ifdef PR_LOGGING
extern PRLogModuleInfo* gPIPNSSLog;
#endif
struct ObjectHashEntry : PLDHashEntryHdr {
nsNSSShutDownObject *obj;
};
PR_STATIC_CALLBACK(const void *)
ObjectSetGetKey(PLDHashTable *table, PLDHashEntryHdr *hdr)
{
ObjectHashEntry *entry = NS_STATIC_CAST(ObjectHashEntry*, hdr);
return entry->obj;
}
PR_STATIC_CALLBACK(PRBool)
ObjectSetMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
const void *key)
{
const ObjectHashEntry *entry = NS_STATIC_CAST(const ObjectHashEntry*, hdr);
return entry->obj == NS_STATIC_CAST(const nsNSSShutDownObject*, key);
}
PR_STATIC_CALLBACK(void)
ObjectSetInitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
const void *key)
{
ObjectHashEntry *entry = NS_STATIC_CAST(ObjectHashEntry*, hdr);
entry->obj = NS_CONST_CAST(nsNSSShutDownObject*, NS_STATIC_CAST(const nsNSSShutDownObject*, key));
}
static PLDHashTableOps gSetOps = {
PL_DHashAllocTable,
PL_DHashFreeTable,
ObjectSetGetKey,
PL_DHashVoidPtrKeyStub,
ObjectSetMatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PL_DHashFinalizeStub,
ObjectSetInitEntry
};
nsNSSShutDownList *nsNSSShutDownList::singleton = nsnull;
nsNSSShutDownList::nsNSSShutDownList()
{
mListLock = PR_NewLock();
mActiveSSLSockets = 0;
mPK11LogoutCancelObjects.ops = nsnull;
mObjects.ops = nsnull;
PL_DHashTableInit(&mObjects, &gSetOps, nsnull,
sizeof(ObjectHashEntry), 16);
PL_DHashTableInit(&mPK11LogoutCancelObjects, &gSetOps, nsnull,
sizeof(ObjectHashEntry), 16);
}
nsNSSShutDownList::~nsNSSShutDownList()
{
if (mListLock) {
PR_DestroyLock(mListLock);
mListLock = nsnull;
}
if (mObjects.ops) {
PL_DHashTableFinish(&mObjects);
mObjects.ops = nsnull;
}
if (mPK11LogoutCancelObjects.ops) {
PL_DHashTableFinish(&mPK11LogoutCancelObjects);
mPK11LogoutCancelObjects.ops = nsnull;
}
PR_ASSERT(this == singleton);
singleton = nsnull;
}
void nsNSSShutDownList::remember(nsNSSShutDownObject *o)
{
if (!singleton)
return;
PR_ASSERT(o);
PR_Lock(singleton->mListLock);
PL_DHashTableOperate(&singleton->mObjects, o, PL_DHASH_ADD);
PR_Unlock(singleton->mListLock);
}
void nsNSSShutDownList::forget(nsNSSShutDownObject *o)
{
if (!singleton)
return;
PR_ASSERT(o);
PR_Lock(singleton->mListLock);
PL_DHashTableOperate(&singleton->mObjects, o, PL_DHASH_REMOVE);
PR_Unlock(singleton->mListLock);
}
void nsNSSShutDownList::remember(nsOnPK11LogoutCancelObject *o)
{
if (!singleton)
return;
PR_ASSERT(o);
PR_Lock(singleton->mListLock);
PL_DHashTableOperate(&singleton->mPK11LogoutCancelObjects, o, PL_DHASH_ADD);
PR_Unlock(singleton->mListLock);
}
void nsNSSShutDownList::forget(nsOnPK11LogoutCancelObject *o)
{
if (!singleton)
return;
PR_ASSERT(o);
PR_Lock(singleton->mListLock);
PL_DHashTableOperate(&singleton->mPK11LogoutCancelObjects, o, PL_DHASH_REMOVE);
PR_Unlock(singleton->mListLock);
}
void nsNSSShutDownList::trackSSLSocketCreate()
{
if (!singleton)
return;
PR_Lock(singleton->mListLock);
++singleton->mActiveSSLSockets;
PR_Unlock(singleton->mListLock);
}
void nsNSSShutDownList::trackSSLSocketClose()
{
if (!singleton)
return;
PR_Lock(singleton->mListLock);
--singleton->mActiveSSLSockets;
PR_Unlock(singleton->mListLock);
}
PRBool nsNSSShutDownList::areSSLSocketsActive()
{
if (!singleton) {
// I'd rather prefer to be pessimistic and return PR_TRUE.
// However, maybe we will get called at a time when the singleton
// has already been freed, and returning PR_TRUE would bring up an
// unnecessary warning.
return PR_FALSE;
}
PRBool retval;
PR_Lock(singleton->mListLock);
retval = (singleton->mActiveSSLSockets > 0);
PR_Unlock(singleton->mListLock);
return retval;
}
nsresult nsNSSShutDownList::doPK11Logout()
{
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("canceling all open SSL sockets to disallow future IO\n"));
// During our iteration we will set a bunch of PRBools to PR_TRUE.
// Nobody else ever modifies that PRBool, only we do.
// We only must ensure that our objects do not go away.
// This is guaranteed by holding the list lock.
PR_Lock(mListLock);
PL_DHashTableEnumerate(&mPK11LogoutCancelObjects, doPK11LogoutHelper, 0);
PR_Unlock(mListLock);
return NS_OK;
}
PLDHashOperator nsNSSShutDownList::doPK11LogoutHelper(PLDHashTable *table,
PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
{
ObjectHashEntry *entry = NS_STATIC_CAST(ObjectHashEntry*, hdr);
nsOnPK11LogoutCancelObject *pklco =
NS_REINTERPRET_CAST(nsOnPK11LogoutCancelObject*, entry->obj);
if (pklco) {
pklco->logout();
}
return PL_DHASH_NEXT;
}
PRBool nsNSSShutDownList::isUIActive()
{
PRBool canDisallow = mActivityState.ifPossibleDisallowUI(nsNSSActivityState::test_only);
PRBool bIsUIActive = !canDisallow;
return bIsUIActive;
}
PRBool nsNSSShutDownList::ifPossibleDisallowUI()
{
PRBool isNowDisallowed = mActivityState.ifPossibleDisallowUI(nsNSSActivityState::do_it_for_real);
return isNowDisallowed;
}
void nsNSSShutDownList::allowUI()
{
mActivityState.allowUI();
}
nsresult nsNSSShutDownList::evaporateAllNSSResources()
{
if (PR_SUCCESS != mActivityState.restrictActivityToCurrentThread()) {
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("failed to restrict activity to current thread\n"));
return NS_ERROR_FAILURE;
}
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("now evaporating NSS resources\n"));
int removedCount;
do {
PR_Lock(mListLock);
removedCount = PL_DHashTableEnumerate(&mObjects, evaporateAllNSSResourcesHelper, 0);
PR_Unlock(mListLock);
} while (removedCount > 0);
mActivityState.releaseCurrentThreadActivityRestriction();
return NS_OK;
}
PLDHashOperator nsNSSShutDownList::evaporateAllNSSResourcesHelper(PLDHashTable *table,
PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
{
ObjectHashEntry *entry = NS_STATIC_CAST(ObjectHashEntry*, hdr);
PR_Unlock(singleton->mListLock);
entry->obj->shutdown(nsNSSShutDownObject::calledFromList);
PR_Lock(singleton->mListLock);
// Never free more than one entry, because other threads might be calling
// us and remove themselves while we are iterating over the list,
// and the behaviour of changing the list while iterating is undefined.
return (PLDHashOperator)(PL_DHASH_STOP | PL_DHASH_REMOVE);
}
nsNSSShutDownList *nsNSSShutDownList::construct()
{
if (singleton) {
// we should never ever be called twice
return nsnull;
}
singleton = new nsNSSShutDownList();
return singleton;
}
nsNSSActivityState::nsNSSActivityState()
:mNSSActivityStateLock(nsnull),
mNSSActivityChanged(nsnull),
mNSSActivityCounter(0),
mBlockingUICounter(0),
mIsUIForbidden(PR_FALSE),
mNSSRestrictedThread(nsnull)
{
mNSSActivityStateLock = PR_NewLock();
if (!mNSSActivityStateLock)
return;
mNSSActivityChanged = PR_NewCondVar(mNSSActivityStateLock);
}
nsNSSActivityState::~nsNSSActivityState()
{
if (mNSSActivityChanged) {
PR_DestroyCondVar(mNSSActivityChanged);
mNSSActivityChanged = nsnull;
}
if (mNSSActivityStateLock) {
PR_DestroyLock(mNSSActivityStateLock);
mNSSActivityStateLock = nsnull;
}
}
void nsNSSActivityState::enter()
{
PR_Lock(mNSSActivityStateLock);
while (mNSSRestrictedThread && mNSSRestrictedThread != PR_GetCurrentThread()) {
PR_WaitCondVar(mNSSActivityChanged, PR_INTERVAL_NO_TIMEOUT);
}
++mNSSActivityCounter;
PR_Unlock(mNSSActivityStateLock);
}
void nsNSSActivityState::leave()
{
PR_Lock(mNSSActivityStateLock);
--mNSSActivityCounter;
if (!mNSSActivityCounter) {
PR_NotifyAllCondVar(mNSSActivityChanged);
}
PR_Unlock(mNSSActivityStateLock);
}
void nsNSSActivityState::enterBlockingUIState()
{
PR_Lock(mNSSActivityStateLock);
++mBlockingUICounter;
PR_Unlock(mNSSActivityStateLock);
}
void nsNSSActivityState::leaveBlockingUIState()
{
PR_Lock(mNSSActivityStateLock);
--mBlockingUICounter;
PR_Unlock(mNSSActivityStateLock);
}
PRBool nsNSSActivityState::isBlockingUIActive()
{
PRBool retval;
PR_Lock(mNSSActivityStateLock);
retval = (mBlockingUICounter > 0);
PR_Unlock(mNSSActivityStateLock);
return retval;
}
PRBool nsNSSActivityState::isUIForbidden()
{
PRBool retval;
PR_Lock(mNSSActivityStateLock);
retval = mIsUIForbidden;
PR_Unlock(mNSSActivityStateLock);
return retval;
}
PRBool nsNSSActivityState::ifPossibleDisallowUI(RealOrTesting rot)
{
PRBool retval = PR_FALSE;
PR_Lock(mNSSActivityStateLock);
// Checking and disallowing the UI must be done atomically.
if (!mBlockingUICounter) {
// No UI is currently shown, we are able to evaporate.
retval = PR_TRUE;
if (rot == do_it_for_real) {
// Remember to disallow UI.
mIsUIForbidden = PR_TRUE;
// to clear the "forbidden" state,
// one must either call
// restrictActivityToCurrentThread() + releaseCurrentThreadActivityRestriction()
// or cancel the operation by calling
// unprepareCurrentThreadRestriction()
}
}
PR_Unlock(mNSSActivityStateLock);
return retval;
}
void nsNSSActivityState::allowUI()
{
PR_Lock(mNSSActivityStateLock);
mIsUIForbidden = PR_FALSE;
PR_Unlock(mNSSActivityStateLock);
}
PRStatus nsNSSActivityState::restrictActivityToCurrentThread()
{
PRStatus retval = PR_FAILURE;
PR_Lock(mNSSActivityStateLock);
if (!mBlockingUICounter) {
while (0 < mNSSActivityCounter && !mBlockingUICounter) {
PR_WaitCondVar(mNSSActivityChanged, PR_TicksPerSecond());
}
if (mBlockingUICounter) {
// This should never happen.
// If we arrive here, our logic is broken.
PR_ASSERT(0);
}
else {
mNSSRestrictedThread = PR_GetCurrentThread();
retval = PR_SUCCESS;
}
}
PR_Unlock(mNSSActivityStateLock);
return retval;
}
void nsNSSActivityState::releaseCurrentThreadActivityRestriction()
{
PR_Lock(mNSSActivityStateLock);
mNSSRestrictedThread = nsnull;
mIsUIForbidden = PR_FALSE;
PR_NotifyAllCondVar(mNSSActivityChanged);
PR_Unlock(mNSSActivityStateLock);
}
nsNSSShutDownPreventionLock::nsNSSShutDownPreventionLock()
{
nsNSSActivityState *state = nsNSSShutDownList::getActivityState();
if (!state)
return;
state->enter();
}
nsNSSShutDownPreventionLock::~nsNSSShutDownPreventionLock()
{
nsNSSActivityState *state = nsNSSShutDownList::getActivityState();
if (!state)
return;
state->leave();
}
nsPSMUITracker::nsPSMUITracker()
{
nsNSSActivityState *state = nsNSSShutDownList::getActivityState();
if (!state)
return;
state->enterBlockingUIState();
}
nsPSMUITracker::~nsPSMUITracker()
{
nsNSSActivityState *state = nsNSSShutDownList::getActivityState();
if (!state)
return;
state->leaveBlockingUIState();
}
PRBool nsPSMUITracker::isUIForbidden()
{
nsNSSActivityState *state = nsNSSShutDownList::getActivityState();
if (!state)
return PR_FALSE;
return state->isUIForbidden();
}

Просмотреть файл

@ -0,0 +1,337 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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.
*
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Kai Engert <kaie@netscape.com>
*
* 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 ***** */
#ifndef _INC_NSSShutDown_H
#define _INC_NSSShutDown_H
#include "nscore.h"
#include "nspr.h"
#include "pldhash.h"
class nsNSSShutDownObject;
class nsOnPK11LogoutCancelObject;
// Singleton, owner by nsNSSShutDownList
class nsNSSActivityState
{
public:
nsNSSActivityState();
~nsNSSActivityState();
// Call enter/leave when PSM enters a scope during which
// shutting down NSS is prohibited.
void enter();
void leave();
// Call enter/leave when PSM is about to show a UI
// while still holding resources.
void enterBlockingUIState();
void leaveBlockingUIState();
// Is the activity aware of any blocking PSM UI currently shown?
PRBool isBlockingUIActive();
// Is it forbidden to bring up an UI while holding resources?
PRBool isUIForbidden();
// Check whether setting the current thread restriction is possible.
// If it is possible, and the "do_it_for_real" flag is used,
// the state tracking will have ensured that we will stay in this state.
// As of writing, this includes forbidding PSM UI.
enum RealOrTesting {test_only, do_it_for_real};
PRBool ifPossibleDisallowUI(RealOrTesting rot);
// Notify the state tracking that going to the restricted state is
// no longer planned.
// As of writing, this includes clearing the "PSM UI forbidden" flag.
void allowUI();
// If currently no UI is shown, wait for all activity to stop,
// and block any other thread on entering relevant PSM code.
PRStatus restrictActivityToCurrentThread();
// Go back to normal state.
void releaseCurrentThreadActivityRestriction();
private:
// The lock protecting all our member variables.
PRLock *mNSSActivityStateLock;
// The activity variable, bound to our lock,
// used either to signal the activity counter reaches zero,
// or a thread restriction has been released.
PRCondVar *mNSSActivityChanged;
// The number of active scopes holding resources.
int mNSSActivityCounter;
// The number of scopes holding resources while blocked
// showing an UI.
int mBlockingUICounter;
// Whether bringing up UI is currently forbidden
PRBool mIsUIForbidden;
// nsnull means "no restriction"
// if != nsnull, activity is only allowed on that thread
PRThread* mNSSRestrictedThread;
};
// Helper class that automatically enters/leaves the global activity state
class nsNSSShutDownPreventionLock
{
public:
nsNSSShutDownPreventionLock();
~nsNSSShutDownPreventionLock();
};
// Helper class that automatically enters/leaves the global UI tracking
class nsPSMUITracker
{
public:
nsPSMUITracker();
~nsPSMUITracker();
PRBool isUIForbidden();
};
// Singleton, used by nsNSSComponent to track the list of PSM objects,
// which hold NSS resources and support the "early cleanup mechanism".
class nsNSSShutDownList
{
public:
~nsNSSShutDownList();
static nsNSSShutDownList *construct();
// track instances that support early cleanup
static void remember(nsNSSShutDownObject *o);
static void forget(nsNSSShutDownObject *o);
// track instances that would like notification when
// a PK11 logout operation is performed.
static void remember(nsOnPK11LogoutCancelObject *o);
static void forget(nsOnPK11LogoutCancelObject *o);
// track the creation and destruction of SSL sockets
// performed by clients using PSM services
static void trackSSLSocketCreate();
static void trackSSLSocketClose();
static PRBool areSSLSocketsActive();
// Are we able to do the early cleanup?
// Returns failure if at the current time "early cleanup" is not possible.
PRBool isUIActive();
// If possible to do "early cleanup" at the current time, remember that we want to
// do it, and disallow actions that would change the possibility.
PRBool ifPossibleDisallowUI();
// Notify that it is no longer planned to do the "early cleanup".
void allowUI();
// Do the "early cleanup", if possible.
nsresult evaporateAllNSSResources();
// PSM has been asked to log out of a token.
// Notify all registered instances that want to react to that event.
nsresult doPK11Logout();
static nsNSSActivityState *getActivityState()
{
return singleton ? &singleton->mActivityState : nsnull;
}
private:
nsNSSShutDownList();
static PLDHashOperator evaporateAllNSSResourcesHelper(PLDHashTable *table, PLDHashEntryHdr *hdr,
PRUint32 number, void *arg);
static PLDHashOperator doPK11LogoutHelper(PLDHashTable *table, PLDHashEntryHdr *hdr,
PRUint32 number, void *arg);
protected:
PRLock* mListLock;
static nsNSSShutDownList *singleton;
PLDHashTable mObjects;
PRUint32 mActiveSSLSockets;
PLDHashTable mPK11LogoutCancelObjects;
nsNSSActivityState mActivityState;
};
/*
A class deriving from nsNSSShutDownObject will have its instances
automatically tracked in a list. However, it must follow some rules
to assure correct behaviour.
The tricky part is that it is not possible to call virtual
functions from a destructor.
The deriving class must override virtualDestroyNSSReference().
Within this function, it should clean up all resources held to NSS.
The function will be called by the global list, if it is time to
shut down NSS before all references have been freed.
The same code that goes into virtualDestroyNSSReference must
also be called from the destructor of the deriving class,
which is the standard cleanup (not called from the tracking list).
Because of that duplication, it is suggested to implement a
function destructorSafeDestroyNSSReference() in the deriving
class, and make the implementation of virtualDestroyNSSReference()
call destructorSafeDestroyNSSReference().
The destructor of the derived class should call
destructorSafeDestroyNSSReference() and afterwards call
shutdown(calledFromObject), in order to deregister with the
tracking list, to ensure no additional attempt to free the resources
will be made.
Function destructorSafeDestroyNSSReference() must
also ensure, that NSS resources have not been freed already.
To achieve this, the deriving class should call
isAlreadyShutDown() to check.
It is important that you make your implementation
failsafe, and check whether the resources have already been freed,
in each function that requires the resources.
class derivedClass : public nsISomeInterface,
public nsNSSShutDownObject
{
virtual void virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
// clean up all NSS resources here
}
virtual ~derivedClass()
{
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
NS_IMETHODIMP doSomething()
{
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
// use the NSS resources and do something
}
};
*/
class nsNSSShutDownObject
{
public:
enum CalledFromType {calledFromList, calledFromObject};
nsNSSShutDownObject()
{
mAlreadyShutDown = PR_FALSE;
nsNSSShutDownList::remember(this);
}
virtual ~nsNSSShutDownObject()
{
// the derived class must call
// shutdown(calledFromObject);
// in its destructor
}
void shutdown(CalledFromType calledFrom)
{
if (!mAlreadyShutDown) {
if (calledFromObject == calledFrom) {
nsNSSShutDownList::forget(this);
}
if (calledFromList == calledFrom) {
virtualDestroyNSSReference();
}
mAlreadyShutDown = PR_TRUE;
}
}
PRBool isAlreadyShutDown() { return mAlreadyShutDown; }
protected:
virtual void virtualDestroyNSSReference() = 0;
private:
volatile PRBool mAlreadyShutDown;
};
class nsOnPK11LogoutCancelObject
{
public:
nsOnPK11LogoutCancelObject()
:mIsLoggedOut(PR_FALSE)
{
nsNSSShutDownList::remember(this);
}
virtual ~nsOnPK11LogoutCancelObject()
{
nsNSSShutDownList::forget(this);
}
void logout()
{
// We do not care for a race condition.
// Once the bool arrived at false,
// later calls to isPK11LoggedOut() will see it.
// This is a one-time change from 0 to 1.
mIsLoggedOut = PR_TRUE;
}
PRBool isPK11LoggedOut()
{
return mIsLoggedOut;
}
private:
volatile PRBool mIsLoggedOut;
};
#endif

Просмотреть файл

@ -25,6 +25,7 @@
#include "prerror.h" #include "prerror.h"
#include "secerr.h" #include "secerr.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsNSSComponent.h"
#include "nsPK11TokenDB.h" #include "nsPK11TokenDB.h"
@ -32,10 +33,16 @@
extern PRLogModuleInfo* gPIPNSSLog; extern PRLogModuleInfo* gPIPNSSLog;
#endif #endif
static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID);
NS_IMPL_ISUPPORTS1(nsPK11Token, nsIPK11Token) NS_IMPL_ISUPPORTS1(nsPK11Token, nsIPK11Token)
nsPK11Token::nsPK11Token(PK11SlotInfo *slot) nsPK11Token::nsPK11Token(PK11SlotInfo *slot)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
PK11_ReferenceSlot(slot); PK11_ReferenceSlot(slot);
mSlot = slot; mSlot = slot;
@ -85,8 +92,28 @@ nsPK11Token::nsPK11Token(PK11SlotInfo *slot)
nsPK11Token::~nsPK11Token() nsPK11Token::~nsPK11Token()
{ {
if (mSlot) PK11_FreeSlot(mSlot); nsNSSShutDownPreventionLock locker;
/* destructor code */ if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsPK11Token::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsPK11Token::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (mSlot) {
PK11_FreeSlot(mSlot);
mSlot = nsnull;
}
} }
/* readonly attribute wstring tokenName; */ /* readonly attribute wstring tokenName; */
@ -141,6 +168,10 @@ NS_IMETHODIMP nsPK11Token::GetTokenSerialNumber(PRUnichar **aTokSerialNum)
/* boolean isLoggedIn (); */ /* boolean isLoggedIn (); */
NS_IMETHODIMP nsPK11Token::IsLoggedIn(PRBool *_retval) NS_IMETHODIMP nsPK11Token::IsLoggedIn(PRBool *_retval)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv = NS_OK; nsresult rv = NS_OK;
*_retval = PK11_IsLoggedIn(mSlot, 0); *_retval = PK11_IsLoggedIn(mSlot, 0);
@ -152,13 +183,17 @@ NS_IMETHODIMP nsPK11Token::IsLoggedIn(PRBool *_retval)
NS_IMETHODIMP NS_IMETHODIMP
nsPK11Token::Login(PRBool force) nsPK11Token::Login(PRBool force)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv; nsresult rv;
SECStatus srv; SECStatus srv;
PRBool test; PRBool test;
rv = this->NeedsLogin(&test); rv = this->NeedsLogin(&test);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (test && force) { if (test && force) {
rv = this->Logout(); rv = this->LogoutSimple();
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
rv = setPassword(mSlot, mUIContext); rv = setPassword(mSlot, mUIContext);
@ -167,18 +202,39 @@ nsPK11Token::Login(PRBool force)
return (srv == SECSuccess) ? NS_OK : NS_ERROR_FAILURE; return (srv == SECSuccess) ? NS_OK : NS_ERROR_FAILURE;
} }
/* void logout (); */ NS_IMETHODIMP nsPK11Token::LogoutSimple()
NS_IMETHODIMP nsPK11Token::Logout()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
// PK11_MapError sets CKR_USER_NOT_LOGGED_IN to SEC_ERROR_LIBRARY_FAILURE, // PK11_MapError sets CKR_USER_NOT_LOGGED_IN to SEC_ERROR_LIBRARY_FAILURE,
// so not going to learn anything here by a failure. Treat it like void. // so not going to learn anything here by a failure. Treat it like void.
PK11_Logout(mSlot); PK11_Logout(mSlot);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsPK11Token::LogoutAndDropAuthenticatedResources()
{
nsresult rv = LogoutSimple();
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
if (NS_FAILED(rv))
return rv;
return nssComponent->LogoutAuthenticatedPK11();
}
/* void reset (); */ /* void reset (); */
NS_IMETHODIMP nsPK11Token::Reset() NS_IMETHODIMP nsPK11Token::Reset()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PK11_ResetToken(mSlot, 0); PK11_ResetToken(mSlot, 0);
return NS_OK; return NS_OK;
} }
@ -186,6 +242,10 @@ NS_IMETHODIMP nsPK11Token::Reset()
/* readonly attribute long minimumPasswordLength; */ /* readonly attribute long minimumPasswordLength; */
NS_IMETHODIMP nsPK11Token::GetMinimumPasswordLength(PRInt32 *aMinimumPasswordLength) NS_IMETHODIMP nsPK11Token::GetMinimumPasswordLength(PRInt32 *aMinimumPasswordLength)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
*aMinimumPasswordLength = PK11_GetMinimumPwdLength(mSlot); *aMinimumPasswordLength = PK11_GetMinimumPwdLength(mSlot);
return NS_OK; return NS_OK;
@ -194,14 +254,21 @@ NS_IMETHODIMP nsPK11Token::GetMinimumPasswordLength(PRInt32 *aMinimumPasswordLen
/* readonly attribute boolean needsUserInit; */ /* readonly attribute boolean needsUserInit; */
NS_IMETHODIMP nsPK11Token::GetNeedsUserInit(PRBool *aNeedsUserInit) NS_IMETHODIMP nsPK11Token::GetNeedsUserInit(PRBool *aNeedsUserInit)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
*aNeedsUserInit = PK11_NeedUserInit(mSlot); *aNeedsUserInit = PK11_NeedUserInit(mSlot);
return NS_OK; return NS_OK;
} }
/* boolean checkPassword (in wstring password); */ /* boolean checkPassword (in wstring password); */
NS_IMETHODIMP nsPK11Token::CheckPassword(const PRUnichar *password, PRBool *_retval) NS_IMETHODIMP nsPK11Token::CheckPassword(const PRUnichar *password, PRBool *_retval)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
SECStatus srv; SECStatus srv;
PRInt32 prerr; PRInt32 prerr;
NS_ConvertUCS2toUTF8 aUtf8Password(password); NS_ConvertUCS2toUTF8 aUtf8Password(password);
@ -223,6 +290,10 @@ NS_IMETHODIMP nsPK11Token::CheckPassword(const PRUnichar *password, PRBool *_ret
/* void initPassword (in wstring initialPassword); */ /* void initPassword (in wstring initialPassword); */
NS_IMETHODIMP nsPK11Token::InitPassword(const PRUnichar *initialPassword) NS_IMETHODIMP nsPK11Token::InitPassword(const PRUnichar *initialPassword)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv = NS_OK; nsresult rv = NS_OK;
SECStatus status; SECStatus status;
@ -238,6 +309,10 @@ done:
NS_IMETHODIMP NS_IMETHODIMP
nsPK11Token::GetAskPasswordTimes(PRInt32 *rvAskTimes) nsPK11Token::GetAskPasswordTimes(PRInt32 *rvAskTimes)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
int askTimes, askTimeout; int askTimes, askTimeout;
PK11_GetSlotPWValues(mSlot, &askTimes, &askTimeout); PK11_GetSlotPWValues(mSlot, &askTimes, &askTimeout);
*rvAskTimes = askTimes; *rvAskTimes = askTimes;
@ -248,6 +323,10 @@ nsPK11Token::GetAskPasswordTimes(PRInt32 *rvAskTimes)
NS_IMETHODIMP NS_IMETHODIMP
nsPK11Token::GetAskPasswordTimeout(PRInt32 *rvAskTimeout) nsPK11Token::GetAskPasswordTimeout(PRInt32 *rvAskTimeout)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
int askTimes, askTimeout; int askTimes, askTimeout;
PK11_GetSlotPWValues(mSlot, &askTimes, &askTimeout); PK11_GetSlotPWValues(mSlot, &askTimes, &askTimeout);
*rvAskTimeout = askTimeout; *rvAskTimeout = askTimeout;
@ -261,6 +340,10 @@ NS_IMETHODIMP
nsPK11Token::SetAskPasswordDefaults(const PRInt32 askTimes, nsPK11Token::SetAskPasswordDefaults(const PRInt32 askTimes,
const PRInt32 askTimeout) const PRInt32 askTimeout)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
PK11_SetSlotPWValues(mSlot, askTimes, askTimeout); PK11_SetSlotPWValues(mSlot, askTimes, askTimeout);
return NS_OK; return NS_OK;
} }
@ -268,6 +351,10 @@ nsPK11Token::SetAskPasswordDefaults(const PRInt32 askTimes,
/* void changePassword (in wstring oldPassword, in wstring newPassword); */ /* void changePassword (in wstring oldPassword, in wstring newPassword); */
NS_IMETHODIMP nsPK11Token::ChangePassword(const PRUnichar *oldPassword, const PRUnichar *newPassword) NS_IMETHODIMP nsPK11Token::ChangePassword(const PRUnichar *oldPassword, const PRUnichar *newPassword)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
SECStatus rv; SECStatus rv;
NS_ConvertUCS2toUTF8 aUtf8OldPassword(oldPassword); NS_ConvertUCS2toUTF8 aUtf8OldPassword(oldPassword);
NS_ConvertUCS2toUTF8 aUtf8NewPassword(newPassword); NS_ConvertUCS2toUTF8 aUtf8NewPassword(newPassword);
@ -280,6 +367,10 @@ NS_IMETHODIMP nsPK11Token::ChangePassword(const PRUnichar *oldPassword, const PR
/* boolean isHardwareToken (); */ /* boolean isHardwareToken (); */
NS_IMETHODIMP nsPK11Token::IsHardwareToken(PRBool *_retval) NS_IMETHODIMP nsPK11Token::IsHardwareToken(PRBool *_retval)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv = NS_OK; nsresult rv = NS_OK;
*_retval = PK11_IsHW(mSlot); *_retval = PK11_IsHW(mSlot);
@ -290,6 +381,10 @@ NS_IMETHODIMP nsPK11Token::IsHardwareToken(PRBool *_retval)
/* boolean needsLogin (); */ /* boolean needsLogin (); */
NS_IMETHODIMP nsPK11Token::NeedsLogin(PRBool *_retval) NS_IMETHODIMP nsPK11Token::NeedsLogin(PRBool *_retval)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv = NS_OK; nsresult rv = NS_OK;
*_retval = PK11_NeedLogin(mSlot); *_retval = PK11_NeedLogin(mSlot);
@ -300,6 +395,10 @@ NS_IMETHODIMP nsPK11Token::NeedsLogin(PRBool *_retval)
/* boolean isFriendly (); */ /* boolean isFriendly (); */
NS_IMETHODIMP nsPK11Token::IsFriendly(PRBool *_retval) NS_IMETHODIMP nsPK11Token::IsFriendly(PRBool *_retval)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv = NS_OK; nsresult rv = NS_OK;
*_retval = PK11_IsFriendly(mSlot); *_retval = PK11_IsFriendly(mSlot);
@ -324,6 +423,7 @@ nsPK11TokenDB::~nsPK11TokenDB()
/* nsIPK11Token getInternalKeyToken (); */ /* nsIPK11Token getInternalKeyToken (); */
NS_IMETHODIMP nsPK11TokenDB::GetInternalKeyToken(nsIPK11Token **_retval) NS_IMETHODIMP nsPK11TokenDB::GetInternalKeyToken(nsIPK11Token **_retval)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
PK11SlotInfo *slot = 0; PK11SlotInfo *slot = 0;
nsCOMPtr<nsIPK11Token> token; nsCOMPtr<nsIPK11Token> token;
@ -346,6 +446,7 @@ done:
NS_IMETHODIMP nsPK11TokenDB:: NS_IMETHODIMP nsPK11TokenDB::
FindTokenByName(const PRUnichar* tokenName, nsIPK11Token **_retval) FindTokenByName(const PRUnichar* tokenName, nsIPK11Token **_retval)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
PK11SlotInfo *slot = 0; PK11SlotInfo *slot = 0;
NS_ConvertUCS2toUTF8 aUtf8TokenName(tokenName); NS_ConvertUCS2toUTF8 aUtf8TokenName(tokenName);
@ -365,6 +466,7 @@ done:
/* nsIEnumerator listTokens (); */ /* nsIEnumerator listTokens (); */
NS_IMETHODIMP nsPK11TokenDB::ListTokens(nsIEnumerator* *_retval) NS_IMETHODIMP nsPK11TokenDB::ListTokens(nsIEnumerator* *_retval)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsISupportsArray> array; nsCOMPtr<nsISupportsArray> array;
PK11SlotList *list = 0; PK11SlotList *list = 0;

Просмотреть файл

@ -32,8 +32,10 @@
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "nsNSSHelper.h" #include "nsNSSHelper.h"
#include "pk11func.h" #include "pk11func.h"
#include "nsNSSShutDown.h"
class nsPK11Token : public nsIPK11Token class nsPK11Token : public nsIPK11Token,
public nsNSSShutDownObject
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -51,6 +53,8 @@ private:
nsString mTokenSerialNum; nsString mTokenSerialNum;
PK11SlotInfo *mSlot; PK11SlotInfo *mSlot;
nsCOMPtr<nsIInterfaceRequestor> mUIContext; nsCOMPtr<nsIInterfaceRequestor> mUIContext;
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
class nsPK11TokenDB : public nsIPK11TokenDB class nsPK11TokenDB : public nsIPK11TokenDB

Просмотреть файл

@ -52,6 +52,10 @@ NS_IMPL_ISUPPORTS1(nsPKCS11Slot, nsIPKCS11Slot)
nsPKCS11Slot::nsPKCS11Slot(PK11SlotInfo *slot) nsPKCS11Slot::nsPKCS11Slot(PK11SlotInfo *slot)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
PK11_ReferenceSlot(slot); PK11_ReferenceSlot(slot);
mSlot = slot; mSlot = slot;
@ -85,13 +89,38 @@ nsPKCS11Slot::nsPKCS11Slot(PK11SlotInfo *slot)
nsPKCS11Slot::~nsPKCS11Slot() nsPKCS11Slot::~nsPKCS11Slot()
{ {
if (mSlot) PK11_FreeSlot(mSlot); nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsPKCS11Slot::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsPKCS11Slot::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (mSlot) {
PK11_FreeSlot(mSlot);
mSlot = nsnull;
}
} }
/* readonly attribute wstring name; */ /* readonly attribute wstring name; */
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11Slot::GetName(PRUnichar **aName) nsPKCS11Slot::GetName(PRUnichar **aName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
char *csn = PK11_GetSlotName(mSlot); char *csn = PK11_GetSlotName(mSlot);
if (*csn) { if (*csn) {
*aName = ToNewUnicode(NS_ConvertUTF8toUCS2(csn)); *aName = ToNewUnicode(NS_ConvertUTF8toUCS2(csn));
@ -112,6 +141,10 @@ nsPKCS11Slot::GetName(PRUnichar **aName)
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11Slot::GetDesc(PRUnichar **aDesc) nsPKCS11Slot::GetDesc(PRUnichar **aDesc)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
*aDesc = ToNewUnicode(mSlotDesc); *aDesc = ToNewUnicode(mSlotDesc);
if (!*aDesc) return NS_ERROR_OUT_OF_MEMORY; if (!*aDesc) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK; return NS_OK;
@ -148,6 +181,10 @@ nsPKCS11Slot::GetFWVersion(PRUnichar **aFWVersion)
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11Slot::GetToken(nsIPK11Token **_retval) nsPKCS11Slot::GetToken(nsIPK11Token **_retval)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsCOMPtr<nsIPK11Token> token = new nsPK11Token(mSlot); nsCOMPtr<nsIPK11Token> token = new nsPK11Token(mSlot);
if (!token) if (!token)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@ -160,6 +197,10 @@ nsPKCS11Slot::GetToken(nsIPK11Token **_retval)
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11Slot::GetTokenName(PRUnichar **aName) nsPKCS11Slot::GetTokenName(PRUnichar **aName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
*aName = ToNewUnicode(NS_ConvertUTF8toUCS2(PK11_GetTokenName(mSlot))); *aName = ToNewUnicode(NS_ConvertUTF8toUCS2(PK11_GetTokenName(mSlot)));
if (!*aName) return NS_ERROR_OUT_OF_MEMORY; if (!*aName) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK; return NS_OK;
@ -168,6 +209,10 @@ nsPKCS11Slot::GetTokenName(PRUnichar **aName)
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11Slot::GetStatus(PRUint32 *_retval) nsPKCS11Slot::GetStatus(PRUint32 *_retval)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
if (PK11_IsDisabled(mSlot)) if (PK11_IsDisabled(mSlot))
*_retval = SLOT_DISABLED; *_retval = SLOT_DISABLED;
else if (!PK11_IsPresent(mSlot)) else if (!PK11_IsPresent(mSlot))
@ -187,19 +232,48 @@ NS_IMPL_ISUPPORTS1(nsPKCS11Module, nsIPKCS11Module)
nsPKCS11Module::nsPKCS11Module(SECMODModule *module) nsPKCS11Module::nsPKCS11Module(SECMODModule *module)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
SECMOD_ReferenceModule(module); SECMOD_ReferenceModule(module);
mModule = module; mModule = module;
} }
nsPKCS11Module::~nsPKCS11Module() nsPKCS11Module::~nsPKCS11Module()
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return;
destructorSafeDestroyNSSReference();
shutdown(calledFromObject);
}
void nsPKCS11Module::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void nsPKCS11Module::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (mModule) {
SECMOD_DestroyModule(mModule); SECMOD_DestroyModule(mModule);
mModule = nsnull;
}
} }
/* readonly attribute wstring name; */ /* readonly attribute wstring name; */
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11Module::GetName(PRUnichar **aName) nsPKCS11Module::GetName(PRUnichar **aName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
*aName = ToNewUnicode(NS_ConvertUTF8toUCS2(mModule->commonName)); *aName = ToNewUnicode(NS_ConvertUTF8toUCS2(mModule->commonName));
return NS_OK; return NS_OK;
} }
@ -208,6 +282,10 @@ nsPKCS11Module::GetName(PRUnichar **aName)
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11Module::GetLibName(PRUnichar **aName) nsPKCS11Module::GetLibName(PRUnichar **aName)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
if ( mModule->dllName ) { if ( mModule->dllName ) {
*aName = ToNewUnicode(NS_ConvertUTF8toUCS2(mModule->dllName)); *aName = ToNewUnicode(NS_ConvertUTF8toUCS2(mModule->dllName));
} else { } else {
@ -221,6 +299,10 @@ NS_IMETHODIMP
nsPKCS11Module::FindSlotByName(const PRUnichar *aName, nsPKCS11Module::FindSlotByName(const PRUnichar *aName,
nsIPKCS11Slot **_retval) nsIPKCS11Slot **_retval)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
char *asciiname = NULL; char *asciiname = NULL;
asciiname = ToNewUTF8String(nsDependentString(aName)); asciiname = ToNewUTF8String(nsDependentString(aName));
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("Getting \"%s\"\n", asciiname)); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("Getting \"%s\"\n", asciiname));
@ -259,6 +341,10 @@ nsPKCS11Module::FindSlotByName(const PRUnichar *aName,
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11Module::ListSlots(nsIEnumerator **_retval) nsPKCS11Module::ListSlots(nsIEnumerator **_retval)
{ {
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown())
return NS_ERROR_NOT_AVAILABLE;
nsresult rv = NS_OK; nsresult rv = NS_OK;
int i; int i;
/* get isupports array */ /* get isupports array */
@ -289,6 +375,7 @@ nsPKCS11ModuleDB::~nsPKCS11ModuleDB()
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11ModuleDB::GetInternal(nsIPKCS11Module **_retval) nsPKCS11ModuleDB::GetInternal(nsIPKCS11Module **_retval)
{ {
nsNSSShutDownPreventionLock locker;
SECMODModule *nssMod = SECMODModule *nssMod =
SECMOD_CreateModule(NULL,SECMOD_INT_NAME, NULL,SECMOD_INT_FLAGS); SECMOD_CreateModule(NULL,SECMOD_INT_NAME, NULL,SECMOD_INT_FLAGS);
nsCOMPtr<nsIPKCS11Module> module = new nsPKCS11Module(nssMod); nsCOMPtr<nsIPKCS11Module> module = new nsPKCS11Module(nssMod);
@ -304,6 +391,7 @@ nsPKCS11ModuleDB::GetInternal(nsIPKCS11Module **_retval)
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11ModuleDB::GetInternalFIPS(nsIPKCS11Module **_retval) nsPKCS11ModuleDB::GetInternalFIPS(nsIPKCS11Module **_retval)
{ {
nsNSSShutDownPreventionLock locker;
SECMODModule *nssMod = SECMODModule *nssMod =
SECMOD_CreateModule(NULL, SECMOD_FIPS_NAME, NULL, SECMOD_FIPS_FLAGS); SECMOD_CreateModule(NULL, SECMOD_FIPS_NAME, NULL, SECMOD_FIPS_FLAGS);
nsCOMPtr<nsIPKCS11Module> module = new nsPKCS11Module(nssMod); nsCOMPtr<nsIPKCS11Module> module = new nsPKCS11Module(nssMod);
@ -320,6 +408,7 @@ NS_IMETHODIMP
nsPKCS11ModuleDB::FindModuleByName(const PRUnichar *aName, nsPKCS11ModuleDB::FindModuleByName(const PRUnichar *aName,
nsIPKCS11Module **_retval) nsIPKCS11Module **_retval)
{ {
nsNSSShutDownPreventionLock locker;
NS_ConvertUCS2toUTF8 aUtf8Name(aName); NS_ConvertUCS2toUTF8 aUtf8Name(aName);
SECMODModule *mod = SECMODModule *mod =
SECMOD_FindModule(NS_CONST_CAST(char *, aUtf8Name.get())); SECMOD_FindModule(NS_CONST_CAST(char *, aUtf8Name.get()));
@ -342,6 +431,7 @@ NS_IMETHODIMP
nsPKCS11ModuleDB::FindSlotByName(const PRUnichar *aName, nsPKCS11ModuleDB::FindSlotByName(const PRUnichar *aName,
nsIPKCS11Slot **_retval) nsIPKCS11Slot **_retval)
{ {
nsNSSShutDownPreventionLock locker;
NS_ConvertUCS2toUTF8 aUtf8Name(aName); NS_ConvertUCS2toUTF8 aUtf8Name(aName);
PK11SlotInfo *slotinfo = PK11SlotInfo *slotinfo =
PK11_FindSlotByName(NS_CONST_CAST(char*, aUtf8Name.get())); PK11_FindSlotByName(NS_CONST_CAST(char*, aUtf8Name.get()));
@ -360,6 +450,7 @@ nsPKCS11ModuleDB::FindSlotByName(const PRUnichar *aName,
NS_IMETHODIMP NS_IMETHODIMP
nsPKCS11ModuleDB::ListModules(nsIEnumerator **_retval) nsPKCS11ModuleDB::ListModules(nsIEnumerator **_retval)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
/* get isupports array */ /* get isupports array */
nsCOMPtr<nsISupportsArray> array; nsCOMPtr<nsISupportsArray> array;
@ -382,6 +473,7 @@ nsPKCS11ModuleDB::ListModules(nsIEnumerator **_retval)
NS_IMETHODIMP nsPKCS11ModuleDB::GetCanToggleFIPS(PRBool *aCanToggleFIPS) NS_IMETHODIMP nsPKCS11ModuleDB::GetCanToggleFIPS(PRBool *aCanToggleFIPS)
{ {
nsNSSShutDownPreventionLock locker;
*aCanToggleFIPS = SECMOD_CanDeleteInternalModule(); *aCanToggleFIPS = SECMOD_CanDeleteInternalModule();
return NS_OK; return NS_OK;
} }
@ -390,6 +482,7 @@ NS_IMETHODIMP nsPKCS11ModuleDB::GetCanToggleFIPS(PRBool *aCanToggleFIPS)
/* void toggleFIPSMode (); */ /* void toggleFIPSMode (); */
NS_IMETHODIMP nsPKCS11ModuleDB::ToggleFIPSMode() NS_IMETHODIMP nsPKCS11ModuleDB::ToggleFIPSMode()
{ {
nsNSSShutDownPreventionLock locker;
// The way to toggle FIPS mode in NSS is extremely obscure. // The way to toggle FIPS mode in NSS is extremely obscure.
// Basically, we delete the internal module, and voila it // Basically, we delete the internal module, and voila it
// gets replaced with the opposite module, ie if it was // gets replaced with the opposite module, ie if it was
@ -413,6 +506,7 @@ NS_IMETHODIMP nsPKCS11ModuleDB::ToggleFIPSMode()
/* readonly attribute boolean isFIPSEnabled; */ /* readonly attribute boolean isFIPSEnabled; */
NS_IMETHODIMP nsPKCS11ModuleDB::GetIsFIPSEnabled(PRBool *aIsFIPSEnabled) NS_IMETHODIMP nsPKCS11ModuleDB::GetIsFIPSEnabled(PRBool *aIsFIPSEnabled)
{ {
nsNSSShutDownPreventionLock locker;
*aIsFIPSEnabled = PK11_IsFIPS(); *aIsFIPSEnabled = PK11_IsFIPS();
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -30,8 +30,10 @@
#include "nsIPKCS11ModuleDB.h" #include "nsIPKCS11ModuleDB.h"
#include "nsString.h" #include "nsString.h"
#include "pk11func.h" #include "pk11func.h"
#include "nsNSSShutDown.h"
class nsPKCS11Slot : public nsIPKCS11Slot class nsPKCS11Slot : public nsIPKCS11Slot,
public nsNSSShutDownObject
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -44,9 +46,13 @@ private:
PK11SlotInfo *mSlot; PK11SlotInfo *mSlot;
nsString mSlotDesc, mSlotManID, mSlotHWVersion, mSlotFWVersion; nsString mSlotDesc, mSlotManID, mSlotHWVersion, mSlotFWVersion;
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
class nsPKCS11Module : public nsIPKCS11Module class nsPKCS11Module : public nsIPKCS11Module,
public nsNSSShutDownObject
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -57,6 +63,9 @@ public:
private: private:
SECMODModule *mModule; SECMODModule *mModule;
virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference();
}; };
class nsPKCS11ModuleDB : public nsIPKCS11ModuleDB class nsPKCS11ModuleDB : public nsIPKCS11ModuleDB

Просмотреть файл

@ -31,7 +31,7 @@
* may use your version of this file under either the MPL or the * may use your version of this file under either the MPL or the
* GPL. * GPL.
* *
* $Id: nsPKCS12Blob.cpp,v 1.33 2003/01/06 22:23:48 kaie%netscape.com Exp $ * $Id: nsPKCS12Blob.cpp,v 1.34 2003/01/18 14:02:59 kaie%netscape.com Exp $
*/ */
#include "prmem.h" #include "prmem.h"
@ -58,7 +58,7 @@
#include "nsKeygenHandler.h" //For GetSlotWithMechanism #include "nsKeygenHandler.h" //For GetSlotWithMechanism
#include "nsPK11TokenDB.h" #include "nsPK11TokenDB.h"
#include "nsICertificateDialogs.h" #include "nsICertificateDialogs.h"
#include "nsPSMTracker.h" #include "nsNSSShutDown.h"
#include "pk11func.h" #include "pk11func.h"
#include "secerr.h" #include "secerr.h"
@ -102,6 +102,7 @@ nsPKCS12Blob::~nsPKCS12Blob()
void void
nsPKCS12Blob::SetToken(nsIPK11Token *token) nsPKCS12Blob::SetToken(nsIPK11Token *token)
{ {
nsNSSShutDownPreventionLock locker;
if (token) { if (token) {
mToken = token; mToken = token;
} else { } else {
@ -124,6 +125,7 @@ nsPKCS12Blob::SetToken(nsIPK11Token *token)
nsresult nsresult
nsPKCS12Blob::ImportFromFile(nsILocalFile *file) nsPKCS12Blob::ImportFromFile(nsILocalFile *file)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
if (!mToken && !mTokenSet) { if (!mToken && !mTokenSet) {
@ -151,6 +153,7 @@ nsPKCS12Blob::ImportFromFile(nsILocalFile *file)
nsresult nsresult
nsPKCS12Blob::ImportFromFileHelper(nsILocalFile *file, PRBool &aWantRetry) nsPKCS12Blob::ImportFromFileHelper(nsILocalFile *file, PRBool &aWantRetry)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
SECStatus srv = SECSuccess; SECStatus srv = SECSuccess;
SEC_PKCS12DecoderContext *dcx = NULL; SEC_PKCS12DecoderContext *dcx = NULL;
@ -287,6 +290,7 @@ nsresult
nsPKCS12Blob::ExportToFile(nsILocalFile *file, nsPKCS12Blob::ExportToFile(nsILocalFile *file,
nsIX509Cert **certs, int numCerts) nsIX509Cert **certs, int numCerts)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
SECStatus srv = SECSuccess; SECStatus srv = SECSuccess;
SEC_PKCS12ExportContext *ecx = NULL; SEC_PKCS12ExportContext *ecx = NULL;
@ -510,6 +514,7 @@ nsPKCS12Blob::getPKCS12FilePassword(SECItem *unicodePw)
nsresult nsresult
nsPKCS12Blob::inputToDecoder(SEC_PKCS12DecoderContext *dcx, nsILocalFile *file) nsPKCS12Blob::inputToDecoder(SEC_PKCS12DecoderContext *dcx, nsILocalFile *file)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
SECStatus srv; SECStatus srv;
PRUint32 amount; PRUint32 amount;
@ -645,6 +650,7 @@ nsPKCS12Blob::digest_write(void *arg, unsigned char *buf, unsigned long len)
SECItem * PR_CALLBACK SECItem * PR_CALLBACK
nsPKCS12Blob::nickname_collision(SECItem *oldNick, PRBool *cancel, void *wincx) nsPKCS12Blob::nickname_collision(SECItem *oldNick, PRBool *cancel, void *wincx)
{ {
nsNSSShutDownPreventionLock locker;
*cancel = PR_FALSE; *cancel = PR_FALSE;
nsresult rv; nsresult rv;
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv)); nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));

Просмотреть файл

@ -1,185 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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.
*
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Kai Engert <kaie@netscape.com>
*
* 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 ***** */
#include "nsPSMTracker.h"
#include "nsCOMPtr.h"
nsPSMTracker *nsPSMTracker::singleton = nsnull;
nsPSMTracker *nsPSMTracker::construct()
{
if (singleton) {
// we should never ever be called twice
return nsnull;
}
singleton = new nsPSMTracker();
return singleton;
}
nsPSMTracker::nsPSMTracker()
{
mLock = PR_NewLock();
mActiveSSLSockets = 0;
mActiveUIContexts = 0;
mIsUIForbidden = PR_FALSE;
}
nsPSMTracker::~nsPSMTracker()
{
if (mLock) {
PR_DestroyLock(mLock);
}
PR_ASSERT(this == singleton);
singleton = nsnull;
}
void nsPSMTracker::enterUIContext()
{
if (!singleton)
return;
PR_Lock(singleton->mLock);
++singleton->mActiveUIContexts;
PR_Unlock(singleton->mLock);
}
void nsPSMTracker::leaveUIContext()
{
if (!singleton)
return;
PR_Lock(singleton->mLock);
--singleton->mActiveUIContexts;
PR_Unlock(singleton->mLock);
}
PRBool nsPSMTracker::isUIActive()
{
if (!singleton) {
// be pessimistic
return PR_TRUE;
}
PRBool retval;
PR_Lock(singleton->mLock);
retval = (singleton->mActiveUIContexts > 0);
PR_Unlock(singleton->mLock);
return retval;
}
PRBool nsPSMTracker::ifPossibleDisallowUI()
{
if (!singleton) {
// be pessimistic
return PR_FALSE;
}
PRBool retval;
PR_Lock(singleton->mLock);
if (singleton->mActiveUIContexts > 0) {
retval = PR_FALSE;
}
else {
retval = PR_TRUE;
singleton->mIsUIForbidden = PR_TRUE;
}
PR_Unlock(singleton->mLock);
return retval;
}
void nsPSMTracker::allowUI()
{
if (!singleton)
return;
PR_Lock(singleton->mLock);
singleton->mIsUIForbidden = PR_FALSE;
PR_Unlock(singleton->mLock);
}
PRBool nsPSMTracker::isUIForbidden()
{
if (!singleton) {
// be pessimistic
return PR_FALSE;
}
PRBool retval;
PR_Lock(singleton->mLock);
retval = singleton->mIsUIForbidden;
PR_Unlock(singleton->mLock);
return retval;
}
void nsPSMTracker::increaseSSLSocketCounter()
{
if (!singleton)
return;
PR_Lock(singleton->mLock);
++singleton->mActiveSSLSockets;
PR_Unlock(singleton->mLock);
}
void nsPSMTracker::decreaseSSLSocketCounter()
{
if (!singleton)
return;
PR_Lock(singleton->mLock);
--singleton->mActiveSSLSockets;
PR_Unlock(singleton->mLock);
}
PRBool nsPSMTracker::areSSLSocketsActive()
{
if (!singleton) {
// be pessimistic
return PR_TRUE;
}
PRBool retval;
PR_Lock(singleton->mLock);
retval = (singleton->mActiveSSLSockets > 0);
PR_Unlock(singleton->mLock);
return retval;
}

Просмотреть файл

@ -1,93 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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.
*
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Kai Engert <kaie@netscape.com>
*
* 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 ***** */
#ifndef _INC_nsPSMTracker_H
#define _INC_nsPSMTracker_H
#include "nscore.h"
#include "nspr.h"
class nsPSMTracker
{
public:
static nsPSMTracker *construct();
~nsPSMTracker();
static void enterUIContext();
static void leaveUIContext();
static PRBool isUIActive();
static PRBool ifPossibleDisallowUI();
static void allowUI();
static PRBool isUIForbidden();
static void increaseSSLSocketCounter();
static void decreaseSSLSocketCounter();
static PRBool areSSLSocketsActive();
private:
nsPSMTracker();
static nsPSMTracker *singleton;
PRLock *mLock;
PRUint32 mActiveSSLSockets;
PRUint32 mActiveUIContexts;
PRBool mIsUIForbidden;
};
class nsPSMUITracker
{
public:
nsPSMUITracker()
{
nsPSMTracker::enterUIContext();
}
~nsPSMUITracker()
{
nsPSMTracker::leaveUIContext();
}
PRBool isUIForbidden()
{
return nsPSMTracker::isUIForbidden();
}
};
#endif

Просмотреть файл

@ -40,7 +40,7 @@
#include "nsISecretDecoderRing.h" #include "nsISecretDecoderRing.h"
#include "nsSDR.h" #include "nsSDR.h"
#include "nsNSSComponent.h" #include "nsNSSComponent.h"
#include "nsPSMTracker.h" #include "nsNSSShutDown.h"
#include "pk11func.h" #include "pk11func.h"
#include "pk11sdr.h" // For PK11SDR_Encrypt, PK11SDR_Decrypt #include "pk11sdr.h" // For PK11SDR_Encrypt, PK11SDR_Decrypt
@ -119,6 +119,7 @@ nsSecretDecoderRing::~nsSecretDecoderRing()
NS_IMETHODIMP nsSecretDecoderRing:: NS_IMETHODIMP nsSecretDecoderRing::
Encrypt(unsigned char * data, PRInt32 dataLen, unsigned char * *result, PRInt32 *_retval) Encrypt(unsigned char * data, PRInt32 dataLen, unsigned char * *result, PRInt32 *_retval)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
PK11SlotInfo *slot = 0; PK11SlotInfo *slot = 0;
PK11SlotInfoCleaner tmpSlotCleaner(slot); PK11SlotInfoCleaner tmpSlotCleaner(slot);
@ -160,6 +161,7 @@ loser:
NS_IMETHODIMP nsSecretDecoderRing:: NS_IMETHODIMP nsSecretDecoderRing::
Decrypt(unsigned char * data, PRInt32 dataLen, unsigned char * *result, PRInt32 *_retval) Decrypt(unsigned char * data, PRInt32 dataLen, unsigned char * *result, PRInt32 *_retval)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
PK11SlotInfo *slot = 0; PK11SlotInfo *slot = 0;
PK11SlotInfoCleaner tmpSlotCleaner(slot); PK11SlotInfoCleaner tmpSlotCleaner(slot);
@ -200,6 +202,7 @@ loser:
NS_IMETHODIMP nsSecretDecoderRing:: NS_IMETHODIMP nsSecretDecoderRing::
EncryptString(const char *text, char **_retval) EncryptString(const char *text, char **_retval)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
unsigned char *encrypted = 0; unsigned char *encrypted = 0;
PRInt32 eLen; PRInt32 eLen;
@ -224,6 +227,7 @@ loser:
NS_IMETHODIMP nsSecretDecoderRing:: NS_IMETHODIMP nsSecretDecoderRing::
DecryptString(const char *crypt, char **_retval) DecryptString(const char *crypt, char **_retval)
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK; nsresult rv = NS_OK;
char *r = 0; char *r = 0;
unsigned char *decoded = 0; unsigned char *decoded = 0;
@ -264,6 +268,7 @@ loser:
NS_IMETHODIMP nsSecretDecoderRing:: NS_IMETHODIMP nsSecretDecoderRing::
ChangePassword() ChangePassword()
{ {
nsNSSShutDownPreventionLock locker;
nsresult rv; nsresult rv;
PK11SlotInfo *slot; PK11SlotInfo *slot;
@ -302,12 +307,22 @@ ChangePassword()
return rv; return rv;
} }
static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID);
/* void logout(); */ /* void logout(); */
NS_IMETHODIMP nsSecretDecoderRing:: NS_IMETHODIMP nsSecretDecoderRing::
Logout() Logout()
{ {
nsresult rv;
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
if (NS_FAILED(rv))
return rv;
{
nsNSSShutDownPreventionLock locker;
PK11_LogoutAll(); PK11_LogoutAll();
return NS_OK; }
return nssComponent->LogoutAuthenticatedPK11();
} }
/* void setWindow(in nsISupports w); */ /* void setWindow(in nsISupports w); */

Просмотреть файл

@ -53,6 +53,7 @@ static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID);
nsUsageArrayHelper::nsUsageArrayHelper(CERTCertificate *aCert) nsUsageArrayHelper::nsUsageArrayHelper(CERTCertificate *aCert)
:mCert(aCert) :mCert(aCert)
{ {
nsNSSShutDownPreventionLock locker;
defaultcertdb = CERT_GetDefaultCertDB(); defaultcertdb = CERT_GetDefaultCertDB();
nssComponent = do_GetService(kNSSComponentCID, &m_rv); nssComponent = do_GetService(kNSSComponentCID, &m_rv);
mCached_NonInadequateReason = SECSuccess; mCached_NonInadequateReason = SECSuccess;
@ -64,6 +65,7 @@ nsUsageArrayHelper::check(char *suffix,
PRUint32 &aCounter, PRUint32 &aCounter,
PRUnichar **outUsages) PRUnichar **outUsages)
{ {
nsNSSShutDownPreventionLock locker;
if (CERT_VerifyCertNow(defaultcertdb, mCert, PR_TRUE, if (CERT_VerifyCertNow(defaultcertdb, mCert, PR_TRUE,
aCertUsage, NULL) == SECSuccess) { aCertUsage, NULL) == SECSuccess) {
nsAutoString typestr; nsAutoString typestr;
@ -177,6 +179,7 @@ nsUsageArrayHelper::GetUsagesArray(char *suffix,
PRUint32 *_count, PRUint32 *_count,
PRUnichar **outUsages) PRUnichar **outUsages)
{ {
nsNSSShutDownPreventionLock locker;
if (NS_FAILED(m_rv)) if (NS_FAILED(m_rv))
return m_rv; return m_rv;