-
Notifications
You must be signed in to change notification settings - Fork 7
/
generate_ssl_cert.py
58 lines (45 loc) · 1.86 KB
/
generate_ssl_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
52
53
54
55
56
57
58
import subprocess
class NginxCert():
# The path on the local filesystem where we can read and write
# AppScale deployment metadata.
LOCAL_NGINX_PATH = "/etc/nginx/"
@classmethod
def get_certificate_location(cls, keyname):
"""Determines the location where the self-signed certificate for this
AppScale deployment can be found.
Args:
keyname: A str that indicates the name of the SSH keypair that
uniquely identifies this AppScale deployment.
Returns:
A str that indicates where the self-signed certificate can be found.
"""
return cls.LOCAL_NGINX_PATH + keyname + "-cert.pem"
@classmethod
def get_private_key_location(cls, keyname):
"""Determines the location where the private key used to sign the
self-signed certificate used for this AppScale deployment can be found.
Args:
keyname: A str that indicates the name of the SSH keypair that
uniquely identifies this AppScale deployment.
Returns:
A str that indicates where the private key can be found.
"""
return cls.LOCAL_NGINX_PATH + keyname + "-key.pem"
@classmethod
def generate_ssl_cert(cls, keyname):
"""Generates a self-signed SSL certificate that AppScale services can use
to encrypt traffic with.
Args:
keyname: A str representing the SSH keypair name used for this AppScale
deployment.
is_verbose: A bool that indicates if we want to print out the certificate
generation to stdout or not.
"""
subprocess.call("openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 " + \
"-subj '/C=US/ST=Foo/L=Bar/O=AppScale/CN=appscale.com' " + \
"-keyout {0} -out {1}".format(NginxCert.get_private_key_location(keyname),
NginxCert.get_certificate_location(keyname)), shell=True)
def main():
NginxCert.generate_ssl_cert('appscake')
if __name__ == '__main__':
main()