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

« back to all changes in this revision

Viewing changes to extensions/enigmail/package/keyManagement.jsm

  • 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) 2012 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
 
Components.utils.import("resource://enigmail/enigmailCommon.jsm");
37
 
Components.utils.import("resource://enigmail/subprocess.jsm");
38
 
 
39
 
var EXPORTED_SYMBOLS = [ "EnigmailKeyMgmt" ];
40
 
 
41
 
const Ec = EnigmailCommon;
42
 
const Cc = Components.classes;
43
 
const Ci = Components.interfaces;
44
 
 
45
 
const GET_BOOL = "GET_BOOL";
46
 
const GET_LINE = "GET_LINE";
47
 
const GET_HIDDEN = "GET_HIDDEN";
48
 
 
49
 
 
50
 
function KeyEditor(reqObserver, callbackFunc, inputData) {
51
 
  this._reqObserver = reqObserver;
52
 
  this._callbackFunc = callbackFunc;
53
 
  this._inputData = inputData;
54
 
 
55
 
  if (this._inputData && this._inputData.cardAdmin) {
56
 
    this._saveCmd = "quit";
57
 
  }
58
 
  else
59
 
    this._saveCmd = "save";
60
 
}
61
 
 
62
 
KeyEditor.prototype = {
63
 
  _stdin: null,
64
 
  _data: "",
65
 
  _txt: "",
66
 
  _exitCode: 0,
67
 
  errorMsg: "",
68
 
 
69
 
  setStdin: function(pipe) {
70
 
    this._stdin = pipe;
71
 
    if (this._data.length > 0) this.processData();
72
 
  },
73
 
 
74
 
  gotData: function(data) {
75
 
    //Ec.DEBUG_LOG("keyManagement.jsm: KeyEditor.gotData: '"+data+"'\n");
76
 
    this._data += data.replace(/\r\n/g, "\n");
77
 
    this.processData();
78
 
  },
79
 
 
80
 
  processData: function() {
81
 
    //Ec.DEBUG_LOG("keyManagement.jsm: KeyEditor.processData\n");
82
 
    var txt = "";
83
 
    while (this._data.length > 0 && this._stdin) {
84
 
      var index = this._data.indexOf("\n");
85
 
      if (index < 0) {
86
 
        txt = this._data;
87
 
        this._data = "";
88
 
      }
89
 
      else {
90
 
        txt = this._data.substr(0, index);
91
 
        this._data = this._data.substr(index+1);
92
 
      }
93
 
      this.nextLine(txt);
94
 
    }
95
 
  },
96
 
 
97
 
  closeStdin: function() {
98
 
    Ec.DEBUG_LOG("keyManagement.jsm: KeyEditor.closeStdin:\n");
99
 
    if (this._stdin) {
100
 
      this._stdin.close();
101
 
      this._stdin = null;
102
 
    }
103
 
  },
104
 
 
105
 
  done: function(parentCallback, exitCode) {
106
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.done: exitCode="+exitCode+"\n");
107
 
 
108
 
    if (exitCode == 0) exitCode = this._exitCode;
109
 
 
110
 
    if (exitCode == 0 && typeof(this._inputData) == "object" && this._inputData.usePassphrase) {
111
 
      Ec.stillActive();
112
 
    }
113
 
 
114
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.done: returning exitCode "+exitCode+"\n");
115
 
 
116
 
    parentCallback(exitCode, this.errorMsg);
117
 
  },
118
 
 
119
 
  writeLine: function (inputData) {
120
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.writeLine: '"+inputData+"'\n");
121
 
    this._stdin.write(inputData+"\n");
122
 
  },
123
 
 
124
 
  nextLine: function(txt) {
125
 
    if (txt.indexOf("[GNUPG:]") >= 0) {
126
 
      if (this._reqObserver) {
127
 
        var newTxt = this._reqObserver.onDataAvailable(txt);
128
 
        if (newTxt.length > 0) {
129
 
 
130
 
          txt = newTxt;
131
 
        }
132
 
      }
133
 
      this._txt = txt;
134
 
      this.processLine(txt);
135
 
    }
136
 
  },
137
 
 
138
 
  doCheck: function(inputType, promptVal) {
139
 
    var a=this._txt.split(/ /);
140
 
    return ((a[1] == inputType) && (a[2] == promptVal))
141
 
  },
142
 
 
143
 
  getText: function() {
144
 
    return this._txt;
145
 
  },
146
 
 
147
 
  processLine: function(txt) {
148
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.processLine: '"+txt+"'\n");
149
 
    var r = { quitNow: false,
150
 
              exitCode: -1 };
151
 
 
152
 
    try {
153
 
      if (txt.indexOf("[GNUPG:] BAD_PASSPHRASE")>=0 ||
154
 
          txt.indexOf("[GNUPG:] SC_OP_FAILURE 2") >= 0) {
155
 
        Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.processLine: detected bad passphrase\n");
156
 
        r.exitCode=-2;
157
 
        r.quitNow=true;
158
 
        this.errorMsg=Ec.getString("badPhrase");
159
 
        Ec.clearCachedPassphrase();
160
 
      }
161
 
      if (txt.indexOf("[GNUPG:] NO_CARD_AVAILABLE")>=0) {
162
 
        Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.processLine: detected missing card\n");
163
 
        this.errorMsg=Ec.getString("noCardAvailable");
164
 
        r.exitCode=-3;
165
 
        r.quitNow=true;
166
 
      }
167
 
      if (txt.indexOf("[GNUPG:] ENIGMAIL_FAILURE")==0) {
168
 
        Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.processLine: detected general failure\n");
169
 
        r.exitCode = -3;
170
 
        r.quitNow = true;
171
 
        this.errorMsg = txt.substr(26);
172
 
      }
173
 
      if (txt.indexOf("[GNUPG:] ALREADY_SIGNED")>=0) {
174
 
        Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.processLine: detected key already signed\n");
175
 
        this.errorMsg=Ec.getString("keyAlreadySigned");
176
 
        r.exitCode=-1;
177
 
        r.quitNow = true;
178
 
      }
179
 
      if (txt.indexOf("[GNUPG:] GET_") < 0) {
180
 
        // return if no "GET" statement
181
 
        return;
182
 
      }
183
 
    }
184
 
    catch (ex) {
185
 
      txt="";
186
 
      r.quitNow=true;
187
 
    }
188
 
 
189
 
    if (! r.quitNow) {
190
 
      if (txt.indexOf("[GNUPG:] GOT_IT") < 0) {
191
 
        if (this._callbackFunc) {
192
 
          this._callbackFunc(this._inputData, this, r);
193
 
          if (r.exitCode == 0) {
194
 
            this.writeLine(r.writeTxt);
195
 
          }
196
 
          else {
197
 
            if (r.errorMsg && r.errorMsg.length > 0)
198
 
              this.errorMsg = r.errorMsg;
199
 
          }
200
 
        }
201
 
        else {
202
 
          r.quitNow=true;
203
 
          r.exitCode = 0;
204
 
        }
205
 
      }
206
 
      else {
207
 
        r.exitCode = 0;
208
 
      }
209
 
    }
210
 
 
211
 
    if (r.quitNow) {
212
 
      try {
213
 
        this.writeLine(this._saveCmd);
214
 
        this.closeStdin();
215
 
      }
216
 
      catch (ex) {
217
 
        Ec.DEBUG_LOG("no more data\n");
218
 
      }
219
 
    }
220
 
 
221
 
    if (r.exitCode != null)
222
 
      this._exitCode = r.exitCode;
223
 
  },
224
 
 
225
 
  QueryInterface: function (iid) {
226
 
    if (!iid.equals(Ci.nsISupports))
227
 
         throw Components.results.NS_ERROR_NO_INTERFACE;
228
 
    return this;
229
 
  }
230
 
};
231
 
 
232
 
