script/voms-ac-issue.pl untested

filter: Statementstmt 0.0% 0 / 83 Branchbran 0.0% 0 / 66 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 3 Podpod n/a totaltotal 0.0% 0 / 157 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 qw(Issue);
4 use VOMS::Lite::PEMHelper qw(writeAC readCert readPrivateKey);
5 use VOMS::Lite::CertKeyHelper qw(buildchain);
6  
7 my $name=$0;
8 $name =~ s#.*/##g;
9 my $usage = "Usage: $name -attrib /VO[/subgroups]*[/role][/capability]\n".
10 " " x (length($name)+8). "-holder /path/to/cert.pem\n".
11 " " x (length($name)+8). "-issuer /path/to/issuing/cert.pem\n".
12 " " x (length($name)+8). "-issuerkey /path/to/issuing/cert's/key.pem\n".
13 " " x (length($name)+8). "-cadir /path/to/dir/of/hashed-CAs or -cafile /path/to/a/CA.pem ...\n".
14 " " x (length($name)+6). "[ -out /path/to/save/AC ]\n".
15 " " x (length($name)+6). "[ -server FQDN ]\n".
16 " " x (length($name)+6). "[ -lifetime N (hours, default 12 hours) ]\n".
17 " " x (length($name)+6). "[ -target URI ]...\n";
18  
19 my ($holder,$cert,$issuer,$key);
20 my $lifetime=(12*3600);
21 my $outfile="/tmp/vomsAC_u$<";
22 my $server=(eval "require Sys::Hostname;") ? Sys::Hostname::hostname : "localhost.localdomain";
23 my @Attribs;
24 my @CAdirs;
25 my @CAfiles;
26 my @targets;
27 while ($_=shift @ARGV) {
28 if ( /^--?holder$/ ) {
29 $holder=shift @ARGV;
30 die "$& requires an argument" if ( ! defined $holder );
31 die "cannot open certificate file $holder" if ( ! -r $holder );
32 }
33 elsif ( /^--?out$/ ) {
34 $outfile=shift @ARGV;
35 die "$& requires an argument" if ( ! defined $outfile );
36 }
37 elsif ( /^--?(?:ca|CA)(?:path|dir)$/ ) {
38 my $dir=shift @ARGV;
39 die "$& requires an argument" if ( ! defined $dir );
40 die "$dir is not a directory" if ( ! -d $dir );
41 push @CAdirs, $dir;
42 }
43 elsif ( /^--?(?:ca|CA)file$/ ) {
44 my $file=shift @ARGV;
45 die "$& requires an argument" if ( ! defined $file );
46 die "cannot open $file" if ( ! -r $file );
47 push @CAfiles, $file;
48 }
49 elsif ( /^--?attrib$/ ) {
50 my $attrib=shift @ARGV;
51 die "$& requires an argument" if ( ! defined $attrib );
52 if ( $attrib =~ m#^(/[^/]+(?:/[^/]+)*?(?:/Role=[^/]+)?(?:/Capability=[^/]+)?)$# ) { push @Attribs,$1; }
53 else { die "Invalid Attribute $attrib"; }
54 }
55 elsif ( /^--?issuer$/ ) {
56 $issuer=shift @ARGV;
57 die "$& requires an argument" if ( ! defined $issuer );
58 die "cannot open issuer certificate file $issuer" if ( ! -r $issuer );
59 }
60 elsif ( /^--?issuerkey$/ ) {
61 $key=shift @ARGV;
62 die "$& requires an argument" if ( ! defined $key );
63 die "cannot open issuer certificate file $key" if ( ! -r $key );
64 }
65 elsif ( /^--?server$/ ) {
66 $server = shift @ARGV;
67 die "$& requires an argument" if ( ! defined $server );
68 }
69 elsif ( /^--?target$/ ) {
70 my $target=shift @ARGV;
71 die "$& requires an argument" if ( ! defined $target );
72 push @targets,$target;
73 }
74 elsif ( /^--?lifetime$/ ) {
75 my $lifetime=shift @ARGV;
76 die "$& requires an argument" if ( ! defined $lifetime );
77 if ( $lifetime =~ /^[0-9]+$/ ) { $lifetime=($1*3600); }
78 else { die "$& requires a positive numeric integer argument."; }
79 }
80 else { die "Unrecognised option \"$_\"\n$usage"; }
81 }
82  
83 die "need to specify a holder\n$usage" if ( ! defined $holder );
84 die "need to specify an issuer\n$usage" if ( ! defined $issuer );
85 die "need to specify a issuerkey\n$usage" if ( ! defined $key );
86 die "No trust root specified, this is required, use -CAdir or -CAfile" if (@CAdirs == 0 && @CAfiles == 0);
87  
88 my @certs=readCert($holder);
89 my @CAcerts=();
90 foreach (@CAfiles) { print "$_\n"; push @CAcerts, VOMS::Lite::PEMHelper::readCert($_); }
91  
92 my %Chain = %{ buildchain( { trustedCAdirs => \@CAdirs, suppliedcerts => \@certs, trustedCAs => \@CAcerts } ) };
93 my $vomscert=readCert($issuer);
94 my $vomskey=readPrivateKey($key);
95  
96 # Get AC
97 my $acref = VOMS::Lite::AC::Create( { Cert => $Chain{EndEntityCert},
98 VOMSCert => $vomscert,
99 VOMSKey => $vomskey,
100 Lifetime => $lifetime,
101 Server => $server,
102 Port => $$, #
103 Serial => time(), #Reasonably different
104 Code => $$, #
105 Attribs => \@Attribs,
106 Broken => 1 } );
107 my %hash=%$acref;
108 foreach my $hash (keys %hash) {
109 if ( ref($hash{$hash}) eq "ARRAY" ) {
110 my $arrayref=$hash{$hash};
111 my @array=@$arrayref;
112 my $tmp=$hash;
113 foreach (@array) { printf "%-15s %s\n", "$tmp:","$_"; $tmp=""; }
114 }
115 }
116  
117 writeAC($outfile,$$acref{AC});
118  
119 __END__