from binascii import b2a_hqx
from runtime.spawn_subprocess import call
restart_stunnel_cmdline = ["/etc/init.d/S50stunnel","restart"]
# 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:
call(restart_stunnel_cmdline)
def ensurePSK(ID, PSKpath):
if not os.path.exists(PSKpath):
if _PSKpath is not None :
if not os.path.exists(_PSKpath):
confnodesroot.logger.write_error(
'Error: Pre-Shared-Key Secret in %s is missing!\n' % _PSKpath)
ID,_sep,PSK = open(_PSKpath).read().partition(':')