Added first truecrypt script
authorft
Tue, 25 Feb 2014 08:08:37 +0100
changeset 035acc83f4749
child 1 ad15a8882cac
Added first truecrypt script
Added tc config
Added alpha implementation of the encryption provider
config/encryptionprovider.cfg
src/encryptionprovider.py
truecrypt_scripts/truecrypt_config.cfg
truecrypt_scripts/truecrypt_getdevices.bash
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/config/encryptionprovider.cfg	Tue Feb 25 08:08:37 2014 +0100
     1.3 @@ -0,0 +1,12 @@
     1.4 +[Main]
     1.5 +# make sure this file is writeable
     1.6 +LogFile: /var/log/encryptionprovider.log
     1.7 +
     1.8 +# DEBUG, INFO, WARNING, ERROR, CRITICAL
     1.9 +LogLevel: debug
    1.10 +
    1.11 +
    1.12 +MountScript: /usr/local/bin/
    1.13 +UmountScript: /usr/local/bin/
    1.14 +InitScript: /usr/local/bin/
    1.15 +GetDevicesScript: /usr/local/bin/
    1.16 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/encryptionprovider.py	Tue Feb 25 08:08:37 2014 +0100
     2.3 @@ -0,0 +1,100 @@
     2.4 +#!/usr/bin/python
     2.5 +
     2.6 +import subprocess
     2.7 +import web
     2.8 +import netifaces
     2.9 +import argparse
    2.10 +import thread
    2.11 +import time
    2.12 +import os
    2.13 +import sys
    2.14 +import ConfigParser
    2.15 +import logging
    2.16 +
    2.17 +
    2.18 +
    2.19 +MINOPTS = { "Main" : ["LogFile", "LogLevel", "MountScript", "UmountScript", "InitScript", "GetDevicesScript"]}
    2.20 +
    2.21 +#CONFIG_FILE="/etc/enryptionprovider/encryptionprovider.cfg"
    2.22 +CONFIG_FILE="/home/spawn/workspace_python/encryptionprovider/config/encryptionprovider.cfg"
    2.23 +CONFIG_NOT_READABLE = "Configfile is not readable"
    2.24 +CONFIG_WRONG = "Something is wrong with the config"
    2.25 +CONFIG_MISSING = "Section: \"%s\" Option: \"%s\" in configfile is missing"
    2.26 +
    2.27 +def checkMinimumOptions (config):
    2.28 +    for section, options in MINOPTS.iteritems ():
    2.29 +        for option in options:
    2.30 +            if (config.has_option(section, option) == False):
    2.31 +                print (CONFIG_MISSING % (section, option))
    2.32 +                exit (129)
    2.33 +    
    2.34 +    
    2.35 +def loadConfig ():
    2.36 +    configfile = CONFIG_FILE
    2.37 +    config = ConfigParser.SafeConfigParser ()
    2.38 +
    2.39 +    if ((os.path.exists (configfile) == False) or (os.path.isfile (configfile) == False) or (os.access (configfile, os.R_OK) == False)):
    2.40 +        print (CONFIG_NOT_READABLE)
    2.41 +        exit (1)
    2.42 +
    2.43 +    try:
    2.44 +        config.read (CONFIG_FILE)
    2.45 +    except Exception, e:
    2.46 +        print (CONFIG_WRONG)
    2.47 +        print ("Error: %s" % (e))
    2.48 +        exit (1)
    2.49 +
    2.50 +    checkMinimumOptions (config)
    2.51 +    return config
    2.52 +
    2.53 +def initLog (config):
    2.54 +    global LOG
    2.55 +    logfile = config.get("Main", "LogFile")
    2.56 +    
    2.57 +    numeric_level = getattr(logging, config.get("Main", "LogLevel").upper(), None)
    2.58 +    if not isinstance(numeric_level, int):
    2.59 +        raise ValueError('Invalid log level: %s' % loglevel)
    2.60 +
    2.61 +    # ToDo move log level and maybe other things to config file
    2.62 +    logging.basicConfig(
    2.63 +                        level = numeric_level,
    2.64 +                        format = "%(asctime)s %(name)-12s %(funcName)-15s %(levelname)-8s %(message)s",
    2.65 +                        datefmt = "%Y-%m-%d %H:%M:%S",
    2.66 +                        filename = logfile,
    2.67 +                        filemode = "a+",
    2.68 +    )
    2.69 +    LOG = logging.getLogger("fuse_main")
    2.70 +    
    2.71 +    
    2.72 +    
    2.73 +    
    2.74 +    
    2.75 +    
    2.76 +    
    2.77 +
    2.78 +if __name__ == "__main__":
    2.79 +    
    2.80 +    parser = argparse.ArgumentParser(epilog='--mount, --umount and --initialize are mutually exclusive')
    2.81 +    group = parser.add_mutually_exclusive_group(required=True)
    2.82 +    group.add_argument('-m', '--mount', action='store', nargs=4, dest='mount', help='Mounts an encrypted device.', metavar=("interface", "port", "device", "mountpoint"))
    2.83 +    group.add_argument('-u', '--umount', action='store', nargs=1, dest='umount', help='Unmounts an encrypted device', metavar="device")
    2.84 +    group.add_argument('-i', '--initialize', action='store', nargs=4, dest='initialize', help='Initialize an device.', metavar=("interface", "port", "device", "mountpoint"))
    2.85 +    group.add_argument('-g', '--getdevices', action='store_true', dest="getdevices", help='Returns a list of all encrypted mounted devices')
    2.86 +    arguments = parser.parse_args()
    2.87 +    
    2.88 +    
    2.89 +    config = loadConfig ()
    2.90 +    initLog (config)
    2.91 +    
    2.92 +    
    2.93 +    if (arguments.getdevices):
    2.94 +        print ("%s" %(arguments.getdevices,))
    2.95 +        
    2.96 +    if (arguments.umount):
    2.97 +        print ("%s" %(arguments.umount,))
    2.98 +    
    2.99 +    if (arguments.mount):
   2.100 +        print ("%s" %(arguments.mount,))
   2.101 +    
   2.102 +    if (arguments.initialize):
   2.103 +        print ("%s" %(arguments.initialize,))
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/truecrypt_scripts/truecrypt_config.cfg	Tue Feb 25 08:08:37 2014 +0100
     3.3 @@ -0,0 +1,3 @@
     3.4 +#!/bin/bash
     3.5 +
     3.6 +tc_cmd="/usr/bin/truecrypt"
     3.7 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/truecrypt_scripts/truecrypt_getdevices.bash	Tue Feb 25 08:08:37 2014 +0100
     4.3 @@ -0,0 +1,18 @@
     4.4 +#!/bin/bash
     4.5 +
     4.6 +if [ -r "truecrypt_config.cfg" ]
     4.7 +then
     4.8 +	. truecrypt_config.cfg
     4.9 +else
    4.10 +	exit 1
    4.11 +fi
    4.12 +
    4.13 +devicelist="$($tc_cmd -l | awk '{ print $2}')"
    4.14 +result="$?"
    4.15 +if [ "$result" != "0" ]
    4.16 +then
    4.17 +	exit 1
    4.18 +fi
    4.19 +
    4.20 +echo "$devicelist"
    4.21 +exit 0
    4.22 \ No newline at end of file