| 1 | 32 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 32 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | package XML::Sig; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 32 | our $VERSION = '0.74'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 32 | ▶ | use Encode qw(encode_utf8); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 32 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | # ABSTRACT: XML::Sig - A toolkit to help sign and verify XML Digital Signatures | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | # use 'our' on v5.6.0 | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 32 | ▶ | use vars qw($VERSION @EXPORT_OK %EXPORT_TAGS $DEBUG); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 32 | $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 32 | ▶ | use base qw(Class::Accessor); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 32 | XML::Sig->mk_accessors(qw(key)); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # Nothing is imported: the functions are looked up below, so that a hash the | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # installed version does not provide is unsupported rather than fatal. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 32 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 32 | ▶ | use Crypt::Digest::RIPEMD160 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 32 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 32 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 32 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # The only hash algorithms XML::Sig will use. Algorithm names read from a | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # document being verified are untrusted and must only ever be looked up | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # here - never resolved to a function by name (e.g. with ->can()). | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # The names below are constants, so ->can() is safe here: it is only used | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # to leave out a hash that the installed module version does not provide. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 96 | ▶ | sub _available_functions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_available_functions: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 96 | my ($class, $prefix, @names) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 96 | my %function; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 96 | foreach my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 39 | 352 | my $ref = $class->can($prefix . $name); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 352 | ▶ | $function{$name} = $ref if $ref && defined &$ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ref and defined &$ref
MC/DC50%1/2
$ref and defined &$ref
$ref
defined &$ref
Truth table66%2/3
A and B
A= $refB= defined &$ref
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 96 | return %function; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 32 | my %HASH_FUNCTION = ( | |||||||||||||||||||||||||||||||||||||||||
| 46 | _available_functions('Digest::SHA', '', qw(sha1 sha224 sha256 sha384 sha512)), | ||||||||||||||||||||||||||||||||||||||||||
| 47 | _available_functions('Crypt::Digest::RIPEMD160', '', qw(ripemd160)), | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 32 | my %HMAC_FUNCTION = ( | |||||||||||||||||||||||||||||||||||||||||
| 51 | _available_functions('Digest::SHA', 'hmac_', qw(sha1 sha224 sha256 sha384 sha512)), | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ## _hash_function($name) | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ## $name: string hash algorithm name (sha1, sha256, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ## Returns: code reference for the hash function | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 62 | ## Dies unless $name is one of the supported hash algorithms | ||||||||||||||||||||||||||||||||||||||||||
| 63 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 759 | ▶ | sub _hash_function { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hash_function: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 759 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 759 | ▶ | if (defined $name && exists $HASH_FUNCTION{$name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $name and exists $HASH_FUNCTION{$name}
MC/DC50%1/2
defined $name and exists $HASH_FUNCTION{$name}
defined $name
exists $HASH_FUNCTION{$name}
Truth table66%2/3
A and B
A= defined $nameB= exists $HASH_FUNCTION{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 744 | return $HASH_FUNCTION{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 15 | die("XML::Sig - unsupported hash algorithm\n"); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 32 | ▶ | use constant TRANSFORM_ENV_SIG => 'http://www.w3.org/2000/09/xmldsig#enveloped-signature'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 32 | ▶ | use constant TRANSFORM_C14N => 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 32 | ▶ | use constant TRANSFORM_C14N_COMMENTS => 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 32 | ▶ | use constant TRANSFORM_C14N_V1_1 => 'http://www.w3.org/TR/2008/REC-xml-c14n11-20080502'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 32 | ▶ | use constant TRANSFORM_C14N_V1_1_COMMENTS => 'http://www.w3.org/TR/2008/REC-xml-c14n11-20080502#WithComments'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 32 | ▶ | use constant TRANSFORM_EXC_C14N => 'http://www.w3.org/2001/10/xml-exc-c14n#'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 32 | ▶ | use constant TRANSFORM_EXC_C14N_COMMENTS => 'http://www.w3.org/2001/10/xml-exc-c14n#WithComments'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # Character class for NCNameStartChar (XML 1.0 Fifth Edition): | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # A-Z_a-z ASCII letters and underscore | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # \xC0-\xD6 Latin-1 supplement: À to Ö | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # \xD8-\xF6 Latin-1 supplement: Ø to ö | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # \xF8-\x{2FF} Latin Extended A/B, IPA, spacing modifiers | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # \x{370}-\x{37D} Greek and Coptic | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # \x{37F}-\x{1FFF} Greek through Greek Extended | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # \x{2070}-\x{218F} Superscripts, currency, letterlike symbols | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # \x{2C00}-\x{2FEF} Glagolitic, Coptic, Georgian, Tifinagh | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # \x{3001}-\x{D7FF} CJK punctuation through Hangul syllables | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # \x{F900}-\x{FDCF} CJK compatibility, Arabic presentation A | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # \x{FDF0}-\x{FFFD} Arabic presentation B, halfwidth/fullwidth | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 32 | my $NCNameStartChar = qr{ | |||||||||||||||||||||||||||||||||||||||||
| 97 | [A-Z_a-z | ||||||||||||||||||||||||||||||||||||||||||
| 98 | \xC0-\xD6 | ||||||||||||||||||||||||||||||||||||||||||
| 99 | \xD8-\xF6 | ||||||||||||||||||||||||||||||||||||||||||
| 100 | \xF8-\x{2FF} | ||||||||||||||||||||||||||||||||||||||||||
| 101 | \x{370}-\x{37D} | ||||||||||||||||||||||||||||||||||||||||||
| 102 | \x{37F}-\x{1FFF} | ||||||||||||||||||||||||||||||||||||||||||
| 103 | \x{2070}-\x{218F} | ||||||||||||||||||||||||||||||||||||||||||
| 104 | \x{2C00}-\x{2FEF} | ||||||||||||||||||||||||||||||||||||||||||
| 105 | \x{3001}-\x{D7FF} | ||||||||||||||||||||||||||||||||||||||||||
| 106 | \x{F900}-\x{FDCF} | ||||||||||||||||||||||||||||||||||||||||||
| 107 | \x{FDF0}-\x{FFFD}] | ||||||||||||||||||||||||||||||||||||||||||
| 108 | }x; | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # Extras (NameChar-only): | ||||||||||||||||||||||||||||||||||||||||||
| 111 | # - hyphen | ||||||||||||||||||||||||||||||||||||||||||
| 112 | # . period | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # 0-9 ASCII digits | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # \xB7 middle dot (·) | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # \x{0300}-\x{036F} combining diacritical marks | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # \x{203F}-\x{2040} undertie (‿) and character tie (⁀) | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 32 | my $NCNameChar = qr{ | |||||||||||||||||||||||||||||||||||||||||
| 119 | (?: $NCNameStartChar | ||||||||||||||||||||||||||||||||||||||||||
| 120 | | [-.0-9\xB7 | ||||||||||||||||||||||||||||||||||||||||||
| 121 | \x{0300}-\x{036F} | ||||||||||||||||||||||||||||||||||||||||||
| 122 | \x{203F}-\x{2040}] | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 124 | }x; | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 32 | my $NCName = qr{\A ${NCNameStartChar} ${NCNameChar}* \z}x; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 32 | $| = 1; # autoflush | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 432 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=21 SCAR=30.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 432 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 432 | my $params = shift; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 432 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 432 | foreach my $prop ( qw/ key cert cert_text ns id_attr/ ) { | |||||||||||||||||||||||||||||||||||||||||
| 140 | 2160 | ▶ | if ( exists $params->{ $prop } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 302 | $self->{ $prop } = $params->{ $prop }; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | # else { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | # confess "You need to provide the $prop parameter!"; | ||||||||||||||||||||||||||||||||||||||||||
| 145 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 432 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 432 | ▶ | $self->{ 'x509' } = exists $params->{ x509 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 432 | ▶ | if ( exists $params->{ key_name } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 20 | $self->{ key_name } = $params->{ key_name }; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 432 | ▶ | if ( exists $params->{ 'key' } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 203 | $self->_load_key( $params->{ 'key' } ); | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 430 | ▶ | if ( exists $params->{ 'cert' } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 90 | $self->_load_cert_file( $params->{ 'cert' } ); | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 430 | ▶ | if ( exists $params->{ 'cert_text' } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 4 | $self->_load_cert_text( $params->{ 'cert_text' } ); | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 430 | ▶ | if ( exists $params->{ 'hmac_key' } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 20 | $self->_load_hmac_key_info; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 430 | ▶ | if ( exists $params->{ sig_hash } && grep { $_ eq $params->{ sig_hash } } ('sha224', 'sha256', 'sha384', 'sha512', 'ripemd160')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $params->{"sig_hash"} and grep {$_ eq $params->{"sig_hash"};} "sha224", "sha256", "sha384", "sha512", "ripemd160"
MC/DC100%2/2
exists $params->{"sig_hash"} and grep {$_ eq $params->{"sig_hash"};} "sha224", "sha256", "sha384", "sha512", "ripemd160"
exists $params->{"sig_hash"}
grep {$_ eq $params->{"sig_hash"};} "sha224", "sha256", "sha384", "sha512", "ripemd160"
Truth table100%3/3
A and B
A= exists $params->{"sig_hash"}B= grep {$_ eq $params->{"sig_hash"};} "sha224", "sha256", "sha384", "sha512", "ripemd160"
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 96 | $self->{ sig_hash } = $params->{ sig_hash }; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 334 | $self->{ sig_hash } = 'sha256'; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 430 | ▶ | if ( exists $params->{ digest_hash } && grep { $_ eq $params->{ digest_hash } } ('sha1', 'sha224', 'sha256', 'sha384','sha512', 'ripemd160')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $params->{"digest_hash"} and grep {$_ eq $params->{"digest_hash"};} "sha1", "sha224", "sha256", "sha384", "sha512", "ripemd160"
MC/DC50%1/2
exists $params->{"digest_hash"} and grep {$_ eq $params->{"digest_hash"};} "sha1", "sha224", "sha256", "sha384", "sha512", "ripemd160"
exists $params->{"digest_hash"}
grep {$_ eq $params->{"digest_hash"};} "sha1", "sha224", "sha256", "sha384", "sha512", "ripemd160"
Truth table66%2/3
A and B
A= exists $params->{"digest_hash"}B= grep {$_ eq $params->{"digest_hash"};} "sha1", "sha224", "sha256", "sha384", "sha512", "ripemd160"
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 110 | $self->{ digest_hash } = $params->{ digest_hash }; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 320 | $self->{ digest_hash } = 'sha256'; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 430 | ▶ | if (defined $self->{ key_type } && XML::Sig::check_dsa_version() && $self->{ key_type } eq 'dsa') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $self->{"key_type"} and check_dsa_version() and $self->{"key_type"} eq "dsa"
defined $self->{"key_type"} and check_dsa_version()
MC/DC66%2/3
defined $self->{"key_type"} and check_dsa_version() and $self->{"key_type"} eq "dsa"
defined $self->{"key_type"}
check_dsa_version()
$self->{"key_type"} eq "dsa"
Truth table75%3/4
A and B and C
A= defined $self->{"key_type"}B= check_dsa_version()C= $self->{"key_type"} eq "dsa"
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 42 | my $sig_size = $self->{ key_obj }->get_sig_size(); | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # The key size dictates the sig size | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 42 | ▶ | if ( $sig_size eq 48 ) { # 1024-bit key | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 22 | $self->{ sig_hash } = 'sha1'; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } else { # 2048-bit or 3072-bit key | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 20 | $self->{ sig_hash } = 'sha256'; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 430 | ▶ | if ( exists $params->{ no_xml_declaration } && $params->{ no_xml_declaration } == 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $params->{"no_xml_declaration"} and $params->{"no_xml_declaration"} == 1
MC/DC100%2/2
exists $params->{"no_xml_declaration"} and $params->{"no_xml_declaration"} == 1
exists $params->{"no_xml_declaration"}
$params->{"no_xml_declaration"} == 1
Truth table100%3/3
A and B
A= exists $params->{"no_xml_declaration"}B= $params->{"no_xml_declaration"} == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 3 | $self->{ no_xml_declaration } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 427 | $self->{ no_xml_declaration } = 0; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 430 | ▶ | if ( !defined $self->{ key_type } && exists $params->{ hmac_key } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $self->{"key_type"} and exists $params->{"hmac_key"}
MC/DC100%2/2
not defined $self->{"key_type"} and exists $params->{"hmac_key"}
not defined $self->{"key_type"}
exists $params->{"hmac_key"}
Truth table100%3/3
not(A) and B
A= not defined $self->{"key_type"}B= exists $params->{"hmac_key"}
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 20 | $self->{ hmac_key } = $params->{ hmac_key }; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 20 | $self->{ key_type } = 'hmac'; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 430 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 257 | ▶ | sub sign { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sign: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 257 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 257 | my ($xml) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 257 | ▶ | die "You cannot sign XML without a private key." unless $self->key || $self->{ hmac_key }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->key or $self->{"hmac_key"}
MC/DC100%2/2
$self->key or $self->{"hmac_key"}
$self->key
$self->{"hmac_key"}
Truth table100%3/3
A or B
A= $self->keyB= $self->{"hmac_key"}
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 256 | local $XML::LibXML::skipXMLDeclaration = $self->{ no_xml_declaration }; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 256 | my $dom = $self->_load_xml($xml); | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 251 | $self->{ parser } = XML::LibXML::XPathContext->new($dom); | |||||||||||||||||||||||||||||||||||||||||
| 218 | 251 | my $parser = $self->{ parser }; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 251 | $parser->registerNs('dsig', 'http://www.w3.org/2000/09/xmldsig#'); | |||||||||||||||||||||||||||||||||||||||||
| 220 | 251 | $parser->registerNs('ec', 'http://www.w3.org/2001/10/xml-exc-c14n#'); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 251 | $parser->registerNs('saml', 'urn:oasis:names:tc:SAML:2.0:assertion'); | |||||||||||||||||||||||||||||||||||||||||
| 222 | 251 | ▶ | if ($self->{ns}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | foreach (keys %{$self->{ns}}) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | $parser->registerNs($_, $self->{ns}{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 251 | ▶ | print ("Signing XML\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 251 | my @ids_to_sign = $self->_get_ids_to_sign(); | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 215 | foreach my $signid (@ids_to_sign) { | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 224 | ▶ | print ("Signing ID $signid\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | # Temporarily create the Signature XML from the part | ||||||||||||||||||||||||||||||||||||||||||
| 237 | # TODO: ths section needs a rewrite to create the xml in | ||||||||||||||||||||||||||||||||||||||||||
| 238 | # a better way. | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | # Create a Reference xml fragment including digest section | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 224 | my $digest_xml = $self->_reference_xml( $signid, "REPLACE DIGEST " . $signid ); | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | # Create a SignedInfo xml fragment including digest section | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 224 | my $signed_info = $self->_signedinfo_xml( $digest_xml ); | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | # Create a Signature xml fragment including SignedInfo section | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 224 | my $signature_xml = $self->_signature_xml( $signed_info, 'REPLACE SIGNATURE ' . $signid ); | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 224 | ▶ | print ("Sign ID: $signid\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | # Get the XML note to sign base on the ID | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 224 | my $xml = $self->_get_xml_to_sign($signid); | |||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | # Canonicalize the XML to http://www.w3.org/2001/10/xml-exc-c14n# | ||||||||||||||||||||||||||||||||||||||||||
| 255 | # TODO Change the Canonicalization method in the xml fragment from _signedinfo_xml | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # <dsig:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /> | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 224 | my $xml_canon = $xml->toStringEC14N(); | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 224 | $self->{digest_method} = _hash_function($self->{ digest_hash }); | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | # Calculate the digest of the XML being signed | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 223 | my $bin_digest = $self->{digest_method}->( Encode::encode_utf8( $xml_canon )); | |||||||||||||||||||||||||||||||||||||||||
| 264 | 223 | my $digest = encode_base64( $bin_digest, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 223 | ▶ | print (" Digest: $digest\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | # Display the ID of the XML being signed for debugging | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 223 | my $reference = $signid; #$self->{parser}->findvalue('//@ID', $xml); | |||||||||||||||||||||||||||||||||||||||||
| 269 | 223 | ▶ | print (" Reference URI: $reference\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 223 | local $XML::LibXML::skipXMLDeclaration = $self->{ no_xml_declaration }; | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 223 | my $signature_dom = $self->_load_xml($signature_xml); | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 223 | my $xpath = XML::LibXML::XPathContext->new($signature_dom); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 223 | $xpath->registerNs('dsig', 'http://www.w3.org/2000/09/xmldsig#'); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 223 | $xpath->registerNs('ec', 'http://www.w3.org/2001/10/xml-exc-c14n#'); | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | # Canonicalize the SignedInfo to http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments | ||||||||||||||||||||||||||||||||||||||||||
| 280 | # TODO Change the Canonicalization method in the xml fragment from _signedinfo_xml | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 223 | my ($signature_node) = $xpath->findnodes( | |||||||||||||||||||||||||||||||||||||||||
| 283 | '/dsig:Signature', $signature_xml); | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 223 | my ($signed_info_node) = $xpath->findnodes( | |||||||||||||||||||||||||||||||||||||||||
| 285 | '/dsig:Signature/dsig:SignedInfo',$signature_xml); | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | # Add the digest value to the Signed info | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 223 | my ($digest_value_node) = $xpath->findnodes( | |||||||||||||||||||||||||||||||||||||||||
| 289 | '/dsig:Signature/dsig:SignedInfo/dsig:Reference/dsig:DigestValue', $signature_xml); | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 223 | $digest_value_node->removeChildNodes(); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 223 | $digest_value_node->appendText($digest); | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | # At this point the SignedInfo includes the information | ||||||||||||||||||||||||||||||||||||||||||
| 294 | # to allow us to use the _canonicalize_xml with the $signature_node | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 223 | my $signed_info_canon = $self->_canonicalize_xml($signed_info_node, $signature_node); | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | # Calculate the signature of the Canonical Form of SignedInfo | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 223 | my $signature; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 223 | ▶ | if ($self->{key_type} eq 'dsa') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 43 | $signature = encode_base64( $self->_calc_dsa_signature( $signed_info_canon ), "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 301 | } elsif ($self->{key_type} eq 'ecdsa') { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 97 | $signature = encode_base64( $self->_calc_ecdsa_signature( $signed_info_canon ), "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 303 | } elsif ($self->{key_type} eq 'rsa') { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 73 | $signature = encode_base64( $self->_calc_rsa_signature( $signed_info_canon ), "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 305 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 10 | ▶ | if ( defined $self->{ hmac_key } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 10 | $signature = encode_base64( $self->_calc_hmac_signature( $signed_info_canon ), "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | die "No Signature signing method provided"; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | # Add the Signature to the SignatureValue | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 222 | my ($signature_value_node) = $xpath->findnodes( | |||||||||||||||||||||||||||||||||||||||||
| 315 | '/dsig:Signature/dsig:SignatureValue', $signature_xml); | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 222 | $signature_value_node->removeChildNodes(); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 222 | $signature_value_node->appendText($signature); | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 222 | my $set = $xpath->findnodes('dsig:Signature'); | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 222 | my $node = $set->get_node(1)->cloneNode( 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 222 | my $root = $dom->findnodes("//*[\@ID=\'$signid\']"); | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 222 | my $loc = $root->shift(); | |||||||||||||||||||||||||||||||||||||||||
| 326 | 222 | $loc->addChild($node); | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 222 | ▶ | print ("\n\n\n SignatureValue:\n" . $signature_value_node . "\n\n\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 213 | return $dom->toString; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 240 | ▶ | sub verify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=47 SCAR=42.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 240 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 240 | delete $self->{signer_cert}; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 240 | delete $self->{verified_ids}; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 240 | delete $self->{verified_elements}; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 240 | my $xml = shift; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 240 | my $dom = $self->_load_xml($xml); | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 239 | $self->{ parser } = XML::LibXML::XPathContext->new($dom); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 239 | my $parser = $self->{ parser }; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 239 | $parser->registerNs('dsig', 'http://www.w3.org/2000/09/xmldsig#'); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 239 | $parser->registerNs('ec', 'http://www.w3.org/2001/10/xml-exc-c14n#'); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 239 | $parser->registerNs('saml', 'urn:oasis:names:tc:SAML:2.0:assertion'); | |||||||||||||||||||||||||||||||||||||||||
| 349 | 239 | $parser->registerNs('ecdsa', 'http://www.w3.org/2001/04/xmldsig-more#'); | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 239 | my $signature_nodeset = $parser->findnodes('//dsig:Signature'); | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 239 | my $key_to_verify; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 239 | ▶ | if ($self->{id_attr}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | ▶ | if ($self->{ns}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | foreach (keys %{$self->{ns}}) { | |||||||||||||||||||||||||||||||||||||||||
| 357 | 2 | $parser->registerNs($_, $self->{ns}{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | $key_to_verify = $self->_get_ids_to_sign(); | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 239 | my $numsigs = $signature_nodeset->size(); | |||||||||||||||||||||||||||||||||||||||||
| 364 | 239 | ▶ | print ("NodeSet Size: $numsigs\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 239 | ▶ | die 'XML::Sig - XML does not include any signatures' if $numsigs <= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | # References actually verified. $numsigs counts Signature elements | ||||||||||||||||||||||||||||||||||||||||||
| 369 | # present, not signatures verified - the loop below skips some before | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # any cryptographic check runs. | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 238 | my @verified; | |||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | # Loop through each Signature in the document checking each | ||||||||||||||||||||||||||||||||||||||||||
| 374 | my $i; | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 238 | ▶ | while (my $signature_node = $signature_nodeset->shift()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 255 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 255 | ▶ | print ("\nSignature $i\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # Get SignedInfo Reference ID | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 255 | my $reference = $parser->findvalue( | |||||||||||||||||||||||||||||||||||||||||
| 381 | 'dsig:SignedInfo/dsig:Reference/@URI', $signature_node); | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 255 | $reference =~ s/#//g; | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 255 | ▶ | if ($reference !~ $NCName) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | croak ("SignedInfo Reference URI is invalid"); | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 255 | ▶ | print(" Reference URI: $reference\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 255 | ▶ | if ($key_to_verify && $key_to_verify ne $reference) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key_to_verify and $key_to_verify ne $reference
MC/DC0%0/2
$key_to_verify and $key_to_verify ne $reference
$key_to_verify
$key_to_verify ne $reference
Truth table66%2/3
A and B
A= $key_to_verifyB= $key_to_verify ne $reference
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | print ("Skipping reference URI: $reference, does not match required option\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | # The reference ID must point to exactly ONE element in the document. | ||||||||||||||||||||||||||||||||||||||||||
| 397 | # If zero, the signature signs nothing. If more than one, the | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # document is ambiguous and vulnerable to XML Signature Wrapping | ||||||||||||||||||||||||||||||||||||||||||
| 399 | # (XSW) attacks - the signature could validate against one element | ||||||||||||||||||||||||||||||||||||||||||
| 400 | # while a caller extracts a different element with the same ID. | ||||||||||||||||||||||||||||||||||||||||||
| 401 | # See USENIX Security 2012 "On Breaking SAML" (Somorovsky et al) | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # and CVE-2025-29774 (xml-crypto). | ||||||||||||||||||||||||||||||||||||||||||
| 403 | my $ref_nodes = $self->{ parser }->findnodes( | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 255 | '//*[@ID=\''. $reference . '\']'); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 255 | my $ref_count = $ref_nodes->size(); | |||||||||||||||||||||||||||||||||||||||||
| 406 | 255 | ▶ | if ($ref_count == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 5 | ▶ | print " Signature reference $reference is not signing anything in this xml\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 5 | ▶ | if ($numsigs <= 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 250 | ▶ | if ($ref_count > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | print " Signature reference $reference matches $ref_count elements - rejecting (XSW mitigation)\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | # Get SignedInfo DigestMethod Algorithim | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 249 | my $digest_method = $parser->findvalue( | |||||||||||||||||||||||||||||||||||||||||
| 425 | 'dsig:SignedInfo/dsig:Reference/dsig:DigestMethod/@Algorithm', $signature_node); | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 249 | $digest_method =~ s/^.*[#]//; | |||||||||||||||||||||||||||||||||||||||||
| 427 | # The name comes from the document: allow-list it before use | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 249 | $self->{digest_method} = _hash_function($digest_method); | |||||||||||||||||||||||||||||||||||||||||
| 429 | 243 | ▶ | print (" Digest Method: $digest_method\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | # Get the DigestValue used to verify Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 432 | # Note that the digest may have embedded newlines in the XML | ||||||||||||||||||||||||||||||||||||||||||
| 433 | # Decode the base64 and encode it with no newlines | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 243 | my $refdigest = encode_base64(decode_base64(_trim($parser->findvalue( | |||||||||||||||||||||||||||||||||||||||||
| 435 | 'dsig:SignedInfo/dsig:Reference/dsig:DigestValue', $signature_node))), ""); | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 243 | ▶ | print (" Digest Value: $refdigest\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | # Get the SignatureValue used to verify the SignedInfo | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 243 | my $signature = _trim($parser->findvalue('dsig:SignatureValue', $signature_node)); | |||||||||||||||||||||||||||||||||||||||||
| 440 | 243 | ▶ | print (" Signature: $signature\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | # Get SignatureMethod Algorithim | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 243 | my $signature_method = $parser->findvalue( | |||||||||||||||||||||||||||||||||||||||||
| 444 | 'dsig:SignedInfo/dsig:SignatureMethod/@Algorithm', $signature_node); | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 243 | $signature_method =~ s/^.*[#]//; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 243 | $signature_method =~ s/^rsa-//; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 243 | $signature_method =~ s/^dsa-//; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 243 | $signature_method =~ s/^ecdsa-//; | |||||||||||||||||||||||||||||||||||||||||
| 449 | 243 | $signature_method =~ s/^hmac-//; | |||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | # The name comes from the document: allow-list it before use | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 243 | $self->{sig_method} = _hash_function($signature_method); | |||||||||||||||||||||||||||||||||||||||||
| 453 | 235 | $self->{ sig_hash } = $signature_method; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 235 | ▶ | print (" SignatureMethod: $signature_method\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | # Get the SignedInfo and obtain its Canonical form | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 235 | my ($signed_info) = $parser->findnodes('dsig:SignedInfo', $signature_node); | |||||||||||||||||||||||||||||||||||||||||
| 458 | 235 | my $signed_info_canon = $self->_canonicalize_xml($signed_info, $signature_node); | |||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 235 | ▶ | print "$signed_info_canon\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | # If a cert was provided to XML::Sig->new() use it to | ||||||||||||||||||||||||||||||||||||||||||
| 463 | # verify the SignedInfo signature | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 235 | ▶ | if (defined $self->{cert_obj}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | # use the provided cert to verify | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 26 | ▶ | unless ($self->_verify_x509_cert($self->{cert_obj},$signed_info_canon,$signature)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | print ("not verified by x509\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | ▶ | elsif (!defined $self->{cert_obj} && defined $self->{ hmac_key }) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not defined $self->{"cert_obj"} and defined $self->{"hmac_key"}
MC/DC50%1/2
not defined $self->{"cert_obj"} and defined $self->{"hmac_key"}
not defined $self->{"cert_obj"}
defined $self->{"hmac_key"}
Truth table66%2/3
not(A) and B
A= not defined $self->{"cert_obj"}B= defined $self->{"hmac_key"}
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | # use the provided cert to verify | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 14 | ▶ | unless ($self->_verify_hmac($signed_info_canon,$signature)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 5 | ▶ | print "not verified by hmac-" . $self->{ sig_hash }, "\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 5 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | # Extract the XML provided certificate and use it to | ||||||||||||||||||||||||||||||||||||||||||
| 479 | # verify the SignedInfo signature | ||||||||||||||||||||||||||||||||||||||||||
| 480 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 481 | # extract the certficate or key from the document | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 195 | my %verify_dispatch = ( | |||||||||||||||||||||||||||||||||||||||||
| 483 | 'X509Data' => '_verify_x509', | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 'RSAKeyValue' => '_verify_rsa', | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 'DSAKeyValue' => '_verify_dsa', | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 'ECDSAKeyValue' => '_verify_ecdsa', | ||||||||||||||||||||||||||||||||||||||||||
| 487 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 195 | my $keyinfo_nodeset; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 195 | foreach my $key_info_sig_type ( qw/X509Data RSAKeyValue DSAKeyValue ECDSAKeyValue/ ) { | |||||||||||||||||||||||||||||||||||||||||
| 490 | 482 | ▶ | if ( $key_info_sig_type eq 'X509Data' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 195 | $keyinfo_nodeset = $parser->find( | |||||||||||||||||||||||||||||||||||||||||
| 492 | "dsig:KeyInfo/dsig:$key_info_sig_type", $signature_node); | ||||||||||||||||||||||||||||||||||||||||||
| 493 | #print (" keyinfo_nodeset X509Data: $keyinfo_nodeset\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 494 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 287 | $keyinfo_nodeset = $parser->find( | |||||||||||||||||||||||||||||||||||||||||
| 496 | "dsig:KeyInfo/dsig:KeyValue/dsig:$key_info_sig_type", $signature_node); | ||||||||||||||||||||||||||||||||||||||||||
| 497 | #print (" keyinfo_nodeset [DR]SAKeyValue: $keyinfo_nodeset\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 482 | ▶ | if ( $keyinfo_nodeset->size ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 195 | my $verify_method = $verify_dispatch{$key_info_sig_type}; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 195 | ▶ | print (" Verify Method: $verify_method\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 195 | ▶ | if ( ! $self->$verify_method($keyinfo_nodeset->get_node(0), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | $signed_info_canon, $signature) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | print ("keyinfo_nodeset->get_node: " . $keyinfo_nodeset->get_node(0) . "\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | print ("Failed to verify using $verify_method\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 507 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 195 | ▶ | print ("Success Verifying\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 195 | last; | |||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 195 | ▶ | die "Unrecognized key type or no KeyInfo in document" unless ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$keyinfo_nodeset and $keyinfo_nodeset->size > 0
MC/DC0%0/2
$keyinfo_nodeset and $keyinfo_nodeset->size > 0
$keyinfo_nodeset
$keyinfo_nodeset->size > 0
Truth table33%1/3
A and B
A= $keyinfo_nodesetB= $keyinfo_nodeset->size > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | $keyinfo_nodeset && $keyinfo_nodeset->size > 0); | ||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | # Signature of SignedInfo was verified above now obtain the | ||||||||||||||||||||||||||||||||||||||||||
| 518 | # Canonical form of the XML and verify the DigestValue of the XML | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | # Remove the Signature from the signed XML | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 230 | my $signed_xml = $self->_get_signed_xml( $signature_node ); | |||||||||||||||||||||||||||||||||||||||||
| 522 | 230 | $signed_xml->removeChild( $signature_node ); | |||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | # Obtain the Canonical form of the XML | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 230 | my $canonical = $self->_transform($signed_xml, $signature_node); | |||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | # Add the $signature_node back to the $signed_xml to allow other | ||||||||||||||||||||||||||||||||||||||||||
| 528 | # signatures to be validated if they exist | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 230 | $signed_xml->addChild( $signature_node ); | |||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | 230 | ▶ | print ( " Canonical XML: " . $canonical ."\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | # Obtain the DigestValue of the Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 230 | my $digest = $self->{digest_method}->(Encode::encode_utf8($canonical)); | |||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 230 | ▶ | print ( " Reference Digest: " . _trim($refdigest) ."\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | 230 | ▶ | print ( " Calculated Digest: ". _trim(encode_base64($digest, '')) ."\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | # Return 0 - fail verification on the first XML signature that fails | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 230 | ▶ | return 0 unless ($refdigest eq _trim(encode_base64($digest, ''))); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | 229 | push @verified, { id => $reference, element => $signed_xml }; | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 229 | ▶ | print ( "Signature $i Valid\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | # Every signature was skipped, so nothing was verified. | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 216 | ▶ | if (!@verified) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 1 | ▶ | print (" No signature in the document was verified\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 215 | $self->{verified_ids} = [ map { $_->{id} } @verified ]; | |||||||||||||||||||||||||||||||||||||||||
| 555 | 215 | $self->{verified_elements} = [ map { $_->{element} } @verified ]; | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 215 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | 14 | ▶ | sub signer_cert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signer_cert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 14 | return $self->{signer_cert}; | |||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 4 | ▶ | sub verified_ids { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verified_ids: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 569 | 4 | ▶ | return $self->{verified_ids} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'verified_ids'} || []
MC/DC100%1/1
$self->{'verified_ids'} || []
$self->{'verified_ids'}
Truth table100%2/2
A
A= $self->{'verified_ids'}
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 2 | ▶ | sub verified_elements { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verified_elements: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 575 | 2 | ▶ | return $self->{verified_elements} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'verified_elements'} || []
MC/DC100%1/1
$self->{'verified_elements'} || []
$self->{'verified_elements'}
Truth table100%2/2
A
A= $self->{'verified_elements'}
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 579 | ## _get_ids_to_sign() | ||||||||||||||||||||||||||||||||||||||||||
| 580 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 581 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 582 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 583 | ## Returns: array Value of ID attributes from XML | ||||||||||||||||||||||||||||||||||||||||||
| 584 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 585 | ## Finds all the values of the ID attributes in the XML | ||||||||||||||||||||||||||||||||||||||||||
| 586 | ## and return them in reverse order found. Reverse order | ||||||||||||||||||||||||||||||||||||||||||
| 587 | ## assumes that the Signatures should be performed on lower | ||||||||||||||||||||||||||||||||||||||||||
| 588 | ## Nodes first. | ||||||||||||||||||||||||||||||||||||||||||
| 589 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 590 | 253 | ▶ | sub _get_ids_to_sign { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_ids_to_sign: called CC=4 SCAR=14.4
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 253 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 592 | 253 | my $parser = $self->{parser}; | |||||||||||||||||||||||||||||||||||||||||
| 593 | 253 | ▶ | if ($self->{id_attr}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 4 | my $nodes = $parser->findnodes($self->{id_attr}); | |||||||||||||||||||||||||||||||||||||||||
| 595 | 4 | ▶ | if ($nodes->size == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | die "Unable to find an attribute node with $self->{id_attr}"; | |||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 4 | my $node = $nodes->get_node(1); | |||||||||||||||||||||||||||||||||||||||||
| 599 | 4 | my $id = $node->getAttribute('ID'); | |||||||||||||||||||||||||||||||||||||||||
| 600 | 4 | ▶ | if ($id !~ $NCName) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | croak ("XML ID format is invalid (should match '$NCName'"); | |||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||
| 603 | 4 | return $node->getAttribute('ID'); | |||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | 249 | my $nodes = $parser->findnodes('//@ID'); | |||||||||||||||||||||||||||||||||||||||||
| 608 | return $nodes->reverse->map( | ||||||||||||||||||||||||||||||||||||||||||
| 609 | 258 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 258 | my $val = $_->getValue; | |||||||||||||||||||||||||||||||||||||||||
| 611 | 258 | ▶ | if ($val !~ $NCName) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | 36 | croak ("XML ID format is invalid (should match '$NCName'"); | |||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | 222 | ▶ | defined($val) && length($val) && $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $val and length $val
MC/DC0%0/2
defined $val and length $val
defined $val
length $val
Truth table33%1/3
A and B
A= defined $valB= length $val
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 249 | ); | |||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 620 | ## _get_xml_to_sign() | ||||||||||||||||||||||||||||||||||||||||||
| 621 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 622 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 623 | ## $id: string ID of the Node for the XML to retrieve | ||||||||||||||||||||||||||||||||||||||||||
| 624 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 625 | ## Returns: XML NodeSet to sign | ||||||||||||||||||||||||||||||||||||||||||
| 626 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 627 | ## Find the XML node with the ID = $id and return the | ||||||||||||||||||||||||||||||||||||||||||
| 628 | ## XML NodeSet | ||||||||||||||||||||||||||||||||||||||||||
| 629 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 630 | 224 | ▶ | sub _get_xml_to_sign { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_xml_to_sign: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 632 | 224 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 224 | ▶ | die "You cannot sign an XML document without identifying the element to sign with an ID attribute" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 224 | my $xpath = "//*[\@ID='$id']"; | |||||||||||||||||||||||||||||||||||||||||
| 636 | 224 | my ($node) = $self->_get_node( $xpath ); | |||||||||||||||||||||||||||||||||||||||||
| 637 | 224 | return $node; | |||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 641 | ## _get_signed_xml($context) | ||||||||||||||||||||||||||||||||||||||||||
| 642 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 643 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 644 | ## $context: string XML NodeSet used as context | ||||||||||||||||||||||||||||||||||||||||||
| 645 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 646 | ## Returns: XML NodeSet for with ID equal to the URI | ||||||||||||||||||||||||||||||||||||||||||
| 647 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 648 | ## Find the XML node with the ID = $URI and return the | ||||||||||||||||||||||||||||||||||||||||||
| 649 | ## XML NodeSet | ||||||||||||||||||||||||||||||||||||||||||
| 650 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 651 | 230 | ▶ | sub _get_signed_xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_signed_xml: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 652 | 230 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 653 | 230 | my ($context) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||
| 655 | 230 | my $id = $self->{parser}->findvalue('./dsig:SignedInfo/dsig:Reference/@URI', $context); | |||||||||||||||||||||||||||||||||||||||||
| 656 | 230 | $id =~ s/^#//; | |||||||||||||||||||||||||||||||||||||||||
| 657 | 230 | ▶ | if ($id !~ $NCName) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | croak ("SignedInfo Reference URI is invalid"); | |||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 230 | ▶ | print (" Signed XML id: $id\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 230 | $self->{'sign_id'} = $id; | |||||||||||||||||||||||||||||||||||||||||
| 664 | 230 | my $xpath = "//*[\@ID='$id']"; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 230 | return $self->_get_node( $xpath, $context ); | |||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 669 | ## _transform($xml, $context) | ||||||||||||||||||||||||||||||||||||||||||
| 670 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 671 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 672 | ## $xml: string XML NodeSet | ||||||||||||||||||||||||||||||||||||||||||
| 673 | ## $context: string XML Context | ||||||||||||||||||||||||||||||||||||||||||
| 674 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 675 | ## Returns: string Transformed XML | ||||||||||||||||||||||||||||||||||||||||||
| 676 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 677 | ## Canonicalizes/Transforms xml based on the Transforms | ||||||||||||||||||||||||||||||||||||||||||
| 678 | ## from the SignedInfo. | ||||||||||||||||||||||||||||||||||||||||||
| 679 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 680 | 230 | ▶ | sub _transform { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_transform: called CC=13 SCAR=35.3
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | 230 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 682 | 230 | my ($xml, $context) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | 230 | $context->setNamespace( 'http://www.w3.org/2000/09/xmldsig#', 'dsig' ); | |||||||||||||||||||||||||||||||||||||||||
| 685 | my $transforms = $self->{parser}->find( | ||||||||||||||||||||||||||||||||||||||||||
| 686 | 230 | 'dsig:SignedInfo/dsig:Reference/dsig:Transforms/dsig:Transform', | |||||||||||||||||||||||||||||||||||||||||
| 687 | $context | ||||||||||||||||||||||||||||||||||||||||||
| 688 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | 230 | ▶ | print "_transform\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | 230 | foreach my $node ($transforms->get_nodelist) { | |||||||||||||||||||||||||||||||||||||||||
| 692 | 460 | my $alg = $node->getAttribute('Algorithm'); | |||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 460 | ▶ | print " Algorithm: $alg\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 460 | ▶ | if ($alg eq TRANSFORM_ENV_SIG) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 696 | # TODO the xml being passed here currently has the | ||||||||||||||||||||||||||||||||||||||||||
| 697 | # Signature removed. May be better to do it all here | ||||||||||||||||||||||||||||||||||||||||||
| 698 | 230 | next; | |||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||
| 700 | elsif ($alg eq TRANSFORM_C14N) { | ||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | print " toStringC14N" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | $xml = $xml->toStringC14N(); | |||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||
| 704 | elsif ($alg eq TRANSFORM_C14N_COMMENTS) { | ||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | ▶ | print " toStringC14N(1)" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | $xml = $xml->toStringC14N(1); | |||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||
| 708 | elsif ($alg eq TRANSFORM_EXC_C14N) { | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 230 | my @prefixlist = $self->_find_prefixlist($node); | |||||||||||||||||||||||||||||||||||||||||
| 710 | 230 | ▶ | print " toStringEC14N(0, '', @prefixlist)\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 230 | $xml = $xml->toStringEC14N(0, '', \@prefixlist); | |||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||
| 713 | elsif ($alg eq TRANSFORM_EXC_C14N_COMMENTS) { | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | my @prefixlist = $self->_find_prefixlist($node); | |||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | print " toStringEC14N(1, '', @prefixlist)\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | $xml = $xml->toStringEC14N(1, '', \@prefixlist); | |||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||
| 718 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | die "Unsupported transform: $alg"; | |||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 230 | return $xml; | |||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 726 | ## _find_prefixlist($node) | ||||||||||||||||||||||||||||||||||||||||||
| 727 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 728 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 729 | ## $node: string XML NodeSet | ||||||||||||||||||||||||||||||||||||||||||
| 730 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 731 | ## Returns: ARRAY of prefix lists | ||||||||||||||||||||||||||||||||||||||||||
| 732 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 733 | ## Generate an array of prefix lists defined in InclusiveNamespaces | ||||||||||||||||||||||||||||||||||||||||||
| 734 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 735 | 230 | ▶ | sub _find_prefixlist { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_prefixlist: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | 230 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 737 | 230 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 738 | 230 | my @children = $node->getChildrenByLocalName('InclusiveNamespaces'); | |||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | 230 | my $prefixlist = ''; | |||||||||||||||||||||||||||||||||||||||||
| 741 | 230 | foreach my $child (@children) { | |||||||||||||||||||||||||||||||||||||||||
| 742 | 4 | ▶ | if ($child) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 743 | 4 | $prefixlist .= $child->getAttribute('PrefixList'); | |||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||
| 745 | 4 | $prefixlist .= ' '; | |||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 230 | return split / /, $prefixlist; | |||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||
| 750 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 751 | ## _verify_rsa($context,$canonical,$sig) | ||||||||||||||||||||||||||||||||||||||||||
| 752 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 753 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 754 | ## $context: string XML Context to use | ||||||||||||||||||||||||||||||||||||||||||
| 755 | ## $canonical: string Canonical XML to verify | ||||||||||||||||||||||||||||||||||||||||||
| 756 | ## $sig: string Base64 encode of RSA Signature | ||||||||||||||||||||||||||||||||||||||||||
| 757 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 758 | ## Returns: integer (1 True, 0 False) if signature is valid | ||||||||||||||||||||||||||||||||||||||||||
| 759 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 760 | ## Verify the RSA signature of Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 761 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 762 | 28 | ▶ | sub _verify_rsa { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_rsa: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | 28 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 764 | 28 | my ($context,$canonical,$sig) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 28 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 767 | 28 | require Crypt::PK::RSA; | |||||||||||||||||||||||||||||||||||||||||
| 768 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 769 | 28 | ▶ | confess "Crypt::PK::RSA needs to be installed so | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 770 | that we can handle X509 certificates" if $@; | ||||||||||||||||||||||||||||||||||||||||||
| 771 | 28 | my $parser = $self->{parser}; | |||||||||||||||||||||||||||||||||||||||||
| 772 | # Generate Public Key from XML | ||||||||||||||||||||||||||||||||||||||||||
| 773 | 28 | my $mod = _trim($parser->findvalue('dsig:Modulus', $context)); | |||||||||||||||||||||||||||||||||||||||||
| 774 | 28 | my $modBin = decode_base64( $mod ); | |||||||||||||||||||||||||||||||||||||||||
| 775 | 28 | my $exp = _trim($parser->findvalue('dsig:Exponent', $context)); | |||||||||||||||||||||||||||||||||||||||||
| 776 | 28 | my $expBin = decode_base64( $exp ); | |||||||||||||||||||||||||||||||||||||||||
| 777 | 28 | my $n = unpack("H*", $modBin); | |||||||||||||||||||||||||||||||||||||||||
| 778 | 28 | my $e = unpack("H*", $expBin); | |||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||
| 780 | 28 | my $pk = Crypt::PK::RSA->new(); | |||||||||||||||||||||||||||||||||||||||||
| 781 | 28 | my $rsa_pub = $pk->import_key({N => $n, e => $e}); | |||||||||||||||||||||||||||||||||||||||||
| 782 | # Decode signature and verify | ||||||||||||||||||||||||||||||||||||||||||
| 783 | 28 | my $bin_signature = decode_base64($sig); | |||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | 28 | ▶ | return 1 if ($rsa_pub->verify_message( $bin_signature, $canonical, $self->{ sig_hash }, "v1.5")); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 790 | ## _clean_x509($cert) | ||||||||||||||||||||||||||||||||||||||||||
| 791 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 792 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 793 | ## $cert: string Certificate in base64 from XML | ||||||||||||||||||||||||||||||||||||||||||
| 794 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 795 | ## Returns: string Certificate in Valid PEM format | ||||||||||||||||||||||||||||||||||||||||||
| 796 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 797 | ## Reformats Certifcate string into PEM format 64 characters | ||||||||||||||||||||||||||||||||||||||||||
| 798 | ## with proper header and footer | ||||||||||||||||||||||||||||||||||||||||||
| 799 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 800 | 67 | ▶ | sub _clean_x509 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clean_x509: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | 67 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 802 | 67 | my ($cert) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 67 | ▶ | $cert = $cert->value() if(ref $cert); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 67 | chomp($cert); | |||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||
| 807 | # rewrap the base64 data from the certificate; it may not be | ||||||||||||||||||||||||||||||||||||||||||
| 808 | # wrapped at 64 characters as PEM requires | ||||||||||||||||||||||||||||||||||||||||||
| 809 | 67 | $cert =~ s/\n//g; | |||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||
| 811 | 67 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 812 | 67 | ▶ | while (length $cert > 64) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 813 | 1380 | push @lines, substr $cert, 0, 64, ''; | |||||||||||||||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||||||||||||||||
| 815 | 67 | push @lines, $cert; | |||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | 67 | $cert = join "\n", @lines; | |||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | 67 | $cert = "-----BEGIN CERTIFICATE-----\n" . $cert . "\n-----END CERTIFICATE-----\n"; | |||||||||||||||||||||||||||||||||||||||||
| 820 | 67 | return $cert; | |||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 824 | ## _verify_x509($context,$canonical,$sig) | ||||||||||||||||||||||||||||||||||||||||||
| 825 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 826 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 827 | ## $context: string XML Context to use | ||||||||||||||||||||||||||||||||||||||||||
| 828 | ## $canonical: string Canonical XML to verify | ||||||||||||||||||||||||||||||||||||||||||
| 829 | ## $sig: string Base64 encode of RSA Signature | ||||||||||||||||||||||||||||||||||||||||||
| 830 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 831 | ## Returns: integer (1 True, 0 False) if signature is valid | ||||||||||||||||||||||||||||||||||||||||||
| 832 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 833 | ## Verify the RSA signature of Canonical XML using an X509 | ||||||||||||||||||||||||||||||||||||||||||
| 834 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 835 | 67 | ▶ | sub _verify_x509 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_x509: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 836 | 67 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 837 | 67 | my ($context,$canonical,$sig) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | 67 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 840 | 67 | require Crypt::OpenSSL::X509; | |||||||||||||||||||||||||||||||||||||||||
| 841 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 842 | 67 | ▶ | confess "Crypt::OpenSSL::X509 needs to be installed so that we can handle X509 certificates" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||
| 844 | # Generate Public Key from XML | ||||||||||||||||||||||||||||||||||||||||||
| 845 | 67 | my $certificate = _trim($self->{parser}->findvalue('dsig:X509Certificate', $context)); | |||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||
| 847 | # This is added because the X509 parser requires it for self-identification | ||||||||||||||||||||||||||||||||||||||||||
| 848 | 67 | $certificate = $self->_clean_x509($certificate); | |||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | 67 | my $cert = Crypt::OpenSSL::X509->new_from_string($certificate); | |||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | 67 | return $self->_verify_x509_cert($cert, $canonical, $sig); | |||||||||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 856 | ## _verify_x509_cert($cert,$canonical,$sig) | ||||||||||||||||||||||||||||||||||||||||||
| 857 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 858 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 859 | ## $cert: string X509 Certificate | ||||||||||||||||||||||||||||||||||||||||||
| 860 | ## $canonical: string Canonical XML to verify | ||||||||||||||||||||||||||||||||||||||||||
| 861 | ## $sig: string Base64 encode of [EC|R]SA Signature | ||||||||||||||||||||||||||||||||||||||||||
| 862 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 863 | ## Returns: integer (1 True, 0 False) if signature is valid | ||||||||||||||||||||||||||||||||||||||||||
| 864 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 865 | ## Verify the X509 signature of Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 866 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 867 | 93 | ▶ | sub _verify_x509_cert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_x509_cert: called CC=9 SCAR=22.2
| |||||||||||||||||||||||||||||||||||||||||||
| 868 | 93 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 869 | 93 | my ($cert, $canonical, $sig) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||
| 871 | # Decode signature and verify | ||||||||||||||||||||||||||||||||||||||||||
| 872 | 93 | my $bin_signature = decode_base64($sig); | |||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | 93 | ▶ | if ($cert->key_alg_name eq 'id-ecPublicKey') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 875 | 27 | ▶ | eval {require Crypt::PK::ECC; CryptX->VERSION('0.036'); 1} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 876 | or confess "Crypt::PK::ECC 0.036+ needs to be installed so | ||||||||||||||||||||||||||||||||||||||||||
| 877 | that we can handle ECDSA signatures"; | ||||||||||||||||||||||||||||||||||||||||||
| 878 | 27 | my $ecdsa_pub = Crypt::PK::ECC->new(\$cert->pubkey); | |||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | 27 | my $ecdsa_hash = $self->{rsa_hash}; | |||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||
| 882 | # Signature is stored as the concatenation of r and s. | ||||||||||||||||||||||||||||||||||||||||||
| 883 | # verify_message_rfc7518 expects that format | ||||||||||||||||||||||||||||||||||||||||||
| 884 | 27 | ▶ | if ($ecdsa_pub->verify_message_rfc7518( $bin_signature, $canonical, uc($self->{sig_hash}) )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 885 | 27 | $self->{signer_cert} = $cert; | |||||||||||||||||||||||||||||||||||||||||
| 886 | 27 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||||||||||||||||
| 889 | elsif ($cert->key_alg_name eq 'dsaEncryption') { | ||||||||||||||||||||||||||||||||||||||||||
| 890 | 3 | ▶ | confess "Crypt::OpenSSL::DSA >= 0.20 needs to be installed so | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 891 | that we can handle DSA X509 certificates" if ! $self->check_dsa_version(); | ||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||
| 893 | 3 | my $dsa_pub = Crypt::OpenSSL::DSA->read_pub_key_str( $cert->pubkey ); | |||||||||||||||||||||||||||||||||||||||||
| 894 | 3 | my $sig_size = ($dsa_pub->get_sig_size - 8)/2; | |||||||||||||||||||||||||||||||||||||||||
| 895 | #my ($r, $s) = unpack('a20a20', $bin_signature); | ||||||||||||||||||||||||||||||||||||||||||
| 896 | 3 | my $unpk = "a" . $sig_size . "a" . $sig_size; | |||||||||||||||||||||||||||||||||||||||||
| 897 | 3 | my ($r, $s) = unpack($unpk, $bin_signature); | |||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||
| 899 | # Create a new Signature Object from r and s | ||||||||||||||||||||||||||||||||||||||||||
| 900 | 3 | my $sigobj = Crypt::OpenSSL::DSA::Signature->new(); | |||||||||||||||||||||||||||||||||||||||||
| 901 | 3 | $sigobj->set_r($r); | |||||||||||||||||||||||||||||||||||||||||
| 902 | 3 | $sigobj->set_s($s); | |||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||
| 904 | 3 | ▶ | if ($dsa_pub->do_verify($self->{sig_method}->($canonical), $sigobj)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 905 | 3 | $self->{signer_cert} = $cert; | |||||||||||||||||||||||||||||||||||||||||
| 906 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 907 | } | ||||||||||||||||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||||||||||||||
| 909 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 910 | 63 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 911 | 63 | require Crypt::PK::RSA; | |||||||||||||||||||||||||||||||||||||||||
| 912 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 913 | 63 | ▶ | confess "Crypt::PK::RSA needs to be installed so | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 914 | that we can handle X509 certificates" if $@; | ||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||
| 916 | 63 | my $pk = Crypt::PK::RSA->new(); | |||||||||||||||||||||||||||||||||||||||||
| 917 | 63 | my $rsa_pub = $pk->import_key(\$cert->pubkey); | |||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||
| 919 | # If successful verify, store the signer's cert for validation | ||||||||||||||||||||||||||||||||||||||||||
| 920 | 63 | ▶ | if ($rsa_pub->verify_message( $bin_signature, $canonical, $self->{sig_hash}, 'v1.5' )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 921 | 63 | $self->{signer_cert} = $cert; | |||||||||||||||||||||||||||||||||||||||||
| 922 | 63 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||
| 929 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 930 | ## _zero_fill_buffer($bits) | ||||||||||||||||||||||||||||||||||||||||||
| 931 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 932 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 933 | ## $bits: number of bits to set to zero | ||||||||||||||||||||||||||||||||||||||||||
| 934 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 935 | ## Returns: Zero filled bit buffer of size $bits | ||||||||||||||||||||||||||||||||||||||||||
| 936 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 937 | ## Create a buffer with all bits set to 0 | ||||||||||||||||||||||||||||||||||||||||||
| 938 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 939 | 43 | ▶ | sub _zero_fill_buffer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_zero_fill_buffer: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 940 | 43 | my $bits = shift; | |||||||||||||||||||||||||||||||||||||||||
| 941 | # set all bit to zero | ||||||||||||||||||||||||||||||||||||||||||
| 942 | 43 | my $v = ''; | |||||||||||||||||||||||||||||||||||||||||
| 943 | 43 | ▶ | for (my $i = 0; $i < $bits; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 944 | 17600 | vec($v, $i, 1) = 0; | |||||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||||||
| 946 | 43 | return $v; | |||||||||||||||||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||
| 949 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 950 | ## _concat_dsa_sig_r_s(\$buffer,$r,$s) | ||||||||||||||||||||||||||||||||||||||||||
| 951 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 952 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 953 | ## $buffer: Zero Filled bit buffer | ||||||||||||||||||||||||||||||||||||||||||
| 954 | ## $r: octet stream | ||||||||||||||||||||||||||||||||||||||||||
| 955 | ## $s: octet stream | ||||||||||||||||||||||||||||||||||||||||||
| 956 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 957 | ## Combine r and s components of DSA signature | ||||||||||||||||||||||||||||||||||||||||||
| 958 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 959 | 43 | ▶ | sub _concat_dsa_sig_r_s { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_concat_dsa_sig_r_s: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||
| 961 | 43 | my ($buffer, $r, $s, $sig_size) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 962 | 43 | my $bits_r = (length($r)*8)-1; | |||||||||||||||||||||||||||||||||||||||||
| 963 | 43 | my $bits_s = (length($s)*8)-1; | |||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||
| 965 | 43 | my $halfsize = $sig_size / 2; | |||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||
| 967 | # Place $s right justified in $v starting at bit 319 | ||||||||||||||||||||||||||||||||||||||||||
| 968 | 43 | ▶ | for (my $i = $bits_s; $i >=0; $i--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 969 | 8800 | vec($$buffer, $halfsize + $i + (($halfsize -1) - $bits_s) , 1) = vec($s, $i, 1); | |||||||||||||||||||||||||||||||||||||||||
| 970 | } | ||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||
| 972 | # Place $r right justified in $v starting at bit 159 | ||||||||||||||||||||||||||||||||||||||||||
| 973 | 43 | ▶ | for (my $i = $bits_r; $i >= 0 ; $i--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 974 | 8800 | vec($$buffer, $i + (($halfsize -1) - $bits_r) , 1) = vec($r, $i, 1); | |||||||||||||||||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 980 | ## assert_dsa_installed | ||||||||||||||||||||||||||||||||||||||||||
| 981 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 982 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 983 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 984 | ## Returns: croak if unable to load Crypt::OpenSSL::DSA | ||||||||||||||||||||||||||||||||||||||||||
| 985 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 986 | ## Verify that Crypt::OpenSSL::DSA is installed | ||||||||||||||||||||||||||||||||||||||||||
| 987 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 988 | 298 | ▶ | sub _assert_dsa_installed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_dsa_installed: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 989 | 298 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 990 | 298 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 991 | 298 | require Crypt::OpenSSL::DSA; | |||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | croak "Crypt::OpenSSL::DSA is not installed"; | |||||||||||||||||||||||||||||||||||||||||
| 994 | 298 | }; | |||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||||||||||||||||
| 997 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 998 | ## check_dsa_version | ||||||||||||||||||||||||||||||||||||||||||
| 999 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1002 | ## Returns: integer (1 True, 0 False) if Correct version of Crypt::OpenSSL::DSA is installed | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1004 | ## Verify the required Crypt::OpenSSL::DSA is installed | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | 298 | ▶ | sub check_dsa_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_dsa_version: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1007 | 298 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1008 | 298 | my $ver; | |||||||||||||||||||||||||||||||||||||||||
| 1009 | 298 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1010 | 298 | XML::Sig::_assert_dsa_installed; | |||||||||||||||||||||||||||||||||||||||||
| 1011 | 298 | $ver = Crypt::OpenSSL::DSA->VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1013 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1014 | 298 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||
| 1016 | 298 | ▶ | if ( (!defined $ver) || (version->parse($ver) lt version->parse('0.20')) ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $ver or "version"->parse($ver) lt "version"->parse("0.20")
MC/DC0%0/2
not defined $ver or "version"->parse($ver) lt "version"->parse("0.20")
not defined $ver
"version"->parse($ver) lt "version"->parse("0.20")
Truth table33%1/3
not(A) or B
A= not defined $verB= "version"->parse($ver) lt "version"->parse("0.20")
| |||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1018 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1019 | 298 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||
| 1022 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | ## _verify_dsa($context,$canonical,$sig) | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1025 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | ## $context: string XML Context to use | ||||||||||||||||||||||||||||||||||||||||||
| 1027 | ## $canonical: string Canonical XML to verify | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | ## $sig: string Base64 encode 40 byte string of r and s | ||||||||||||||||||||||||||||||||||||||||||
| 1029 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1030 | ## Returns: integer (1 True, 0 False) if signature is valid | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | ## Verify the DSA signature of Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 1033 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | 41 | ▶ | sub _verify_dsa { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_dsa: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1035 | 41 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1036 | 41 | my ($context,$canonical,$sig) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||
| 1039 | 41 | ▶ | confess "Crypt::OpenSSL::DSA >= 0.20 needs to be installed so | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1040 | that we can handle DSA signatures" if ! $self->check_dsa_version(); | ||||||||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||||||||
| 1042 | 41 | my $parser = $self->{parser}; | |||||||||||||||||||||||||||||||||||||||||
| 1043 | # Generate Public Key from XML | ||||||||||||||||||||||||||||||||||||||||||
| 1044 | 41 | my $p = decode_base64(_trim($parser->findvalue('dsig:P', $context))); | |||||||||||||||||||||||||||||||||||||||||
| 1045 | 41 | my $q = decode_base64(_trim($parser->findvalue('dsig:Q', $context))); | |||||||||||||||||||||||||||||||||||||||||
| 1046 | 41 | my $g = decode_base64(_trim($parser->findvalue('dsig:G', $context))); | |||||||||||||||||||||||||||||||||||||||||
| 1047 | 41 | my $y = decode_base64(_trim($parser->findvalue('dsig:Y', $context))); | |||||||||||||||||||||||||||||||||||||||||
| 1048 | 41 | my $dsa_pub = Crypt::OpenSSL::DSA->new(); | |||||||||||||||||||||||||||||||||||||||||
| 1049 | 41 | $dsa_pub->set_p($p); | |||||||||||||||||||||||||||||||||||||||||
| 1050 | 41 | $dsa_pub->set_q($q); | |||||||||||||||||||||||||||||||||||||||||
| 1051 | 41 | $dsa_pub->set_g($g); | |||||||||||||||||||||||||||||||||||||||||
| 1052 | 41 | $dsa_pub->set_pub_key($y); | |||||||||||||||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||||||||||||||||
| 1054 | # Decode signature and verify | ||||||||||||||||||||||||||||||||||||||||||
| 1055 | 41 | my $bin_signature = decode_base64($sig); | |||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||
| 1057 | # https://www.w3.org/TR/2002/REC-xmldsig-core-20020212/#sec-SignatureAlg | ||||||||||||||||||||||||||||||||||||||||||
| 1058 | # The output of the DSA algorithm consists of a pair of integers | ||||||||||||||||||||||||||||||||||||||||||
| 1059 | # The signature value consists of the base64 encoding of the | ||||||||||||||||||||||||||||||||||||||||||
| 1060 | # concatenation of r and s in that order ($r . $s) | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | # Binary Signature is stored as a concatenation of r and s | ||||||||||||||||||||||||||||||||||||||||||
| 1062 | 41 | my $sig_size = ($dsa_pub->get_sig_size - 8)/2; | |||||||||||||||||||||||||||||||||||||||||
| 1063 | 41 | my $unpk = "a" . $sig_size . "a" . $sig_size; | |||||||||||||||||||||||||||||||||||||||||
| 1064 | 41 | my ($r, $s) = unpack($unpk, $bin_signature); | |||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||
| 1066 | # Create a new Signature Object from r and s | ||||||||||||||||||||||||||||||||||||||||||
| 1067 | 41 | my $sigobj = Crypt::OpenSSL::DSA::Signature->new(); | |||||||||||||||||||||||||||||||||||||||||
| 1068 | 41 | $sigobj->set_r($r); | |||||||||||||||||||||||||||||||||||||||||
| 1069 | 41 | $sigobj->set_s($s); | |||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||
| 1071 | # DSA signatures are limited to a message body of 20 characters, so a sha1 digest is taken | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | 41 | ▶ | return 1 if ($dsa_pub->do_verify( $self->{sig_method}->($canonical), $sigobj )); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1073 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1074 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||||||||||||||||
| 1076 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1077 | ## _verify_ecdsa($context,$canonical,$sig) | ||||||||||||||||||||||||||||||||||||||||||
| 1078 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1079 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | ## $context: string XML Context to use | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | ## $canonical: string Canonical XML to verify | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | ## $sig: string Base64 encoded | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1084 | ## Returns: integer (1 True, 0 False) if signature is valid | ||||||||||||||||||||||||||||||||||||||||||
| 1085 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | ## Verify the ECDSA signature of Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 1087 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | 59 | ▶ | sub _verify_ecdsa { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_ecdsa: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1089 | 59 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1090 | 59 | my ($context,$canonical,$sig) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||
| 1092 | 59 | my $parser = $self->{parser}; | |||||||||||||||||||||||||||||||||||||||||
| 1093 | 59 | ▶ | eval {require Crypt::PK::ECC; CryptX->VERSION('0.036'); 1} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1094 | or confess "Crypt::PK::ECC 0.036+ needs to be installed so | ||||||||||||||||||||||||||||||||||||||||||
| 1095 | that we can handle ECDSA signatures"; | ||||||||||||||||||||||||||||||||||||||||||
| 1096 | # Generate Public Key from XML | ||||||||||||||||||||||||||||||||||||||||||
| 1097 | 59 | my $oid = _trim($parser->findvalue('.//dsig:NamedCurve/@URN', $context)); | |||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||
| 1099 | 32 | ▶ | use URI (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1100 | 59 | my $u1 = URI->new($oid); | |||||||||||||||||||||||||||||||||||||||||
| 1101 | 59 | $oid = $u1->nss; | |||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||
| 1103 | 59 | my %curve_name = ( | |||||||||||||||||||||||||||||||||||||||||
| 1104 | '1.2.840.10045.3.1.1' => 'secp192r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1105 | '1.3.132.0.33' => 'secp224r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1106 | '1.2.840.10045.3.1.7' => 'secp256r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1107 | '1.3.132.0.34' => 'secp384r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | '1.3.132.0.35' => 'secp521r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1109 | '1.3.36.3.3.2.8.1.1.1' => 'brainpoolP160r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1110 | '1.3.36.3.3.2.8.1.1.3' => 'brainpoolP192r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1111 | '1.3.36.3.3.2.8.1.1.5' => 'brainpoolP224r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1112 | '1.3.36.3.3.2.8.1.1.7' => 'brainpoolP256r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | '1.3.36.3.3.2.8.1.1.9' => 'brainpoolP320r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1114 | '1.3.36.3.3.2.8.1.1.11' => 'brainpoolP384r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1115 | '1.3.36.3.3.2.8.1.1.13' => 'brainpoolP512r1', | ||||||||||||||||||||||||||||||||||||||||||
| 1116 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||||||
| 1118 | 59 | my $x = $parser->findvalue('.//dsig:PublicKey/dsig:X/@Value', $context); | |||||||||||||||||||||||||||||||||||||||||
| 1119 | 59 | my $y = $parser->findvalue('.//dsig:PublicKey/dsig:Y/@Value', $context); | |||||||||||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||||||||||||
| 1121 | 59 | my $ecdsa_pub = Crypt::PK::ECC->new(); | |||||||||||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||||||||||||
| 1123 | $ecdsa_pub->import_key({ | ||||||||||||||||||||||||||||||||||||||||||
| 1124 | kty => "EC", | ||||||||||||||||||||||||||||||||||||||||||
| 1125 | 59 | curve_name => $curve_name{ $oid }, | |||||||||||||||||||||||||||||||||||||||||
| 1126 | pub_x => $x, | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | pub_y => $y, | ||||||||||||||||||||||||||||||||||||||||||
| 1128 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||||||||||
| 1130 | 59 | my $bin_signature = decode_base64($sig); | |||||||||||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||||||||||||
| 1132 | # verify_message_rfc7518 is used to verify signature stored as a | ||||||||||||||||||||||||||||||||||||||||||
| 1133 | # concatenation of integers r and s | ||||||||||||||||||||||||||||||||||||||||||
| 1134 | return 1 if ($ecdsa_pub->verify_message_rfc7518( | ||||||||||||||||||||||||||||||||||||||||||
| 1135 | $bin_signature, | ||||||||||||||||||||||||||||||||||||||||||
| 1136 | $canonical, | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | 59 | ▶ | uc($self->{sig_hash})) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1138 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1139 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||
| 1142 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1143 | ## _verify_hmac($canonical, $sig) | ||||||||||||||||||||||||||||||||||||||||||
| 1144 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1146 | ## $canonical: string Canonical XML to verify | ||||||||||||||||||||||||||||||||||||||||||
| 1147 | ## $sig: string Base64 encode of HMAC Signature | ||||||||||||||||||||||||||||||||||||||||||
| 1148 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1149 | ## Returns: integer (1 True, 0 False) if signature is valid | ||||||||||||||||||||||||||||||||||||||||||
| 1150 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | ## Verify the HMAC signature of Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 1152 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1153 | 14 | ▶ | sub _verify_hmac { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_hmac: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1154 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1155 | 14 | my ($canonical, $sig) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||||||||||||||||
| 1157 | # Decode signature and verify | ||||||||||||||||||||||||||||||||||||||||||
| 1158 | 14 | my $bin_signature = decode_base64($sig); | |||||||||||||||||||||||||||||||||||||||||
| 1159 | 32 | ▶ | use Crypt::Mac::HMAC qw( hmac ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1160 | 14 | ▶ | if ( defined $self->{ hmac_key } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1161 | 14 | ▶ | print (" Verifying SignedInfo using hmac-", $self->{ sig_hash }, "\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1162 | # _calc_hmac_signature dies on an unsupported hash algorithm | ||||||||||||||||||||||||||||||||||||||||||
| 1163 | 14 | ▶ | return ($bin_signature eq $self->_calc_hmac_signature( $canonical )) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||
| 1165 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1166 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1169 | |||||||||||||||||||||||||||||||||||||||||||
| 1170 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1171 | ## _get_node($xpath, context) | ||||||||||||||||||||||||||||||||||||||||||
| 1172 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | ## $xpath: string XML XPath to use | ||||||||||||||||||||||||||||||||||||||||||
| 1175 | ## $context: string XML context | ||||||||||||||||||||||||||||||||||||||||||
| 1176 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1177 | ## Returns: string XML NodeSet | ||||||||||||||||||||||||||||||||||||||||||
| 1178 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1179 | ## Return a NodeSet based on the xpath string | ||||||||||||||||||||||||||||||||||||||||||
| 1180 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1181 | 454 | ▶ | sub _get_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_node: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1182 | 454 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1183 | 454 | my ($xpath, $context) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1184 | 454 | my $parser = $self->{parser}; | |||||||||||||||||||||||||||||||||||||||||
| 1185 | 454 | my $nodeset; | |||||||||||||||||||||||||||||||||||||||||
| 1186 | 454 | ▶ | if ($context) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1187 | 230 | $nodeset = $parser->find($xpath, $context); | |||||||||||||||||||||||||||||||||||||||||
| 1188 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1189 | 224 | $nodeset = $parser->find($xpath); | |||||||||||||||||||||||||||||||||||||||||
| 1190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1191 | 454 | foreach my $node ($nodeset->get_nodelist) { | |||||||||||||||||||||||||||||||||||||||||
| 1192 | 454 | return $node; | |||||||||||||||||||||||||||||||||||||||||
| 1193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||
| 1196 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | ## _trim($string) | ||||||||||||||||||||||||||||||||||||||||||
| 1198 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | ## $string: string String to remove whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 1201 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1202 | ## Returns: string Trimmed String | ||||||||||||||||||||||||||||||||||||||||||
| 1203 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1204 | ## Trim the whitespace from the begining and end of the string | ||||||||||||||||||||||||||||||||||||||||||
| 1205 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1206 | 1156 | ▶ | sub _trim { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1207 | 1156 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1208 | 1156 | $string =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 1209 | 1156 | $string =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 1210 | 1156 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 1211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||||||||||||||||
| 1213 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1214 | ## _load_ecdsa_key($key_text) | ||||||||||||||||||||||||||||||||||||||||||
| 1215 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1216 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1217 | ## $key_text: string ECDSA Private Key as String | ||||||||||||||||||||||||||||||||||||||||||
| 1218 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1219 | ## Returns: nothing | ||||||||||||||||||||||||||||||||||||||||||
| 1220 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | ## Populate: | ||||||||||||||||||||||||||||||||||||||||||
| 1222 | ## self->{KeyInfo} | ||||||||||||||||||||||||||||||||||||||||||
| 1223 | ## self->{key_obj} | ||||||||||||||||||||||||||||||||||||||||||
| 1224 | ## self->{key_type} | ||||||||||||||||||||||||||||||||||||||||||
| 1225 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1226 | 85 | ▶ | sub _load_ecdsa_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_ecdsa_key: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1227 | 85 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1228 | 85 | my $key_text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1229 | |||||||||||||||||||||||||||||||||||||||||||
| 1230 | 85 | ▶ | eval {require Crypt::PK::ECC; CryptX->VERSION('0.036'); 1} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1231 | or confess "Crypt::PK::ECC 0.036+ needs to be installed so | ||||||||||||||||||||||||||||||||||||||||||
| 1232 | that we can handle ECDSA signatures"; | ||||||||||||||||||||||||||||||||||||||||||
| 1233 | |||||||||||||||||||||||||||||||||||||||||||
| 1234 | 85 | my $ecdsa_key = Crypt::PK::ECC->new(\$key_text); | |||||||||||||||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||||||||||||||||
| 1236 | 85 | ▶ | if ( $ecdsa_key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1237 | 85 | $self->{ key_obj } = $ecdsa_key; | |||||||||||||||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||||||||||||||||
| 1239 | 85 | my $key_hash = $ecdsa_key->key2hash; | |||||||||||||||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||||||||||||||||
| 1241 | 85 | my $oid = $key_hash->{ curve_oid }; | |||||||||||||||||||||||||||||||||||||||||
| 1242 | 85 | my $x = $key_hash->{ pub_x }; | |||||||||||||||||||||||||||||||||||||||||
| 1243 | 85 | my $y = $key_hash->{ pub_y }; | |||||||||||||||||||||||||||||||||||||||||
| 1244 | |||||||||||||||||||||||||||||||||||||||||||
| 1245 | 85 | $self->{KeyInfo} = "<dsig:KeyInfo> | |||||||||||||||||||||||||||||||||||||||||
| 1246 | <dsig:KeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1247 | <dsig:ECDSAKeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1248 | <dsig:DomainParameters> | ||||||||||||||||||||||||||||||||||||||||||
| 1249 | <dsig:NamedCurve URN=\"urn:oid:$oid\" /> | ||||||||||||||||||||||||||||||||||||||||||
| 1250 | </dsig:DomainParameters> | ||||||||||||||||||||||||||||||||||||||||||
| 1251 | <dsig:PublicKey> | ||||||||||||||||||||||||||||||||||||||||||
| 1252 | <dsig:X Value=\"$x\" /> | ||||||||||||||||||||||||||||||||||||||||||
| 1253 | <dsig:Y Value=\"$y\" /> | ||||||||||||||||||||||||||||||||||||||||||
| 1254 | </dsig:PublicKey> | ||||||||||||||||||||||||||||||||||||||||||
| 1255 | </dsig:ECDSAKeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1256 | </dsig:KeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1257 | </dsig:KeyInfo>"; | ||||||||||||||||||||||||||||||||||||||||||
| 1258 | 85 | $self->{key_type} = 'ecdsa'; | |||||||||||||||||||||||||||||||||||||||||
| 1259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1260 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1261 | 0 | confess "did not get a new Crypt::PK::ECC object"; | |||||||||||||||||||||||||||||||||||||||||
| 1262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||||||||||||||||
| 1265 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1266 | ## _load_dsa_key($key_text) | ||||||||||||||||||||||||||||||||||||||||||
| 1267 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1268 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1269 | ## $key_text: string DSA Private Key as String | ||||||||||||||||||||||||||||||||||||||||||
| 1270 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1271 | ## Returns: nothing | ||||||||||||||||||||||||||||||||||||||||||
| 1272 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1273 | ## Populate: | ||||||||||||||||||||||||||||||||||||||||||
| 1274 | ## self->{KeyInfo} | ||||||||||||||||||||||||||||||||||||||||||
| 1275 | ## self->{key_obj} | ||||||||||||||||||||||||||||||||||||||||||
| 1276 | ## self->{key_type} | ||||||||||||||||||||||||||||||||||||||||||
| 1277 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1278 | 42 | ▶ | sub _load_dsa_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_dsa_key: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1279 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1280 | 42 | my $key_text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1281 | |||||||||||||||||||||||||||||||||||||||||||
| 1282 | 42 | ▶ | confess "Crypt::OpenSSL::DSA >= 0.20 needs to be installed so that we can handle DSA keys." | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1283 | if ! $self->check_dsa_version(); | ||||||||||||||||||||||||||||||||||||||||||
| 1284 | |||||||||||||||||||||||||||||||||||||||||||
| 1285 | 42 | my $dsa_key = Crypt::OpenSSL::DSA->read_priv_key_str( $key_text ); | |||||||||||||||||||||||||||||||||||||||||
| 1286 | |||||||||||||||||||||||||||||||||||||||||||
| 1287 | 42 | ▶ | if ( $dsa_key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1288 | 42 | $self->{ key_obj } = $dsa_key; | |||||||||||||||||||||||||||||||||||||||||
| 1289 | 42 | my $g = encode_base64( $dsa_key->get_g(), '' ); | |||||||||||||||||||||||||||||||||||||||||
| 1290 | 42 | my $p = encode_base64( $dsa_key->get_p(), '' ); | |||||||||||||||||||||||||||||||||||||||||
| 1291 | 42 | my $q = encode_base64( $dsa_key->get_q(), '' ); | |||||||||||||||||||||||||||||||||||||||||
| 1292 | 42 | my $y = encode_base64( $dsa_key->get_pub_key(), '' ); | |||||||||||||||||||||||||||||||||||||||||
| 1293 | |||||||||||||||||||||||||||||||||||||||||||
| 1294 | 42 | $self->{KeyInfo} = "<dsig:KeyInfo> | |||||||||||||||||||||||||||||||||||||||||
| 1295 | <dsig:KeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1296 | <dsig:DSAKeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1297 | <dsig:P>$p</dsig:P> | ||||||||||||||||||||||||||||||||||||||||||
| 1298 | <dsig:Q>$q</dsig:Q> | ||||||||||||||||||||||||||||||||||||||||||
| 1299 | <dsig:G>$g</dsig:G> | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | <dsig:Y>$y</dsig:Y> | ||||||||||||||||||||||||||||||||||||||||||
| 1301 | </dsig:DSAKeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1302 | </dsig:KeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1303 | </dsig:KeyInfo>"; | ||||||||||||||||||||||||||||||||||||||||||
| 1304 | 42 | $self->{key_type} = 'dsa'; | |||||||||||||||||||||||||||||||||||||||||
| 1305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1306 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1307 | 0 | confess "did not get a new Crypt::PK::RSA object"; | |||||||||||||||||||||||||||||||||||||||||
| 1308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1310 | |||||||||||||||||||||||||||||||||||||||||||
| 1311 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1312 | ## _load_rsa_key($key_text) | ||||||||||||||||||||||||||||||||||||||||||
| 1313 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1314 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1315 | ## $key_text: string RSA Private Key as String | ||||||||||||||||||||||||||||||||||||||||||
| 1316 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1317 | ## Returns: nothing | ||||||||||||||||||||||||||||||||||||||||||
| 1318 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1319 | ## Populate: | ||||||||||||||||||||||||||||||||||||||||||
| 1320 | ## self->{KeyInfo} | ||||||||||||||||||||||||||||||||||||||||||
| 1321 | ## self->{key_obj} | ||||||||||||||||||||||||||||||||||||||||||
| 1322 | ## self->{key_type} | ||||||||||||||||||||||||||||||||||||||||||
| 1323 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1324 | 74 | ▶ | sub _load_rsa_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_rsa_key: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1325 | 74 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1326 | 74 | my ($key_text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1327 | |||||||||||||||||||||||||||||||||||||||||||
| 1328 | 74 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 1329 | 74 | require Crypt::PK::RSA; | |||||||||||||||||||||||||||||||||||||||||
| 1330 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1331 | 74 | ▶ | confess "Crypt::PK::RSA needs to be installed so that we can handle RSA keys." if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1332 | |||||||||||||||||||||||||||||||||||||||||||
| 1333 | 74 | my $pk = Crypt::PK::RSA->new(); | |||||||||||||||||||||||||||||||||||||||||
| 1334 | 74 | my $rsaKey = $pk->import_key(\$key_text); | |||||||||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||||||||||
| 1336 | 74 | ▶ | if ( $rsaKey ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1337 | 74 | $self->{ key_obj } = $rsaKey; | |||||||||||||||||||||||||||||||||||||||||
| 1338 | 74 | $self->{ key_type } = 'rsa'; | |||||||||||||||||||||||||||||||||||||||||
| 1339 | |||||||||||||||||||||||||||||||||||||||||||
| 1340 | 74 | ▶ | if (!$self->{ x509 }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1341 | 43 | my $key_params = $rsaKey->key2hash; | |||||||||||||||||||||||||||||||||||||||||
| 1342 | 43 | my $exp = encode_base64(pack("H*", $key_params->{e}), ''); | |||||||||||||||||||||||||||||||||||||||||
| 1343 | 43 | my $mod = encode_base64(pack("H*", $key_params->{N}), ''); | |||||||||||||||||||||||||||||||||||||||||
| 1344 | 43 | $self->{KeyInfo} = "<dsig:KeyInfo> | |||||||||||||||||||||||||||||||||||||||||
| 1345 | <dsig:KeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1346 | <dsig:RSAKeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1347 | <dsig:Modulus>$mod</dsig:Modulus> | ||||||||||||||||||||||||||||||||||||||||||
| 1348 | <dsig:Exponent>$exp</dsig:Exponent> | ||||||||||||||||||||||||||||||||||||||||||
| 1349 | </dsig:RSAKeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1350 | </dsig:KeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1351 | </dsig:KeyInfo>"; | ||||||||||||||||||||||||||||||||||||||||||
| 1352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1354 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1355 | 0 | confess "did not get a new Crypt::PK::RSA object"; | |||||||||||||||||||||||||||||||||||||||||
| 1356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||||||||||||||||
| 1359 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1360 | ## _load_hmac_key_info() | ||||||||||||||||||||||||||||||||||||||||||
| 1361 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1362 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1363 | ## none | ||||||||||||||||||||||||||||||||||||||||||
| 1364 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1365 | ## Returns: nothing | ||||||||||||||||||||||||||||||||||||||||||
| 1366 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1367 | ## Populate: | ||||||||||||||||||||||||||||||||||||||||||
| 1368 | ## self->{KeyInfo} | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1370 | 20 | ▶ | sub _load_hmac_key_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_hmac_key_info: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 1371 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1372 | |||||||||||||||||||||||||||||||||||||||||||
| 1373 | 20 | ▶ | if (! defined $self->{ key_name }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1374 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||||||||||||||||
| 1377 | 20 | $self->{KeyInfo} = qq{<dsig:KeyInfo><dsig:KeyName>$self->{key_name}</dsig:KeyName></dsig:KeyInfo>}; | |||||||||||||||||||||||||||||||||||||||||
| 1378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | |||||||||||||||||||||||||||||||||||||||||||
| 1380 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1381 | ## _load_x509_key($key_text) | ||||||||||||||||||||||||||||||||||||||||||
| 1382 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1383 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1384 | ## $key_text: string RSA Private Key as String | ||||||||||||||||||||||||||||||||||||||||||
| 1385 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1386 | ## Returns: nothing | ||||||||||||||||||||||||||||||||||||||||||
| 1387 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1388 | ## Populate: | ||||||||||||||||||||||||||||||||||||||||||
| 1389 | ## self->{key_obj} | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | ## self->{key_type} | ||||||||||||||||||||||||||||||||||||||||||
| 1391 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | 0 | ▶ | sub _load_x509_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_x509_key: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 1393 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1394 | 0 | my $key_text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1395 | |||||||||||||||||||||||||||||||||||||||||||
| 1396 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 1397 | 0 | require Crypt::OpenSSL::X509; | |||||||||||||||||||||||||||||||||||||||||
| 1398 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1399 | 0 | ▶ | confess "Crypt::OpenSSL::X509 needs to be installed so that we | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1400 | can handle X509 Certificates." if $@; | ||||||||||||||||||||||||||||||||||||||||||
| 1401 | |||||||||||||||||||||||||||||||||||||||||||
| 1402 | 0 | my $x509Key = Crypt::OpenSSL::X509->new_private_key( $key_text ); | |||||||||||||||||||||||||||||||||||||||||
| 1403 | |||||||||||||||||||||||||||||||||||||||||||
| 1404 | 0 | ▶ | if ( $x509Key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1405 | 0 | $x509Key->use_pkcs1_oaep_padding(); | |||||||||||||||||||||||||||||||||||||||||
| 1406 | 0 | $self->{ key_obj } = $x509Key; | |||||||||||||||||||||||||||||||||||||||||
| 1407 | 0 | $self->{key_type} = 'x509'; | |||||||||||||||||||||||||||||||||||||||||
| 1408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1409 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1410 | 0 | confess "did not get a new Crypt::OpenSSL::X509 object"; | |||||||||||||||||||||||||||||||||||||||||
| 1411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||||||||||||||||
| 1414 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1415 | ## _load_cert_file() | ||||||||||||||||||||||||||||||||||||||||||
| 1416 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1417 | ## Arguments: none | ||||||||||||||||||||||||||||||||||||||||||
| 1418 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1419 | ## Returns: nothing | ||||||||||||||||||||||||||||||||||||||||||
| 1420 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1421 | ## Read the file name from $self->{ cert } and | ||||||||||||||||||||||||||||||||||||||||||
| 1422 | ## Populate: | ||||||||||||||||||||||||||||||||||||||||||
| 1423 | ## self->{key_obj} | ||||||||||||||||||||||||||||||||||||||||||
| 1424 | ## $self->{KeyInfo} | ||||||||||||||||||||||||||||||||||||||||||
| 1425 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1426 | 90 | ▶ | sub _load_cert_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_cert_file: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 1427 | 90 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1428 | |||||||||||||||||||||||||||||||||||||||||||
| 1429 | 90 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 1430 | 90 | require Crypt::OpenSSL::X509; | |||||||||||||||||||||||||||||||||||||||||
| 1431 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1432 | |||||||||||||||||||||||||||||||||||||||||||
| 1433 | 90 | ▶ | confess "Crypt::OpenSSL::X509 needs to be installed so that we can handle X509 certs." if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1434 | |||||||||||||||||||||||||||||||||||||||||||
| 1435 | 90 | my $file = $self->{ cert }; | |||||||||||||||||||||||||||||||||||||||||
| 1436 | 90 | ▶ | if ( open my $CERT, '<', "$file" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1437 | 90 | my $text = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1438 | 90 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1439 | 90 | $text = <$CERT>; | |||||||||||||||||||||||||||||||||||||||||
| 1440 | 90 | close $CERT; | |||||||||||||||||||||||||||||||||||||||||
| 1441 | |||||||||||||||||||||||||||||||||||||||||||
| 1442 | 90 | my $cert = Crypt::OpenSSL::X509->new_from_string($text); | |||||||||||||||||||||||||||||||||||||||||
| 1443 | 90 | ▶ | if ( $cert ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1444 | 90 | $self->{ cert_obj } = $cert; | |||||||||||||||||||||||||||||||||||||||||
| 1445 | 90 | my $cert_text = $cert->as_string; | |||||||||||||||||||||||||||||||||||||||||
| 1446 | 90 | $cert_text =~ s/-----[^-]*-----//gm; | |||||||||||||||||||||||||||||||||||||||||
| 1447 | 90 | $self->{KeyInfo} = "<dsig:KeyInfo><dsig:X509Data><dsig:X509Certificate>\n"._trim($cert_text)."\n</dsig:X509Certificate></dsig:X509Data></dsig:KeyInfo>"; | |||||||||||||||||||||||||||||||||||||||||
| 1448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1449 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1450 | 0 | confess "Could not load certificate from $file"; | |||||||||||||||||||||||||||||||||||||||||
| 1451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1453 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1454 | 0 | confess "Could not find certificate file $file"; | |||||||||||||||||||||||||||||||||||||||||
| 1455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1456 | |||||||||||||||||||||||||||||||||||||||||||
| 1457 | 90 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1459 | |||||||||||||||||||||||||||||||||||||||||||
| 1460 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1461 | ## _load_cert_text() | ||||||||||||||||||||||||||||||||||||||||||
| 1462 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1463 | ## Arguments: none | ||||||||||||||||||||||||||||||||||||||||||
| 1464 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1465 | ## Returns: nothing | ||||||||||||||||||||||||||||||||||||||||||
| 1466 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1467 | ## Read the certificate from $self->{ cert_text } and | ||||||||||||||||||||||||||||||||||||||||||
| 1468 | ## Populate: | ||||||||||||||||||||||||||||||||||||||||||
| 1469 | ## self->{key_obj} | ||||||||||||||||||||||||||||||||||||||||||
| 1470 | ## $self->{KeyInfo} | ||||||||||||||||||||||||||||||||||||||||||
| 1471 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1472 | 4 | ▶ | sub _load_cert_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_cert_text: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1473 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1474 | |||||||||||||||||||||||||||||||||||||||||||
| 1475 | 4 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 1476 | 4 | require Crypt::OpenSSL::X509; | |||||||||||||||||||||||||||||||||||||||||
| 1477 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1478 | |||||||||||||||||||||||||||||||||||||||||||
| 1479 | 4 | ▶ | confess "Crypt::OpenSSL::X509 needs to be installed so that we can handle X509 certs." if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1480 | |||||||||||||||||||||||||||||||||||||||||||
| 1481 | 4 | my $text = $self->{ cert_text }; | |||||||||||||||||||||||||||||||||||||||||
| 1482 | 4 | my $cert = Crypt::OpenSSL::X509->new_from_string($text); | |||||||||||||||||||||||||||||||||||||||||
| 1483 | 4 | ▶ | if ( $cert ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1484 | 4 | $self->{ cert_obj } = $cert; | |||||||||||||||||||||||||||||||||||||||||
| 1485 | 4 | my $cert_text = $cert->as_string; | |||||||||||||||||||||||||||||||||||||||||
| 1486 | 4 | $cert_text =~ s/-----[^-]*-----//gm; | |||||||||||||||||||||||||||||||||||||||||
| 1487 | 4 | $self->{KeyInfo} = "<dsig:KeyInfo><dsig:X509Data><dsig:X509Certificate>\n"._trim($cert_text)."\n</dsig:X509Certificate></dsig:X509Data></dsig:KeyInfo>"; | |||||||||||||||||||||||||||||||||||||||||
| 1488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1489 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1490 | 0 | confess "Could not load certificate from given text."; | |||||||||||||||||||||||||||||||||||||||||
| 1491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1492 | |||||||||||||||||||||||||||||||||||||||||||
| 1493 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1495 | |||||||||||||||||||||||||||||||||||||||||||
| 1496 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1497 | ## _load_key($file) | ||||||||||||||||||||||||||||||||||||||||||
| 1498 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1499 | ## Arguments: $self->{ key } | ||||||||||||||||||||||||||||||||||||||||||
| 1500 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1501 | ## Returns: nothing | ||||||||||||||||||||||||||||||||||||||||||
| 1502 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1503 | ## Load the key and process it acording to its headers | ||||||||||||||||||||||||||||||||||||||||||
| 1504 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1505 | 203 | ▶ | sub _load_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_key: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 1506 | 203 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1507 | 203 | my $file = $self->{ key }; | |||||||||||||||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||||||||||||||||
| 1509 | 203 | ▶ | if ( open my $KEY, '<', "$file" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1510 | 202 | my $text = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1511 | 202 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1512 | 202 | $text = <$KEY>; | |||||||||||||||||||||||||||||||||||||||||
| 1513 | 202 | close $KEY; | |||||||||||||||||||||||||||||||||||||||||
| 1514 | |||||||||||||||||||||||||||||||||||||||||||
| 1515 | 202 | ▶ | if ( $text =~ m/BEGIN ([DR]SA) PRIVATE KEY/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1516 | 114 | my $key_used = $1; | |||||||||||||||||||||||||||||||||||||||||
| 1517 | |||||||||||||||||||||||||||||||||||||||||||
| 1518 | 114 | ▶ | if ( $key_used eq 'RSA' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1519 | 72 | $self->_load_rsa_key( $text ); | |||||||||||||||||||||||||||||||||||||||||
| 1520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1521 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1522 | 42 | $self->_load_dsa_key( $text ); | |||||||||||||||||||||||||||||||||||||||||
| 1523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1524 | } elsif ( $text =~ m/BEGIN EC PRIVATE KEY/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1525 | 85 | $self->_load_ecdsa_key( $text ); | |||||||||||||||||||||||||||||||||||||||||
| 1526 | } elsif ( $text =~ m/BEGIN PRIVATE KEY/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1527 | 2 | $self->_load_rsa_key( $text ); | |||||||||||||||||||||||||||||||||||||||||
| 1528 | } elsif ($text =~ m/BEGIN CERTIFICATE/) { | ||||||||||||||||||||||||||||||||||||||||||
| 1529 | 0 | $self->_load_x509_key( $text ); | |||||||||||||||||||||||||||||||||||||||||
| 1530 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1531 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1532 | 1 | confess "Could not detect type of key $file."; | |||||||||||||||||||||||||||||||||||||||||
| 1533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1535 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1536 | 1 | confess "Could not load key $file: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 1537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1538 | |||||||||||||||||||||||||||||||||||||||||||
| 1539 | 201 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1541 | |||||||||||||||||||||||||||||||||||||||||||
| 1542 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1543 | ## _signature_xml($signed_info,$signature_value) | ||||||||||||||||||||||||||||||||||||||||||
| 1544 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1545 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1546 | ## $signed_info: string XML String Fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1547 | ## $signature_value String Base64 Signature Value | ||||||||||||||||||||||||||||||||||||||||||
| 1548 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1549 | ## Returns: string XML fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1550 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1551 | ## Create a XML string of the Signature | ||||||||||||||||||||||||||||||||||||||||||
| 1552 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1553 | 224 | ▶ | sub _signature_xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_signature_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1554 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1555 | 224 | my ($signed_info,$signature_value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1556 | |||||||||||||||||||||||||||||||||||||||||||
| 1557 | 224 | return qq{<dsig:Signature xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> | |||||||||||||||||||||||||||||||||||||||||
| 1558 | $signed_info | ||||||||||||||||||||||||||||||||||||||||||
| 1559 | <dsig:SignatureValue>$signature_value</dsig:SignatureValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1560 | $self->{KeyInfo} | ||||||||||||||||||||||||||||||||||||||||||
| 1561 | </dsig:Signature>}; | ||||||||||||||||||||||||||||||||||||||||||
| 1562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | |||||||||||||||||||||||||||||||||||||||||||
| 1564 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1565 | ## _signedinfo_xml($digest_xml) | ||||||||||||||||||||||||||||||||||||||||||
| 1566 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1567 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1568 | ## $digest_xml string XML String Fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1569 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1570 | ## Returns: string XML fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1571 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1572 | ## Create a XML string of the SignedInfo | ||||||||||||||||||||||||||||||||||||||||||
| 1573 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1574 | 224 | ▶ | sub _signedinfo_xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_signedinfo_xml: called CC=10 SCAR=25.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1575 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1576 | 224 | my ($digest_xml) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1577 | |||||||||||||||||||||||||||||||||||||||||||
| 1578 | 224 | my $algorithm; | |||||||||||||||||||||||||||||||||||||||||
| 1579 | 224 | ▶ | if (! defined $self->{key_type} && defined $self->{ hmac_key } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $self->{"key_type"} and defined $self->{"hmac_key"}
MC/DC0%0/2
not defined $self->{"key_type"} and defined $self->{"hmac_key"}
not defined $self->{"key_type"}
defined $self->{"hmac_key"}
Truth table33%1/3
not(A) and B
A= not defined $self->{"key_type"}B= defined $self->{"hmac_key"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1580 | 0 | $self->{key_type} = 'hmac'; | |||||||||||||||||||||||||||||||||||||||||
| 1581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1582 | |||||||||||||||||||||||||||||||||||||||||||
| 1583 | 224 | ▶ | if ( $self->{ sig_hash } eq 'sha1' && $self->{key_type} ne 'ecdsa' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$self->{"sig_hash"} eq "sha1" and $self->{"key_type"} ne "ecdsa"
MC/DC50%1/2
$self->{"sig_hash"} eq "sha1" and $self->{"key_type"} ne "ecdsa"
$self->{"sig_hash"} eq "sha1"
$self->{"key_type"} ne "ecdsa"
Truth table66%2/3
A and B
A= $self->{"sig_hash"} eq "sha1"B= $self->{"key_type"} ne "ecdsa"
| |||||||||||||||||||||||||||||||||||||||||||
| 1584 | 23 | $algorithm = "http://www.w3.org/2000/09/xmldsig#$self->{key_type}-$self->{ sig_hash }"; | |||||||||||||||||||||||||||||||||||||||||
| 1585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1586 | elsif ( $self->{key_type} eq 'ecdsa' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1587 | 97 | ▶ | if ( $self->{ sig_hash } eq 'ripemd160' || $self->{ sig_hash } eq 'whirlpool' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"sig_hash"} eq "ripemd160" or $self->{"sig_hash"} eq "whirlpool"
MC/DC0%0/2
$self->{"sig_hash"} eq "ripemd160" or $self->{"sig_hash"} eq "whirlpool"
$self->{"sig_hash"} eq "ripemd160"
$self->{"sig_hash"} eq "whirlpool"
Truth table33%1/3
A or B
A= $self->{"sig_hash"} eq "ripemd160"B= $self->{"sig_hash"} eq "whirlpool"
| |||||||||||||||||||||||||||||||||||||||||||
| 1588 | 0 | $algorithm = "http://www.w3.org/2007/05/xmldsig-more#$self->{key_type}-$self->{ sig_hash }"; | |||||||||||||||||||||||||||||||||||||||||
| 1589 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1590 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1591 | 97 | $algorithm = "http://www.w3.org/2001/04/xmldsig-more#$self->{key_type}-$self->{ sig_hash }"; | |||||||||||||||||||||||||||||||||||||||||
| 1592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1594 | ▶ | elsif ( $self->{ key_type } eq 'dsa' && $self->{ sig_hash } eq 'sha256') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"key_type"} eq "dsa" and $self->{"sig_hash"} eq "sha256"
MC/DC50%1/2
$self->{"key_type"} eq "dsa" and $self->{"sig_hash"} eq "sha256"
$self->{"key_type"} eq "dsa"
$self->{"sig_hash"} eq "sha256"
Truth table66%2/3
A and B
A= $self->{"key_type"} eq "dsa"B= $self->{"sig_hash"} eq "sha256"
| |||||||||||||||||||||||||||||||||||||||||||
| 1595 | 20 | $algorithm = "http://www.w3.org/2009/xmldsig11#$self->{key_type}-$self->{ sig_hash }"; | |||||||||||||||||||||||||||||||||||||||||
| 1596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1597 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1598 | 84 | $algorithm = "http://www.w3.org/2001/04/xmldsig-more#$self->{key_type}-$self->{ sig_hash }"; | |||||||||||||||||||||||||||||||||||||||||
| 1599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1600 | |||||||||||||||||||||||||||||||||||||||||||
| 1601 | #return qq{<dsig:SignedInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> | ||||||||||||||||||||||||||||||||||||||||||
| 1602 | 224 | return qq{<dsig:SignedInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"> | |||||||||||||||||||||||||||||||||||||||||
| 1603 | <dsig:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> | ||||||||||||||||||||||||||||||||||||||||||
| 1604 | <dsig:SignatureMethod Algorithm="$algorithm" /> | ||||||||||||||||||||||||||||||||||||||||||
| 1605 | $digest_xml | ||||||||||||||||||||||||||||||||||||||||||
| 1606 | </dsig:SignedInfo>}; | ||||||||||||||||||||||||||||||||||||||||||
| 1607 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1608 | |||||||||||||||||||||||||||||||||||||||||||
| 1609 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1610 | ## _reference_xml($id) | ||||||||||||||||||||||||||||||||||||||||||
| 1611 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1612 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1613 | ## $id string XML ID related to the URI | ||||||||||||||||||||||||||||||||||||||||||
| 1614 | ## $digest string Base64 encoded digest | ||||||||||||||||||||||||||||||||||||||||||
| 1615 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1616 | ## Returns: string XML fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1617 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1618 | ## Create a XML string of the Reference | ||||||||||||||||||||||||||||||||||||||||||
| 1619 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1620 | 224 | ▶ | sub _reference_xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reference_xml: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1621 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1622 | 224 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1623 | 224 | my ($digest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1624 | |||||||||||||||||||||||||||||||||||||||||||
| 1625 | 224 | my $algorithm; | |||||||||||||||||||||||||||||||||||||||||
| 1626 | 224 | ▶ | if ( $self->{ digest_hash } eq 'sha1') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1627 | 1 | $algorithm = "http://www.w3.org/2000/09/xmldsig#$self->{ digest_hash }"; | |||||||||||||||||||||||||||||||||||||||||
| 1628 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1629 | ▶ | elsif (($self->{ digest_hash } eq 'sha224') || ($self->{ digest_hash } eq 'sha384')) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->{"digest_hash"} eq "sha224" or $self->{"digest_hash"} eq "sha384"
MC/DC100%2/2
$self->{"digest_hash"} eq "sha224" or $self->{"digest_hash"} eq "sha384"
$self->{"digest_hash"} eq "sha224"
$self->{"digest_hash"} eq "sha384"
Truth table100%3/3
A or B
A= $self->{"digest_hash"} eq "sha224"B= $self->{"digest_hash"} eq "sha384"
| |||||||||||||||||||||||||||||||||||||||||||
| 1630 | 54 | $algorithm = "http://www.w3.org/2001/04/xmldsig-more#$self->{ digest_hash }"; | |||||||||||||||||||||||||||||||||||||||||
| 1631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1632 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1633 | 169 | $algorithm = "http://www.w3.org/2001/04/xmlenc#$self->{ digest_hash }"; | |||||||||||||||||||||||||||||||||||||||||
| 1634 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1635 | |||||||||||||||||||||||||||||||||||||||||||
| 1636 | 224 | return qq{<dsig:Reference URI="#$id"> | |||||||||||||||||||||||||||||||||||||||||
| 1637 | <dsig:Transforms> | ||||||||||||||||||||||||||||||||||||||||||
| 1638 | <dsig:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /> | ||||||||||||||||||||||||||||||||||||||||||
| 1639 | <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1640 | </dsig:Transforms> | ||||||||||||||||||||||||||||||||||||||||||
| 1641 | <dsig:DigestMethod Algorithm="$algorithm" /> | ||||||||||||||||||||||||||||||||||||||||||
| 1642 | <dsig:DigestValue>$digest</dsig:DigestValue> | ||||||||||||||||||||||||||||||||||||||||||
| 1643 | </dsig:Reference>}; | ||||||||||||||||||||||||||||||||||||||||||
| 1644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1645 | |||||||||||||||||||||||||||||||||||||||||||
| 1646 | |||||||||||||||||||||||||||||||||||||||||||
| 1647 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1648 | ## _canonicalize_xml($xml, $context) | ||||||||||||||||||||||||||||||||||||||||||
| 1649 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1650 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1651 | ## $xml: string XML NodeSet | ||||||||||||||||||||||||||||||||||||||||||
| 1652 | ## $context: string XML Context | ||||||||||||||||||||||||||||||||||||||||||
| 1653 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1654 | ## Returns: string Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 1655 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1656 | ## Canonicalizes xml based on the CanonicalizationMethod | ||||||||||||||||||||||||||||||||||||||||||
| 1657 | ## from the SignedInfo. | ||||||||||||||||||||||||||||||||||||||||||
| 1658 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1659 | 458 | ▶ | sub _canonicalize_xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_canonicalize_xml: called CC=16 SCAR=37.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1660 | 458 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1661 | 458 | my ($xml, $context) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1662 | |||||||||||||||||||||||||||||||||||||||||||
| 1663 | 458 | ▶ | print ("_canonicalize_xml:\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1664 | my $canon_method = $self->{ parser }->findnodes( | ||||||||||||||||||||||||||||||||||||||||||
| 1665 | 458 | 'dsig:SignedInfo/dsig:CanonicalizationMethod', $context | |||||||||||||||||||||||||||||||||||||||||
| 1666 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1667 | |||||||||||||||||||||||||||||||||||||||||||
| 1668 | 458 | foreach my $node ($canon_method->get_nodelist) { | |||||||||||||||||||||||||||||||||||||||||
| 1669 | 458 | my $alg = $node->getAttribute('Algorithm'); | |||||||||||||||||||||||||||||||||||||||||
| 1670 | |||||||||||||||||||||||||||||||||||||||||||
| 1671 | 458 | ▶ | print (" Canon Method: $alg\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1672 | 458 | ▶ | if ($alg eq TRANSFORM_C14N) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1673 | 1 | ▶ | print (" toStringC14N\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1674 | 1 | $xml = $xml->toStringC14N(); | |||||||||||||||||||||||||||||||||||||||||
| 1675 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1676 | elsif ($alg eq TRANSFORM_C14N_COMMENTS) { | ||||||||||||||||||||||||||||||||||||||||||
| 1677 | 5 | ▶ | print (" toStringC14N_Comments\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1678 | 5 | $xml = $xml->toStringC14N(1); | |||||||||||||||||||||||||||||||||||||||||
| 1679 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1680 | elsif ($alg eq TRANSFORM_C14N_V1_1) { | ||||||||||||||||||||||||||||||||||||||||||
| 1681 | 0 | ▶ | print (" toStringC14N_v1_1\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1682 | 0 | $xml = $xml->toStringC14N_v1_1(); | |||||||||||||||||||||||||||||||||||||||||
| 1683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1684 | elsif ($alg eq TRANSFORM_C14N_V1_1_COMMENTS) { | ||||||||||||||||||||||||||||||||||||||||||
| 1685 | 0 | ▶ | print (" toStringC14N_v1_1_Comments\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1686 | 0 | $xml = $xml->toStringC14N_v1_1(1); | |||||||||||||||||||||||||||||||||||||||||
| 1687 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1688 | elsif ($alg eq TRANSFORM_EXC_C14N) { | ||||||||||||||||||||||||||||||||||||||||||
| 1689 | 452 | ▶ | print (" toStringEC14N\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1690 | 452 | $xml = $xml->toStringEC14N(); | |||||||||||||||||||||||||||||||||||||||||
| 1691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1692 | elsif ($alg eq TRANSFORM_EXC_C14N_COMMENTS) { | ||||||||||||||||||||||||||||||||||||||||||
| 1693 | 0 | ▶ | print (" toStringEC14N_Comments\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1694 | 0 | $xml = $xml->toStringEC14N(1); | |||||||||||||||||||||||||||||||||||||||||
| 1695 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1696 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1697 | 0 | die "Unsupported transform: $alg"; | |||||||||||||||||||||||||||||||||||||||||
| 1698 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1699 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1700 | 458 | return $xml; | |||||||||||||||||||||||||||||||||||||||||
| 1701 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1702 | |||||||||||||||||||||||||||||||||||||||||||
| 1703 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1704 | ## _calc_dsa_signature($signed_info_canon) | ||||||||||||||||||||||||||||||||||||||||||
| 1705 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1706 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1707 | ## $canonical: string Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 1708 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1709 | ## Returns: string Signature | ||||||||||||||||||||||||||||||||||||||||||
| 1710 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1711 | ## Calculates signature based on the method and hash | ||||||||||||||||||||||||||||||||||||||||||
| 1712 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1713 | 43 | ▶ | sub _calc_dsa_signature { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calc_dsa_signature: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1714 | 43 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1715 | 43 | my $signed_info_canon = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1716 | |||||||||||||||||||||||||||||||||||||||||||
| 1717 | 43 | ▶ | print (" Signing SignedInfo using DSA key type\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1718 | 43 | $self->{sig_method} = _hash_function($self->{ sig_hash }); | |||||||||||||||||||||||||||||||||||||||||
| 1719 | |||||||||||||||||||||||||||||||||||||||||||
| 1720 | # DSA 1024-bit only permits the signing of 20 bytes or less, hence the sha1 | ||||||||||||||||||||||||||||||||||||||||||
| 1721 | # DSA 2048-bit only permits the signing sha256 | ||||||||||||||||||||||||||||||||||||||||||
| 1722 | my $bin_signature = $self->{key_obj}->do_sign( | ||||||||||||||||||||||||||||||||||||||||||
| 1723 | 43 | $self->{ sig_method }(encode_utf8($signed_info_canon)) ); | |||||||||||||||||||||||||||||||||||||||||
| 1724 | |||||||||||||||||||||||||||||||||||||||||||
| 1725 | # https://www.w3.org/TR/2002/REC-xmldsig-core-20020212/#sec-SignatureAlg | ||||||||||||||||||||||||||||||||||||||||||
| 1726 | # The output of the DSA algorithm consists of a pair of integers | ||||||||||||||||||||||||||||||||||||||||||
| 1727 | # The signature value consists of the base64 encoding of the | ||||||||||||||||||||||||||||||||||||||||||
| 1728 | # concatenation of r and s in that order ($r . $s) | ||||||||||||||||||||||||||||||||||||||||||
| 1729 | 43 | my $r = $bin_signature->get_r; | |||||||||||||||||||||||||||||||||||||||||
| 1730 | 43 | my $s = $bin_signature->get_s; | |||||||||||||||||||||||||||||||||||||||||
| 1731 | |||||||||||||||||||||||||||||||||||||||||||
| 1732 | 43 | my $sig_size = ($self->{key_obj}->get_sig_size - 8) * 8; | |||||||||||||||||||||||||||||||||||||||||
| 1733 | 43 | my $rs = _zero_fill_buffer($sig_size); | |||||||||||||||||||||||||||||||||||||||||
| 1734 | 43 | _concat_dsa_sig_r_s(\$rs, $r, $s, $sig_size); | |||||||||||||||||||||||||||||||||||||||||
| 1735 | |||||||||||||||||||||||||||||||||||||||||||
| 1736 | 43 | return $rs; | |||||||||||||||||||||||||||||||||||||||||
| 1737 | |||||||||||||||||||||||||||||||||||||||||||
| 1738 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1739 | |||||||||||||||||||||||||||||||||||||||||||
| 1740 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1741 | ## _calc_ecdsa_signature($signed_info_canon) | ||||||||||||||||||||||||||||||||||||||||||
| 1742 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1743 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1744 | ## $canonical: string Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 1745 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1746 | ## Returns: string Signature | ||||||||||||||||||||||||||||||||||||||||||
| 1747 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1748 | ## Calculates signature based on the method and hash | ||||||||||||||||||||||||||||||||||||||||||
| 1749 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1750 | 97 | ▶ | sub _calc_ecdsa_signature { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calc_ecdsa_signature: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1751 | 97 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1752 | 97 | my $signed_info_canon = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1753 | |||||||||||||||||||||||||||||||||||||||||||
| 1754 | 97 | ▶ | print (" Signing SignedInfo using ECDSA key type\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1755 | |||||||||||||||||||||||||||||||||||||||||||
| 1756 | my $bin_signature = $self->{key_obj}->sign_message_rfc7518( | ||||||||||||||||||||||||||||||||||||||||||
| 1757 | encode_utf8($signed_info_canon), uc($self->{sig_hash}) | ||||||||||||||||||||||||||||||||||||||||||
| 1758 | 97 | ); | |||||||||||||||||||||||||||||||||||||||||
| 1759 | # The output of the ECDSA algorithm consists of a pair of integers | ||||||||||||||||||||||||||||||||||||||||||
| 1760 | # The signature value consists of the base64 encoding of the | ||||||||||||||||||||||||||||||||||||||||||
| 1761 | # concatenation of r and s in that order ($r . $s). In this | ||||||||||||||||||||||||||||||||||||||||||
| 1762 | # case sign_message_rfc7518 produces that | ||||||||||||||||||||||||||||||||||||||||||
| 1763 | 97 | return $bin_signature; | |||||||||||||||||||||||||||||||||||||||||
| 1764 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1765 | |||||||||||||||||||||||||||||||||||||||||||
| 1766 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1767 | ## _calc_rsa_signature($signed_info_canon) | ||||||||||||||||||||||||||||||||||||||||||
| 1768 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1769 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1770 | ## $canonical: string Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 1771 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1772 | ## Returns: string Signature | ||||||||||||||||||||||||||||||||||||||||||
| 1773 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1774 | ## Calculates signature based on the method and hash | ||||||||||||||||||||||||||||||||||||||||||
| 1775 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1776 | 73 | ▶ | sub _calc_rsa_signature { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calc_rsa_signature: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1777 | 73 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1778 | 73 | my $signed_info_canon = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1779 | |||||||||||||||||||||||||||||||||||||||||||
| 1780 | 73 | ▶ | print (" Signing SignedInfo using RSA key type\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1781 | my $bin_signature = $self->{key_obj}->sign_message( | ||||||||||||||||||||||||||||||||||||||||||
| 1782 | 73 | encode_utf8($signed_info_canon), $self->{sig_hash}, 'v1.5' ); | |||||||||||||||||||||||||||||||||||||||||
| 1783 | |||||||||||||||||||||||||||||||||||||||||||
| 1784 | 73 | return $bin_signature; | |||||||||||||||||||||||||||||||||||||||||
| 1785 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1786 | |||||||||||||||||||||||||||||||||||||||||||
| 1787 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1788 | ## _calc_hmac_signature($signed_info_canon) | ||||||||||||||||||||||||||||||||||||||||||
| 1789 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1790 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1791 | ## $signed_info_canon: string Canonical XML | ||||||||||||||||||||||||||||||||||||||||||
| 1792 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1793 | ## Returns: string Signature | ||||||||||||||||||||||||||||||||||||||||||
| 1794 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1795 | ## Calculates signature based on the method and hash | ||||||||||||||||||||||||||||||||||||||||||
| 1796 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1797 | 24 | ▶ | sub _calc_hmac_signature { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calc_hmac_signature: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 1798 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1799 | 24 | my $signed_info_canon = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1800 | |||||||||||||||||||||||||||||||||||||||||||
| 1801 | 32 | ▶ | use Crypt::Mac::HMAC qw( hmac ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1802 | 24 | my $bin_signature; | |||||||||||||||||||||||||||||||||||||||||
| 1803 | 24 | ▶ | print (" Signing SignedInfo using hmac-", $self->{ sig_hash }, "\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1804 | 24 | ▶ | my $hash = defined $self->{ sig_hash } ? $self->{ sig_hash } : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1805 | 24 | ▶ | if (exists $HMAC_FUNCTION{$hash}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1806 | $bin_signature = $HMAC_FUNCTION{$hash}->( | ||||||||||||||||||||||||||||||||||||||||||
| 1807 | encode_utf8($signed_info_canon), | ||||||||||||||||||||||||||||||||||||||||||
| 1808 | decode_base64( $self->{ hmac_key } ) | ||||||||||||||||||||||||||||||||||||||||||
| 1809 | 23 | ); | |||||||||||||||||||||||||||||||||||||||||
| 1810 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1811 | elsif ( $hash eq 'ripemd160' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1812 | 0 | $bin_signature = hmac('RIPEMD160', decode_base64( $self->{ hmac_key } ), $signed_info_canon ); | |||||||||||||||||||||||||||||||||||||||||
| 1813 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1814 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1815 | 1 | die("XML::Sig - unsupported hash algorithm\n"); | |||||||||||||||||||||||||||||||||||||||||
| 1816 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1817 | |||||||||||||||||||||||||||||||||||||||||||
| 1818 | 23 | return $bin_signature; | |||||||||||||||||||||||||||||||||||||||||
| 1819 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1820 | |||||||||||||||||||||||||||||||||||||||||||
| 1821 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1822 | ## _load_xml($xml) | ||||||||||||||||||||||||||||||||||||||||||
| 1823 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1824 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 1825 | ## $xml: string XML | ||||||||||||||||||||||||||||||||||||||||||
| 1826 | ## $func: string name of calling function | ||||||||||||||||||||||||||||||||||||||||||
| 1827 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1828 | ## Returns: string Signature | ||||||||||||||||||||||||||||||||||||||||||
| 1829 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1830 | ## Load the XML using XML::LibXML::parser() | ||||||||||||||||||||||||||||||||||||||||||
| 1831 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 1832 | 719 | ▶ | sub _load_xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1833 | 719 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1834 | 719 | my $xml = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1835 | |||||||||||||||||||||||||||||||||||||||||||
| 1836 | 719 | my ($package, $filename, $line) = caller; | |||||||||||||||||||||||||||||||||||||||||
| 1837 | my $dom = try | ||||||||||||||||||||||||||||||||||||||||||
| 1838 | 719 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1839 | 719 | XML::LibXML->load_xml( string => $xml ); | |||||||||||||||||||||||||||||||||||||||||
| 1840 | 6 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1841 | 6 | croak 'XML::Sig: line ' , $line , ' unable to parse xml with XML::LibXML'; | |||||||||||||||||||||||||||||||||||||||||
| 1842 | 719 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1843 | 713 | return $dom; | |||||||||||||||||||||||||||||||||||||||||
| 1844 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1845 | 32 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1846 | |||||||||||||||||||||||||||||||||||||||||||
| 1847 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 1848 | |||||||||||||||||||||||||||||||||||||||||||
| 1849 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 1850 | |||||||||||||||||||||||||||||||||||||||||||
| 1851 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 1852 | |||||||||||||||||||||||||||||||||||||||||||
| 1853 | XML::Sig - XML::Sig - A toolkit to help sign and verify XML Digital Signatures | ||||||||||||||||||||||||||||||||||||||||||
| 1854 | |||||||||||||||||||||||||||||||||||||||||||
| 1855 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 1856 | |||||||||||||||||||||||||||||||||||||||||||
| 1857 | version 0.74 | ||||||||||||||||||||||||||||||||||||||||||
| 1858 | |||||||||||||||||||||||||||||||||||||||||||
| 1859 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 1860 | |||||||||||||||||||||||||||||||||||||||||||
| 1861 | my $xml = '<foo ID="abc">123</foo>'; | ||||||||||||||||||||||||||||||||||||||||||
| 1862 | my $signer = XML::Sig->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 1863 | key => 'path/to/private.key', | ||||||||||||||||||||||||||||||||||||||||||
| 1864 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1865 | |||||||||||||||||||||||||||||||||||||||||||
| 1866 | # create a signature | ||||||||||||||||||||||||||||||||||||||||||
| 1867 | my $signed = $signer->sign($xml); | ||||||||||||||||||||||||||||||||||||||||||
| 1868 | print "Signed XML: $signed\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1869 | |||||||||||||||||||||||||||||||||||||||||||
| 1870 | # verify a signature | ||||||||||||||||||||||||||||||||||||||||||
| 1871 | $signer->verify($signed) | ||||||||||||||||||||||||||||||||||||||||||
| 1872 | or die "Signature Invalid."; | ||||||||||||||||||||||||||||||||||||||||||
| 1873 | print "Signature valid.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1874 | |||||||||||||||||||||||||||||||||||||||||||
| 1875 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 1876 | |||||||||||||||||||||||||||||||||||||||||||
| 1877 | This perl module provides two primary capabilities: given an XML string, create | ||||||||||||||||||||||||||||||||||||||||||
| 1878 | and insert digital signatures, or if one is already present in the string verify | ||||||||||||||||||||||||||||||||||||||||||
| 1879 | it -- all in accordance with the W3C standard governing XML signatures. | ||||||||||||||||||||||||||||||||||||||||||
| 1880 | |||||||||||||||||||||||||||||||||||||||||||
| 1881 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 1882 | |||||||||||||||||||||||||||||||||||||||||||
| 1883 | XML::Sig - A toolkit to help sign and verify XML Digital Signatures. | ||||||||||||||||||||||||||||||||||||||||||
| 1884 | |||||||||||||||||||||||||||||||||||||||||||
| 1885 | =head1 PREREQUISITES | ||||||||||||||||||||||||||||||||||||||||||
| 1886 | |||||||||||||||||||||||||||||||||||||||||||
| 1887 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 1888 | |||||||||||||||||||||||||||||||||||||||||||
| 1889 | =item * L<Digest::SHA> | ||||||||||||||||||||||||||||||||||||||||||
| 1890 | |||||||||||||||||||||||||||||||||||||||||||
| 1891 | =item * L<XML::LibXML> | ||||||||||||||||||||||||||||||||||||||||||
| 1892 | |||||||||||||||||||||||||||||||||||||||||||
| 1893 | =item * L<MIME::Base64> | ||||||||||||||||||||||||||||||||||||||||||
| 1894 | |||||||||||||||||||||||||||||||||||||||||||
| 1895 | =item * L<Crypt::OpenSSL::X509> | ||||||||||||||||||||||||||||||||||||||||||
| 1896 | |||||||||||||||||||||||||||||||||||||||||||
| 1897 | =item * L<Crypt::OpenSSL::Bignum> | ||||||||||||||||||||||||||||||||||||||||||
| 1898 | |||||||||||||||||||||||||||||||||||||||||||
| 1899 | =item * L<Crypt::PK::RSA> | ||||||||||||||||||||||||||||||||||||||||||
| 1900 | |||||||||||||||||||||||||||||||||||||||||||
| 1901 | =item * L<Crypt::OpenSSL::DSA> (>= 0.20 Optional - required for DSA signatures) | ||||||||||||||||||||||||||||||||||||||||||
| 1902 | |||||||||||||||||||||||||||||||||||||||||||
| 1903 | =item * L<Crypt::PK::ECC> | ||||||||||||||||||||||||||||||||||||||||||
| 1904 | |||||||||||||||||||||||||||||||||||||||||||
| 1905 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1906 | |||||||||||||||||||||||||||||||||||||||||||
| 1907 | =head1 USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 1908 | |||||||||||||||||||||||||||||||||||||||||||
| 1909 | =head2 SUPPORTED ALGORITHMS & TRANSFORMS | ||||||||||||||||||||||||||||||||||||||||||
| 1910 | |||||||||||||||||||||||||||||||||||||||||||
| 1911 | This module supports the following signature methods: | ||||||||||||||||||||||||||||||||||||||||||
| 1912 | |||||||||||||||||||||||||||||||||||||||||||
| 1913 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 1914 | |||||||||||||||||||||||||||||||||||||||||||
| 1915 | =item * DSA | ||||||||||||||||||||||||||||||||||||||||||
| 1916 | |||||||||||||||||||||||||||||||||||||||||||
| 1917 | =item * RSA | ||||||||||||||||||||||||||||||||||||||||||
| 1918 | |||||||||||||||||||||||||||||||||||||||||||
| 1919 | =item * RSA encoded as x509 | ||||||||||||||||||||||||||||||||||||||||||
| 1920 | |||||||||||||||||||||||||||||||||||||||||||
| 1921 | =item * ECDSA | ||||||||||||||||||||||||||||||||||||||||||
| 1922 | |||||||||||||||||||||||||||||||||||||||||||
| 1923 | =item * ECDSA encoded as x509 | ||||||||||||||||||||||||||||||||||||||||||
| 1924 | |||||||||||||||||||||||||||||||||||||||||||
| 1925 | =item * HMAC | ||||||||||||||||||||||||||||||||||||||||||
| 1926 | |||||||||||||||||||||||||||||||||||||||||||
| 1927 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1928 | |||||||||||||||||||||||||||||||||||||||||||
| 1929 | This module supports the following canonicalization methods and transforms: | ||||||||||||||||||||||||||||||||||||||||||
| 1930 | |||||||||||||||||||||||||||||||||||||||||||
| 1931 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 1932 | |||||||||||||||||||||||||||||||||||||||||||
| 1933 | =item * Enveloped Signature | ||||||||||||||||||||||||||||||||||||||||||
| 1934 | |||||||||||||||||||||||||||||||||||||||||||
| 1935 | =item * REC-xml-c14n-20010315# | ||||||||||||||||||||||||||||||||||||||||||
| 1936 | |||||||||||||||||||||||||||||||||||||||||||
| 1937 | =item * REC-xml-c14n-20010315#WithComments | ||||||||||||||||||||||||||||||||||||||||||
| 1938 | |||||||||||||||||||||||||||||||||||||||||||
| 1939 | =item * REC-xml-c14n11-20080502 | ||||||||||||||||||||||||||||||||||||||||||
| 1940 | |||||||||||||||||||||||||||||||||||||||||||
| 1941 | =item * REC-xml-c14n11-20080502#WithComments | ||||||||||||||||||||||||||||||||||||||||||
| 1942 | |||||||||||||||||||||||||||||||||||||||||||
| 1943 | =item * xml-exc-c14n# | ||||||||||||||||||||||||||||||||||||||||||
| 1944 | |||||||||||||||||||||||||||||||||||||||||||
| 1945 | =item * xml-exc-c14n#WithComments | ||||||||||||||||||||||||||||||||||||||||||
| 1946 | |||||||||||||||||||||||||||||||||||||||||||
| 1947 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1948 | |||||||||||||||||||||||||||||||||||||||||||
| 1949 | =head2 OPTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 1950 | |||||||||||||||||||||||||||||||||||||||||||
| 1951 | Each of the following options are also accessors on the main | ||||||||||||||||||||||||||||||||||||||||||
| 1952 | XML::Sig object. TODO Not strictly correct rewrite | ||||||||||||||||||||||||||||||||||||||||||
| 1953 | |||||||||||||||||||||||||||||||||||||||||||
| 1954 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 1955 | |||||||||||||||||||||||||||||||||||||||||||
| 1956 | =item B<key> | ||||||||||||||||||||||||||||||||||||||||||
| 1957 | |||||||||||||||||||||||||||||||||||||||||||
| 1958 | The path to a file containing the contents of a private key. This option | ||||||||||||||||||||||||||||||||||||||||||
| 1959 | is used only when generating signatures. | ||||||||||||||||||||||||||||||||||||||||||
| 1960 | |||||||||||||||||||||||||||||||||||||||||||
| 1961 | =item B<cert> | ||||||||||||||||||||||||||||||||||||||||||
| 1962 | |||||||||||||||||||||||||||||||||||||||||||
| 1963 | The path to a file containing a PEM-formatted X509 certificate. This | ||||||||||||||||||||||||||||||||||||||||||
| 1964 | option is used only when generating signatures with the "x509" | ||||||||||||||||||||||||||||||||||||||||||
| 1965 | option. This certificate will be embedded in the signed document, and | ||||||||||||||||||||||||||||||||||||||||||
| 1966 | should match the private key used for the signature. | ||||||||||||||||||||||||||||||||||||||||||
| 1967 | |||||||||||||||||||||||||||||||||||||||||||
| 1968 | =item B<cert_text> | ||||||||||||||||||||||||||||||||||||||||||
| 1969 | |||||||||||||||||||||||||||||||||||||||||||
| 1970 | A string containing a PEM-formatted X509 certificate. This | ||||||||||||||||||||||||||||||||||||||||||
| 1971 | option is used only when generating signatures with the "x509" | ||||||||||||||||||||||||||||||||||||||||||
| 1972 | option. This certificate will be embedded in the signed document, and | ||||||||||||||||||||||||||||||||||||||||||
| 1973 | should match the private key used for the signature. | ||||||||||||||||||||||||||||||||||||||||||
| 1974 | |||||||||||||||||||||||||||||||||||||||||||
| 1975 | =item B<x509> | ||||||||||||||||||||||||||||||||||||||||||
| 1976 | |||||||||||||||||||||||||||||||||||||||||||
| 1977 | Takes a true (1) or false (0) value and indicates how you want the | ||||||||||||||||||||||||||||||||||||||||||
| 1978 | signature to be encoded. When true, the X509 certificate supplied will | ||||||||||||||||||||||||||||||||||||||||||
| 1979 | be encoded in the signature. Otherwise the native encoding format for | ||||||||||||||||||||||||||||||||||||||||||
| 1980 | RSA, DSA and ECDSA will be used. | ||||||||||||||||||||||||||||||||||||||||||
| 1981 | |||||||||||||||||||||||||||||||||||||||||||
| 1982 | =item B<sig_hash> | ||||||||||||||||||||||||||||||||||||||||||
| 1983 | |||||||||||||||||||||||||||||||||||||||||||
| 1984 | Passing sig_hash to new allows you to specify the SignatureMethod | ||||||||||||||||||||||||||||||||||||||||||
| 1985 | hashing algorithm used when signing the SignedInfo. RSA and ECDSA | ||||||||||||||||||||||||||||||||||||||||||
| 1986 | supports the hashes specified sha1, sha224, sha256, sha384 and sha512 | ||||||||||||||||||||||||||||||||||||||||||
| 1987 | |||||||||||||||||||||||||||||||||||||||||||
| 1988 | DSA supports only sha1 and sha256 (but you really should not sign | ||||||||||||||||||||||||||||||||||||||||||
| 1989 | anything with DSA anyway). This is over-ridden by the key's signature | ||||||||||||||||||||||||||||||||||||||||||
| 1990 | size which is related to the key size. 1024-bit keys require sha1, | ||||||||||||||||||||||||||||||||||||||||||
| 1991 | 2048-bit and 3072-bit keys require sha256. | ||||||||||||||||||||||||||||||||||||||||||
| 1992 | |||||||||||||||||||||||||||||||||||||||||||
| 1993 | =item B<digest_hash> | ||||||||||||||||||||||||||||||||||||||||||
| 1994 | |||||||||||||||||||||||||||||||||||||||||||
| 1995 | Passing digest_hash to new allows you to specify the DigestMethod | ||||||||||||||||||||||||||||||||||||||||||
| 1996 | hashing algorithm used when calculating the hash of the XML being | ||||||||||||||||||||||||||||||||||||||||||
| 1997 | signed. Supported hashes can be specified sha1, sha224, sha256, | ||||||||||||||||||||||||||||||||||||||||||
| 1998 | sha384, sha512, ripemd160 | ||||||||||||||||||||||||||||||||||||||||||
| 1999 | |||||||||||||||||||||||||||||||||||||||||||
| 2000 | =item B<hmac_key> | ||||||||||||||||||||||||||||||||||||||||||
| 2001 | |||||||||||||||||||||||||||||||||||||||||||
| 2002 | Base64 encoded hmac_key | ||||||||||||||||||||||||||||||||||||||||||
| 2003 | |||||||||||||||||||||||||||||||||||||||||||
| 2004 | =item B<key_name> | ||||||||||||||||||||||||||||||||||||||||||
| 2005 | |||||||||||||||||||||||||||||||||||||||||||
| 2006 | The name of the key that should be referenced. In the case of | ||||||||||||||||||||||||||||||||||||||||||
| 2007 | xmlsec the --keys-file (ex. t/xmlsec-keys.xml) holds keys with a | ||||||||||||||||||||||||||||||||||||||||||
| 2008 | KeyName that is referenced by this name. | ||||||||||||||||||||||||||||||||||||||||||
| 2009 | |||||||||||||||||||||||||||||||||||||||||||
| 2010 | =item B<no_xml_declaration> | ||||||||||||||||||||||||||||||||||||||||||
| 2011 | |||||||||||||||||||||||||||||||||||||||||||
| 2012 | Some applications such as Net::SAML2 expect to sign a fragment of the | ||||||||||||||||||||||||||||||||||||||||||
| 2013 | full XML document so is this is true (1) it will not include the | ||||||||||||||||||||||||||||||||||||||||||
| 2014 | XML Declaration at the beginning of the signed XML. False (0) or | ||||||||||||||||||||||||||||||||||||||||||
| 2015 | undefined returns an XML document starting with the XML Declaration. | ||||||||||||||||||||||||||||||||||||||||||
| 2016 | |||||||||||||||||||||||||||||||||||||||||||
| 2017 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2018 | |||||||||||||||||||||||||||||||||||||||||||
| 2019 | The following options act similar to C<< xmlsec --id-attr:ID | ||||||||||||||||||||||||||||||||||||||||||
| 2020 | <node-namespace-uri>:<name> >> | ||||||||||||||||||||||||||||||||||||||||||
| 2021 | |||||||||||||||||||||||||||||||||||||||||||
| 2022 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 2023 | |||||||||||||||||||||||||||||||||||||||||||
| 2024 | =item B<ns> | ||||||||||||||||||||||||||||||||||||||||||
| 2025 | |||||||||||||||||||||||||||||||||||||||||||
| 2026 | A HashRef to namespaces you want to define to select the correct attribute ID on | ||||||||||||||||||||||||||||||||||||||||||
| 2027 | |||||||||||||||||||||||||||||||||||||||||||
| 2028 | =item B<id_attr> | ||||||||||||||||||||||||||||||||||||||||||
| 2029 | |||||||||||||||||||||||||||||||||||||||||||
| 2030 | The xpath string you want to sign your XML message on. | ||||||||||||||||||||||||||||||||||||||||||
| 2031 | |||||||||||||||||||||||||||||||||||||||||||
| 2032 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2033 | |||||||||||||||||||||||||||||||||||||||||||
| 2034 | =head2 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 2035 | |||||||||||||||||||||||||||||||||||||||||||
| 2036 | =head3 B<new(...)> | ||||||||||||||||||||||||||||||||||||||||||
| 2037 | |||||||||||||||||||||||||||||||||||||||||||
| 2038 | Constructor; see OPTIONS above. | ||||||||||||||||||||||||||||||||||||||||||
| 2039 | |||||||||||||||||||||||||||||||||||||||||||
| 2040 | =head3 B<sign($xml)> | ||||||||||||||||||||||||||||||||||||||||||
| 2041 | |||||||||||||||||||||||||||||||||||||||||||
| 2042 | When given a string of XML, it will return the same string with a signature | ||||||||||||||||||||||||||||||||||||||||||
| 2043 | generated from the key provided when the XML::Sig object was initialized. | ||||||||||||||||||||||||||||||||||||||||||
| 2044 | |||||||||||||||||||||||||||||||||||||||||||
| 2045 | This method will sign all elements in your XML with an ID (case sensitive) | ||||||||||||||||||||||||||||||||||||||||||
| 2046 | attribute. Each element with an ID attribute will be the basis for a seperate | ||||||||||||||||||||||||||||||||||||||||||
| 2047 | signature. It will correspond to the URI attribute in the Reference element | ||||||||||||||||||||||||||||||||||||||||||
| 2048 | that will be contained by the signature. If no ID attribute can be found on | ||||||||||||||||||||||||||||||||||||||||||
| 2049 | an element, the signature will not be created. | ||||||||||||||||||||||||||||||||||||||||||
| 2050 | |||||||||||||||||||||||||||||||||||||||||||
| 2051 | The elements are signed in reverse order currently assuming (possibly | ||||||||||||||||||||||||||||||||||||||||||
| 2052 | incorrectly) that the lower element in the tree may need to be signed | ||||||||||||||||||||||||||||||||||||||||||
| 2053 | inclusive of its Signature because it is a child of the higher element. | ||||||||||||||||||||||||||||||||||||||||||
| 2054 | |||||||||||||||||||||||||||||||||||||||||||
| 2055 | Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 2056 | $xml: string XML string | ||||||||||||||||||||||||||||||||||||||||||
| 2057 | |||||||||||||||||||||||||||||||||||||||||||
| 2058 | Returns: string Signed XML | ||||||||||||||||||||||||||||||||||||||||||
| 2059 | |||||||||||||||||||||||||||||||||||||||||||
| 2060 | =head3 B<verify($xml)> | ||||||||||||||||||||||||||||||||||||||||||
| 2061 | |||||||||||||||||||||||||||||||||||||||||||
| 2062 | Returns true or false based upon whether the signature is valid or not. | ||||||||||||||||||||||||||||||||||||||||||
| 2063 | |||||||||||||||||||||||||||||||||||||||||||
| 2064 | When using XML::Sig exclusively to verify a signature, no key needs to be | ||||||||||||||||||||||||||||||||||||||||||
| 2065 | specified during initialization given that the public key should be | ||||||||||||||||||||||||||||||||||||||||||
| 2066 | transmitted with the signature. | ||||||||||||||||||||||||||||||||||||||||||
| 2067 | |||||||||||||||||||||||||||||||||||||||||||
| 2068 | XML::Sig checks all signature in the provided xml and will fail should any | ||||||||||||||||||||||||||||||||||||||||||
| 2069 | signature pointing to an existing ID in the XML fail to verify. | ||||||||||||||||||||||||||||||||||||||||||
| 2070 | |||||||||||||||||||||||||||||||||||||||||||
| 2071 | Should there be a Signature included that does not point to an existing node | ||||||||||||||||||||||||||||||||||||||||||
| 2072 | in the XML it is ignored and other Signaures are checked. If there are no | ||||||||||||||||||||||||||||||||||||||||||
| 2073 | other Signatures it will return false. | ||||||||||||||||||||||||||||||||||||||||||
| 2074 | |||||||||||||||||||||||||||||||||||||||||||
| 2075 | Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 2076 | $xml: string XML string | ||||||||||||||||||||||||||||||||||||||||||
| 2077 | |||||||||||||||||||||||||||||||||||||||||||
| 2078 | Returns: string Signed XML | ||||||||||||||||||||||||||||||||||||||||||
| 2079 | |||||||||||||||||||||||||||||||||||||||||||
| 2080 | =head3 B<signer_cert()> | ||||||||||||||||||||||||||||||||||||||||||
| 2081 | |||||||||||||||||||||||||||||||||||||||||||
| 2082 | Following a successful verify with an X509 certificate, returns the | ||||||||||||||||||||||||||||||||||||||||||
| 2083 | signer's certificate as embedded in the XML document for verification | ||||||||||||||||||||||||||||||||||||||||||
| 2084 | against a CA certificate. The certificate is returned as a | ||||||||||||||||||||||||||||||||||||||||||
| 2085 | Crypt::OpenSSL::X509 object. | ||||||||||||||||||||||||||||||||||||||||||
| 2086 | |||||||||||||||||||||||||||||||||||||||||||
| 2087 | Arguments: none | ||||||||||||||||||||||||||||||||||||||||||
| 2088 | |||||||||||||||||||||||||||||||||||||||||||
| 2089 | Returns: Crypt::OpenSSL::X509: Certificate used to sign the XML | ||||||||||||||||||||||||||||||||||||||||||
| 2090 | |||||||||||||||||||||||||||||||||||||||||||
| 2091 | =head3 B<verified_ids()> | ||||||||||||||||||||||||||||||||||||||||||
| 2092 | |||||||||||||||||||||||||||||||||||||||||||
| 2093 | Following a successful verify, returns an ARRAY reference of the ID | ||||||||||||||||||||||||||||||||||||||||||
| 2094 | attribute values that were covered by a verified signature - that is, the | ||||||||||||||||||||||||||||||||||||||||||
| 2095 | Reference URIs whose digests were checked and matched. | ||||||||||||||||||||||||||||||||||||||||||
| 2096 | |||||||||||||||||||||||||||||||||||||||||||
| 2097 | Callers that extract a specific element from a verified document (for | ||||||||||||||||||||||||||||||||||||||||||
| 2098 | example C<//saml:Assertion>) should confirm that the element's ID appears | ||||||||||||||||||||||||||||||||||||||||||
| 2099 | in this list. Without that check the element acted on may not be the | ||||||||||||||||||||||||||||||||||||||||||
| 2100 | element that was signed, which is the basis of the XML Signature Wrapping | ||||||||||||||||||||||||||||||||||||||||||
| 2101 | (XSW) attack class. | ||||||||||||||||||||||||||||||||||||||||||
| 2102 | |||||||||||||||||||||||||||||||||||||||||||
| 2103 | if ($sig->verify($xml)) { | ||||||||||||||||||||||||||||||||||||||||||
| 2104 | my %signed = map { $_ => 1 } @{ $sig->verified_ids }; | ||||||||||||||||||||||||||||||||||||||||||
| 2105 | die "element was not signed" | ||||||||||||||||||||||||||||||||||||||||||
| 2106 | unless $signed{ $element->getAttribute('ID') }; | ||||||||||||||||||||||||||||||||||||||||||
| 2107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2108 | |||||||||||||||||||||||||||||||||||||||||||
| 2109 | Arguments: none | ||||||||||||||||||||||||||||||||||||||||||
| 2110 | |||||||||||||||||||||||||||||||||||||||||||
| 2111 | Returns: ARRAY reference of ID strings. Empty after a failed verify or | ||||||||||||||||||||||||||||||||||||||||||
| 2112 | before verify is called. | ||||||||||||||||||||||||||||||||||||||||||
| 2113 | |||||||||||||||||||||||||||||||||||||||||||
| 2114 | =head3 B<verified_elements()> | ||||||||||||||||||||||||||||||||||||||||||
| 2115 | |||||||||||||||||||||||||||||||||||||||||||
| 2116 | Following a successful verify, returns an ARRAY reference of the | ||||||||||||||||||||||||||||||||||||||||||
| 2117 | XML::LibXML::Element objects that were covered by a verified signature, | ||||||||||||||||||||||||||||||||||||||||||
| 2118 | in the order the signatures were processed. | ||||||||||||||||||||||||||||||||||||||||||
| 2119 | |||||||||||||||||||||||||||||||||||||||||||
| 2120 | This is the safer counterpart to C<verified_ids()>: rather than | ||||||||||||||||||||||||||||||||||||||||||
| 2121 | re-extracting an element from the document and checking its ID, work | ||||||||||||||||||||||||||||||||||||||||||
| 2122 | directly from the elements returned here and no re-extraction step exists | ||||||||||||||||||||||||||||||||||||||||||
| 2123 | to get wrong. | ||||||||||||||||||||||||||||||||||||||||||
| 2124 | |||||||||||||||||||||||||||||||||||||||||||
| 2125 | if ($sig->verify($xml)) { | ||||||||||||||||||||||||||||||||||||||||||
| 2126 | for my $el (@{ $sig->verified_elements }) { | ||||||||||||||||||||||||||||||||||||||||||
| 2127 | my @attrs = $el->findnodes('.//saml:Attribute'); | ||||||||||||||||||||||||||||||||||||||||||
| 2128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2130 | |||||||||||||||||||||||||||||||||||||||||||
| 2131 | Note that the returned elements are live nodes in the document parsed by | ||||||||||||||||||||||||||||||||||||||||||
| 2132 | C<verify()> and still contain their C<Signature> child, which verify() | ||||||||||||||||||||||||||||||||||||||||||
| 2133 | detaches and reattaches during canonicalization. Reattachment appends, | ||||||||||||||||||||||||||||||||||||||||||
| 2134 | so a Signature that was not the last child originally will have moved to | ||||||||||||||||||||||||||||||||||||||||||
| 2135 | the end. | ||||||||||||||||||||||||||||||||||||||||||
| 2136 | |||||||||||||||||||||||||||||||||||||||||||
| 2137 | Arguments: none | ||||||||||||||||||||||||||||||||||||||||||
| 2138 | |||||||||||||||||||||||||||||||||||||||||||
| 2139 | Returns: ARRAY reference of XML::LibXML::Element objects. Empty after a | ||||||||||||||||||||||||||||||||||||||||||
| 2140 | failed verify or before verify is called. | ||||||||||||||||||||||||||||||||||||||||||
| 2141 | |||||||||||||||||||||||||||||||||||||||||||
| 2142 | =head3 B<check_dsa_version()> | ||||||||||||||||||||||||||||||||||||||||||
| 2143 | |||||||||||||||||||||||||||||||||||||||||||
| 2144 | Verify the required Crypt::OpenSSL::DSA is installed | ||||||||||||||||||||||||||||||||||||||||||
| 2145 | |||||||||||||||||||||||||||||||||||||||||||
| 2146 | Arguments: none | ||||||||||||||||||||||||||||||||||||||||||
| 2147 | |||||||||||||||||||||||||||||||||||||||||||
| 2148 | Returns: integer (1 True, 0 False) if a valid version of | ||||||||||||||||||||||||||||||||||||||||||
| 2149 | Crypt::OpenSSL::DSA is installed | ||||||||||||||||||||||||||||||||||||||||||
| 2150 | |||||||||||||||||||||||||||||||||||||||||||
| 2151 | =head1 ID VALIDATION | ||||||||||||||||||||||||||||||||||||||||||
| 2152 | |||||||||||||||||||||||||||||||||||||||||||
| 2153 | The ID in a document must match the criteria set out below. It is a subset of | ||||||||||||||||||||||||||||||||||||||||||
| 2154 | the allowed format in the specification: L<https://www.w3.org/TR/REC-xml/#NT-Name> | ||||||||||||||||||||||||||||||||||||||||||
| 2155 | |||||||||||||||||||||||||||||||||||||||||||
| 2156 | =head2 Permitted Starting character | ||||||||||||||||||||||||||||||||||||||||||
| 2157 | |||||||||||||||||||||||||||||||||||||||||||
| 2158 | An ID can start with characters in this range only: | ||||||||||||||||||||||||||||||||||||||||||
| 2159 | |||||||||||||||||||||||||||||||||||||||||||
| 2160 | Character class for NCNameStartChar (XML 1.0 Fifth Edition): | ||||||||||||||||||||||||||||||||||||||||||
| 2161 | |||||||||||||||||||||||||||||||||||||||||||
| 2162 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 2163 | |||||||||||||||||||||||||||||||||||||||||||
| 2164 | A-Z_a-z ASCII letters and underscore | ||||||||||||||||||||||||||||||||||||||||||
| 2165 | \xC0-\xD6 Latin-1 supplement: À to Ö | ||||||||||||||||||||||||||||||||||||||||||
| 2166 | \xD8-\xF6 Latin-1 supplement: Ø to ö | ||||||||||||||||||||||||||||||||||||||||||
| 2167 | \xF8-\x{2FF} Latin Extended A/B, IPA, spacing modifiers | ||||||||||||||||||||||||||||||||||||||||||
| 2168 | \x{370}-\x{37D} Greek and Coptic | ||||||||||||||||||||||||||||||||||||||||||
| 2169 | \x{37F}-\x{1FFF} Greek through Greek Extended | ||||||||||||||||||||||||||||||||||||||||||
| 2170 | \x{2070}-\x{218F} Superscripts, currency, letterlike symbols | ||||||||||||||||||||||||||||||||||||||||||
| 2171 | \x{2C00}-\x{2FEF} Glagolitic, Coptic, Georgian, Tifinagh | ||||||||||||||||||||||||||||||||||||||||||
| 2172 | \x{3001}-\x{D7FF} CJK punctuation through Hangul syllables | ||||||||||||||||||||||||||||||||||||||||||
| 2173 | \x{F900}-\x{FDCF} CJK compatibility, Arabic presentation A | ||||||||||||||||||||||||||||||||||||||||||
| 2174 | \x{FDF0}-\x{FFFD} Arabic presentation B, halfwidth/fullwidth | ||||||||||||||||||||||||||||||||||||||||||
| 2175 | |||||||||||||||||||||||||||||||||||||||||||
| 2176 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2177 | |||||||||||||||||||||||||||||||||||||||||||
| 2178 | =head2 Permitted Remaining characters | ||||||||||||||||||||||||||||||||||||||||||
| 2179 | |||||||||||||||||||||||||||||||||||||||||||
| 2180 | The rest of the ID can include all of the charaters that match the | ||||||||||||||||||||||||||||||||||||||||||
| 2181 | NCNameStartChar and any character that matches the following: | ||||||||||||||||||||||||||||||||||||||||||
| 2182 | |||||||||||||||||||||||||||||||||||||||||||
| 2183 | Extras (NameChar-only): | ||||||||||||||||||||||||||||||||||||||||||
| 2184 | |||||||||||||||||||||||||||||||||||||||||||
| 2185 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 2186 | |||||||||||||||||||||||||||||||||||||||||||
| 2187 | - hyphen | ||||||||||||||||||||||||||||||||||||||||||
| 2188 | . period | ||||||||||||||||||||||||||||||||||||||||||
| 2189 | 0-9 ASCII digits | ||||||||||||||||||||||||||||||||||||||||||
| 2190 | \xB7 middle dot (·) | ||||||||||||||||||||||||||||||||||||||||||
| 2191 | \x{0300}-\x{036F} combining diacritical marks | ||||||||||||||||||||||||||||||||||||||||||
| 2192 | \x{203F}-\x{2040} undertie (‿) and character tie (⁀) | ||||||||||||||||||||||||||||||||||||||||||
| 2193 | |||||||||||||||||||||||||||||||||||||||||||
| 2194 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2195 | |||||||||||||||||||||||||||||||||||||||||||
| 2196 | =head1 ABOUT DIGITAL SIGNATURES | ||||||||||||||||||||||||||||||||||||||||||
| 2197 | |||||||||||||||||||||||||||||||||||||||||||
| 2198 | Just as one might want to send an email message that is cryptographically signed | ||||||||||||||||||||||||||||||||||||||||||
| 2199 | in order to give the recipient the means to independently verify who sent the email, | ||||||||||||||||||||||||||||||||||||||||||
| 2200 | one might also want to sign an XML document. This is especially true in the | ||||||||||||||||||||||||||||||||||||||||||
| 2201 | scenario where an XML document is received in an otherwise unauthenticated | ||||||||||||||||||||||||||||||||||||||||||
| 2202 | context, e.g. SAML. | ||||||||||||||||||||||||||||||||||||||||||
| 2203 | |||||||||||||||||||||||||||||||||||||||||||
| 2204 | However XML provides a challenge that email does not. In XML, two documents can be | ||||||||||||||||||||||||||||||||||||||||||
| 2205 | byte-wise inequivalent, and semanticaly equivalent at the same time. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 2206 | |||||||||||||||||||||||||||||||||||||||||||
| 2207 | <?xml version="1.0"?> | ||||||||||||||||||||||||||||||||||||||||||
| 2208 | <foo> | ||||||||||||||||||||||||||||||||||||||||||
| 2209 | <bar /> | ||||||||||||||||||||||||||||||||||||||||||
| 2210 | </foo> | ||||||||||||||||||||||||||||||||||||||||||
| 2211 | |||||||||||||||||||||||||||||||||||||||||||
| 2212 | And: | ||||||||||||||||||||||||||||||||||||||||||
| 2213 | |||||||||||||||||||||||||||||||||||||||||||
| 2214 | <?xml version="1.0"?> | ||||||||||||||||||||||||||||||||||||||||||
| 2215 | <foo> | ||||||||||||||||||||||||||||||||||||||||||
| 2216 | <bar></bar> | ||||||||||||||||||||||||||||||||||||||||||
| 2217 | </foo> | ||||||||||||||||||||||||||||||||||||||||||
| 2218 | |||||||||||||||||||||||||||||||||||||||||||
| 2219 | Each of these document express the same thing, or in other words they "mean" | ||||||||||||||||||||||||||||||||||||||||||
| 2220 | the same thing. However if you were to strictly sign the raw text of these | ||||||||||||||||||||||||||||||||||||||||||
| 2221 | documents, they would each produce different signatures. | ||||||||||||||||||||||||||||||||||||||||||
| 2222 | |||||||||||||||||||||||||||||||||||||||||||
| 2223 | XML Signatures on the other hand will produce the same signature for each of | ||||||||||||||||||||||||||||||||||||||||||
| 2224 | the documents above. Therefore an XML document can be written and rewritten by | ||||||||||||||||||||||||||||||||||||||||||
| 2225 | different parties and still be able to have someone at the end of the line | ||||||||||||||||||||||||||||||||||||||||||
| 2226 | verify a signature the document may contain. | ||||||||||||||||||||||||||||||||||||||||||
| 2227 | |||||||||||||||||||||||||||||||||||||||||||
| 2228 | There is a specially subscribed methodology for how this process should be | ||||||||||||||||||||||||||||||||||||||||||
| 2229 | executed and involves transforming the XML into its canonical form so a | ||||||||||||||||||||||||||||||||||||||||||
| 2230 | signature can be reliably inserted or extracted for verification. This | ||||||||||||||||||||||||||||||||||||||||||
| 2231 | module implements that process. | ||||||||||||||||||||||||||||||||||||||||||
| 2232 | |||||||||||||||||||||||||||||||||||||||||||
| 2233 | =head2 EXAMPLE SIGNATURE | ||||||||||||||||||||||||||||||||||||||||||
| 2234 | |||||||||||||||||||||||||||||||||||||||||||
| 2235 | Below is a sample XML signature to give you some sense of what they look like. | ||||||||||||||||||||||||||||||||||||||||||
| 2236 | First let's look at the original XML document, prior to being signed: | ||||||||||||||||||||||||||||||||||||||||||
| 2237 | |||||||||||||||||||||||||||||||||||||||||||
| 2238 | <?xml version="1.0"?> | ||||||||||||||||||||||||||||||||||||||||||
| 2239 | <foo ID="abc"> | ||||||||||||||||||||||||||||||||||||||||||
| 2240 | <bar>123</bar> | ||||||||||||||||||||||||||||||||||||||||||
| 2241 | </foo> | ||||||||||||||||||||||||||||||||||||||||||
| 2242 | |||||||||||||||||||||||||||||||||||||||||||
| 2243 | Now, let's insert a signature: | ||||||||||||||||||||||||||||||||||||||||||
| 2244 | |||||||||||||||||||||||||||||||||||||||||||
| 2245 | <?xml version="1.0"?> | ||||||||||||||||||||||||||||||||||||||||||
| 2246 | <foo ID="abc"> | ||||||||||||||||||||||||||||||||||||||||||
| 2247 | <bar>123</bar> | ||||||||||||||||||||||||||||||||||||||||||
| 2248 | <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> | ||||||||||||||||||||||||||||||||||||||||||
| 2249 | <SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"> | ||||||||||||||||||||||||||||||||||||||||||
| 2250 | <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" /> | ||||||||||||||||||||||||||||||||||||||||||
| 2251 | <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /> | ||||||||||||||||||||||||||||||||||||||||||
| 2252 | <Reference URI="#abc"> | ||||||||||||||||||||||||||||||||||||||||||
| 2253 | <Transforms> | ||||||||||||||||||||||||||||||||||||||||||
| 2254 | <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /> | ||||||||||||||||||||||||||||||||||||||||||
| 2255 | </Transforms> | ||||||||||||||||||||||||||||||||||||||||||
| 2256 | <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> | ||||||||||||||||||||||||||||||||||||||||||
| 2257 | <DigestValue>9kpmrvv3peVJpNSTRycrV+jeHVY=</DigestValue> | ||||||||||||||||||||||||||||||||||||||||||
| 2258 | </Reference> | ||||||||||||||||||||||||||||||||||||||||||
| 2259 | </SignedInfo> | ||||||||||||||||||||||||||||||||||||||||||
| 2260 | <SignatureValue> | ||||||||||||||||||||||||||||||||||||||||||
| 2261 | HXUBnMgPJf//j4ihaWnaylNwAR5AzDFY83HljFIlLmTqX1w1C72ZTuRObvYve8TNEbVsQlTQkj4R | ||||||||||||||||||||||||||||||||||||||||||
| 2262 | hiY0pgIMQUb75GLYFtc+f0YmBZf5rCWY3NWzo432D3ogAvpEzYXEQPmicWe2QozQhybaz9/wrYki | ||||||||||||||||||||||||||||||||||||||||||
| 2263 | XiXY+57fqCkf7aT8Bb6G+fn7Aj8gnZFLkmKxwCdyGsIZOIZdQ8MWpeQrifxBR0d8W1Zm6ix21WNv | ||||||||||||||||||||||||||||||||||||||||||
| 2264 | ONt575h7VxLKw8BDhNPS0p8CS3hOnSk29stpiDMCHFPxAwrbKVL1kGDLaLZn1q8nNRmH8oFxG15l | ||||||||||||||||||||||||||||||||||||||||||
| 2265 | UmS3JXDZAss8gZhU7g9T4XllCqjrAvzPLOFdeQ== | ||||||||||||||||||||||||||||||||||||||||||
| 2266 | </SignatureValue> | ||||||||||||||||||||||||||||||||||||||||||
| 2267 | <KeyInfo> | ||||||||||||||||||||||||||||||||||||||||||
| 2268 | <KeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 2269 | <RSAKeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 2270 | <Modulus> | ||||||||||||||||||||||||||||||||||||||||||
| 2271 | 1b+m37u3Xyawh2ArV8txLei251p03CXbkVuWaJu9C8eHy1pu87bcthi+T5WdlCPKD7KGtkKn9vq | ||||||||||||||||||||||||||||||||||||||||||
| 2272 | i4BJBZcG/Y10e8KWVlXDLg9gibN5hb0Agae3i1cCJTqqnQ0Ka8w1XABtbxTimS1B0aO1zYW6d+U | ||||||||||||||||||||||||||||||||||||||||||
| 2273 | Yl0xIeAOPsGMfWeu1NgLChZQton1/NrJsKwzMaQy1VI8m4gUleit9Z8mbz9bNMshdgYEZ9oC4bH | ||||||||||||||||||||||||||||||||||||||||||
| 2274 | n/SnA4FvQl1fjWyTpzL/aWF/bEzS6Qd8IBk7yhcWRJAGdXTWtwiX4mXb4h/2sdrSNvyOsd/shCf | ||||||||||||||||||||||||||||||||||||||||||
| 2275 | OSMsf0TX+OdlbH079AsxOwoUjlzjuKdCiFPdU6yAJw== | ||||||||||||||||||||||||||||||||||||||||||
| 2276 | </Modulus> | ||||||||||||||||||||||||||||||||||||||||||
| 2277 | <Exponent>Iw==</Exponent> | ||||||||||||||||||||||||||||||||||||||||||
| 2278 | </RSAKeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 2279 | </KeyValue> | ||||||||||||||||||||||||||||||||||||||||||
| 2280 | </KeyInfo> | ||||||||||||||||||||||||||||||||||||||||||
| 2281 | </Signature> | ||||||||||||||||||||||||||||||||||||||||||
| 2282 | </foo> | ||||||||||||||||||||||||||||||||||||||||||
| 2283 | |||||||||||||||||||||||||||||||||||||||||||
| 2284 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 2285 | |||||||||||||||||||||||||||||||||||||||||||
| 2286 | L<http://www.w3.org/TR/xmldsig-core/> | ||||||||||||||||||||||||||||||||||||||||||
| 2287 | |||||||||||||||||||||||||||||||||||||||||||
| 2288 | =head1 VERSION CONTROL | ||||||||||||||||||||||||||||||||||||||||||
| 2289 | |||||||||||||||||||||||||||||||||||||||||||
| 2290 | L<https://github.com/perl-net-saml2/perl-XML-Sig> | ||||||||||||||||||||||||||||||||||||||||||
| 2291 | |||||||||||||||||||||||||||||||||||||||||||
| 2292 | =head1 AUTHORS and CREDITS | ||||||||||||||||||||||||||||||||||||||||||
| 2293 | |||||||||||||||||||||||||||||||||||||||||||
| 2294 | Author: Byrne Reese <byrne@majordojo.com> | ||||||||||||||||||||||||||||||||||||||||||
| 2295 | |||||||||||||||||||||||||||||||||||||||||||
| 2296 | Thanks to Manni Heumann who wrote Google::SAML::Response from | ||||||||||||||||||||||||||||||||||||||||||
| 2297 | which this module borrows heavily in order to create digital | ||||||||||||||||||||||||||||||||||||||||||
| 2298 | signatures. | ||||||||||||||||||||||||||||||||||||||||||
| 2299 | |||||||||||||||||||||||||||||||||||||||||||
| 2300 | Net::SAML2 embedded version amended by Chris Andrews <chris@nodnol.org>. | ||||||||||||||||||||||||||||||||||||||||||
| 2301 | |||||||||||||||||||||||||||||||||||||||||||
| 2302 | Maintainer: Timothy Legge <timlegge@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||
| 2303 | |||||||||||||||||||||||||||||||||||||||||||
| 2304 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 2305 | |||||||||||||||||||||||||||||||||||||||||||
| 2306 | Timothy Legge <timlegge@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||
| 2307 | |||||||||||||||||||||||||||||||||||||||||||
| 2308 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 2309 | |||||||||||||||||||||||||||||||||||||||||||
| 2310 | This software is copyright (c) 2026 by Byrne Reese, Chris Andrews and Others; in detail: | ||||||||||||||||||||||||||||||||||||||||||
| 2311 | |||||||||||||||||||||||||||||||||||||||||||
| 2312 | Copyright 2009 Byrne, Michael Hendricks | ||||||||||||||||||||||||||||||||||||||||||
| 2313 | 2010 Chris Andrews | ||||||||||||||||||||||||||||||||||||||||||
| 2314 | 2011 Chris Andrews, Oskari Okko Ojala | ||||||||||||||||||||||||||||||||||||||||||
| 2315 | 2012 Chris Andrews, Peter Marschall | ||||||||||||||||||||||||||||||||||||||||||
| 2316 | 2015 Mike Wisener | ||||||||||||||||||||||||||||||||||||||||||
| 2317 | 2016 Jeff Fearn | ||||||||||||||||||||||||||||||||||||||||||
| 2318 | 2017 Mike Wisener, xmikew | ||||||||||||||||||||||||||||||||||||||||||
| 2319 | 2019-2021 Timothy Legge | ||||||||||||||||||||||||||||||||||||||||||
| 2320 | 2022-2023 Timothy Legge, Wesley Schwengle | ||||||||||||||||||||||||||||||||||||||||||
| 2321 | 2025-2026 Timothy Legge | ||||||||||||||||||||||||||||||||||||||||||
| 2322 | |||||||||||||||||||||||||||||||||||||||||||
| 2323 | |||||||||||||||||||||||||||||||||||||||||||
| 2324 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 2325 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 2326 | |||||||||||||||||||||||||||||||||||||||||||
| 2327 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2328 | |||||||||||||||||||||||||||||||||||||||||||
| 2329 | __END__ | ||||||||||||||||||||||||||||||||||||||||||