File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -386,7 +386,10 @@ The settings related to sign are stored in the `security` attribute of the setti
386386```ruby
387387 settings.security[:authn_requests_signed] = true # Enable or not signature on AuthNRequest
388388 settings.security[:logout_requests_signed] = true # Enable or not signature on Logout Request
389- settings.security[:logout_responses_signed] = true # Enable or not signature on Logout Response
389+ settings.security[:logout_responses_signed] = true # Enable or not
390+ signature on Logout Response
391+ settings.security[:want_assertions_signed] = true # Enable or not
392+ the requirement of signed assertion
390393 settings.security[:metadata_signed] = true # Enable or not signature on Metadata
391394
392395 settings.security[:digest_method] = XMLSecurity::Document::SHA1
Original file line number Diff line number Diff line change @@ -29,8 +29,7 @@ def generate(settings, pretty_print=false)
2929 sp_sso = root . add_element "md:SPSSODescriptor" , {
3030 "protocolSupportEnumeration" => "urn:oasis:names:tc:SAML:2.0:protocol" ,
3131 "AuthnRequestsSigned" => settings . security [ :authn_requests_signed ] ,
32- # However we would like assertions signed if idp_cert_fingerprint or idp_cert is set
33- "WantAssertionsSigned" => !!( settings . idp_cert_fingerprint || settings . idp_cert )
32+ "WantAssertionsSigned" => settings . security [ :want_assertions_signed ] ,
3433 }
3534
3635 # Add KeyDescriptor if messages will be signed / encrypted
Original file line number Diff line number Diff line change @@ -448,6 +448,10 @@ def validate_signed_elements
448448 return append_error ( "Found an unexpected number of Signature Element. SAML Response rejected" )
449449 end
450450
451+ if settings . security [ :want_assertions_signed ] && !( signed_elements . include? "Assertion" )
452+ return append_error ( "The Assertion of the Response is not signed and the SP requires it" )
453+ end
454+
451455 true
452456 end
453457
Original file line number Diff line number Diff line change @@ -154,6 +154,7 @@ def get_sp_key
154154 :authn_requests_signed => false ,
155155 :logout_requests_signed => false ,
156156 :logout_responses_signed => false ,
157+ :want_assertions_signed => false ,
157158 :metadata_signed => false ,
158159 :embed_sign => false ,
159160 :digest_method => XMLSecurity ::Document ::SHA1 ,
Original file line number Diff line number Diff line change @@ -75,6 +75,20 @@ class MetadataTest < Minitest::Test
7575 assert validate_xml! ( xml_text , "saml-schema-metadata-2.0.xsd" )
7676 end
7777
78+ describe "WantAssertionsSigned" do
79+ it "generates Service Provider Metadata with WantAssertionsSigned = false" do
80+ settings . security [ :want_assertions_signed ] = false
81+ assert_equal "false" , spsso_descriptor . attribute ( "WantAssertionsSigned" ) . value
82+ assert validate_xml! ( xml_text , "saml-schema-metadata-2.0.xsd" )
83+ end
84+
85+ it "generates Service Provider Metadata with WantAssertionsSigned = true" do
86+ settings . security [ :want_assertions_signed ] = true
87+ assert_equal "true" , spsso_descriptor . attribute ( "WantAssertionsSigned" ) . value
88+ assert validate_xml! ( xml_text , "saml-schema-metadata-2.0.xsd" )
89+ end
90+ end
91+
7892 describe "when auth requests are signed" do
7993 let ( :key_descriptors ) do
8094 REXML ::XPath . match (
Original file line number Diff line number Diff line change @@ -997,6 +997,26 @@ class RubySamlTest < Minitest::Test
997997 end
998998 end
999999
1000+ describe '#want_assertion_signed' do
1001+ before do
1002+ settings . security [ :want_assertions_signed ] = true
1003+ @signed_assertion = OneLogin ::RubySaml ::Response . new ( response_document_with_signed_assertion , :settings => settings )
1004+ @no_signed_assertion = OneLogin ::RubySaml ::Response . new ( response_document_valid_signed , :settings => settings )
1005+ end
1006+
1007+
1008+ it 'returns false if :want_assertion_signed enabled and Assertion not signed' do
1009+ assert !@no_signed_assertion . send ( :validate_signed_elements )
1010+ assert_includes @no_signed_assertion . errors , "The Assertion of the Response is not signed and the SP requires it"
1011+
1012+ end
1013+
1014+ it 'returns true if :want_assertion_signed enabled and Assertion is signed' do
1015+ assert @signed_assertion . send ( :validate_signed_elements )
1016+ assert_empty @signed_assertion . errors
1017+ end
1018+ end
1019+
10001020 describe "retrieve nameID" do
10011021 it 'is possible when nameID inside the assertion' do
10021022 response_valid_signed . settings = settings
You can’t perform that action at this time.
0 commit comments