/*
233
 
 * NOTE: the callbackFunc used in every call to the key editor needs to be implemented like this:
234
 
 * callbackFunc(returnCode, errorMsg)
235
 
 * returnCode = 0 in case of success
236
 
 * returnCode != 0 and errorMsg set in case of failure
237
 
*/
238
 
 
239
 
var EnigmailKeyMgmt = {
240
 
 
241
 
  editKey: function (parent, needPassphrase, userId, keyId, editCmd, inputData, callbackFunc, requestObserver, parentCallback) {
242
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: editKey: parent="+parent+", editCmd="+editCmd+"\n");
243
 
 
244
 
    var enigmailSvc = Ec.getService(parent);
245
 
    if (!enigmailSvc) {
246
 
      Ec.ERROR_LOG("keyManagmenent.jsm: Enigmail.editKey: not yet initialized\n");
247
 
      parentCallback(-1, Ec.getString("notInit"));
248
 
      return -1;
249
 
    }
250
 
 
251
 
    var keyIdList = keyId.split(" ");
252
 
    var args = Ec.getAgentArgs(false);
253
 
 
254
 
    var statusFlags = new Object();
255
 
 
256
 
    var passphrase = "";
257
 
    var useAgentObj = new Object();
258
 
 
259
 
    if (needPassphrase) {
260
 
      args=args.concat(Ec.passwdCommand());
261
 
 
262
 
      var passwdObj = new Object();
263
 
 
264
 
      if (!Ec.getPassphrase(parent, passwdObj, useAgentObj, 0)) {
265
 
         Ec.ERROR_LOG("keyManagmenent.jsm: editKey: Error - no passphrase supplied\n");
266
 
 
267
 
         parentCallback(-1, Ec.getString("noPassphrase"));
268
 
         return -1;
269
 
      }
270
 
 
271
 
      passphrase = passwdObj.value;
272
 
    }
273
 
    else
274
 
    {
275
 
      useAgentObj.value = true;
276
 
    }
277
 
 
278
 
    args=args.concat(["--no-tty", "--status-fd", "1", "--logger-fd", "1", "--command-fd", "0"]);
279
 
    if (userId) args=args.concat(["-u", userId]);
280
 
    var editCmdArr;
281
 
    if (typeof(editCmd) == "string") {
282
 
      editCmdArr = [ editCmd ];
283
 
    }
284
 
    else {
285
 
      editCmdArr = editCmd;
286
 
    }
287
 
 
288
 
    if (editCmdArr[0] == "revoke") {
289
 
      // escape backslashes and ' characters
290
 
      args=args.concat(["-a", "-o"]);
291
 
      args.push(Ec.getEscapedFilename(inputData.outFile.path));
292
 
      args.push("--gen-revoke");
293
 
      args=args.concat(keyIdList);
294
 
    }
295
 
    else if (editCmdArr[0].indexOf("--")==0) {
296
 
      args=args.concat(editCmd);
297
 
      args=args.concat(keyIdList);
298
 
    }
299
 
    else {
300
 
      args=args.concat(["--ask-cert-level", "--edit-key", keyId]);
301
 
      args=args.concat(editCmd);
302
 
    }
303
 
 
304
 
 
305
 
    var command= enigmailSvc.agentPath;
306
 
    Ec.CONSOLE_LOG("enigmail> "+Ec.printCmdLine(command, args)+"\n");
307
 
 
308
 
    var keyEdit = new KeyEditor(requestObserver, callbackFunc, inputData);
309
 
 
310
 
    try {
311
 
      var proc = subprocess.call({
312
 
        command: command,
313
 
        arguments: args,
314
 
        charset: null,
315
 
        environment: Ec.getEnvList(),
316
 
        stdin: function (stdin) {
317
 
          if (needPassphrase && Ec.requirePassword()) {
318
 
            stdin.write(passphrase+"\n");
319
 
          }
320
 
          keyEdit.setStdin(stdin);
321
 
        },
322
 
        stdout: function(data) {
323
 
          keyEdit.gotData(data);
324
 
        },
325
 
        done: function(result) {
326
 
          Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.editKey: GnuPG terminated with code="+result.exitCode+"\n");
327
 
          keyEdit.done(parentCallback, result.exitCode);
328
 
        },
329
 
        mergeStderr: false,
330
 
      });
331
 
    } catch (ex) {
332
 
      Ec.ERROR_LOG("keyManagement.jsm: editKey: "+command.path+" failed\n");
333
 
      parentCallback(-1, "");
334
 
    }
335
 
  },
336
 
 
337
 
  setKeyTrust: function (parent, keyId, trustLevel, callbackFunc) {
338
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.setKeyTrust: trustLevel="+trustLevel+", keyId="+keyId+"\n");
339
 
 
340
 
    return this.editKey(parent, false, null, keyId, "trust",
341
 
                        { trustLevel: trustLevel},
342
 
                        keyTrustCallback,
343
 
                        null,
344
 
                        callbackFunc);
345
 
  },
346
 
 
347
 
  signKey: function (parent, userId, keyId, signLocally, trustLevel, callbackFunc) {
348
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.signKey: trustLevel="+trustLevel+", userId="+userId+", keyId="+keyId+"\n");
349
 
    return this.editKey(parent, true, userId, keyId,
350
 
                        (signLocally ? "lsign" : "sign"),
351
 
                        { trustLevel: trustLevel,
352
 
                          usePassphrase: true },
353
 
                        signKeyCallback,
354
 
                        null,
355
 
                        callbackFunc);
356
 
  },
357
 
 
358
 
  genRevokeCert: function (parent, keyId, outFile, reasonCode, reasonText, callbackFunc) {
359
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.genRevokeCert: keyId="+keyId+"\n");
360
 
 
361
 
    var r= this.editKey(parent, true, null, keyId, "revoke",
362
 
                        { outFile: outFile,
363
 
                          reasonCode: reasonCode,
364
 
                          reasonText: Ec.convertFromUnicode(reasonText),
365
 
                          usePassphrase: true },
366
 
                        revokeCertCallback,
367
 
                        null,
368
 
                        callbackFunc);
369
 
    return r;
370
 
  },
371
 
 
372
 
  addUid: function (parent, keyId, name, email, comment, callbackFunc) {
373
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.addUid: keyId="+keyId+", name="+name+", email="+email+"\n");
374
 
    var r= this.editKey(parent, true, null, keyId, "adduid",
375
 
                        { email: email,
376
 
                          name: name,
377
 
                          comment: comment,
378
 
                          nameAsked: 0,
379
 
                          emailAsked: 0,
380
 
                          usePassphrase: true },
381
 
                        addUidCallback,
382
 
                        null,
383
 
                        callbackFunc);
384
 
    return r;
385
 
  },
386
 
 
387
 
  deleteKey: function (parent, keyId, deleteSecretKey, callbackFunc) {
388
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.addUid: keyId="+keyId+", deleteSecretKey="+deleteSecretKey+"\n");
389
 
 
390
 
    var cmd = (deleteSecretKey ? "--delete-secret-and-public-key" : "--delete-key");
391
 
    var r= this.editKey(parent, false, null, keyId, cmd,
392
 
                        { usePassphrase: true },
393
 
                        deleteKeyCallback,
394
 
                        null,
395
 
                        callbackFunc);
396
 
    return r;
397
 
  },
398
 
 
399
 
  changePassphrase: function (parent, keyId, oldPw, newPw, callbackFunc) {
400
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.changePassphrase: keyId="+keyId+"\n");
401
 
 
402
 
    var pwdObserver = new ChangePasswdObserver();
403
 
    var r= this.editKey(parent, false, null, keyId, "passwd",
404
 
                        { oldPw: oldPw,
405
 
                          newPw: newPw,
406
 
                          useAgent: Ec.enigmailSvc.useGpgAgent(),
407
 
                          step: 0,
408
 
                          observer: pwdObserver,
409
 
                          usePassphrase: true },
410
 
                        changePassphraseCallback,
411
 
                        pwdObserver,
412
 
                        callbackFunc);
413
 
    return r;
414
 
  },
415
 
 
416
 
 
417
 
  enableDisableKey: function (parent, keyId, disableKey, callbackFunc) {
418
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.enableDisableKey: keyId="+keyId+", disableKey="+disableKey+"\n");
419
 
 
420
 
    var cmd = (disableKey ? "disable" : "enable");
421
 
    var r= this.editKey(parent, false, null, keyId, cmd,
422
 
                        { usePassphrase: true },
423
 
                        null,
424
 
                        null,
425
 
                        callbackFunc);
426
 
    return r;
427
 
  },
428
 
 
429
 
  setPrimaryUid: function (parent, keyId, idNumber, callbackFunc) {
430
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.setPrimaryUid: keyId="+keyId+", idNumber="+idNumber+"\n");
431
 
    var r = this.editKey(parent, true, null, keyId, "",
432
 
                        { idNumber: idNumber,
433
 
                          step: 0,
434
 
                          usePassphrase: true },
435
 
                        setPrimaryUidCallback,
436
 
                        null,
437
 
                        callbackFunc);
438
 
    return r;
439
 
  },
440
 
 
441
 
 
442
 
  deleteUid: function (parent, keyId, idNumber, callbackFunc) {
443
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.deleteUid: keyId="+keyId+", idNumber="+idNumber+"\n");
444
 
    var r = this.editKey(parent, true, null, keyId, "",
445
 
                        { idNumber: idNumber,
446
 
                          step: 0,
447
 
                          usePassphrase: true },
448
 
                        deleteUidCallback,
449
 
                        null,
450
 
                        callbackFunc);
451
 
    return r;
452
 
  },
453
 
 
454
 
 
455
 
  revokeUid: function (parent, keyId, idNumber, callbackFunc) {
456
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.revokeUid: keyId="+keyId+", idNumber="+idNumber+"\n");
457
 
    var r = this.editKey(parent, true, null, keyId, "",
458
 
                        { idNumber: idNumber,
459
 
                          step: 0,
460
 
                          usePassphrase: true },
461
 
                        revokeUidCallback,
462
 
                        null,
463
 
                        callbackFunc);
464
 
    return r;
465
 
  },
466
 
 
467
 
  addPhoto: function (parent, keyId, photoFile, callbackFunc) {
468
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.addPhoto: keyId="+keyId+"\n");
469
 
 
470
 
    var photoFileName = Ec.getEscapedFilename(Ec.getFilePath(photoFile.QueryInterface(Ec.getLocalFileApi())));
471
 
 
472
 
    var r = this.editKey(parent, true, null, keyId, "addphoto",
473
 
                        { file: photoFileName,
474
 
                          step: 0,
475
 
                          usePassphrase: true },
476
 
                        addPhotoCallback,
477
 
                        null,
478
 
                        callbackFunc);
479
 
    return r;
480
 
  },
481
 
 
482
 
 
483
 
  genCardKey: function (parent, name, email, comment, expiry, backupPasswd, requestObserver, callbackFunc) {
484
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.genCardKey: \n");
485
 
    var generateObserver = new enigCardAdminObserver(requestObserver, this.isDosLike);
486
 
    var r = this.editKey(parent, false, null, "", ["--with-colons", "--card-edit"] ,
487
 
                        { step: 0,
488
 
                          name: Ec.convertFromUnicode(name),
489
 
                          email: email,
490
 
                          comment: Ec.convertFromUnicode(comment),
491
 
                          expiry: expiry,
492
 
                          backupPasswd: backupPasswd,
493
 
                          cardAdmin: true,
494
 
                          backupKey: (backupPasswd.length > 0 ? "Y" : "N"),
495
 
                          parent: parent },
496
 
                        genCardKeyCallback,
497
 
                        generateObserver,
498
 
                        callbackFunc);
499
 
    return r;
500
 
  },
501
 
 
502
 
  cardAdminData: function (parent, name, firstname, lang, sex, url, login, forcepin, callbackFunc) {
503
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.cardAdminData: parent="+parent+", name="+name+", firstname="+firstname+", lang="+lang+", sex="+sex+", url="+url+", login="+login+", forcepin="+forcepin+"\n");
504
 
    var adminObserver = new enigCardAdminObserver(null, this.isDosLike);
505
 
    var r = this.editKey(parent, false, null, "", ["--with-colons", "--card-edit"],
506
 
            { step: 0,
507
 
              name: name,
508
 
              firstname: firstname,
509
 
              lang: lang,
510
 
              sex: sex,
511
 
              url: url,
512
 
              login: login,
513
 
              cardAdmin: true,
514
 
              forcepin: forcepin },
515
 
             cardAdminDataCallback,
516
 
             adminObserver,
517
 
             callbackFunc);
518
 
    return r;
519
 
  },
520
 
 
521
 
  cardChangePin: function (parent, action, oldPin, newPin, adminPin, pinObserver, callbackFunc) {
522
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.cardChangePin: parent="+parent+", action="+action+"\n");
523
 
    var adminObserver = new enigCardAdminObserver(pinObserver, this.isDosLike);
524
 
    var enigmailSvc = Ec.getService(parent);
525
 
 
526
 
    var r = this.editKey(parent, enigmailSvc.useGpgAgent(), null, "", ["--with-colons", "--card-edit"],
527
 
            { step: 0,
528
 
              pinStep: 0,
529
 
              cardAdmin: true,
530
 
              action: action,
531
 
              oldPin: oldPin,
532
 
              newPin: newPin,
533
 
              adminPin: adminPin },
534
 
             cardChangePinCallback,
535
 
             adminObserver,
536
 
             callbackFunc);
537
 
    return r;
538
 
  }
539
 
 
540
 
} // EnigmailKeyMgmt
541
 
 
542
 
 
543
 
