~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to mailnews/extensions/enigmail/ui/content/enigmailKeyDetailsDlg.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 * License Version 1.1 (the "MPL"); you may not use this file
 
6
 * except in compliance with the MPL. You may obtain a copy of
 
7
 * the MPL at http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the MPL is distributed on an "AS
 
10
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
11
 * implied. See the MPL for the specific language governing
 
12
 * rights and limitations under the MPL.
 
13
 *
 
14
 * The Original Code is Enigmail.
 
15
 *
 
16
 * The Initial Developer of the Original Code is Patrick Brunschwig.
 
17
 * Portions created by Patrick Brunschwig <patrick@mozilla-enigmail.org> are
 
18
 * Copyright (C) 2007 Patrick Brunschwig. All Rights Reserved.
 
19
 *
 
20
 * Contributor(s):
 
21
 *
 
22
 * Alternatively, the contents of this file may be used under the terms of
 
23
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
24
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
25
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
26
 * of those above. If you wish to allow use of your version of this file only
 
27
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
28
 * use your version of this file under the terms of the MPL, indicate your
 
29
 * decision by deleting the provisions above and replace them with the notice
 
30
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
31
 * the provisions above, a recipient may use your version of this file under
 
32
 * the terms of any one of the MPL, the GPL or the LGPL.
 
33
 * ***** END LICENSE BLOCK ***** */
 
34
 
 
35
 
 
36
EnigInitCommon("enigmailKeyDetailsDlg");
 
37
 
 
38
var gKeyId = null;
 
39
var gUserId = null;
 
40
var gKeyList = null;
 
41
 
 
42
function onLoad() {
 
43
  window.arguments[1].refresh = false;
 
44
 
 
45
  gKeyId = window.arguments[0].keyId;
 
46
  gKeyList = window.arguments[0].keyListArr;
 
47
 
 
48
  reloadData();
 
49
 
 
50
  if (window.arguments[0].secKey) {
 
51
    setAttr("keyType", EnigGetString("keyTypePair"));
 
52
    document.getElementById("ownKeyCommands").removeAttribute("hidden");
 
53
  }
 
54
  else {
 
55
    setAttr("keyType", EnigGetString("keyTypePublic"));
 
56
  }
 
57
}
 
58
 
 
59
function reloadData() {
 
60
  var enigmailSvc = GetEnigmailSvc();
 
61
  if (!enigmailSvc) {
 
62
    EnigAlert(EnigGetString("accessError"));
 
63
    window.close();
 
64
    return;
 
65
  }
 
66
  var exitCodeObj = new Object();
 
67
  var statusFlagsObj = new Object();
 
68
  var errorMsgObj = new Object();
 
69
 
 
70
  gUserId = null;
 
71
 
 
72
  var fingerprint = "";
 
73
  var subKeyLen="";
 
74
  var subAlgo="";
 
75
  var treeChildren = document.getElementById("keyListChildren");
 
76
  var uidList = document.getElementById("uidListChildren");
 
77
 
 
78
  // clean lists
 
79
  while (treeChildren.firstChild) {
 
80
    treeChildren.removeChild(treeChildren.firstChild);
 
81
  }
 
82
  while (uidList.firstChild) {
 
83
    uidList.removeChild(uidList.firstChild);
 
84
  }
 
85
 
 
86
  var sigListStr = enigmailSvc.getKeySig("0x"+gKeyId, exitCodeObj, errorMsgObj);
 
87
  if (exitCodeObj.value == 0) {
 
88
    var sigList = sigListStr.split(/[\n\r]+/);
 
89
    for (var i=0; i < sigList.length; i++) {
 
90
      var aLine=sigList[i].split(/:/);
 
91
      switch (aLine[0]) {
 
92
      case "pub":
 
93
        gUserId=EnigConvertGpgToUnicode(aLine[9]);
 
94
        var calcTrust=aLine[1];
 
95
        if (aLine[11].indexOf("D")>=0) calcTrust="d";
 
96
        calcTrust=getTrustLabel(calcTrust);
 
97
        var ownerTrust=getTrustLabel(aLine[8]);
 
98
        addSubkey(treeChildren, aLine);
 
99
      case "uid":
 
100
        if (! gUserId) {
 
101
          gUserId=EnigConvertGpgToUnicode(aLine[9]);
 
102
        }
 
103
        else {
 
104
          uidList.appendChild(createUidRow(aLine));
 
105
        }
 
106
        break;
 
107
      case "uat":
 
108
        if (aLine[9].search("1 ") == 0) {
 
109
          document.getElementById("showPhoto").removeAttribute("disabled");
 
110
        }
 
111
        break;
 
112
      case "sub":
 
113
        addSubkey(treeChildren, aLine);
 
114
        break;
 
115
      case "fpr":
 
116
        fingerprint = aLine[9];
 
117
        break;
 
118
      }
 
119
    }
 
120
  }
 
121
 
 
122
  setAttr("userId", gUserId);
 
123
  setAttr("keyId", "0x"+ gKeyId.substr(-8,8));
 
124
  setAttr("calcTrust", calcTrust);
 
125
  setAttr("ownerTrust", ownerTrust);
 
126
  if (fingerprint) {
 
127
    setAttr("fingerprint", EnigFormatFpr(fingerprint));
 
128
  }
 
129
}
 
