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

« back to all changes in this revision

Viewing changes to mailnews/extensions/enigmail/ui/content/enigmailGenCardKey.xul

  • 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
<?xml version="1.0"?>
 
2
<!--
 
3
 * ***** BEGIN LICENSE BLOCK *****
 
4
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
5
 *
 
6
 * The contents of this file are subject to the Mozilla Public
 
7
 * License Version 1.1 (the "MPL"); you may not use this file
 
8
 * except in compliance with the MPL. You may obtain a copy of
 
9
 * the MPL at http://www.mozilla.org/MPL/
 
10
 *
 
11
 * Software distributed under the MPL is distributed on an "AS
 
12
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
13
 * implied. See the MPL for the specific language governing
 
14
 * rights and limitations under the MPL.
 
15
 *
 
16
 * The Original Code is Enigmail.
 
17
 *
 
18
 * The Initial Developer of the Original Code is Patrick Brunschwig.
 
19
 * Portions created by Patrick Brunschwig <patrick@mozilla-enigmail.org> are
 
20
 * Copyright (C) 2005 Patrick Brunschwig. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
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
 * ***** END LICENSE BLOCK ***** *
 
36
-->
 
37
 
 
38
 
 
39
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
 
40
<?xml-stylesheet href="chrome://enigmail/skin/enigmail.css" type="text/css"?>
 
41
 
 
42
<!DOCTYPE window [
 
43
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
 
44
%brandDTD;
 
45
<!ENTITY % enigMailDTD SYSTEM "chrome://enigmail/locale/enigmail.dtd" >
 
46
%enigMailDTD;
 
47
]>
 
48
 
 
49
<window id="enigmailGenCardKeyDlg"
 
50
        title="&enigmail.genCardKey.title;"
 
51
        windowtype="enigmail:genCardKey"
 
52
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
 
53
        onload="onLoad()"
 
54
        buttons="accept,cancel"
 
55
        minwidth="450px"
 
56
        maxwidth="600px">
 
57
 
 
58
  <script type="application/x-javascript" src="chrome://enigmail/content/enigmailCommon.js"/>
 
59
  <script type="application/x-javascript" src="chrome://enigmail/content/enigmailKeygen.js"/>
 
60
 
 
61
  <broadcasterset>
 
62
    <broadcaster id="bcBackupKey"/>
 
63
    <broadcaster id="bcNoExpiry"/>
 
64
  </broadcasterset>
 
65
 
 
66
  <popupset id="aTooltipSet"/>
 
67
 
 
68
  <groupbox id="userIdBox" orient="vertical">
 
69
 
 
70
    <hbox orient="horizontal" align="center">
 
71
      <label value="&enigmail.keyUserId.label;" control="userIdentity"/>
 
72
      <menulist id="userIdentity" label="..." flex="1">
 
73
        <menupopup id="userIdentityPopup"/>
 
74
      </menulist>
 
75
    </hbox>
 
76
 
 
77
    <checkbox id="useForSigning"
 
78
              label="&enigmail.useForSigning.label;"
 
79
              checked="true" />
 
80
 
 
81
  </groupbox>
 
82
 
 
83
  <checkbox id="createBackup"
 
84
            label="&enigmail.genCardKey.backupKey.label;"
 
85
            checked="true"
 
86
            oncommand="enableDisable('createBackup','bcBackupKey', false)"/>
 
87
  <grid>
 
88
    <columns>
 
89
      <column />
 
90
      <column flex="1"/>
 
91
    </columns>
 
92
 
 
93
    <rows>
 
94
      <row>
 
95
        <hbox id="passphraseBox" align="center">
 
96
          <label control="passphrase" value="&enigmail.keyPassphrase.label;" />
 
97
        </hbox>
 
98
        <hbox align="center">
 
99
          <textbox id="passphrase" type="password" observes="bcBackupKey"/>
 
100
          <label control="passphraseRepeat" value="&enigmail.keyPassphraseRepeat.label;" />
 
101
          <textbox id="passphraseRepeat" type="password" observes="bcBackupKey"/>
 
102
        </hbox>
 