function signKeyCallback(inputData, keyEdit, ret) {
544
 
 
545
 
  ret.writeTxt = "";
546
 
  ret.errorMsg = "";
547
 
 
548
 
  if (keyEdit.doCheck(GET_BOOL, "sign_uid.okay" )) {
549
 
    ret.exitCode = 0;
550
 
    ret.writeTxt = "Y";
551
 
  }
552
 
  else if (keyEdit.doCheck(GET_BOOL, "keyedit.sign_all.okay" )) {
553
 
    ret.exitCode = 0;
554
 
    ret.writeTxt = "Y";
555
 
  }
556
 
  else if (keyEdit.doCheck(GET_LINE, "sign_uid.expire" )) {
557
 
    ret.exitCode = 0;
558
 
    ret.writeTxt = "0";
559
 
  }
560
 
  else if (keyEdit.doCheck(GET_LINE, "trustsig_prompt.trust_value" )) {
561
 
    ret.exitCode = 0;
562
 
    ret.writeTxt = "0";
563
 
  }
564
 
  else if (keyEdit.doCheck(GET_LINE, "trustsig_prompt.trust_depth" )) {
565
 
    ret.exitCode = 0;
566
 
    ret.writeTxt = "";
567
 
  }
568
 
  else if (keyEdit.doCheck(GET_LINE, "trustsig_prompt.trust_regexp" )) {
569
 
    ret.exitCode = 0;
570
 
    ret.writeTxt = "0";}
571
 
  else if (keyEdit.doCheck(GET_LINE, "siggen.valid" )) {
572
 
    ret.exitCode = 0;
573
 
    ret.writeTxt = "0";
574
 
  }
575
 
  else if (keyEdit.doCheck(GET_BOOL, "sign_uid.local_promote_okay" )) {
576
 
    ret.exitCode = 0;
577
 
    ret.writeTxt = "Y";
578
 
  }
579
 
  else if (keyEdit.doCheck(GET_LINE, "sign_uid.class" )) {
580
 
    ret.exitCode = 0;
581
 
    ret.writeTxt = new String(inputData.trustLevel);
582
 
  }
583
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
584
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
585
 
  }
