]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/gnutlscert.pm
Fix mistakenly using Clang instead of GCC on older FreeBSD versions.
[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
33 sub make_gnutls_cert()
34 {
35         open (FH, ">certtool.template");
36         my $timestr = time();
37         my $commonname = promptstring_s('What is the hostname of your server?', 'irc.example.com');
38         my $email = promptstring_s('What email address can you be contacted at?', 'example@example.com');
39         my $unit = promptstring_s('What is the name of your unit?', 'Server Admins');
40         my $org = promptstring_s('What is the name of your organization?', 'Example IRC Network');
41         my $city = promptstring_s('What city are you located in?', 'Example City');
42         my $state = promptstring_s('What state are you located in?', 'Example State');
43         my $country = promptstring_s('What is the ISO 3166-1 code for the country you are located in?', 'XZ');
44         my $days = promptstring_s('How many days do you want your certificate to be valid for?', '365');
45         print FH <<__END__;
46 # X.509 Certificate options
47 #
48 # DN options
49
50 # The organization of the subject.
51 organization = "$org"
52
53 # The organizational unit of the subject.
54 unit = "$unit"
55
56 # The locality of the subject.
57 locality = "$city"
58
59 # The state of the certificate owner.
60 state = "$state"
61
62 # The country of the subject. Two letter code.
63 country = "$country"
64
65 # The common name of the certificate owner.
66 cn = "$commonname"
67
68 # A user id of the certificate owner.
69 #uid = "clauper"
70
71 # If the supported DN OIDs are not adequate you can set
72 # any OID here.
73 # For example set the X.520 Title and the X.520 Pseudonym
74 # by using OID and string pairs.
75 #dn_oid = "2.5.4.12" "Dr." "2.5.4.65" "jackal"
76
77 # This is deprecated and should not be used in new
78 # certificates.
79 # pkcs9_email = "none\@none.org"
80
81 # The serial number of the certificate
82 serial = $timestr
83
84 # In how many days, counting from today, this certificate will expire.
85 expiration_days = $days
86
87 # X.509 v3 extensions
88
89 # A dnsname in case of a WWW server.
90 #dns_name = "www.none.org"
91
92 # An IP address in case of a server.
93 #ip_address = "192.168.1.1"
94
95 # An email in case of a person
96 email = "$email"
97
98 # An URL that has CRLs (certificate revocation lists)
99 # available. Needed in CA certificates.
100 #crl_dist_points = "http://www.getcrl.crl/getcrl/"
101
102 # Whether this is a CA certificate or not
103 #ca
104
105 # Whether this certificate will be used for a TLS client
106 tls_www_client
107
108 # Whether this certificate will be used for a TLS server
109 tls_www_server
110
111 # Whether this certificate will be used to sign data (needed
112 # in TLS DHE ciphersuites).
113 signing_key
114
115 # Whether this certificate will be used to encrypt data (needed
116 # in TLS RSA ciphersuites). Note that it is prefered to use different
117 # keys for encryption and signing.
118 encryption_key
119
120 # Whether this key will be used to sign other certificates.
121 cert_signing_key
122
123 # Whether this key will be used to sign CRLs.
124 crl_signing_key
125
126 # Whether this key will be used to sign code.
127 code_signing_key
128
129 # Whether this key will be used to sign OCSP data.
130 ocsp_signing_key
131
132 # Whether this key will be used for time stamping.
133 time_stamping_key
134 __END__
135 close(FH);
136 my $certtool = "certtool";
137 if (`uname -s` eq "Darwin\n") {
138         # On OS X the certtool binary name is different to prevent
139         # collisions with the system certtool from NSS.
140         $certtool = "gnutls-certtool";
141 }
142 if ( (my $status = system("$certtool --generate-privkey --outfile key.pem")) ne 0) { return 1; }
143 if ( (my $status = system("$certtool --generate-self-signed --load-privkey key.pem --outfile cert.pem --template certtool.template")) ne 0) { return 1; }
144 unlink("certtool.template");
145 return 0;
146 }
147
148 1;
149