Class: Sphragis::Providers::FortifyProvider
Instance Attribute Summary
Attributes inherited from BaseProvider
#config
Instance Method Summary
collapse
#connected?, #provider_name
Constructor Details
Initialize Fortify provider with hardware token configuration
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
#certificate ⇒ Object
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
|
#connect ⇒ Object
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!
@private_key = OpenSSL::PKey::RSA.generate(2048)
@signing_cert = build_self_signed_cert
@session = {
connected: true,
slot: @config[:token_slot],
provider: "fortify"
}
true
rescue StandardError => e
raise ProviderError, "Failed to connect to Fortify token: #{e.message}"
end
|
#disconnect ⇒ Object
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?
simulate_signing(data)
rescue StandardError => e
raise ProviderError, "Failed to sign data with Fortify: #{e.message}"
end
|
#sign_bytes(hash) ⇒ Object
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?
@private_key.sign_raw("SHA256", hash)
end
|
#validate_configuration! ⇒ Object
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_certificate ⇒ Object
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
|