586
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
587
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
588
 
  }
589
 
  else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
590
 
    ret.exitCode = 0;
591
 
    ret.quitNow = true;
592
 
  }
593
 
  else {
594
 
    ret.quitNow=true;
595
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
596
 
    ret.exitCode=-1;
597
 
  }
598
 
}
599
 
 
600
 
function keyTrustCallback(inputData, keyEdit, ret) {
601
 
  ret.writeTxt = "";
602
 
  ret.errorMsg = "";
603
 
 
604
 
  if (keyEdit.doCheck(GET_LINE, "edit_ownertrust.value" )) {
605
 
    ret.exitCode = 0;
606
 
    ret.writeTxt = new String(inputData.trustLevel);
607
 
  }
608
 
  else if (keyEdit.doCheck(GET_BOOL, "edit_ownertrust.set_ultimate.okay")) {
609
 
    ret.exitCode = 0;
610
 
    ret.writeTxt = "Y";
611
 
  }
612
 
  else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
613
 
    ret.exitCode = 0;
614
 
    ret.quitNow = true;
615
 
  }
616
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
617
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
618
 
  }
619
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
620
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
621
 
  }
622
 
  else {
623
 
    ret.quitNow=true;
624
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
625
 
    ret.exitCode=-1;
626
 
  }
