Skip to content

Commit 5e6c0f0

Browse files
committed
Add ds:KeyName to md:KeyDescriptor/ds:Keyinfo
Some SAML implemenations (such as the Dutch eHerkenning) require a KeyName on the KeyDescriptor node. Signed-off-by: Wesley Schwengle <wesley@opndev.io>
1 parent c6b9dfb commit 5e6c0f0

File tree

4 files changed

+46
-27
lines changed

4 files changed

+46
-27
lines changed

Makefile.PL

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ my %WriteMakefileArgs = (
2424
"DateTime" => 0,
2525
"DateTime::Format::XSD" => 0,
2626
"DateTime::HiRes" => 0,
27+
"Digest::MD5" => 0,
2728
"Exporter" => 0,
2829
"File::Slurper" => 0,
2930
"HTTP::Request::Common" => 0,
@@ -84,6 +85,7 @@ my %FallbackPrereqs = (
8485
"DateTime" => 0,
8586
"DateTime::Format::XSD" => 0,
8687
"DateTime::HiRes" => 0,
88+
"Digest::MD5" => 0,
8789
"Exporter" => 0,
8890
"File::Slurper" => 0,
8991
"HTTP::Request::Common" => 0,

cpanfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ requires "Crypt::OpenSSL::X509" => "0";
88
requires "DateTime" => "0";
99
requires "DateTime::Format::XSD" => "0";
1010
requires "DateTime::HiRes" => "0";
11+
requires "Digest::MD5" => "0";
1112
requires "Exporter" => "0";
1213
requires "File::Slurper" => "0";
1314
requires "HTTP::Request::Common" => "0";

lib/Net/SAML2/SP.pm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Net::SAML2::SP - SAML Service Provider object
2828
use Crypt::OpenSSL::X509;
2929
use XML::Generator;
3030

31+
use Digest::MD5 ();
32+
3133
use Net::SAML2::Binding::POST;
3234
use Net::SAML2::Binding::Redirect;
3335
use Net::SAML2::Binding::SOAP;
@@ -349,7 +351,12 @@ sub generate_metadata {
349351
$ds,
350352
$self->_cert_text,
351353
)
352-
)
354+
),
355+
$x->KeyName(
356+
$ds,
357+
Digest::MD5::md5_hex($self->_cert_text)
358+
),
359+
353360
)
354361
),
355362
$x->SingleLogoutService(

t/02-create-sp.t

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if (is(@ssos, 2, "Got two assertionConsumerService(s)")) {
3939
get_single_node_ok($xpath, '//ds:Signature');
4040

4141
{
42-
my $sp = net_saml2_sp(sign_metadata => 0);
42+
my $sp = net_saml2_sp(sign_metadata => 0);
4343
my $xpath = get_xpath(
4444
$sp->metadata,
4545
md => 'urn:oasis:names:tc:SAML:2.0:metadata',
@@ -72,13 +72,13 @@ get_single_node_ok($xpath, '//ds:Signature');
7272
error_url => '/error',
7373
);
7474

75-
my $xpc = get_xpath(
75+
my $xpath = get_xpath(
7676
$sp->metadata,
7777
md => 'urn:oasis:names:tc:SAML:2.0:metadata',
7878
ds => 'http://www.w3.org/2000/09/xmldsig#'
7979
);
8080

81-
my $node = get_single_node_ok($xpc, '/md:EntityDescriptor');
81+
my $node = get_single_node_ok($xpath, '/md:EntityDescriptor');
8282
is(
8383
$node->getAttribute('entityID'),
8484
'Some entity ID',
@@ -89,68 +89,77 @@ get_single_node_ok($xpath, '//ds:Signature');
8989

9090
{
9191
# Test ContactPerson
92-
my $node = get_single_node_ok($xpc, '/node()/md:ContactPerson');
92+
my $node = get_single_node_ok($xpath, '/node()/md:ContactPerson');
9393
my $p = $node->nodePath();
9494

95-
my $company = get_single_node_ok($xpc, "$p/md:Company");
95+
my $company = get_single_node_ok($xpath, "$p/md:Company");
9696
is(
9797
$company->textContent,
9898
'Net::SAML2::SP testsuite',
9999
"Got the correct company name for the contact person"
100100
);
101101

102-
my $email = get_single_node_ok($xpc, "$p/md:EmailAddress");
102+
my $email = get_single_node_ok($xpath, "$p/md:EmailAddress");
103103
is($email->textContent, 'test@example.com',
104104
".. and the correct email");
105105
}
106106

107107
{
108108
# Test Organisation
109-
my $node = get_single_node_ok($xpc, '/node()/md:Organization');
109+
my $node = get_single_node_ok($xpath, '/node()/md:Organization');
110110
my $p = $node->nodePath();
111111

112-
my $name = get_single_node_ok($xpc, "$p/md:OrganizationName");
113-
is(
114-
$name->textContent,
115-
'Net::SAML2::SP',
116-
"Got the correct company name"
117-
);
112+
my $name = get_single_node_ok($xpath, "$p/md:OrganizationName");
113+
is($name->textContent, 'Net::SAML2::SP',
114+
"Got the correct company name");
118115

119116
my $display_name
120-
= get_single_node_ok($xpc, "$p/md:OrganizationDisplayName");
117+
= get_single_node_ok($xpath, "$p/md:OrganizationDisplayName");
121118
is(
122119
$display_name->textContent,
123120
'Net::SAML2::SP testsuite',
124121
".. and the correct display name"
125122
);
126123

127-
my $url = get_single_node_ok($xpc, "$p/md:OrganizationURL");
124+
my $url = get_single_node_ok($xpath, "$p/md:OrganizationURL");
128125
is($url->textContent, 'http://www.example.com',
129126
".. and the correct URI");
130127
}
131128

132129
{
133130
# Test SPSSODescriptor
134-
my $node = get_single_node_ok($xpc, '/node()/md:SPSSODescriptor');
131+
my $node = get_single_node_ok($xpath, '/node()/md:SPSSODescriptor');
135132
is($node->getAttribute('AuthnRequestsSigned'),
136133
'1', '.. and authn request needs signing');
137134
is($node->getAttribute('WantAssertionsSigned'),
138135
'1', '.. as does assertions');
139-
is(
140-
$node->getAttribute('errorURL'),
141-
'http://localhost:3000/error',
142-
'Got the correct error URI'
143-
);
136+
is($node->getAttribute('errorURL'),
137+
'http://localhost:3000/error', 'Got the correct error URI');
144138

145-
# TODO: Add more tests for other metadata parts
139+
my $p = $node->nodePath();
146140

147-
}
141+
my $kd = get_single_node_ok($xpath, "$p/md:KeyDescriptor");
148142

149-
{
150-
# Test Signature
151-
my $node = get_single_node_ok($xpc, '/node()/ds:Signature');
143+
is($kd->getAttribute('use'),
144+
"signing", "Key descriptor is there for signing only");
145+
146+
my $ki = get_single_node_ok($xpath, $kd->nodePath() . "/ds:KeyInfo");
147+
148+
my $cert = get_single_node_ok($xpath,
149+
$ki->nodePath() . "/ds:X509Data/ds:X509Certificate");
150+
ok($cert->textContent, "And we have the certificate data");
151+
152+
my $keyname
153+
= get_single_node_ok($xpath, $ki->nodePath() . "/ds:KeyName");
154+
ok($keyname->textContent, "... and we have a key name");
152155
}
153156

154157
}
155158

159+
{
160+
# Test Signature
161+
my $node = get_single_node_ok($xpath, '/node()/ds:Signature');
162+
163+
}
164+
156165
done_testing;

0 commit comments

Comments
 (0)