Make p12 build on the Mac. Make p12 initialize the key db if it hasn't been initialized.

This commit is contained in:
javi%netscape.com 2001-03-21 00:57:46 +00:00
Родитель 88e4808e18
Коммит 7f68152e3f
5 изменённых файлов: 59 добавлений и 22 удалений

Двоичные данные
security/manager/ssl/macbuild/PIPNSS.mcp

Двоичный файл не отображается.

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

@ -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

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

@ -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

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

@ -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);
}
nsCOMPtr<nsIInterfaceRequestor>uiContext = 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<numCerts; i++) {
nsCOMPtr<nsNSSCertificate> 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,

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

@ -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; }