627
 
}
628
 
 
629
 
 
630
 
function addUidCallback(inputData, keyEdit, ret) {
631
 
  ret.writeTxt = "";
632
 
  ret.errorMsg = "";
633
 
 
634
 
  if (keyEdit.doCheck(GET_LINE, "keygen.name" )) {
635
 
    ++inputData.nameAsked;
636
 
    if (inputData.nameAsked==1) {
637
 
      ret.exitCode = 0;
638
 
      ret.writeTxt = inputData.name;
639
 
    }
640
 
    else {
641
 
      ret.exitCode=-1;
642
 
      ret.quitNow=true;
643
 
      ret.errorMsg="Invalid name (too short)";
644
 
    }
645
 
  }
646
 
  else if (keyEdit.doCheck(GET_LINE, "keygen.email")) {
647
 
    ++inputData.emailAsked;
648
 
    if (inputData.emailAsked==1) {
649
 
      ret.exitCode = 0;
650
 
      ret.writeTxt = inputData.email;
651
 
    }
652
 
    else {
653
 
      ret.exitCode=-1;
654
 
      ret.quitNow=true;
655
 
      ret.errorMsg="Invalid email";
656
 
    }
657
 
  }
658
 
  else if (keyEdit.doCheck(GET_LINE, "keygen.comment")) {
659
 
    ret.exitCode = 0;
660
 
    if (inputData.comment) {
661
 
      ret.writeTxt = inputData.comment;
662
 
    }
663
 
    else {
664
 
      ret.writeTxt="";
665
 
    }
666
 
  }
667
 
  else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
668
 
    ret.exitCode = 0;
669
 
    ret.quitNow = true;
670
 
  }
671
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
672
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
673
 
  }
674
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
675
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
676
 
  }
677
 
  else {
678
 
    ret.quitNow=true;
679
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
680
 
    ret.exitCode=-1;
681
 
  }
682
 
}
683
 
 
684
 
 
685
 
function revokeCertCallback(inputData, keyEdit, ret) {
686
 
  ret.writeTxt = "";
687
 
  ret.errorMsg = "";
688
 
 
689
 
  if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.code" )) {
690
 
    ret.exitCode = 0;
691
 
    ret.writeTxt = new String(inputData.reasonCode);
692
 
  }
693
 
  else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.text" )) {
694
 
    ret.exitCode = 0;
695
 
    ret.writeTxt = "";
696
 
  }
697
 
  else if (keyEdit.doCheck(GET_BOOL, "gen_revoke.okay")) {
698
 
    ret.exitCode = 0;
699
 
    ret.writeTxt = "Y";
700
 
  }
701
 
  else if (keyEdit.doCheck(GET_BOOL, "ask_revocation_reason.okay" )) {
702
 
    ret.exitCode = 0;
703
 
    ret.writeTxt = "Y";
704
 
  }
705
 
  else if (keyEdit.doCheck(GET_BOOL, "openfile.overwrite.okay" )) {
706
 
    ret.exitCode = 0;
707
 
    ret.writeTxt = "Y";
708
 
  }
709
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
710
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
711
 
  }
712
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
713
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
714
 
  }
715
 
  else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
716
 
    ret.exitCode = 0;
717
 
    ret.quitNow = true;
718
 
  }
719
 
  else {
720
 
    ret.quitNow=true;
721
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
722
 
    ret.exitCode=-1;
723
 
  }
724
 
}
725
 
 
726
 
 
727
 
function setPrimaryUidCallback(inputData, keyEdit, ret) {
728
 
  ret.writeTxt = "";
729
 
  ret.errorMsg = "";
730
 
 
731
 
  if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
732
 
    ++inputData.step;
733
 
    switch (inputData.step) {
734
 
    case 1:
735
 
      ret.exitCode = 0;
736
 
      ret.writeTxt = "uid "+inputData.idNumber;
737
 
      break;
738
 
    case 2:
739
 
      ret.exitCode = 0;
740
 
      ret.writeTxt = "primary";
741
 
      break;
742
 
    case 3:
743
 
      ret.exitCode = 0;
744
 
      ret.quitNow=true;
745
 
      break;
746
 
    default:
747
 
      ret.exitCode = -1;
748
 
      ret.quitNow=true;
749
 
    }
750
 
 
751
 
  }
752
 
  else {
753
 
    ret.quitNow=true;
754
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
755
 
    ret.exitCode=-1;
756
 
  }
757
 
}
758
 
 
759
 
 
760
 
function changePassphraseCallback(inputData, keyEdit, ret) {
761
 
  ret.writeTxt = "";
762
 
  ret.errorMsg = "";
763
 
 
764
 
  if (keyEdit.doCheck(GET_HIDDEN, "passphrase.enter")) {
765
 
    switch (inputData.observer.passphraseStatus) {
766
 
    case 0:
767
 
      ret.writeTxt = inputData.oldPw;
768
 
      ret.exitCode = 0;
769
 
      break;
770
 
    case 1:
771
 
      ret.writeTxt = inputData.newPw;
772
 
      ret.exitCode = 0;
773
 
      break;
774
 
    case -1:
775
 
      ret.exitCode = -2;
776
 
      ret.quitNow=true;
777
 
      break;
778
 
    }
779
 
  }
780
 
  else if (keyEdit.doCheck(GET_BOOL, "change_passwd.empty.okay")) {
781
 
    ret.writeTxt = "Y";
782
 
    ret.exitCode = 0;
783
 
  }
784
 
  else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
785
 
    if (inputData.useAgent) {
786
 
      ret.exitCode=0;
787
 
    }
788
 
    else
789
 
      ret.exitCode = null;
790
 
    ret.quitNow = true;
791
 
  }
792
 
  else {
793
 
    ret.quitNow=true;
794
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
795
 
    ret.exitCode=-1;
796
 
  }
