Skip to content

Commit

Permalink
Set key to be only for signing by adding signing_only in the SP
Browse files Browse the repository at this point in the history
In 3c87e51 we defined the signing key to be for signing and encryption.
This new flag allows consumers to keep old behaviour where the key
was/is only used for signing and not encrypting.

Signed-off-by: Wesley Schwengle <waterkip@cpan.org>
  • Loading branch information
waterkip committed Apr 26, 2024
1 parent a19257d commit f4853b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Net/SAML2/SP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ has 'cert' => (isa => 'Str', is => 'ro', required => 1, predicate => 'has_cert
has 'key' => (isa => 'Str', is => 'ro', required => 1);
has 'cacert' => (isa => 'Str', is => 'rw', required => 0, predicate => 'has_cacert');

has 'signing_only' => (isa => 'Bool', is => 'ro', required => 0);

has 'encryption_key' => (isa => 'Str', is => 'ro', required => 0, predicate => 'has_encryption_key');
has 'error_url' => (isa => Uri, is => 'ro', required => 1, coerce => 1);
has 'org_name' => (isa => 'Str', is => 'ro', required => 1);
Expand Down Expand Up @@ -654,6 +656,8 @@ sub _generate_key_descriptors {

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

$use = 'signing' if $self->signing_only && $use eq 'both';

return $x->KeyDescriptor(
$md,
$use ne 'both' ? { use => $use } : {},
Expand Down
14 changes: 14 additions & 0 deletions t/02-create-sp.t
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,20 @@ use URN::OASIS::SAML2 qw(:bindings :urn);
}

}

{
my $sp = net_saml2_sp(signing_only => 1);
my $xpath = get_xpath(
$sp->metadata,
md => URN_METADATA,
ds => URN_SIGNATURE,
);


my $kd = get_single_node_ok($xpath, "//md:KeyDescriptor");
is($kd->getAttribute('use'), 'signing', "Key descriptor says sign");
}

{
my $sp = net_saml2_sp( ( encryption_key => 't/sign-nopw-cert.pem' ) );

Expand Down

0 comments on commit f4853b0

Please sign in to comment.