diff --git a/security/manager/ssl/macbuild/PIPNSS.mcp b/security/manager/ssl/macbuild/PIPNSS.mcp index 72be028adb9..af34d21f8fc 100644 Binary files a/security/manager/ssl/macbuild/PIPNSS.mcp and b/security/manager/ssl/macbuild/PIPNSS.mcp differ diff --git a/security/manager/ssl/src/nsNSSComponent.cpp b/security/manager/ssl/src/nsNSSComponent.cpp index b805b5154db..184c7397e74 100644 --- a/security/manager/ssl/src/nsNSSComponent.cpp +++ b/security/manager/ssl/src/nsNSSComponent.cpp @@ -66,7 +66,6 @@ static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); PRBool nsNSSComponent::mNSSInitialized = PR_FALSE; #ifdef XP_MAC -extern OSErr ConvertMacPathToUnixPath(const char *macPath, char **unixPath); OSErr ConvertMacPathToUnixPath(const char *macPath, char **unixPath) { @@ -630,6 +629,33 @@ getNSSDialogs(void **_result, REFNSIID aIID) return rv; } +nsresult +setPassword(PK11SlotInfo *slot, nsIInterfaceRequestor *ctx) +{ + nsresult rv = NS_OK; + + if (PK11_NeedUserInit(slot)) { + nsITokenPasswordDialogs *dialogs; + PRBool canceled; + NS_ConvertUTF8toUCS2 tokenName(PK11_GetTokenName(slot)); + + rv = getNSSDialogs((void**)&dialogs, + NS_GET_IID(nsITokenPasswordDialogs)); + + if (NS_FAILED(rv)) goto loser; + + rv = dialogs->SetPassword(ctx, + tokenName.get(), + &canceled); + NS_RELEASE(dialogs); + if (NS_FAILED(rv)) goto loser; + + if (canceled) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; } + } + loser: + return rv; +} + // // Implementation of an nsIInterfaceRequestor for use // as context for NSS calls diff --git a/security/manager/ssl/src/nsNSSHelper.h b/security/manager/ssl/src/nsNSSHelper.h index 70d552d3c89..c4d63b0c6c4 100644 --- a/security/manager/ssl/src/nsNSSHelper.h +++ b/security/manager/ssl/src/nsNSSHelper.h @@ -37,6 +37,7 @@ #define NSS_HELPER_ #include "nsIInterfaceRequestor.h" +#include "pk11func.h" // // Implementation of an nsIInterfaceRequestor for use @@ -73,5 +74,15 @@ pip_ucs2_ascii_conversion_fn(PRBool toUnicode, PRBool swapBytes); } +// +// A function that sets the password on an unitialized slot. +// +nsresult +setPassword(PK11SlotInfo *slot, nsIInterfaceRequestor *ctx); + +#ifdef XP_MAC +extern OSErr ConvertMacPathToUnixPath(const char *macPath, char **unixPath); +#endif + #endif diff --git a/security/manager/ssl/src/nsPKCS12Blob.cpp b/security/manager/ssl/src/nsPKCS12Blob.cpp index bf57352a096..eb9e226018b 100644 --- a/security/manager/ssl/src/nsPKCS12Blob.cpp +++ b/security/manager/ssl/src/nsPKCS12Blob.cpp @@ -31,7 +31,7 @@ * may use your version of this file under either the MPL or the * GPL. * - * $Id: nsPKCS12Blob.cpp,v 1.2 2001-03-20 22:41:35 bryner%uiuc.edu Exp $ + * $Id: nsPKCS12Blob.cpp,v 1.3 2001-03-21 00:57:38 javi%netscape.com Exp $ */ #include "prmem.h" @@ -134,6 +134,14 @@ nsPKCS12Blob::ImportFromFile(nsILocalFile *file) // XXX fix this later by getting it from mToken int count = 0; slot = PK11_GetInternalKeySlot(); + if (PK11_NeedLogin(slot)) { + PK11_Logout(slot); + } + nsCOMPtruiContext = new PipUIContext(); + rv = setPassword(slot, uiContext); + if (NS_FAILED(rv)) + goto finish; + PK11_Authenticate(slot, PR_TRUE, &count); #if 0 // init slot @@ -294,8 +302,8 @@ nsPKCS12Blob::ExportToFile(nsILocalFile *file) goto finish; } for (i=0; i cert; - nrv = mCertArray->GetElementAt(i, getter_AddRefs(cert)); + nsNSSCertificate *cert; + nrv = mCertArray->GetElementAt(i, &NS_STATIC_CAST(nsISupports*,cert)); if (NS_FAILED(nrv)) { PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("FAILED getting el %d", i)); goto finish; @@ -328,6 +336,7 @@ nsPKCS12Blob::ExportToFile(nsILocalFile *file) goto finish; } PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("added %s", cert->GetCert()->nickname)); + NS_RELEASE(cert); } // XXX cheating this->__mTmp = NULL; @@ -510,6 +519,12 @@ nsPKCS12Blob::digest_open(void *arg, PRBool reading) nsXPIDLCString pathBuf; tmpFile->GetPath(getter_Copies(pathBuf)); cx->__mTmpFilePath = PL_strdup(pathBuf.get()); +#ifdef XP_MAC + char *unixPath = nsnull; + ConvertMacPathToUnixPath(cx->__mTmpFilePath, &unixPath); + nsMemory::Free(cx->__mTmpFilePath); + cx->__mTmpFilePath = unixPath; +#endif PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("opened temp %s", cx->__mTmpFilePath)); #if 0 rv = tmpFile->CreateUnique(PIP_PKCS12_TMPFILENAME, diff --git a/security/manager/ssl/src/nsSDR.cpp b/security/manager/ssl/src/nsSDR.cpp index 77d2c6ab107..ac8dda5de5a 100644 --- a/security/manager/ssl/src/nsSDR.cpp +++ b/security/manager/ssl/src/nsSDR.cpp @@ -126,24 +126,9 @@ Encrypt(unsigned char * data, PRInt32 dataLen, unsigned char * *result, PRInt32 if (!slot) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; } /* Make sure token is initialized. */ - if (PK11_NeedUserInit(slot)) { - nsITokenPasswordDialogs *dialogs; - PRBool canceled; - NS_ConvertUTF8toUCS2 tokenName(PK11_GetTokenName(slot)); - - rv = getNSSDialogs((void**)&dialogs, - NS_GET_IID(nsITokenPasswordDialogs)); - - if (NS_FAILED(rv)) goto loser; - - rv = dialogs->SetPassword(ctx, - tokenName.get(), - &canceled); - NS_RELEASE(dialogs); - if (NS_FAILED(rv)) goto loser; - - if (canceled) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; } - } + rv = setPassword(slot, ctx); + if (NS_FAILED(rv)) + goto loser; s = PK11_Authenticate(slot, PR_TRUE, ctx); if (s != SECSuccess) { rv = NS_ERROR_FAILURE; goto loser; }