runtime/Stunnel.py
changeset 3848 91da73c3df61
parent 3750 f62625418bff
child 3884 34da877021d5
equal deleted inserted replaced
3847:832c257d5618 3848:91da73c3df61
     1 
     1 
     2 
     2 
     3 import os
     3 import os
     4 from binascii import b2a_hqx
     4 from binascii import b2a_base64
     5 try:
     5 try:
     6     from runtime.spawn_subprocess import call
     6     from runtime.spawn_subprocess import call
     7 except ImportError:
     7 except ImportError:
     8     from subprocess import call
     8     from subprocess import call
     9 
     9 
    23         print(_("Couldn't restart stunnel service"))
    23         print(_("Couldn't restart stunnel service"))
    24 
    24 
    25 
    25 
    26 def PSKgen(ID, PSKpath):
    26 def PSKgen(ID, PSKpath):
    27 
    27 
    28     # b2a_hqx output len is 4/3 input len
    28     # secret string length is 256
       
    29     # b2a_base64 output len is 4/3 input len
    29     secret = os.urandom(192)  # int(256/1.3333)
    30     secret = os.urandom(192)  # int(256/1.3333)
    30     secretstring = b2a_hqx(secret)
    31     secretstring = b2a_base64(secret)
    31 
    32 
    32     PSKstring = ID+":"+secretstring
    33     PSKstring = ID+":"+secretstring
    33     with open(PSKpath, 'w') as f:
    34     with open(PSKpath, 'w') as f:
    34         f.write(PSKstring)
    35         f.write(PSKstring)
    35     restartStunnel()
    36     restartStunnel()