130
 
 
131
function createUidRow(aLine) {
 
132
  var treeItem = document.createElement("treeitem");
 
133
  var treeRow = document.createElement("treerow");
 
134
  var uidCol = createCell(EnigConvertGpgToUnicode(aLine[9]));
 
135
  var validCol = createCell(getTrustLabel(aLine[1]));
 
136
  if ("dre".search(aLine[1]) >= 0) {
 
137
    uidCol.setAttribute("properties", "enigKeyInactive");
 
138
    validCol.setAttribute("properties", "enigKeyInactive");
 
139
  }
 
140
  treeRow.appendChild(uidCol);
 
141
  treeRow.appendChild(validCol);
 
142
  treeItem.appendChild(treeRow);
 
143
  return treeItem;
 
144
}
 
145
 
 
146
function addSubkey(treeChildren, aLine) {
 
147
  var aRow=document.createElement("treerow");
 
148
  var treeItem=document.createElement("treeitem");
 
149
  var subkey=EnigGetString(aLine[0]=="sub" ? "keyTypeSubkey" : "keyTypePrimary");
 
150
  aRow.appendChild(createCell(subkey)); // subkey type
 
151
  aRow.appendChild(createCell("0x"+aLine[4].substr(-8,8))); // key id
 
152
  aRow.appendChild(createCell(EnigGetString("keyAlgorithm_"+aLine[3]))); // algorithm
 
153
  aRow.appendChild(createCell(aLine[2])); // size
 
154
  aRow.appendChild(createCell(EnigGetDateTime(aLine[5], true, false))); // created
 
155
  var expire=(aLine[6].length==0 ? EnigGetString("keyExpiryNever") : EnigGetDateTime(aLine[6], true, false));
 
156
  if (aLine[1]=="r") {
 
157
    expire = EnigGetString("keyValid.revoked");
 
158
  }
 
159
  aRow.appendChild(createCell(expire)); // expiry
 
160
  var usagecodes=aLine[11];
 
161
  var usagetext = "";
 
162
/*  e = encrypt
 
163
    s = sign
 
164
    c = certify
 
165
    a = authentication
 
166
    Capital Letters are ignored, as these reflect summary properties of a key
 
167
*/
 
168
  var singlecode = "";
 
169
  for (i=0; i < aLine[11].length; i++)
 
170
  {
 
171
    singlecode = aLine[11].substr(i, 1);
 
172
    switch (singlecode)
 
173
    {
 
174
    case "e":
 
175
      if (usagetext.length>0)
 
176
      {
 
177
        usagetext = usagetext + ", ";
 
178
      }
 
179
      usagetext = usagetext + EnigGetString("keyUsageEncrypt");
 
180
      break;
 
181
    case "s":
 
182
      if (usagetext.length>0)
 
183
      {
 
184
        usagetext = usagetext + ", ";
 
185
      }
 
186
      usagetext = usagetext + EnigGetString("keyUsageSign");
 
187
      break;
 
188
    case "c":
 
189
      if (usagetext.length>0)
 
190
      {
 
191
        usagetext = usagetext + ", ";
 
192
      }
 
193
      usagetext = usagetext + EnigGetString("keyUsageCertify");
 
194
      break;
 
195
    case "a":
 
196
      if (usagetext.length>0)
 
197
      {
 
198
        usagetext = usagetext + ", ";
 
199
      }
 
200
      usagetext = usagetext + EnigGetString("keyUsageAuthentication");
 
201
      break;
 
202
    } /* case */
 
203
  } /* for */
 
204
 
 
205
  aRow.appendChild(createCell(usagetext)); // usage
 
206
  treeItem.appendChild(aRow);
 
207
  treeChildren.appendChild(treeItem);
 
208
}
 
