Class: HexaPDF::DigitalSignature::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/digital_signature/handler.rb

Overview

The base signature handler providing common functionality.

Specific signature handlers need to override methods if necessary and implement the needed ones that don’t have a default implementation.

Direct Known Subclasses

CMSHandler, PKCS1Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature_dict) ⇒ Handler

Creates a new signature handler for the given signature dictionary.



52
53
54
# File 'lib/hexapdf/digital_signature/handler.rb', line 52

def initialize(signature_dict)
  @signature_dict = signature_dict
end

Instance Attribute Details

#signature_dictObject (readonly)

The signature dictionary used by the handler.



49
50
51
# File 'lib/hexapdf/digital_signature/handler.rb', line 49

def signature_dict
  @signature_dict
end

Instance Method Details

#certificate_chainObject

Returns the certificate chain.

Needs to be implemented by specific handlers.



69
70
71
# File 'lib/hexapdf/digital_signature/handler.rb', line 69

def certificate_chain
  raise "Needs to be implemented by specific handlers"
end

#signer_certificateObject

Returns the certificate used for signing.

Needs to be implemented by specific handlers.



76
77
78
# File 'lib/hexapdf/digital_signature/handler.rb', line 76

def signer_certificate
  raise "Needs to be implemented by specific handlers"
end

#signer_nameObject

Returns the common name of the signer (/Name field of the signature dictionary).



57
58
59
# File 'lib/hexapdf/digital_signature/handler.rb', line 57

def signer_name
  @signature_dict[:Name]
end

#signing_timeObject

Returns the time of signing (/M field of the signature dictionary).



62
63
64
# File 'lib/hexapdf/digital_signature/handler.rb', line 62

def signing_time
  @signature_dict[:M]
end

#verify(store, allow_self_signed: false) ⇒ Object

Verifies general signature properties and prepares the provided OpenSSL::X509::Store object for use by concrete implementations.

Needs to be called by specific handlers.



84
85
86
87
88
89
90
91
# File 'lib/hexapdf/digital_signature/handler.rb', line 84

def verify(store, allow_self_signed: false)
  result = VerificationResult.new
  check_certified_signature(result)
  verify_signing_time(result)
  store.verify_callback =
    store_verification_callback(result, allow_self_signed: allow_self_signed)
  result
end