-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsend_mitcert_request.py
executable file
·48 lines (37 loc) · 1.21 KB
/
send_mitcert_request.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
#!/usr/bin/env python
from __future__ import print_function
from email.mime.text import MIMEText
import socket
import subprocess
import sys
locker = sys.argv[1]
hostnames = []
for hostname in sys.argv[2:]:
hostname = hostname.lower()
if not hostname.endswith(".mit.edu"):
hostname += ".mit.edu"
if hostname not in hostnames:
hostnames.append(hostname)
for hostname in hostnames:
assert hostname.endswith(".mit.edu"), hostname
assert socket.gethostbyname(hostname) == "18.4.86.46", hostname
csr = subprocess.check_output(["sudo", "/etc/pki/tls/gencsr-pony", locker] + hostnames)
assert csr.startswith("-----BEGIN CERTIFICATE REQUEST-----\n")
msg = MIMEText(
"""\
At your convenience, please sign this certificate for
{hostnames} (an alias of scripts-vhosts).
Thanks,
SIPB Scripts team
{csr}
""".format(
hostnames=", ".join(hostnames), csr=csr
)
)
msg["From"] = "scripts-tls@mit.edu"
msg["To"] = "mitcert@mit.edu"
msg["Cc"] = "scripts-root@mit.edu"
msg["Subject"] = "Certificate signing request for " + ", ".join(hostnames)
p = subprocess.Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=subprocess.PIPE)
p.communicate(msg.as_string())
print("CSR sent for " + ", ".join(hostnames))