seekrit 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/seekrit +1 -1
- data/lib/seekrit/store.rb +13 -6
- metadata +3 -3
data/bin/seekrit
CHANGED
@@ -24,7 +24,7 @@ def interactor(&blk)
|
|
24
24
|
password = lambda{ ask('Enter password: '){ |q| q.echo = false } }
|
25
25
|
store = Seekrit::Store.new(password, file)
|
26
26
|
yield Seekrit::Interactor.new(store)
|
27
|
-
rescue Seekrit::
|
27
|
+
rescue Seekrit::PasswordError => err
|
28
28
|
puts err.message
|
29
29
|
exit 1
|
30
30
|
end
|
data/lib/seekrit/store.rb
CHANGED
@@ -3,7 +3,7 @@ require 'openssl'
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
5
|
module Seekrit
|
6
|
-
class
|
6
|
+
class PasswordError < RuntimeError
|
7
7
|
end
|
8
8
|
|
9
9
|
class Store
|
@@ -62,7 +62,7 @@ module Seekrit
|
|
62
62
|
|
63
63
|
private
|
64
64
|
|
65
|
-
def
|
65
|
+
def get_key_from_user
|
66
66
|
Digest::SHA256.digest(@password.respond_to?(:call) ? @password.call : @password)
|
67
67
|
end
|
68
68
|
|
@@ -98,9 +98,16 @@ module Seekrit
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def encrypt(data)
|
101
|
+
unless @correct_key
|
102
|
+
if secrets.any?
|
103
|
+
decrypt(secrets.values.first)
|
104
|
+
else
|
105
|
+
@correct_key = get_key_from_user
|
106
|
+
end
|
107
|
+
end
|
101
108
|
cipher = OpenSSL::Cipher::Cipher.new(@cipher)
|
102
109
|
cipher.encrypt
|
103
|
-
cipher.key =
|
110
|
+
cipher.key = @correct_key
|
104
111
|
cipher.iv = iv = cipher.random_iv
|
105
112
|
ciphertext = cipher.update(data)
|
106
113
|
ciphertext << cipher.final
|
@@ -111,11 +118,11 @@ module Seekrit
|
|
111
118
|
err = nil
|
112
119
|
3.times do
|
113
120
|
begin
|
114
|
-
k = @correct_key ||
|
121
|
+
k = @correct_key || get_key_from_user
|
115
122
|
decrypted = decrypt_once(data, k)
|
116
123
|
@correct_key ||= k
|
117
124
|
return decrypted
|
118
|
-
rescue
|
125
|
+
rescue PasswordError => err
|
119
126
|
end
|
120
127
|
end
|
121
128
|
raise err
|
@@ -132,7 +139,7 @@ module Seekrit
|
|
132
139
|
plaintext << cipher.final
|
133
140
|
return plaintext
|
134
141
|
rescue => err
|
135
|
-
raise
|
142
|
+
raise PasswordError, err.message
|
136
143
|
end
|
137
144
|
end
|
138
145
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seekrit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Battley
|