Cleaned up key generation.

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

@ -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: '

@ -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

Loading…
Cancel
Save