209
 
 
210
function createCell(label) {
 
211
  var cell = document.createElement("treecell");
 
212
  cell.setAttribute("label", label);
 
213
  return cell;
 
214
}
 
215
 
 
216
function getTrustLabel(trustCode) {
 
217
  var trustTxt=EnigGetTrustLabel(trustCode);
 
218
  if (trustTxt=="-" || trustTxt.length==0) {
 
219
    trustTxt=EnigGetString("keyValid.unknown");
 
220
  }
 
221
  return trustTxt;
 
222
}
 
223
 
 
224
function setAttr(attribute, value) {
 
225
  var elem = document.getElementById(attribute);
 
226
  if (elem) {
 
227
    elem.value = value;
 
228
  }
 
229
}
 
230
 
 
231
function enableRefresh() {
 
232
  window.arguments[1].refresh = true;
 
233
}
 
234
 
 
235
// ------------------ onCommand Functions  -----------------
 
236
 
 
237
function showPhoto() {
 
238
  EnigShowPhoto(gKeyId, gUserId, 0);
 
239
}
 
240
 
 
241
function viewSignatures() {
 
242
  var inputObj = {
 
243
    keyId: gKeyId,
 
244
    keyListArr: gKeyList
 
245
  };
 
246
  var resultObj = {refresh: false};
 
247
 
 
248
  window.openDialog("chrome://enigmail/content/enigmailViewKeySigDlg.xul",
 
249
        "", "dialog,modal,centerscreen,resizable=yes", inputObj, resultObj);
 
250
 
 
251
  if (resultObj.refresh) {
 
252
    enableRefresh();
 
253
    reloadData();
 
254
  }
 
255
 
 
256
}
 
257
 
 
258
function keyDetailsAddPhoto() {
 
259
  keyMgrAddPhoto(gUserId, gKeyId);
 
260
}
 
261
 
 
262
function signKey() {
 
263
  if (EnigSignKey(gUserId, gKeyId, null)) {
 
264
    enableRefresh();
 
265
    reloadData();
 
266
  }
 
267
}
 
268
 
 
269
function setOwnerTrust() {
 
270
 
 
271
  if (EnigEditKeyTrust([gUserId], [gKeyId])) {
 
272
    enableRefresh();
 
273
    reloadData();
 
274
  }
 
275
}
 
276
 
 
277
function manageUids() {
 
278
  var inputObj = {
 
279
    keyId: gKeyId,
 
280
    ownKey: window.arguments[0].secKey
 
281
  };
 
282
 
 
283
  var resultObj = {refresh: false};
 
284
  window.openDialog("chrome://enigmail/content/enigmailManageUidDlg.xul",
 
285
        "", "dialog,modal,centerscreen,resizable=yes", inputObj, resultObj);
 
286
  if (resultObj.refresh) {
 
287
    enableRefresh();
 
288
    reloadData();
 
289
  }
 
290
}
 
291
 
 
292
function changePassword() {
 
293
  EnigChangeKeyPwd(gKeyId, gUserId);
 
294
}
 
295
 
 
296
function revokeKey() {
 
297
  EnigRevokeKey(gKeyId, gUserId, function _revokeKeyCb(success) {
 
298
    if (success) {
 
299
      enableRefresh();
 
300
      reloadData();
 
301
    }
 
302
  });
 
303
}
 
304
 
 
305
function genRevocationCert() {
 
306
  EnigCreateRevokeCert(gKeyId, gUserId);
 
307
}