Debian lenny version packages
[pkg-perl] / deb-src / libnet-ssleay-perl / libnet-ssleay-perl-1.35 / examples / makecert.pl
1 #!/usr/bin/perl
2 # 19.6.1998, Sampo Kellomaki <sampo@iki.fi>
3 # 31.3.1999, Upgraded to OpenSSL-0.9.2b, --Sampo
4 # 31.7.1999, Upgraded to OpenSSL-0.9.3a, fixed depending on symlinks
5 #            (thanks to schinder@@pobox_.com) --Sampo
6 # 7.4.2001,  Upgraded to OpenSSL-0.9.6a --Sampo
7 # 9.11.2001, EGD patch from Mik Firestone <mik@@speed.stdio._com> --Sampo
8 #
9 # Make a self signed cert
10
11 use strict;
12 use warnings;
13 use File::Copy;
14 use File::Spec::Functions qw(catfile);
15
16 my $dir      = shift || usage();
17 my $exe_path = shift || '/usr/local/ssl/bin/openssl';
18 my $egd      = defined( $ENV{EGD_POOL} ) ? "-rand $ENV{EGD_POOL}" : '';
19
20 my $conf = catfile($dir, 'req.conf');
21 my $key  = catfile($dir, 'key.pem' );
22 my $cert = catfile($dir, 'cert.pem');
23
24 open (REQ, "|$exe_path req -config $conf "
25       . "-x509 -days 3650 -new -keyout $key $egd >$cert")
26     or die "cant open req. check your path ($!)";
27 print REQ <<DISTINGUISHED_NAME;
28 XX
29 Net::SSLeay
30 test land
31 Test City
32 Net::SSLeay Organization
33 Test Unit
34 127.0.0.1
35 sampo\@iki.fi
36 DISTINGUISHED_NAME
37     ;
38 close REQ;
39 system "$exe_path verify $cert";  # Just to check
40
41 # Generate an encrypted password too
42 system "$exe_path rsa -in $key -des -passout pass:secret -out $key.e"; 
43
44 ### Prepare examples directory as certificate directory
45
46 my $hash = `$exe_path x509 -inform pem -hash -noout <$cert`;
47 chomp $hash;
48
49 my $hash_file = catfile($dir, "$hash.0");
50 unlink $hash_file;
51 copy($cert, $hash_file) or die "Can't symlink $dir/$hash.0 ($!)";
52
53 sub usage {
54     die "Usage: $0 DIR [PATH_TO_OPENSSL]";
55 }