diff --git a/generate-config.py b/generate-config.py index 1b6555f..807c1a9 100644 --- a/generate-config.py +++ b/generate-config.py @@ -7,15 +7,7 @@ from datetime import datetime pia = piawg() # Generate public and private key pair -while True: - if os.path.exists('privatekey') or os.path.exists('publickey'): - value = input("Key files already exist. If you want to overwrite them type 'YES': ") - if value == 'YES': - pia.generate_keys() - break - else: - pia.generate_keys() - break +pia.generate_keys() # Select region title = 'Please choose a region: ' diff --git a/piawg.py b/piawg.py index d354a49..58ada0f 100644 --- a/piawg.py +++ b/piawg.py @@ -2,7 +2,7 @@ import requests import json from requests_toolbelt.adapters import host_header_ssl import urllib3 -import os +import subprocess import urllib.parse # PIA uses the CN attribute for certificates they issue themselves. @@ -51,15 +51,9 @@ class piawg: return False def generate_keys(self): - os.system('wg genkey > privatekey') - os.system('wg pubkey < privatekey > publickey') - - # Read newly created keys - with open('publickey', 'r') as file: - self.publickey = file.read().splitlines()[0] - - with open('privatekey', 'r') as file: - self.privatekey = file.read().splitlines()[0] + self.privatekey = subprocess.run(['wg', 'genkey'], stdout=subprocess.PIPE, encoding="utf-8").stdout.strip() + self.publickey = subprocess.run(['wg', 'pubkey'], input=self.privatekey, stdout=subprocess.PIPE, + encoding="utf-8").stdout.strip() def addkey(self): # Get common name and IP address for wireguard endpoint in region