~ubuntu-branches/ubuntu/oneiric/enigmail/oneiric-updates

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-04-30 01:08:44 UTC
  • mfrom: (0.12.10)
  • Revision ID: package-import@ubuntu.com-20120430010844-i4a0z0d73kgrah49
Tags: 2:1.4.1-0ubuntu0.11.10.2
* New upstream release v1.4.1
  - LP: #987305
  - Fix LP: #968122 - localization messed up

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