Class: Facturae::Xades::SignedInfo

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/facturae/xades/signed_info.rb

Overview

Handles the building of the SignedInfo element for XAdES signatures. This class is responsible for creating the SignedInfo element that contains references to all signed content, including the document itself, the certificate, and the signed properties.

Constant Summary collapse

C14N_METHOD_ALGORITHM =
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
SIGNATURE_METHOD_ALGORITHM =
"http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
TRANSFORM_ALGORITHM =
"http://www.w3.org/2000/09/xmldsig#enveloped-signature"
DIGEST_METHOD_ALGORITHM =
"http://www.w3.org/2001/04/xmlenc#sha512"
SIGNED_PROPERTIES_TYPE =
"http://uri.etsi.org/01903#SignedProperties"
REFERENCE_ID_TYPE =
"http://www.w3.org/2000/09/xmldsig#Object"
NAMESPACES =
{
  "ds" => "http://www.w3.org/2000/09/xmldsig#",
  "xades" => "http://uri.etsi.org/01903/v1.3.2#"
}.freeze

Instance Method Summary collapse

Methods included from Utils

#base64_encode, #base64_encode_raw, #calculate_sha512_digest, #create_xml_element, #create_xml_node_with_algorithm, #rand_id

Constructor Details

#initialize(doc, signing_ids) ⇒ SignedInfo

Returns a new instance of SignedInfo.



27
28
29
30
31
32
33
# File 'lib/facturae/xades/signed_info.rb', line 27

def initialize(doc, signing_ids)
  @doc = doc
  @signed_info_id = signing_ids[:signed_info_id]
  @signed_properties_id = signing_ids[:signed_properties_id]
  @certificate_id = signing_ids[:certificate_id]
  @reference_id = signing_ids[:reference_id]
end

Instance Method Details

#buildObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/facturae/xades/signed_info.rb', line 35

def build
  signed_info = build_signed_info
  signed_info.add_child(build_canonicalization_method)
  signed_info.add_child(build_signature_method)

  # Signed properties reference
  signed_info.add_child(
    build_reference(type: SIGNED_PROPERTIES_TYPE,
                    uri: "##{@signed_properties_id}",
                    node_to_digest: find_node_by_id(@signed_properties_id))
  )

  # Certificate reference
  signed_info.add_child(
    build_reference(uri: "##{@certificate_id}",
                    node_to_digest: find_node_by_id(@certificate_id))
  )

  # Document reference - this needs to be the last reference
  # because it includes a transform that affects the whole document
  signed_info.add_child(
    build_reference(id: @reference_id,
                    type: REFERENCE_ID_TYPE,
                    include_transform: true,
                    node_to_digest: @doc.root)
  )

  signed_info
end