Back to index

lightning-sunbird  0.9+nobinonly
nsNSSDialogs.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Terry Hayes <thayes@netscape.com>
00025  *   Javier Delgadillo <javi@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 /*
00042  * Dialog services for PIP.
00043  */
00044 #include "nsCOMPtr.h"
00045 #include "nsString.h"
00046 #include "nsXPIDLString.h"
00047 #include "nsReadableUtils.h"
00048 #include "nsIPrompt.h"
00049 #include "nsIDOMWindowInternal.h"
00050 #include "nsIDialogParamBlock.h"
00051 #include "nsIComponentManager.h"
00052 #include "nsIServiceManager.h"
00053 #include "nsIStringBundle.h"
00054 #include "nsIInterfaceRequestor.h"
00055 #include "nsIInterfaceRequestorUtils.h"
00056 #include "nsIX509Cert.h"
00057 #include "nsIX509CertDB.h"
00058 #include "nsILocaleService.h"
00059 #include "nsIDateTimeFormat.h"
00060 #include "nsDateTimeFormatCID.h"
00061 
00062 #include "nsNSSDialogs.h"
00063 #include "nsPKIParamBlock.h"
00064 #include "nsIKeygenThread.h"
00065 #include "nsNSSDialogHelper.h"
00066 #include "nsIX509CertValidity.h"
00067 #include "nsICRLInfo.h"
00068 
00069 #define PIPSTRING_BUNDLE_URL "chrome://pippki/locale/pippki.properties"
00070 
00071 static NS_DEFINE_CID(kCStringBundleServiceCID,  NS_STRINGBUNDLESERVICE_CID);
00072 static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
00073 
00074 /* ==== */
00075 static NS_DEFINE_CID(kPKIParamBlockCID, NS_PKIPARAMBLOCK_CID);
00076 
00077 nsNSSDialogs::nsNSSDialogs()
00078 {
00079 }
00080 
00081 nsNSSDialogs::~nsNSSDialogs()
00082 {
00083 }
00084 
00085 NS_IMPL_THREADSAFE_ISUPPORTS8(nsNSSDialogs, nsITokenPasswordDialogs,
00086                                             nsIBadCertListener,
00087                                             nsICertificateDialogs,
00088                                             nsIClientAuthDialogs,
00089                                             nsICertPickDialogs,
00090                                             nsITokenDialogs,
00091                                             nsIDOMCryptoDialogs,
00092                                             nsIGeneratingKeypairInfoDialogs)
00093 
00094 nsresult
00095 nsNSSDialogs::Init()
00096 {
00097   nsresult rv;
00098 
00099   nsCOMPtr<nsIStringBundleService> service = do_GetService(kCStringBundleServiceCID, &rv);
00100   if (NS_FAILED(rv)) return rv;
00101   
00102   rv = service->CreateBundle(PIPSTRING_BUNDLE_URL,
00103                              getter_AddRefs(mPIPStringBundle));
00104   return rv;
00105 }
00106 
00107 nsresult
00108 nsNSSDialogs::SetPassword(nsIInterfaceRequestor *ctx,
00109                           const PRUnichar *tokenName, PRBool* _canceled)
00110 {
00111   nsresult rv;
00112 
00113   *_canceled = PR_FALSE;
00114 
00115   // Get the parent window for the dialog
00116   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(ctx);
00117 
00118   nsCOMPtr<nsIDialogParamBlock> block(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
00119   if (!block) return NS_ERROR_FAILURE;
00120 
00121   // void ChangePassword(in wstring tokenName, out int status);
00122   rv = block->SetString(1, tokenName);
00123   if (NS_FAILED(rv)) return rv;
00124 
00125   rv = nsNSSDialogHelper::openDialog(parent,
00126                                 "chrome://pippki/content/changepassword.xul",
00127                                 block);
00128 
00129   if (NS_FAILED(rv)) return rv;
00130 
00131   PRInt32 status;
00132 
00133   rv = block->GetInt(1, &status);
00134   if (NS_FAILED(rv)) return rv;
00135 
00136   *_canceled = (status == 0)?PR_TRUE:PR_FALSE;
00137 
00138   return rv;
00139 }
00140 
00141 nsresult
00142 nsNSSDialogs::GetPassword(nsIInterfaceRequestor *ctx,
00143                           const PRUnichar *tokenName, 
00144                           PRUnichar **_password,
00145                           PRBool* _canceled)
00146 {
00147   nsresult rv;
00148   *_canceled = PR_FALSE;
00149   // Get the parent window for the dialog
00150   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(ctx);
00151   nsCOMPtr<nsIDialogParamBlock> block(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
00152   if (!block) return NS_ERROR_FAILURE;
00153   // Set the token name in the window
00154   rv = block->SetString(1, tokenName);
00155   if (NS_FAILED(rv)) return rv;
00156   // open up the window
00157   rv = nsNSSDialogHelper::openDialog(parent,
00158                                      "chrome://pippki/content/getpassword.xul",
00159                                      block);
00160   if (NS_FAILED(rv)) return rv;
00161   // see if user canceled
00162   PRInt32 status;
00163   rv = block->GetInt(1, &status);
00164   if (NS_FAILED(rv)) return rv;
00165   *_canceled = (status == 0) ? PR_TRUE : PR_FALSE;
00166   if (!*_canceled) {
00167     // retrieve the password
00168     rv = block->GetString(2, _password);
00169   }
00170   return rv;
00171 }
00172 
00173 NS_IMETHODIMP
00174 nsNSSDialogs::ConfirmUnknownIssuer(nsIInterfaceRequestor *socketInfo,
00175                                    nsIX509Cert *cert, PRInt16 *outAddType,
00176                                    PRBool *_retval)
00177 {
00178   nsresult rv;
00179   PRInt32 addType;
00180   
00181   *_retval = PR_FALSE;
00182 
00183   nsCOMPtr<nsIPKIParamBlock> block = do_CreateInstance(kPKIParamBlockCID);
00184 
00185   if (!block)
00186     return NS_ERROR_FAILURE;
00187 
00188   nsXPIDLString commonName;
00189   rv = block->SetISupportAtIndex(1, cert);
00190   if (NS_FAILED(rv))
00191     return rv;
00192 
00193   rv = nsNSSDialogHelper::openDialog(nsnull, 
00194                                      "chrome://pippki/content/newserver.xul",
00195                                      block);
00196 
00197   if (NS_FAILED(rv))
00198     return rv;
00199 
00200   PRInt32 status;
00201   nsCOMPtr<nsIDialogParamBlock> dialogBlock = do_QueryInterface(block);
00202   rv = dialogBlock->GetInt(1, &status);
00203   if (NS_FAILED(rv))
00204     return rv; 
00205 
00206   if (status == 0) {
00207     *_retval = PR_FALSE;
00208   } else {
00209     // The user wants to continue, let's figure out
00210     // what to do with this cert. 
00211     rv = dialogBlock->GetInt(2, &addType);
00212     switch (addType) {
00213       case 0:
00214         *outAddType = ADD_TRUSTED_PERMANENTLY;
00215         *_retval    = PR_TRUE;
00216         break;
00217       case 1:
00218         *outAddType = ADD_TRUSTED_FOR_SESSION;
00219         *_retval    = PR_TRUE;
00220         break;
00221       default:
00222         *outAddType = UNINIT_ADD_FLAG;
00223         *_retval    = PR_FALSE;
00224         break;
00225     } 
00226   }
00227 
00228   return NS_OK; 
00229 }
00230 
00231 NS_IMETHODIMP 
00232 nsNSSDialogs::ConfirmMismatchDomain(nsIInterfaceRequestor *socketInfo, 
00233                                     const nsACString &targetURL, 
00234                                     nsIX509Cert *cert, PRBool *_retval) 
00235 {
00236   nsresult rv;
00237 
00238   *_retval = PR_FALSE;
00239 
00240   nsCOMPtr<nsIPKIParamBlock> block = do_CreateInstance(kPKIParamBlockCID);
00241 
00242   if (!block)
00243     return NS_ERROR_FAILURE;
00244 
00245   nsCOMPtr<nsIDialogParamBlock> dialogBlock = do_QueryInterface(block);
00246   rv = dialogBlock->SetString(1, NS_ConvertUTF8toUCS2(targetURL).get());
00247   if (NS_FAILED(rv))
00248     return rv;
00249 
00250   rv = block->SetISupportAtIndex(1, cert);
00251   if (NS_FAILED(rv))
00252     return rv;
00253 
00254   rv = nsNSSDialogHelper::openDialog(nsnull,
00255                                  "chrome://pippki/content/domainMismatch.xul",
00256                                  block);
00257   if (NS_FAILED(rv))
00258     return rv;
00259 
00260   PRInt32 status;
00261 
00262   rv = dialogBlock->GetInt(1, &status);
00263   if (NS_FAILED(rv))
00264     return rv;
00265 
00266   *_retval = (status) ? PR_TRUE : PR_FALSE;
00267 
00268   return NS_OK;  
00269 }
00270 
00271 NS_IMETHODIMP 
00272 nsNSSDialogs::ConfirmCertExpired(nsIInterfaceRequestor *socketInfo, 
00273                                  nsIX509Cert *cert, PRBool *_retval)
00274 {
00275   nsresult rv;
00276   PRTime now = PR_Now();
00277   PRTime notAfter, notBefore, timeToUse;
00278   nsCOMPtr<nsIX509CertValidity> validity;
00279   const char *key;
00280   const char *titleKey;
00281 
00282   *_retval = PR_FALSE;
00283 
00284   nsCOMPtr<nsIPKIParamBlock> block = do_CreateInstance(kPKIParamBlockCID);
00285 
00286   if (!block)
00287     return NS_ERROR_FAILURE; 
00288   rv = cert->GetValidity(getter_AddRefs(validity));
00289   if (NS_FAILED(rv))
00290     return rv;
00291 
00292   rv = validity->GetNotAfter(&notAfter);
00293   if (NS_FAILED(rv))
00294     return rv;
00295 
00296   rv = validity->GetNotBefore(&notBefore);
00297   if (NS_FAILED(rv))
00298     return rv;
00299 
00300   if (LL_CMP(now, >, notAfter)) {
00301     key       = "serverCertExpiredMsg1"; 
00302     titleKey  = "serverCertExpiredTitle";
00303     timeToUse = notAfter; 
00304   } else {
00305     key = "serverCertNotYetValedMsg1";
00306     titleKey  = "serverCertNotYetValidTitle";
00307     timeToUse = notBefore;
00308   }
00309 
00310   nsXPIDLString message1;
00311   nsXPIDLString title;
00312   nsAutoString commonName;
00313   nsAutoString formattedDate;
00314 
00315   rv = cert->GetCommonName(commonName);
00316 
00317   nsIDateTimeFormat *aDateTimeFormat;
00318   rv = CallCreateInstance(kDateTimeFormatCID, &aDateTimeFormat);
00319 
00320   aDateTimeFormat->FormatPRTime(nsnull, kDateFormatShort, 
00321                                 kTimeFormatNoSeconds, timeToUse, 
00322                                 formattedDate);
00323   const PRUnichar *formatStrings[2] = { commonName.get(), formattedDate.get() }; 
00324   NS_ConvertASCIItoUCS2 keyString(key);
00325   NS_ConvertASCIItoUCS2 titleKeyString(titleKey);
00326   mPIPStringBundle->FormatStringFromName(keyString.get(), formatStrings, 
00327                                          2, getter_Copies(message1));
00328   mPIPStringBundle->FormatStringFromName(titleKeyString.get(), formatStrings,
00329                                          2, getter_Copies(title));
00330   
00331   nsCOMPtr<nsIDialogParamBlock> dialogBlock = do_QueryInterface(block);
00332   rv = dialogBlock->SetString(1,message1); 
00333   rv = dialogBlock->SetString(2,title);
00334 
00335   if (NS_FAILED(rv))
00336     return rv;
00337 
00338   rv = block->SetISupportAtIndex(1, cert);
00339   if (NS_FAILED(rv))
00340     return rv;
00341 
00342   rv = nsNSSDialogHelper::openDialog(nsnull,
00343                              "chrome://pippki/content/serverCertExpired.xul",
00344                              block);
00345 
00346   PRInt32 status;
00347   rv = dialogBlock->GetInt(1, &status);
00348   if (NS_FAILED(rv))
00349     return rv; 
00350 
00351   *_retval = (status) ? PR_TRUE : PR_FALSE;
00352   
00353   return NS_OK;
00354 }
00355 
00356 NS_IMETHODIMP 
00357 nsNSSDialogs::NotifyCrlNextupdate(nsIInterfaceRequestor *socketInfo, 
00358                                   const nsACString &targetURL, nsIX509Cert *cert)
00359 {
00360   nsresult rv;
00361 
00362   nsCOMPtr<nsIPKIParamBlock> block = do_CreateInstance(kPKIParamBlockCID);
00363   nsCOMPtr<nsIDialogParamBlock> dialogBlock = do_QueryInterface(block);
00364 
00365   rv = dialogBlock->SetString(1, NS_ConvertUTF8toUCS2(targetURL).get());
00366   if (NS_FAILED(rv))
00367     return rv;
00368 
00369   rv = block->SetISupportAtIndex(1, cert);
00370   if (NS_FAILED(rv))
00371     return rv;
00372 
00373   rv = nsNSSDialogHelper::openDialog(nsnull,
00374                              "chrome://pippki/content/serverCrlNextupdate.xul",
00375                              block);
00376   return NS_OK;
00377 }
00378 
00379 NS_IMETHODIMP 
00380 nsNSSDialogs::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl)
00381 {
00382   nsresult rv;
00383 
00384   nsCOMPtr<nsIPKIParamBlock> block = do_CreateInstance(kPKIParamBlockCID,&rv);
00385   if (NS_FAILED(rv))
00386     return rv;
00387   
00388   rv = block->SetISupportAtIndex(1, crl);
00389   if (NS_FAILED(rv))
00390     return rv;
00391 
00392   rv = nsNSSDialogHelper::openDialog(nsnull,
00393                              "chrome://pippki/content/crlImportDialog.xul",
00394                              block);
00395   return NS_OK;
00396 }
00397 
00398 NS_IMETHODIMP 
00399 nsNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx, 
00400                                     nsIX509Cert *cert,
00401                                     PRUint32 *_trust,
00402                                     PRBool *_retval)
00403 {
00404   nsresult rv;
00405 
00406   *_retval = PR_TRUE;
00407 
00408   // Get the parent window for the dialog
00409   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(ctx);
00410 
00411   nsCOMPtr<nsIPKIParamBlock> block = do_CreateInstance(kPKIParamBlockCID);
00412   if (!block)
00413     return NS_ERROR_FAILURE;
00414 
00415   rv = block->SetISupportAtIndex(1, cert);
00416   if (NS_FAILED(rv))
00417     return rv;
00418 
00419   rv = nsNSSDialogHelper::openDialog(parent, 
00420                                    "chrome://pippki/content/downloadcert.xul",
00421                                      block);
00422   if (NS_FAILED(rv)) return rv;
00423 
00424   PRInt32 status;
00425   PRInt32 ssl, email, objsign;
00426 
00427   nsCOMPtr<nsIDialogParamBlock> dlgParamBlock = do_QueryInterface(block);
00428   
00429   rv = dlgParamBlock->GetInt(1, &status);
00430   if (NS_FAILED(rv)) return rv;
00431   rv = dlgParamBlock->GetInt(2, &ssl);
00432   if (NS_FAILED(rv)) return rv;
00433   rv = dlgParamBlock->GetInt(3, &email);
00434   if (NS_FAILED(rv)) return rv;
00435   rv = dlgParamBlock->GetInt(4, &objsign);
00436   if (NS_FAILED(rv)) return rv;
00437  
00438   *_trust = nsIX509CertDB::UNTRUSTED;
00439   *_trust |= (ssl) ? nsIX509CertDB::TRUSTED_SSL : 0;
00440   *_trust |= (email) ? nsIX509CertDB::TRUSTED_EMAIL : 0;
00441   *_trust |= (objsign) ? nsIX509CertDB::TRUSTED_OBJSIGN : 0;
00442 
00443   *_retval = (status == 0)?PR_FALSE:PR_TRUE;
00444 
00445   return rv;
00446 }
00447 
00448 
00449 NS_IMETHODIMP 
00450 nsNSSDialogs::NotifyCACertExists(nsIInterfaceRequestor *ctx)
00451 {
00452   nsresult rv;
00453 
00454   // Get the parent window for the dialog
00455   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(ctx);
00456 
00457   nsCOMPtr<nsIDialogParamBlock> block(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
00458   if (!block) return NS_ERROR_FAILURE;
00459 
00460   
00461   rv = nsNSSDialogHelper::openDialog(parent, 
00462                                      "chrome://pippki/content/cacertexists.xul",
00463                                      block);
00464 
00465   return rv;
00466 }
00467 
00468 
00469 NS_IMETHODIMP
00470 nsNSSDialogs::ChooseCertificate(nsIInterfaceRequestor *ctx, const PRUnichar *cn, const PRUnichar *organization, const PRUnichar *issuer, const PRUnichar **certNickList, const PRUnichar **certDetailsList, PRUint32 count, PRInt32 *selectedIndex, PRBool *canceled) 
00471 {
00472   nsresult rv;
00473   PRUint32 i;
00474 
00475   *canceled = PR_FALSE;
00476 
00477   // Get the parent window for the dialog
00478   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(ctx);
00479 
00480   nsCOMPtr<nsIDialogParamBlock> block(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
00481   if (!block) return NS_ERROR_FAILURE;
00482 
00483   block->SetNumberStrings(4+count*2);
00484 
00485   rv = block->SetString(0, cn);
00486   if (NS_FAILED(rv)) return rv;
00487 
00488   rv = block->SetString(1, organization);
00489   if (NS_FAILED(rv)) return rv;
00490 
00491   rv = block->SetString(2, issuer);
00492   if (NS_FAILED(rv)) return rv;
00493 
00494   for (i = 0; i < count; i++) {
00495     rv = block->SetString(i+3, certNickList[i]);
00496     if (NS_FAILED(rv)) return rv;
00497   }
00498 
00499   for (i = 0; i < count; i++) {
00500     rv = block->SetString(i+count+3, certDetailsList[i]);
00501     if (NS_FAILED(rv)) return rv;
00502   }
00503 
00504   rv = block->SetInt(0, count);
00505   if (NS_FAILED(rv)) return rv;
00506 
00507   rv = nsNSSDialogHelper::openDialog(nsnull,
00508                                 "chrome://pippki/content/clientauthask.xul",
00509                                 block);
00510   if (NS_FAILED(rv)) return rv;
00511 
00512   PRInt32 status;
00513   rv = block->GetInt(0, &status);
00514   if (NS_FAILED(rv)) return rv;
00515 
00516   nsCOMPtr<nsIClientAuthUserDecision> extraResult = do_QueryInterface(ctx);
00517   if (extraResult) {
00518     PRInt32 rememberSelection;
00519     rv = block->GetInt(2, &rememberSelection);
00520     if (NS_SUCCEEDED(rv)) {
00521       extraResult->SetRememberClientAuthCertificate(rememberSelection!=0);
00522     }
00523   }
00524 
00525   *canceled = (status == 0)?PR_TRUE:PR_FALSE;
00526   if (!*canceled) {
00527     // retrieve the nickname
00528     rv = block->GetInt(1, selectedIndex);
00529   }
00530   return rv;
00531 }
00532 
00533 
00534 NS_IMETHODIMP
00535 nsNSSDialogs::PickCertificate(nsIInterfaceRequestor *ctx, 
00536                               const PRUnichar **certNickList, 
00537                               const PRUnichar **certDetailsList, 
00538                               PRUint32 count, 
00539                               PRInt32 *selectedIndex, 
00540                               PRBool *canceled) 
00541 {
00542   nsresult rv;
00543   PRUint32 i;
00544 
00545   *canceled = PR_FALSE;
00546 
00547   // Get the parent window for the dialog
00548   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(ctx);
00549 
00550   nsCOMPtr<nsIDialogParamBlock> block(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
00551   if (!block) return NS_ERROR_FAILURE;
00552 
00553   block->SetNumberStrings(1+count*2);
00554 
00555   for (i = 0; i < count; i++) {
00556     rv = block->SetString(i, certNickList[i]);
00557     if (NS_FAILED(rv)) return rv;
00558   }
00559 
00560   for (i = 0; i < count; i++) {
00561     rv = block->SetString(i+count, certDetailsList[i]);
00562     if (NS_FAILED(rv)) return rv;
00563   }
00564 
00565   rv = block->SetInt(0, count);
00566   if (NS_FAILED(rv)) return rv;
00567 
00568   rv = block->SetInt(1, *selectedIndex);
00569   if (NS_FAILED(rv)) return rv;
00570 
00571   rv = nsNSSDialogHelper::openDialog(nsnull,
00572                                 "chrome://pippki/content/certpicker.xul",
00573                                 block);
00574   if (NS_FAILED(rv)) return rv;
00575 
00576   PRInt32 status;
00577 
00578   rv = block->GetInt(0, &status);
00579   if (NS_FAILED(rv)) return rv;
00580 
00581   *canceled = (status == 0)?PR_TRUE:PR_FALSE;
00582   if (!*canceled) {
00583     rv = block->GetInt(1, selectedIndex);
00584   }
00585   return rv;
00586 }
00587 
00588 
00589 NS_IMETHODIMP 
00590 nsNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor *ctx, 
00591                                     nsAString &_password,
00592                                     PRBool *_retval)
00593 {
00594   nsresult rv;
00595   *_retval = PR_TRUE;
00596   // Get the parent window for the dialog
00597   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(ctx);
00598   nsCOMPtr<nsIDialogParamBlock> block(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
00599   if (!block) return NS_ERROR_FAILURE;
00600   // open up the window
00601   rv = nsNSSDialogHelper::openDialog(parent,
00602                                   "chrome://pippki/content/setp12password.xul",
00603                                   block);
00604   if (NS_FAILED(rv)) return rv;
00605   // see if user canceled
00606   PRInt32 status;
00607   rv = block->GetInt(1, &status);
00608   if (NS_FAILED(rv)) return rv;
00609   *_retval = (status == 0) ? PR_FALSE : PR_TRUE;
00610   if (*_retval) {
00611     // retrieve the password
00612     PRUnichar *pw;
00613     rv = block->GetString(2, &pw);
00614     if (NS_SUCCEEDED(rv)) {
00615       _password = pw;
00616       nsMemory::Free(pw);
00617     }
00618   }
00619   return rv;
00620 }
00621 
00622 NS_IMETHODIMP 
00623 nsNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx, 
00624                                     nsAString &_password,
00625                                     PRBool *_retval)
00626 {
00627   nsresult rv;
00628   *_retval = PR_TRUE;
00629   // Get the parent window for the dialog
00630   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(ctx);
00631   nsCOMPtr<nsIDialogParamBlock> block(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
00632   if (!block) return NS_ERROR_FAILURE;
00633   // open up the window
00634   rv = nsNSSDialogHelper::openDialog(parent,
00635                                   "chrome://pippki/content/getp12password.xul",
00636                                   block);
00637   if (NS_FAILED(rv)) return rv;
00638   // see if user canceled
00639   PRInt32 status;
00640   rv = block->GetInt(1, &status);
00641   if (NS_FAILED(rv)) return rv;
00642   *_retval = (status == 0) ? PR_FALSE : PR_TRUE;
00643   if (*_retval) {
00644     // retrieve the password
00645     PRUnichar *pw;
00646     rv = block->GetString(2, &pw);
00647     if (NS_SUCCEEDED(rv)) {
00648       _password = pw;
00649       nsMemory::Free(pw);
00650     }
00651   }
00652   return rv;
00653 }
00654 
00655 /* void viewCert (in nsIX509Cert cert); */
00656 NS_IMETHODIMP 
00657 nsNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx, 
00658                        nsIX509Cert *cert)
00659 {
00660   nsresult rv;
00661 
00662   nsCOMPtr<nsIPKIParamBlock> block = do_CreateInstance(kPKIParamBlockCID);
00663   if (!block)
00664     return NS_ERROR_FAILURE;
00665 
00666   rv = block->SetISupportAtIndex(1, cert);
00667   if (NS_FAILED(rv))
00668     return rv;
00669 
00670   // Get the parent window for the dialog
00671   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(ctx);
00672 
00673   rv = nsNSSDialogHelper::openDialog(parent,
00674                                      "chrome://pippki/content/certViewer.xul",
00675                                      block);
00676   return rv;
00677 }
00678 
00679 NS_IMETHODIMP
00680 nsNSSDialogs::DisplayGeneratingKeypairInfo(nsIInterfaceRequestor *aCtx, nsIKeygenThread *runnable) 
00681 {
00682   nsresult rv;
00683 
00684   // Get the parent window for the dialog
00685   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(aCtx);
00686 
00687   rv = nsNSSDialogHelper::openDialog(parent,
00688                                      "chrome://pippki/content/createCertInfo.xul",
00689                                      runnable);
00690   return rv;
00691 }
00692 
00693 NS_IMETHODIMP
00694 nsNSSDialogs::ChooseToken(nsIInterfaceRequestor *aCtx, const PRUnichar **aTokenList, PRUint32 aCount, PRUnichar **aTokenChosen, PRBool *aCanceled) {
00695   nsresult rv;
00696   PRUint32 i;
00697 
00698   *aCanceled = PR_FALSE;
00699 
00700   // Get the parent window for the dialog
00701   nsCOMPtr<nsIDOMWindowInternal> parent = do_GetInterface(aCtx);
00702 
00703   nsCOMPtr<nsIDialogParamBlock> block(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
00704   if (!block) return NS_ERROR_FAILURE;
00705 
00706   block->SetNumberStrings(aCount);
00707 
00708   for (i = 0; i < aCount; i++) {
00709     rv = block->SetString(i, aTokenList[i]);
00710     if (NS_FAILED(rv)) return rv;
00711   }
00712 
00713   rv = block->SetInt(0, aCount);
00714   if (NS_FAILED(rv)) return rv;
00715 
00716   rv = nsNSSDialogHelper::openDialog(nsnull,
00717                                 "chrome://pippki/content/choosetoken.xul",
00718                                 block);
00719   if (NS_FAILED(rv)) return rv;
00720 
00721   PRInt32 status;
00722 
00723   rv = block->GetInt(0, &status);
00724   if (NS_FAILED(rv)) return rv;
00725 
00726   *aCanceled = (status == 0)?PR_TRUE:PR_FALSE;
00727   if (!*aCanceled) {
00728     // retrieve the nickname
00729     rv = block->GetString(0, aTokenChosen);
00730   }
00731   return rv;
00732 }
00733 
00734 /* boolean ConfirmKeyEscrow (in nsIX509Cert escrowAuthority); */
00735 NS_IMETHODIMP 
00736 nsNSSDialogs::ConfirmKeyEscrow(nsIX509Cert *escrowAuthority, PRBool *_retval)
00737                                      
00738 {
00739   *_retval = PR_FALSE;
00740 
00741   nsresult rv;
00742 
00743   nsCOMPtr<nsIPKIParamBlock> block = do_CreateInstance(kPKIParamBlockCID);
00744   if (!block)
00745     return NS_ERROR_FAILURE;
00746 
00747   rv = block->SetISupportAtIndex(1, escrowAuthority);
00748   if (NS_FAILED(rv))
00749     return rv;
00750 
00751   rv = nsNSSDialogHelper::openDialog(nsnull,
00752                                      "chrome://pippki/content/escrowWarn.xul",
00753                                      block);
00754 
00755   if (NS_FAILED(rv))
00756     return rv;
00757 
00758   PRInt32 status=0;
00759   nsCOMPtr<nsIDialogParamBlock> dlgParamBlock = do_QueryInterface(block);
00760   rv = dlgParamBlock->GetInt(1, &status);
00761  
00762   if (status) {
00763     *_retval = PR_TRUE;
00764   } 
00765   return rv;
00766 }
00767 
00768