saml-idp / saml_idp

Ruby SAML Identity Provider, best used with Rails (though not required)
MIT License
263 stars 181 forks source link

403 error with SLO request #197

Closed habin201291 closed 10 months ago

habin201291 commented 11 months ago
Zogoo commented 11 months ago

@habin201291 is your logout request signed? or just plain request as you described?

habin201291 commented 11 months ago

@Zogoo yes, my logout request is signed. This is my Saml SP config: config.saml_configure do |settings| settings.assertion_consumer_service_url = "#{saml_sp_host}/users/saml/auth" settings.assertion_consumer_service_binding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" settings.name_identifier_format = "urn:oasis:names:tc:SAML:2.0:nameid-format:transient" settings.sp_entity_id = "#{saml_sp_host}/users/saml/metadata" settings.idp_slo_service_url = "#{saml_idp_host}/saml/logout" settings.idp_sso_service_url = "#{saml_idp_host}/saml/auth" settings.idp_slo_service_binding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" settings.idp_cert = "-----BEGIN CERTIFICATE-----\n#{ENV["SAML_IDP_SECRET_KEY"]}\n-----END CERTIFICATE-----" settings.authn_context = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport" settings.certificate = "-----BEGIN CERTIFICATE-----\n#{ENV["SAML_SP_X509_CERTIFICATE"]}\n-----END CERTIFICATE-----" settings.private_key = "-----BEGIN PRIVATE KEY-----\n#{ENV["SAML_SP_SECRET_KEY"]}\n-----END PRIVATE KEY-----" settings.security[:authn_requests_signed] = true settings.security[:logout_requests_signed] = true settings.security[:logout_responses_signed] = true settings.security[:metadata_signed] = true settings.security[:digest_method] = XMLSecurity::Document::SHA1 settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA1 settings.security[:embed_sign] = false settings.security[:want_assertions_signed] = true end

And this is my logout request encoded XML: fZHBasMwDIZfJTefvMix06SmCQzKoNDtsI0ddimK466BxM4sB/b4S5odyga7GCz+T5+EdoRDP+qj//BTfLafk6WY7Oencxg77yp2iXHUadp7g/3FU9QSANIFm2sLxZLDvmInqdR2K3LkjYGSK4mKb0FZ3ioFotw0UBgzR4kme3AU0cWKZZBJLgSX8CpAy0yLzTtL3mygqzq7A5Z8Db0jvfgqNgWnPVJH2uFgSUejX+4fj3oOaiSyYRn5Fhn/Z8bgoze+Z/VuSevrdKH+s3IJJaTT3J/WxQcbscWIu/QWW3s8zZbDPnnwYcD4v36pdC0/X6M6BnTUWRdZfcqNzKEVZ76xwnDVNAVHzDPe5DIvCtsCWPMjX331+vt1yfob

And this is signature of the logout request: LaCXmCMkyMsF0VbBNRc8ppoO9nWPDcS/bw9tsAdOqkZznJLoOIaiEL/qeny5rx63CbCWDFFNPTS312cLhaCYi3hCBzCqvKs+fDztgREJq53APJaWQR3fQ6cK+mzaSrSsBKa/kIIv1b43NhfltbKTVArPMYwj3Ws0yX/2YeWAbCg=

I have tried to validate it by https://www.samltool.com/validate_logout_req.php and got a valid message

Zogoo commented 10 months ago

@habin201291 sorry for the delayed response. I think you are missing a service provider finder in your config. In there, you need to configure the following parameters. Here is an example of a single SP. Following lambda should be set into your config config.service_provider.finder = <service_providers_lambda>

    lambda { |_issuer_or_entity_id|
      {
        response_hosts: sp_metadata.assertion_consumer_services.map do |acs|
          url = acs['location'] || acs[:location]
          URI(url).host
        end,
        acs_url: sp_metadata.acs_urls.first[:location],
        cert: (sp_metadata&.signing_certificate.present? ? Base64.decode64(sp_metadata&.signing_certificate) : nil),
        fingerprint: (sp_metadata&.signing_certificate.present? ? SamlIdp::Fingerprint.certificate_digest(Base64.decode64(sp_metadata&.signing_certificate)) : nil)
      }
    }

From this configuration, fingerprint will be used to request signature validation.

Zogoo commented 10 months ago

So, I'm going to close this issue, if you still having trouble with your config please feel free re-open it.