Skip to content

Commit

Permalink
added 'sanitize_passphrase' for DRY, added a passphrase with spaces t…
Browse files Browse the repository at this point in the history
…o tests and added nja files to gitignore
  • Loading branch information
reiven committed Jun 9, 2014
1 parent ccd47e7 commit d0fa62d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
*.nja
3 changes: 2 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def setUpClass(self):
self.keyfile = '.'.join([self.pid, 'key'])
self.keyfile2 = '.'.join([self.pid, '2ndkey'])
self.mountpath = './tmptomb'
self.passphrase = str(randrange(2 ** 64))
# generate a passphrase with spaces
self.passphrase = str(randrange(2 ** 64)).replace("", " ")[1:-1]
self.passphrase2 = str(randrange(2 ** 64))
self.imagefile = '.'.join([self.pid, 'jpg'])
self.createImage(self.imagefile)
Expand Down
45 changes: 24 additions & 21 deletions tomber.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,50 @@ def execute(cmd):
return False, get_message(stderr, 'error')


def sanitize_passphrase(passphrase):
"""
Used to avoid errors with passphrase which includes spaces
"""
return ''.join(['"', passphrase, '"'])


def tdig(tombfile, size):
"""
Usage: tdig <tombfilename> <size> - dig a tomb of given size
"""

cmd = ' '.join(['tomb', 'dig', tombfile, '-s', str(size), '--no-color'])
return execute(cmd)


def tforge(keyfile, passphrase):
# avoid errors with spaces in passphrase
passphrase = ''.join(['"', passphrase, '"'])
"""
Usage: tforge <keyfile> <passphrase> - forge a key with given passphrase
"""
cmd = ' '.join(['tomb',
'forge',
keyfile,
'--unsecure-dev-mode',
'--tomb-pwd',
passphrase,
sanitize_passphrase(passphrase),
'--no-color'])
return execute(cmd)


def tlock(tombfile, keyfile, passphrase):
passphrase = ''.join(['"', passphrase, '"'])
cmd = ' '.join(['tomb',
'lock',
tombfile,
'-k',
keyfile,
'--unsecure-dev-mode',
'--tomb-pwd',
passphrase,
sanitize_passphrase(passphrase),
'--no-color'])
return execute(cmd)


def topen(tombfile, keyfile, passphrase, mountpath=False):
passphrase = ''.join(['"', passphrase, '"'])
if not mountpath:
mountpath = ''
cmd = ' '.join(['tomb',
Expand All @@ -71,7 +81,7 @@ def topen(tombfile, keyfile, passphrase, mountpath=False):
keyfile,
'--unsecure-dev-mode',
'--tomb-pwd',
passphrase,
sanitize_passphrase(passphrase),
'--no-color',
mountpath])
return execute(cmd)
Expand All @@ -83,77 +93,70 @@ def tclose(tombfile):


def tresize(tombfile, keyfile, passphrase, newsize):
passphrase = ''.join(['"', passphrase, '"'])
cmd = ' '.join(['tomb',
'resize',
tombfile,
'-k',
keyfile,
'--unsecure-dev-mode',
'--tomb-pwd',
passphrase,
sanitize_passphrase(passphrase),
'-s',
str(newsize),
'--no-color'])
return execute(cmd)


def tbury(keyfile, passphrase, imagefile):
passphrase = ''.join(['"', passphrase, '"'])
cmd = ' '.join(['tomb',
'bury',
'-k',
keyfile,
'--unsecure-dev-mode',
'--tomb-pwd',
passphrase,
sanitize_passphrase(passphrase),
imagefile,
'--no-color'])
return execute(cmd)


def texhume(keyfile, passphrase, imagefile):
passphrase = ''.join(['"', passphrase, '"'])
cmd = ' '.join(['tomb',
'exhume',
'-k',
keyfile,
'--unsecure-dev-mode',
'--tomb-pwd',
passphrase,
sanitize_passphrase(passphrase),
imagefile,
'--no-color'])
return execute(cmd)


def tpasswd(keyfile, newpassphrase, oldpassphrase):
newpassphrase = ''.join(['"', newpassphrase, '"'])
oldpassphrase = ''.join(['"', oldpassphrase, '"'])
cmd = ' '.join(['tomb',
'passwd',
'-k',
keyfile,
'--unsecure-dev-mode',
'--tomb-pwd',
newpassphrase,
sanitize_passphrase(newpassphrase),
'--tomb-old-pwd',
oldpassphrase,
sanitize_passphrase(oldpassphrase),
'--no-color'])
return execute(cmd)


def tsetkey(oldkeyfile, tombfile, newkeyfile, newpassphrase, oldpassphrase):
newpassphrase = ''.join(['"', newpassphrase, '"'])
oldpassphrase = ''.join(['"', oldpassphrase, '"'])
cmd = ' '.join(['tomb',
'setkey',
oldkeyfile,
'-k',
newkeyfile,
'--unsecure-dev-mode',
'--tomb-pwd',
newpassphrase,
sanitize_passphrase(newpassphrase),
'--tomb-old-pwd',
oldpassphrase,
sanitize_passphrase(oldpassphrase),
'--no-color'])
return execute(cmd)

0 comments on commit d0fa62d

Please sign in to comment.