2 # InspIRCd -- Internet Relay Chat Daemon
4 # Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 # Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
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.
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
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/>.
21 package make::gnutlscert;
26 use warnings FATAL => qw(all);
28 use Exporter 'import';
30 our @EXPORT = qw(make_gnutls_cert);
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';
35 sub make_gnutls_cert()
37 if (system "$certtool --version >/dev/null 2>&1")
39 print "\e[1;31mError:\e[0m unable to find '$certtool' in the PATH!\n";
42 open (FH, ">certtool.template");
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');
53 # X.509 Certificate options
57 # The organization of the subject.
60 # The organizational unit of the subject.
63 # The locality of the subject.
66 # The state of the certificate owner.
69 # The country of the subject. Two letter code.
72 # The common name of the certificate owner.
75 # A user id of the certificate owner.
78 # If the supported DN OIDs are not adequate you can set
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"
84 # This is deprecated and should not be used in new
86 # pkcs9_email = "none\@none.org"
88 # The serial number of the certificate
91 # In how many days, counting from today, this certificate will expire.
92 expiration_days = $days
96 # A dnsname in case of a WWW server.
97 #dns_name = "www.none.org"
99 # An IP address in case of a server.
100 #ip_address = "192.168.1.1"
102 # An email in case of a person
105 # An URL that has CRLs (certificate revocation lists)
106 # available. Needed in CA certificates.
107 #crl_dist_points = "http://www.getcrl.crl/getcrl/"
109 # Whether this is a CA certificate or not
112 # Whether this certificate will be used for a TLS client
115 # Whether this certificate will be used for a TLS server
118 # Whether this certificate will be used to sign data (needed
119 # in TLS DHE ciphersuites).
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.
127 # Whether this key will be used to sign other certificates.
130 # Whether this key will be used to sign CRLs.
133 # Whether this key will be used to sign code.
136 # Whether this key will be used to sign OCSP data.
139 # Whether this key will be used for time stamping.
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");