script/proxy-init.pl untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 139 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use VOMS::Lite::PEMHelper qw(readCert readAC readPrivateKey writeCertKey);
4 use VOMS::Lite::ASN1Helper qw(ASN1Wrap ASN1Unwrap DecToHex Hex ASN1BitStr);
5 use VOMS::Lite::PROXY;
6 use VOMS::Lite::Audit;
7  
8 my $name=$0;
9 my $lname=length($name);
10 $name =~ s#.*/##g;
11 my $usage = "Usage: $name [ -cert /path/to/cert.pem ]\n".
12 " " x ($lname+8). "[ -key /path/to/cert's/key.pem ]\n".
13 " " x ($lname+8). "[ -out /path/to/save/proxy ]\n".
14 " " x ($lname+8). "[ -vomsAC /path/to/VOMS/AC ]\n".
15 " " x ($lname+8). "[ -audit 'http://proxyaudit.endpoint' ]\n".
16 " " x ($lname+8). "[ -lifetime N (hours, default 12 hours) ]\n".
17 " " x ($lname+8). "[ -pl N ]\n".
18 " " x ($lname+8). "[ -(old|new|rfc|limited) ]\n".
19 " " x ($lname+8). "[ -limited ]\n";
20  
21 my %Input;
22 my $HolderCert="$ENV{HOME}/.globus/usercert.pem";
23 my $HolderKey="$ENV{HOME}/.globus/userkey.pem";
24 my $outfile="/tmp/x509up_u$<";
25 if ( defined $ENV{"X509_USER_PROXY"} && $ENV{"X509_USER_PROXY"} =~ /(.*)/ ) { $outfile=$1; };
26 my ($vomsattribfile,$pathlen,$lifetime,$audit);
27  
28 while ($_=shift @ARGV) {
29 if ( /^--?cert$/ ) {
30 $HolderCert=shift @ARGV;
31 die "$& requires an argument" if ( ! defined $HolderCert );
32 die "cannot open certificate file $HolderCert" if ( ! -r $HolderCert );
33 }
34 elsif ( /^--?key$/ ) {
35 $HolderKey=shift @ARGV;
36 die "$& requires an argument" if ( ! defined $HolderKey );
37 die "cannot open certificate file $HolderKey" if ( ! -r $HolderKey );
38 }
39 elsif ( /^--?vomsAC$/ ) {
40 $vomsattribfile=shift @ARGV;
41 die "$& requires an argument" if ( ! defined $vomsattribfile );
42 die "cannot open certificate file $vomsattribfile" if ( ! -r $vomsattribfile );
43 }
44 elsif ( /^--?out$/ ) {
45 $outfile=shift @ARGV;
46 die "$& requires an argument" if ( ! defined $outfile );
47 }
48 elsif ( /^--?audit$/ ) {
49 $audit=shift @ARGV;
50 die "$& requires an argument" if ( ! defined $audit );
51 }
52 elsif ( /^--?limited$/ ) { $Input{'Type'}="Limited"; }
53 elsif ( /^--?(new|gt3)$/ ) { $Input{'Type'}="Pre-RFC"; }
54 elsif ( /^--?rfc$/ ) { $Input{'Type'}="RFC"; }
55 elsif ( /^--?(old|legacy)$/ ) { $Input{'Type'}="Legacy"; }
56 elsif ( /^--?(pl|pathlength)$/ ) {
57 $pathlen=shift @ARGV;
58 die "$& requires an argument" if ( ! defined $pathlen );
59 die "Bad Pathlength argument, $& requires a positive integer" if ( $pathlen =~ /^[0-9]+$/ );
60 }
61 elsif ( /^--?lifetime$/ ) {
62 $lifetime=shift @ARGV;
63 die "$& requires an argument" if ( ! defined $lifetime );
64 die "$& requires a positive numeric integer argument." if ( $lifetime =~ /^[0-9]+$/ );
65 $lifetime*=3600;
66 }
67 else { die "Unrecognised option \"$_\"\n$usage"; }
68 }
69  
70 my @decodedCERTS=readCert($HolderCert);
71 $Input{'Cert'}=$decodedCERTS[0];
72 $Input{'Key'}=readPrivateKey($HolderKey);
73 $Input{'Lifetime'}=$lifetime;
74 $Input{'PathLength'}=$pathlen;
75  
76 if ( defined $vomsattribfile ) { $Input{'AC'}=readAC($vomsattribfile); }
77  
78 if ( defined $audit ) { $Input{'Ext'} = [ VOMS::Lite::Audit::Create("$audit") ]; }
79  
80 my %Output = %{ VOMS::Lite::PROXY::Create(\%Input) };
81  
82 if ( ! defined $Output{ProxyCert} || ! defined $Output{ProxyKey} ) {
83 foreach ( @{ $Output{Errors} } ) { print "Error: $_\n"; }
84 die "Failed to create proxy";
85 }
86  
87 foreach ( @{ $Output{Warnings} } ) { print "Warning: $_\n"; }
88  
89 writeCertKey($outfile, $Output{'ProxyCert'}, $Output{'ProxyKey'}, @decodedCERTS);
90  
91 __END__