12 '/password', 'os_password',
16 #__LOG = logging.getLogger("passwordreceiver")
20 # delete the key file in a secure way (will not working on ssd's :/ ,but ram only vm -> should be ok)
21 def deleteKeyfile(self, keyfilepath):
22 filesize = os.path.getsize(keyfilepath)
23 keyfile = open (keyfilepath, "w+")
24 for i in range (0, 10):
26 keyfile.write(os.urandom(filesize))
29 os.remove(keyfilepath)
32 def GET(self, settings):
33 return self.POST(settings)
35 def POST(self, settings):
40 if not "password" in args:
41 raise web.badrequest()
44 keyfile = open (settings["keyfilepath"], "w+")
45 keyfile.write(base64.b64decode(args["keyfile"]))
47 command = [settings["script"], settings["device"], settings["mountpoint"], args["password"], settings["keyfilepath"]]
49 command = [settings["script"], settings["device"], settings["mountpoint"], args["password"]]
51 process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
52 retval = process.wait()
53 ( stdout, stderr ) = process.communicate()
56 self.deleteKeyfile(settings["keyfilepath"])
59 raise web.badrequest(stderr)
61 return "Success: Encrypted Stick is mounted"
64 # delete the key file in a secure way (will not working on ssd's :/ ,but ram only vm -> should be ok)
65 def deleteKeyfile(self, keyfilepath):
66 filesize = os.path.getsize(keyfilepath)
67 keyfile = open (keyfilepath, "w+")
68 for i in range (0, 10):
70 keyfile.write(os.urandom(filesize))
73 os.remove(keyfilepath)
75 def runPreInitScript(self, preinitscript, device):
76 #__LOG.debug("Start preinit Script")
78 command = [preinitscript, device]
79 process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
80 retval = process.wait()
81 ( stdout, stderr ) = process.communicate()
83 #__LOG.debug("preinit done result: %s" %(retval,))
86 raise web.badrequest(stderr)
88 def runPostInitScript(self, postinitscript):
89 #__LOG.debug("Start postinit Script")
91 command = [postinitscript]
92 process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
93 retval = process.wait()
94 ( stdout, stderr ) = process.communicate()
96 #__LOG.debug("postinit done result: %s" %(retval,))
99 raise web.badrequest(stderr)
101 def GET(self, settings):
102 return self.POST(settings)
104 def POST(self, settings):
109 if not "password" in args:
110 raise web.badrequest()
112 # Do the preinit stuff
113 self.runPreInitScript(settings["preinitscript"], settings["device"])
115 if "keyfile" in args:
116 keyfile = open (settings["keyfilepath"], "w+")
117 keyfile.write(base64.b64decode(args["keyfile"]))
119 command = [settings["script"], settings["device"], settings["mountpoint"], args["password"], settings["keyfilepath"]]
121 command = [settings["script"], settings["device"], settings["mountpoint"], args["password"]]
123 #__LOG.debug("Start init script")
125 process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
126 retval = process.wait()
127 ( stdout, stderr ) = process.communicate()
129 if "keyfile" in args:
130 self.deleteKeyfile(settings["keyfilepath"])
132 #__LOG.debug("init done result: %s" %(retval,))
135 raise web.badrequest(stderr)
137 # Do the postinit stuff
138 self.runPostInitScript(settings["postinitscript"])
140 return "Success: Stick is initialized and mounted"
142 class MyRestListener(web.application):
143 def __init__(self, mapping=(), fvars={}, autoreload=None, script=None, device=None, mountpoint=None, tries=None, keyfilepath=None, preinitscript=None, postinitscript=None):
144 web.application.__init__(self, mapping, fvars, autoreload)
146 self.mountpoint = mountpoint
149 self.keyfilepath = keyfilepath
150 self.preinitscript = preinitscript
151 self.postinitscript = postinitscript
153 def run(self, interface, port, *middleware):
154 func = self.wsgifunc(*middleware)
155 ifaceip = netifaces.ifaddresses(interface)[2][0]["addr"]
156 return web.httpserver.runsimple(func, (ifaceip, port))
159 fn, args = self._match(self.mapping, web.ctx.path)
160 args.append({"script": self.script, "device": self.device, "mountpoint": self.mountpoint, "tries": self.tries, "keyfilepath": self.keyfilepath, "preinitscript": self.preinitscript, "postinitscript": self.postinitscript})
161 return self._delegate(fn, self.fvars, args)