Listing 5: Perl script for installing client certificate
#!/usr/local/bin/perl
%arguments;
foreach (@ARGV) {
s/\n//g;
my( $key, $value ) = split( /=/ );
$arguments{$key} = $value;
}
$serial = $arguments{"serial"};
$cert = "certs/$serial.pem";
#$cert = "../../certs/$serial.pem";
open CERT, "<$cert" or die "certificate: $!\n";
@full = <CERT>;
close CERT;
$size = 0;
shift @full until( $full[0] =~ /-----BEGIN CERTIFICATE-----/ );
shift @full;
push @cert, shift @full until( ($size += (length( $cert[$#cert]) )) \ && $full[0] =~ /-----END
CERTIFICATE-----/ );
$size += length( "-----BEGIN CERTIFICATE-----\n" );
$size += length( "-----END CERTIFICATE-----\n" );
print "HTTP/1.0 200 \n";
print "Content-Type: application/x-x509-user-cert\n";
print "Content-Encoding: base64\n";
print "Content-Length: " . $size . "\n\n";
print "-----BEGIN CERTIFICATE-----\n";
foreach (@cert) { chomp; print"$_\n"; }
print "-----END CERTIFICATE-----\n";
# End of File
|