From 882c35c8771ce815083d5d0aca276155f7eaca81 Mon Sep 17 00:00:00 2001 From: "kaie%netscape.com" Date: Tue, 4 Dec 2001 15:56:54 +0000 Subject: [PATCH] b=110420 fix cert prompt dialogs r=javi sr=shaver --- security/manager/pki/src/nsNSSDialogs.cpp | 9 ++++--- security/manager/ssl/src/nsCertPicker.cpp | 31 +++++++++++++++-------- security/manager/ssl/src/nsNSSIOLayer.cpp | 27 +++++++++++++------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/security/manager/pki/src/nsNSSDialogs.cpp b/security/manager/pki/src/nsNSSDialogs.cpp index d4295fe3390..ecf30880c4a 100644 --- a/security/manager/pki/src/nsNSSDialogs.cpp +++ b/security/manager/pki/src/nsNSSDialogs.cpp @@ -731,15 +731,14 @@ nsNSSDialogs::ChooseCertificate(nsIInterfaceRequestor *ctx, const PRUnichar *cn, nsCOMPtr block(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); if (!block) return NS_ERROR_FAILURE; - // void ChangePassword(in wstring tokenName, out int status); + block->SetNumberStrings(4+count*2); + rv = block->SetString(1, cn); if (NS_FAILED(rv)) return rv; - // void ChangePassword(in wstring tokenName, out int status); rv = block->SetString(2, organization); if (NS_FAILED(rv)) return rv; - // void ChangePassword(in wstring tokenName, out int status); rv = block->SetString(3, issuer); if (NS_FAILED(rv)) return rv; @@ -789,6 +788,8 @@ nsNSSDialogs::PickCertificate(nsIInterfaceRequestor *ctx, const PRUnichar *title nsCOMPtr block(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); if (!block) return NS_ERROR_FAILURE; + block->SetNumberStrings(3+count*2); + rv = block->SetString(1, title); if (NS_FAILED(rv)) return rv; @@ -939,6 +940,8 @@ nsNSSDialogs::ChooseToken(nsIInterfaceRequestor *aCtx, const PRUnichar **aTokenL nsCOMPtr block(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1")); if (!block) return NS_ERROR_FAILURE; + block->SetNumberStrings(aCount); + for (i = 0; i < aCount; i++) { rv = block->SetString(i+1, aTokenList[i]); if (NS_FAILED(rv)) return rv; diff --git a/security/manager/ssl/src/nsCertPicker.cpp b/security/manager/ssl/src/nsCertPicker.cpp index 3cf16647b2d..743a7370dc9 100644 --- a/security/manager/ssl/src/nsCertPicker.cpp +++ b/security/manager/ssl/src/nsCertPicker.cpp @@ -66,7 +66,6 @@ nsCertPicker::~nsCertPicker() /* nsIX509Cert pick (in nsIInterfaceRequestor ctx, in wstring title, in wstring infoPrompt, in PRInt32 certUsage, in boolean allowInvalid, in boolean allowDuplicateNicknames, out boolean canceled); */ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx, const PRUnichar *title, const PRUnichar *infoPrompt, PRInt32 certUsage, PRBool allowInvalid, PRBool allowDuplicateNicknames, PRBool *canceled, nsIX509Cert **_retval) { - PRInt32 i = 0; PRInt32 selectedIndex = -1; PRUnichar **certNicknameList = nsnull; PRUnichar **certDetailsList = nsnull; @@ -111,12 +110,15 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx, const PRUnic certNicknameList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames); certDetailsList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames); - for (i = 0, node = CERT_LIST_HEAD(certList); - !CERT_LIST_END(node, certList); - ++i, node = CERT_LIST_NEXT(node) + PRInt32 CertsToUse; + + for (CertsToUse = 0, node = CERT_LIST_HEAD(certList); + !CERT_LIST_END(node, certList) && CertsToUse < nicknames->numnicknames; + node = CERT_LIST_NEXT(node) ) { nsNSSCertificate *tempCert = new nsNSSCertificate(node->cert); + if (tempCert) { // XXX we really should be using an nsCOMPtr instead of manually add-refing, @@ -124,19 +126,26 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx, const PRUnic NS_ADDREF(tempCert); - nsAutoString i_nickname(NS_ConvertUTF8toUCS2(nicknames->nicknames[i])); + nsAutoString i_nickname(NS_ConvertUTF8toUCS2(nicknames->nicknames[CertsToUse])); nsAutoString nickWithSerial; nsAutoString details; if (NS_SUCCEEDED(tempCert->FormatUIStrings(i_nickname, nickWithSerial, details))) { - certNicknameList[i] = ToNewUnicode(nickWithSerial); - certDetailsList[i] = ToNewUnicode(details); + certNicknameList[CertsToUse] = ToNewUnicode(nickWithSerial); + certDetailsList[CertsToUse] = ToNewUnicode(details); + } + else { + certNicknameList[CertsToUse] = nsnull; + certDetailsList[CertsToUse] = nsnull; } NS_RELEASE(tempCert); + + ++CertsToUse; } } - + + PRInt32 i = 0; nsICertPickDialogs *dialogs = nsnull; rv = getNSSDialogs((void**)&dialogs, NS_GET_IID(nsICertPickDialogs)); @@ -144,9 +153,9 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx, const PRUnic /* Throw up the cert picker dialog and get back the index of the selected cert */ rv = dialogs->PickCertificate(ctx, title, infoPrompt, (const PRUnichar**)certNicknameList, (const PRUnichar**)certDetailsList, - nicknames->numnicknames, &selectedIndex, canceled); + CertsToUse, &selectedIndex, canceled); - for (i = 0; i < nicknames->numnicknames; ++i) { + for (i = 0; i < CertsToUse; ++i) { nsMemory::Free(certNicknameList[i]); nsMemory::Free(certDetailsList[i]); } @@ -188,5 +197,5 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx, const PRUnic if (certList) { CERT_DestroyCertList(certList); } - return NS_OK; + return rv; } diff --git a/security/manager/ssl/src/nsNSSIOLayer.cpp b/security/manager/ssl/src/nsNSSIOLayer.cpp index fc8ed8c3667..e3ed86de763 100644 --- a/security/manager/ssl/src/nsNSSIOLayer.cpp +++ b/security/manager/ssl/src/nsNSSIOLayer.cpp @@ -1637,7 +1637,6 @@ SECStatus nsNSS_SSLGetClientAuthData(void* arg, PRFileDesc* socket, } else { /* user selects a cert to present */ - int i; nsIClientAuthDialogs *dialogs = NULL; PRInt32 selectedIndex = -1; PRUnichar **certNicknameList = NULL; @@ -1716,12 +1715,15 @@ SECStatus nsNSS_SSLGetClientAuthData(void* arg, PRFileDesc* socket, certNicknameList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames); certDetailsList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames); - for (i = 0, node = CERT_LIST_HEAD(certList); - !CERT_LIST_END(node, certList); - ++i, node = CERT_LIST_NEXT(node) + PRInt32 CertsToUse; + + for (CertsToUse = 0, node = CERT_LIST_HEAD(certList); + !CERT_LIST_END(node, certList) && CertsToUse < nicknames->numnicknames; + node = CERT_LIST_NEXT(node) ) { nsNSSCertificate *tempCert = new nsNSSCertificate(node->cert); + if (tempCert) { // XXX we really should be using an nsCOMPtr instead of manually add-refing, @@ -1729,15 +1731,21 @@ SECStatus nsNSS_SSLGetClientAuthData(void* arg, PRFileDesc* socket, NS_ADDREF(tempCert); - nsAutoString i_nickname(NS_ConvertUTF8toUCS2(nicknames->nicknames[i])); + nsAutoString i_nickname(NS_ConvertUTF8toUCS2(nicknames->nicknames[CertsToUse])); nsAutoString nickWithSerial; nsAutoString details; if (NS_SUCCEEDED(tempCert->FormatUIStrings(i_nickname, nickWithSerial, details))) { - certNicknameList[i] = ToNewUnicode(nickWithSerial); - certDetailsList[i] = ToNewUnicode(details); + certNicknameList[CertsToUse] = ToNewUnicode(nickWithSerial); + certDetailsList[CertsToUse] = ToNewUnicode(details); + } + else { + certNicknameList[CertsToUse] = nsnull; + certDetailsList[CertsToUse] = nsnull; } NS_RELEASE(tempCert); + + ++CertsToUse; } } @@ -1748,9 +1756,10 @@ SECStatus nsNSS_SSLGetClientAuthData(void* arg, PRFileDesc* socket, rv = dialogs->ChooseCertificate(info, cn.get(), org.get(), issuer.get(), (const PRUnichar**)certNicknameList, (const PRUnichar**)certDetailsList, - nicknames->numnicknames, &selectedIndex, &canceled); + CertsToUse, &selectedIndex, &canceled); - for (i = 0; i < nicknames->numnicknames; ++i) { + int i; + for (i = 0; i < CertsToUse; ++i) { nsMemory::Free(certNicknameList[i]); nsMemory::Free(certDetailsList[i]); }