Class: Saml::Util
- Inherits:
-
Object
- Object
- Saml::Util
- Defined in:
- lib/saml/util.rb
Class Method Summary collapse
- .encrypt_assertion(assertion, certificate) ⇒ Object
- .parse_params(url) ⇒ Object
- .post(location, message) ⇒ Object
- .sign_xml(message, format = :xml, &block) ⇒ Object
- .verify_xml(message, raw_body) ⇒ Object
Class Method Details
.encrypt_assertion(assertion, certificate) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/saml/util.rb', line 42 def encrypt_assertion(assertion, certificate) encrypted_data = Xmlenc::Builder::EncryptedData.new encrypted_data.set_encryption_method(algorithm: 'http://www.w3.org/2001/04/xmlenc#aes128-cbc') encrypted_key = encrypted_data.encrypt(assertion) encrypted_key.set_encryption_method(algorithm: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p', digest_method_algorithm: 'http://www.w3.org/2000/09/xmldsig#sha1') encrypted_key.encrypt(certificate.public_key) Saml::Elements::EncryptedAssertion.new(encrypted_data: encrypted_data, encrypted_keys: encrypted_key) end |
.parse_params(url) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/saml/util.rb', line 4 def parse_params(url) query = URI.parse(url).query return {} unless query params = {} query.split(/[&;]/).each do |pairs| key, value = pairs.split('=', 2) params[key] = value end params end |
.post(location, message) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/saml/util.rb', line 17 def post(location, ) request = HTTPI::Request.new request.url = location request.headers['Content-Type'] = 'text/xml' request.body = request.auth.ssl.cert_file = Saml::Config.ssl_certificate_file request.auth.ssl.cert_key_file = Saml::Config.ssl_private_key_file HTTPI.post request end |
.sign_xml(message, format = :xml, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/saml/util.rb', line 29 def sign_xml(, format = :xml, &block) .add_signature document = Xmldsig::SignedDocument.new(.send("to_#{format}")) if block_given? document.sign(&block) else document.sign do |data, signature_algorithm| .provider.sign(signature_algorithm, data) end end end |
.verify_xml(message, raw_body) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/saml/util.rb', line 54 def verify_xml(, raw_body) document = Xmldsig::SignedDocument.new(raw_body) signature_valid = document.validate do |signature, data, signature_algorithm| .provider.verify(signature_algorithm, signature, data, .signature.key_name) end raise Saml::Errors::SignatureInvalid.new unless signature_valid signed_node = document.signed_nodes.find { |node| node['ID'] == ._id } .class.parse(signed_node.to_xml, single: true) end |