@@ -33,6 +33,7 @@ use Net::SAML2::Binding::Redirect;
3333use Net::SAML2::Binding::SOAP;
3434use Net::SAML2::Protocol::AuthnRequest;
3535use Net::SAML2::Protocol::LogoutRequest;
36+ use Net::SAML2::Util ();
3637
3738=head2 new( ... )
3839
@@ -117,6 +118,8 @@ has '_cert_text' => (isa => 'Str', is => 'ro', init_arg => undef, builder => '_b
117118has ' authnreq_signed' => (isa => ' Bool' , is => ' ro' , required => 0, default => 1);
118119has ' want_assertions_signed' => (isa => ' Bool' , is => ' ro' , required => 0, default => 1);
119120
121+ has ' sign_metadata' => (isa => ' Bool' , is => ' ro' , required => 0, default => 1);
122+
120123sub _build_cert_text {
121124 my ($self ) = @_ ;
122125
@@ -297,22 +300,25 @@ sub post_binding {
297300 return $post ;
298301}
299302
303+ sub generate_sp_desciptor_id {
304+ my $self = shift ;
305+ return Net::SAML2::Util::generate_id();
306+ }
307+
300308=head2 metadata( )
301309
302310Returns the metadata XML document for this SP.
303311
304312=cut
305313
306- sub metadata {
307- my ($self ) = @_ ;
308-
309- use Net::SAML2::Util qw/ generate_id/ ;
314+ sub generate_metadata {
315+ my $self = shift ;
310316
311317 my $x = XML::Generator-> new(' :pretty' , conformance => ' loose' );
312318 my $md = [' md' => ' urn:oasis:names:tc:SAML:2.0:metadata' ];
313319 my $ds = [' ds' => ' http://www.w3.org/2000/09/xmldsig#' ];
314320
315- my $metadata = $x -> EntityDescriptor(
321+ return $x -> EntityDescriptor(
316322 $md ,
317323 {
318324 entityID => $self -> id },
@@ -322,7 +328,8 @@ sub metadata {
322328 WantAssertionsSigned => $self -> want_assertions_signed,
323329 errorURL => $self -> url . $self -> error_url,
324330 protocolSupportEnumeration => ' urn:oasis:names:tc:SAML:2.0:protocol' ,
325- ID => generate_id()},
331+ ID => $self -> generate_sp_desciptor_id(),
332+ },
326333 $x -> KeyDescriptor(
327334 $md ,
328335 {
@@ -403,21 +410,25 @@ sub metadata {
403410 ),
404411 )
405412 );
413+ }
406414
407- use Net::SAML2::XML::Sig;
408-
409- my $signer = Net::SAML2::XML::Sig-> new({
410- key => $self -> key,
411- cert => $self -> cert,
412- sig_hash => ' sha256' ,
413- digest_hash => ' sha256' ,
414- x509 => 1,
415- });
415+ sub metadata {
416+ my ($self ) = @_ ;
416417
417- # create a signature
418- my $signed = $signer -> sign( $metadata ) ;
418+ my $metadata = $self -> generate_metadata();
419+ return $metadata unless $self -> sign_metadata ;
419420
420- return $signed ;
421+ use Net::SAML2::XML::Sig;
422+ my $signer = Net::SAML2::XML::Sig-> new(
423+ {
424+ key => $self -> key,
425+ cert => $self -> cert,
426+ sig_hash => ' sha256' ,
427+ digest_hash => ' sha256' ,
428+ x509 => 1,
429+ }
430+ );
431+ return $signer -> sign($metadata );
421432}
422433
423434__PACKAGE__ -> meta-> make_immutable;
0 commit comments