| 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
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ( ! defined $context{'Key'} ) { push @Errors, "PROXY: Issuer key not supplied"; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Bail if there isn't enough information | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ( @Errors > 0 ) { return { Errors => \@Errors} ; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | my $KeyInfoRef = (($context{'Key'} =~ /^(\060.+)$/s) ? VOMS::Lite::KEY::Examine($&, {Keymodulus=>"", KeyprivateExponent=>""}) : undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my %CI; if ( defined $CertInfoRef ) { %CI=%$CertInfoRef; } else { push @Errors, "PROXY: Unable to parse certificate."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my %KI; if ( defined $KeyInfoRef ) { %KI=%$KeyInfoRef; } else { push @Errors, "PROXY: Unable to parse key."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Bail if there is a certificate Parse error | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ( @Errors > 0 ) { return { Errors => \@Errors} ; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $context{"Type"} and $context{"Type"} =~ /^(Lega[cs]y|Limited|Pre-RFC|RFC)$/
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)$/
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ( $type eq "Legasy" ) { $type = "Legacy"; $context{'Type'}="Legacy"; } # oops was going through a bad spell! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 1 | ▶ | my $pathlen = ((( defined $context{'PathLength'} && $context{'PathLength'} =~ /^([0-9]+)$/s) ) ? $& : undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"PathLength"} and $context{"PathLength"} =~ /^([0-9]+)$/s
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
| |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | my $bits = ((( defined $context{'Bits'} && $context{'Bits'} =~ /^(512|1024|2048|4096)$/s) ) ? $& : undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"Bits"} and $context{"Bits"} =~ /^(512|1024|2048|4096)$/s
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
| |||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my $lifetime = ((( defined $context{'Lifetime'} && $context{'Lifetime'} =~ /^([0-9]+)$/s) ) ? $& : undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"Lifetime"} and $context{"Lifetime"} =~ /^([0-9]+)$/s
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
| |||||||||||||||||||||||||||||
| 56 | 1 | ▶ | my $start = ((( defined $context{'Start'} && $context{'Start'} =~ /^([0-9]+)$/s) ) ? $& : undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"Start"} and $context{"Start"} =~ /^([0-9]+)$/s
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
| |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | my $AC = ((( defined $context{'AC'} && $context{'AC'} =~ /^(\060.+)$/s) ) ? $& : undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"AC"} and $context{"AC"} =~ /^(\060.+)$/s
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
| |||||||||||||||||||||||||||||
| 58 | 1 | my @Ext; | |||||||||||||||||||||||||||
| 59 | 1 | ▶ | if ( defined $context{'Ext'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( ref ($context{'Ext'}) eq "ARRAY" ) { @Ext = @{ $context{'Ext'} }; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | my $KeypublicE = ((( defined $context{'KeypublicExponent'} && $context{'KeypublicExponent'} =~ /^([\x00-\x7f].+)$/s) ) ? $& : undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"KeypublicExponent"} and $context{"KeypublicExponent"} =~ /^([\x00-\x7f].+)$/s
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
| |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | my $KeypublicM = ((( defined $context{'KeypublicModulus'} && $context{'KeypublicModulus'} =~ /^([\x00-\x7f].+)$/s) ) ? $& : undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"KeypublicModulus"} and $context{"KeypublicModulus"} =~ /^([\x00-\x7f].+)$/s
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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $context{"Type"} and not defined $type
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
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ( defined $context{'PathLength'} && ! defined $pathlen ) { push @Errors, "PROXY: Invalid Pathlength $context{'PathLength'}. Must be a positive integer."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"PathLength"} and not defined $pathlen
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
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ( defined $context{'Bits'} && ! defined $bits ) { push @Errors, "PROXY: Key size may only be 512, 1024, 2048 or 4096."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"Bits"} and not defined $bits
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
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( defined $context{'Lifetime'} && ! defined $lifetime ) { push @Errors, "PROXY: Invalid Lifetime $context{'Lifetime'}. Must be a positive integer."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"Lifetime"} and not defined $lifetime
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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $context{"Start"} and not defined $start
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
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ( defined $context{'AC'} && ! defined $AC ) { push @Errors, "PROXY: AC Must be in DER format."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $context{"AC"} and not defined $AC
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( defined $start ) { $now = $start;} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # Bail if any recognised options are invalid | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( @Errors > 0 ) { return { Errors => \@Errors} ; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( ! defined $lifetime ) { $lifetime = 43200; push @Warnings, "PROXY: Undefined lifetime. Defaulting to $lifetime seconds."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 1 | ▶ | if ( ! defined $bits ) { $bits = 512; push @Warnings, "PROXY: Undefined key size. Defaulting to $bits bits."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( $lifetime > 86400 ) { push @Warnings, "PROXY: Requested lifetime exceeds 24 hours."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ( ( $lifetime ) > ( $CI{'End'} - $now ) ) { push @Warnings, "PROXY: Requested lifetime exceeds lifetime of issuer."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | if ( ( $CI{'End'} - $now ) < 604800 ) { push @Warnings, "PROXY: Issuer certificate will expire in less than 1 week."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( $type =~ "Legacy" && defined $pathlen ) { push @Warnings, "PROXY: Legacy Proxy may not a proxy pathlength."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type =~ /Legacy/ and defined $pathlen
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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $KeypublicE && defined $KeypublicM
MC/DC0%0/2
defined $KeypublicE && defined $KeypublicM
defined $KeypublicE
defined $KeypublicM
Truth table33%1/3
A && B
A= defined $KeypublicEB= defined $KeypublicM
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # Generate Key Pair | ||||||||||||||||||||||||||||
| 109 | 1 | ▶ | my $keyref = VOMS::Lite::RSAKey::Create( { Bits => $bits, Verbose => (defined $context{'Quiet'})?undef:"y" } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ( ! defined $keyref ) { return { Errors => [ "PROXY: Key Generation Failure" ] } ; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 1 | my %key = %{ $keyref }; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( defined $key{'Errors'} ) { return { Errors => [ "PROXY: Error in Key Generation ".$key{'Errors'} ] } ; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 158 | 1 | ▶ | $proxystr = Hex(hex($SN)) if ($type ne "Legacy" && $type ne "Limited"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type ne "Legacy" and $type ne "Limited"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 172 | 1 | my $Policy; | |||||||||||||||||||||||||||
| 173 | 1 | ▶ | $Policy=ASN1Wrap("04",ASN1Wrap("30","300a06082b06010505071501".$PolicyVal)) if ($type eq "Pre-RFC"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 1 | ▶ | $Policy=ASN1Wrap("04",ASN1Wrap("30",$PolicyVal."300a06082b06010505071501")) if ($type eq "RFC"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 1 | my $ProxyInfo=""; | |||||||||||||||||||||||||||
| 176 | 1 | ▶ | $ProxyInfo=ASN1Wrap("30","060a2b060104019b5001815e"."0101ff".$Policy) if ($type eq "Pre-RFC"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 1 | ▶ | $ProxyInfo=ASN1Wrap("30","06082b0601050507010e". "0101ff".$Policy) if ($type eq "RFC"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $KeypublicE and defined $KeypublicM
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
| |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 1 | return { ProxyCert=>$Certificate, ProxyKey=>$Privatekey, Warnings=>\@Warnings }; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 1 | 1; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | __END__ | ||||||||||||||||||||||||||||