ssl.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Certificate::X509::SSL < Certificate::X509
  3. def applicable?
  4. return true if ca?
  5. # This is necessary because some legacy certificates may not have an extended key usage.
  6. return false if !extensions_as_hash.fetch('keyUsage', ['Digital Signature']).intersect?(['Digital Signature', 'Certificate Sign']) # rubocop:disable Zammad/DetectTranslatableString
  7. tls_web_server_authentication? || tls_web_client_authentication?
  8. end
  9. def valid_ssl_certificate!
  10. return if applicable? && usable?
  11. message = __('The certificate is not valid for SSL usage. Please check e.g. the validity period or the extensions.')
  12. Rails.logger.error { "Certificate::X509::SSL: #{message}" }
  13. Rails.logger.error { "Certificate::X509::SSL:\n #{to_text}" }
  14. raise Exceptions::UnprocessableEntity, message
  15. end
  16. private
  17. def tls_web_client_authentication?
  18. extensions_as_hash.fetch('extendedKeyUsage', ['TLS Web Client Authentication']).include?('TLS Web Client Authentication')
  19. end
  20. def tls_web_server_authentication?
  21. extensions_as_hash.fetch('extendedKeyUsage', ['TLS Web Server Authentication']).include?('TLS Web Server Authentication')
  22. end
  23. end