103
      </row>
 
104
 
 
105
      <row>
 
106
        <hbox align="center">
 
107
          <label control="keyComment" value="&enigmail.keyComment.label;" />
 
108
        </hbox>
 
109
        <textbox id="keyComment" />
 
110
      </row>
 
111
 
 
112
      <row>
 
113
        <hbox align="center">
 
114
          <label value="&enigmail.keyGen.expire.label;" control="expireInput"/>
 
115
        </hbox>
 
116
        <hbox align="center">
 
117
          <textbox id="expireInput" size="5" maxlength="5" value="5" observes="bcNoExpiry"/>
 
118
          <menulist id="timeScale" label="&enigmail.keyGen.years.label;" value="365"  observes="bcNoExpiry">
 
119
            <menupopup id="timeScalePopup" value="5">
 
120
              <menuitem id="years" value="y" label="&enigmail.keyGen.years.label;" selected="true"/>
 
121
              <menuitem id="months" value="m" label="&enigmail.keyGen.months.label;"/>
 
122
              <menuitem id="days" value="d" label="&enigmail.keyGen.days.label;"/>
 
123
            </menupopup>
 
124
          </menulist>
 
125
          <checkbox label="&enigmail.keyGen.noExpiry.label;"
 
126
                    id="noExpiry"
 
127
                    oncommand="enableDisable('noExpiry','bcNoExpiry', true)"/>
 
128
        </hbox>
 
129
      </row>
 
130
 
 
131
    </rows>
 
132
  </grid>
 
133
 
 
134
  <separator/>
 
135
 
 
136
<hbox autostretch="never">
 
137
  <button label="&enigmail.generateKey.label;"
 
138
          class="dialog"
 
139
          tooltip="aTooltip"
 
140
          tooltiptext="&enigmail.generateKey.tooltip;"
 
141
          oncommand="startKeyGen();" />
 
142
 
 
143
  <button label="&enigmail.cancelKey.label;"
 
144
          class="dialog"
 
145
          tooltip="aTooltip"
 
146
          tooltiptext="&enigmail.cancelKey.tooltip;"
 
147
          oncommand="onClose();" />
 
148
</hbox>
 
149
 
 
150
<groupbox id="keygenConsoleBox" orient="vertical">
 
151
 
 
152
  <caption label="&enigmail.keyGen.console.label;"/>
 
153
 
 
154
  <description>&enigmail.genCardKey.desc;</description>
 
155
 
 
156
  <iframe id="keygenConsole" type="content" name="keygenConsole"
 
157
          src="chrome://enigmail/content/enigmailKeygenConsole.htm"
 
158
          height="200" flex="1"/>
 
159
 
 
160
</groupbox>
 
161
 
 
162
 
 
163
  <script type="application/x-javascript">
 
