Class: Saml::Elements::EncryptedID

Inherits:
Object
  • Object
show all
Includes:
Base, XMLHelpers, XmlMapper
Defined in:
lib/saml/elements/encrypted_id.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XMLHelpers

#add_signature, #to_soap, #to_xml

Constructor Details

#initialize(*args) ⇒ EncryptedID

Returns a new instance of EncryptedID.



21
22
23
24
# File 'lib/saml/elements/encrypted_id.rb', line 21

def initialize(*args)
  options = args.extract_options!
  super(*(args << options))
end

Instance Attribute Details

#xml_nodeObject

Returns the value of attribute xml_node.



10
11
12
# File 'lib/saml/elements/encrypted_id.rb', line 10

def xml_node
  @xml_node
end

Instance Method Details

#encrypt(key_descriptors, key_options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/saml/elements/encrypted_id.rb', line 26

def encrypt(key_descriptors, key_options = {})
  key_descriptors = Array(key_descriptors)
  encrypted_keys = []

  self.encrypted_data = Xmlenc::Builder::EncryptedData.new
  self.encrypted_data.set_key_retrieval_method Xmlenc::Builder::RetrievalMethod.new(
    uri: "##{key_options[:id]}"
  )
  self.encrypted_data.set_encryption_method(
    algorithm: 'http://www.w3.org/2001/04/xmlenc#aes256-cbc'
  )

  key_descriptors.each do |key_descriptor|
    encrypted_key = self.encrypted_data.encrypt(name_id_xml, key_options)
    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.set_key_name(key_descriptor.key_info.key_name)
    encrypted_key.encrypt(key_descriptor.certificate.public_key)

    encrypted_keys << encrypted_key
  end

  self.encrypted_keys = encrypted_keys
  self.name_id = nil
end