!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corp..
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s): Kai Engert <kaie@netscape.com>
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38 const nsIPKIParamBlock = Components.interfaces.nsIPKIParamBlock;
39 const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
40 const nsIX509Cert = Components.interfaces.nsIX509Cert;
41 const nsICMSMessageErrors = Components.interfaces.nsICMSMessageErrors;
42 const nsICertificateDialogs = Components.interfaces.nsICertificateDialogs;
43 const nsCertificateDialogs = "@mozilla.org/nsCertificateDialogs;1"
44
45 var gSignerCert = null;
46 var gEncryptionCert = null;
47
48 var gSignatureStatus = -1;
49 var gEncryptionStatus = -1;
50
51 var params = null;
52
setText
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
53 function setText(id, value) {
54 var element = document.getElementById(id);
55 if (!element)
56 return;
57 if (element.hasChildNodes())
58 element.removeChild(element.firstChild);
59 var textNode = document.createTextNode(value);
60 element.appendChild(textNode);
61 }
62
onLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
63 function onLoad()
64 {
65 var pkiParams = window.arguments[0].QueryInterface(nsIPKIParamBlock);
66 var isupport = pkiParams.getISupportAtIndex(1);
67 if (isupport) {
68 gSignerCert = isupport.QueryInterface(nsIX509Cert);
69 }
70 isupport = pkiParams.getISupportAtIndex(2);
71 if (isupport) {
72 gEncryptionCert = isupport.QueryInterface(nsIX509Cert);
73 }
74
75 params = pkiParams.QueryInterface(nsIDialogParamBlock);
76
77 gSignatureStatus = params.GetInt(1);
78 gEncryptionStatus = params.GetInt(2);
79
80 var bundle = document.getElementById("bundle_smime_read_info");
81
82 if (bundle) {
83 var sigInfoLabel = null;
84 var sigInfoHeader = null;
85 var sigInfo = null;
86 var sigInfo_clueless = false;
87
88 switch (gSignatureStatus) {
89 case -1:
90 case nsICMSMessageErrors.VERIFY_NOT_SIGNED:
91 sigInfoLabel = "SINoneLabel";
92 sigInfo = "SINone";
93 break;
94
95 case nsICMSMessageErrors.SUCCESS:
96 sigInfoLabel = "SIValidLabel";
97 sigInfo = "SIValid";
98 break;
99
100
101 case nsICMSMessageErrors.VERIFY_BAD_SIGNATURE:
102 case nsICMSMessageErrors.VERIFY_DIGEST_MISMATCH:
103 sigInfoLabel = "SIInvalidLabel";
104 sigInfoHeader = "SIInvalidHeader";
105 sigInfo = "SIContentAltered";
106 break;
107
108 case nsICMSMessageErrors.VERIFY_UNKNOWN_ALGO:
109 case nsICMSMessageErrors.VERIFY_UNSUPPORTED_ALGO:
110 sigInfoLabel = "SIInvalidLabel";
111 sigInfoHeader = "SIInvalidHeader";
112 sigInfo = "SIInvalidCipher";
113 break;
114
115 case nsICMSMessageErrors.VERIFY_HEADER_MISMATCH:
116 sigInfoLabel = "SIPartiallyValidLabel";
117 sigInfoHeader = "SIPartiallyValidHeader";
118 sigInfo = "SIHeaderMismatch";
119 break;
120
121 case nsICMSMessageErrors.VERIFY_CERT_WITHOUT_ADDRESS:
122 sigInfoLabel = "SIPartiallyValidLabel";
123 sigInfoHeader = "SIPartiallyValidHeader";
124 sigInfo = "SICertWithoutAddress";
125 break;
126
127 case nsICMSMessageErrors.VERIFY_UNTRUSTED:
128 sigInfoLabel = "SIInvalidLabel";
129 sigInfoHeader = "SIInvalidHeader";
130 sigInfo = "SIUntrustedCA";
131 // XXX Need to extend to communicate better errors
132 // might also be:
133 // SIExpired SIRevoked SINotYetValid SIUnknownCA SIExpiredCA SIRevokedCA SINotYetValidCA
134 break;
135
136 case nsICMSMessageErrors.VERIFY_NOT_YET_ATTEMPTED:
137 case nsICMSMessageErrors.GENERAL_ERROR:
138 case nsICMSMessageErrors.VERIFY_NO_CONTENT_INFO:
139 case nsICMSMessageErrors.VERIFY_BAD_DIGEST:
140 case nsICMSMessageErrors.VERIFY_NOCERT:
141 case nsICMSMessageErrors.VERIFY_ERROR_UNVERIFIED:
142 case nsICMSMessageErrors.VERIFY_ERROR_PROCESSING:
143 case nsICMSMessageErrors.VERIFY_MALFORMED_SIGNATURE:
144 sigInfoLabel = "SIInvalidLabel";
145 sigInfoHeader = "SIInvalidHeader";
146 sigInfo_clueless = true;
147 break;
148 }
149
150
151 document.getElementById("signatureLabel").value =
152 bundle.getString(sigInfoLabel);
153
154 var label;
155 if (sigInfoHeader) {
156 label = document.getElementById("signatureHeader");
157 label.collapsed = false;
158 label.value = bundle.getString(sigInfoHeader);
159 }
160
161 var str;
162 if (sigInfo) {
163 str = bundle.getString(sigInfo);
164 }
165 else if (sigInfo_clueless) {
166 str = bundle.getString("SIClueless") + " (" + gSignatureStatus + ")";
167 }
168 setText("signatureExplanation", str);
169
170
171 var encInfoLabel = null;
172 var encInfoHeader = null;
173 var encInfo = null;
174 var encInfo_clueless = false;
175
176 switch (gEncryptionStatus) {
177 case -1:
178 encInfoLabel = "EINoneLabel";
179 encInfo = "EINone";
180 break;
181
182 case nsICMSMessageErrors.SUCCESS:
183 encInfoLabel = "EIValidLabel";
184 encInfo = "EIValid";
185 break;
186
187 case nsICMSMessageErrors.ENCRYPT_INCOMPLETE:
188 encInfoLabel = "EIInvalidLabel";
189 encInfo = "EIContentAltered";
190 break;
191
192 case nsICMSMessageErrors.GENERAL_ERROR:
193 encInfoLabel = "EIInvalidLabel";
194 encInfoHeader = "EIInvalidHeader";
195 encInfo_clueless = 1;
196 break;
197 }
198
199
200 document.getElementById("encryptionLabel").value =
201 bundle.getString(encInfoLabel);
202
203 if (encInfoHeader) {
204 label = document.getElementById("encryptionHeader");
205 label.collapsed = false;
206 label.value = bundle.getString(encInfoHeader);
207 }
208
209 if (encInfo) {
210 str = bundle.getString(encInfo);
211 }
212 else if (encInfo_clueless) {
213 str = bundle.getString("EIClueless");
214 }
215 setText("encryptionExplanation", str);
216 }
217
218 if (gSignerCert) {
219 document.getElementById("signatureCert").collapsed = false;
220 if (gSignerCert.subjectName) {
221 document.getElementById("signedBy").value = gSignerCert.commonName;
222 }
223 if (gSignerCert.emailAddress) {
224 document.getElementById("signerEmail").value = gSignerCert.emailAddress;
225 }
226 if (gSignerCert.issuerName) {
227 document.getElementById("sigCertIssuedBy").value = gSignerCert.issuerCommonName;
228 }
229 }
230
231 if (gEncryptionCert) {
232 document.getElementById("encryptionCert").collapsed = false;
233 if (gEncryptionCert.subjectName) {
234 document.getElementById("encryptedFor").value = gEncryptionCert.commonName;
235 }
236 if (gEncryptionCert.emailAddress) {
237 document.getElementById("recipientEmail").value = gEncryptionCert.emailAddress;
238 }
239 if (gEncryptionCert.issuerName) {
240 document.getElementById("encCertIssuedBy").value = gEncryptionCert.issuerCommonName;
241 }
242 }
243 }
244
viewCertHelper
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
245 function viewCertHelper(parent, cert) {
246 var cd = Components.classes[nsCertificateDialogs].getService(nsICertificateDialogs);
247 cd.viewCert(parent, cert);
248 }
249
viewSignatureCert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
250 function viewSignatureCert()
251 {
252 if (gSignerCert) {
253 viewCertHelper(window, gSignerCert);
254 }
255 }
256
viewEncryptionCert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
257 function viewEncryptionCert()
258 {
259 if (gEncryptionCert) {
260 viewCertHelper(window, gEncryptionCert);
261 }
262 }
263
doHelpButton
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
264 function doHelpButton()
265 {
266 openHelp('received_security');
267 }