Skip to content

Commit ced6595

Browse files
committed
Update security contact. Provide an example on how validate signature metadata before parsing it.
1 parent 82f08a3 commit ced6595

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ In addition, the following may work but are untested:
5252
## Security Guidelines
5353

5454
If you believe you have discovered a security vulnerability in this gem, please report it
55-
as an issue to [email protected]
55+
by mail to the maintainer: sixto.martin.garcia+security@gmail.com
5656

5757
### Security Warning
5858

@@ -391,6 +391,51 @@ The `OneLogin::RubySaml::IdpMetadataParser` also provides the methods `#parse_to
391391
Those return an Hash instead of a `Settings` object, which may be useful for configuring
392392
[omniauth-saml](https://github.com/omniauth/omniauth-saml), for instance.
393393
394+
395+
### Validating Signature of Metadata and retrieve settings
396+
397+
Right now there is no method at ruby_saml to validate the signature of the metadata that gonna be parsed,
398+
but it can be done as follows:
399+
* Download the XML.
400+
* Validate the Signature, providing the cert.
401+
* Provide the XML to the parse method if the signature was validated
402+
403+
```
404+
require "xml_security"
405+
require "onelogin/ruby-saml/utils"
406+
require "onelogin/ruby-saml/idp_metadata_parser"
407+
408+
url = "<url_to_the_metadata>"
409+
idp_metadata_parser = OneLogin::RubySaml::IdpMetadataParser.new
410+
411+
uri = URI.parse(url)
412+
raise ArgumentError.new("url must begin with http or https") unless /^https?/ =~ uri.scheme
413+
http = Net::HTTP.new(uri.host, uri.port)
414+
if uri.scheme == "https"
415+
http.use_ssl = true
416+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
417+
end
418+
419+
get = Net::HTTP::Get.new(uri.request_uri)
420+
get.basic_auth uri.user, uri.password if uri.user
421+
response = http.request(get)
422+
xml = response.body
423+
errors = []
424+
doc = XMLSecurity::SignedDocument.new(xml, errors)
425+
cert_str = "<include_cert_here>"
426+
cert = OneLogin::RubySaml::Utils.format_cert("cert_str")
427+
metadata_sign_cert = OpenSSL::X509::Certificate.new(cert)
428+
valid = doc.validate_document_with_cert(metadata_sign_cert, true)
429+
if valid
430+
settings = idp_metadata_parser.parse(
431+
xml,
432+
entity_id: "<entity_id_of_the_entity_to_be_retrieved>"
433+
)
434+
else
435+
print "Metadata Signarture failed to be verified with the cert provided"
436+
end
437+
438+
394439
## Retrieving Attributes
395440
396441
If you are using `saml:AttributeStatement` to transfer data like the username, you can access all the attributes through `response.attributes`. It contains all the `saml:AttributeStatement`s with its 'Name' as an indifferent key and one or more `saml:AttributeValue`s as values. The value returned depends on the value of the

0 commit comments

Comments
 (0)