Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const nsIFilePicker = Components.interfaces.nsIFilePicker; |
michael@0 | 6 | const nsFilePicker = "@mozilla.org/filepicker;1"; |
michael@0 | 7 | const nsIX509CertDB = Components.interfaces.nsIX509CertDB; |
michael@0 | 8 | const nsX509CertDB = "@mozilla.org/security/x509certdb;1"; |
michael@0 | 9 | const nsIX509Cert = Components.interfaces.nsIX509Cert; |
michael@0 | 10 | const nsICertTree = Components.interfaces.nsICertTree; |
michael@0 | 11 | const nsCertTree = "@mozilla.org/security/nsCertTree;1"; |
michael@0 | 12 | const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock; |
michael@0 | 13 | const nsDialogParamBlock = "@mozilla.org/embedcomp/dialogparam;1"; |
michael@0 | 14 | const nsIPKIParamBlock = Components.interfaces.nsIPKIParamBlock; |
michael@0 | 15 | const nsPKIParamBlock = "@mozilla.org/security/pkiparamblock;1"; |
michael@0 | 16 | const nsINSSCertCache = Components.interfaces.nsINSSCertCache; |
michael@0 | 17 | const nsNSSCertCache = "@mozilla.org/security/nsscertcache;1"; |
michael@0 | 18 | |
michael@0 | 19 | var key; |
michael@0 | 20 | |
michael@0 | 21 | var selected_certs = []; |
michael@0 | 22 | var selected_tree_items = []; |
michael@0 | 23 | var selected_index = []; |
michael@0 | 24 | var certdb; |
michael@0 | 25 | |
michael@0 | 26 | var caTreeView; |
michael@0 | 27 | var serverTreeView; |
michael@0 | 28 | var emailTreeView; |
michael@0 | 29 | var userTreeView; |
michael@0 | 30 | var orphanTreeView; |
michael@0 | 31 | |
michael@0 | 32 | function LoadCerts() |
michael@0 | 33 | { |
michael@0 | 34 | window.crypto.enableSmartCardEvents = true; |
michael@0 | 35 | document.addEventListener("smartcard-insert", onSmartCardChange, false); |
michael@0 | 36 | document.addEventListener("smartcard-remove", onSmartCardChange, false); |
michael@0 | 37 | |
michael@0 | 38 | certdb = Components.classes[nsX509CertDB].getService(nsIX509CertDB); |
michael@0 | 39 | var certcache = Components.classes[nsNSSCertCache].createInstance(nsINSSCertCache); |
michael@0 | 40 | |
michael@0 | 41 | certcache.cacheAllCerts(); |
michael@0 | 42 | |
michael@0 | 43 | caTreeView = Components.classes[nsCertTree] |
michael@0 | 44 | .createInstance(nsICertTree); |
michael@0 | 45 | caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT); |
michael@0 | 46 | document.getElementById('ca-tree') |
michael@0 | 47 | .treeBoxObject.view = caTreeView; |
michael@0 | 48 | |
michael@0 | 49 | serverTreeView = Components.classes[nsCertTree] |
michael@0 | 50 | .createInstance(nsICertTree); |
michael@0 | 51 | serverTreeView.loadCertsFromCache(certcache, nsIX509Cert.SERVER_CERT); |
michael@0 | 52 | document.getElementById('server-tree') |
michael@0 | 53 | .treeBoxObject.view = serverTreeView; |
michael@0 | 54 | |
michael@0 | 55 | emailTreeView = Components.classes[nsCertTree] |
michael@0 | 56 | .createInstance(nsICertTree); |
michael@0 | 57 | emailTreeView.loadCertsFromCache(certcache, nsIX509Cert.EMAIL_CERT); |
michael@0 | 58 | document.getElementById('email-tree') |
michael@0 | 59 | .treeBoxObject.view = emailTreeView; |
michael@0 | 60 | |
michael@0 | 61 | userTreeView = Components.classes[nsCertTree] |
michael@0 | 62 | .createInstance(nsICertTree); |
michael@0 | 63 | userTreeView.loadCertsFromCache(certcache, nsIX509Cert.USER_CERT); |
michael@0 | 64 | document.getElementById('user-tree') |
michael@0 | 65 | .treeBoxObject.view = userTreeView; |
michael@0 | 66 | |
michael@0 | 67 | orphanTreeView = Components.classes[nsCertTree] |
michael@0 | 68 | .createInstance(nsICertTree); |
michael@0 | 69 | orphanTreeView.loadCertsFromCache(certcache, nsIX509Cert.UNKNOWN_CERT); |
michael@0 | 70 | document.getElementById('orphan-tree') |
michael@0 | 71 | .treeBoxObject.view = orphanTreeView; |
michael@0 | 72 | |
michael@0 | 73 | enableBackupAllButton(); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function enableBackupAllButton() |
michael@0 | 77 | { |
michael@0 | 78 | var rowCnt = userTreeView.rowCount; |
michael@0 | 79 | var backupAllButton=document.getElementById('mine_backupAllButton'); |
michael@0 | 80 | backupAllButton.disabled = (rowCnt < 1); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function getSelectedCerts() |
michael@0 | 84 | { |
michael@0 | 85 | var ca_tab = document.getElementById("ca_tab"); |
michael@0 | 86 | var mine_tab = document.getElementById("mine_tab"); |
michael@0 | 87 | var others_tab = document.getElementById("others_tab"); |
michael@0 | 88 | var websites_tab = document.getElementById("websites_tab"); |
michael@0 | 89 | var orphan_tab = document.getElementById("orphan_tab"); |
michael@0 | 90 | var items = null; |
michael@0 | 91 | if (ca_tab.selected) { |
michael@0 | 92 | items = caTreeView.selection; |
michael@0 | 93 | } else if (mine_tab.selected) { |
michael@0 | 94 | items = userTreeView.selection; |
michael@0 | 95 | } else if (others_tab.selected) { |
michael@0 | 96 | items = emailTreeView.selection; |
michael@0 | 97 | } else if (websites_tab.selected) { |
michael@0 | 98 | items = serverTreeView.selection; |
michael@0 | 99 | } else if (orphan_tab.selected) { |
michael@0 | 100 | items = orphanTreeView.selection; |
michael@0 | 101 | } |
michael@0 | 102 | selected_certs = []; |
michael@0 | 103 | var cert = null; |
michael@0 | 104 | var nr = 0; |
michael@0 | 105 | if (items != null) nr = items.getRangeCount(); |
michael@0 | 106 | if (nr > 0) { |
michael@0 | 107 | for (var i=0; i<nr; i++) { |
michael@0 | 108 | var o1 = {}; |
michael@0 | 109 | var o2 = {}; |
michael@0 | 110 | items.getRangeAt(i, o1, o2); |
michael@0 | 111 | var min = o1.value; |
michael@0 | 112 | var max = o2.value; |
michael@0 | 113 | for (var j=min; j<=max; j++) { |
michael@0 | 114 | if (ca_tab.selected) { |
michael@0 | 115 | cert = caTreeView.getCert(j); |
michael@0 | 116 | } else if (mine_tab.selected) { |
michael@0 | 117 | cert = userTreeView.getCert(j); |
michael@0 | 118 | } else if (others_tab.selected) { |
michael@0 | 119 | cert = emailTreeView.getCert(j); |
michael@0 | 120 | } else if (websites_tab.selected) { |
michael@0 | 121 | cert = serverTreeView.getCert(j); |
michael@0 | 122 | } else if (orphan_tab.selected) { |
michael@0 | 123 | cert = orphanTreeView.getCert(j); |
michael@0 | 124 | } |
michael@0 | 125 | if (cert) { |
michael@0 | 126 | var sc = selected_certs.length; |
michael@0 | 127 | selected_certs[sc] = cert; |
michael@0 | 128 | selected_index[sc] = j; |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | } |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | function getSelectedTreeItems() |
michael@0 | 136 | { |
michael@0 | 137 | var ca_tab = document.getElementById("ca_tab"); |
michael@0 | 138 | var mine_tab = document.getElementById("mine_tab"); |
michael@0 | 139 | var others_tab = document.getElementById("others_tab"); |
michael@0 | 140 | var websites_tab = document.getElementById("websites_tab"); |
michael@0 | 141 | var orphan_tab = document.getElementById("orphan_tab"); |
michael@0 | 142 | var items = null; |
michael@0 | 143 | if (ca_tab.selected) { |
michael@0 | 144 | items = caTreeView.selection; |
michael@0 | 145 | } else if (mine_tab.selected) { |
michael@0 | 146 | items = userTreeView.selection; |
michael@0 | 147 | } else if (others_tab.selected) { |
michael@0 | 148 | items = emailTreeView.selection; |
michael@0 | 149 | } else if (websites_tab.selected) { |
michael@0 | 150 | items = serverTreeView.selection; |
michael@0 | 151 | } else if (orphan_tab.selected) { |
michael@0 | 152 | items = orphanTreeView.selection; |
michael@0 | 153 | } |
michael@0 | 154 | selected_certs = []; |
michael@0 | 155 | selected_tree_items = []; |
michael@0 | 156 | selected_index = []; |
michael@0 | 157 | var tree_item = null; |
michael@0 | 158 | var nr = 0; |
michael@0 | 159 | if (items != null) nr = items.getRangeCount(); |
michael@0 | 160 | if (nr > 0) { |
michael@0 | 161 | for (var i=0; i<nr; i++) { |
michael@0 | 162 | var o1 = {}; |
michael@0 | 163 | var o2 = {}; |
michael@0 | 164 | items.getRangeAt(i, o1, o2); |
michael@0 | 165 | var min = o1.value; |
michael@0 | 166 | var max = o2.value; |
michael@0 | 167 | for (var j=min; j<=max; j++) { |
michael@0 | 168 | if (ca_tab.selected) { |
michael@0 | 169 | tree_item = caTreeView.getTreeItem(j); |
michael@0 | 170 | } else if (mine_tab.selected) { |
michael@0 | 171 | tree_item = userTreeView.getTreeItem(j); |
michael@0 | 172 | } else if (others_tab.selected) { |
michael@0 | 173 | tree_item = emailTreeView.getTreeItem(j); |
michael@0 | 174 | } else if (websites_tab.selected) { |
michael@0 | 175 | tree_item = serverTreeView.getTreeItem(j); |
michael@0 | 176 | } else if (orphan_tab.selected) { |
michael@0 | 177 | tree_item = orphanTreeView.getTreeItem(j); |
michael@0 | 178 | } |
michael@0 | 179 | if (tree_item) { |
michael@0 | 180 | var sc = selected_tree_items.length; |
michael@0 | 181 | selected_tree_items[sc] = tree_item; |
michael@0 | 182 | selected_index[sc] = j; |
michael@0 | 183 | } |
michael@0 | 184 | } |
michael@0 | 185 | } |
michael@0 | 186 | } |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | function ca_enableButtons() |
michael@0 | 190 | { |
michael@0 | 191 | var items = caTreeView.selection; |
michael@0 | 192 | var nr = items.getRangeCount(); |
michael@0 | 193 | var toggle="false"; |
michael@0 | 194 | if (nr == 0) { |
michael@0 | 195 | toggle="true"; |
michael@0 | 196 | } |
michael@0 | 197 | var edit_toggle=toggle; |
michael@0 | 198 | /* |
michael@0 | 199 | var edit_toggle="true"; |
michael@0 | 200 | if (nr > 0) { |
michael@0 | 201 | for (var i=0; i<nr; i++) { |
michael@0 | 202 | var o1 = {}; |
michael@0 | 203 | var o2 = {}; |
michael@0 | 204 | items.getRangeAt(i, o1, o2); |
michael@0 | 205 | var min = o1.value; |
michael@0 | 206 | var max = o2.value; |
michael@0 | 207 | var stop = false; |
michael@0 | 208 | for (var j=min; j<=max; j++) { |
michael@0 | 209 | var tokenName = items.tree.view.getCellText(j, "tokencol"); |
michael@0 | 210 | if (tokenName == "Builtin Object Token") { stop = true; } break; |
michael@0 | 211 | } |
michael@0 | 212 | if (stop) break; |
michael@0 | 213 | } |
michael@0 | 214 | if (i == nr) { |
michael@0 | 215 | edit_toggle="false"; |
michael@0 | 216 | } |
michael@0 | 217 | } |
michael@0 | 218 | */ |
michael@0 | 219 | var enableViewButton=document.getElementById('ca_viewButton'); |
michael@0 | 220 | enableViewButton.setAttribute("disabled",toggle); |
michael@0 | 221 | var enableEditButton=document.getElementById('ca_editButton'); |
michael@0 | 222 | enableEditButton.setAttribute("disabled",edit_toggle); |
michael@0 | 223 | var enableExportButton=document.getElementById('ca_exportButton'); |
michael@0 | 224 | enableExportButton.setAttribute("disabled",toggle); |
michael@0 | 225 | var enableDeleteButton=document.getElementById('ca_deleteButton'); |
michael@0 | 226 | enableDeleteButton.setAttribute("disabled",toggle); |
michael@0 | 227 | } |
michael@0 | 228 | |
michael@0 | 229 | function mine_enableButtons() |
michael@0 | 230 | { |
michael@0 | 231 | var items = userTreeView.selection; |
michael@0 | 232 | var toggle="false"; |
michael@0 | 233 | if (items.getRangeCount() == 0) { |
michael@0 | 234 | toggle="true"; |
michael@0 | 235 | } |
michael@0 | 236 | var enableViewButton=document.getElementById('mine_viewButton'); |
michael@0 | 237 | enableViewButton.setAttribute("disabled",toggle); |
michael@0 | 238 | var enableBackupButton=document.getElementById('mine_backupButton'); |
michael@0 | 239 | enableBackupButton.setAttribute("disabled",toggle); |
michael@0 | 240 | var enableDeleteButton=document.getElementById('mine_deleteButton'); |
michael@0 | 241 | enableDeleteButton.setAttribute("disabled",toggle); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | function websites_enableButtons() |
michael@0 | 245 | { |
michael@0 | 246 | var items = serverTreeView.selection; |
michael@0 | 247 | var count_ranges = items.getRangeCount(); |
michael@0 | 248 | |
michael@0 | 249 | var enable_delete = false; |
michael@0 | 250 | var enable_view = false; |
michael@0 | 251 | |
michael@0 | 252 | if (count_ranges > 0) { |
michael@0 | 253 | enable_delete = true; |
michael@0 | 254 | } |
michael@0 | 255 | |
michael@0 | 256 | if (count_ranges == 1) { |
michael@0 | 257 | var o1 = {}; |
michael@0 | 258 | var o2 = {}; |
michael@0 | 259 | items.getRangeAt(0, o1, o2); // the first range |
michael@0 | 260 | if (o1.value == o2.value) { |
michael@0 | 261 | // only a single item is selected |
michael@0 | 262 | try { |
michael@0 | 263 | var ti = serverTreeView.getTreeItem(o1.value); |
michael@0 | 264 | if (ti) { |
michael@0 | 265 | if (ti.cert) { |
michael@0 | 266 | enable_view = true; |
michael@0 | 267 | } |
michael@0 | 268 | } |
michael@0 | 269 | } |
michael@0 | 270 | catch (e) { |
michael@0 | 271 | } |
michael@0 | 272 | } |
michael@0 | 273 | } |
michael@0 | 274 | |
michael@0 | 275 | var enableViewButton=document.getElementById('websites_viewButton'); |
michael@0 | 276 | enableViewButton.setAttribute("disabled", !enable_view); |
michael@0 | 277 | var enableExportButton=document.getElementById('websites_exportButton'); |
michael@0 | 278 | enableExportButton.setAttribute("disabled", !enable_view); |
michael@0 | 279 | var enableDeleteButton=document.getElementById('websites_deleteButton'); |
michael@0 | 280 | enableDeleteButton.setAttribute("disabled", !enable_delete); |
michael@0 | 281 | } |
michael@0 | 282 | |
michael@0 | 283 | function email_enableButtons() |
michael@0 | 284 | { |
michael@0 | 285 | var items = emailTreeView.selection; |
michael@0 | 286 | var toggle="false"; |
michael@0 | 287 | if (items.getRangeCount() == 0) { |
michael@0 | 288 | toggle="true"; |
michael@0 | 289 | } |
michael@0 | 290 | var enableViewButton=document.getElementById('email_viewButton'); |
michael@0 | 291 | enableViewButton.setAttribute("disabled",toggle); |
michael@0 | 292 | var enableEditButton=document.getElementById('email_editButton'); |
michael@0 | 293 | enableEditButton.setAttribute("disabled",toggle); |
michael@0 | 294 | var enableExportButton=document.getElementById('email_exportButton'); |
michael@0 | 295 | enableExportButton.setAttribute("disabled",toggle); |
michael@0 | 296 | var enableDeleteButton=document.getElementById('email_deleteButton'); |
michael@0 | 297 | enableDeleteButton.setAttribute("disabled",toggle); |
michael@0 | 298 | } |
michael@0 | 299 | |
michael@0 | 300 | function orphan_enableButtons() |
michael@0 | 301 | { |
michael@0 | 302 | var items = orphanTreeView.selection; |
michael@0 | 303 | var toggle="false"; |
michael@0 | 304 | if (items.getRangeCount() == 0) { |
michael@0 | 305 | toggle="true"; |
michael@0 | 306 | } |
michael@0 | 307 | var enableViewButton=document.getElementById('orphan_viewButton'); |
michael@0 | 308 | enableViewButton.setAttribute("disabled",toggle); |
michael@0 | 309 | var enableExportButton=document.getElementById('orphan_exportButton'); |
michael@0 | 310 | enableExportButton.setAttribute("disabled",toggle); |
michael@0 | 311 | var enableDeleteButton=document.getElementById('orphan_deleteButton'); |
michael@0 | 312 | enableDeleteButton.setAttribute("disabled",toggle); |
michael@0 | 313 | } |
michael@0 | 314 | |
michael@0 | 315 | function backupCerts() |
michael@0 | 316 | { |
michael@0 | 317 | getSelectedCerts(); |
michael@0 | 318 | var numcerts = selected_certs.length; |
michael@0 | 319 | if (!numcerts) |
michael@0 | 320 | return; |
michael@0 | 321 | var bundle = document.getElementById("pippki_bundle"); |
michael@0 | 322 | var fp = Components.classes[nsFilePicker].createInstance(nsIFilePicker); |
michael@0 | 323 | fp.init(window, |
michael@0 | 324 | bundle.getString("chooseP12BackupFileDialog"), |
michael@0 | 325 | nsIFilePicker.modeSave); |
michael@0 | 326 | fp.appendFilter(bundle.getString("file_browse_PKCS12_spec"), |
michael@0 | 327 | "*.p12"); |
michael@0 | 328 | fp.appendFilters(nsIFilePicker.filterAll); |
michael@0 | 329 | var rv = fp.show(); |
michael@0 | 330 | if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { |
michael@0 | 331 | certdb.exportPKCS12File(null, fp.file, |
michael@0 | 332 | selected_certs.length, selected_certs); |
michael@0 | 333 | } |
michael@0 | 334 | } |
michael@0 | 335 | |
michael@0 | 336 | function backupAllCerts() |
michael@0 | 337 | { |
michael@0 | 338 | // Select all rows, then call doBackup() |
michael@0 | 339 | var items = userTreeView.selection.selectAll(); |
michael@0 | 340 | backupCerts(); |
michael@0 | 341 | } |
michael@0 | 342 | |
michael@0 | 343 | function editCerts() |
michael@0 | 344 | { |
michael@0 | 345 | getSelectedCerts(); |
michael@0 | 346 | var numcerts = selected_certs.length; |
michael@0 | 347 | if (!numcerts) |
michael@0 | 348 | return; |
michael@0 | 349 | for (var t=0; t<numcerts; t++) { |
michael@0 | 350 | var cert = selected_certs[t]; |
michael@0 | 351 | var certkey = cert.dbKey; |
michael@0 | 352 | if (document.getElementById("ca_tab").selected) { |
michael@0 | 353 | window.openDialog('chrome://pippki/content/editcacert.xul', certkey, |
michael@0 | 354 | 'chrome,centerscreen,modal'); |
michael@0 | 355 | } else if (document.getElementById("others_tab").selected) { |
michael@0 | 356 | window.openDialog('chrome://pippki/content/editemailcert.xul', certkey, |
michael@0 | 357 | 'chrome,centerscreen,modal'); |
michael@0 | 358 | } |
michael@0 | 359 | } |
michael@0 | 360 | } |
michael@0 | 361 | |
michael@0 | 362 | function restoreCerts() |
michael@0 | 363 | { |
michael@0 | 364 | var bundle = document.getElementById("pippki_bundle"); |
michael@0 | 365 | var fp = Components.classes[nsFilePicker].createInstance(nsIFilePicker); |
michael@0 | 366 | fp.init(window, |
michael@0 | 367 | bundle.getString("chooseP12RestoreFileDialog2"), |
michael@0 | 368 | nsIFilePicker.modeOpen); |
michael@0 | 369 | fp.appendFilter(bundle.getString("file_browse_PKCS12_spec"), |
michael@0 | 370 | "*.p12; *.pfx"); |
michael@0 | 371 | fp.appendFilters(nsIFilePicker.filterAll); |
michael@0 | 372 | if (fp.show() == nsIFilePicker.returnOK) { |
michael@0 | 373 | certdb.importPKCS12File(null, fp.file); |
michael@0 | 374 | |
michael@0 | 375 | var certcache = Components.classes[nsNSSCertCache].createInstance(nsINSSCertCache); |
michael@0 | 376 | certcache.cacheAllCerts(); |
michael@0 | 377 | userTreeView.loadCertsFromCache(certcache, nsIX509Cert.USER_CERT); |
michael@0 | 378 | userTreeView.selection.clearSelection(); |
michael@0 | 379 | caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT); |
michael@0 | 380 | caTreeView.selection.clearSelection(); |
michael@0 | 381 | enableBackupAllButton(); |
michael@0 | 382 | } |
michael@0 | 383 | } |
michael@0 | 384 | |
michael@0 | 385 | function exportCerts() |
michael@0 | 386 | { |
michael@0 | 387 | getSelectedCerts(); |
michael@0 | 388 | var numcerts = selected_certs.length; |
michael@0 | 389 | if (!numcerts) |
michael@0 | 390 | return; |
michael@0 | 391 | |
michael@0 | 392 | for (var t=0; t<numcerts; t++) { |
michael@0 | 393 | exportToFile(window, selected_certs[t]); |
michael@0 | 394 | } |
michael@0 | 395 | } |
michael@0 | 396 | |
michael@0 | 397 | function deleteCerts() |
michael@0 | 398 | { |
michael@0 | 399 | getSelectedTreeItems(); |
michael@0 | 400 | var numcerts = selected_tree_items.length; |
michael@0 | 401 | if (!numcerts) |
michael@0 | 402 | return; |
michael@0 | 403 | |
michael@0 | 404 | var params = Components.classes[nsDialogParamBlock].createInstance(nsIDialogParamBlock); |
michael@0 | 405 | |
michael@0 | 406 | var selTab = document.getElementById('certMgrTabbox').selectedItem; |
michael@0 | 407 | var selTabID = selTab.getAttribute('id'); |
michael@0 | 408 | var t; |
michael@0 | 409 | |
michael@0 | 410 | params.SetNumberStrings(numcerts+1); |
michael@0 | 411 | |
michael@0 | 412 | if (selTabID == 'mine_tab') |
michael@0 | 413 | { |
michael@0 | 414 | params.SetString(0, selTabID); |
michael@0 | 415 | } |
michael@0 | 416 | else if (selTabID == "websites_tab") |
michael@0 | 417 | { |
michael@0 | 418 | params.SetString(0, selTabID); |
michael@0 | 419 | } |
michael@0 | 420 | else if (selTabID == "ca_tab") |
michael@0 | 421 | { |
michael@0 | 422 | params.SetString(0, selTabID); |
michael@0 | 423 | } |
michael@0 | 424 | else if (selTabID == "others_tab") |
michael@0 | 425 | { |
michael@0 | 426 | params.SetString(0, selTabID); |
michael@0 | 427 | } |
michael@0 | 428 | else if (selTabID == "orphan_tab") |
michael@0 | 429 | { |
michael@0 | 430 | params.SetString(0, selTabID); |
michael@0 | 431 | } |
michael@0 | 432 | else |
michael@0 | 433 | { |
michael@0 | 434 | return; |
michael@0 | 435 | } |
michael@0 | 436 | |
michael@0 | 437 | params.SetInt(0,numcerts); |
michael@0 | 438 | for (t=0; t<numcerts; t++) |
michael@0 | 439 | { |
michael@0 | 440 | var tree_item = selected_tree_items[t]; |
michael@0 | 441 | var c = tree_item.cert; |
michael@0 | 442 | if (!c) { |
michael@0 | 443 | params.SetString(t+1, tree_item.hostPort); |
michael@0 | 444 | } |
michael@0 | 445 | else { |
michael@0 | 446 | params.SetString(t+1, c.commonName); |
michael@0 | 447 | } |
michael@0 | 448 | |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | window.openDialog('chrome://pippki/content/deletecert.xul', "", |
michael@0 | 452 | 'chrome,centerscreen,modal', params); |
michael@0 | 453 | |
michael@0 | 454 | if (params.GetInt(1) == 1) { |
michael@0 | 455 | // user closed dialog with OK |
michael@0 | 456 | var treeView = null; |
michael@0 | 457 | var loadParam = null; |
michael@0 | 458 | |
michael@0 | 459 | selTab = document.getElementById('certMgrTabbox').selectedItem; |
michael@0 | 460 | selTabID = selTab.getAttribute('id'); |
michael@0 | 461 | if (selTabID == 'mine_tab') { |
michael@0 | 462 | treeView = userTreeView; |
michael@0 | 463 | } else if (selTabID == "others_tab") { |
michael@0 | 464 | treeView = emailTreeView; |
michael@0 | 465 | } else if (selTabID == "websites_tab") { |
michael@0 | 466 | treeView = serverTreeView; |
michael@0 | 467 | } else if (selTabID == "ca_tab") { |
michael@0 | 468 | treeView = caTreeView; |
michael@0 | 469 | } else if (selTabID == "orphan_tab") { |
michael@0 | 470 | treeView = orphanTreeView; |
michael@0 | 471 | } |
michael@0 | 472 | |
michael@0 | 473 | for (t=numcerts-1; t>=0; t--) |
michael@0 | 474 | { |
michael@0 | 475 | treeView.deleteEntryObject(selected_index[t]); |
michael@0 | 476 | } |
michael@0 | 477 | |
michael@0 | 478 | selected_tree_items = []; |
michael@0 | 479 | selected_index = []; |
michael@0 | 480 | treeView.selection.clearSelection(); |
michael@0 | 481 | if (selTabID == 'mine_tab') { |
michael@0 | 482 | enableBackupAllButton(); |
michael@0 | 483 | } |
michael@0 | 484 | } |
michael@0 | 485 | } |
michael@0 | 486 | |
michael@0 | 487 | function viewCerts() |
michael@0 | 488 | { |
michael@0 | 489 | getSelectedCerts(); |
michael@0 | 490 | var numcerts = selected_certs.length; |
michael@0 | 491 | if (!numcerts) |
michael@0 | 492 | return; |
michael@0 | 493 | |
michael@0 | 494 | for (var t=0; t<numcerts; t++) { |
michael@0 | 495 | viewCertHelper(window, selected_certs[t]); |
michael@0 | 496 | } |
michael@0 | 497 | } |
michael@0 | 498 | |
michael@0 | 499 | function addCACerts() |
michael@0 | 500 | { |
michael@0 | 501 | var bundle = document.getElementById("pippki_bundle"); |
michael@0 | 502 | var fp = Components.classes[nsFilePicker].createInstance(nsIFilePicker); |
michael@0 | 503 | fp.init(window, |
michael@0 | 504 | bundle.getString("importCACertsPrompt"), |
michael@0 | 505 | nsIFilePicker.modeOpen); |
michael@0 | 506 | fp.appendFilter(bundle.getString("file_browse_Certificate_spec"), |
michael@0 | 507 | "*.crt; *.cert; *.cer; *.pem; *.der"); |
michael@0 | 508 | fp.appendFilters(nsIFilePicker.filterAll); |
michael@0 | 509 | if (fp.show() == nsIFilePicker.returnOK) { |
michael@0 | 510 | certdb.importCertsFromFile(null, fp.file, nsIX509Cert.CA_CERT); |
michael@0 | 511 | caTreeView.loadCerts(nsIX509Cert.CA_CERT); |
michael@0 | 512 | caTreeView.selection.clearSelection(); |
michael@0 | 513 | } |
michael@0 | 514 | } |
michael@0 | 515 | |
michael@0 | 516 | function onSmartCardChange() |
michael@0 | 517 | { |
michael@0 | 518 | var certcache = Components.classes[nsNSSCertCache].createInstance(nsINSSCertCache); |
michael@0 | 519 | // We've change the state of the smart cards inserted or removed |
michael@0 | 520 | // that means the available certs may have changed. Update the display |
michael@0 | 521 | certcache.cacheAllCerts(); |
michael@0 | 522 | userTreeView.loadCertsFromCache(certcache, nsIX509Cert.USER_CERT); |
michael@0 | 523 | userTreeView.selection.clearSelection(); |
michael@0 | 524 | caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT); |
michael@0 | 525 | caTreeView.selection.clearSelection(); |
michael@0 | 526 | serverTreeView.loadCertsFromCache(certcache, nsIX509Cert.SERVER_CERT); |
michael@0 | 527 | serverTreeView.selection.clearSelection(); |
michael@0 | 528 | emailTreeView.loadCertsFromCache(certcache, nsIX509Cert.EMAIL_CERT); |
michael@0 | 529 | emailTreeView.selection.clearSelection(); |
michael@0 | 530 | orphanTreeView.loadCertsFromCache(certcache, nsIX509Cert.UNKNOWN_CERT); |
michael@0 | 531 | orphanTreeView.selection.clearSelection(); |
michael@0 | 532 | } |
michael@0 | 533 | |
michael@0 | 534 | function addEmailCert() |
michael@0 | 535 | { |
michael@0 | 536 | var bundle = document.getElementById("pippki_bundle"); |
michael@0 | 537 | var fp = Components.classes[nsFilePicker].createInstance(nsIFilePicker); |
michael@0 | 538 | fp.init(window, |
michael@0 | 539 | bundle.getString("importEmailCertPrompt"), |
michael@0 | 540 | nsIFilePicker.modeOpen); |
michael@0 | 541 | fp.appendFilter(bundle.getString("file_browse_Certificate_spec"), |
michael@0 | 542 | "*.crt; *.cert; *.cer; *.pem; *.der"); |
michael@0 | 543 | fp.appendFilters(nsIFilePicker.filterAll); |
michael@0 | 544 | if (fp.show() == nsIFilePicker.returnOK) { |
michael@0 | 545 | certdb.importCertsFromFile(null, fp.file, nsIX509Cert.EMAIL_CERT); |
michael@0 | 546 | var certcache = Components.classes[nsNSSCertCache].createInstance(nsINSSCertCache); |
michael@0 | 547 | certcache.cacheAllCerts(); |
michael@0 | 548 | emailTreeView.loadCertsFromCache(certcache, nsIX509Cert.EMAIL_CERT); |
michael@0 | 549 | emailTreeView.selection.clearSelection(); |
michael@0 | 550 | caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT); |
michael@0 | 551 | caTreeView.selection.clearSelection(); |
michael@0 | 552 | } |
michael@0 | 553 | } |
michael@0 | 554 | |
michael@0 | 555 | function addWebSiteCert() |
michael@0 | 556 | { |
michael@0 | 557 | var bundle = document.getElementById("pippki_bundle"); |
michael@0 | 558 | var fp = Components.classes[nsFilePicker].createInstance(nsIFilePicker); |
michael@0 | 559 | fp.init(window, |
michael@0 | 560 | bundle.getString("importServerCertPrompt"), |
michael@0 | 561 | nsIFilePicker.modeOpen); |
michael@0 | 562 | fp.appendFilter(bundle.getString("file_browse_Certificate_spec"), |
michael@0 | 563 | "*.crt; *.cert; *.cer; *.pem; *.der"); |
michael@0 | 564 | fp.appendFilters(nsIFilePicker.filterAll); |
michael@0 | 565 | if (fp.show() == nsIFilePicker.returnOK) { |
michael@0 | 566 | certdb.importCertsFromFile(null, fp.file, nsIX509Cert.SERVER_CERT); |
michael@0 | 567 | |
michael@0 | 568 | var certcache = Components.classes[nsNSSCertCache].createInstance(nsINSSCertCache); |
michael@0 | 569 | certcache.cacheAllCerts(); |
michael@0 | 570 | serverTreeView.loadCertsFromCache(certcache, nsIX509Cert.SERVER_CERT); |
michael@0 | 571 | serverTreeView.selection.clearSelection(); |
michael@0 | 572 | caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT); |
michael@0 | 573 | caTreeView.selection.clearSelection(); |
michael@0 | 574 | } |
michael@0 | 575 | } |
michael@0 | 576 | |
michael@0 | 577 | function addException() |
michael@0 | 578 | { |
michael@0 | 579 | window.openDialog('chrome://pippki/content/exceptionDialog.xul', "", |
michael@0 | 580 | 'chrome,centerscreen,modal'); |
michael@0 | 581 | var certcache = Components.classes[nsNSSCertCache].createInstance(nsINSSCertCache); |
michael@0 | 582 | certcache.cacheAllCerts(); |
michael@0 | 583 | serverTreeView.loadCertsFromCache(certcache, nsIX509Cert.SERVER_CERT); |
michael@0 | 584 | serverTreeView.selection.clearSelection(); |
michael@0 | 585 | orphanTreeView.loadCertsFromCache(certcache, nsIX509Cert.UNKNOWN_CERT); |
michael@0 | 586 | orphanTreeView.selection.clearSelection(); |
michael@0 | 587 | } |
michael@0 | 588 |