saml-kit 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/exe/saml-kit-create-self-signed-certificate +1 -1
  3. data/exe/saml-kit-decode-http-post +1 -3
  4. data/exe/saml-kit-decode-http-redirect +2 -3
  5. data/lib/saml/kit.rb +1 -14
  6. data/lib/saml/kit/assertion.rb +14 -11
  7. data/lib/saml/kit/bindings/url_builder.rb +1 -1
  8. data/lib/saml/kit/builders.rb +2 -2
  9. data/lib/saml/kit/builders/assertion.rb +3 -2
  10. data/lib/saml/kit/builders/authentication_request.rb +3 -2
  11. data/lib/saml/kit/builders/encrypted_assertion.rb +20 -0
  12. data/lib/saml/kit/builders/identity_provider_metadata.rb +4 -3
  13. data/lib/saml/kit/builders/logout_request.rb +3 -2
  14. data/lib/saml/kit/builders/logout_response.rb +3 -2
  15. data/lib/saml/kit/builders/metadata.rb +4 -3
  16. data/lib/saml/kit/builders/response.rb +14 -5
  17. data/lib/saml/kit/builders/service_provider_metadata.rb +2 -1
  18. data/lib/saml/kit/builders/templates/assertion.builder +21 -23
  19. data/lib/saml/kit/builders/templates/encrypted_assertion.builder +5 -0
  20. data/lib/saml/kit/configuration.rb +2 -2
  21. data/lib/saml/kit/document.rb +11 -1
  22. data/lib/saml/kit/metadata.rb +13 -6
  23. data/lib/saml/kit/namespaces.rb +0 -11
  24. data/lib/saml/kit/signature.rb +1 -1
  25. data/lib/saml/kit/trustable.rb +7 -1
  26. data/lib/saml/kit/version.rb +1 -1
  27. data/lib/saml/kit/xml_templatable.rb +37 -0
  28. data/saml-kit.gemspec +1 -3
  29. metadata +10 -56
  30. data/lib/saml/kit/builders/templates/certificate.builder +0 -7
  31. data/lib/saml/kit/builders/templates/nil_class.builder +0 -0
  32. data/lib/saml/kit/builders/templates/xml_encryption.builder +0 -16
  33. data/lib/saml/kit/builders/templates/xml_signature.builder +0 -20
  34. data/lib/saml/kit/builders/xml_encryption.rb +0 -20
  35. data/lib/saml/kit/builders/xml_signature.rb +0 -40
  36. data/lib/saml/kit/certificate.rb +0 -96
  37. data/lib/saml/kit/crypto.rb +0 -17
  38. data/lib/saml/kit/crypto/oaep_cipher.rb +0 -22
  39. data/lib/saml/kit/crypto/rsa_cipher.rb +0 -23
  40. data/lib/saml/kit/crypto/simple_cipher.rb +0 -38
  41. data/lib/saml/kit/crypto/unknown_cipher.rb +0 -18
  42. data/lib/saml/kit/fingerprint.rb +0 -50
  43. data/lib/saml/kit/id.rb +0 -14
  44. data/lib/saml/kit/key_pair.rb +0 -29
  45. data/lib/saml/kit/self_signed_certificate.rb +0 -28
  46. data/lib/saml/kit/signatures.rb +0 -57
  47. data/lib/saml/kit/templatable.rb +0 -67
  48. data/lib/saml/kit/template.rb +0 -33
  49. data/lib/saml/kit/xml.rb +0 -80
  50. data/lib/saml/kit/xml_decryption.rb +0 -44
@@ -1,44 +0,0 @@
1
- module Saml
2
- module Kit
3
- # {include:file:spec/saml/xml_decryption_spec.rb}
4
- class XmlDecryption
5
- # The list of private keys to use to attempt to decrypt the document.
6
- attr_reader :private_keys
7
-
8
- def initialize(configuration: Saml::Kit.configuration)
9
- @private_keys = configuration.private_keys(use: :encryption)
10
- end
11
-
12
- # Decrypts an EncryptedData section of an XML document.
13
- #
14
- # @param data [Hash] the XML document converted to a [Hash] using Hash.from_xml.
15
- def decrypt(data)
16
- encrypted_data = data['EncryptedData']
17
- symmetric_key = symmetric_key_from(encrypted_data)
18
- cipher_text = Base64.decode64(encrypted_data["CipherData"]["CipherValue"])
19
- to_plaintext(cipher_text, symmetric_key, encrypted_data["EncryptionMethod"]['Algorithm'])
20
- end
21
-
22
- private
23
-
24
- def symmetric_key_from(encrypted_data)
25
- encrypted_key = encrypted_data['KeyInfo']['EncryptedKey']
26
- cipher_text = Base64.decode64(encrypted_key['CipherData']['CipherValue'])
27
- attempts = private_keys.count
28
- private_keys.each do |private_key|
29
- begin
30
- attempts -= 1
31
- return to_plaintext(cipher_text, private_key, encrypted_key["EncryptionMethod"]['Algorithm'])
32
- rescue OpenSSL::PKey::RSAError => error
33
- Saml::Kit.logger.error(error)
34
- raise if attempts.zero?
35
- end
36
- end
37
- end
38
-
39
- def to_plaintext(cipher_text, symmetric_key, algorithm)
40
- Crypto.decryptor_for(algorithm, symmetric_key).decrypt(cipher_text)
41
- end
42
- end
43
- end
44
- end