797
 
}
798
 
 
799
 
 
800
 
function deleteUidCallback(inputData, keyEdit, ret) {
801
 
  ret.writeTxt = "";
802
 
  ret.errorMsg = "";
803
 
 
804
 
  if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
805
 
    ++inputData.step;
806
 
    switch (inputData.step) {
807
 
    case 1:
808
 
      ret.exitCode = 0;
809
 
      ret.writeTxt = "uid "+inputData.idNumber;
810
 
      break;
811
 
    case 2:
812
 
      ret.exitCode = 0;
813
 
      ret.writeTxt = "deluid";
814
 
      break;
815
 
    case 4:
816
 
      ret.exitCode = 0;
817
 
      ret.quitNow=true;
818
 
      break;
819
 
    default:
820
 
      ret.exitCode = -1;
821
 
      ret.quitNow=true;
822
 
    }
823
 
  }
824
 
  else if (keyEdit.doCheck(GET_BOOL, "keyedit.remove.uid.okay" )) {
825
 
    ++inputData.step;
826
 
    ret.exitCode = 0;
827
 
    ret.writeTxt = "Y";
828
 
  }
829
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
830
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
831
 
  }
832
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
833
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
834
 
  }
835
 
  else {
836
 
    ret.quitNow=true;
837
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
838
 
    ret.exitCode=-1;
839
 
  }
840
 
}
841
 
 
842
 
 
843
 
function revokeUidCallback(inputData, keyEdit, ret) {
844
 
  ret.writeTxt = "";
845
 
  ret.errorMsg = "";
846
 
 
847
 
  if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
848
 
    ++inputData.step;
849
 
    switch (inputData.step) {
850
 
    case 1:
851
 
      ret.exitCode = 0;
852
 
      ret.writeTxt = "uid "+inputData.idNumber;
853
 
      break;
854
 
    case 2:
855
 
      ret.exitCode = 0;
856
 
      ret.writeTxt = "revuid";
857
 
      break;
858
 
    case 7:
859
 
      ret.exitCode = 0;
860
 
      ret.quitNow=true;
861
 
      break;
862
 
    default:
863
 
      ret.exitCode = -1;
864
 
      ret.quitNow=true;
865
 
    }
866
 
  }
867
 
  else if (keyEdit.doCheck(GET_BOOL, "keyedit.revoke.uid.okay" )) {
868
 
    ++inputData.step;
869
 
    ret.exitCode = 0;
870
 
    ret.writeTxt = "Y";
871
 
  }
872
 
  else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.code")) {
873
 
    ++inputData.step;
874
 
    ret.exitCode = 0;
875
 
    ret.writeTxt = "0"; // no reason specified
876
 
  }
877
 
  else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.text")) {
878
 
    ++inputData.step;
879
 
    ret.exitCode = 0;
880
 
    ret.writeTxt = "";
881
 
  }
882
 
  else if (keyEdit.doCheck(GET_BOOL, "ask_revocation_reason.okay")) {
883
 
    ++inputData.step;
884
 
    ret.exitCode = 0;
885
 
    ret.writeTxt = "Y";
886
 
  }
887
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
888
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
889
 
  }
890
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
891
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
892
 
  }
893
 
  else {
894
 
    ret.quitNow=true;
895
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
896
 
    ret.exitCode=-1;
897
 
  }
898
 
}
899
 
 
900
 
 
901
 
function deleteKeyCallback(inputData, keyEdit, ret) {
902
 
  ret.writeTxt = "";
903
 
  ret.errorMsg = "";
904
 
 
905
 
  if (keyEdit.doCheck(GET_BOOL, "delete_key.secret.okay")) {
906
 
    ret.exitCode = 0;
907
 
    ret.writeTxt = "Y";
908
 
  }
909
 
  else if (keyEdit.doCheck(GET_BOOL, "keyedit.remove.subkey.okay")) {
910
 
    ret.exitCode = 0;
911
 
    ret.writeTxt = "Y";
912
 
  }
913
 
  else if (keyEdit.doCheck(GET_BOOL, "delete_key.okay" )) {
914
 
    ret.exitCode = 0;
915
 
    ret.writeTxt = "Y";
916
 
  }
917
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
918
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
919
 
  }
920
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
921
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
922
 
  }
923
 
  else {
924
 
    ret.quitNow=true;
925
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
926
 
    ret.exitCode=-1;
927
 
  }
928
 
}
929
 
 
930
 
function GetPin(domWindow, promptMsg, ret) {
931
 
  Ec.DEBUG_LOG("keyManagmenent.jsm: GetPin: \n");
932
 
 
933
 
  var passwdObj = {value: ""};
934
 
  var dummyObj = {};
935
 
 
936
 
  var success = false;
937
 
 
938
 
  var promptService = Cc[NS_PROMPTSERVICE_CONTRACTID].getService(Ci.nsIPromptService);
939
 
  success = promptService.promptPassword(domWindow,
940
 
                                         Ec.getString("Enigmail"),
941
 
                                         promptMsg,
942
 
                                         passwdObj,
943
 
                                         null,
944
 
                                         dummyObj);
945
 
 
946
 
  if (!success) {
947
 
    ret.errorMsg = Ec.getString("noPassphrase");
948
 
    ret.quitNow=true;
949
 
    return false;
950
 
  }
951
 
 
952
 
  Ec.DEBUG_LOG("keyManagmenent.jsm: GetPin: got pin\n");
953
 
  ret.writeTxt = passwdObj.value;
954
 
 
955
 
  return true;
956
 
}
957
 
 
958
 
