from __future__ import absolute_import
from __future__ import print_function
from binascii import b2a_hqx
from runtime.spawn_subprocess import call
from subprocess import call
restart_stunnel_cmdline = ["/etc/init.d/S50stunnel", "restart"]
Restart stunnel service using SysV init stript
to apply new generated credentials
call(restart_stunnel_cmdline)
print(_("Couldn't restart stunnel service"))
# b2a_hqx output len is 4/3 input len
secret = os.urandom(192) # int(256/1.3333)
secretstring = b2a_hqx(secret)
PSKstring = ID+":"+secretstring
with open(PSKpath, 'w') as f:
def ensurePSK(ID, PSKpath):
if not os.path.exists(PSKpath):
if not os.path.exists(_PSKpath):
'Error: Pre-Shared-Key Secret in %s is missing!\n' % _PSKpath)
ID, _sep, PSK = open(_PSKpath).read().partition(':')