39 lines
1.2 KiB
Python
Executable File
39 lines
1.2 KiB
Python
Executable File
#!/usr/bin/python3
|
|
''' This Script decrypt Wireguardfiles for Wirepy users '''
|
|
|
|
import os
|
|
from subprocess import check_call
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
''' Dirname "tlecdewg" = Tunnel Encrypt Decrypt Wireguard '''
|
|
dirname = Path('/tmp/tlecdcwg/')
|
|
keyfile = '/usr/local/etc/ssl/pwgk.pem'
|
|
logname = os.getlogin()
|
|
|
|
''' Remove the folder when it is there '''
|
|
if os.path.exists(str(dirname)):
|
|
shutil.rmtree(str(dirname))
|
|
|
|
os.mkdir(dirname)
|
|
shutil.chown(dirname, 1000, 1000)
|
|
tl = os.listdir(str(dirname))
|
|
|
|
dirname2 = '/home/' + logname + '/.config/wire_py/'
|
|
detl = os.listdir(dirname2)
|
|
os.chdir(dirname2)
|
|
detl.remove('keys')
|
|
detl.remove('settings')
|
|
if os.path.exists(dirname2 + 'pbwgk.pem'):
|
|
detl.remove('pbwgk.pem')
|
|
for detunnels in detl:
|
|
tlname2 = detunnels[:-4] + '.conf'
|
|
extpath = str(dirname) + '/' + tlname2
|
|
check_call(['openssl', 'pkeyutl', '-decrypt', '-inkey', keyfile, '-in', detunnels, '-out', extpath])
|
|
|
|
|
|
def create_pub_key():
|
|
pth_with_keyname = '/home/' + logname + '/.config/wire_py/pbwgk.pem'
|
|
check_call(['openssl', 'rsa', '-in', keyfile, '-out', pth_with_keyname, '-outform', 'PEM', '-pubout'])
|
|
shutil.chown(pth_with_keyname, 1000, 1000)
|