Class: Sphragis::Providers::FortifyProvider

Inherits:
BaseProvider show all
Defined in:
lib/sphragis/providers/fortify_provider.rb

Instance Attribute Summary

Attributes inherited from BaseProvider

#config

Instance Method Summary collapse

Methods inherited from BaseProvider

#connected?, #provider_name

Constructor Details

#initialize(config = {}) ⇒ FortifyProvider

Initialize Fortify provider with hardware token configuration

Parameters:

  • (defaults to: {})

    Configuration options

    • library_path: Path to Fortify library
    • token_pin: Hardware token PIN
    • token_slot: Token slot number
    • certificate_label: Certificate label on token


17
18
19
20
21
22
23
24
25
# File 'lib/sphragis/providers/fortify_provider.rb', line 17

def initialize(config = {})
  super
  @config = {
    library_path: config[:library_path] || Sphragis.configuration.fortify_library_path,
    token_pin: config[:token_pin] || Sphragis.configuration.token_pin,
    token_slot: config[:token_slot] || Sphragis.configuration.token_slot,
    certificate_label: config[:certificate_label] || Sphragis.configuration.certificate_label
  }
end

Instance Method Details

#certificateObject

Raises:



63
64
65
66
67
# File 'lib/sphragis/providers/fortify_provider.rb', line 63

def certificate
  raise ProviderError, "Not connected to Fortify token" unless connected?

  simulate_certificate
end

#connectObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sphragis/providers/fortify_provider.rb', line 27

def connect
  validate_configuration!

  # Generate a self-signed cert simulating a token certificate
  @private_key = OpenSSL::PKey::RSA.generate(2048)
  @signing_cert = build_self_signed_cert

  # In a real implementation, this would use FFI to connect to Fortify
  @session = {
    connected: true,
    slot: @config[:token_slot],
    provider: "fortify"
  }
  true
rescue StandardError => e
  raise ProviderError, "Failed to connect to Fortify token: #{e.message}"
end

#disconnectObject



45
46
47
48
# File 'lib/sphragis/providers/fortify_provider.rb', line 45

def disconnect
  @session = nil
  true
end

#sign(data) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sphragis/providers/fortify_provider.rb', line 50

def sign(data)
  raise ProviderError, "Not connected to Fortify token" unless connected?

  # In a real implementation, this would:
  # 1. Find the private key on the token using certificate_label
  # 2. Use PKCS#11 to sign the data
  # 3. Return the signature

  simulate_signing(data)
rescue StandardError => e
  raise ProviderError, "Failed to sign data with Fortify: #{e.message}"
end

#sign_bytes(hash) ⇒ Object

Raises:



69
70
71
72
73
74
# File 'lib/sphragis/providers/fortify_provider.rb', line 69

def sign_bytes(hash)
  raise ProviderError, "Not connected to Fortify token" unless connected?

  # hash is the SHA256 digest of the CMS signed attributes DER
  @private_key.sign_raw("SHA256", hash)
end

#validate_configuration!Object

Raises:



82
83
84
85
# File 'lib/sphragis/providers/fortify_provider.rb', line 82

def validate_configuration!
  raise ProviderError, "Fortify library path not configured" if @config[:library_path].nil?
  raise ProviderError, "Token PIN not configured" if @config[:token_pin].nil?
end

#x509_certificateObject

Raises:



76
77
78
79
80
# File 'lib/sphragis/providers/fortify_provider.rb', line 76

def x509_certificate
  raise ProviderError, "Not connected to Fortify token" unless connected?

  @signing_cert
end