]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/gnutlscert.pm
Fix checking whether kqueue is available.
[user/henk/code/inspircd.git] / make / gnutlscert.pm
1 #
2 # InspIRCd -- Internet Relay Chat Daemon
3 #
4 #   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 #   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
6 #
7 # This file is part of InspIRCd.  InspIRCd is free software: you can
8 # redistribute it and/or modify it under the terms of the GNU General Public
9 # License as published by the Free Software Foundation, version 2.
10 #
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14 # details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20
21 package make::gnutlscert;
22
23 require 5.8.0;
24
25 use strict;
26 use warnings FATAL => qw(all);
27
28 use Exporter 'import';
29 use make::configure;
30 our @EXPORT = qw(make_gnutls_cert);
31
32 # On OS X the GnuTLS certtool is prefixed to avoid collision with the system certtool.
33 my $certtool = $^O eq 'darwin' ? 'gnutls-certtool' : 'certtool';
34
35 sub make_gnutls_cert()
36 {
37         if (system "$certtool --version >/dev/null 2>&1")
38         {
39                 print "\e[1;31mError:\e[0m unable to find '$certtool' in the PATH!\n";
40                 return 1;
41         }
42         open (FH, ">certtool.template");
43         my $timestr = time();
44         my $commonname = promptstring_s('What is the hostname of your server?', 'irc.example.com');
45         my $email = promptstring_s('What email address can you be contacted at?', 'example@example.com');
46         my $unit = promptstring_s('What is the name of your unit?', 'Server Admins');
47         my $org = promptstring_s('What is the name of your organization?', 'Example IRC Network');
48         my $city = promptstring_s('What city are you located in?', 'Example City');
49         my $state = promptstring_s('What state are you located in?', 'Example State');
50         my $country = promptstring_s('What is the ISO 3166-1 code for the country you are located in?', 'XZ');
51         my $days = promptstring_s('How many days do you want your certificate to be valid for?', '365');
52         print FH <<__END__;
53 # X.509 Certificate options
54 #
55 # DN options
56
57 # The organization of the subject.
58 organization = "$org"
59
60 # The organizational unit of the subject.
61 unit = "$unit"
62
63 # The locality of the subject.
64 locality = "$city"
65
66 # The state of the certificate owner.
67 state = "$state"
68
69 # The country of the subject. Two letter code.
70 country = "$country"
71
72 # The common name of the certificate owner.
73 cn = "$commonname"
74
75 # A user id of the certificate owner.
76 #uid = "clauper"
77
78 # If the supported DN OIDs are not adequate you can set
79 # any OID here.
80 # For example set the X.520 Title and the X.520 Pseudonym
81 # by using OID and string pairs.
82 #dn_oid = "2.5.4.12" "Dr." "2.5.4.65" "jackal"
83
84 # This is deprecated and should not be used in new
85 # certificates.
86 # pkcs9_email = "none\@none.org"
87
88 # The serial number of the certificate
89 serial = $timestr
90
91 # In how many days, counting from today, this certificate will expire.
92 expiration_days = $days
93
94 # X.509 v3 extensions
95
96 # A dnsname in case of a WWW server.
97 #dns_name = "www.none.org"
98
99 # An IP address in case of a server.
100 #ip_address = "192.168.1.1"
101
102 # An email in case of a person
103 email = "$email"
104
105 # An URL that has CRLs (certificate revocation lists)
106 # available. Needed in CA certificates.
107 #crl_dist_points = "http://www.getcrl.crl/getcrl/"
108
109 # Whether this is a CA certificate or not
110 #ca
111
112 # Whether this certificate will be used for a TLS client
113 tls_www_client
114
115 # Whether this certificate will be used for a TLS server
116 tls_www_server
117
118 # Whether this certificate will be used to sign data (needed
119 # in TLS DHE ciphersuites).
120 signing_key
121
122 # Whether this certificate will be used to encrypt data (needed
123 # in TLS RSA ciphersuites). Note that it is prefered to use different
124 # keys for encryption and signing.
125 encryption_key
126
127 # Whether this key will be used to sign other certificates.
128 cert_signing_key
129
130 # Whether this key will be used to sign CRLs.
131 crl_signing_key
132
133 # Whether this key will be used to sign code.
134 code_signing_key
135
136 # Whether this key will be used to sign OCSP data.
137 ocsp_signing_key
138
139 # Whether this key will be used for time stamping.
140 time_stamping_key
141 __END__
142 close(FH);
143 if ( (my $status = system("$certtool --generate-privkey --outfile key.pem")) ne 0) { return 1; }
144 if ( (my $status = system("$certtool --generate-self-signed --load-privkey key.pem --outfile cert.pem --template certtool.template")) ne 0) { return 1; }
145 unlink("certtool.template");
146 return 0;
147 }
148
149 1;
150