Skip to content

Commit

Permalink
Don't mention key usage unless we have both signing and encryption
Browse files Browse the repository at this point in the history
Closes: perl-net-saml2#205

Signed-off-by: Wesley Schwengle <waterkip@cpan.org>
  • Loading branch information
waterkip committed Apr 9, 2024
1 parent 239d1b4 commit 3c87e51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 7 additions & 5 deletions lib/Net/SAML2/SP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,11 @@ sub generate_metadata {
protocolSupportEnumeration => URN_PROTOCOL,
},

$self->_generate_key_descriptors($x, 'signing'),
$self->has_encryption_key
? ($self->_generate_key_descriptors($x, 'encryption'),
$self->_generate_key_descriptors($x, 'signing'))
: $self->_generate_key_descriptors($x, 'both'),

$self->has_encryption_key ? $self->_generate_key_descriptors($x, 'encryption') : (),

$self->_generate_single_logout_service($x),

Expand Down Expand Up @@ -659,11 +661,11 @@ sub _generate_key_descriptors {
&& !$self->want_assertions_signed
&& !$self->sign_metadata;

my $key = $use eq 'signing' ? $self->_cert_text : $self->_encryption_key_text;
my $key = $use eq 'encryption' ? $self->_encryption_key_text : $self->_cert_text;

return $x->KeyDescriptor(
$md,
{ use => $use },
$use ne 'both' ? { use => $use } : {},
$x->KeyInfo(
$ds,
$x->X509Data($ds, $x->X509Certificate($ds, $key)),
Expand All @@ -681,7 +683,7 @@ Get the key name for either the C<signing> or C<encryption> key
sub key_name {
my $self = shift;
my $use = shift;
my $key = $use eq 'signing' ? $self->_cert_text : $self->_encryption_key_text;
my $key = $use eq 'encryption' ? $self->_encryption_key_text : $self->_cert_text;
return unless $key;
return Digest::MD5::md5_hex($key);
}
Expand Down
3 changes: 1 addition & 2 deletions t/02-create-sp.t
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ use URN::OASIS::SAML2 qw(:bindings :urn);

my $kd = get_single_node_ok($xpath, "$p/md:KeyDescriptor");

is($kd->getAttribute('use'),
"signing", "Key descriptor is there for signing only");
ok(!$kd->getAttribute('use'), "No key descriptor");

ok(
!$kd->getAttribute('encryption'),
Expand Down

0 comments on commit 3c87e51

Please sign in to comment.