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

Cert parsing

Oliver Güntherff57c6add8b3
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 9d097ec4f4b..2e1f0bc71c9 100644
--- a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
+++ b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
@@ -51,10 +51,24 @@ module Saml
url: { schemes: %w[http https] },
if: -> { model.idp_slo_service_url_changed? }
+ attribute :idp_cert
+ validates_presence_of :idp_cert,
+ if: -> { model.idp_cert_changed? }
+ validate :idp_cert_is_valid,
+ if: -> { model.idp_cert_changed? }
+
%i[mapping_mail mapping_login mapping_firstname mapping_lastname].each do |attr|
attribute attr
validates_presence_of attr
end
+
+ def idp_cert_is_valid
+ return if model.idp_cert.blank?
+
+ OpenSSL::X509::Certificate.load(model.idp_cert)
+ rescue OpenSSL::X509::CertificateError => e
+ errors.add :idp_cert, :invalid_certificate, additional_message: e.message
+ end
end
end
end
diff --git a/modules/auth_saml/app/forms/saml/providers/configuration_form.rb b/modules/auth_saml/app/forms/saml/providers/configuration_form.rb
index 448028c4f92..da39f5cb98b 100644
--- a/modules/auth_saml/app/forms/saml/providers/configuration_form.rb
+++ b/modules/auth_saml/app/forms/saml/providers/configuration_form.rb
@@ -56,7 +56,7 @@ module Saml
rows: 10,
label: I18n.t("activemodel.attributes.saml/provider.idp_cert"),
caption: I18n.t("saml.instructions.idp_cert"),
- required: false,
+ required: true,
input_width: :large
)
f.select_list(
diff --git a/modules/auth_saml/app/services/saml/update_metadata_service.rb b/modules/auth_saml/app/services/saml/update_metadata_service.rb
index 8e8779d5ca7..a4416d11791 100644
--- a/modules/auth_saml/app/services/saml/update_metadata_service.rb
+++ b/modules/auth_saml/app/services/saml/update_metadata_service.rb
@@ -37,7 +37,6 @@ module Saml
def call
updated_metadata
- updated_metadata
rescue StandardError => e
OpenProject.logger.error(e)
ServiceResult.failure(message: I18n.t("saml.metadata_parser.error", error: e.class.name))
@@ -51,7 +50,7 @@ module Saml
elsif provider.metadata_xml.present?
parse_xml
else
- {}
+ ServiceResult.success(result: {})
end
end
diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.yml
index c94f7741fb0..a82e01b4b01 100644
--- a/modules/auth_saml/config/locales/en.yml
+++ b/modules/auth_saml/config/locales/en.yml
@@ -19,6 +19,14 @@ en:
sp_certificate: Certificate used by OpenProject for SAML requests
sp_private_key: Corresponding private key for OpenProject SAML requests
format: "Format"
+ activerecord:
+ errors:
+ models:
+ saml/provider:
+ attributes:
+ idp_cert:
+ invalid_certificate: "The certificate for the identity provider is invalid: %{additional_message}"
+ format: "%{message}"
saml:
menu_title: SAML providers
info: