~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to src/escrow/escrow-passphrase.py

  • Committer: Dustin Kirkland
  • Date: 2016-02-27 00:00:23 UTC
  • Revision ID: kirkland@ubuntu.com-20160227000023-h0e4oui5y1vbaurd
openingĀ 112

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
import sys
4
 
import getopt
5
 
import base64
6
 
from ZSI.client import Binding
7
 
import libecryptfs
8
 
 
9
 
__doc__ = '''
10
 
Usage: escrow-passphrase.py <-v|--verbose> <[salt]> [passphrase]
11
 
'''
12
 
 
13
 
def main():
14
 
    verbosity = 0
15
 
    default_salt_hex = "0011223344556677"
16
 
    try:
17
 
        opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "verbose"])
18
 
    except getopt.error, msg:
19
 
        print msg
20
 
        print "for help use --help"
21
 
        sys.exit(2)
22
 
    for o, a in opts:
23
 
        if o in ("-h", "--help"):
24
 
            print __doc__
25
 
            sys.exit(0)
26
 
        elif o in ("-v", "--verbose"):
27
 
            verbosity = 1
28
 
    salt_bytes = []
29
 
    if len(args) < 1 or len(args) > 2:
30
 
        print "invalid number of arguments"
31
 
        print "for help use --help"
32
 
        sys.exit(2)        
33
 
    if len(args) == 1:
34
 
        salt_hex = default_salt_hex
35
 
        passphrase_charstr = args[0]
36
 
    if len(args) == 2:
37
 
        salt_hex = args[0]
38
 
        passphrase_charstr = args[1]
39
 
    if len(salt_hex) != 16:
40
 
            print "Salt value provided is [%s], which is [%d] characters long. The salt must be comprised of [%d] hexidecimal characters." % (salt_hex, len(salt_hex), 16)
41
 
    for i in range(0, 16, 2):
42
 
        salt_bytes.append(chr(int(salt_hex[i:i+2], 16)))
43
 
    salt_charstr = ""
44
 
    for sb in salt_bytes:
45
 
        salt_charstr = "%s%c" % (salt_charstr, sb)
46
 
    blob = libecryptfs.ecryptfs_passphrase_blob(salt_charstr, \
47
 
                                                    passphrase_charstr)
48
 
    sig = libecryptfs.ecryptfs_passphrase_sig_from_blob(blob)
49
 
    b = Binding(url="http://127.0.0.1:8080")
50
 
    b64sig = base64.b64encode(sig)
51
 
    b64blob = base64.b64encode(blob)
52
 
    b.store_key_blob([b64sig, b64blob])
53
 
 
54
 
if __name__ == "__main__":
55
 
    main()