-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_wildcard_cert.py
executable file
·51 lines (38 loc) · 1.19 KB
/
make_wildcard_cert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# Simple wrapper to create wildcard dns certificates using certbot and acme-dns
# CoCo - e.t.s.v. Thor
import subprocess
import argparse
from string import Template
from typing import List
import re
AUTHHOOK_PATH = "/etc/letsencrypt/acme-dns-auth.py"
CERTBOT_COMMAND_BASE = [
"certbot",
"certonly",
"--manual",
"--manual-auth-hook",
AUTHHOOK_PATH,
"--preferred-challenges",
"dns",
"--debug-challenges",
]
domain_pattern = re.compile(
r"^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|"
r"([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|"
r"([a-zA-Z0-9][-_.a-zA-Z0-9]{0,61}[a-zA-Z0-9]))\."
r"([a-zA-Z]{2,13}|[a-zA-Z0-9-]{2,30}.[a-zA-Z]{2,3})$"
)
def create_certbot_command(domain: str) -> List:
if domain.startswith("*."):
domain = domain[2:]
command = CERTBOT_COMMAND_BASE + ["-d", domain, "-d", "*." + domain]
return command
parser = argparse.ArgumentParser()
parser.add_argument("domain", type=str, help="Domain to be used")
args = parser.parse_args()
domain = args.domain
if not domain_pattern.match(domain):
raise Exception("Invalid domain provided")
command = create_certbot_command(domain)
subprocess.call(command)