!import
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Mozilla Communicator.
15 *
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2002
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ***** END LICENSE BLOCK ***** */
36
37 var gListBox;
38 var gViewButton;
39 var gBundle;
40
41 var gEmailAddresses;
42 var gCertStatusSummaries;
43 var gCertIssuedInfos;
44 var gCertExpiresInfos;
45 var gCerts;
46 var gCount;
47
48 var gSMimeContractID = "@mozilla.org/messenger-smime/smimejshelper;1";
49 var gISMimeJSHelper = Components.interfaces.nsISMimeJSHelper;
50 var gIX509Cert = Components.interfaces.nsIX509Cert;
51 const nsICertificateDialogs = Components.interfaces.nsICertificateDialogs;
52 const nsCertificateDialogs = "@mozilla.org/nsCertificateDialogs;1"
53
getStatusExplanation
54 function getStatusExplanation(value)
55 {
56 switch (value)
57 {
58 case gIX509Cert.VERIFIED_OK:
59 return gBundle.getString("StatusValid");
60
61 case gIX509Cert.NOT_VERIFIED_UNKNOWN:
62 case gIX509Cert.INVALID_CA:
63 case gIX509Cert.USAGE_NOT_ALLOWED:
64 return gBundle.getString("StatusInvalid");
65
66 case gIX509Cert.CERT_REVOKED:
67 return gBundle.getString("StatusRevoked");
68
69 case gIX509Cert.CERT_EXPIRED:
70 return gBundle.getString("StatusExpired");
71
72 case gIX509Cert.CERT_NOT_TRUSTED:
73 case gIX509Cert.ISSUER_NOT_TRUSTED:
74 case gIX509Cert.ISSUER_UNKNOWN:
75 return gBundle.getString("StatusUntrusted");
76 }
77
78 return "";
79 }
80
onLoad
81 function onLoad()
82 {
83 var params = window.arguments[0];
84 if (!params)
85 return;
86
87 var helper = Components.classes[gSMimeContractID].createInstance(gISMimeJSHelper);
88
89 if (!helper)
90 return;
91
92 gListBox = document.getElementById("infolist");
93 gViewButton = document.getElementById("viewCertButton");
94 gBundle = document.getElementById("bundle_smime_comp_info");
95
96 gEmailAddresses = new Object();
97 gCertStatusSummaries = new Object();
98 gCertIssuedInfos = new Object();
99 gCertExpiresInfos = new Object();
100 gCerts = new Object();
101 gCount = new Object();
102 var canEncrypt = new Object();
103
104 var allow_ldap_cert_fetching = false;
105
106 try {
107 if (params.compFields.securityInfo.requireEncryptMessage) {
108 allow_ldap_cert_fetching = true;
109 }
110 }
111 catch (e)
112 {
113 }
114
115 while (true)
116 {
117 try
118 {
119 helper.getRecipientCertsInfo(
120 params.compFields,
121 gCount,
122 gEmailAddresses,
123 gCertStatusSummaries,
124 gCertIssuedInfos,
125 gCertExpiresInfos,
126 gCerts,
127 canEncrypt);
128 }
129 catch (e)
130 {
131 dump(e);
132 return;
133 }
134
135 if (!allow_ldap_cert_fetching)
136 break;
137
138 allow_ldap_cert_fetching = false;
139
140 var missing = new Array();
141
142 for (var j = gCount.value - 1; j >= 0; --j)
143 {
144 if (!gCerts.value[j])
145 {
146 missing[missing.length] = gEmailAddresses.value[j];
147 }
148 }
149
150 if (missing.length > 0)
151 {
152 var prefService =
153 Components.classes["@mozilla.org/preferences-service;1"]
154 .getService(Components.interfaces.nsIPrefService);
155 var sPrefs = prefService.getBranch(null);
156
157 var autocompleteLdap = false;
158 autocompleteLdap = sPrefs.getBoolPref("ldap_2.autoComplete.useDirectory");
159
160 if (autocompleteLdap)
161 {
162 var autocompleteDirectory = null;
163 autocompleteDirectory = sPrefs.getCharPref(
164 "ldap_2.autoComplete.directoryServer");
165
166 if(params.currentIdentity.overrideGlobalPref) {
167 autocompleteDirectory = params.currentIdentity.directoryServer;
168 }
169
170 if (autocompleteDirectory)
171 {
172 window.openDialog('chrome://messenger-smime/content/certFetchingStatus.xul',
173 '',
174 'chrome,resizable=1,modal=1,dialog=1',
175 autocompleteDirectory,
176 missing
177 );
178 }
179 }
180 }
181 }
182
183 if (gBundle)
184 {
185 var yes_string = gBundle.getString("StatusYes");
186 var no_string = gBundle.getString("StatusNo");
187 var not_possible_string = gBundle.getString("StatusNotPossible");
188
189 var signed_element = document.getElementById("signed");
190 var encrypted_element = document.getElementById("encrypted");
191
192 if (params.smFields.requireEncryptMessage)
193 {
194 if (params.isEncryptionCertAvailable && canEncrypt.value)
195 {
196 encrypted_element.value = yes_string;
197 }
198 else
199 {
200 encrypted_element.value = not_possible_string;
201 }
202 }
203 else
204 {
205 encrypted_element.value = no_string;
206 }
207
208 if (params.smFields.signMessage)
209 {
210 if (params.isSigningCertAvailable)
211 {
212 signed_element.value = yes_string;
213 }
214 else
215 {
216 signed_element.value = not_possible_string;
217 }
218 }
219 else
220 {
221 signed_element.value = no_string;
222 }
223 }
224
225 var imax = gCount.value;
226
227 for (var i = 0; i < imax; ++i)
228 {
229 var listitem = document.createElement("listitem");
230
231 listitem.appendChild(createCell(gEmailAddresses.value[i]));
232
233 if (!gCerts.value[i])
234 {
235 listitem.appendChild(createCell(gBundle.getString("StatusNotFound")));
236 }
237 else
238 {
239 listitem.appendChild(createCell(getStatusExplanation(gCertStatusSummaries.value[i])));
240 listitem.appendChild(createCell(gCertIssuedInfos.value[i]));
241 listitem.appendChild(createCell(gCertExpiresInfos.value[i]));
242 }
243
244 gListBox.appendChild(listitem);
245 }
246 }
247
onSelectionChange
248 function onSelectionChange(event)
249 {
250 if (gListBox.selectedItems.length <= 0)
251 {
252 gViewButton.setAttribute("disabled", "true");
253 }
254 else
255 {
256 gViewButton.removeAttribute("disabled");
257 }
258 }
259
viewCertHelper
260 function viewCertHelper(parent, cert) {
261 var cd = Components.classes[nsCertificateDialogs].getService(nsICertificateDialogs);
262 cd.viewCert(parent, cert);
263 }
264
viewSelectedCert
265 function viewSelectedCert()
266 {
267 if (gListBox.selectedItems.length > 0)
268 {
269 var selected = gListBox.selectedIndex;
270 var cert = gCerts.value[selected];
271 if (cert)
272 {
273 viewCertHelper(window, cert);
274 }
275 }
276 }
277
doHelpButton
278 function doHelpButton()
279 {
280 openHelp('compose_security');
281 }
282
createCell
283 function createCell(label)
284 {
285 var cell = document.createElement("listcell");
286 cell.setAttribute("label", label)
287 return cell;
288 }