1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
14
* The Original Code is Enigmail.
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.
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 ***** */
36
Components.utils.import("resource://enigmail/enigmailCommon.jsm");
37
Components.utils.import("resource://enigmail/subprocess.jsm");
39
var EXPORTED_SYMBOLS = [ "EnigmailKeyMgmt" ];
41
const Ec = EnigmailCommon;
43
const GET_BOOL = "GET_BOOL";
44
const GET_LINE = "GET_LINE";
45
const GET_HIDDEN = "GET_HIDDEN";
48
function KeyEditor(reqObserver, callbackFunc, inputData) {
49
this._reqObserver = reqObserver;
50
this._callbackFunc = callbackFunc;
51
this._inputData = inputData;
54
KeyEditor.prototype = {
61
setStdin: function(pipe) {
63
if (this._data.length > 0) this.processData();
66
gotData: function(data) {
67
//Ec.DEBUG_LOG("keyManagement.jsm: KeyEditor.gotData: '"+data+"'\n");
68
this._data += data.replace(/\r\n/g, "\n");
72
processData: function() {
73
//Ec.DEBUG_LOG("keyManagement.jsm: KeyEditor.processData\n");
75
while (this._data.length > 0 && this._stdin) {
76
var index = this._data.indexOf("\n");
82
txt = this._data.substr(0, index);
83
this._data = this._data.substr(index+1);
89
closeStdin: function() {
90
Ec.DEBUG_LOG("keyManagement.jsm: KeyEditor.closeStdin:\n");
97
done: function(parentCallback, exitCode) {
98
Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.done: exitCode="+exitCode+"\n");
100
if (exitCode == 0) exitCode = this._exitCode;
102
if (exitCode == 0 && typeof(this._inputData) == "object" && this._inputData.usePassphrase) {
106
Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.done: returning exitCode "+exitCode+"\n");
108
parentCallback(exitCode, this.errorMsg);
111
writeLine: function (inputData) {
112
Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.writeLine: '"+inputData+"'\n");
113
if (inputData.length > 0) this._stdin.write(inputData+"\n");
116
nextLine: function(txt) {
117
if (txt.indexOf("[GNUPG:]") < 0) {
118
if (this._reqObserver) {
119
var newTxt = this._reqObserver.onDataAvailable(txt);
125
if (txt.indexOf("[GNUPG:]") >= 0) {
127
this.processLine(txt);
131
doCheck: function(inputType, promptVal) {
132
var a=this._txt.split(/ /);
133
return ((a[1] == inputType) && (a[2] == promptVal))
136
getText: function() {
140
processLine: function(txt) {
141
Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.processLine: '"+txt+"'\n");
142
var r = { quitNow: false,
146
Ec.DEBUG_LOG(txt+"\n");
147
if (txt.indexOf("[GNUPG:] BAD_PASSPHRASE")>=0) {
150
this.errorMsg=Ec.getString("badPhrase");
151
Ec.clearCachedPassphrase();
153
if (txt.indexOf("[GNUPG:] NO_CARD_AVAILABLE")>=0) {
154
this.errorMsg=Ec.getString("noCardAvailable");
158
if (txt.indexOf("[GNUPG:] ENIGMAIL_FAILURE")==0) {
161
this.errorMsg = txt.substr(26);
163
if (txt.indexOf("[GNUPG:] ALREADY_SIGNED")>=0) {
164
this.errorMsg=Ec.getString("keyAlreadySigned");
168
if (txt.indexOf("[GNUPG:] GET_") < 0) {
169
// return if no "GET" statement
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);
186
this.errorMsg = r.errorMsg;
201
this.writeLine("save");
205
Ec.DEBUG_LOG("no more data\n");
209
this._exitCode = r.exitCode;
212
QueryInterface: function (iid) {
213
if (!iid.equals(Ci.nsISupports))
214
throw Components.results.NS_ERROR_NO_INTERFACE;
219
var EnigmailKeyMgmt = {
221
editKey: function (parent, needPassphrase, userId, keyId, editCmd, inputData, callbackFunc, requestObserver, parentCallback) {
222
Ec.DEBUG_LOG("keyManagmenent.jsm: editKey: parent="+parent+", editCmd="+editCmd+"\n");
224
var enigmailSvc = Ec.getService(parent);
226
Ec.ERROR_LOG("keyManagmenent.jsm: Enigmail.editKey: not yet initialized\n");
227
parentCallback(-1, Ec.getString("notInit"));
231
var keyIdList = keyId.split(" ");
232
var args = Ec.getAgentArgs(false);
234
var statusFlags = new Object();
237
var useAgentObj = new Object();
239
if (needPassphrase) {
240
args=args.concat(Ec.passwdCommand());
242
var passwdObj = new Object();
244
if (!Ec.getPassphrase(parent, passwdObj, useAgentObj, 0)) {
245
Ec.ERROR_LOG("keyManagmenent.jsm: editKey: Error - no passphrase supplied\n");
247
parentCallback(-1, Ec.getString("noPassphrase"));
251
passphrase = passwdObj.value;
255
useAgentObj.value = true;
258
args=args.concat(["--no-tty", "--status-fd", "1", "--logger-fd", "1", "--command-fd", "0"]);
259
if (userId) args=args.concat(["-u", userId]);
261
if (typeof(editCmd) == "string") {
262
editCmdArr = [ editCmd ];
265
editCmdArr = editCmd;
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);
275
else if (editCmdArr[0].indexOf("--")==0) {
276
args=args.concat(editCmd);
277
args=args.concat(keyIdList);
280
args=args.concat(["--ask-cert-level", "--edit-key", keyId]);
281
args=args.concat(editCmd);
285
var command= enigmailSvc.agentPath;
286
Ec.CONSOLE_LOG("enigmail> "+Ec.printCmdLine(command, args)+"\n");
288
var keyEdit = new KeyEditor(requestObserver, callbackFunc, inputData);
295
environment: Ec.getEnvList(),
296
stdin: function (stdin) {
297
if (needPassphrase && Ec.requirePassword()) {
298
stdin.write(passphrase+"\n");
300
keyEdit.setStdin(stdin);
302
stdout: function(data) {
303
keyEdit.gotData(data);
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);
312
Ec.ERROR_LOG("keyManagement.jsm: editKey: "+command.path+" failed\n");
313
parentCallback(-1, "");
317
setKeyTrust: function (parent, keyId, trustLevel, callbackFunc) {
318
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.setKeyTrust: trustLevel="+trustLevel+", keyId="+keyId+"\n");
320
return this.editKey(parent, false, null, keyId, "trust",
321
{ trustLevel: trustLevel},
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 },
338
genRevokeCert: function (parent, keyId, outFile, reasonCode, reasonText, callbackFunc) {
339
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.genRevokeCert: keyId="+keyId+"\n");
341
var r= this.editKey(parent, true, null, keyId, "revoke",
343
reasonCode: reasonCode,
344
reasonText: Ec.convertFromUnicode(reasonText),
345
usePassphrase: true },
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",
360
usePassphrase: true },
367
deleteKey: function (parent, keyId, deleteSecretKey, callbackFunc) {
368
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.addUid: keyId="+keyId+", deleteSecretKey="+deleteSecretKey+"\n");
370
var cmd = (deleteSecretKey ? "--delete-secret-and-public-key" : "--delete-key");
371
var r= this.editKey(parent, false, null, keyId, cmd,
372
{ usePassphrase: true },
379
changePassphrase: function (parent, keyId, oldPw, newPw, callbackFunc) {
380
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.changePassphrase: keyId="+keyId+"\n");
382
var pwdObserver = new enigChangePasswdObserver();
383
var r= this.editKey(parent, false, null, keyId, "passwd",
386
useAgent: this.useGpgAgent(),
388
observer: pwdObserver,
389
usePassphrase: true },
390
changePassphraseCallback,
397
revokeSubkey: function (parent, keyId, subkeys, reasonCode, reasonText, callbackFunc) {
398
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.revokeSubkey: keyId="+keyId+"\n");
400
var r= this.editKey(parent, true, null, keyId, "",
402
subkeys: subkeys.split(/,/),
403
reasonCode: reasonCode,
404
reasonText: Ec.convertFromUnicode(reasonText),
405
usePassphrase: true },
406
revokeSubkeyCallback,
412
enableDisableKey: function (parent, keyId, disableKey, callbackFunc) {
413
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.addUid: keyId="+keyId+", disableKey="+disableKey+"\n");
415
var cmd = (disableKey ? "disable" : "enable");
416
var r= this.editKey(parent, false, null, keyId, cmd,
417
{ usePassphrase: true },
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,
429
usePassphrase: true },
430
setPrimaryUidCallback,
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,
442
usePassphrase: true },
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,
455
usePassphrase: true },
462
addPhoto: function (parent, keyId, photoFile, callbackFunc) {
463
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.addPhoto: keyId="+keyId+"\n");
465
var photoFileName = this.getEscapedFilename(getFilePath(photoFile.QueryInterface(nsILocalFile)));
467
var r = this.editKey(parent, true, null, keyId, "addphoto",
468
{ file: photoFileName,
470
usePassphrase: true },
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"] ,
483
name: Ec.convertFromUnicode(name),
485
comment: Ec.convertFromUnicode(comment),
487
backupPasswd: backupPasswd,
488
backupKey: (backupPasswd.length > 0 ? "Y" : "N"),
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"],
502
firstname: firstname,
507
forcepin: forcepin },
508
cardAdminDataCallback,
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"],
523
adminPin: adminPin },
524
cardChangePinCallback,
533
function signKeyCallback(inputData, keyEdit, ret) {
538
if (keyEdit.doCheck(GET_BOOL, "sign_uid.okay" )) {
542
else if (keyEdit.doCheck(GET_BOOL, "keyedit.sign_all.okay" )) {
546
else if (keyEdit.doCheck(GET_LINE, "sign_uid.expire" )) {
550
else if (keyEdit.doCheck(GET_LINE, "trustsig_prompt.trust_value" )) {
554
else if (keyEdit.doCheck(GET_LINE, "trustsig_prompt.trust_depth" )) {
558
else if (keyEdit.doCheck(GET_LINE, "trustsig_prompt.trust_regexp" )) {
561
else if (keyEdit.doCheck(GET_LINE, "siggen.valid" )) {
565
else if (keyEdit.doCheck(GET_BOOL, "sign_uid.local_promote_okay" )) {
569
else if (keyEdit.doCheck(GET_LINE, "sign_uid.class" )) {
571
ret.writeTxt = new String(inputData.trustLevel);
573
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
574
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
576
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
577
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
579
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
585
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
590
function keyTrustCallback(inputData, keyEdit, ret) {
594
if (keyEdit.doCheck(GET_LINE, "edit_ownertrust.value" )) {
596
ret.writeTxt = new String(inputData.trustLevel);
598
else if (keyEdit.doCheck(GET_BOOL, "edit_ownertrust.set_ultimate.okay")) {
602
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
606
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
607
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
609
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
610
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
614
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
620
function addUidCallback(inputData, keyEdit, ret) {
624
if (keyEdit.doCheck(GET_LINE, "keygen.name" )) {
625
++inputData.nameAsked;
626
if (inputData.nameAsked==1) {
628
ret.writeTxt = inputData.name;
633
ret.errorMsg="Invalid name (too short)";
636
else if (keyEdit.doCheck(GET_LINE, "keygen.email")) {
637
++inputData.emailAsked;
638
if (inputData.emailAsked==1) {
640
ret.writeTxt = inputData.email;
645
ret.errorMsg="Invalid email";
648
else if (keyEdit.doCheck(GET_LINE, "keygen.comment")) {
650
if (inputData.comment) {
651
ret.writeTxt = inputData.comment;
657
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
661
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
662
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
664
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
665
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
669
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
675
function revokeCertCallback(inputData, keyEdit, ret) {
679
if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.code" )) {
681
ret.writeTxt = new String(inputData.reasonCode);
683
else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.text" )) {
687
else if (keyEdit.doCheck(GET_BOOL, "gen_revoke.okay")) {
691
else if (keyEdit.doCheck(GET_BOOL, "ask_revocation_reason.okay" )) {
695
else if (keyEdit.doCheck(GET_BOOL, "openfile.overwrite.okay" )) {
699
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
700
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
702
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
703
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
705
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
711
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
716
function revokeSubkeyCallback(inputData, keyEdit, ret) {
720
if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
721
if (inputData.step < inputData.subkeys.length) {
723
ret.writeTxt = "key "+inputData.subkeys[inputData.step];
726
else if (inputData.step == inputData.subkeys.length) {
728
ret.writeTxt = "revkey";
732
if (inputData.step == (inputData.subkeys.length+1)) {
741
else if (keyEdit.doCheck(GET_BOOL, "keyedit.revoke.subkey.okay")) {
745
else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.code" )) {
747
ret.writeTxt = new String(inputData.reasonCode);
749
else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.text" )) {
753
else if (keyEdit.doCheck(GET_BOOL, "ask_revocation_reason.okay" )) {
758
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
759
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
761
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
762
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
766
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
771
function setPrimaryUidCallback(inputData, keyEdit, ret) {
775
if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
777
switch (inputData.step) {
780
ret.writeTxt = "uid "+inputData.idNumber;
784
ret.writeTxt = "primary";
798
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
804
function changePassphraseCallback(inputData, keyEdit, ret) {
808
if (keyEdit.doCheck(GET_HIDDEN, "passphrase.enter")) {
809
switch (inputData.observer.passphraseStatus) {
811
ret.writeTxt = inputData.oldPw;
815
ret.writeTxt = inputData.newPw;
824
else if (keyEdit.doCheck(GET_BOOL, "change_passwd.empty.okay")) {
828
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
829
if (inputData.useAgent) ret.exitCode=0;
834
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
840
function deleteUidCallback(inputData, keyEdit, ret) {
844
if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
846
switch (inputData.step) {
849
ret.writeTxt = "uid "+inputData.idNumber;
853
ret.writeTxt = "deluid";
864
else if (keyEdit.doCheck(GET_BOOL, "keyedit.remove.uid.okay" )) {
869
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
870
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
872
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
873
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
877
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
883
function revokeUidCallback(inputData, keyEdit, ret) {
887
if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
889
switch (inputData.step) {
892
ret.writeTxt = "uid "+inputData.idNumber;
896
ret.writeTxt = "revuid";
907
else if (keyEdit.doCheck(GET_BOOL, "keyedit.revoke.uid.okay" )) {
912
else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.code")) {
915
ret.writeTxt = "0"; // no reason specified
917
else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.text")) {
922
else if (keyEdit.doCheck(GET_BOOL, "ask_revocation_reason.okay")) {
927
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
928
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
930
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
931
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
935
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
941
function deleteKeyCallback(inputData, keyEdit, ret) {
945
if (keyEdit.doCheck(GET_BOOL, "delete_key.secret.okay")) {
949
else if (keyEdit.doCheck(GET_BOOL, "keyedit.remove.subkey.okay")) {
953
else if (keyEdit.doCheck(GET_BOOL, "delete_key.okay" )) {
957
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
958
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
960
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
961
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
965
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
970
function GetPin(domWindow, promptMsg, ret) {
971
Ec.DEBUG_LOG("keyManagmenent.jsm: GetPin: \n");
973
var passwdObj = {value: ""};
978
var promptService = Cc[NS_PROMPTSERVICE_CONTRACTID].getService(Ci.nsIPromptService);
979
success = promptService.promptPassword(domWindow,
980
Ec.getString("Enigmail"),
987
ret.errorMsg = Ec.getString("noPassphrase");
992
Ec.DEBUG_LOG("keyManagmenent.jsm: GetPin: got pin\n");
993
ret.writeTxt = passwdObj.value;
998
function genCardKeyCallback(inputData, keyEdit, ret) {
1004
if (keyEdit.doCheck(GET_LINE, "cardedit.prompt")) {
1005
if (inputData.step == 0) {
1007
ret.writeTxt = "admin";
1009
else if (inputData.step == 1) {
1011
ret.writeTxt = "generate";
1016
ret.writeTxt = "quit";
1020
else if (keyEdit.doCheck(GET_LINE, "cardedit.genkeys.backup_enc") ||
1021
keyEdit.doCheck(GET_BOOL, "cardedit.genkeys.backup_enc")) {
1023
ret.writeTxt = new String(inputData.backupKey);
1025
else if (keyEdit.doCheck(GET_BOOL, "cardedit.genkeys.replace_keys")) {
1029
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1030
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
1032
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1033
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
1035
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.enter")) {
1037
ret.writeTxt = inputData.backupPasswd;
1039
else if (keyEdit.doCheck(GET_LINE, "keygen.valid")) {
1041
ret.writeTxt = new String(inputData.expiry);
1043
else if (keyEdit.doCheck(GET_LINE, "cardedit.genkeys.size")) {
1045
ret.writeTxt = "2048";
1047
else if (keyEdit.doCheck(GET_LINE, "keygen.name")) {
1049
ret.writeTxt = inputData.name;
1051
else if (keyEdit.doCheck(GET_LINE, "keygen.email")) {
1053
ret.writeTxt = inputData.email;
1055
else if (keyEdit.doCheck(GET_LINE, "keygen.comment")) {
1057
if (inputData.comment) {
1058
ret.writeTxt = inputData.comment;
1066
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1071
function cardAdminDataCallback(inputData, keyEdit, ret) {
1077
if (keyEdit.doCheck(GET_LINE, "cardedit.prompt")) {
1080
switch(inputData.step) {
1082
ret.writeTxt = "admin";
1085
ret.writeTxt = "name";
1088
ret.writeTxt = "lang";
1091
ret.writeTxt = "sex";
1094
ret.writeTxt = "url";
1097
ret.writeTxt = "login";
1100
if (inputData.forcepin != 0) {
1101
ret.writeTxt = "forcesig";
1105
ret.writeTxt = "quit";
1111
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1112
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
1114
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1115
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
1117
else if (keyEdit.doCheck(GET_LINE, "keygen.smartcard.surname")) {
1119
ret.writeTxt = inputData.firstname.replace(/^$/, "-");;
1121
else if (keyEdit.doCheck(GET_LINE, "keygen.smartcard.givenname")) {
1123
ret.writeTxt = inputData.name.replace(/^$/, "-");;
1125
else if (keyEdit.doCheck(GET_LINE, "cardedit.change_sex")) {
1127
ret.writeTxt = inputData.sex;
1129
else if (keyEdit.doCheck(GET_LINE, "cardedit.change_lang")) {
1131
ret.writeTxt = inputData.lang.replace(/^$/, "-");;
1133
else if (keyEdit.doCheck(GET_LINE, "cardedit.change_url")) {
1135
ret.writeTxt = inputData.url.replace(/^$/, "-");;
1137
else if (keyEdit.doCheck(GET_LINE, "cardedit.change_login")) {
1139
ret.writeTxt = inputData.login.replace(/^$/, "-");
1143
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1148
function cardChangePinCallback(inputData, keyEdit, ret) {
1152
if (keyEdit.doCheck(GET_LINE, "cardedit.prompt")) {
1155
switch (inputData.step) {
1157
ret.writeTxt = "admin";
1160
ret.writeTxt = "passwd";
1163
ret.writeTxt = "quit";
1169
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1171
ret.writeTxt = inputData.adminPin;
1173
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1175
ret.writeTxt = inputData.oldPin;
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")) {
1182
ret.writeTxt = inputData.newPin;
1184
else if (keyEdit.doCheck(GET_LINE, "cardutil.change_pin.menu")) {
1186
++inputData.pinStep;
1187
if (inputData.pinStep == 1) {
1188
ret.writeTxt = inputData.action.toString();
1197
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1202
function addPhotoCallback(inputData, keyEdit, ret) {
1206
if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
1208
ret.writeTxt = "save";
1211
else if (keyEdit.doCheck(GET_LINE, "photoid.jpeg.add" )) {
1212
if (inputData.step == 0) {
1215
ret.writeTxt = inputData.file;
1222
else if (keyEdit.doCheck(GET_BOOL, "photoid.jpeg.size")) {
1224
ret.writeTxt = "Y"; // add large file
1226
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1227
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
1229
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1230
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
1234
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1239
function enigCardAdminObserver(guiObserver, isDosLike) {
1240
this._guiObserver = guiObserver;
1241
this.isDosLike = isDosLike;
1244
enigCardAdminObserver.prototype =
1249
QueryInterface : function(iid)
1251
if (iid.equals(Ci.nsIEnigMimeReadCallback) ||
1252
iid.equals(Ci.nsISupports) )
1255
throw Components.results.NS_NOINTERFACE;
1258
onDataAvailable: function (data) {
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, "\\");
1264
if (this._failureCode) {
1265
ret = "[GNUPG:] ENIGMAIL_FAILURE "+data;
1267
if (data.indexOf("[GNUPG:] SC_OP_FAILURE")>=0) {
1268
this._failureCode = 1;
1270
if (this._guiObserver) {
1271
this._guiObserver.onDataAvailable(data);
1277
function enigChangePasswdObserver() {}
1279
enigChangePasswdObserver.prototype =
1282
passphraseStatus: 0,
1284
QueryInterface : function(iid)
1286
if (iid.equals(Ci.nsIEnigMimeReadCallback) ||
1287
iid.equals(Ci.nsISupports) )
1290
throw Components.results.NS_NOINTERFACE;
1293
onDataAvailable: function (data) {
1295
Ec.DEBUG_LOG("keyManagmenent.jsm: enigChangePasswdObserver.onDataAvailable: data="+data+"\n");
1296
if (this._failureCode) {
1297
ret = "[GNUPG:] ENIGMAIL_FAILURE "+data;
1299
if (data.indexOf("[GNUPG:] GOOD_PASSPHRASE")>=0) {
1300
this.passphraseStatus = 1;
1302
else if (data.indexOf("[GNUPG:] BAD_PASSPHRASE")>=0) {
1303
this.passphraseStatus = -1;