script/extractVOMS.pl untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 3 Podpod n/a totaltotal 0.0% 0 / 86 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 writeAC);
4 use VOMS::Lite::CertKeyHelper qw(buildchain);
5 use VOMS::Lite::X509;
6  
7 my $cert=undef;
8  
9 while ($_=shift @ARGV) {
10 if ( /^(--?cert)$/ ) {
11 $cert=shift @ARGV;
12 die "$1 requires an argument" if ( ! defined $cert );
13 die "cannot open certificate file $cert" if ( ! -r $cert );
14 }
15 elsif ( /^(--?out)$/ ) {
16 $out=shift @ARGV;
17 die "$1 requires an argument" if ( ! defined $out );
18 }
19 else { die "Unrecognised option \"$_\"\nUsage: $0 [ -cert /path/to/cert.pem ] [ -out /path/to/save/AC.pem ]"; }
20 }
21  
22 if ( ! defined $cert ) {
23 if ( defined $ENV{X509_USER_PROXY} && $ENV{X509_USER_PROXY} =~ /(.*)/ ) { $cert=$1; }
24 else { $cert="/tmp/x509up_u$<" };
25 }
26  
27 if ( ! defined $out ) {
28 if ( defined $ENV{VOMS_USER_AC} && $ENV{VOMS_USER_AC} =~ /(.*)/ ) { $out=$1; }
29 else { $out="/tmp/vomsAC_u$<" };
30 }
31  
32 my @cert=readCert($cert);
33 my %Chain = %{ buildchain( { suppliedcerts => \@cert } ) };
34  
35 my $got=0;
36 for ( my $i=0;$i<@{ $Chain{Certs} };$i++) {
37 print "Checking ".${ $Chain{DistinguishedNames} }[$i]." for VOMS Attribute Extension ... ";
38 my $AC=${VOMS::Lite::X509::Examine($cert[$i],{'Extension:1.3.6.1.4.1.8005.100.100.5' => "" })}{'Extension:1.3.6.1.4.1.8005.100.100.5'};
39  
40 if ( $AC eq "" ) { print "Nope!\n";}
41 elsif ( $got == 0 ) {
42 print "Found!\nWriting it out to $out\n";
43 if ( $AC ne "" ) { writeAC($out,$AC); }
44 $got++;
45 }
46 else {
47 print "Found!\nNOT Writing it out to file\n";
48 }
49 }
50  
51 __END__