Changes

From SME Server
Jump to navigationJump to search
2,437 bytes added ,  02:53, 17 March 2007
New page: Extracted from: http://forums.contribs.org/index.php?topic=34624.0 Author: slords As root do the following: mkdir ~/cacert cd ~/cacert Make a file named #!/usr/bin/perl use strict; use...
Extracted from: http://forums.contribs.org/index.php?topic=34624.0
Author: slords

As root do the following:

mkdir ~/cacert
cd ~/cacert

Make a file named

#!/usr/bin/perl

use strict;
use esmith::util;
use esmith::ConfigDB;
use esmith::DomainsDB;

my $config = esmith::ConfigDB->open;
my $domainsdb = esmith::DomainsDB->open_ro;

my $domain = $config->get('DomainName')->value;
my %domain_names = map { $_->{key} => 1 } grep { $_->key ne $domain } $domainsdb->domains;

my @domains = ($domain, keys %domain_names);

open(CONFIG, ">$domains[0].config") or die "Can't open openssl config file: $!";
print CONFIG "HOME = .\nRANDFILE = \$ENV::HOME/.rnd\n\n";
print CONFIG "[ req ]\ndefault_bits = 1024\ndistinguished_name = req_distinguished_name\n";
print CONFIG "req_extensions = v3_req\nprompt = no\n\n";
print CONFIG "[ req_distinguished_name ]\nCN = $domains[0]\n\n";
print CONFIG "[ v3_req ]\nbasicConstraints = CA:FALSE\nkeyUsage = nonRepudiation,digitalSignature,keyEncipherment\n";
print CONFIG "subjectAltName = critical,", join ",", map { "DNS:$_,DNS:*.$_" } @domains;
print CONFIG "\n";
close(CONFIG) or die "Closing openssl config file reported: $!";

unless ( -f "$domains[0].key" )
{
open(KEY, ">$domains[0].key") or die "Can't open key file: $!";
unless (open(SSL,"-|"))
{
exec("/usr/bin/openssl",
qw(genrsa -rand),
join(':',
qw(
/proc/apm
/proc/cpuinfo
/proc/dma
/proc/filesystems
/proc/interrupts
/proc/ioports
/proc/bus/pci/devices
/proc/rtc
/proc/uptime
)),
'1024')
|| die "can't exec program: $!";
}
while (<SSL>)
{
print KEY $_;
}
close(SSL) or die "Closing openssl pipe reported: $!";
close(KEY) or die "Closing key file reported: $!";
}

open(CSR, ">$domains[0].csr") or die "Can't open csr $!";
unless (open(SSL,"-|"))
{
exec("/usr/bin/openssl",
qw(req -config), "$domains[0].config",
qw(-new -key), "$domains[0].key",
qw(-days 730 -set_serial), time())
|| die "can't exec program: $!";
}
while (<SSL>)
{
print CSR $_;
}
close(SSL) or die "Closing openssl pipe reported: $!";
close(CSR) or die "Closing csr file reported: $!";
985

edits

Navigation menu