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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
private key validation
Oliver Güntherd779692b1269
diff --git a/modules/auth_saml/app/components/saml/providers/view_component.html.erb b/modules/auth_saml/app/components/saml/providers/view_component.html.erbindex 5c7e28f0e05..dfd0cff379f 100644--- a/modules/auth_saml/app/components/saml/providers/view_component.html.erb+++ b/modules/auth_saml/app/components/saml/providers/view_component.html.erb@@ -78,7 +78,7 @@elserender(Saml::Providers::Sections::ShowComponent.new(provider,- target_state: :configuration,+ target_state: :encryption,view_mode:,heading: t("saml.providers.label_configuration_encryption"),description: t("saml.providers.section_texts.encryption")@@ -119,7 +119,7 @@elserender(Saml::Providers::Sections::ShowComponent.new(provider,- target_state: :configuration,+ target_state: :requested_attributes,view_mode:,heading: t("saml.providers.requested_attributes"),description: t("saml.providers.section_texts.requested_attributes")diff --git a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb b/modules/auth_saml/app/contracts/saml/providers/base_contract.rbindex 2e1f0bc71c9..b3c6edd4180 100644--- a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb+++ b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb@@ -57,6 +57,9 @@ module Samlvalidate :idp_cert_is_valid,if: -> { model.idp_cert_changed? }+ attribute :authn_requests_signed+ validate :authn_requests_signed_requires_cert+%i[mapping_mail mapping_login mapping_firstname mapping_lastname].each do |attr|attribute attrvalidates_presence_of attr@@ -69,6 +72,38 @@ module Samlrescue OpenSSL::X509::CertificateError => eerrors.add :idp_cert, :invalid_certificate, additional_message: e.messageend++ def valid_certificate+ if model.certificate.blank?+ errors.add :certificate, :blank+ else+ OpenSSL::X509::Certificate.new(model.certificate)+ end+ rescue OpenSSL::X509::CertificateError => e+ errors.add :certificate, :invalid_certificate, additional_message: e.message+ end++ def valid_sp_key+ if model.private_key.blank?+ errors.add :private_key, :blank+ else+ OpenSSL::PKey::RSA.new(model.private_key)+ end+ rescue OpenSSL::X509::CertificateError => e+ errors.add :private_key, :invalid_private_key, additional_message: e.message+ end++ def authn_requests_signed_requires_cert+ return unless model.authn_requests_signed+ return unless model.authn_requests_signed_changed? || model.certificate_changed? || model.private_key_changed?++ cert = valid_certificate+ key = valid_sp_key++ unless cert.public_key.public_to_pem == key.public_key.public_to_pem+ errors.add :private_key, :unmatched_private_key+ end+ endendendenddiff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rbindex 5041fc0c871..66d2388ae7e 100644--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb@@ -156,6 +156,8 @@ module Saml.require(:saml_provider).permit(:display_name, :sp_entity_id, :idp_sso_service_url, :idp_slo_service_url, :idp_cert,:name_identifier_format, :limit_self_registration,+ :certificate, :private_key, :authn_requests_signed,+ :want_assertions_signed, :want_assertions_encrypted,:mapping_login, :mapping_mail, :mapping_firstname, :mapping_lastname, :mapping_uid,:requested_login_attribute, :requested_mail_attribute, :requested_firstname_attribute,:requested_lastname_attribute, :requested_uid_attribute,diff --git a/modules/auth_saml/app/forms/saml/providers/encryption_form.rb b/modules/auth_saml/app/forms/saml/providers/encryption_form.rbindex 2e99edb9b1d..88c0a2a5adf 100644--- a/modules/auth_saml/app/forms/saml/providers/encryption_form.rb+++ b/modules/auth_saml/app/forms/saml/providers/encryption_form.rb@@ -49,18 +49,18 @@ module Samlrequired: true)f.text_area(- name: :sp_certificate,+ name: :certificate,rows: 10,- label: I18n.t("activemodel.attributes.saml/provider.sp_certificate"),- caption: I18n.t("saml.instructions.sp_certificate"),+ label: I18n.t("activemodel.attributes.saml/provider.certificate"),+ caption: I18n.t("saml.instructions.certificate"),required: false,input_width: :large)f.text_area(- name: :sp_private_key,+ name: :private_key,rows: 10,- label: I18n.t("activemodel.attributes.saml/provider.sp_private_key"),- caption: I18n.t("saml.instructions.sp_private_key"),+ label: I18n.t("activemodel.attributes.saml/provider.private_key"),+ caption: I18n.t("saml.instructions.private_key"),required: false,input_width: :large)diff --git a/modules/auth_saml/app/models/saml/provider.rb b/modules/auth_saml/app/models/saml/provider.rbindex e2011c17f9e..0a2f74f0c89 100644--- a/modules/auth_saml/app/models/saml/provider.rb+++ b/modules/auth_saml/app/models/saml/provider.rb@@ -15,6 +15,8 @@ module Samlstore_attribute :options, :idp_cert, :stringstore_attribute :options, :idp_cert_fingerprint, :string+ store_attribute :options, :certificate, :string+ store_attribute :options, :private_key, :stringstore_attribute :options, :authn_requests_signed, :booleanstore_attribute :options, :want_assertions_signed, :booleanstore_attribute :options, :want_assertions_encrypted, :booleandiff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.ymlindex a82e01b4b01..72816050ff1 100644--- a/modules/auth_saml/config/locales/en.yml+++ b/modules/auth_saml/config/locales/en.yml@@ -16,8 +16,8 @@ en:authn_requests_signed: Sign SAML AuthnRequestswant_assertions_signed: Require signed responseswant_assertions_encrypted: Require encrypted responses- sp_certificate: Certificate used by OpenProject for SAML requests- sp_private_key: Corresponding private key for OpenProject SAML requests+ certificate: Certificate used by OpenProject for SAML requests+ private_key: Corresponding private key for OpenProject SAML requestsformat: "Format"activerecord:errors:@@ -25,7 +25,14 @@ en:saml/provider:attributes:idp_cert:- invalid_certificate: "The certificate for the identity provider is invalid: %{additional_message}"+ invalid_certificate: "The certificate provided for the identity provider is invalid: %{additional_message}"+ format: "%{message}"+ certificate:+ invalid_certificate: "The certificate is invalid: %{additional_message}"+ format: "%{message}"+ private_key:+ invalid_private_key: "The provided private key is invalid: %{additional_message}"+ unmatched_private_key: "The provided private key does not belong to the given certificate"format: "%{message}"saml:menu_title: SAML providers@@ -135,3 +142,7 @@ en:OpenProject will verify the signature against the certificate from the basic configuration section.want_assertions_encrypted: >If enabled, require the identity provider to encrypt the assertion response using the certificate pair that you provide.+ certificate: >+ Enter the X509 PEM-formatted certificate used by OpenProject for signing SAML requests.+ private_key: >+ Enter the X509 PEM-formatted private key for the above certificate. This needs to be an RSA private key.