Class: VacmanController::Token
- Inherits:
-
Object
- Object
- VacmanController::Token
- Defined in:
- lib/vacman_controller/token.rb,
lib/vacman_controller/token/properties.rb
Defined Under Namespace
Classes: Properties
Class Method Summary collapse
-
.import(dpx_filename, transport_key) ⇒ Object
Opens the given dpx_filename with the given transport key and, if successful, returns Token instances for all tokens in the DPX file.
Instance Method Summary collapse
-
#activation ⇒ Object
Generate activation data from the token blob and the digipass parameters embodied in the token static initialisation vector.
-
#app_name ⇒ Object
Returns the token Application Name.
-
#disable! ⇒ Object
Sets the “disabled” token status.
-
#disable_pin! ⇒ Object
Disables the PIN on this token.
-
#enable! ⇒ Object
Set both primary and backup application enabled status.
-
#enable_backup_only! ⇒ Object
Set the backup application enabled status.
-
#enable_pin! ⇒ Object
Enables the PIN on this token.
-
#enable_primary_only! ⇒ Object
Set the primary application enabled status.
-
#force_pin_change! ⇒ Object
Forces PIN change on this token.
-
#generate ⇒ Object
Generate an OTP from this token.
-
#initialize(token_hash) ⇒ Token
constructor
Initialises a Token instance with the given token hash.
-
#inspect ⇒ Object
Renders this token in your development console and in your logs (possibly).
-
#properties ⇒ Object
Returns a
Token::Properties
object giving low-level access to the token properties. -
#reset! ⇒ Object
Resets error count and time window.
-
#reset_error_count! ⇒ Object
Resets the token error count.
-
#serial ⇒ Object
Return the token serial number.
-
#set_pin(pin) ⇒ Object
Set this token’s PIN.
-
#to_h ⇒ Object
Returns the token as an hash, that is suitable for passing to the low-level functions, or for persistance purposes.
-
#verify(otp) ⇒ Object
Verify a password.
-
#verify!(otp) ⇒ Object
Same as verify, but raises a VacmanController::Error if OTP verification fails.
Constructor Details
#initialize(token_hash) ⇒ Token
Initialises a Token instance with the given token hash.
19 20 21 |
# File 'lib/vacman_controller/token.rb', line 19 def initialize(token_hash) @token_hash = token_hash end |
Class Method Details
.import(dpx_filename, transport_key) ⇒ Object
Opens the given dpx_filename with the given transport key and, if successful, returns Token instances for all tokens in the DPX file.
10 11 12 13 14 |
# File 'lib/vacman_controller/token.rb', line 10 def self.import(dpx_filename, transport_key) VacmanController.import(dpx_filename, transport_key).map do |hash| Token.new(hash) end end |
Instance Method Details
#activation ⇒ Object
Generate activation data from the token blob and the digipass parameters embodied in the token static initialisation vector.
Returns:
The token serial number and the activation code as an Array, suitable for multiple assignment.
Not all tokens support activation data generation. This is determined by the DPX having a static vector or not. You can check whether your token instance has a static vector by assessing the presence of the ‘sv’ key in the token hash.
107 108 109 110 |
# File 'lib/vacman_controller/token.rb', line 107 def activation ad = VacmanController::LowLevel.generate_activation(@token_hash) [ ad.fetch('serial').scan(/\d(\d)/).flatten.join, ad.fetch('activation') ] end |
#app_name ⇒ Object
Returns the token Application Name
33 34 35 |
# File 'lib/vacman_controller/token.rb', line 33 def app_name @token_hash.fetch('app_name').dup end |
#disable! ⇒ Object
Sets the “disabled” token status
169 170 171 172 |
# File 'lib/vacman_controller/token.rb', line 169 def disable! properties[:token_status] = :disabled true end |
#disable_pin! ⇒ Object
Disables the PIN on this token
145 146 147 148 |
# File 'lib/vacman_controller/token.rb', line 145 def disable_pin! properties[:pin_enabled] = false true end |
#enable! ⇒ Object
Set both primary and backup application enabled status
193 194 195 196 |
# File 'lib/vacman_controller/token.rb', line 193 def enable! properties[:token_status] = :enabled true end |
#enable_backup_only! ⇒ Object
Set the backup application enabled status
185 186 187 188 |
# File 'lib/vacman_controller/token.rb', line 185 def enable_backup_only! properties[:token_status] = :backup_only true end |
#enable_pin! ⇒ Object
Enables the PIN on this token
137 138 139 140 |
# File 'lib/vacman_controller/token.rb', line 137 def enable_pin! properties[:pin_enabled] = true true end |
#enable_primary_only! ⇒ Object
Set the primary application enabled status
177 178 179 180 |
# File 'lib/vacman_controller/token.rb', line 177 def enable_primary_only! properties[:token_status] = :primary_only true end |
#force_pin_change! ⇒ Object
Forces PIN change on this token
153 154 155 156 |
# File 'lib/vacman_controller/token.rb', line 153 def force_pin_change! properties[:pin_change_forced] = true true end |
#generate ⇒ Object
Generate an OTP from this token. This does the same as hitting the button on the hardware token.
Returns:
The OTP as a String. The OTP is only valid for a limited time period.
Not all tokens support OTP generation.
90 91 92 |
# File 'lib/vacman_controller/token.rb', line 90 def generate VacmanController::LowLevel.generate_password(@token_hash) end |
#inspect ⇒ Object
Renders this token in your development console and in your logs (possibly)
41 42 43 |
# File 'lib/vacman_controller/token.rb', line 41 def inspect "#<#{self.class.name} serial=#{serial.inspect} app_name=#{app_name.inspect}>" end |
#properties ⇒ Object
Returns a Token::Properties
object giving low-level access to the token properties.
202 203 204 |
# File 'lib/vacman_controller/token.rb', line 202 def properties @_properties = VacmanController::Token::Properties.new(self) end |
#reset! ⇒ Object
Resets error count and time window
126 127 128 |
# File 'lib/vacman_controller/token.rb', line 126 def reset! VacmanController::LowLevel.reset!(@token_hash) end |
#reset_error_count! ⇒ Object
Resets the token error count
161 162 163 164 |
# File 'lib/vacman_controller/token.rb', line 161 def reset_error_count! properties[:error_count] = 0 true end |
#serial ⇒ Object
Return the token serial number
26 27 28 |
# File 'lib/vacman_controller/token.rb', line 26 def serial @token_hash.fetch('serial').dup end |
#set_pin(pin) ⇒ Object
Set this token’s PIN
Parameters:
- pin
-
the new PIN. Must be coercible to String.
119 120 121 |
# File 'lib/vacman_controller/token.rb', line 119 def set_pin(pin) VacmanController::LowLevel.set_token_pin(@token_hash, pin.to_s) end |
#to_h ⇒ Object
Returns the token as an hash, that is suitable for passing to the low-level functions, or for persistance purposes.
49 50 51 |
# File 'lib/vacman_controller/token.rb', line 49 def to_h @token_hash end |
#verify(otp) ⇒ Object
Verify a password. This is the usecase a user sends you an OTP generated by their token and we have to verify it.
Parameters:
- otp
-
The OTP provided by the user
Returns:
true if the password is valid, false otherwise
ATTENTION: it is very important to persist the token hash afterwards.
67 68 69 70 71 |
# File 'lib/vacman_controller/token.rb', line 67 def verify(otp) verify!(otp) rescue VacmanController::Error false end |
#verify!(otp) ⇒ Object
Same as verify, but raises a VacmanController::Error if OTP verification fails.
77 78 79 |
# File 'lib/vacman_controller/token.rb', line 77 def verify!(otp) VacmanController::LowLevel.verify_password(@token_hash, otp.to_s) end |