function genCardKeyCallback(inputData, keyEdit, ret) {
959
 
  ret.writeTxt = "";
960
 
  ret.errorMsg = "";
961
 
 
962
 
  var pinObj={};
963
 
 
964
 
  if (keyEdit.doCheck(GET_LINE, "cardedit.prompt")) {
965
 
    if (inputData.step == 0) {
966
 
      ret.exitCode = 0;
967
 
      ret.writeTxt = "admin";
968
 
    }
969
 
    else if (inputData.step == 1) {
970
 
      ret.exitCode = 0;
971
 
      ret.writeTxt = "generate";
972
 
    }
973
 
    else {
974
 
      ret.exitCode = 0;
975
 
      ret.quitNow=true;
976
 
      ret.writeTxt = "quit";
977
 
    }
978
 
    ++inputData.step;
979
 
  }
980
 
  else if (keyEdit.doCheck(GET_LINE, "cardedit.genkeys.backup_enc") ||
981
 
           keyEdit.doCheck(GET_BOOL, "cardedit.genkeys.backup_enc")) {
982
 
    ret.exitCode = 0;
983
 
    ret.writeTxt = new String(inputData.backupKey);
984
 
  }
985
 
  else if (keyEdit.doCheck(GET_BOOL, "cardedit.genkeys.replace_keys")) {
986
 
    ret.exitCode = 0;
987
 
    ret.writeTxt = "Y";
988
 
  }
989
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
990
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
991
 
  }
992
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
993
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
994
 
  }
995
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.enter")) {
996
 
    ret.exitCode = 0;
997
 
    ret.writeTxt = inputData.backupPasswd;
998
 
  }
999
 
  else if (keyEdit.doCheck(GET_LINE, "keygen.valid")) {
1000
 
    ret.exitCode = 0;
1001
 
    ret.writeTxt = new String(inputData.expiry);
1002
 
  }
1003
 
  else if (keyEdit.doCheck(GET_LINE, "cardedit.genkeys.size")) {
1004
 
    ret.exitCode = 0;
1005
 
    ret.writeTxt = "2048";
1006
 
  }
1007
 
  else if (keyEdit.doCheck(GET_LINE, "keygen.name")) {
1008
 
    ret.exitCode = 0;
1009
 
    ret.writeTxt = inputData.name;
1010
 
  }
1011
 
  else if (keyEdit.doCheck(GET_LINE, "keygen.email")) {
1012
 
    ret.exitCode = 0;
1013
 
    ret.writeTxt = inputData.email;
1014
 
  }
1015
 
  else if (keyEdit.doCheck(GET_LINE, "keygen.comment")) {
1016
 
    ret.exitCode = 0;
1017
 
    if (inputData.comment) {
1018
 
      ret.writeTxt = inputData.comment;
1019
 
    }
1020
 
    else {
1021
 
      ret.writeTxt="";
1022
 
    }
1023
 
  }
1024
 
  else {
1025
 
    ret.quitNow=true;
1026
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1027
 
    ret.exitCode=-1;
1028
 
  }
1029
 
}
1030
 
 
1031
 
function cardAdminDataCallback(inputData, keyEdit, ret) {
1032
 
  ret.writeTxt = "";
1033
 
  ret.errorMsg = "";
1034
 
 
1035
 
  var pinObj={};
1036
 
 
1037
 
  if (keyEdit.doCheck(GET_LINE, "cardedit.prompt")) {
1038
 
    ++inputData.step;
1039
 
    ret.exitCode = 0;
1040
 
    switch(inputData.step) {
1041
 
    case 1:
1042
 
      ret.writeTxt = "admin";
1043
 
      break;
1044
 
    case 2:
1045
 
      ret.writeTxt = "name";
1046
 
      break;
1047
 
    case 3:
1048
 
      ret.writeTxt = "lang";
1049
 
      break;
1050
 
    case 4:
1051
 
      ret.writeTxt = "sex";
1052
 
      break;
1053
 
    case 5:
1054
 
      ret.writeTxt = "url";
1055
 
      break;
1056
 
    case 6:
1057
 
      ret.writeTxt = "login";
1058
 
      break;
1059
 
    case 7:
1060
 
      if (inputData.forcepin != 0) {
1061
 
        ret.writeTxt = "forcesig";
1062
 
        break;
1063
 
      }
1064
 
    default:
1065
 
      ret.writeTxt = "quit";
1066
 
      ret.exitCode = 0;
1067
 
      ret.quitNow=true;
1068
 
      break;
1069
 
    }
1070
 
  }
1071
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1072
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
1073
 
  }
1074
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1075
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
1076
 
  }
1077
 
  else if (keyEdit.doCheck(GET_LINE, "keygen.smartcard.surname")) {
1078
 
    ret.exitCode = 0;
1079
 
    ret.writeTxt = inputData.firstname.replace(/^$/, "-");;
1080
 
  }
1081
 
  else if (keyEdit.doCheck(GET_LINE, "keygen.smartcard.givenname")) {
1082
 
    ret.exitCode = 0;
1083
 
    ret.writeTxt = inputData.name.replace(/^$/, "-");;
1084
 
  }
1085
 
  else if (keyEdit.doCheck(GET_LINE, "cardedit.change_sex")) {
1086
 
    ret.exitCode = 0;
1087
 
    ret.writeTxt = inputData.sex;
1088
 
  }
1089
 
  else if (keyEdit.doCheck(GET_LINE, "cardedit.change_lang")) {
1090
 
    ret.exitCode = 0;
1091
 
    ret.writeTxt = inputData.lang.replace(/^$/, "-");;
1092
 
  }
1093
 
  else if (keyEdit.doCheck(GET_LINE, "cardedit.change_url")) {
1094
 
    ret.exitCode = 0;
1095
 
    ret.writeTxt = inputData.url.replace(/^$/, "-");;
1096
 
  }
1097
 
  else if (keyEdit.doCheck(GET_LINE, "cardedit.change_login")) {
1098
 
    ret.exitCode = 0;
1099
 
    ret.writeTxt = inputData.login.replace(/^$/, "-");
1100
 
  }
1101
 
  else {
1102
 
    ret.quitNow=true;
1103
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1104
 
    ret.exitCode=-1;
1105
 
  }
1106
 
}
1107
 
 
1108
 
function cardChangePinCallback(inputData, keyEdit, ret) {
1109
 
  ret.writeTxt = "";
1110
 
  ret.errorMsg = "";
1111
 
 
1112
 
  if (keyEdit.doCheck(GET_LINE, "cardedit.prompt")) {
1113
 
    ++inputData.step;
1114
 
    ret.exitCode=0;
1115
 
    switch (inputData.step) {
1116
 
    case 1:
1117
 
      ret.writeTxt = "admin";
1118
 
      break;
1119
 
    case 2:
1120
 
      ret.writeTxt = "passwd";
1121
 
      break;
1122
 
    default:
1123
 
      ret.writeTxt = "quit";
1124
 
      ret.exitCode = 0;
1125
 
      ret.quitNow=true;
1126
 
      break;
1127
 
    }
1128
 
  }
1129
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1130
 
    ret.exitCode=0;
1131
 
    ret.writeTxt = inputData.adminPin;
1132
 
  }
