tls.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Setting::Validation::Saml::TLS < Setting::Validation::Base
  3. def run
  4. return result_success if value.blank?
  5. msg = check_tls_verification
  6. return result_failed(msg) if !msg.nil?
  7. result_success
  8. end
  9. private
  10. def check_tls_verification
  11. return nil if !value[:ssl_verify]
  12. url = value[:idp_sso_target_url]
  13. return nil if !url.starts_with?('https://')
  14. resp = UserAgent.get(
  15. url,
  16. {},
  17. {
  18. verify_ssl: true,
  19. log: { facility: 'SAML' }
  20. }
  21. )
  22. return nil if resp.error.nil?
  23. return nil if resp.error.include?('#<Net::HTTP')
  24. Rails.logger.error("SAML: TLS verification failed for '#{url}': #{resp.error}")
  25. if resp.error.starts_with?('#<OpenSSL::SSL::SSLError')
  26. __('The verification of the TLS connection failed. Please check the SAML IDP certificate.')
  27. else
  28. __('The verification of the TLS connection is not possible. Please check the SAML IDP connection.')
  29. end
  30. end
  31. end