Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix validity checking of certs with idp_cert_multi

Oliver Günther7760c4fea55f
diff --git a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
index f0169df9e8f..3450597c6f1 100644
--- a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
+++ b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
@@ -55,7 +55,7 @@ module Saml
attribute :idp_cert
validates_presence_of :idp_cert,
if: -> { model.idp_cert_changed? }
- validate :idp_cert_is_valid,
+ validate :idp_cert_not_expired,
if: -> { model.idp_cert_changed? && model.idp_cert.present? }
attribute :authn_requests_signed
@@ -66,12 +66,9 @@ module Saml
validates_presence_of attr, if: -> { model.public_send(:"#{attr}_changed?") }
end
- def idp_cert_is_valid
- model.loaded_idp_certificates.each do |cert|
- if OneLogin::RubySaml::Utils.is_cert_expired(cert)
- errors.add :certificate, :certificate_expired
- break
- end
+ def idp_cert_not_expired
+ unless model.idp_certificate_expired?
+ errors.add :certificate, :certificate_expired
end
rescue OpenSSL::X509::CertificateError => e
errors.add :idp_cert, :invalid_certificate, additional_message: e.message
diff --git a/modules/auth_saml/app/models/saml/provider.rb b/modules/auth_saml/app/models/saml/provider.rb
index 704fc6935f9..7b156dbbf8d 100644
--- a/modules/auth_saml/app/models/saml/provider.rb
+++ b/modules/auth_saml/app/models/saml/provider.rb
@@ -67,7 +67,7 @@ module Saml
def configured?
sp_entity_id.present? &&
idp_sso_service_url.present? &&
- certificate_configured?
+ idp_certificate_configured?
end
def mapping_configured?
@@ -95,10 +95,14 @@ module Saml
@loaded_idp_certificates ||= OpenSSL::X509::Certificate.load(idp_cert)
end
- def certificate_configured?
+ def idp_certificate_configured?
idp_cert.present?
end
+ def idp_certificate_expired?
+ !loaded_idp_certificates.all? { |cert| OneLogin::RubySaml::Utils.is_cert_expired(cert) }
+ end
+
def idp_cert=(cert)
formatted =
if cert.include?("BEGIN CERTIFICATE")