Skip to content

Commit 5dcb7bb

Browse files
committed
Merge pull request #287 from peterwake/master
Keep the extracted certificate when parsing IdP metadata
2 parents a0d5d69 + 885e59f commit 5dcb7bb

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

lib/onelogin/ruby-saml/idp_metadata_parser.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def parse(idp_metadata)
4444
settings.name_identifier_format = idp_name_id_format
4545
settings.idp_sso_target_url = single_signon_service_url
4646
settings.idp_slo_target_url = single_logout_service_url
47+
settings.idp_cert = certificate_base64
4748
settings.idp_cert_fingerprint = fingerprint
4849
end
4950
end
@@ -133,19 +134,28 @@ def single_logout_service_url
133134
node.value if node
134135
end
135136

137+
# @return [String|nil] Unformatted Certificate if exists
138+
#
139+
def certificate_base64
140+
@certificate_base64 ||= begin
141+
node = REXML::XPath.first(
142+
document,
143+
"/md:EntityDescriptor/md:IDPSSODescriptor/md:KeyDescriptor[@use='signing']/ds:KeyInfo/ds:X509Data/ds:X509Certificate",
144+
{ "md" => METADATA, "ds" => DSIG }
145+
)
146+
node.text if node
147+
end
148+
end
149+
136150
# @return [String|nil] X509Certificate if exists
137151
#
138152
def certificate
139153
@certificate ||= begin
140-
node = REXML::XPath.first(
141-
document,
142-
"/md:EntityDescriptor/md:IDPSSODescriptor/md:KeyDescriptor[@use='signing']/ds:KeyInfo/ds:X509Data/ds:X509Certificate",
143-
{ "md" => METADATA, "ds" => DSIG }
144-
)
145-
Base64.decode64(node.text) if node
154+
Base64.decode64(certificate_base64) if certificate_base64
146155
end
147156
end
148157

158+
149159
# @return [String|nil] the SHA-1 fingerpint of the X509Certificate if it exists
150160
#
151161
def fingerprint

lib/onelogin/ruby-saml/settings.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ def get_fingerprint
118118
def get_idp_cert
119119
return nil if idp_cert.nil? || idp_cert.empty?
120120

121-
formated_cert = OneLogin::RubySaml::Utils.format_cert(idp_cert)
122-
OpenSSL::X509::Certificate.new(formated_cert)
121+
formatted_cert = OneLogin::RubySaml::Utils.format_cert(idp_cert)
122+
OpenSSL::X509::Certificate.new(formatted_cert)
123123
end
124124

125125
# @return [OpenSSL::X509::Certificate|nil] Build the SP certificate from the settings (previously format it)
126126
#
127127
def get_sp_cert
128128
return nil if certificate.nil? || certificate.empty?
129129

130-
formated_cert = OneLogin::RubySaml::Utils.format_cert(certificate)
131-
OpenSSL::X509::Certificate.new(formated_cert)
130+
formatted_cert = OneLogin::RubySaml::Utils.format_cert(certificate)
131+
OpenSSL::X509::Certificate.new(formatted_cert)
132132
end
133133

134134
# @return [OpenSSL::PKey::RSA] Build the SP private from the settings (previously format it)

0 commit comments

Comments
 (0)