Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mention key usage unless we have both signing and encryption #206

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions lib/Net/SAML2/SP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,6 @@ around BUILDARGS => sub {

sub _build_id {
my $self = shift;

# This allows current clients to override the builder without changing
# their code
if (my $f = $self->can('generate_sp_desciptor_id')) {
Net::SAML2::Util::deprecation_warning
"generate_sp_desciptor_id has been deprecated, please override " .
"_build_id yourself or supply the ID to the constructor";
return $f->();
}
return Net::SAML2::Util::generate_id();
}

Expand Down Expand Up @@ -615,9 +606,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 +652,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 } : {},
waterkip marked this conversation as resolved.
Show resolved Hide resolved
$x->KeyInfo(
$ds,
$x->X509Data($ds, $x->X509Certificate($ds, $key)),
Expand All @@ -681,7 +674,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