Skip to content

Commit f4853b0

Browse files
committed
Set key to be only for signing by adding signing_only in the SP
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 <[email protected]>
1 parent a19257d commit f4853b0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Net/SAML2/SP.pm

+4
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ has 'cert' => (isa => 'Str', is => 'ro', required => 1, predicate => 'has_cert
175175
has 'key' => (isa => 'Str', is => 'ro', required => 1);
176176
has 'cacert' => (isa => 'Str', is => 'rw', required => 0, predicate => 'has_cacert');
177177

178+
has 'signing_only' => (isa => 'Bool', is => 'ro', required => 0);
179+
178180
has 'encryption_key' => (isa => 'Str', is => 'ro', required => 0, predicate => 'has_encryption_key');
179181
has 'error_url' => (isa => Uri, is => 'ro', required => 1, coerce => 1);
180182
has 'org_name' => (isa => 'Str', is => 'ro', required => 1);
@@ -654,6 +656,8 @@ sub _generate_key_descriptors {
654656

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

659+
$use = 'signing' if $self->signing_only && $use eq 'both';
660+
657661
return $x->KeyDescriptor(
658662
$md,
659663
$use ne 'both' ? { use => $use } : {},

t/02-create-sp.t

+14
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ use URN::OASIS::SAML2 qw(:bindings :urn);
219219
}
220220

221221
}
222+
223+
{
224+
my $sp = net_saml2_sp(signing_only => 1);
225+
my $xpath = get_xpath(
226+
$sp->metadata,
227+
md => URN_METADATA,
228+
ds => URN_SIGNATURE,
229+
);
230+
231+
232+
my $kd = get_single_node_ok($xpath, "//md:KeyDescriptor");
233+
is($kd->getAttribute('use'), 'signing', "Key descriptor says sign");
234+
}
235+
222236
{
223237
my $sp = net_saml2_sp( ( encryption_key => 't/sign-nopw-cert.pem' ) );
224238

0 commit comments

Comments
 (0)