164
  <![CDATA[
 
165
    Components.utils.import("resource://enigmail/commonFuncs.jsm");
 
166
    Components.utils.import("resource://enigmail/enigmailCommon.jsm");
 
167
    Components.utils.import("resource://enigmail/keyManagement.jsm");
 
168
 
 
169
    // Ec is predefined by enigmailCommon.js
 
170
 
 
171
    var gIdentityList;
 
172
    var gIdentityListPopup;
 
173
    var gUseForSigning;
 
174
    var gUsedId;
 
175
 
 
176
    function onLoad() {
 
177
      gIdentityList      = document.getElementById("userIdentity");
 
178
      gIdentityListPopup = document.getElementById("userIdentityPopup");
 
179
      gUseForSigning     = document.getElementById("useForSigning");
 
180
      //document.getElementById("bcNoExpiry")
 
181
      if (gIdentityListPopup) {
 
182
        fillIdentityListPopup();
 
183
      }
 
184
    }
 
185
 
 
186
    function onClose() {
 
187
      window.close();
 
188
    }
 
189
 
 
190
    function enableDisable(watchElement, bcElement, inverted) {
 
191
      var bcBackupKey = document.getElementById(bcElement);
 
192
 
 
193
      if (document.getElementById(watchElement).checked) {
 
194
        if (inverted) {
 
195
          bcBackupKey.setAttribute("disabled", "true");
 
196
        }
 
197
        else {
 
198
         bcBackupKey.removeAttribute("disabled");
 
199
        }
 
200
      }
 
201
      else {
 
202
        if (inverted) {
 
203
          bcBackupKey.removeAttribute("disabled");
 
204
        }
 
205
        else {
 
206
          bcBackupKey.setAttribute("disabled", "true");
 
207
        }
 
208
      }
 
209
    }
 
210
 
 
211
    function enigGenKeyObserver() {
 
212
      this._state = 0;
 
213
    }
 
214
 
 
215
    enigGenKeyObserver.prototype =
 
216
    {
 
217
      keyId: null,
 
218
      backupLocation: null,
 
219
      _state: null,
 
220
 
 
221
      QueryInterface : function(iid)
 
222
      {
 
223
        //DEBUG_LOG("enigmailGenCardKey: EnigMimeReadCallback.QI: "+iid+"\n");
 
224
        if (iid.equals(Components.interfaces.nsIEnigMimeReadCallback) ||
 
225
            iid.equals(Components.interfaces.nsISupports) )
 
226
          return this;
 
227
 
 
228
        throw Components.results.NS_NOINTERFACE;
 
229
      },
 
230
 
 
231
      onDataAvailable: function (data) {
 
232
        var txt = "";
 
233
        var aLine = data.split(/ +/);
 
234
        if (aLine[0] == "[GNUPG:]") {
 
235
         if (aLine[1]=="GET_LINE" && aLine[2]=="keygen.comment") {
 
236
            txt=Ec.getString("keygen.started")+"\n";
 
237
            this._state=1;
 
238
          }
 
239
          else if (aLine[1]=="PROGRESS" && aLine[2]=="primegen") {
 
240
            txt = aLine[3];
 
241
          }
 
242
          else if (aLine[1] == "BACKUP_KEY_CREATED") {
 
243
            this.backupLocation = data.replace(/^.*BACKUP_KEY_CREATED [A-Z0-9]+ +/, "");
 
244
          }
 
245
          else if (aLine[1] == "KEY_CREATED") {
 
246
            this.keyId = aLine[3].substr(-16);
 
247
          }
 
248
        }
 
249
        else if (this._state>0) {
 
250
          txt=data+"\n";
 
251
        }
 
252
        if (txt) {
 
253
          var contentFrame = Ec.getFrame(window, "keygenConsole");
 
254
          if (contentFrame) {
 
255
            var consoleElement = contentFrame.document.getElementById('console');
 
256
            consoleElement.firstChild.data += txt;
 
257
            if (!contentFrame.mouseDownState)
 
258
              contentFrame.scrollTo(0,9999);
 
259
          }
 
260
        }
 
261
        return "";
 
262
      }
 
263
    }
 
264
 
 
265
    function startKeyGen() {
 
266
      DEBUG_LOG("enigmailGenCardKey: startKeyGen(): Start\n");
 
267
 
 
268
      var enigmailSvc = Ec.getService(window);
 
269
      if (!enigmailSvc) {
 
270
        Ec.alert(window,Ec.getString("accessError"));
 
271
        return;
 
272
      }
 
273
 
 
274
      var passphraseElement = document.getElementById("passphrase");
 
275
      var passphrase2Element = document.getElementById("passphraseRepeat");
 
276
      var createBackupElement = document.getElementById("createBackup");
 
277
 
 
278
      var passphrase = passphraseElement.value;
 
279
 
 
280
      if (!createBackupElement.checked) {
 
281
        passphrase="";
 
282
      }
 
283
      else {
 
284
        if (passphrase != passphrase2Element.value) {
 
285
          Ec.alert(window,Ec.getString("passNoMatch"));
 
286
          return;
 
287
        }
 
288
 
 
289
        if (passphrase.search(/[\x80-\xFF]/)>=0) {
 
290
          Ec.alert(window,Ec.getString("passCharProblem"));
 
291
          return;
 
292
        }
 
293
 
 
294
        if (!passphrase) {
 
295
          Ec.alert(window,Ec.getString("keygen.passRequired"));
 
296
          return;
 
297
        }
 
298
      }
 
299
 
 
300
      var commentElement = document.getElementById("keyComment");
 
301
      var comment = commentElement.value;
 
302
 
 
303
      var noExpiry = document.getElementById("noExpiry");
 
304
      var expireInput = document.getElementById("expireInput");
 
305
      var timeScale = document.getElementById("timeScale");
 
306
 
 
307
      var expiryTime = 0;
 
308
      var valid = "0";
 
309
      if (! noExpiry.checked) {
 
310
        expiryTime = Number(expireInput.value) * (timeScale.value == "y" ? 365 : (timeScale.value == "m" ? 30 : 1));
 
311
        if (expiryTime > 36500) {
 
312
          Ec.alert(window,Ec.getString("expiryTooLong"));
 
313
          return;
 
314
        }
 
315
        if (! (expiryTime > 0)) {
 
316
          Ec.alert(window,Ec.getString("expiryTooShort"));
 
317
          return;
 
318
        }
 
319
        valid = String(Number(expireInput.value));
 
320
        if (timeScale.value != "d") valid += timeScale.value;
 
321
      }
 
322
      var curId = getCurrentIdentity();
 
323
      gUsedId = curId;
 
324
 
 
325
      var userName = curId.fullName;
 
326
      var userEmail = curId.email;
 
327
 
 
328
      if (!userName) {
 
329
        Ec.alert(window,Ec.getString("passUserName"));
 
330
        return;
 
331
      }
 
332
 
 
333
      var idString = userName;
 
334
 
 
335
      if (comment)
 
336
        idString += " (" + comment + ")";
 
337
 
 
338
      idString += " <" + userEmail + ">";
 
339
 
 
340
      var confirmMsg = Ec.getString("keyConfirm",idString);
 
341
 
 
342
      if (!EnigConfirm(confirmMsg, Ec.getString("keyMan.button.generateKey"))) {
 
343
       return;
 
344
      }
 
345
      var contentFrame = Ec.getFrame(window, "keygenConsole");
 
346
      if (contentFrame) {
 
347
        var consoleElement = contentFrame.document.getElementById('console');
 
348
        consoleElement.firstChild.data = "";
 
349
      }
 
350
 
 
351
      var generateObserver = new enigGenKeyObserver();
 
352
      EnigmailKeyMgmt.genCardKey(window,
 
353
                               userName,
 
354
                               userEmail,
 
355
                               comment,
 
356
                               valid,
 
357
                               passphrase,
 
358
                               generateObserver,
 
359
        function _keyGenCb(exitCode, errorMsg) {
 
360
          if (exitCode == 0 && generateObserver.keyId) {
 
361
            if (document.getElementById("useForSigning").checked && generateObserver.keyId) {
 
362
              gUsedId.setBoolAttribute("enablePgp", true);
 
363
              gUsedId.setIntAttribute("pgpKeyMode", 1);
 
364
              gUsedId.setCharAttribute("pgpkeyId", "0x"+generateObserver.keyId.substr(-8,8));
 
365
            }
 
366
            var msg=Ec.getString("keygen.completed", generateObserver.keyId);
 
367
            if (generateObserver.backupLocation) {
 
368
              msg += "\n"+Ec.getString("keygen.keyBackup", generateObserver.backupLocation);
 
369
            }
 
370
            if (Ec.confirmDlg(window, msg+"\n\n"+Ec.getString("revokeCertRecommended"), Ec.getString("keyMan.button.generateCert"))) {
 
371
              EnigCreateRevokeCert(generateObserver.keyId, curId.email, closeWin);
 
372
            }
 
373
            else
 
374
              closeWin();
 
375
          }
 
376
          else {
 
377
            Ec.alert(window, errorMsg);
 
378
          }
 
379
        });
 
380
    }
 
381
 
 
382
    function closeWin() {
 
383
      window.close();
 
384
    }
 
385
 
 
386
  ]]>
 
387
  </script>
 
388
 
 
389
</window>
 
390