Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | * Dialog services for PIP. |
michael@0 | 9 | */ |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsString.h" |
michael@0 | 12 | #include "nsXPIDLString.h" |
michael@0 | 13 | #include "nsReadableUtils.h" |
michael@0 | 14 | #include "nsIDOMWindow.h" |
michael@0 | 15 | #include "nsIDialogParamBlock.h" |
michael@0 | 16 | #include "nsIComponentManager.h" |
michael@0 | 17 | #include "nsIServiceManager.h" |
michael@0 | 18 | #include "nsIStringBundle.h" |
michael@0 | 19 | #include "nsIInterfaceRequestor.h" |
michael@0 | 20 | #include "nsIInterfaceRequestorUtils.h" |
michael@0 | 21 | #include "nsIX509Cert.h" |
michael@0 | 22 | #include "nsIX509CertDB.h" |
michael@0 | 23 | #include "nsIDateTimeFormat.h" |
michael@0 | 24 | #include "nsDateTimeFormatCID.h" |
michael@0 | 25 | #include "nsPromiseFlatString.h" |
michael@0 | 26 | |
michael@0 | 27 | #include "nsNSSDialogs.h" |
michael@0 | 28 | #include "nsPKIParamBlock.h" |
michael@0 | 29 | #include "nsIKeygenThread.h" |
michael@0 | 30 | #include "nsIProtectedAuthThread.h" |
michael@0 | 31 | #include "nsNSSDialogHelper.h" |
michael@0 | 32 | #include "nsIWindowWatcher.h" |
michael@0 | 33 | #include "nsIX509CertValidity.h" |
michael@0 | 34 | |
michael@0 | 35 | #include "nsEmbedCID.h" |
michael@0 | 36 | #include "nsIPromptService.h" |
michael@0 | 37 | |
michael@0 | 38 | #define PIPSTRING_BUNDLE_URL "chrome://pippki/locale/pippki.properties" |
michael@0 | 39 | |
michael@0 | 40 | /* ==== */ |
michael@0 | 41 | |
michael@0 | 42 | nsNSSDialogs::nsNSSDialogs() |
michael@0 | 43 | { |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | nsNSSDialogs::~nsNSSDialogs() |
michael@0 | 47 | { |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | NS_IMPL_ISUPPORTS(nsNSSDialogs, nsITokenPasswordDialogs, |
michael@0 | 51 | nsICertificateDialogs, |
michael@0 | 52 | nsIClientAuthDialogs, |
michael@0 | 53 | nsICertPickDialogs, |
michael@0 | 54 | nsITokenDialogs, |
michael@0 | 55 | nsIDOMCryptoDialogs, |
michael@0 | 56 | nsIGeneratingKeypairInfoDialogs, |
michael@0 | 57 | nsISSLCertErrorDialog) |
michael@0 | 58 | |
michael@0 | 59 | nsresult |
michael@0 | 60 | nsNSSDialogs::Init() |
michael@0 | 61 | { |
michael@0 | 62 | nsresult rv; |
michael@0 | 63 | |
michael@0 | 64 | nsCOMPtr<nsIStringBundleService> service = |
michael@0 | 65 | do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); |
michael@0 | 66 | if (NS_FAILED(rv)) return rv; |
michael@0 | 67 | |
michael@0 | 68 | rv = service->CreateBundle(PIPSTRING_BUNDLE_URL, |
michael@0 | 69 | getter_AddRefs(mPIPStringBundle)); |
michael@0 | 70 | return rv; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | nsresult |
michael@0 | 74 | nsNSSDialogs::SetPassword(nsIInterfaceRequestor *ctx, |
michael@0 | 75 | const char16_t *tokenName, bool* _canceled) |
michael@0 | 76 | { |
michael@0 | 77 | nsresult rv; |
michael@0 | 78 | |
michael@0 | 79 | *_canceled = false; |
michael@0 | 80 | |
michael@0 | 81 | // Get the parent window for the dialog |
michael@0 | 82 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx); |
michael@0 | 83 | |
michael@0 | 84 | nsCOMPtr<nsIDialogParamBlock> block = |
michael@0 | 85 | do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID); |
michael@0 | 86 | if (!block) return NS_ERROR_FAILURE; |
michael@0 | 87 | |
michael@0 | 88 | // void ChangePassword(in wstring tokenName, out int status); |
michael@0 | 89 | rv = block->SetString(1, tokenName); |
michael@0 | 90 | if (NS_FAILED(rv)) return rv; |
michael@0 | 91 | |
michael@0 | 92 | rv = nsNSSDialogHelper::openDialog(parent, |
michael@0 | 93 | "chrome://pippki/content/changepassword.xul", |
michael@0 | 94 | block); |
michael@0 | 95 | |
michael@0 | 96 | if (NS_FAILED(rv)) return rv; |
michael@0 | 97 | |
michael@0 | 98 | int32_t status; |
michael@0 | 99 | |
michael@0 | 100 | rv = block->GetInt(1, &status); |
michael@0 | 101 | if (NS_FAILED(rv)) return rv; |
michael@0 | 102 | |
michael@0 | 103 | *_canceled = (status == 0)?true:false; |
michael@0 | 104 | |
michael@0 | 105 | return rv; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | nsresult |
michael@0 | 109 | nsNSSDialogs::GetPassword(nsIInterfaceRequestor *ctx, |
michael@0 | 110 | const char16_t *tokenName, |
michael@0 | 111 | char16_t **_password, |
michael@0 | 112 | bool* _canceled) |
michael@0 | 113 | { |
michael@0 | 114 | nsresult rv; |
michael@0 | 115 | *_canceled = false; |
michael@0 | 116 | // Get the parent window for the dialog |
michael@0 | 117 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx); |
michael@0 | 118 | nsCOMPtr<nsIDialogParamBlock> block = |
michael@0 | 119 | do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID); |
michael@0 | 120 | if (!block) return NS_ERROR_FAILURE; |
michael@0 | 121 | // Set the token name in the window |
michael@0 | 122 | rv = block->SetString(1, tokenName); |
michael@0 | 123 | if (NS_FAILED(rv)) return rv; |
michael@0 | 124 | // open up the window |
michael@0 | 125 | rv = nsNSSDialogHelper::openDialog(parent, |
michael@0 | 126 | "chrome://pippki/content/getpassword.xul", |
michael@0 | 127 | block); |
michael@0 | 128 | if (NS_FAILED(rv)) return rv; |
michael@0 | 129 | // see if user canceled |
michael@0 | 130 | int32_t status; |
michael@0 | 131 | rv = block->GetInt(1, &status); |
michael@0 | 132 | if (NS_FAILED(rv)) return rv; |
michael@0 | 133 | *_canceled = (status == 0) ? true : false; |
michael@0 | 134 | if (!*_canceled) { |
michael@0 | 135 | // retrieve the password |
michael@0 | 136 | rv = block->GetString(2, _password); |
michael@0 | 137 | } |
michael@0 | 138 | return rv; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | NS_IMETHODIMP |
michael@0 | 142 | nsNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx, |
michael@0 | 143 | nsIX509Cert *cert, |
michael@0 | 144 | uint32_t *_trust, |
michael@0 | 145 | bool *_retval) |
michael@0 | 146 | { |
michael@0 | 147 | nsresult rv; |
michael@0 | 148 | |
michael@0 | 149 | *_retval = true; |
michael@0 | 150 | |
michael@0 | 151 | // Get the parent window for the dialog |
michael@0 | 152 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx); |
michael@0 | 153 | |
michael@0 | 154 | nsCOMPtr<nsIPKIParamBlock> block = |
michael@0 | 155 | do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID); |
michael@0 | 156 | if (!block) |
michael@0 | 157 | return NS_ERROR_FAILURE; |
michael@0 | 158 | |
michael@0 | 159 | rv = block->SetISupportAtIndex(1, cert); |
michael@0 | 160 | if (NS_FAILED(rv)) |
michael@0 | 161 | return rv; |
michael@0 | 162 | |
michael@0 | 163 | rv = nsNSSDialogHelper::openDialog(parent, |
michael@0 | 164 | "chrome://pippki/content/downloadcert.xul", |
michael@0 | 165 | block); |
michael@0 | 166 | if (NS_FAILED(rv)) return rv; |
michael@0 | 167 | |
michael@0 | 168 | int32_t status; |
michael@0 | 169 | int32_t ssl, email, objsign; |
michael@0 | 170 | |
michael@0 | 171 | nsCOMPtr<nsIDialogParamBlock> dlgParamBlock = do_QueryInterface(block); |
michael@0 | 172 | |
michael@0 | 173 | rv = dlgParamBlock->GetInt(1, &status); |
michael@0 | 174 | if (NS_FAILED(rv)) return rv; |
michael@0 | 175 | rv = dlgParamBlock->GetInt(2, &ssl); |
michael@0 | 176 | if (NS_FAILED(rv)) return rv; |
michael@0 | 177 | rv = dlgParamBlock->GetInt(3, &email); |
michael@0 | 178 | if (NS_FAILED(rv)) return rv; |
michael@0 | 179 | rv = dlgParamBlock->GetInt(4, &objsign); |
michael@0 | 180 | if (NS_FAILED(rv)) return rv; |
michael@0 | 181 | |
michael@0 | 182 | *_trust = nsIX509CertDB::UNTRUSTED; |
michael@0 | 183 | *_trust |= (ssl) ? nsIX509CertDB::TRUSTED_SSL : 0; |
michael@0 | 184 | *_trust |= (email) ? nsIX509CertDB::TRUSTED_EMAIL : 0; |
michael@0 | 185 | *_trust |= (objsign) ? nsIX509CertDB::TRUSTED_OBJSIGN : 0; |
michael@0 | 186 | |
michael@0 | 187 | *_retval = (status == 0)?false:true; |
michael@0 | 188 | |
michael@0 | 189 | return rv; |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | |
michael@0 | 193 | NS_IMETHODIMP |
michael@0 | 194 | nsNSSDialogs::NotifyCACertExists(nsIInterfaceRequestor *ctx) |
michael@0 | 195 | { |
michael@0 | 196 | nsresult rv; |
michael@0 | 197 | |
michael@0 | 198 | nsCOMPtr<nsIPromptService> promptSvc(do_GetService(NS_PROMPTSERVICE_CONTRACTID)); |
michael@0 | 199 | if (!promptSvc) |
michael@0 | 200 | return NS_ERROR_FAILURE; |
michael@0 | 201 | |
michael@0 | 202 | // Get the parent window for the dialog |
michael@0 | 203 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx); |
michael@0 | 204 | |
michael@0 | 205 | nsAutoString title; |
michael@0 | 206 | rv = mPIPStringBundle->GetStringFromName(MOZ_UTF16("caCertExistsTitle"), |
michael@0 | 207 | getter_Copies(title)); |
michael@0 | 208 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 209 | |
michael@0 | 210 | nsAutoString msg; |
michael@0 | 211 | rv = mPIPStringBundle->GetStringFromName(MOZ_UTF16("caCertExistsMessage"), |
michael@0 | 212 | getter_Copies(msg)); |
michael@0 | 213 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 214 | |
michael@0 | 215 | rv = promptSvc->Alert(parent, title.get(), msg.get()); |
michael@0 | 216 | |
michael@0 | 217 | return rv; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | |
michael@0 | 221 | NS_IMETHODIMP |
michael@0 | 222 | nsNSSDialogs::ChooseCertificate(nsIInterfaceRequestor *ctx, const char16_t *cn, const char16_t *organization, const char16_t *issuer, const char16_t **certNickList, const char16_t **certDetailsList, uint32_t count, int32_t *selectedIndex, bool *canceled) |
michael@0 | 223 | { |
michael@0 | 224 | nsresult rv; |
michael@0 | 225 | uint32_t i; |
michael@0 | 226 | |
michael@0 | 227 | *canceled = false; |
michael@0 | 228 | |
michael@0 | 229 | // Get the parent window for the dialog |
michael@0 | 230 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx); |
michael@0 | 231 | |
michael@0 | 232 | nsCOMPtr<nsIDialogParamBlock> block = |
michael@0 | 233 | do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID); |
michael@0 | 234 | if (!block) return NS_ERROR_FAILURE; |
michael@0 | 235 | |
michael@0 | 236 | block->SetNumberStrings(4+count*2); |
michael@0 | 237 | |
michael@0 | 238 | rv = block->SetString(0, cn); |
michael@0 | 239 | if (NS_FAILED(rv)) return rv; |
michael@0 | 240 | |
michael@0 | 241 | rv = block->SetString(1, organization); |
michael@0 | 242 | if (NS_FAILED(rv)) return rv; |
michael@0 | 243 | |
michael@0 | 244 | rv = block->SetString(2, issuer); |
michael@0 | 245 | if (NS_FAILED(rv)) return rv; |
michael@0 | 246 | |
michael@0 | 247 | for (i = 0; i < count; i++) { |
michael@0 | 248 | rv = block->SetString(i+3, certNickList[i]); |
michael@0 | 249 | if (NS_FAILED(rv)) return rv; |
michael@0 | 250 | } |
michael@0 | 251 | |
michael@0 | 252 | for (i = 0; i < count; i++) { |
michael@0 | 253 | rv = block->SetString(i+count+3, certDetailsList[i]); |
michael@0 | 254 | if (NS_FAILED(rv)) return rv; |
michael@0 | 255 | } |
michael@0 | 256 | |
michael@0 | 257 | rv = block->SetInt(0, count); |
michael@0 | 258 | if (NS_FAILED(rv)) return rv; |
michael@0 | 259 | |
michael@0 | 260 | rv = nsNSSDialogHelper::openDialog(nullptr, |
michael@0 | 261 | "chrome://pippki/content/clientauthask.xul", |
michael@0 | 262 | block); |
michael@0 | 263 | if (NS_FAILED(rv)) return rv; |
michael@0 | 264 | |
michael@0 | 265 | int32_t status; |
michael@0 | 266 | rv = block->GetInt(0, &status); |
michael@0 | 267 | if (NS_FAILED(rv)) return rv; |
michael@0 | 268 | |
michael@0 | 269 | nsCOMPtr<nsIClientAuthUserDecision> extraResult = do_QueryInterface(ctx); |
michael@0 | 270 | if (extraResult) { |
michael@0 | 271 | int32_t rememberSelection; |
michael@0 | 272 | rv = block->GetInt(2, &rememberSelection); |
michael@0 | 273 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 274 | extraResult->SetRememberClientAuthCertificate(rememberSelection!=0); |
michael@0 | 275 | } |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | *canceled = (status == 0)?true:false; |
michael@0 | 279 | if (!*canceled) { |
michael@0 | 280 | // retrieve the nickname |
michael@0 | 281 | rv = block->GetInt(1, selectedIndex); |
michael@0 | 282 | } |
michael@0 | 283 | return rv; |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | |
michael@0 | 287 | NS_IMETHODIMP |
michael@0 | 288 | nsNSSDialogs::PickCertificate(nsIInterfaceRequestor *ctx, |
michael@0 | 289 | const char16_t **certNickList, |
michael@0 | 290 | const char16_t **certDetailsList, |
michael@0 | 291 | uint32_t count, |
michael@0 | 292 | int32_t *selectedIndex, |
michael@0 | 293 | bool *canceled) |
michael@0 | 294 | { |
michael@0 | 295 | nsresult rv; |
michael@0 | 296 | uint32_t i; |
michael@0 | 297 | |
michael@0 | 298 | *canceled = false; |
michael@0 | 299 | |
michael@0 | 300 | // Get the parent window for the dialog |
michael@0 | 301 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx); |
michael@0 | 302 | |
michael@0 | 303 | nsCOMPtr<nsIDialogParamBlock> block = |
michael@0 | 304 | do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID); |
michael@0 | 305 | if (!block) return NS_ERROR_FAILURE; |
michael@0 | 306 | |
michael@0 | 307 | block->SetNumberStrings(1+count*2); |
michael@0 | 308 | |
michael@0 | 309 | for (i = 0; i < count; i++) { |
michael@0 | 310 | rv = block->SetString(i, certNickList[i]); |
michael@0 | 311 | if (NS_FAILED(rv)) return rv; |
michael@0 | 312 | } |
michael@0 | 313 | |
michael@0 | 314 | for (i = 0; i < count; i++) { |
michael@0 | 315 | rv = block->SetString(i+count, certDetailsList[i]); |
michael@0 | 316 | if (NS_FAILED(rv)) return rv; |
michael@0 | 317 | } |
michael@0 | 318 | |
michael@0 | 319 | rv = block->SetInt(0, count); |
michael@0 | 320 | if (NS_FAILED(rv)) return rv; |
michael@0 | 321 | |
michael@0 | 322 | rv = block->SetInt(1, *selectedIndex); |
michael@0 | 323 | if (NS_FAILED(rv)) return rv; |
michael@0 | 324 | |
michael@0 | 325 | rv = nsNSSDialogHelper::openDialog(nullptr, |
michael@0 | 326 | "chrome://pippki/content/certpicker.xul", |
michael@0 | 327 | block); |
michael@0 | 328 | if (NS_FAILED(rv)) return rv; |
michael@0 | 329 | |
michael@0 | 330 | int32_t status; |
michael@0 | 331 | |
michael@0 | 332 | rv = block->GetInt(0, &status); |
michael@0 | 333 | if (NS_FAILED(rv)) return rv; |
michael@0 | 334 | |
michael@0 | 335 | *canceled = (status == 0)?true:false; |
michael@0 | 336 | if (!*canceled) { |
michael@0 | 337 | rv = block->GetInt(1, selectedIndex); |
michael@0 | 338 | } |
michael@0 | 339 | return rv; |
michael@0 | 340 | } |
michael@0 | 341 | |
michael@0 | 342 | |
michael@0 | 343 | NS_IMETHODIMP |
michael@0 | 344 | nsNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor *ctx, |
michael@0 | 345 | nsAString &_password, |
michael@0 | 346 | bool *_retval) |
michael@0 | 347 | { |
michael@0 | 348 | nsresult rv; |
michael@0 | 349 | *_retval = true; |
michael@0 | 350 | // Get the parent window for the dialog |
michael@0 | 351 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx); |
michael@0 | 352 | nsCOMPtr<nsIDialogParamBlock> block = |
michael@0 | 353 | do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID); |
michael@0 | 354 | if (!block) return NS_ERROR_FAILURE; |
michael@0 | 355 | // open up the window |
michael@0 | 356 | rv = nsNSSDialogHelper::openDialog(parent, |
michael@0 | 357 | "chrome://pippki/content/setp12password.xul", |
michael@0 | 358 | block); |
michael@0 | 359 | if (NS_FAILED(rv)) return rv; |
michael@0 | 360 | // see if user canceled |
michael@0 | 361 | int32_t status; |
michael@0 | 362 | rv = block->GetInt(1, &status); |
michael@0 | 363 | if (NS_FAILED(rv)) return rv; |
michael@0 | 364 | *_retval = (status == 0) ? false : true; |
michael@0 | 365 | if (*_retval) { |
michael@0 | 366 | // retrieve the password |
michael@0 | 367 | char16_t *pw; |
michael@0 | 368 | rv = block->GetString(2, &pw); |
michael@0 | 369 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 370 | _password = pw; |
michael@0 | 371 | nsMemory::Free(pw); |
michael@0 | 372 | } |
michael@0 | 373 | } |
michael@0 | 374 | return rv; |
michael@0 | 375 | } |
michael@0 | 376 | |
michael@0 | 377 | NS_IMETHODIMP |
michael@0 | 378 | nsNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx, |
michael@0 | 379 | nsAString &_password, |
michael@0 | 380 | bool *_retval) |
michael@0 | 381 | { |
michael@0 | 382 | nsresult rv; |
michael@0 | 383 | *_retval = true; |
michael@0 | 384 | // Get the parent window for the dialog |
michael@0 | 385 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx); |
michael@0 | 386 | nsCOMPtr<nsIDialogParamBlock> block = |
michael@0 | 387 | do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID); |
michael@0 | 388 | if (!block) return NS_ERROR_FAILURE; |
michael@0 | 389 | // open up the window |
michael@0 | 390 | rv = nsNSSDialogHelper::openDialog(parent, |
michael@0 | 391 | "chrome://pippki/content/getp12password.xul", |
michael@0 | 392 | block); |
michael@0 | 393 | if (NS_FAILED(rv)) return rv; |
michael@0 | 394 | // see if user canceled |
michael@0 | 395 | int32_t status; |
michael@0 | 396 | rv = block->GetInt(1, &status); |
michael@0 | 397 | if (NS_FAILED(rv)) return rv; |
michael@0 | 398 | *_retval = (status == 0) ? false : true; |
michael@0 | 399 | if (*_retval) { |
michael@0 | 400 | // retrieve the password |
michael@0 | 401 | char16_t *pw; |
michael@0 | 402 | rv = block->GetString(2, &pw); |
michael@0 | 403 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 404 | _password = pw; |
michael@0 | 405 | nsMemory::Free(pw); |
michael@0 | 406 | } |
michael@0 | 407 | } |
michael@0 | 408 | return rv; |
michael@0 | 409 | } |
michael@0 | 410 | |
michael@0 | 411 | /* void viewCert (in nsIX509Cert cert); */ |
michael@0 | 412 | NS_IMETHODIMP |
michael@0 | 413 | nsNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx, |
michael@0 | 414 | nsIX509Cert *cert) |
michael@0 | 415 | { |
michael@0 | 416 | nsresult rv; |
michael@0 | 417 | |
michael@0 | 418 | nsCOMPtr<nsIPKIParamBlock> block = |
michael@0 | 419 | do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID); |
michael@0 | 420 | if (!block) |
michael@0 | 421 | return NS_ERROR_FAILURE; |
michael@0 | 422 | |
michael@0 | 423 | rv = block->SetISupportAtIndex(1, cert); |
michael@0 | 424 | if (NS_FAILED(rv)) |
michael@0 | 425 | return rv; |
michael@0 | 426 | |
michael@0 | 427 | // Get the parent window for the dialog |
michael@0 | 428 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(ctx); |
michael@0 | 429 | |
michael@0 | 430 | rv = nsNSSDialogHelper::openDialog(parent, |
michael@0 | 431 | "chrome://pippki/content/certViewer.xul", |
michael@0 | 432 | block, |
michael@0 | 433 | false); |
michael@0 | 434 | return rv; |
michael@0 | 435 | } |
michael@0 | 436 | |
michael@0 | 437 | NS_IMETHODIMP |
michael@0 | 438 | nsNSSDialogs::DisplayGeneratingKeypairInfo(nsIInterfaceRequestor *aCtx, nsIKeygenThread *runnable) |
michael@0 | 439 | { |
michael@0 | 440 | nsresult rv; |
michael@0 | 441 | |
michael@0 | 442 | // Get the parent window for the dialog |
michael@0 | 443 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aCtx); |
michael@0 | 444 | |
michael@0 | 445 | rv = nsNSSDialogHelper::openDialog(parent, |
michael@0 | 446 | "chrome://pippki/content/createCertInfo.xul", |
michael@0 | 447 | runnable); |
michael@0 | 448 | return rv; |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | NS_IMETHODIMP |
michael@0 | 452 | nsNSSDialogs::ChooseToken(nsIInterfaceRequestor *aCtx, const char16_t **aTokenList, uint32_t aCount, char16_t **aTokenChosen, bool *aCanceled) { |
michael@0 | 453 | nsresult rv; |
michael@0 | 454 | uint32_t i; |
michael@0 | 455 | |
michael@0 | 456 | *aCanceled = false; |
michael@0 | 457 | |
michael@0 | 458 | // Get the parent window for the dialog |
michael@0 | 459 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aCtx); |
michael@0 | 460 | |
michael@0 | 461 | nsCOMPtr<nsIDialogParamBlock> block = |
michael@0 | 462 | do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID); |
michael@0 | 463 | if (!block) return NS_ERROR_FAILURE; |
michael@0 | 464 | |
michael@0 | 465 | block->SetNumberStrings(aCount); |
michael@0 | 466 | |
michael@0 | 467 | for (i = 0; i < aCount; i++) { |
michael@0 | 468 | rv = block->SetString(i, aTokenList[i]); |
michael@0 | 469 | if (NS_FAILED(rv)) return rv; |
michael@0 | 470 | } |
michael@0 | 471 | |
michael@0 | 472 | rv = block->SetInt(0, aCount); |
michael@0 | 473 | if (NS_FAILED(rv)) return rv; |
michael@0 | 474 | |
michael@0 | 475 | rv = nsNSSDialogHelper::openDialog(nullptr, |
michael@0 | 476 | "chrome://pippki/content/choosetoken.xul", |
michael@0 | 477 | block); |
michael@0 | 478 | if (NS_FAILED(rv)) return rv; |
michael@0 | 479 | |
michael@0 | 480 | int32_t status; |
michael@0 | 481 | |
michael@0 | 482 | rv = block->GetInt(0, &status); |
michael@0 | 483 | if (NS_FAILED(rv)) return rv; |
michael@0 | 484 | |
michael@0 | 485 | *aCanceled = (status == 0)?true:false; |
michael@0 | 486 | if (!*aCanceled) { |
michael@0 | 487 | // retrieve the nickname |
michael@0 | 488 | rv = block->GetString(0, aTokenChosen); |
michael@0 | 489 | } |
michael@0 | 490 | return rv; |
michael@0 | 491 | } |
michael@0 | 492 | |
michael@0 | 493 | /* boolean ConfirmKeyEscrow (in nsIX509Cert escrowAuthority); */ |
michael@0 | 494 | NS_IMETHODIMP |
michael@0 | 495 | nsNSSDialogs::ConfirmKeyEscrow(nsIX509Cert *escrowAuthority, bool *_retval) |
michael@0 | 496 | |
michael@0 | 497 | { |
michael@0 | 498 | *_retval = false; |
michael@0 | 499 | |
michael@0 | 500 | nsresult rv; |
michael@0 | 501 | |
michael@0 | 502 | nsCOMPtr<nsIPKIParamBlock> block = |
michael@0 | 503 | do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID); |
michael@0 | 504 | if (!block) |
michael@0 | 505 | return NS_ERROR_FAILURE; |
michael@0 | 506 | |
michael@0 | 507 | rv = block->SetISupportAtIndex(1, escrowAuthority); |
michael@0 | 508 | if (NS_FAILED(rv)) |
michael@0 | 509 | return rv; |
michael@0 | 510 | |
michael@0 | 511 | rv = nsNSSDialogHelper::openDialog(nullptr, |
michael@0 | 512 | "chrome://pippki/content/escrowWarn.xul", |
michael@0 | 513 | block); |
michael@0 | 514 | |
michael@0 | 515 | if (NS_FAILED(rv)) |
michael@0 | 516 | return rv; |
michael@0 | 517 | |
michael@0 | 518 | int32_t status=0; |
michael@0 | 519 | nsCOMPtr<nsIDialogParamBlock> dlgParamBlock = do_QueryInterface(block); |
michael@0 | 520 | rv = dlgParamBlock->GetInt(1, &status); |
michael@0 | 521 | |
michael@0 | 522 | if (status) { |
michael@0 | 523 | *_retval = true; |
michael@0 | 524 | } |
michael@0 | 525 | return rv; |
michael@0 | 526 | } |
michael@0 | 527 | |
michael@0 | 528 | NS_IMETHODIMP |
michael@0 | 529 | nsNSSDialogs::DisplayProtectedAuth(nsIInterfaceRequestor *aCtx, nsIProtectedAuthThread *runnable) |
michael@0 | 530 | { |
michael@0 | 531 | // We cannot use nsNSSDialogHelper here. We cannot allow close widget |
michael@0 | 532 | // in the window because protected authentication is interruptible |
michael@0 | 533 | // from user interface and changing nsNSSDialogHelper's static variable |
michael@0 | 534 | // would not be thread-safe |
michael@0 | 535 | |
michael@0 | 536 | nsresult rv = NS_ERROR_FAILURE; |
michael@0 | 537 | |
michael@0 | 538 | // Get the parent window for the dialog |
michael@0 | 539 | nsCOMPtr<nsIDOMWindow> parent = do_GetInterface(aCtx); |
michael@0 | 540 | |
michael@0 | 541 | nsCOMPtr<nsIWindowWatcher> windowWatcher = |
michael@0 | 542 | do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv); |
michael@0 | 543 | if (NS_FAILED(rv)) |
michael@0 | 544 | return rv; |
michael@0 | 545 | |
michael@0 | 546 | if (!parent) { |
michael@0 | 547 | windowWatcher->GetActiveWindow(getter_AddRefs(parent)); |
michael@0 | 548 | } |
michael@0 | 549 | |
michael@0 | 550 | nsCOMPtr<nsIDOMWindow> newWindow; |
michael@0 | 551 | rv = windowWatcher->OpenWindow(parent, |
michael@0 | 552 | "chrome://pippki/content/protectedAuth.xul", |
michael@0 | 553 | "_blank", |
michael@0 | 554 | "centerscreen,chrome,modal,titlebar,close=no", |
michael@0 | 555 | runnable, |
michael@0 | 556 | getter_AddRefs(newWindow)); |
michael@0 | 557 | |
michael@0 | 558 | return rv; |
michael@0 | 559 | } |
michael@0 | 560 | |
michael@0 | 561 | NS_IMETHODIMP |
michael@0 | 562 | nsNSSDialogs::ShowCertError(nsIInterfaceRequestor *ctx, |
michael@0 | 563 | nsISSLStatus *status, |
michael@0 | 564 | nsIX509Cert *cert, |
michael@0 | 565 | const nsAString & textErrorMessage, |
michael@0 | 566 | const nsAString & htmlErrorMessage, |
michael@0 | 567 | const nsACString & hostName, |
michael@0 | 568 | uint32_t portNumber) |
michael@0 | 569 | { |
michael@0 | 570 | nsCOMPtr<nsIPKIParamBlock> block = |
michael@0 | 571 | do_CreateInstance(NS_PKIPARAMBLOCK_CONTRACTID); |
michael@0 | 572 | if (!block) |
michael@0 | 573 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 574 | |
michael@0 | 575 | nsCOMPtr<nsIDialogParamBlock> dialogBlock = do_QueryInterface(block); |
michael@0 | 576 | |
michael@0 | 577 | nsresult rv; |
michael@0 | 578 | rv = dialogBlock->SetInt(1, portNumber); |
michael@0 | 579 | if (NS_FAILED(rv)) |
michael@0 | 580 | return rv; |
michael@0 | 581 | |
michael@0 | 582 | rv = dialogBlock->SetString(1, NS_ConvertUTF8toUTF16(hostName).get()); |
michael@0 | 583 | if (NS_FAILED(rv)) |
michael@0 | 584 | return rv; |
michael@0 | 585 | |
michael@0 | 586 | rv = dialogBlock->SetString(2, PromiseFlatString(textErrorMessage).get()); |
michael@0 | 587 | if (NS_FAILED(rv)) |
michael@0 | 588 | return rv; |
michael@0 | 589 | |
michael@0 | 590 | rv = block->SetISupportAtIndex(1, cert); |
michael@0 | 591 | if (NS_FAILED(rv)) |
michael@0 | 592 | return rv; |
michael@0 | 593 | |
michael@0 | 594 | rv = nsNSSDialogHelper::openDialog(nullptr, |
michael@0 | 595 | "chrome://pippki/content/certerror.xul", |
michael@0 | 596 | block); |
michael@0 | 597 | return rv; |
michael@0 | 598 | } |