You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
978 B
18 lines
978 B
import os
|
|
import paramiko
|
|
from time import sleep
|
|
|
|
def gen_certs(client, ip):
|
|
if "temp" not in os.listdir():
|
|
os.mkdir("temp")
|
|
priv_key = paramiko.RSAKey.from_private_key_file(f"{os.environ['USERPROFILE']}{os.sep}.ssh{os.sep}id_rsa")
|
|
with paramiko.SSHClient() as ssh_client:
|
|
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
ssh_client.connect(hostname=f"{ip}", username="root", pkey=priv_key)
|
|
_, stdout, _ = ssh_client.exec_command(f"EASYRSA_BATCH=1 EASYRSA_PKI=/etc/openvpn/pki easyrsa build-client-full {client} nopass")
|
|
stdout.read()
|
|
with ssh_client.open_sftp() as scp_client:
|
|
scp_client.get(f"/etc/openvpn/pki/private/{client}.key", f"temp/{client}.key")
|
|
scp_client.get(f"/etc/openvpn/pki/issued/{client}.crt", f"temp/{client}.crt")
|
|
scp_client.get(f"/etc/openvpn/pki/ca.crt", f"temp/ca.crt")
|
|
scp_client.get(f"/etc/openvpn/keys/ta.key", f"temp/ta.key") |