Class: Virgil::SDK::Client::CardValidator
- Inherits:
-
Object
- Object
- Virgil::SDK::Client::CardValidator
- Defined in:
- lib/virgil/sdk/client/card_validator.rb
Overview
Class used for cards signatures validation.
Constant Summary collapse
- SERVICE_CARD_ID =
'3e29d43373348cfb373b7eae189214dc01d7237765e572db685839b64adca853'- SERVICE_PUBLIC_KEY =
'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUNvd0JRWURLMlZ3QXlFQVlSNTAx'\ 'a1YxdFVuZTJ1T2RrdzRrRXJSUmJKcmMyU3lhejVWMWZ1RytyVnM9Ci0tLS0tRU5E'\ 'IFBVQkxJQyBLRVktLS0tLQo='
Instance Attribute Summary collapse
-
#crypto ⇒ Object
readonly
Returns the value of attribute crypto.
-
#verifiers ⇒ Object
readonly
Returns the value of attribute verifiers.
Instance Method Summary collapse
-
#add_verifier(card_id, public_key) ⇒ Object
Add signature verifier.
-
#initialize(crypto) ⇒ CardValidator
constructor
A new instance of CardValidator.
-
#is_valid?(card) ⇒ Boolean
Validates Card using verifiers.
Constructor Details
#initialize(crypto) ⇒ CardValidator
Returns a new instance of CardValidator.
51 52 53 54 55 56 57 58 |
# File 'lib/virgil/sdk/client/card_validator.rb', line 51 def initialize(crypto) @crypto = crypto @public_key_bytes = Crypto::Bytes.from_base64(SERVICE_PUBLIC_KEY) @public_key = crypto.import_public_key(@public_key_bytes) @verifiers = { SERVICE_CARD_ID => @public_key } end |
Instance Attribute Details
#crypto ⇒ Object (readonly)
Returns the value of attribute crypto.
49 50 51 |
# File 'lib/virgil/sdk/client/card_validator.rb', line 49 def crypto @crypto end |
#verifiers ⇒ Object (readonly)
Returns the value of attribute verifiers.
49 50 51 |
# File 'lib/virgil/sdk/client/card_validator.rb', line 49 def verifiers @verifiers end |
Instance Method Details
#add_verifier(card_id, public_key) ⇒ Object
Add signature verifier.
Args:
card_id: Card identifier
public_key: Public key used for signature verification.
65 66 67 |
# File 'lib/virgil/sdk/client/card_validator.rb', line 65 def add_verifier(card_id, public_key) @verifiers[card_id] = public_key end |
#is_valid?(card) ⇒ Boolean
Validates Card using verifiers.
Args:
card: Card for validation.
Returns:
True if card signatures are valid, false otherwise.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/virgil/sdk/client/card_validator.rb', line 75 def is_valid?(card) return true if (card.version == '4.0' || card.version == '3.0') fingerprint = self.crypto.calculate_fingerprint( Crypto::Bytes.from_string(card.snapshot) ) fingerprint_hex = fingerprint.to_hex return false if fingerprint_hex != card.id verifiers = self.verifiers.clone card_public_key = self.crypto.import_public_key(card.public_key) verifiers[fingerprint_hex] = card_public_key verifiers.each do |id, key| unless card.signatures.has_key?(id) return false end is_valid = self.crypto.verify( fingerprint.value, Crypto::Bytes.from_base64(card.signatures[id]), key ) return false unless is_valid end true end |