lib/VOMS/Lite/PROXY.pm

filter: Statementstmt 79.5% 136 / 171 Branchbran 48.0% 48 / 100 Conditioncond 33.3% 18 / 54 MC/DCmcdc 0.0% 0 / 36 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 2 totaltotal 56.6% 212 / 374 CC 71 SCAR 59.4
CC
71
Cov
62%
Create
431.2
Examine
2.0
BEGIN
1.0
CRAP 378.1
« lib/VOMS/Lite/Attribs/DBHelper.pm ↑ Summary lib/VOMS/Lite/SAMLHelper.pm »
1 package VOMS::Lite::PROXY;
2  
3 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use VOMS::Lite::PEMHelper qw(readCert readAC readPrivateKey);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use VOMS::Lite::CertKeyHelper qw(digestSign);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use VOMS::Lite::ASN1Helper qw(ASN1Wrap ASN1Unwrap DecToHex Hex ASN1BitStr);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use VOMS::Lite::KEY;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use VOMS::Lite::X509;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use VOMS::Lite::RSAKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 require Exporter;
13 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 @ISA = qw(Exporter);
15  
16 1 $VERSION = '0.20';
17  
18 0 ▶sub Examine {
Subroutine Examine: not called CC=1 SCAR=6.9
Pod undocumented
19 0 return VOMS::Lite::X509::Examine(@_);
20 }
21  
22 1 ▶sub Create {
Subroutine Create: called CC=71 SCAR=60.7
Pod undocumented
23  
24 # Load in Context
25 1 my %context = %{ shift() };
26  
27 # Create error and warning arrays
28 1 my @Errors;
29 my @Warnings;
30  
31 # Get request time;
32 1 my $now=time();
33  
34 # Check for required input values
35 0 ▶ if ( ! defined $context{'Cert'} ) { push @Errors, "PROXY: Issuer certificate not supplied"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $context{"Cert"}) 0 1 1
36 0 ▶ if ( ! defined $context{'Key'} ) { push @Errors, "PROXY: Issuer key not supplied"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $context{"Key"}) 0 1 1
37  
38 # Bail if there isn't enough information
39 0 ▶ if ( @Errors > 0 ) { return { Errors => \@Errors} ; }
Branch: 1 branch
BranchTrueFalseTotal
if (@Errors > 0) 0 1 1
40  
41 # Load input data into local variables
42 1 ▶ my $CertInfoRef = (($context{'Cert'} =~ /^(\060.+)$/s) ? VOMS::Lite::X509::Examine($&, {X509serial=>"", X509subject=>"", End=>""}) : undef);
Branch: 1 branch
BranchTrueFalseTotal
$context{'Cert'} =~ /^(\060.+)$/s ? : 1 0 1
43 1 ▶ my $KeyInfoRef = (($context{'Key'} =~ /^(\060.+)$/s) ? VOMS::Lite::KEY::Examine($&, {Keymodulus=>"", KeyprivateExponent=>""}) : undef);
Branch: 1 branch
BranchTrueFalseTotal
$context{'Key'} =~ /^(\060.+)$/s ? : 1 0 1
44 0 ▶ my %CI; if ( defined $CertInfoRef ) { %CI=%$CertInfoRef; } else { push @Errors, "PROXY: Unable to parse certificate."; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $CertInfoRef) { } 1 0 1
45 0 ▶ my %KI; if ( defined $KeyInfoRef ) { %KI=%$KeyInfoRef; } else { push @Errors, "PROXY: Unable to parse key."; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $KeyInfoRef) { } 1 0 1
46  
47 # Bail if there is a certificate Parse error
48 0 ▶ if ( @Errors > 0 ) { return { Errors => \@Errors} ; }
Branch: 1 branch
BranchTrueFalseTotal
if (@Errors > 0) 0 1 1
49  
50 # Load optional values
51 1 ▶ my $type = ((( defined $context{'Type'} && $context{'Type'} =~ /^(Lega[cs]y|Limited|Pre-RFC|RFC)$/) ) ? $& : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $context{'Type'} && $context{'Type'} =~ /^(Lega[cs]y|Limited|Pre-RFC|RFC)$/ ? : 1 0 1
Condition33%1/3
defined $context{"Type"} and $context{"Type"} =~ /^(Lega[cs]y|Limited|Pre-RFC|RFC)$/
!ll&&!rl&&r
001
MC/DC0%0/2
defined $context{"Type"} and $context{"Type"} =~ /^(Lega[cs]y|Limited|Pre-RFC|RFC)$/
defined $context{"Type"} $context{"Type"} =~ /^(Lega[cs]y|Limited|Pre-RFC|RFC)$/
Truth table33%1/3
A and B
A= defined $context{"Type"}B= $context{"Type"} =~ /^(Lega[cs]y|Limited|Pre-RFC|RFC)$/
ABresult
0X0
100
111
52 0 ▶ if ( $type eq "Legasy" ) { $type = "Legacy"; $context{'Type'}="Legacy"; } # oops was going through a bad spell!
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Legasy") 0 1 1
53 1 ▶ my $pathlen = ((( defined $context{'PathLength'} && $context{'PathLength'} =~ /^([0-9]+)$/s) ) ? $& : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $context{'PathLength'} && $context{'PathLength'} =~ /^([0-9]+)$/s ? : 0 1 1
Condition33%1/3
defined $context{"PathLength"} and $context{"PathLength"} =~ /^([0-9]+)$/s
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"PathLength"} and $context{"PathLength"} =~ /^([0-9]+)$/s
defined $context{"PathLength"} $context{"PathLength"} =~ /^([0-9]+)$/s
Truth table33%1/3
A and B
A= defined $context{"PathLength"}B= $context{"PathLength"} =~ /^([0-9]+)$/s
ABresult
0X0
100
111
54 1 ▶ my $bits = ((( defined $context{'Bits'} && $context{'Bits'} =~ /^(512|1024|2048|4096)$/s) ) ? $& : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $context{'Bits'} && $context{'Bits'} =~ /^(512|1024|2048|4096)$/s ? : 0 1 1
Condition33%1/3
defined $context{"Bits"} and $context{"Bits"} =~ /^(512|1024|2048|4096)$/s
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"Bits"} and $context{"Bits"} =~ /^(512|1024|2048|4096)$/s
defined $context{"Bits"} $context{"Bits"} =~ /^(512|1024|2048|4096)$/s
Truth table33%1/3
A and B
A= defined $context{"Bits"}B= $context{"Bits"} =~ /^(512|1024|2048|4096)$/s
ABresult
0X0
100
111
55 1 ▶ my $lifetime = ((( defined $context{'Lifetime'} && $context{'Lifetime'} =~ /^([0-9]+)$/s) ) ? $& : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $context{'Lifetime'} && $context{'Lifetime'} =~ /^([0-9]+)$/s ? : 1 0 1
Condition33%1/3
defined $context{"Lifetime"} and $context{"Lifetime"} =~ /^([0-9]+)$/s
!ll&&!rl&&r
001
MC/DC0%0/2
defined $context{"Lifetime"} and $context{"Lifetime"} =~ /^([0-9]+)$/s
defined $context{"Lifetime"} $context{"Lifetime"} =~ /^([0-9]+)$/s
Truth table33%1/3
A and B
A= defined $context{"Lifetime"}B= $context{"Lifetime"} =~ /^([0-9]+)$/s
ABresult
0X0
100
111
56 1 ▶ my $start = ((( defined $context{'Start'} && $context{'Start'} =~ /^([0-9]+)$/s) ) ? $& : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $context{'Start'} && $context{'Start'} =~ /^([0-9]+)$/s ? : 0 1 1
Condition33%1/3
defined $context{"Start"} and $context{"Start"} =~ /^([0-9]+)$/s
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"Start"} and $context{"Start"} =~ /^([0-9]+)$/s
defined $context{"Start"} $context{"Start"} =~ /^([0-9]+)$/s
Truth table33%1/3
A and B
A= defined $context{"Start"}B= $context{"Start"} =~ /^([0-9]+)$/s
ABresult
0X0
100
111
57 1 ▶ my $AC = ((( defined $context{'AC'} && $context{'AC'} =~ /^(\060.+)$/s) ) ? $& : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $context{'AC'} && $context{'AC'} =~ /^(\060.+)$/s ? : 0 1 1
Condition33%1/3
defined $context{"AC"} and $context{"AC"} =~ /^(\060.+)$/s
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"AC"} and $context{"AC"} =~ /^(\060.+)$/s
defined $context{"AC"} $context{"AC"} =~ /^(\060.+)$/s
Truth table33%1/3
A and B
A= defined $context{"AC"}B= $context{"AC"} =~ /^(\060.+)$/s
ABresult
0X0
100
111
58 1 my @Ext;
59 1 ▶ if ( defined $context{'Ext'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context{"Ext"}) 0 1 1
60 0 ▶ if ( ref ($context{'Ext'}) eq "ARRAY" ) { @Ext = @{ $context{'Ext'} }; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $context{'Ext'} eq 'ARRAY') { } 0 0 0
61 0 else { push @Errors,"PROXY: Ext must be an array reference"; }
62 };
63 0 ▶ foreach (@Ext) { if ( ! /^(\060.+)$/ ) { push @Errors,"Extension ".Hex($1)." isn't DER encoded"; } }
Branch: 1 branch
BranchTrueFalseTotal
unless (/^(\060.+)$/) 0 0 0
64 1 ▶ my $KeypublicE = ((( defined $context{'KeypublicExponent'} && $context{'KeypublicExponent'} =~ /^([\x00-\x7f].+)$/s) ) ? $& : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $context{'KeypublicExponent'} && $context{'KeypublicExponent'} =~ /^([\x00-\x7f].+)$/s ? : 0 1 1
Condition33%1/3
defined $context{"KeypublicExponent"} and $context{"KeypublicExponent"} =~ /^([\x00-\x7f].+)$/s
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"KeypublicExponent"} and $context{"KeypublicExponent"} =~ /^([\x00-\x7f].+)$/s
defined $context{"KeypublicExponent"} $context{"KeypublicExponent"} =~ /^([\x00-\x7f].+)$/s
Truth table33%1/3
A and B
A= defined $context{"KeypublicExponent"}B= $context{"KeypublicExponent"} =~ /^([\x00-\x7f].+)$/s
ABresult
0X0
100
111
65 1 ▶ my $KeypublicM = ((( defined $context{'KeypublicModulus'} && $context{'KeypublicModulus'} =~ /^([\x00-\x7f].+)$/s) ) ? $& : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $context{'KeypublicModulus'} && $context{'KeypublicModulus'} =~ /^([\x00-\x7f].+)$/s ? : 0 1 1
Condition33%1/3
defined $context{"KeypublicModulus"} and $context{"KeypublicModulus"} =~ /^([\x00-\x7f].+)$/s
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"KeypublicModulus"} and $context{"KeypublicModulus"} =~ /^([\x00-\x7f].+)$/s
defined $context{"KeypublicModulus"} $context{"KeypublicModulus"} =~ /^([\x00-\x7f].+)$/s
Truth table33%1/3
A and B
A= defined $context{"KeypublicModulus"}B= $context{"KeypublicModulus"} =~ /^([\x00-\x7f].+)$/s
ABresult
0X0
100
111
66  
67 # Check for unrecognised values for recognised options
68 0 ▶ if ( defined $context{'Type'} && ! defined $type ) { push @Errors, "PROXY: Unknown proxy type $context{'Type'}. Try Legacy, Limited, Pre-RFC or RFC."; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context{"Type"} and not defined $type) 0 1 1
Condition33%1/3
defined $context{"Type"} and not defined $type
!ll&&!rl&&r
010
MC/DC0%0/2
defined $context{"Type"} and not defined $type
defined $context{"Type"} not defined $type
Truth table33%1/3
A and not(B)
A= defined $context{"Type"}B= not defined $type
ABresult
0X0
100
111
69 0 ▶ if ( defined $context{'PathLength'} && ! defined $pathlen ) { push @Errors, "PROXY: Invalid Pathlength $context{'PathLength'}. Must be a positive integer."; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context{"PathLength"} and not defined $pathlen) 0 1 1
Condition33%1/3
defined $context{"PathLength"} and not defined $pathlen
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"PathLength"} and not defined $pathlen
defined $context{"PathLength"} not defined $pathlen
Truth table33%1/3
A and not(B)
A= defined $context{"PathLength"}B= not defined $pathlen
ABresult
0X0
100
111
70 0 ▶ if ( defined $context{'Bits'} && ! defined $bits ) { push @Errors, "PROXY: Key size may only be 512, 1024, 2048 or 4096."; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context{"Bits"} and not defined $bits) 0 1 1
Condition33%1/3
defined $context{"Bits"} and not defined $bits
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"Bits"} and not defined $bits
defined $context{"Bits"} not defined $bits
Truth table33%1/3
A and not(B)
A= defined $context{"Bits"}B= not defined $bits
ABresult
0X0
100
111
71 0 ▶ if ( defined $context{'Lifetime'} && ! defined $lifetime ) { push @Errors, "PROXY: Invalid Lifetime $context{'Lifetime'}. Must be a positive integer."; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context{"Lifetime"} and not defined $lifetime) 0 1 1
Condition33%1/3
defined $context{"Lifetime"} and not defined $lifetime
!ll&&!rl&&r
010
MC/DC0%0/2
defined $context{"Lifetime"} and not defined $lifetime
defined $context{"Lifetime"} not defined $lifetime
Truth table33%1/3
A and not(B)
A= defined $context{"Lifetime"}B= not defined $lifetime
ABresult
0X0
100
111
72 0 ▶ if ( defined $context{'Start'} && ! defined $start ) { push @Errors, "PROXY: Invalid Start $context{'Start'}. Must be a positive integer (seconds since epoch)."; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context{"Start"} and not defined $start) 0 1 1
Condition33%1/3
defined $context{"Start"} and not defined $start
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"Start"} and not defined $start
defined $context{"Start"} not defined $start
Truth table33%1/3
A and not(B)
A= defined $context{"Start"}B= not defined $start
ABresult
0X0
100
111
73 0 ▶ if ( defined $context{'AC'} && ! defined $AC ) { push @Errors, "PROXY: AC Must be in DER format."; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context{"AC"} and not defined $AC) 0 1 1
Condition33%1/3
defined $context{"AC"} and not defined $AC
!ll&&!rl&&r
100
MC/DC0%0/2
defined $context{"AC"} and not defined $AC
defined $context{"AC"} not defined $AC
Truth table33%1/3
A and not(B)
A= defined $context{"AC"}B= not defined $AC
ABresult
0X0
100
111
74  
75 # Check for unknown options
76 0 ▶ foreach (keys %context) { if ( ! /^(Quiet|Type|PathLength|Lifetime|AC|Ext|Cert|Key|Start|Bits|KeypublicExponent|KeypublicModulus)$/ ) { push @Errors, "PROXY: $_ is an invalid option.";}}
Branch: 1 branch
BranchTrueFalseTotal
unless (/^(Quiet|Type|PathLength|Lifetime|AC|Ext|Cert|Key|Start|Bits|KeypublicExponent|KeypublicModulus)$/) 0 4 4
77  
78 0 ▶ if ( defined $start ) { $now = $start;}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start) 0 1 1
79  
80 # Bail if any recognised options are invalid
81 0 ▶ if ( @Errors > 0 ) { return { Errors => \@Errors} ; }
Branch: 1 branch
BranchTrueFalseTotal
if (@Errors > 0) 0 1 1
82  
83 # Warn if there is something queer
84 0 ▶ if ( ! defined $type ) { $type = "Legacy"; push @Warnings, "PROXY: Undefined proxy type. Defaulting to Legacy."; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 0 1 1
85 0 ▶ if ( ! defined $lifetime ) { $lifetime = 43200; push @Warnings, "PROXY: Undefined lifetime. Defaulting to $lifetime seconds."; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lifetime) 0 1 1
86 1 ▶ if ( ! defined $bits ) { $bits = 512; push @Warnings, "PROXY: Undefined key size. Defaulting to $bits bits."; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 1 0 1
87 0 ▶ if ( $lifetime > 86400 ) { push @Warnings, "PROXY: Requested lifetime exceeds 24 hours."; }
Branch: 1 branch
BranchTrueFalseTotal
if ($lifetime > 86400) 0 1 1
88 0 ▶ if ( ( $lifetime ) > ( $CI{'End'} - $now ) ) { push @Warnings, "PROXY: Requested lifetime exceeds lifetime of issuer."; }
Branch: 1 branch
BranchTrueFalseTotal
if ($lifetime > $CI{"End"} - $now) 0 1 1
89 1 ▶ if ( ( $CI{'End'} - $now ) < 604800 ) { push @Warnings, "PROXY: Issuer certificate will expire in less than 1 week."; }
Branch: 1 branch
BranchTrueFalseTotal
if ($CI{"End"} - $now < 604800) 1 0 1
90 0 ▶ if ( $type =~ "Legacy" && defined $pathlen ) { push @Warnings, "PROXY: Legacy Proxy may not a proxy pathlength."; }
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /Legacy/ and defined $pathlen) 0 1 1
Condition33%1/3
$type =~ /Legacy/ and defined $pathlen
!ll&&!rl&&r
010
MC/DC0%0/2
$type =~ /Legacy/ and defined $pathlen
$type =~ /Legacy/ defined $pathlen
Truth table33%1/3
A and B
A= $type =~ /Legacy/B= defined $pathlen
ABresult
0X0
100
111
91  
92 ###################################################################
93 # Do not edit below these lines (unless there's a bug of course!) #
94 ###################################################################
95  
96 #Get times Now and Now + $lifetime (12 hours)
97 1 my @NOW=gmtime($now );
98 1 my @FUT=gmtime($now + $lifetime );
99  
100 # UTCTIME (so two digit years, OK for the next 40 or so years!)
101 1 my $beforeDate=sprintf("%02i%02i%02i%02i%02i%02iZ",($NOW[5] % 100),($NOW[4]+1),$NOW[3],$NOW[2],$NOW[1],$NOW[0]);
102 1 my $afterDate=sprintf("%02i%02i%02i%02i%02i%02iZ",($FUT[5] % 100),($FUT[4]+1),$FUT[3],$FUT[2],$FUT[1],$FUT[0]);
103  
104 1 my ( $Keyversion, $Keymodulus, $KeypublicExponent, $KeyprivateExponent, $Keyprime1, $Keyprime2, $Keyexponent1, $Keyexponent2, $Keycoefficient, $Privatekey);
105  
106 1 ▶ if ( ! defined($KeypublicE) || ! defined($KeypublicM) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $KeypublicE && defined $KeypublicM) { } 1 0 1
Condition33%1/3
defined $KeypublicE && defined $KeypublicM
!ll&&!rl&&r
100
MC/DC0%0/2
defined $KeypublicE && defined $KeypublicM
defined $KeypublicE defined $KeypublicM
Truth table33%1/3
A && B
A= defined $KeypublicEB= defined $KeypublicM
ABresult
0X0
100
111
107  
108 # Generate Key Pair
109 1 ▶ my $keyref = VOMS::Lite::RSAKey::Create( { Bits => $bits, Verbose => (defined $context{'Quiet'})?undef:"y" } );
Branch: 1 branch
BranchTrueFalseTotal
defined $context{'Quiet'} ? : 0 1 1
110 0 ▶ if ( ! defined $keyref ) { return { Errors => [ "PROXY: Key Generation Failure" ] } ; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $keyref) 0 1 1
111 1 my %key = %{ $keyref };
112 0 ▶ if ( defined $key{'Errors'} ) { return { Errors => [ "PROXY: Error in Key Generation ".$key{'Errors'} ] } ; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key{"Errors"}) 0 1 1
113  
114 ### Proxy Private Key#####################################################
115 # Keyversion Keymodulus KeypublicExponent KeyprivateExponent
116 # Keyprime1 Keyprime2 Keyexponent1 Keyexponent2 Keycoefficient
117 1 $Keyversion = "020100";
118 1 $Keymodulus = ASN1Wrap("02",DecToHex($key{Modulus}));
119 1 $KeypublicExponent = ASN1Wrap("02",DecToHex($key{PublicExponent}));
120 1 $KeyprivateExponent = ASN1Wrap("02",DecToHex($key{PrivateExponent}));
121 1 $Keyprime1 = ASN1Wrap("02",DecToHex($key{Prime1}));
122 1 $Keyprime2 = ASN1Wrap("02",DecToHex($key{Prime2}));
123 1 $Keyexponent1 = ASN1Wrap("02",DecToHex($key{Exponent1}));
124 1 $Keyexponent2 = ASN1Wrap("02",DecToHex($key{Exponent2}));
125 1 $Keycoefficient = ASN1Wrap("02",DecToHex($key{Iqmp}));
126  
127 1 $Privatekey=ASN1Wrap("30",$Keyversion.$Keymodulus.$KeypublicExponent.$KeyprivateExponent.
128 $Keyprime1.$Keyprime2.$Keyexponent1.$Keyexponent2.$Keycoefficient);
129 } else {
130 0 $Keymodulus = ASN1Wrap("02",Hex($KeypublicM));
131 0 $KeypublicExponent = ASN1Wrap("02",Hex($KeypublicE));
132 }
133  
134 ###Proxy Public Bits######################################################
135 # TBSCertificate:
136 # X509version X509serial X509signature X509issuer X509validity X509subject
137 # X509subjectPublicKeyInfo (X509issuerUniqueID) (X509subjectUniqueID) X509extensions
138  
139 #Certificate Version (x509 v3)
140 1 my $X509version = "a003020102";
141  
142 #Serial Number (different algorithm for (Pre)?RFC and Legacy Globus
143 1 my $SN=DecToHex( ((($CI{End}-$now) & hex("00ffffff"))<<8 ) + int(rand 256));
144 1 ▶ my $X509serial=($type eq "Legacy")?Hex($CI{X509serial}):ASN1Wrap("02",$SN);
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'Legacy' ? : 1 0 1
145  
146 #Use MD5 and RSA for now
147 1 my $X509signature="300d06092a864886f70d0101040500"; #SEQ(OID:md5WithRSAEncryption NULL)
148  
149 #Issuer (straight from certificate)
150 1 my $X509issuer=Hex($CI{X509subject});
151  
152 #Validity
153 1 my $X509Validity=ASN1Wrap("30",ASN1Wrap("17",Hex($beforeDate)).ASN1Wrap("17",Hex($afterDate)));
154  
155 #Subject
156 1 my $proxystr = Hex("proxy");
157 1 ▶ $proxystr = Hex("limited proxy") if ($type eq "Limited");
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "Limited" 0 1 1
158 1 ▶ $proxystr = Hex(hex($SN)) if ($type ne "Legacy" && $type ne "Limited");
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "Legacy" and $type ne "Limited" 0 1 1
Condition33%1/3
$type ne "Legacy" and $type ne "Limited"
!ll&&!rl&&r
100
MC/DC0%0/2
$type ne "Legacy" and $type ne "Limited"
$type ne "Legacy" $type ne "Limited"
Truth table33%1/3
A and B
A= $type ne "Legacy"B= $type ne "Limited"
ABresult
0X0
100
111
159 1 my $PROXYNAME=ASN1Wrap("31",ASN1Wrap("30","0603550403".ASN1Wrap("13",$proxystr))); #SET{SEQ{OID:CN CN}}
160 1 my $X509subject=ASN1Wrap("30",Hex(scalar ASN1Unwrap($CI{X509subject})).$PROXYNAME);
161  
162 #Public Key
163 1 my $PubKeyChunck=ASN1Wrap("30",$Keymodulus.$KeypublicExponent);
164 1 my $X509subjectPublicKeyInfo=ASN1Wrap("30",ASN1Wrap("30","06092a864886f70d0101010500").ASN1Wrap("03",ASN1BitStr($PubKeyChunck)));
165  
166 #Extensions
167 #KeyUsage
168 1 my $keyusage=ASN1Wrap("30","0603551d0f"."0101ff"."0404030203a8");#Critical:Dig sign & Key encypher & Key Agree
169 ######Proxyinfo not quite right yet
170 #ProxyInfo Extensions SEQ{OID(GlobusProxy|id-ppl-inheritALL) . Criticality . PolicyLangOID+Policy}
171 1 ▶ my $PolicyVal=( defined $pathlen )?ASN1Wrap("a1",ASN1Wrap("02",DecToHex($pathlen))):"";
Branch: 1 branch
BranchTrueFalseTotal
defined $pathlen ? : 0 1 1
172 1 my $Policy;
173 1 ▶ $Policy=ASN1Wrap("04",ASN1Wrap("30","300a06082b06010505071501".$PolicyVal)) if ($type eq "Pre-RFC");
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "Pre-RFC" 0 1 1
174 1 ▶ $Policy=ASN1Wrap("04",ASN1Wrap("30",$PolicyVal."300a06082b06010505071501")) if ($type eq "RFC");
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "RFC" 0 1 1
175 1 my $ProxyInfo="";
176 1 ▶ $ProxyInfo=ASN1Wrap("30","060a2b060104019b5001815e"."0101ff".$Policy) if ($type eq "Pre-RFC");
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "Pre-RFC" 0 1 1
177 1 ▶ $ProxyInfo=ASN1Wrap("30","06082b0601050507010e". "0101ff".$Policy) if ($type eq "RFC");
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "RFC" 0 1 1
178 #VOMS
179 1 my $VOMS="";
180 # $VOMS=ASN1Wrap("30","060a2b06010401be45646405"."".ASN1Wrap("04",Hex($AC))) if ( defined $AC );
181 1 ▶ $VOMS=ASN1Wrap("30","060a2b06010401be45646405"."".ASN1Wrap("04",ASN1Wrap("30",ASN1Wrap("30",Hex($AC))))) if ( defined $AC );
Branch: 1 branch
BranchTrueFalseTotal
if defined $AC 0 1 1
182  
183 1 my $X509extensions=ASN1Wrap("a3",ASN1Wrap("30",$keyusage.$ProxyInfo.$VOMS.Hex(join('',@Ext))));
184  
185 #The whole chunck of certificate to be signed
186 1 my $TBSCertificate=ASN1Wrap("30",$X509version.$X509serial.$X509signature.$X509issuer.$X509Validity.
187 $X509subject.$X509subjectPublicKeyInfo.$X509extensions);
188  
189 ###Signature Bits#####################################################
190 # X509signatureAlgorithm X509signature
191  
192 # Make MD5 Checksum and RSA sign it
193 1 my $BinaryTBSCertificate = $TBSCertificate;
194 1 $BinaryTBSCertificate =~ s/(..)/pack('C',hex($&))/ge;
195 1 my $RSAsignedDigest = digestSign("md5WithRSA",$BinaryTBSCertificate,Hex($KI{KeyprivateExponent}),Hex($KI{Keymodulus}));
196 1 my $Signature = ASN1Wrap("03",ASN1BitStr($RSAsignedDigest)); #(Always n*8 bits for MDnRSA and SHA1RSA)
197  
198  
199 ###Wrap it all up Public Bits and Signature############################
200 # TBSCertificate X509signatureAlgorithm X509signature
201  
202 1 my $Certificate = ASN1Wrap("30",$TBSCertificate.$X509signature.$Signature);
203  
204 ###Write out the proxy to the proxy file###############################
205 # ProxyCert ProxyKey SigningCerts ##### Would like to put full chain in here!
206  
207 1 $Certificate=~s/(..)/pack('C',hex($&))/ge;
208 1 ▶ if ( ! defined($KeypublicE) || ! defined($KeypublicM) ) { $Privatekey=~s/(..)/pack('C',hex($&))/ge; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $KeypublicE and defined $KeypublicM) 1 0 1
Condition33%1/3
defined $KeypublicE and defined $KeypublicM
!ll&&!rl&&r
100
MC/DC0%0/2
defined $KeypublicE and defined $KeypublicM
defined $KeypublicE defined $KeypublicM
Truth table33%1/3
A and B
A= defined $KeypublicEB= defined $KeypublicM
ABresult
0X0
100
111
209  
210 1 return { ProxyCert=>$Certificate, ProxyKey=>$Privatekey, Warnings=>\@Warnings };
211 }
212  
213 1 1;
214  
215 __END__
« lib/VOMS/Lite/Attribs/DBHelper.pm ↑ Summary lib/VOMS/Lite/SAMLHelper.pm »