runtime/Stunnel.py
author Edouard Tisserant
Tue, 23 Oct 2018 13:36:07 +0200
changeset 2321 0a3103cd825d
child 2323 33a0dbabccd3
permissions -rw-r--r--
Small cosmetic change to enhance readability and avoid confusion.
import os
from binascii import hexlify

restart_stunnel_cmdline = ["/etc/init.d/S50stunnel","restart"]

def pskgen(ID, pskpath):
    secretstring = hexlify(os.urandom(256))
    pskstring = ID+":"+secretstring
    with open(pskpath, 'w') as f:
        f.write(pskstring)
    call(restart_stunnel_cmdline)

def ensurepsk(ID, pskpath):
    # check if already there
    if not os.path.exists(pskpath):
        # create if needed
        pskgen(IS, pskpath)