seekrit 0.2.2 → 0.2.4
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 +7 -10
- data/lib/seekrit/store.rb +17 -3
- metadata +4 -4
data/bin/seekrit
CHANGED
@@ -13,17 +13,14 @@ def interactor(&blk)
|
|
13
13
|
FileUtils.touch DATAFILE
|
14
14
|
end
|
15
15
|
File.open(DATAFILE, "r+") do |file|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
16
|
+
begin
|
17
|
+
password = lambda{ ask('Enter password: '){ |q| q.echo = false } }
|
18
|
+
store = Seekrit::Store.new(password, file)
|
19
|
+
yield Seekrit::Interactor.new(store)
|
20
|
+
rescue Seekrit::DecryptionError => err
|
21
|
+
puts err.message
|
22
|
+
exit 1
|
24
23
|
end
|
25
|
-
puts err.message
|
26
|
-
exit 1
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
data/lib/seekrit/store.rb
CHANGED
@@ -23,7 +23,7 @@ module Seekrit
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def [](name)
|
26
|
-
decrypt(secrets[name])
|
26
|
+
secrets[name] && decrypt(secrets[name])
|
27
27
|
end
|
28
28
|
|
29
29
|
def []=(name, value)
|
@@ -63,7 +63,7 @@ module Seekrit
|
|
63
63
|
private
|
64
64
|
|
65
65
|
def crypt_key
|
66
|
-
Digest::SHA256.digest(@password)
|
66
|
+
Digest::SHA256.digest(@password.respond_to?(:call) ? @password.call : @password)
|
67
67
|
end
|
68
68
|
|
69
69
|
def escape(value)
|
@@ -108,11 +108,25 @@ module Seekrit
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def decrypt(data)
|
111
|
+
err = nil
|
112
|
+
3.times do
|
113
|
+
begin
|
114
|
+
k = @correct_key || crypt_key
|
115
|
+
decrypted = decrypt_once(data, k)
|
116
|
+
@correct_key ||= k
|
117
|
+
return decrypted
|
118
|
+
rescue DecryptionError => err
|
119
|
+
end
|
120
|
+
end
|
121
|
+
raise err
|
122
|
+
end
|
123
|
+
|
124
|
+
def decrypt_once(data, key)
|
111
125
|
cipher = OpenSSL::Cipher::Cipher.new(@cipher)
|
112
126
|
iv = data[0, cipher.iv_len]
|
113
127
|
ciphertext = data[cipher.iv_len..-1]
|
114
128
|
cipher.decrypt
|
115
|
-
cipher.key =
|
129
|
+
cipher.key = key
|
116
130
|
cipher.iv = iv
|
117
131
|
plaintext = cipher.update(ciphertext)
|
118
132
|
plaintext << cipher.final
|
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: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Battley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-07 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|