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:

  • config (Hash) (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



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

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:



59
60
61
62
63
# File 'lib/sphragis/providers/fortify_provider.rb', line 59

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

  simulate_certificate
end

#connectObject



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

def connect
  validate_configuration!

  # In a real implementation, this would use FFI to connect to Fortify
  # For now, we'll simulate the connection
  @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



41
42
43
44
# File 'lib/sphragis/providers/fortify_provider.rb', line 41

def disconnect
  @session = nil
  true
end

#sign(data) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sphragis/providers/fortify_provider.rb', line 46

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

#validate_configuration!Object

Raises:



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

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