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;
42
const Cc = Components.classes;
43
const Ci = Components.interfaces;
45
const GET_BOOL = "GET_BOOL";
46
const GET_LINE = "GET_LINE";
47
const GET_HIDDEN = "GET_HIDDEN";
50
function KeyEditor(reqObserver, callbackFunc, inputData) {
51
this._reqObserver = reqObserver;
52
this._callbackFunc = callbackFunc;
53
this._inputData = inputData;
55
if (this._inputData && this._inputData.cardAdmin) {
56
this._saveCmd = "quit";
59
this._saveCmd = "save";
62
KeyEditor.prototype = {
69
setStdin: function(pipe) {
71
if (this._data.length > 0) this.processData();
74
gotData: function(data) {
75
//Ec.DEBUG_LOG("keyManagement.jsm: KeyEditor.gotData: '"+data+"'\n");
76
this._data += data.replace(/\r\n/g, "\n");
80
processData: function() {
81
//Ec.DEBUG_LOG("keyManagement.jsm: KeyEditor.processData\n");
83
while (this._data.length > 0 && this._stdin) {
84
var index = this._data.indexOf("\n");
90
txt = this._data.substr(0, index);
91
this._data = this._data.substr(index+1);
97
closeStdin: function() {
98
Ec.DEBUG_LOG("keyManagement.jsm: KeyEditor.closeStdin:\n");
105
done: function(parentCallback, exitCode) {
106
Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.done: exitCode="+exitCode+"\n");
108
if (exitCode == 0) exitCode = this._exitCode;
110
if (exitCode == 0 && typeof(this._inputData) == "object" && this._inputData.usePassphrase) {
114
Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.done: returning exitCode "+exitCode+"\n");
116
parentCallback(exitCode, this.errorMsg);
119
writeLine: function (inputData) {
120
Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.writeLine: '"+inputData+"'\n");
121
this._stdin.write(inputData+"\n");
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) {
134
this.processLine(txt);
138
doCheck: function(inputType, promptVal) {
139
var a=this._txt.split(/ /);
140
return ((a[1] == inputType) && (a[2] == promptVal))
143
getText: function() {
147
processLine: function(txt) {
148
Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.processLine: '"+txt+"'\n");
149
var r = { quitNow: false,
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");
158
this.errorMsg=Ec.getString("badPhrase");
159
Ec.clearCachedPassphrase();
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");
167
if (txt.indexOf("[GNUPG:] ENIGMAIL_FAILURE")==0) {
168
Ec.DEBUG_LOG("keyManagmenent.jsm: KeyEditor.processLine: detected general failure\n");
171
this.errorMsg = txt.substr(26);
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");
179
if (txt.indexOf("[GNUPG:] GET_") < 0) {
180
// return if no "GET" statement
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);
197
if (r.errorMsg && r.errorMsg.length > 0)
198
this.errorMsg = r.errorMsg;
213
this.writeLine(this._saveCmd);
217
Ec.DEBUG_LOG("no more data\n");
221
if (r.exitCode != null)
222
this._exitCode = r.exitCode;
225
QueryInterface: function (iid) {
226
if (!iid.equals(Ci.nsISupports))
227
throw Components.results.NS_ERROR_NO_INTERFACE;
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
239
var EnigmailKeyMgmt = {
241
editKey: function (parent, needPassphrase, userId, keyId, editCmd, inputData, callbackFunc, requestObserver, parentCallback) {
242
Ec.DEBUG_LOG("keyManagmenent.jsm: editKey: parent="+parent+", editCmd="+editCmd+"\n");
244
var enigmailSvc = Ec.getService(parent);
246
Ec.ERROR_LOG("keyManagmenent.jsm: Enigmail.editKey: not yet initialized\n");
247
parentCallback(-1, Ec.getString("notInit"));
251
var keyIdList = keyId.split(" ");
252
var args = Ec.getAgentArgs(false);
254
var statusFlags = new Object();
257
var useAgentObj = new Object();
259
if (needPassphrase) {
260
args=args.concat(Ec.passwdCommand());
262
var passwdObj = new Object();
264
if (!Ec.getPassphrase(parent, passwdObj, useAgentObj, 0)) {
265
Ec.ERROR_LOG("keyManagmenent.jsm: editKey: Error - no passphrase supplied\n");
267
parentCallback(-1, Ec.getString("noPassphrase"));
271
passphrase = passwdObj.value;
275
useAgentObj.value = true;
278
args=args.concat(["--no-tty", "--status-fd", "1", "--logger-fd", "1", "--command-fd", "0"]);
279
if (userId) args=args.concat(["-u", userId]);
281
if (typeof(editCmd) == "string") {
282
editCmdArr = [ editCmd ];
285
editCmdArr = editCmd;
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);
295
else if (editCmdArr[0].indexOf("--")==0) {
296
args=args.concat(editCmd);
297
args=args.concat(keyIdList);
300
args=args.concat(["--ask-cert-level", "--edit-key", keyId]);
301
args=args.concat(editCmd);
305
var command= enigmailSvc.agentPath;
306
Ec.CONSOLE_LOG("enigmail> "+Ec.printCmdLine(command, args)+"\n");
308
var keyEdit = new KeyEditor(requestObserver, callbackFunc, inputData);
311
var proc = subprocess.call({
315
environment: Ec.getEnvList(),
316
stdin: function (stdin) {
317
if (needPassphrase && Ec.requirePassword()) {
318
stdin.write(passphrase+"\n");
320
keyEdit.setStdin(stdin);
322
stdout: function(data) {
323
keyEdit.gotData(data);
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);
332
Ec.ERROR_LOG("keyManagement.jsm: editKey: "+command.path+" failed\n");
333
parentCallback(-1, "");
337
setKeyTrust: function (parent, keyId, trustLevel, callbackFunc) {
338
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.setKeyTrust: trustLevel="+trustLevel+", keyId="+keyId+"\n");
340
return this.editKey(parent, false, null, keyId, "trust",
341
{ trustLevel: trustLevel},
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 },
358
genRevokeCert: function (parent, keyId, outFile, reasonCode, reasonText, callbackFunc) {
359
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.genRevokeCert: keyId="+keyId+"\n");
361
var r= this.editKey(parent, true, null, keyId, "revoke",
363
reasonCode: reasonCode,
364
reasonText: Ec.convertFromUnicode(reasonText),
365
usePassphrase: true },
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",
380
usePassphrase: true },
387
deleteKey: function (parent, keyId, deleteSecretKey, callbackFunc) {
388
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.addUid: keyId="+keyId+", deleteSecretKey="+deleteSecretKey+"\n");
390
var cmd = (deleteSecretKey ? "--delete-secret-and-public-key" : "--delete-key");
391
var r= this.editKey(parent, false, null, keyId, cmd,
392
{ usePassphrase: true },
399
changePassphrase: function (parent, keyId, oldPw, newPw, callbackFunc) {
400
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.changePassphrase: keyId="+keyId+"\n");
402
var pwdObserver = new ChangePasswdObserver();
403
var r= this.editKey(parent, false, null, keyId, "passwd",
406
useAgent: Ec.enigmailSvc.useGpgAgent(),
408
observer: pwdObserver,
409
usePassphrase: true },
410
changePassphraseCallback,
417
enableDisableKey: function (parent, keyId, disableKey, callbackFunc) {
418
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.enableDisableKey: keyId="+keyId+", disableKey="+disableKey+"\n");
420
var cmd = (disableKey ? "disable" : "enable");
421
var r= this.editKey(parent, false, null, keyId, cmd,
422
{ usePassphrase: true },
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,
434
usePassphrase: true },
435
setPrimaryUidCallback,
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,
447
usePassphrase: true },
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,
460
usePassphrase: true },
467
addPhoto: function (parent, keyId, photoFile, callbackFunc) {
468
Ec.DEBUG_LOG("keyManagmenent.jsm: Enigmail.addPhoto: keyId="+keyId+"\n");
470
var photoFileName = Ec.getEscapedFilename(Ec.getFilePath(photoFile.QueryInterface(Ec.getLocalFileApi())));
472
var r = this.editKey(parent, true, null, keyId, "addphoto",
473
{ file: photoFileName,
475
usePassphrase: true },
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"] ,
488
name: Ec.convertFromUnicode(name),
490
comment: Ec.convertFromUnicode(comment),
492
backupPasswd: backupPasswd,
494
backupKey: (backupPasswd.length > 0 ? "Y" : "N"),
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"],
508
firstname: firstname,
514
forcepin: forcepin },
515
cardAdminDataCallback,
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);
526
var r = this.editKey(parent, enigmailSvc.useGpgAgent(), null, "", ["--with-colons", "--card-edit"],
533
adminPin: adminPin },
534
cardChangePinCallback,
543
function signKeyCallback(inputData, keyEdit, ret) {
548
if (keyEdit.doCheck(GET_BOOL, "sign_uid.okay" )) {
552
else if (keyEdit.doCheck(GET_BOOL, "keyedit.sign_all.okay" )) {
556
else if (keyEdit.doCheck(GET_LINE, "sign_uid.expire" )) {
560
else if (keyEdit.doCheck(GET_LINE, "trustsig_prompt.trust_value" )) {
564
else if (keyEdit.doCheck(GET_LINE, "trustsig_prompt.trust_depth" )) {
568
else if (keyEdit.doCheck(GET_LINE, "trustsig_prompt.trust_regexp" )) {
571
else if (keyEdit.doCheck(GET_LINE, "siggen.valid" )) {
575
else if (keyEdit.doCheck(GET_BOOL, "sign_uid.local_promote_okay" )) {
579
else if (keyEdit.doCheck(GET_LINE, "sign_uid.class" )) {
581
ret.writeTxt = new String(inputData.trustLevel);
583
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
584
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
586
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
587
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
589
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
595
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
600
function keyTrustCallback(inputData, keyEdit, ret) {
604
if (keyEdit.doCheck(GET_LINE, "edit_ownertrust.value" )) {
606
ret.writeTxt = new String(inputData.trustLevel);
608
else if (keyEdit.doCheck(GET_BOOL, "edit_ownertrust.set_ultimate.okay")) {
612
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
616
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
617
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
619
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
620
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
624
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
630
function addUidCallback(inputData, keyEdit, ret) {
634
if (keyEdit.doCheck(GET_LINE, "keygen.name" )) {
635
++inputData.nameAsked;
636
if (inputData.nameAsked==1) {
638
ret.writeTxt = inputData.name;
643
ret.errorMsg="Invalid name (too short)";
646
else if (keyEdit.doCheck(GET_LINE, "keygen.email")) {
647
++inputData.emailAsked;
648
if (inputData.emailAsked==1) {
650
ret.writeTxt = inputData.email;
655
ret.errorMsg="Invalid email";
658
else if (keyEdit.doCheck(GET_LINE, "keygen.comment")) {
660
if (inputData.comment) {
661
ret.writeTxt = inputData.comment;
667
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
671
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
672
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
674
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
675
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
679
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
685
function revokeCertCallback(inputData, keyEdit, ret) {
689
if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.code" )) {
691
ret.writeTxt = new String(inputData.reasonCode);
693
else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.text" )) {
697
else if (keyEdit.doCheck(GET_BOOL, "gen_revoke.okay")) {
701
else if (keyEdit.doCheck(GET_BOOL, "ask_revocation_reason.okay" )) {
705
else if (keyEdit.doCheck(GET_BOOL, "openfile.overwrite.okay" )) {
709
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
710
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
712
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
713
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
715
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
721
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
727
function setPrimaryUidCallback(inputData, keyEdit, ret) {
731
if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
733
switch (inputData.step) {
736
ret.writeTxt = "uid "+inputData.idNumber;
740
ret.writeTxt = "primary";
754
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
760
function changePassphraseCallback(inputData, keyEdit, ret) {
764
if (keyEdit.doCheck(GET_HIDDEN, "passphrase.enter")) {
765
switch (inputData.observer.passphraseStatus) {
767
ret.writeTxt = inputData.oldPw;
771
ret.writeTxt = inputData.newPw;
780
else if (keyEdit.doCheck(GET_BOOL, "change_passwd.empty.okay")) {
784
else if (keyEdit.doCheck(GET_LINE, "keyedit.prompt")) {
785
if (inputData.useAgent) {
794
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
800
function deleteUidCallback(inputData, keyEdit, ret) {
804
if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
806
switch (inputData.step) {
809
ret.writeTxt = "uid "+inputData.idNumber;
813
ret.writeTxt = "deluid";
824
else if (keyEdit.doCheck(GET_BOOL, "keyedit.remove.uid.okay" )) {
829
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
830
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
832
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
833
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
837
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
843
function revokeUidCallback(inputData, keyEdit, ret) {
847
if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
849
switch (inputData.step) {
852
ret.writeTxt = "uid "+inputData.idNumber;
856
ret.writeTxt = "revuid";
867
else if (keyEdit.doCheck(GET_BOOL, "keyedit.revoke.uid.okay" )) {
872
else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.code")) {
875
ret.writeTxt = "0"; // no reason specified
877
else if (keyEdit.doCheck(GET_LINE, "ask_revocation_reason.text")) {
882
else if (keyEdit.doCheck(GET_BOOL, "ask_revocation_reason.okay")) {
887
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
888
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
890
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
891
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
895
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
901
function deleteKeyCallback(inputData, keyEdit, ret) {
905
if (keyEdit.doCheck(GET_BOOL, "delete_key.secret.okay")) {
909
else if (keyEdit.doCheck(GET_BOOL, "keyedit.remove.subkey.okay")) {
913
else if (keyEdit.doCheck(GET_BOOL, "delete_key.okay" )) {
917
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
918
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
920
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
921
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
925
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
930
function GetPin(domWindow, promptMsg, ret) {
931
Ec.DEBUG_LOG("keyManagmenent.jsm: GetPin: \n");
933
var passwdObj = {value: ""};
938
var promptService = Cc[NS_PROMPTSERVICE_CONTRACTID].getService(Ci.nsIPromptService);
939
success = promptService.promptPassword(domWindow,
940
Ec.getString("Enigmail"),
947
ret.errorMsg = Ec.getString("noPassphrase");
952
Ec.DEBUG_LOG("keyManagmenent.jsm: GetPin: got pin\n");
953
ret.writeTxt = passwdObj.value;
958
function genCardKeyCallback(inputData, keyEdit, ret) {
964
if (keyEdit.doCheck(GET_LINE, "cardedit.prompt")) {
965
if (inputData.step == 0) {
967
ret.writeTxt = "admin";
969
else if (inputData.step == 1) {
971
ret.writeTxt = "generate";
976
ret.writeTxt = "quit";
980
else if (keyEdit.doCheck(GET_LINE, "cardedit.genkeys.backup_enc") ||
981
keyEdit.doCheck(GET_BOOL, "cardedit.genkeys.backup_enc")) {
983
ret.writeTxt = new String(inputData.backupKey);
985
else if (keyEdit.doCheck(GET_BOOL, "cardedit.genkeys.replace_keys")) {
989
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
990
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
992
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
993
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
995
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.enter")) {
997
ret.writeTxt = inputData.backupPasswd;
999
else if (keyEdit.doCheck(GET_LINE, "keygen.valid")) {
1001
ret.writeTxt = new String(inputData.expiry);
1003
else if (keyEdit.doCheck(GET_LINE, "cardedit.genkeys.size")) {
1005
ret.writeTxt = "2048";
1007
else if (keyEdit.doCheck(GET_LINE, "keygen.name")) {
1009
ret.writeTxt = inputData.name;
1011
else if (keyEdit.doCheck(GET_LINE, "keygen.email")) {
1013
ret.writeTxt = inputData.email;
1015
else if (keyEdit.doCheck(GET_LINE, "keygen.comment")) {
1017
if (inputData.comment) {
1018
ret.writeTxt = inputData.comment;
1026
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1031
function cardAdminDataCallback(inputData, keyEdit, ret) {
1037
if (keyEdit.doCheck(GET_LINE, "cardedit.prompt")) {
1040
switch(inputData.step) {
1042
ret.writeTxt = "admin";
1045
ret.writeTxt = "name";
1048
ret.writeTxt = "lang";
1051
ret.writeTxt = "sex";
1054
ret.writeTxt = "url";
1057
ret.writeTxt = "login";
1060
if (inputData.forcepin != 0) {
1061
ret.writeTxt = "forcesig";
1065
ret.writeTxt = "quit";
1071
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1072
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
1074
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1075
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
1077
else if (keyEdit.doCheck(GET_LINE, "keygen.smartcard.surname")) {
1079
ret.writeTxt = inputData.firstname.replace(/^$/, "-");;
1081
else if (keyEdit.doCheck(GET_LINE, "keygen.smartcard.givenname")) {
1083
ret.writeTxt = inputData.name.replace(/^$/, "-");;
1085
else if (keyEdit.doCheck(GET_LINE, "cardedit.change_sex")) {
1087
ret.writeTxt = inputData.sex;
1089
else if (keyEdit.doCheck(GET_LINE, "cardedit.change_lang")) {
1091
ret.writeTxt = inputData.lang.replace(/^$/, "-");;
1093
else if (keyEdit.doCheck(GET_LINE, "cardedit.change_url")) {
1095
ret.writeTxt = inputData.url.replace(/^$/, "-");;
1097
else if (keyEdit.doCheck(GET_LINE, "cardedit.change_login")) {
1099
ret.writeTxt = inputData.login.replace(/^$/, "-");
1103
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1108
function cardChangePinCallback(inputData, keyEdit, ret) {
1112
if (keyEdit.doCheck(GET_LINE, "cardedit.prompt")) {
1115
switch (inputData.step) {
1117
ret.writeTxt = "admin";
1120
ret.writeTxt = "passwd";
1123
ret.writeTxt = "quit";
1129
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1131
ret.writeTxt = inputData.adminPin;
1133
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1135
ret.writeTxt = inputData.oldPin;
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")) {
1142
ret.writeTxt = inputData.newPin;
1144
else if (keyEdit.doCheck(GET_LINE, "cardutil.change_pin.menu")) {
1146
++inputData.pinStep;
1147
if (inputData.pinStep == 1) {
1148
ret.writeTxt = inputData.action.toString();
1157
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1162
function addPhotoCallback(inputData, keyEdit, ret) {
1166
if (keyEdit.doCheck(GET_LINE, "keyedit.prompt" )) {
1168
ret.writeTxt = "save";
1171
else if (keyEdit.doCheck(GET_LINE, "photoid.jpeg.add" )) {
1172
if (inputData.step == 0) {
1175
ret.writeTxt = inputData.file;
1182
else if (keyEdit.doCheck(GET_BOOL, "photoid.jpeg.size")) {
1184
ret.writeTxt = "Y"; // add large file
1186
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.adminpin.ask")) {
1187
GetPin(inputData.parent, Ec.getString("enterAdminPin"), ret);
1189
else if (keyEdit.doCheck(GET_HIDDEN, "passphrase.pin.ask")) {
1190
GetPin(inputData.parent, Ec.getString("enterCardPin"), ret);
1194
Ec.ERROR_LOG("Unknown command prompt: "+keyEdit.getText()+"\n");
1199
function enigCardAdminObserver(guiObserver, isDosLike) {
1200
this._guiObserver = guiObserver;
1201
this.isDosLike = isDosLike;
1204
enigCardAdminObserver.prototype =
1209
QueryInterface : function(iid)
1211
if (iid.equals(Ci.nsIEnigMimeReadCallback) ||
1212
iid.equals(Ci.nsISupports) )
1215
throw Components.results.NS_NOINTERFACE;
1218
onDataAvailable: function (data) {
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, "\\");
1224
if (data.indexOf("[GNUPG:] SC_OP_FAILURE")>=0) {
1225
data=data.substr(23);
1227
data = "[GNUPG:] BAD_PASSPHRASE 0";
1228
this._failureCode = 2;
1231
this._failureCode = 1;
1233
if (this._failureCode == 1) {
1234
ret = "[GNUPG:] ENIGMAIL_FAILURE "+data;
1236
if (this._guiObserver) {
1237
this._guiObserver.onDataAvailable(data);
1243
function ChangePasswdObserver() {}
1245
ChangePasswdObserver.prototype =
1248
passphraseStatus: 0,
1250
QueryInterface : function(iid)
1252
if (iid.equals(Ci.nsIEnigMimeReadCallback) ||
1253
iid.equals(Ci.nsISupports) )
1256
throw Components.results.NS_NOINTERFACE;
1259
onDataAvailable: function (data) {
1261
Ec.DEBUG_LOG("keyManagmenent.jsm: ChangePasswdObserver.onDataAvailable: data="+data+"\n");
1262
if (this._failureCode) {
1263
ret = "[GNUPG:] ENIGMAIL_FAILURE "+data;
1265
if (data.indexOf("[GNUPG:] GOOD_PASSPHRASE")>=0) {
1266
this.passphraseStatus = 1;
1268
else if (data.indexOf("[GNUPG:] BAD_PASSPHRASE")>=0) {
1269
this.passphraseStatus = -1;