Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 78 lines (60 sloc) 1.945 kB
e53a712 @alobbs Adds a missing file
alobbs authored
1 # -*- coding: utf-8 -*-
2 #
3 # Cherokee-admin
4 #
5 # Authors:
6 # Alvaro Lopez Ortega <alvaro@alobbs.com>
7 #
8 # Copyright (C) 2001-2011 Alvaro Lopez Ortega
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of version 2 of the GNU General Public
12 # License as published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # 02110-1301, USA.
23 #
24
25 import os
26 import CTK
27
28 from util import run
29
30 SSL_CONFIG = """
31 [ req ]
32 default_bits = 1024
33 encrypt_key = yes
34 distinguished_name = req_dn
35 x509_extensions = cert_type
36 prompt = no
37
38 [ req_dn ]
39 # Organizational Unit Name (eg. section)
40 OU=Cherokee Web Server
41
42 # Common Name (*.example.com is also possible)
43 CN=%(domain)s
44
45 # E-mail contact
46 emailAddress=root@%(domain)s
47
48 [ cert_type ]
49 nsCertType = server
50 """
51
52
53 def create_selfsigned_cert (dir_path, filename, domain, bits=1024, days=9999):
54 conf = SSL_CONFIG %(locals())
55
56 # Write the OpenSSL config file
57 conf_fp = os.path.join (dir_path, "tmp_ssl.conf")
58
59 f = open (conf_fp, 'w+')
60 f.write (conf)
61 f.close()
62
63 # Create the self signed cert
64 crt_fp = os.path.join (dir_path, "%s.crt"%(filename))
65 key_fp = os.path.join (dir_path, "%s.key"%(filename))
66
67 cmd = "openssl req -new -x509 -nodes -out %(crt_fp)s -keyout %(key_fp)s -config %(conf_fp)s" %(locals())
68 re = run (cmd, stdout=False, stderr=True, retcode=True)
69
70 os.unlink (conf_fp)
71
72 if re['retcode'] != 0:
73 return re['stderr']
74
75
76 if __name__ == "__main__":
77 create_selfsigned_cert ("/tmp", "test")
Something went wrong with that request. Please try again.