Class: Keepasshttp
- Inherits:
-
Object
- Object
- Keepasshttp
- Defined in:
- lib/keepasshttp.rb,
lib/keepasshttp/key_store.rb
Overview
At the moment everything is in this one class as the “logic” is manageable
Defined Under Namespace
Modules: Base64Helper, KeyStore
Constant Summary collapse
- VERSION =
'0.2.0'
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#port ⇒ Object
Returns the value of attribute port.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Class Method Summary collapse
Instance Method Summary collapse
- #cached_login ⇒ Object
- #credentials_for(url) ⇒ Object
- #init_keystore(key_store) ⇒ Object
-
#initialize(port: 19_455, key_store: false) ⇒ Keepasshttp
constructor
A new instance of Keepasshttp.
- #login ⇒ Object
- #ping ⇒ Object
Constructor Details
#initialize(port: 19_455, key_store: false) ⇒ Keepasshttp
Returns a new instance of Keepasshttp.
33 34 35 36 37 |
# File 'lib/keepasshttp.rb', line 33 def initialize(port: 19_455, key_store: false) @port = port @session = false init_keystore(key_store) if key_store end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
30 31 32 |
# File 'lib/keepasshttp.rb', line 30 def id @id end |
#port ⇒ Object
Returns the value of attribute port.
28 29 30 |
# File 'lib/keepasshttp.rb', line 28 def port @port end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
29 30 31 |
# File 'lib/keepasshttp.rb', line 29 def session @session end |
Class Method Details
.connect(**params) ⇒ Object
22 23 24 25 26 |
# File 'lib/keepasshttp.rb', line 22 def self.connect(**params) kee = new(**params) kee.login kee end |
Instance Method Details
#cached_login ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/keepasshttp.rb', line 79 def cached_login cache = @key_store.load @key = cache[:key] @id = cache[:id] new_iv ping end |
#credentials_for(url) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/keepasshttp.rb', line 47 def credentials_for(url) ping enc_url = encrypt(url, iv: new_iv) json = http('get-logins', Url: enc_url) iv = json['Nonce'] json['Entries'].map do |dataset| dataset.map do |key, val| [key, decrypt(val, iv: iv)] end.to_h end end |
#init_keystore(key_store) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/keepasshttp.rb', line 39 def init_keystore(key_store) @key_store = if key_store.is_a?(Hash) KeyStore::External.new(key_store) else KeyStore.const_get(key_store) end end |
#login ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/keepasshttp.rb', line 60 def login return true if @session @session = OpenSSL::Cipher.new('AES-256-CBC') session.encrypt return cached_login if @key_store&.available? @key = session.random_key new_iv json = http(:associate, Key: @key.to_base64) return false unless json @id = json['Id'] @key_store&.save(id: @id, key: @key) end |
#ping ⇒ Object
87 88 89 |
# File 'lib/keepasshttp.rb', line 87 def ping http 'test-associate' end |