Class: Sphragis::HardwareToken
- Inherits:
-
Object
- Object
- Sphragis::HardwareToken
- Defined in:
- lib/sphragis/hardware_token.rb
Defined Under Namespace
Classes: TokenError
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#certificate ⇒ Object
Get certificate from token.
-
#connect ⇒ Object
Initialize the token session.
-
#connected? ⇒ Boolean
Check if connected.
-
#disconnect ⇒ Object
Disconnect from the token.
-
#initialize(config = Sphragis.configuration) ⇒ HardwareToken
constructor
A new instance of HardwareToken.
-
#sign(data) ⇒ Object
Sign data using the hardware token.
Constructor Details
#initialize(config = Sphragis.configuration) ⇒ HardwareToken
Returns a new instance of HardwareToken.
11 12 13 14 |
# File 'lib/sphragis/hardware_token.rb', line 11 def initialize(config = Sphragis.configuration) @config = config @session = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/sphragis/hardware_token.rb', line 9 def config @config end |
Instance Method Details
#certificate ⇒ Object
Get certificate from token
55 56 57 58 59 60 61 |
# File 'lib/sphragis/hardware_token.rb', line 55 def certificate raise TokenError, "Not connected to token" unless connected? # In a real implementation, this would retrieve the actual certificate # from the token using the certificate_label simulate_certificate end |
#connect ⇒ Object
Initialize the token session
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sphragis/hardware_token.rb', line 17 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 } true rescue StandardError => e raise TokenError, "Failed to connect to hardware token: #{e.}" end |
#connected? ⇒ Boolean
Check if connected
35 36 37 |
# File 'lib/sphragis/hardware_token.rb', line 35 def connected? !@session.nil? end |
#disconnect ⇒ Object
Disconnect from the token
29 30 31 32 |
# File 'lib/sphragis/hardware_token.rb', line 29 def disconnect @session = nil true end |
#sign(data) ⇒ Object
Sign data using the hardware token
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sphragis/hardware_token.rb', line 40 def sign(data) raise TokenError, "Not connected to 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 # Simulated signature for development simulate_signing(data) rescue StandardError => e raise TokenError, "Failed to sign data: #{e.}" end |