1133
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1134
 
    ret.exitCode=0;
1135
 
    ret.writeTxt = inputData.oldPin;
1136
 
  }
1137
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.new.ask") ||
1138
 
           keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.repeat") ||
1139
 
           keyEdit.doCheck(GET_HIDDEN, "passphrase.ask") ||
1140
 
           keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.new.ask")) {
1141
 
    ret.exitCode = 0;
1142
 
    ret.writeTxt = inputData.newPin;
1143
 
  }
1144
 
  else if (keyEdit.doCheck(GET_LINE, "cardutil.change_pin.menu")) {
1145
 
    ret.exitCode=0;
1146
 
    ++inputData.pinStep;
1147
 
    if (inputData.pinStep == 1) {
1148
 
      ret.writeTxt = inputData.action.toString();
1149
 
    }
1150
 
    else {
1151
 
      ret.writeTxt = "Q";
1152
 
    }
1153
 
  }
1154
 
  else {
1155
 
    ret.exitCode=-1;
1156
 
    ret.quitNow=true;
1157
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1158
 
  }
1159
 
}
1160
 
 
1161
 
 
1162
 
function addPhotoCallback(inputData, keyEdit, ret) {
1163
 
  ret.writeTxt = "";
1164
 
  ret.errorMsg = "";
1165
 
 
1166
 
  if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
1167
 
    ret.exitCode = 0;
1168
 
    ret.writeTxt = "save";
1169
 
    ret.quitNow=true;
1170
 
  }
1171
 
  else if (keyEdit.doCheck(GET_LINE, "photoid.jpeg.add" )) {
1172
 
    if (inputData.step == 0) {
1173
 
      ++inputData.step;
1174
 
      ret.exitCode = 0;
1175
 
      ret.writeTxt = inputData.file;
1176
 
    }
1177
 
    else {
1178
 
      ret.exitCode = -1;
1179
 
      ret.quitNow=true;
1180
 
    }
1181
 
  }
1182
 
  else if (keyEdit.doCheck(GET_BOOL, "photoid.jpeg.size")) {
1183
 
    ret.exitCode = 0;
1184
 
    ret.writeTxt = "Y"; // add large file
1185
 
  }
1186
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1187
 
    GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
1188
 
  }
1189
 
  else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1190
 
    GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
1191
 
  }
1192
 
  else {
1193
 
    ret.quitNow=true;
1194
 
    Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1195
 
    ret.exitCode=-1;
1196
 
  }
1197
 
}
1198
 
 
1199
 
function enigCardAdminObserver(guiObserver, isDosLike) {
1200
 
  this._guiObserver = guiObserver;
1201
 
  this.isDosLike = isDosLike;
1202
 
}
1203
 
 
1204
 
enigCardAdminObserver.prototype =
1205
 
{
1206
 
  _guiObserver: null,
1207
 
  _failureCode: 0,
1208
 
 
1209
 
  QueryInterface : function(iid)
1210
 
  {
1211
 
    if (iid.equals(Ci.nsIEnigMimeReadCallback) ||
1212
 
        iid.equals(Ci.nsISupports) )
1213
 
      return this;
1214
 
 
1215
 
    throw Components.results.NS_NOINTERFACE;
1216
 
  },
1217
 
 
1218
 
  onDataAvailable: function (data) {
1219
 
    var ret="";
1220
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: enigCardAdminObserver.onDataAvailable: data="+data+"\n");
1221
 
    if (this.isDosLike && data.indexOf("[GNUPG:] BACKUP_KEY_CREATED") == 0) {
1222
 
      data=data.replace(/\//g, "\\");
1223
 
    }
1224
 
    if (data.indexOf("[GNUPG:] SC_OP_FAILURE")>=0) {
1225
 
      data=data.substr(23);
1226
 
      if (data == "2") {
1227
 
        data = "[GNUPG:] BAD_PASSPHRASE 0";
1228
 
        this._failureCode = 2;
1229
 
      }
1230
 
      else
1231
 
        this._failureCode = 1;
1232
 
    }
1233
 
    if (this._failureCode == 1) {
1234
 
      ret = "[GNUPG:] ENIGMAIL_FAILURE "+data;
1235
 
    }
1236
 
    if (this._guiObserver) {
1237
 
      this._guiObserver.onDataAvailable(data);
1238
 
    }
1239
 
    return ret;
1240
 
  }
1241
 
}
1242
 
 
1243
 
function ChangePasswdObserver() {}
1244
 
 
1245
 
ChangePasswdObserver.prototype =
1246
 
{
1247
 
  _failureCode: 0,
1248
 
  passphraseStatus: 0,
1249
 
 
1250
 
  QueryInterface : function(iid)
1251
 
  {
1252
 
    if (iid.equals(Ci.nsIEnigMimeReadCallback) ||
1253
 
        iid.equals(Ci.nsISupports) )
1254
 
      return this;
1255
 
 
1256
 
    throw Components.results.NS_NOINTERFACE;
1257
 
  },
1258
 
 
1259
 
  onDataAvailable: function (data) {
1260
 
    var ret="";
1261
 
    Ec.DEBUG_LOG("keyManagmenent.jsm: ChangePasswdObserver.onDataAvailable: data="+data+"\n");
1262
 
    if (this._failureCode) {
1263
 
      ret = "[GNUPG:] ENIGMAIL_FAILURE "+data;
1264
 
    }
1265
 
    if (data.indexOf("[GNUPG:] GOOD_PASSPHRASE")>=0) {
1266
 
      this.passphraseStatus = 1;
1267
 
    }
1268
 
    else if (data.indexOf("[GNUPG:] BAD_PASSPHRASE")>=0) {
1269
 
      this.passphraseStatus = -1;
1270
 
    }
1271
 
    return ret;
1272
 
  }
1273
 
}
1274