Cleaned up key generation.

main
Harrison Sand 5 years ago
parent 168b90472d
commit 14bb8a1eb2

@ -7,15 +7,7 @@ from datetime import datetime
pia = piawg() pia = piawg()
# Generate public and private key pair # Generate public and private key pair
while True: pia.generate_keys()
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
# Select region # Select region
title = 'Please choose a region: ' title = 'Please choose a region: '

@ -2,7 +2,7 @@ import requests
import json import json
from requests_toolbelt.adapters import host_header_ssl from requests_toolbelt.adapters import host_header_ssl
import urllib3 import urllib3
import os import subprocess
import urllib.parse import urllib.parse
# PIA uses the CN attribute for certificates they issue themselves. # PIA uses the CN attribute for certificates they issue themselves.
@ -51,15 +51,9 @@ class piawg:
return False return False
def generate_keys(self): def generate_keys(self):
os.system('wg genkey > privatekey') self.privatekey = subprocess.run(['wg', 'genkey'], stdout=subprocess.PIPE, encoding="utf-8").stdout.strip()
os.system('wg pubkey < privatekey > publickey') self.publickey = subprocess.run(['wg', 'pubkey'], input=self.privatekey, stdout=subprocess.PIPE,
encoding="utf-8").stdout.strip()
# 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]
def addkey(self): def addkey(self):
# Get common name and IP address for wireguard endpoint in region # Get common name and IP address for wireguard endpoint in region

Loading…
Cancel
Save