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
9 # Make a self signed cert
14 use File::Spec::Functions qw(catfile);
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}" : '';
20 my $conf = catfile($dir, 'req.conf');
21 my $key = catfile($dir, 'key.pem' );
22 my $cert = catfile($dir, 'cert.pem');
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;
32 Net::SSLeay Organization
39 system "$exe_path verify $cert"; # Just to check
41 # Generate an encrypted password too
42 system "$exe_path rsa -in $key -des -passout pass:secret -out $key.e";
44 ### Prepare examples directory as certificate directory
46 my $hash = `$exe_path x509 -inform pem -hash -noout <$cert`;
49 my $hash_file = catfile($dir, "$hash.0");
51 copy($cert, $hash_file) or die "Can't symlink $dir/$hash.0 ($!)";
54 die "Usage: $0 DIR [PATH_TO_OPENSSL]";