Cleaned up key generation.
This commit is contained in:
@@ -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
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user