forked from goatpig/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtdialogs.py
13850 lines (11230 loc) · 560 KB
/
qtdialogs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: UTF-8 -*-
################################################################################
# #
# Copyright (C) 2011-2015, Armory Technologies, Inc. #
# Distributed under the GNU Affero General Public License (AGPL v3) #
# See LICENSE or http://www.gnu.org/licenses/agpl.html #
# #
################################################################################
import functools
import shutil
import socket
import sys
import time
from zipfile import ZipFile, ZIP_DEFLATED
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from armoryengine.ALL import *
from armorycolors import Colors, htmlColor
from armorymodels import *
import qrc_img_resources
from qtdefines import *
from armoryengine.PyBtcAddress import calcWalletIDFromRoot
from armoryengine.MultiSigUtils import calcLockboxID, createLockboxEntryStr,\
LBPREFIX, isBareLockbox, isP2SHLockbox
from ui.MultiSigModels import LockboxDisplayModel, LockboxDisplayProxy,\
LOCKBOXCOLS
from armoryengine.PyBtcWalletRecovery import RECOVERMODE
from armoryengine.ArmoryUtils import BTC_HOME_DIR
from ui.TreeViewGUI import AddressTreeModel
from ui.QrCodeMatrix import CreateQRMatrix
from ui.SignerSelectDialog import SignerLabelFrame
NO_CHANGE = 'NoChange'
MIN_PASSWD_WIDTH = lambda obj: tightSizeStr(obj, '*' * 16)[0]
STRETCH = 'Stretch'
CLICKED = 'clicked()'
BACKUP_TYPE_135A = '1.35a'
BACKUP_TYPE_135C = '1.35c'
BACKUP_TYPE_0_TEXT = 'Version 0 (from script, 9 lines)'
BACKUP_TYPE_135a_TEXT = 'Version 1.35a (5 lines Unencrypted)'
BACKUP_TYPE_135a_SP_TEXT = u'Version 1.35a (5 lines + SecurePrint\u200b\u2122)'
BACKUP_TYPE_135c_TEXT = 'Version 1.35c (3 lines Unencrypted)'
BACKUP_TYPE_135c_SP_TEXT = u'Version 1.35c (3 lines + SecurePrint\u200b\u2122)'
MAX_QR_SIZE = 198
MAX_SATOSHIS = 2100000000000000
################################################################################
class DlgUnlockWallet(ArmoryDialog):
def __init__(self, wlt, parent=None, main=None, unlockMsg='Unlock Wallet', \
returnResult=False, returnPassphrase=False):
super(DlgUnlockWallet, self).__init__(parent, main)
self.wlt = wlt
self.returnResult = returnResult
self.returnPassphrase = returnPassphrase
##### Upper layout
lblDescr = QLabel(self.tr("Enter your passphrase to unlock this wallet"))
lblPasswd = QLabel(self.tr("Passphrase:"))
self.edtPasswd = QLineEdit()
self.edtPasswd.setEchoMode(QLineEdit.Password)
self.edtPasswd.setMinimumWidth(MIN_PASSWD_WIDTH(self))
self.edtPasswd.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
self.btnAccept = QPushButton(self.tr("Unlock"))
self.btnCancel = QPushButton(self.tr("Cancel"))
self.connect(self.btnAccept, SIGNAL(CLICKED), self.acceptPassphrase)
self.connect(self.btnCancel, SIGNAL(CLICKED), self.reject)
buttonBox = QDialogButtonBox()
buttonBox.addButton(self.btnAccept, QDialogButtonBox.AcceptRole)
buttonBox.addButton(self.btnCancel, QDialogButtonBox.RejectRole)
layoutUpper = QGridLayout()
layoutUpper.addWidget(lblDescr, 1, 0, 1, 2)
layoutUpper.addWidget(lblPasswd, 2, 0, 1, 1)
layoutUpper.addWidget(self.edtPasswd, 2, 1, 1, 1)
self.frmUpper = QFrame()
self.frmUpper.setLayout(layoutUpper)
##### Lower layout
# Add scrambled keyboard (EN-US only)
ttipScramble = self.main.createToolTipWidget(\
self.tr('Using a visual keyboard to enter your passphrase '
'protects you against simple keyloggers. Scrambling '
'makes it difficult to use, but prevents even loggers '
'that record mouse clicks.'))
self.createKeyButtons()
self.rdoScrambleNone = QRadioButton(self.tr('Regular Keyboard'))
self.rdoScrambleLite = QRadioButton(self.tr('Scrambled (Simple)'))
self.rdoScrambleFull = QRadioButton(self.tr('Scrambled (Dynamic)'))
btngrp = QButtonGroup(self)
btngrp.addButton(self.rdoScrambleNone)
btngrp.addButton(self.rdoScrambleLite)
btngrp.addButton(self.rdoScrambleFull)
btngrp.setExclusive(True)
defaultScramble = self.main.getSettingOrSetDefault('ScrambleDefault', 0)
if defaultScramble == 0:
self.rdoScrambleNone.setChecked(True)
elif defaultScramble == 1:
self.rdoScrambleLite.setChecked(True)
elif defaultScramble == 2:
self.rdoScrambleFull.setChecked(True)
self.connect(self.rdoScrambleNone, SIGNAL(CLICKED), self.changeScramble)
self.connect(self.rdoScrambleLite, SIGNAL(CLICKED), self.changeScramble)
self.connect(self.rdoScrambleFull, SIGNAL(CLICKED), self.changeScramble)
btnRowFrm = makeHorizFrame([self.rdoScrambleNone, \
self.rdoScrambleLite, \
self.rdoScrambleFull, \
STRETCH])
self.layoutKeyboard = QGridLayout()
self.frmKeyboard = QFrame()
self.frmKeyboard.setLayout(self.layoutKeyboard)
showOSD = self.main.getSettingOrSetDefault('KeybdOSD', False)
self.layoutLower = QGridLayout()
self.layoutLower.addWidget(btnRowFrm , 0, 0)
self.layoutLower.addWidget(self.frmKeyboard , 1, 0)
self.frmLower = QFrame()
self.frmLower.setLayout(self.layoutLower)
self.frmLower.setVisible(showOSD)
##### Expand button
self.btnShowOSD = QPushButton(self.tr('Show Keyboard >>>'))
self.btnShowOSD.setCheckable(True)
self.btnShowOSD.setChecked(showOSD)
if showOSD:
self.toggleOSD()
self.connect(self.btnShowOSD, SIGNAL('toggled(bool)'), self.toggleOSD)
frmAccept = makeHorizFrame([self.btnShowOSD, ttipScramble, STRETCH, buttonBox])
##### Complete Layout
layout = QVBoxLayout()
layout.addWidget(self.frmUpper)
layout.addWidget(frmAccept)
layout.addWidget(self.frmLower)
self.setLayout(layout)
self.setWindowTitle(unlockMsg + ' - ' + wlt.uniqueIDB58)
# Add scrambled keyboard
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.changeScramble()
self.redrawKeys()
#############################################################################
def toggleOSD(self, *args):
isChk = self.btnShowOSD.isChecked()
self.main.settings.set('KeybdOSD', isChk)
self.frmLower.setVisible(isChk)
if isChk:
self.btnShowOSD.setText(self.tr('Hide Keyboard <<<'))
else:
self.btnShowOSD.setText(self.tr('Show Keyboard >>>'))
#############################################################################
def createKeyboardKeyButton(self, keyLow, keyUp, defRow, special=None):
theBtn = LetterButton(keyLow, keyUp, defRow, special, self.edtPasswd, self)
self.connect(theBtn, SIGNAL(CLICKED), theBtn.insertLetter)
theBtn.setMaximumWidth(40)
return theBtn
#############################################################################
def redrawKeys(self):
for btn in self.btnList:
btn.setText(btn.upper if self.btnShift.isChecked() else btn.lower)
self.btnShift.setText(self.tr('SHIFT'))
self.btnSpace.setText(self.tr('SPACE'))
self.btnDelete.setText(self.tr('DEL'))
#############################################################################
def deleteKeyboard(self):
for btn in self.btnList:
btn.setParent(None)
del btn
self.btnList = []
self.btnShift.setParent(None)
self.btnSpace.setParent(None)
self.btnDelete.setParent(None)
del self.btnShift
del self.btnSpace
del self.btnDelete
del self.frmKeyboard
del self.layoutKeyboard
#############################################################################
def createKeyButtons(self):
# TODO: Add some locale-agnostic method here, that could replace
# the letter arrays with something more appropriate for non en-us
self.letLower = r"`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./"
self.letUpper = r'~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?'
self.letRows = r'11111111111112222222222222333333333334444444444'
self.letPairs = zip(self.letLower, self.letUpper, self.letRows)
self.btnList = []
for l, u, r in zip(self.letLower, self.letUpper, self.letRows):
if l == '7':
# Because QPushButtons interpret ampersands as special characters
u = 2 * u
if l.isdigit():
self.btnList.append(self.createKeyboardKeyButton('#' + l, u, int(r)))
else:
self.btnList.append(self.createKeyboardKeyButton(l, u, int(r)))
# Add shift and space keys
self.btnShift = self.createKeyboardKeyButton('', '', 5, 'shift')
self.btnSpace = self.createKeyboardKeyButton(' ', ' ', 5, 'space')
self.btnDelete = self.createKeyboardKeyButton(' ', ' ', 5, 'delete')
self.btnShift.setCheckable(True)
self.btnShift.setChecked(False)
#############################################################################
def reshuffleKeys(self):
if self.rdoScrambleFull.isChecked():
self.changeScramble()
#############################################################################
def changeScramble(self):
self.deleteKeyboard()
self.frmKeyboard = QFrame()
self.layoutKeyboard = QGridLayout()
self.createKeyButtons()
if self.rdoScrambleNone.isChecked():
opt = 0
prevRow = 1
col = 0
for btn in self.btnList:
row = btn.defRow
if not row == prevRow:
col = 0
if row > 3 and col == 0:
col += 1
prevRow = row
self.layoutKeyboard.addWidget(btn, row, col)
col += 1
self.layoutKeyboard.addWidget(self.btnShift, self.btnShift.defRow, 0, 1, 3)
self.layoutKeyboard.addWidget(self.btnSpace, self.btnSpace.defRow, 4, 1, 5)
self.layoutKeyboard.addWidget(self.btnDelete, self.btnDelete.defRow, 11, 1, 2)
self.btnShift.setMaximumWidth(1000)
self.btnSpace.setMaximumWidth(1000)
self.btnDelete.setMaximumWidth(1000)
elif self.rdoScrambleLite.isChecked():
opt = 1
nchar = len(self.btnList)
rnd = SecureBinaryData().GenerateRandom(2 * nchar).toBinStr()
newBtnList = [[self.btnList[i], rnd[2 * i:2 * (i + 1)]] for i in range(nchar)]
newBtnList.sort(key=lambda x: x[1])
prevRow = 0
col = 0
for i, btn in enumerate(newBtnList):
row = i / 12
if not row == prevRow:
col = 0
prevRow = row
self.layoutKeyboard.addWidget(btn[0], row, col)
col += 1
self.layoutKeyboard.addWidget(self.btnShift, self.btnShift.defRow, 0, 1, 3)
self.layoutKeyboard.addWidget(self.btnSpace, self.btnSpace.defRow, 4, 1, 5)
self.layoutKeyboard.addWidget(self.btnDelete, self.btnDelete.defRow, 10, 1, 2)
self.btnShift.setMaximumWidth(1000)
self.btnSpace.setMaximumWidth(1000)
self.btnDelete.setMaximumWidth(1000)
elif self.rdoScrambleFull.isChecked():
opt = 2
extBtnList = self.btnList[:]
extBtnList.extend([self.btnShift, self.btnSpace])
nchar = len(extBtnList)
rnd = SecureBinaryData().GenerateRandom(2 * nchar).toBinStr()
newBtnList = [[extBtnList[i], rnd[2 * i:2 * (i + 1)]] for i in range(nchar)]
newBtnList.sort(key=lambda x: x[1])
prevRow = 0
col = 0
for i, btn in enumerate(newBtnList):
row = i / 12
if not row == prevRow:
col = 0
prevRow = row
self.layoutKeyboard.addWidget(btn[0], row, col)
col += 1
self.layoutKeyboard.addWidget(self.btnDelete, self.btnDelete.defRow - 1, 11, 1, 2)
self.btnShift.setMaximumWidth(40)
self.btnSpace.setMaximumWidth(40)
self.btnDelete.setMaximumWidth(40)
self.frmKeyboard.setLayout(self.layoutKeyboard)
self.layoutLower.addWidget(self.frmKeyboard, 1, 0)
self.main.settings.set('ScrambleDefault', opt)
self.redrawKeys()
#############################################################################
def acceptPassphrase(self):
self.securePassphrase = SecureBinaryData(str(self.edtPasswd.text()))
self.edtPasswd.setText('')
if self.returnResult:
self.accept()
return
try:
if self.returnPassphrase == False:
unlockProgress = DlgProgress(self, self.main, HBar=1,
Title=self.tr("Unlocking Wallet"))
unlockProgress.exec_(self.wlt.unlock, securePassphrase=self.securePassphrase)
self.securePassphrase.destroy()
else:
if self.wlt.verifyPassphrase(self.securePassphrase) == False:
raise PassphraseError
self.accept()
except PassphraseError:
QMessageBox.critical(self, self.tr('Invalid Passphrase'), \
self.tr('That passphrase is not correct!'), QMessageBox.Ok)
self.securePassphrase.destroy()
self.edtPasswd.setText('')
return
#############################################################################
class LetterButton(QPushButton):
def __init__(self, Low, Up, Row, Spec, edtTarget, parent):
super(LetterButton, self).__init__('')
self.lower = Low
self.upper = Up
self.defRow = Row
self.special = Spec
self.target = edtTarget
self.parent = parent
if self.special:
super(LetterButton, self).setFont(GETFONT('Var', 8))
else:
super(LetterButton, self).setFont(GETFONT('Fixed', 10))
if self.special == 'space':
self.setText(self.tr('SPACE'))
self.lower = ' '
self.upper = ' '
self.special = 5
elif self.special == 'shift':
self.setText(self.tr('SHIFT'))
self.special = 5
self.insertLetter = self.pressShift
elif self.special == 'delete':
self.setText(self.tr('DEL'))
self.special = 5
self.insertLetter = self.pressBackspace
def insertLetter(self):
currPwd = str(self.parent.edtPasswd.text())
insChar = self.upper if self.parent.btnShift.isChecked() else self.lower
if len(insChar) == 2 and insChar.startswith('#'):
insChar = insChar[1]
self.parent.edtPasswd.setText(currPwd + insChar)
self.parent.reshuffleKeys()
def pressShift(self):
self.parent.redrawKeys()
def pressBackspace(self):
currPwd = str(self.parent.edtPasswd.text())
if len(currPwd) > 0:
self.parent.edtPasswd.setText(currPwd[:-1])
self.parent.redrawKeys()
################################################################################
class DlgGenericGetPassword(ArmoryDialog):
def __init__(self, descriptionStr, parent=None, main=None):
super(DlgGenericGetPassword, self).__init__(parent, main)
lblDescr = QRichLabel(descriptionStr)
lblPasswd = QRichLabel(self.tr("Password:"))
self.edtPasswd = QLineEdit()
self.edtPasswd.setEchoMode(QLineEdit.Password)
self.edtPasswd.setMinimumWidth(MIN_PASSWD_WIDTH(self))
self.edtPasswd.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
self.btnAccept = QPushButton(self.tr("OK"))
self.btnCancel = QPushButton(self.tr("Cancel"))
self.connect(self.btnAccept, SIGNAL(CLICKED), self.accept)
self.connect(self.btnCancel, SIGNAL(CLICKED), self.reject)
buttonBox = QDialogButtonBox()
buttonBox.addButton(self.btnAccept, QDialogButtonBox.AcceptRole)
buttonBox.addButton(self.btnCancel, QDialogButtonBox.RejectRole)
layout = QGridLayout()
layout.addWidget(lblDescr, 1, 0, 1, 2)
layout.addWidget(lblPasswd, 2, 0, 1, 1)
layout.addWidget(self.edtPasswd, 2, 1, 1, 1)
layout.addWidget(buttonBox, 3, 1, 1, 2)
self.setLayout(layout)
self.setWindowTitle(self.tr('Enter Password'))
self.setWindowIcon(QIcon(self.main.iconfile))
################################################################################
# Hack! We need to replicate the DlgBugReport... but to be as safe as
# possible for 0.91.1, we simply duplicate the dialog and modify directly.
# TODO: There's definitely a way to make DlgBugReport more generic so that
# both these contexts can be handled by it.
class DlgInconsistentWltReport(ArmoryDialog):
def __init__(self, parent, main, logPathList):
super(DlgInconsistentWltReport, self).__init__(parent, main)
QMessageBox.critical(self, self.tr('Inconsistent Wallet!'), self.tr(
'<font color="%1" size=4><b><u>Important:</u> Wallet Consistency'
'Issues Detected!</b></font>'
'<br><br>'
'Armory now detects certain kinds of hardware errors, and one'
'or more of your wallets'
'was flagged. The consistency logs need to be analyzed by the'
'Armory team to determine if any further action is required.'
'<br><br>'
'<b>This warning will pop up every time you start Armory until'
'the wallet is fixed</b>').arg(htmlColor('TextWarn')),
QMessageBox.Ok)
# logPathList is [wltID, corruptFolder] pairs
self.logPathList = logPathList[:]
walletList = [self.main.walletMap[wid] for wid,folder in logPathList]
getWltStr = lambda w: '<b>Wallet "%s" (%s)</b>' % \
(w.labelName, w.uniqueIDB58)
if len(logPathList) == 1:
wltDispStr = getWltStr(walletList[0]) + ' is'
else:
strList = [getWltStr(w) for w in walletList]
wltDispStr = ', '.join(strList[:-1]) + ' and ' + strList[-1] + ' are '
lblTopDescr = QRichLabel(self.tr(
'<b><u><font color="%1" size=4>Submit Wallet Analysis Logs for '
'Review</font></u></b><br>').arg(htmlColor('TextWarn')),
hAlign=Qt.AlignHCenter)
lblDescr = QRichLabel(self.tr(
'Armory has detected that %1 is inconsistent, '
'possibly due to hardware errors out of our control. It <u>strongly '
'recommended</u> you submit the wallet logs to the Armory developers '
'for review. Until you hear back from an Armory developer, '
'it is recommended that you: '
'<ul>'
'<li><b>Do not delete any data in your Armory home directory</b></li> '
'<li><b>Do not send or receive any funds with the affected wallet(s)</b></li> '
'<li><b>Create a backup of the wallet analysis logs</b></li> '
'</ul>').arg(wltDispStr))
btnBackupLogs = QPushButton(self.tr("Save backup of log files"))
self.connect(btnBackupLogs, SIGNAL('clicked()'), self.doBackupLogs)
frmBackup = makeHorizFrame(['Stretch', btnBackupLogs, 'Stretch'])
self.lblSubject = QRichLabel(self.tr('Subject:'))
self.edtSubject = QLineEdit()
self.edtSubject.setMaxLength(64)
self.edtSubject.setText("Wallet Consistency Logs")
self.txtDescr = QTextEdit()
self.txtDescr.setFont(GETFONT('Fixed', 9))
w,h = tightSizeNChar(self, 80)
self.txtDescr.setMinimumWidth(w)
self.txtDescr.setMinimumHeight(int(2.5*h))
self.btnCancel = QPushButton(self.tr('Close'))
self.btnbox = QDialogButtonBox()
self.btnbox.addButton(self.btnCancel, QDialogButtonBox.RejectRole)
self.connect(self.btnCancel, SIGNAL(CLICKED), self, SLOT('reject()'))
layout = QGridLayout()
i = -1
i += 1
layout.addWidget(lblTopDescr, i,0, 1,2)
i += 1
layout.addWidget(lblDescr, i,0, 1,2)
i += 1
layout.addWidget(frmBackup, i,0, 1,2)
i += 1
layout.addWidget(HLINE(), i,0, 1,2)
i += 1
layout.addWidget(self.btnbox, i,0, 1,2)
self.setLayout(layout)
self.setWindowTitle(self.tr('Inconsistent Wallet'))
self.setWindowIcon(QIcon(self.main.iconfile))
#############################################################################
def createZipfile(self, zfilePath=None, forceIncludeAllData=False):
"""
If not forceIncludeAllData, then we will exclude wallet file and/or
regular logs, depending on the user's checkbox selection. For making
a user backup, we always want to include everything, regardless of
that selection.
"""
# Should we include wallet files from logs directory?
includeWlt = self.chkIncludeWOW.isChecked()
includeReg = self.chkIncludeReg.isChecked()
# Set to default save path if needed
if zfilePath is None:
zfilePath = os.path.join(ARMORY_HOME_DIR, 'wallet_analyze_logs.zip')
# Remove a previous copy
if os.path.exists(zfilePath):
os.remove(zfilePath)
LOGINFO('Creating archive: %s', zfilePath)
zfile = ZipFile(zfilePath, 'w', ZIP_DEFLATED)
# Iterate over all log directories (usually one)
for wltID,logDir in self.logPathList:
for fn in os.listdir(logDir):
fullpath = os.path.join(logDir, fn)
# If multiple dirs, will see duplicate armorylogs and multipliers
if not os.path.isfile(fullpath):
continue
if not forceIncludeAllData:
# Exclude any wallet files if the checkbox was not checked
if not includeWlt and os.path.getsize(fullpath) >= 8:
# Don't exclude based on file extension, check leading bytes
with open(fullpath, 'rb') as tempopen:
if tempopen.read(8) == '\xbaWALLET\x00':
continue
# Exclude regular logs as well, if desired
if not includeReg and fn in ['armorylog.txt', 'armorycpplog.txt', 'dbLog.txt']:
continue
# If we got here, add file to archive
parentDir = os.path.basename(logDir)
archiveName = '%s_%s_%s' % (wltID, parentDir, fn)
LOGINFO(' Adding %s to archive' % archiveName)
zfile.write(fullpath, archiveName)
zfile.close()
return zfilePath
#############################################################################
def doBackupLogs(self):
saveTo = self.main.getFileSave(ffilter=['Zip files (*.zip)'],
defaultFilename='wallet_analyze_logs.zip')
if not saveTo:
QMessageBox.critical(self, self.tr("Not saved"), self.tr(
'You canceled the backup operation. No backup was made.'),
QMessageBox.Ok)
return
try:
self.createZipfile(saveTo, forceIncludeAllData=True)
QMessageBox.information(self, self.tr('Success'), self.tr(
'The wallet logs were successfully saved to the following'
'location:'
'<br><br>'
'%1'
'<br><br>'
'It is still important to complete the rest of this form'
'and submit the data to the Armory team for review!').arg(saveTo), QMessageBox.Ok)
except:
LOGEXCEPT('Failed to create zip file')
QMessageBox.warning(self, self.tr('Save Failed'), self.tr('There was an '
'error saving a copy of your log files'), QMessageBox.Ok)
################################################################################
class DlgNewWallet(ArmoryDialog):
def __init__(self, parent=None, main=None, initLabel=''):
super(DlgNewWallet, self).__init__(parent, main)
self.selectedImport = False
# Options for creating a new wallet
lblDlgDescr = QRichLabel(self.tr(
'Create a new wallet for managing your funds.<br> '
'The name and description can be changed at any time.'))
lblDlgDescr.setWordWrap(True)
self.edtName = QLineEdit()
self.edtName.setMaxLength(32)
self.edtName.setText(initLabel)
lblName = QLabel("Wallet &name:")
lblName.setBuddy(self.edtName)
self.edtDescr = QTextEdit()
self.edtDescr.setMaximumHeight(75)
lblDescr = QLabel("Wallet &description:")
lblDescr.setAlignment(Qt.AlignVCenter)
lblDescr.setBuddy(self.edtDescr)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | \
QDialogButtonBox.Cancel)
# Advanced Encryption Options
lblComputeDescr = QLabel(self.tr(
'Armory will test your system\'s speed to determine the most '
'challenging encryption settings that can be performed '
'in a given amount of time. High settings make it much harder '
'for someone to guess your passphrase. This is used for all '
'encrypted wallets, but the default parameters can be changed below.\n'))
lblComputeDescr.setWordWrap(True)
timeDescrTip = self.main.createToolTipWidget(self.tr(
'This is the amount of time it will take for your computer '
'to unlock your wallet after you enter your passphrase. '
'(the actual time used will be less than the specified '
'time, but more than one half of it).'))
# Set maximum compute time
self.edtComputeTime = QLineEdit()
self.edtComputeTime.setText('250 ms')
self.edtComputeTime.setMaxLength(12)
lblComputeTime = QLabel('Target compute &time (s, ms):')
memDescrTip = self.main.createToolTipWidget(self.tr(
'This is the <b>maximum</b> memory that will be '
'used as part of the encryption process. The actual value used '
'may be lower, depending on your system\'s speed. If a '
'low value is chosen, Armory will compensate by chaining '
'together more calculations to meet the target time. High '
'memory target will make GPU-acceleration useless for '
'guessing your passphrase.'))
lblComputeTime.setBuddy(self.edtComputeTime)
# Set maximum memory usage
self.edtComputeMem = QLineEdit()
self.edtComputeMem.setText('32.0 MB')
self.edtComputeMem.setMaxLength(12)
lblComputeMem = QLabel(self.tr('Max &memory usage (kB, MB):'))
lblComputeMem.setBuddy(self.edtComputeMem)
self.edtComputeTime.setMaximumWidth(tightSizeNChar(self, 20)[0])
self.edtComputeMem.setMaximumWidth(tightSizeNChar(self, 20)[0])
# Fork watching-only wallet
cryptoLayout = QGridLayout()
cryptoLayout.addWidget(lblComputeDescr, 0, 0, 1, 3)
cryptoLayout.addWidget(timeDescrTip, 1, 0, 1, 1)
cryptoLayout.addWidget(lblComputeTime, 1, 1, 1, 1)
cryptoLayout.addWidget(self.edtComputeTime, 1, 2, 1, 1)
cryptoLayout.addWidget(memDescrTip, 2, 0, 1, 1)
cryptoLayout.addWidget(lblComputeMem, 2, 1, 1, 1)
cryptoLayout.addWidget(self.edtComputeMem, 2, 2, 1, 1)
self.cryptoFrame = QFrame()
self.cryptoFrame.setFrameStyle(STYLE_SUNKEN)
self.cryptoFrame.setLayout(cryptoLayout)
self.cryptoFrame.setVisible(False)
self.chkUseCrypto = QCheckBox(self.tr("Use wallet &encryption"))
self.chkUseCrypto.setChecked(True)
usecryptoTooltip = self.main.createToolTipWidget(self.tr(
'Encryption prevents anyone who accesses your computer '
'or wallet file from being able to spend your money, as '
'long as they do not have the passphrase. '
'You can choose to encrypt your wallet at a later time '
'through the wallet properties dialog by double clicking '
'the wallet on the dashboard.'))
# For a new wallet, the user may want to print out a paper backup
self.chkPrintPaper = QCheckBox(self.tr("Print a paper-backup of this wallet"))
self.chkPrintPaper.setChecked(True)
paperBackupTooltip = self.main.createToolTipWidget(self.tr(
'A paper-backup allows you to recover your wallet/funds even '
'if you lose your original wallet file, any time in the future. '
'Because Armory uses "deterministic wallets," '
'a single backup when the wallet is first made is sufficient '
'for all future transactions (except ones to imported '
'addresses).\n\n'
'Anyone who gets hold of your paper backup will be able to spend '
'the money in your wallet, so please secure it appropriately.'))
self.btnAccept = QPushButton(self.tr("Accept"))
self.btnCancel = QPushButton(self.tr("Cancel"))
self.btnAdvCrypto = QPushButton(self.tr("Advanced Encryption Options>>>"))
self.btnAdvCrypto.setCheckable(True)
self.btnbox = QDialogButtonBox()
self.btnbox.addButton(self.btnAdvCrypto, QDialogButtonBox.ActionRole)
self.btnbox.addButton(self.btnCancel, QDialogButtonBox.RejectRole)
self.btnbox.addButton(self.btnAccept, QDialogButtonBox.AcceptRole)
self.connect(self.btnAdvCrypto, SIGNAL('toggled(bool)'), \
self.cryptoFrame, SLOT('setVisible(bool)'))
self.connect(self.btnAccept, SIGNAL(CLICKED), \
self.verifyInputsBeforeAccept)
self.connect(self.btnCancel, SIGNAL(CLICKED), \
self, SLOT('reject()'))
self.btnImportWlt = QPushButton(self.tr("Import wallet..."))
self.connect(self.btnImportWlt, SIGNAL("clicked()"), \
self.importButtonClicked)
masterLayout = QGridLayout()
masterLayout.addWidget(lblDlgDescr, 1, 0, 1, 2)
# masterLayout.addWidget(self.btnImportWlt, 1, 2, 1, 1)
masterLayout.addWidget(lblName, 2, 0, 1, 1)
masterLayout.addWidget(self.edtName, 2, 1, 1, 2)
masterLayout.addWidget(lblDescr, 3, 0, 1, 2)
masterLayout.addWidget(self.edtDescr, 3, 1, 2, 2)
masterLayout.addWidget(self.chkUseCrypto, 5, 0, 1, 1)
masterLayout.addWidget(usecryptoTooltip, 5, 1, 1, 1)
masterLayout.addWidget(self.chkPrintPaper, 6, 0, 1, 1)
masterLayout.addWidget(paperBackupTooltip, 6, 1, 1, 1)
masterLayout.addWidget(self.cryptoFrame, 8, 0, 3, 3)
masterLayout.addWidget(self.btnbox, 11, 0, 1, 2)
masterLayout.setVerticalSpacing(5)
self.setLayout(masterLayout)
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.connect(self.chkUseCrypto, SIGNAL("clicked()"), \
self.cryptoFrame, SLOT("setEnabled(bool)"))
self.setWindowTitle(self.tr('Create Armory wallet'))
self.setWindowIcon(QIcon(self.main.iconfile))
def importButtonClicked(self):
self.selectedImport = True
self.accept()
def verifyInputsBeforeAccept(self):
### Confirm that the name and descr are within size limits #######
wltName = self.edtName.text()
wltDescr = self.edtDescr.toPlainText()
if len(wltName) < 1:
QMessageBox.warning(self, self.tr('Invalid wallet name'), \
self.tr('You must enter a name for this wallet, up to 32 characters.'), \
QMessageBox.Ok)
return False
if len(wltDescr) > 256:
reply = QMessageBox.warning(self, self.tr('Input too long'), self.tr(
'The wallet description is limited to 256 characters. Only the first '
'256 characters will be used.'), \
QMessageBox.Ok | QMessageBox.Cancel)
if reply == QMessageBox.Ok:
self.edtDescr.setText(wltDescr[:256])
else:
return False
### Check that the KDF inputs are well-formed ####################
try:
kdfT, kdfUnit = str(self.edtComputeTime.text()).strip().split(' ')
if kdfUnit.lower() == 'ms':
self.kdfSec = float(kdfT) / 1000.
elif kdfUnit.lower() in ('s', 'sec', 'seconds'):
self.kdfSec = float(kdfT)
if not (self.kdfSec <= 20.0):
QMessageBox.critical(self, self.tr('Invalid KDF Parameters'), self.tr(
'Please specify a compute time no more than 20 seconds. '
'Values above one second are usually unnecessary.'))
return False
kdfM, kdfUnit = str(self.edtComputeMem.text()).split(' ')
if kdfUnit.lower() == 'mb':
self.kdfBytes = round(float(kdfM) * (1024.0 ** 2))
if kdfUnit.lower() == 'kb':
self.kdfBytes = round(float(kdfM) * (1024.0))
if not (2 ** 15 <= self.kdfBytes <= 2 ** 31):
QMessageBox.critical(self, self.tr('Invalid KDF Parameters'), \
self.tr('Please specify a maximum memory usage between 32 kB and 2048 MB.'))
return False
LOGINFO('KDF takes %0.2f seconds and %d bytes', self.kdfSec, self.kdfBytes)
except:
QMessageBox.critical(self, self.tr('Invalid Input'), self.tr(
'Please specify time with units, such as '
'"250 ms" or "2.1 s". Specify memory as kB or MB, such as '
'"32 MB" or "256 kB". '), QMessageBox.Ok)
return False
self.accept()
def getImportWltPath(self):
self.importFile = QFileDialog.getOpenFileName(self, self.tr('Import Wallet File'), \
ARMORY_HOME_DIR, self.tr('Wallet files (*.wallet);; All files (*)'))
if self.importFile:
self.accept()
################################################################################
class DlgChangePassphrase(ArmoryDialog):
def __init__(self, parent=None, main=None, noPrevEncrypt=True):
super(DlgChangePassphrase, self).__init__(parent, main)
layout = QGridLayout()
if noPrevEncrypt:
lblDlgDescr = QLabel(self.tr('Please enter an passphrase for wallet encryption.\n\n'
'A good passphrase consists of at least 8 or more\n'
'random letters, or 5 or more random words.\n'))
lblDlgDescr.setWordWrap(True)
layout.addWidget(lblDlgDescr, 0, 0, 1, 2)
else:
lblDlgDescr = QLabel(self.tr("Change your wallet encryption passphrase"))
layout.addWidget(lblDlgDescr, 0, 0, 1, 2)
self.edtPasswdOrig = QLineEdit()
self.edtPasswdOrig.setEchoMode(QLineEdit.Password)
self.edtPasswdOrig.setMinimumWidth(MIN_PASSWD_WIDTH(self))
lblCurrPasswd = QLabel(self.tr('Current Passphrase:'))
layout.addWidget(lblCurrPasswd, 1, 0)
layout.addWidget(self.edtPasswdOrig, 1, 1)
lblPwd1 = QLabel(self.tr("New Passphrase:"))
self.edtPasswd1 = QLineEdit()
self.edtPasswd1.setEchoMode(QLineEdit.Password)
self.edtPasswd1.setMinimumWidth(MIN_PASSWD_WIDTH(self))
lblPwd2 = QLabel(self.tr("Again:"))
self.edtPasswd2 = QLineEdit()
self.edtPasswd2.setEchoMode(QLineEdit.Password)
self.edtPasswd2.setMinimumWidth(MIN_PASSWD_WIDTH(self))
layout.addWidget(lblPwd1, 2, 0)
layout.addWidget(lblPwd2, 3, 0)
layout.addWidget(self.edtPasswd1, 2, 1)
layout.addWidget(self.edtPasswd2, 3, 1)
self.lblMatches = QLabel(' ' * 20)
self.lblMatches.setTextFormat(Qt.RichText)
layout.addWidget(self.lblMatches, 4, 1)
self.chkDisableCrypt = QCheckBox(self.tr('Disable encryption for this wallet'))
if not noPrevEncrypt:
self.connect(self.chkDisableCrypt, SIGNAL('toggled(bool)'), \
self.disablePassphraseBoxes)
layout.addWidget(self.chkDisableCrypt, 4, 0)
self.btnAccept = QPushButton(self.tr("Accept"))
self.btnCancel = QPushButton(self.tr("Cancel"))
buttonBox = QDialogButtonBox()
buttonBox.addButton(self.btnAccept, QDialogButtonBox.AcceptRole)
buttonBox.addButton(self.btnCancel, QDialogButtonBox.RejectRole)
layout.addWidget(buttonBox, 5, 0, 1, 2)
if noPrevEncrypt:
self.setWindowTitle(self.tr("Set Encryption Passphrase"))
else:
self.setWindowTitle(self.tr("Change Encryption Passphrase"))
self.setWindowIcon(QIcon(self.main.iconfile))
self.setLayout(layout)
self.connect(self.edtPasswd1, SIGNAL('textChanged(QString)'), \
self.checkPassphrase)
self.connect(self.edtPasswd2, SIGNAL('textChanged(QString)'), \
self.checkPassphrase)
self.connect(self.btnAccept, SIGNAL(CLICKED), \
self.checkPassphraseFinal)
self.connect(self.btnCancel, SIGNAL(CLICKED), \
self, SLOT('reject()'))
def disablePassphraseBoxes(self, noEncrypt=True):
self.edtPasswd1.setEnabled(not noEncrypt)
self.edtPasswd2.setEnabled(not noEncrypt)
def checkPassphrase(self):
if self.chkDisableCrypt.isChecked():
return True
p1 = self.edtPasswd1.text()
p2 = self.edtPasswd2.text()
goodColor = htmlColor('TextGreen')
badColor = htmlColor('TextRed')
if not isASCII(unicode(p1)) or \
not isASCII(unicode(p2)):
self.lblMatches.setText(self.tr('<font color=%1><b>Passphrase is non-ASCII!</b></font>').arg(badColor))
return False
if not p1 == p2:
self.lblMatches.setText(self.tr('<font color=%1><b>Passphrases do not match!</b></font>').arg(badColor))
return False
if len(p1) < 5:
self.lblMatches.setText(self.tr('<font color=%1><b>Passphrase is too short!</b></font>').arg(badColor))
return False
self.lblMatches.setText(self.tr('<font color=%1><b>Passphrases match!</b></font>').arg(goodColor))
return True
def checkPassphraseFinal(self):
if self.chkDisableCrypt.isChecked():
self.accept()
else:
if self.checkPassphrase():
dlg = DlgPasswd3(self, self.main)
if dlg.exec_():
if not str(dlg.edtPasswd3.text()) == str(self.edtPasswd1.text()):
QMessageBox.critical(self, self.tr('Invalid Passphrase'), \
self.tr('You entered your confirmation passphrase incorrectly!'), QMessageBox.Ok)
else:
self.accept()
else:
self.reject()
class DlgPasswd3(ArmoryDialog):
def __init__(self, parent=None, main=None):
super(DlgPasswd3, self).__init__(parent, main)
lblWarnImgL = QLabel()
lblWarnImgL.setPixmap(QPixmap(':/MsgBox_warning48.png'))
lblWarnImgL.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
lblWarnTxt1 = QRichLabel(\
self.tr('<font color="red"><b>!!! DO NOT FORGET YOUR PASSPHRASE !!!</b></font>'), size=4)
lblWarnTxt1.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
lblWarnTxt2 = QRichLabel(self.tr(
'<b>No one can help you recover you bitcoins if you forget the '
'passphrase and don\'t have a paper backup!</b> Your wallet and '
'any <u>digital</u> backups are useless if you forget it. '
'<br><br>'
'A <u>paper</u> backup protects your wallet forever, against '
'hard-drive loss and losing your passphrase. It also protects you '
'from theft, if the wallet was encrypted and the paper backup '
'was not stolen with it. Please make a paper backup and keep it in '
'a safe place.'
'<br><br>'
'<b>Please enter your passphrase a third time to indicate that you '
'are aware of the risks of losing your passphrase!</b>'), doWrap=True)
self.edtPasswd3 = QLineEdit()
self.edtPasswd3.setEchoMode(QLineEdit.Password)
self.edtPasswd3.setMinimumWidth(MIN_PASSWD_WIDTH(self))
bbox = QDialogButtonBox()
btnOk = QPushButton(self.tr('Accept'))
btnNo = QPushButton(self.tr('Cancel'))
self.connect(btnOk, SIGNAL(CLICKED), self.accept)
self.connect(btnNo, SIGNAL(CLICKED), self.reject)
bbox.addButton(btnOk, QDialogButtonBox.AcceptRole)
bbox.addButton(btnNo, QDialogButtonBox.RejectRole)
layout = QGridLayout()
layout.addWidget(lblWarnImgL, 0, 0, 4, 1)
layout.addWidget(lblWarnTxt1, 0, 1, 1, 1)
layout.addWidget(lblWarnTxt2, 2, 1, 1, 1)
layout.addWidget(self.edtPasswd3, 5, 1, 1, 1)
layout.addWidget(bbox, 6, 1, 1, 2)
self.setLayout(layout)