Skip to content

Commit d2f8928

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 8a4b99c commit d2f8928

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Diff for: lib/Net/SAML2/SP.pm

+9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ Path to the private key for the signing certificate
7474
Path to the public key that the IdP should use for encryption. This
7575
is used when generating the metadata.
7676
77+
=item B<signing_only>
78+
79+
Indicate that the key for signing is exclusively used for signing and not
80+
encryption and signing.
81+
7782
=item B<cacert>
7883
7984
Path to the CA certificate for verification
@@ -175,6 +180,8 @@ has 'cert' => (isa => 'Str', is => 'ro', required => 1, predicate => 'has_cert
175180
has 'key' => (isa => 'Str', is => 'ro', required => 1);
176181
has 'cacert' => (isa => 'Str', is => 'rw', required => 0, predicate => 'has_cacert');
177182

183+
has 'signing_only' => (isa => 'Bool', is => 'ro', required => 0);
184+
178185
has 'encryption_key' => (isa => 'Str', is => 'ro', required => 0, predicate => 'has_encryption_key');
179186
has 'error_url' => (isa => Uri, is => 'ro', required => 1, coerce => 1);
180187
has 'org_name' => (isa => 'Str', is => 'ro', required => 1);
@@ -654,6 +661,8 @@ sub _generate_key_descriptors {
654661

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

664+
$use = 'signing' if $self->signing_only && $use eq 'both';
665+
657666
return $x->KeyDescriptor(
658667
$md,
659668
$use ne 'both' ? { use => $use } : {},

Diff for: 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)