-
Notifications
You must be signed in to change notification settings - Fork 5
/
cvolume.py
679 lines (564 loc) · 32.1 KB
/
cvolume.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
# encfsgui Create a new volume
#
#
import os
import sys
import time
import datetime
import string
from PyQt5 import uic
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
import encfsgui_globals
from encfsgui_globals import *
import encfsgui_helper
from encfsgui_helper import *
class CVolumeWindow(QtWidgets.QDialog):
def __init__(self):
encfsgui_helper.print_debug("Start CVolumeWindow %s" % inspect.stack()[0][3])
super(CVolumeWindow, self).__init__()
uic.loadUi('encfsgui_volume.ui', self)
# disable/remove buttons
self.setWindowFlags(self.windowFlags() | QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowStaysOnTopHint)
self.setWindowFlag(QtCore.Qt.WindowMaximizeButtonHint, False)
self.setWindowFlag(QtCore.Qt.WindowCloseButtonHint, False)
# 0 = create
# 1 = add
# 2 = edit
self.runmode = 0 # create
self.origvolumename = ""
self.encfsfolderbutton = self.findChild(QtWidgets.QPushButton, 'btn_selectencfsfolder')
self.encfsfolderbutton.clicked.connect(self.SelectEncfsFolderClicked)
self.mountfolderbutton = self.findChild(QtWidgets.QPushButton, 'btn_selectmountfolder')
self.mountfolderbutton.clicked.connect(self.SelectMountFolderClicked)
self.txt_encfsfolder = self.findChild(QtWidgets.QLineEdit, 'txt_encfsfolder')
self.txt_mountfolder = self.findChild(QtWidgets.QLineEdit, 'txt_mountfolder')
self.txt_volumename = self.findChild(QtWidgets.QLineEdit, 'txt_volumename')
self.txt_password = self.findChild(QtWidgets.QLineEdit, 'txt_password')
self.txt_password2 = self.findChild(QtWidgets.QLineEdit, 'txt_password2')
self.txt_encfsmountoptions = self.findChild(QtWidgets.QLineEdit, 'txt_encfsmountoptions')
self.chk_saveinkeychain = self.findChild(QtWidgets.QCheckBox, 'chk_saveinkeychain')
self.chk_mountaslocal = self.findChild(QtWidgets.QCheckBox, 'chk_mountaslocal')
self.chk_usesudo = self.findChild(QtWidgets.QCheckBox, 'chk_usesudo')
self.chk_automount = self.findChild(QtWidgets.QCheckBox, 'chk_automount')
self.chk_preventautounmount = self.findChild(QtWidgets.QCheckBox, 'chk_preventautounmount')
self.chk_accesstoother = self.findChild(QtWidgets.QCheckBox, 'chk_accesstoother')
self.savebutton = self.findChild(QtWidgets.QPushButton, 'btn_save')
self.savebutton.clicked.connect(self.SaveButtonClicked)
self.cancelbutton = self.findChild(QtWidgets.QPushButton, 'btn_cancel')
self.cancelbutton.clicked.connect(self.CancelButtonClicked)
self.radio_volumetype_gocryptfs = self.findChild(QtWidgets.QRadioButton, 'radio_type_gocryptfs')
self.radio_volumetype_gocryptfs.clicked.connect(self.SelectVolumeTypeGoCryptFS)
self.radio_volumetype_encfs = self.findChild(QtWidgets.QRadioButton, 'radio_type_encfs')
self.radio_volumetype_encfs.clicked.connect(self.SelectVolumeTypeEncFS)
self.radio_balanced = self.findChild(QtWidgets.QRadioButton, 'radio_balanced')
self.radio_performance = self.findChild(QtWidgets.QRadioButton, 'radio_performance')
self.radio_secure = self.findChild(QtWidgets.QRadioButton, 'radio_secure')
self.radio_custom = self.findChild(QtWidgets.QRadioButton, 'radio_custom')
self.radio_balanced.clicked.connect(self.SelectProfileBalanced)
self.radio_performance.clicked.connect(self.SelectProfilePerformance)
self.radio_secure.clicked.connect(self.SelectProfileSecure)
self.radio_custom.clicked.connect(self.SelectProfileCustom)
self.chk_perblockhmac = self.findChild(QtWidgets.QCheckBox, 'chk_perblockhmac')
self.chk_perfileuniqueiv = self.findChild(QtWidgets.QCheckBox, 'chk_perfileuniqueiv')
self.chk_chainediv = self.findChild(QtWidgets.QCheckBox, 'chk_chainediv')
self.chk_externaliv = self.findChild(QtWidgets.QCheckBox, 'chk_externaliv')
self.grp_volumetypes = self.findChild(QtWidgets.QGroupBox, 'grp_volumetypes')
self.grp_encfsoptions = self.findChild(QtWidgets.QGroupBox, 'grp_encfsoptions')
self.grp_gocryptfsoptions = self.findChild(QtWidgets.QGroupBox, 'grp_gocryptfsoptions')
self.tab_volumetypes = self.findChild(QtWidgets.QTabWidget, 'tab_volumetypes')
self.tab_encfs_options = self.findChild(QtWidgets.QWidget, 'tab_encfs_options')
self.tab_gocryptfs_options = self.findChild(QtWidgets.QWidget, 'tab_gocryptfs_options')
self.chk_gocryptfs_plaintext = self.findChild(QtWidgets.QCheckBox, 'chk_gocryptfs_plaintext')
self.chk_gocryptfs_aessiv = self.findChild(QtWidgets.QCheckBox, 'chk_gocryptfs_aessiv')
# populate combo boxes
self.ciphercombo = self.findChild(QtWidgets.QComboBox, ('cmb_ciphers'))
self.ciphercombo.clear()
self.ciphercombo.addItem("AES")
self.keysizecombo = self.findChild(QtWidgets.QComboBox, ('cmb_keysize'))
self.blocksizecombo = self.findChild(QtWidgets.QComboBox, ('cmb_blocksize'))
self.filenameencodingcombo = self.findChild(QtWidgets.QComboBox, ('cmb_filenameencoding'))
self.keysizecombo.clear()
self.keysizecombo.addItem("128")
self.keysizecombo.addItem("192")
self.keysizecombo.addItem("256")
blocksize = 64
self.blocksizecombo.clear()
while (blocksize <= 4096):
self.blocksizecombo.addItem("%d" % blocksize)
blocksize += 16
self.filenameencodingcombo.clear()
for encodingtype in encfsgui_globals.g_Encodings:
self.filenameencodingcombo.addItem(encodingtype)
self.SelectProfileBalanced()
# default to GoCryptFS
self.SelectVolumeTypeGoCryptFS()
def SelectEncfsFolderClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
folderName = str(QtWidgets.QFileDialog.getExistingDirectory(self, "Select Directory", self.txt_encfsfolder.displayText(), QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontResolveSymlinks))
if folderName:
self.txt_encfsfolder.setText("%s" % folderName)
return
def SelectMountFolderClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
folderName = str(QtWidgets.QFileDialog.getExistingDirectory(self, "Select Directory", self.txt_mountfolder.displayText(), QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontResolveSymlinks))
if folderName:
self.txt_mountfolder.setText("%s" % folderName)
return
def SelectVolumeTypeEncFS(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
#disable the GoCryptFS tab
if self.runmode == 0:
self.grp_encfsoptions.setEnabled(True)
self.grp_gocryptfsoptions.setEnabled(False)
#set EncFS tab in focus
self.tab_encfs_options.setEnabled(True)
self.tab_gocryptfs_options.setEnabled(False)
self.tab_volumetypes.setCurrentWidget(self.tab_encfs_options)
self.tab_encfs_options.show()
#self.chk_mountaslocal.setEnabled(True)
return
def SelectVolumeTypeGoCryptFS(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
#disable the EncfS tab
if self.runmode == 0:
self.grp_encfsoptions.setEnabled(False)
self.grp_gocryptfsoptions.setEnabled(True)
#set GoCryptFS tab in focus
self.tab_encfs_options.setEnabled(False)
self.tab_gocryptfs_options.setEnabled(True)
self.tab_volumetypes.setCurrentWidget(self.tab_gocryptfs_options)
self.tab_gocryptfs_options.show()
#self.chk_mountaslocal.setEnabled(False)
return
def SelectProfileCustom(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.ciphercombo.setEnabled(True)
self.keysizecombo.setEnabled(True)
self.blocksizecombo.setEnabled(True)
self.filenameencodingcombo.setEnabled(True)
self.chk_perblockhmac.setEnabled(True)
self.chk_perfileuniqueiv.setEnabled(True)
self.chk_chainediv.setEnabled(True)
self.chk_externaliv.setEnabled(True)
return
def SelectProfileBalanced(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.ciphercombo.setEnabled(False)
self.keysizecombo.setEnabled(False)
self.blocksizecombo.setEnabled(False)
self.filenameencodingcombo.setEnabled(False)
self.chk_perblockhmac.setEnabled(False)
self.chk_perfileuniqueiv.setEnabled(False)
self.chk_chainediv.setEnabled(False)
self.chk_externaliv.setEnabled(False)
self.chk_perfileuniqueiv.setChecked(True)
self.chk_externaliv.setChecked(False)
self.chk_chainediv.setChecked(False)
self.chk_perblockhmac.setChecked(False)
self.ciphercombo.setCurrentText("AES")
self.keysizecombo.setCurrentText("192")
self.blocksizecombo.setCurrentText("2048")
self.filenameencodingcombo.setCurrentText("Stream")
return
def SelectProfilePerformance(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.ciphercombo.setEnabled(False)
self.keysizecombo.setEnabled(False)
self.blocksizecombo.setEnabled(False)
self.filenameencodingcombo.setEnabled(False)
self.chk_perblockhmac.setEnabled(False)
self.chk_perfileuniqueiv.setEnabled(False)
self.chk_chainediv.setEnabled(False)
self.chk_externaliv.setEnabled(False)
self.ciphercombo.setCurrentText("AES")
self.keysizecombo.setCurrentText("192")
self.blocksizecombo.setCurrentText("1024")
self.filenameencodingcombo.setCurrentText("Null")
self.chk_perfileuniqueiv.setChecked(False)
self.chk_externaliv.setChecked(False)
self.chk_chainediv.setChecked(False)
self.chk_perblockhmac.setChecked(False)
return
def SelectProfileSecure(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.ciphercombo.setEnabled(False)
self.keysizecombo.setEnabled(False)
self.blocksizecombo.setEnabled(False)
self.filenameencodingcombo.setEnabled(False)
self.chk_perblockhmac.setEnabled(False)
self.chk_perfileuniqueiv.setEnabled(False)
self.chk_chainediv.setEnabled(False)
self.chk_externaliv.setEnabled(False)
self.ciphercombo.setCurrentText("AES")
self.keysizecombo.setCurrentText("256")
self.blocksizecombo.setCurrentText("4096")
self.filenameencodingcombo.setCurrentText("Block")
self.chk_perfileuniqueiv.setChecked(True)
self.chk_externaliv.setChecked(True)
self.chk_chainediv.setChecked(True)
self.chk_perblockhmac.setChecked(True)
return
def SaveButtonClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
# sanity check
newvolumename = str(self.txt_volumename.displayText()).strip()
errorfound = False
if (self.txt_volumename.text().replace(" ","") == ""):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Error checking volume name","Volume name cannot be empty.\n Please enter a unique volume name." )
if (self.txt_encfsfolder.text().replace(" ","") == ""):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Error checking encfs/gocryptfs folder path","Please select a valid encfs/gocryptfs folder." )
else:
if (self.runmode == 0):
# encfs folder must be empty
if (os.listdir(self.txt_encfsfolder.text())):
QtWidgets.QMessageBox.warning(None,"Error checking encfs/gocryptfs folder","Please make sure the new encfs/gocryptfs folder is empty at this point." )
errorfound = True
if (self.txt_mountfolder.text().replace(" ","") == ""):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Error checking volume name","Please select a valid mount folder" )
else:
if (self.runmode == 0):
# encfs folder must be empty
if (os.listdir(self.txt_mountfolder.text())):
QtWidgets.QMessageBox.warning(None,"Error checking mount folder","Please make sure the mount folder is empty at this point." )
errorfound = True
# runmode 0 = create
# runmode 1 = add
# runmode 2 = edit
if (self.runmode == 0) or (self.runmode == 1):
if (newvolumename in encfsgui_globals.g_Volumes):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Error checking volume name","Volume name '%s' already exists.\n Please choose a unique volume name." % newvolumename )
if (self.runmode == 2):
if (newvolumename != self.origvolumename):
if (newvolumename in encfsgui_globals.g_Volumes):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Error checking volume name","Volume name '%s' already exists.\n Please choose a unique volume name." % newvolumename )
else:
print_debug("Volume '%s' will be renamed to '%s'" % (self.origvolumename, newvolumename))
if self.chk_saveinkeychain.isChecked() and (self.txt_password.text() == "" or self.txt_password2.text() == ""):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Re-enter password","You are trying to rename a volume that had its password saved in keychain.\n\nPlease enter the password again, or disable saving the password in keychain.\n\n" )
if (self.chk_saveinkeychain.isChecked() or self.runmode == 0):
if (self.txt_password.text() != self.txt_password2.text()):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Password error","Both passwords do not match" )
if not self.chk_saveinkeychain.isChecked() and not self.runmode == 2:
# in edit mode, we can allow empty passwords, providing that password has been saved in keychain already
if (self.txt_password.text() == "" or self.txt_password2.text() == ""):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Password error","Password cannot be empty" )
if ("'" in self.txt_password.text()):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Password error","Sorry, you're not allowed to use the 'single-tick' character (') in the password" )
if ("!" in self.txt_password.text()):
errorfound = True
QtWidgets.QMessageBox.warning(None,"Password error","Sorry, you're not allowed to use the 'exclamation mark' character (!) in the password" )
if not errorfound:
# save everything
# translate options into object
EncVolumeObj = encfsgui_globals.CEncryptedVolume()
EncVolumeObj.enc_path = str(self.txt_encfsfolder.displayText()).strip()
EncVolumeObj.mount_path = str(self.txt_mountfolder.displayText()).strip()
EncVolumeObj.encfsmountoptions = str(self.txt_encfsmountoptions.displayText()).strip()
if (self.radio_volumetype_gocryptfs.isChecked()):
EncVolumeObj.enctype = "gocryptfs"
if (self.radio_volumetype_encfs.isChecked()):
EncVolumeObj.enctype = "encfs"
if (self.chk_mountaslocal.isChecked()):
EncVolumeObj.mountaslocal = "1"
else:
EncVolumeObj.mountaslocal = "0"
if (self.chk_saveinkeychain.isChecked()):
EncVolumeObj.passwordsaved = "1"
else:
EncVolumeObj.passwordsaved = "0"
if (self.chk_automount.isChecked()):
EncVolumeObj.automount = "1"
else:
EncVolumeObj.automount = "0"
if (self.chk_preventautounmount.isChecked()):
EncVolumeObj.preventautounmount = "1"
else:
EncVolumeObj.preventautounmount = "0"
if (self.chk_accesstoother.isChecked()):
EncVolumeObj.allowother = "1"
else:
EncVolumeObj.allowother = "0"
if (self.chk_usesudo.isChecked()):
EncVolumeObj.sudo = "1"
else:
EncVolumeObj.sudo = "0"
# in create mode, first create the actual encrypted folder
# and then add it to the config
if (self.runmode == 0):
if (self.CreateNewEncryptedVolume()):
encfsgui_globals.appconfig.addVolume(newvolumename, EncVolumeObj)
# add mode
if (self.runmode == 1):
encfsgui_globals.appconfig.addVolume(newvolumename, EncVolumeObj)
# in edit mode, remove previous volume from volume list
# and add new one
if (self.runmode == 2):
encfsgui_globals.appconfig.delVolume(self.origvolumename)
# only remove password if a new is set, to avoid that a simple edit would clear the saved password
if self.chk_saveinkeychain.isChecked() and not self.txt_password.text() == "" and not self.txt_password2 == "":
encfsgui_helper.RemovePasswordFromKeyChain(self.origvolumename)
encfsgui_globals.appconfig.addVolume(newvolumename, EncVolumeObj)
# remove old password
if not self.chk_saveinkeychain.isChecked():
encfsgui_helper.RemovePasswordFromKeyChain(newvolumename)
# save new password
if (self.chk_saveinkeychain.isChecked() and self.txt_password.text() != ""):
encfsgui_helper.RemovePasswordFromKeyChain(newvolumename)
encfsgui_helper.SavePasswordInKeyChain(newvolumename, self.txt_password.text())
# and close the dialog
self.close()
return
def CancelButtonClicked(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.close()
return
def CreateNewEncryptedVolume(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QMessageBox.Question)
msgBox.setWindowTitle("Are you sure?")
msgboxtext = ""
if self.radio_volumetype_encfs.isChecked():
msgboxtext = "Are you sure you would like to create a new encfs volume '%s' at '%s' ?" % (self.txt_volumename.text(), self.txt_encfsfolder.text())
if self.radio_volumetype_gocryptfs.isChecked():
msgboxtext = "Are you sure you would like to create a new gocryptfs volume '%s' at '%s' ?" % (self.txt_volumename.text(), self.txt_encfsfolder.text())
msgBox.setText(msgboxtext)
msgBox.setStandardButtons(QtWidgets.QMessageBox.No)
msgBox.addButton(QtWidgets.QMessageBox.Yes)
msgBox.show()
encfolderfound = False
if (msgBox.exec_() == QtWidgets.QMessageBox.Yes):
# encfs
if self.radio_volumetype_encfs.isChecked():
cipheralgos = {}
cipheralgos["AES"] = 1
cipheralgos["Blowfish"] = 2
cipheralgos["Camilla"] = 3
encfsversion = encfsgui_helper.getEncFSVersion()
selectedalgo = 1
if not encfsversion.startswith("1.9."):
# number selection
selectedalgo = str(cipheralgos[self.ciphercombo.currentText()])
else:
# selectedalgo = "%s" % self.ciphercombo.currentText()
selectedalgo = str(cipheralgos[self.ciphercombo.currentText()])
fileencodings = {}
encodingindex = 1
selectedfileencoding = ""
for encodingtype in encfsgui_globals.g_Encodings:
fileencodings[encodingtype] = encodingindex
encodingindex += 1
encfsgui_helper.print_debug("File encodings: %s" % fileencodings)
if not encfsversion.startswith("1.9."):
# number selection
selectedfileencoding = str(fileencodings[self.filenameencodingcombo.currentText()])
else:
selectedfileencoding = str(fileencodings[self.filenameencodingcombo.currentText()])
#selectedfileencoding = "%s" % self.filenameencodingcombo.currentText()
encfsgui_helper.print_debug("Encoding selected: %s" % selectedfileencoding)
# create expect script
scriptcontents = encfsgui_helper.getExpectScriptContents("encfs", False)
# replace variables in the script
scriptcontents = scriptcontents.replace("$ENCFSBIN", encfsgui_globals.g_Settings["encfspath"])
scriptcontents = scriptcontents.replace("$ENCPATH", self.txt_encfsfolder.text())
scriptcontents = scriptcontents.replace("$MOUNTPATH", self.txt_mountfolder.text())
scriptcontents = scriptcontents.replace("$CIPHERALGO", selectedalgo)
scriptcontents = scriptcontents.replace("$CIPHERKEYSIZE", self.keysizecombo.currentText())
scriptcontents = scriptcontents.replace("$BLOCKSIZE", self.blocksizecombo.currentText())
scriptcontents = scriptcontents.replace("$ENCODINGALGO", selectedfileencoding)
if (self.chk_chainediv.isChecked()):
scriptcontents = scriptcontents.replace("$IVCHAINING","")
else:
scriptcontents = scriptcontents.replace("$IVCHAINING","n")
if (self.chk_perfileuniqueiv.isChecked()):
scriptcontents = scriptcontents.replace("$PERFILEIV","")
else:
scriptcontents = scriptcontents.replace("$PERFILEIV","n")
if (self.chk_externaliv.isChecked()):
scriptcontents = scriptcontents.replace("$FILETOIVHEADERCHAINING","y")
else:
scriptcontents = scriptcontents.replace("$FILETOIVHEADERCHAINING","") # n is default here
if (self.chk_perblockhmac.isChecked()):
scriptcontents = scriptcontents.replace("$BLOCKAUTHCODEHEADERS","y")
else:
scriptcontents = scriptcontents.replace("$BLOCKAUTHCODEHEADERS","") # n is default here
scriptcontents = scriptcontents.replace("sleep x","expect eof")
expectfilename = "expect.encfsgui"
# write script to file
scriptfile = open(expectfilename, 'w')
scriptfile.write(scriptcontents)
scriptfile.close()
# run script file
cmdarray = ["expect",expectfilename, self.txt_password.text(), ">/dev/null"]
encfsgui_helper.execOScmdAsync(cmdarray)
self.setEnabled(False)
time.sleep(3)
encfolderfound = False
secondswaited = 1
while not encfolderfound:
if (os.path.exists( self.txt_encfsfolder.text() + "/.encfs6.xml" )):
encfolderfound = True
else:
time.sleep(1)
secondswaited += 1
if (secondswaited > 10):
break
self.setEnabled(True)
# unmount new volume
cmd = "%s '%s'" % (encfsgui_globals.g_Settings["umountpath"], self.txt_mountfolder.text())
encfsgui_helper.execOSCmd(cmd)
if encfolderfound:
QtWidgets.QMessageBox.information(None,"EncFS volume created successfully","EncFS volume was created successfully")
#delete script file again
os.remove(expectfilename)
else:
QtWidgets.QMessageBox.information(None,"Error creating volume","Error while creating EncFS volume")
# keep the expect file for debugging purposes in case debug mode is active
if not encfsgui_globals.debugmode:
os.remove(expectfilename)
# gocryptfs
if self.radio_volumetype_gocryptfs.isChecked():
# create expect script
extra_opts = ""
if self.chk_gocryptfs_plaintext.isChecked():
extra_opts += "-plaintextnames "
if self.chk_gocryptfs_aessiv.isChecked():
extra_opts += "-aessiv "
scriptcontents = encfsgui_helper.getExpectScriptContents("gocryptfs", False)
# replace variables in the script
scriptcontents = scriptcontents.replace("$GOCRYPTFSBIN", encfsgui_globals.g_Settings["gocryptfspath"])
scriptcontents = scriptcontents.replace("$ENCPATH", self.txt_encfsfolder.text())
scriptcontents = scriptcontents.replace("$MOUNTPATH", self.txt_mountfolder.text())
scriptcontents = scriptcontents.replace("$EXTRAOPTS", extra_opts)
scriptcontents = scriptcontents.replace("sleep x","expect eof")
expectfilename = "expect.encfsgui"
# write script to file
scriptfile = open(expectfilename, 'w')
scriptfile.write(scriptcontents)
scriptfile.close()
# run script file
cmdarray = ["expect",expectfilename, self.txt_password.text(), ">/dev/null"]
#QtWidgets.QMessageBox.information(None,"expect script ready","expect script ready")
#encfsgui_helper.execOScmdAsync(cmdarray)
gocryptfslines, retval = encfsgui_helper.execOSCmdRetVal(cmdarray)
self.setEnabled(False)
time.sleep(3)
encfolderfound = False
secondswaited = 1
while not encfolderfound:
if (os.path.exists( self.txt_encfsfolder.text() + "/gocryptfs.diriv" ) or os.path.exists( self.txt_encfsfolder.text() + "/gocryptfs.conf" )):
encfolderfound = True
else:
time.sleep(1)
secondswaited += 1
if (secondswaited > 10):
break
self.setEnabled(True)
if encfolderfound:
QtWidgets.QMessageBox.information(None,"GoCryptFS volume created successfully","GoCryptFS volume was created successfully")
masterkeyinfo = ""
takenote = False
for line in gocryptfslines:
if "Your master key" in line:
takenote = True
if takenote:
if "-" in line:
masterkeyinfo += "%s\n" % str(line.replace(" ","").replace("[2m","").replace("[0m","").replace("\x1b",""))
QtWidgets.QMessageBox.information(None,"Your master key","WARNING! This is the only time when you get to see your master key!\n\nYour master key is:\n\n%s\n\nPrint it to a piece of paper and store it in a safe location.\n" % masterkeyinfo)
#delete script file again
os.remove(expectfilename)
else:
QtWidgets.QMessageBox.information(None,"Error creating volume","Error while creating GoCryptFS volume")
# keep the expect file for debugging purposes in case debug mode is active
if not encfsgui_globals.debugmode:
os.remove(expectfilename)
return encfolderfound
def setRunMode(self, mode):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
self.runmode = mode
self.lbl_encfsfolder = self.findChild(QtWidgets.QLabel,'lbl_encfsfolder')
if mode == 0:
self.setWindowTitle("Create a new encfs/gocryptfs volume")
self.lbl_encfsfolder.setText("Location of new (empty) encfs/gocryptfs folder:")
self.savebutton.setText("Create")
self.grp_encfsoptions.setEnabled(True)
self.grp_gocryptfsoptions.setEnabled(True)
self.tab_volumetypes.setEnabled(True)
if mode == 1:
self.setWindowTitle("Open/Add an existing encfs/gocryptfs volume")
self.lbl_encfsfolder.setText("Location of existing encfs/gocryptfs folder:")
self.savebutton.setText("Add")
self.grp_encfsoptions.setEnabled(False)
self.grp_gocryptfsoptions.setEnabled(False)
self.tab_volumetypes.setEnabled(False)
if mode == 2:
self.setWindowTitle("Edit an encfs/gocryptfs volume")
self.lbl_encfsfolder.setText("Location of existing encfs/gocryptfs folder:")
self.savebutton.setText("Save")
self.grp_encfsoptions.setEnabled(False)
self.grp_gocryptfsoptions.setEnabled(False)
self.grp_volumetypes.setEnabled(False)
#unsupported
if encfsgui_helper.isLinux():
self.chk_mountaslocal.setEnabled(False)
self.chk_mountaslocal.setChecked(False)
if encfsgui_helper.isWindows():
self.chk_usesudo.setEnabled(False)
self.chk_usesudo.setChecked(False)
return
def getRunMode(self):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
encfsgui_helper.print_debug("mode: %d" % self.runmode)
return
def PopulateFields(self, volumename):
encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
if volumename in encfsgui_globals.g_Volumes:
EncVolumeObj = encfsgui_globals.g_Volumes[volumename]
self.txt_volumename.setText(volumename)
self.txt_encfsfolder.setText(EncVolumeObj.enc_path)
self.txt_mountfolder.setText(EncVolumeObj.mount_path)
self.txt_encfsmountoptions.setText(EncVolumeObj.encfsmountoptions)
self.chk_mountaslocal.setChecked(False)
self.chk_automount.setChecked(False)
self.chk_preventautounmount.setChecked(False)
self.chk_accesstoother.setChecked(False)
self.chk_saveinkeychain.setChecked(False)
if str(EncVolumeObj.mountaslocal) == "1":
self.chk_mountaslocal.setChecked(True)
if str(EncVolumeObj.automount) == "1":
self.chk_automount.setChecked(True)
if str(EncVolumeObj.preventautounmount) == "1":
self.chk_preventautounmount.setChecked(True)
if str(EncVolumeObj.allowother) == "1":
self.chk_accesstoother.setChecked(True)
if str(EncVolumeObj.passwordsaved) == "1":
self.chk_saveinkeychain.setChecked(True)
if str(EncVolumeObj.sudo) == "1":
self.chk_usesudo.setChecked(True)
if str(EncVolumeObj.enctype) == "encfs":
self.radio_volumetype_encfs.setChecked(True)
self.tab_volumetypes.setCurrentWidget(self.tab_encfs_options)
self.chk_mountaslocal.setEnabled(True)
if str(EncVolumeObj.enctype) == "gocryptfs":
self.radio_volumetype_gocryptfs.setChecked(True)
self.tab_volumetypes.setCurrentWidget(self.tab_gocryptfs_options)
#self.chk_mountaslocal.setEnabled(False)
# overrule, unsupported features
if encfsgui_helper.isLinux():
self.chk_mountaslocal.setEnabled(False)
self.chk_mountaslocal.setChecked(False)
if encfsgui_helper.isWindows():
self.chk_usesudo.setEnabled(False)
self.chk_usesudo.setChecked(False)
return