legion-crypt 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.idea/legion-crypt.iml +44 -35
- data/.rubocop.yml +9 -0
- data/Gemfile +1 -0
- data/README.md +5 -1
- data/legion-crypt.gemspec +5 -5
- data/lib/legion/crypt.rb +7 -9
- data/lib/legion/crypt/box.rb +1 -1
- data/lib/legion/crypt/cipher.rb +90 -0
- data/lib/legion/crypt/settings.rb +2 -2
- data/lib/legion/crypt/vault.rb +13 -6
- data/lib/legion/crypt/vault_renewer.rb +5 -1
- data/lib/legion/crypt/version.rb +1 -1
- metadata +12 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd2d51f77fcc6ca9912e92fbc1a7aa633182d17c503d8ae9b0c130de46e9c3d6
|
|
4
|
+
data.tar.gz: f2973995be01490a44a894e52809391c40e0dcfce69b3f6517a2c662f3b30f99
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52d19767ddc8bf1d5919c63176118cb6160179dea6670c7ac513cc6895d0c3fab7d2d7a0588475176fc392e9d7d952668b80449b101768c72b3130a5e5f74e5e
|
|
7
|
+
data.tar.gz: '088e8074518db4634c575e5f409eac8a890c40b84ba6445ab6eb7ff4c0505b5f4abad62a7dd4f2a274426e7df98aec9bae3d0b9d5a66b93535aea311670f3e47'
|
data/.idea/legion-crypt.iml
CHANGED
|
@@ -5,41 +5,50 @@
|
|
|
5
5
|
</component>
|
|
6
6
|
<component name="NewModuleRootManager">
|
|
7
7
|
<content url="file://$MODULE_DIR$" />
|
|
8
|
-
<orderEntry type="
|
|
8
|
+
<orderEntry type="jdk" jdkName="RVM: ruby-2.7.0" jdkType="RUBY_SDK" />
|
|
9
9
|
<orderEntry type="sourceFolder" forTests="false" />
|
|
10
|
-
<orderEntry type="library" scope="PROVIDED" name="amq-protocol (v2.3.
|
|
11
|
-
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.
|
|
12
|
-
<orderEntry type="library" scope="PROVIDED" name="aws-eventstream (v1.0
|
|
13
|
-
<orderEntry type="library" scope="PROVIDED" name="aws-sigv4 (v1.
|
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, RVM: ruby-2.
|
|
15
|
-
<orderEntry type="library" scope="PROVIDED" name="bunny (v2.
|
|
16
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
17
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
18
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
20
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
21
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
22
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
23
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
24
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
25
|
-
<orderEntry type="library" scope="PROVIDED" name="legion-
|
|
26
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
27
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
28
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
29
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
30
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
31
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
32
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
33
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
34
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
35
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
36
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
37
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
38
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
39
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
40
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
41
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
42
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
43
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
10
|
+
<orderEntry type="library" scope="PROVIDED" name="amq-protocol (v2.3.2, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
11
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
12
|
+
<orderEntry type="library" scope="PROVIDED" name="aws-eventstream (v1.1.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
13
|
+
<orderEntry type="library" scope="PROVIDED" name="aws-sigv4 (v1.2.2, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="bunny (v2.16.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="chef (v16.1.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.7, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby-ext (v1.1.7, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="connection_pool (v2.2.3, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="daemons (v1.3.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="dalli (v2.7.10, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="ffi (v1.13.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="hashdiff (v1.0.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="legion-cache (v1.0.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="legion-data (v0.2.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="legion-exceptions (v1.1.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="legion-json (v1.1.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="legion-logging (v1.1.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="legion-settings (v1.1.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="legion-transport (v1.1.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.15.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="mysql2 (v0.5.3, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.19.2, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v2.7.1.4, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="rbnacl (v7.1.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="redis (v4.2.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v1.7.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.4, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.9.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.9.2, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.9.2, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.9.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
46
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.9.3, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
47
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.89.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v0.3.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
49
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.10.1, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
50
|
+
<orderEntry type="library" scope="PROVIDED" name="sequel (v5.35.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
51
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v1.7.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
52
|
+
<orderEntry type="library" scope="PROVIDED" name="vault (v0.15.0, RVM: ruby-2.7.0) [gem]" level="application" />
|
|
44
53
|
</component>
|
|
45
54
|
</module>
|
data/.rubocop.yml
CHANGED
|
@@ -6,6 +6,14 @@ Metrics/ClassLength:
|
|
|
6
6
|
Max: 1500
|
|
7
7
|
Metrics/BlockLength:
|
|
8
8
|
Max: 50
|
|
9
|
+
Metrics/CyclomaticComplexity:
|
|
10
|
+
Max: 15
|
|
11
|
+
Metrics/AbcSize:
|
|
12
|
+
Max: 20
|
|
13
|
+
Metrics/PerceivedComplexity:
|
|
14
|
+
Max: 15
|
|
15
|
+
Naming/MethodParameterName:
|
|
16
|
+
Enabled: false
|
|
9
17
|
Layout/SpaceAroundEqualsInParameterDefault:
|
|
10
18
|
EnforcedStyle: space
|
|
11
19
|
Style/SymbolArray:
|
|
@@ -17,6 +25,7 @@ Style/Documentation:
|
|
|
17
25
|
Enabled: false
|
|
18
26
|
AllCops:
|
|
19
27
|
TargetRubyVersion: 2.5
|
|
28
|
+
NewCops: enable
|
|
20
29
|
Style/FrozenStringLiteralComment:
|
|
21
30
|
Enabled: false
|
|
22
31
|
Naming/FileName:
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -22,7 +22,11 @@ Or install it yourself as:
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Ciper class
|
|
26
|
+
1) check to see if connected to vault, if so, use that
|
|
27
|
+
2) check to see if it was set via config
|
|
28
|
+
3) request it from the cluster
|
|
29
|
+
4) generate it
|
|
26
30
|
|
|
27
31
|
## Development
|
|
28
32
|
|
data/legion-crypt.gemspec
CHANGED
|
@@ -28,12 +28,12 @@ Gem::Specification.new do |spec|
|
|
|
28
28
|
spec.add_dependency 'rbnacl'
|
|
29
29
|
spec.add_dependency 'vault'
|
|
30
30
|
|
|
31
|
-
spec.add_development_dependency 'legion'
|
|
32
|
-
spec.add_development_dependency 'legion-
|
|
33
|
-
spec.add_development_dependency 'legion-
|
|
34
|
-
spec.add_development_dependency '
|
|
31
|
+
spec.add_development_dependency 'legion-logging'
|
|
32
|
+
spec.add_development_dependency 'legion-settings'
|
|
33
|
+
spec.add_development_dependency 'legion-transport'
|
|
34
|
+
# spec.add_development_dependency 'legionio'
|
|
35
35
|
spec.add_development_dependency 'rake'
|
|
36
36
|
spec.add_development_dependency 'rspec'
|
|
37
37
|
spec.add_development_dependency 'rubocop'
|
|
38
|
-
spec.add_development_dependency 'simplecov'
|
|
38
|
+
# spec.add_development_dependency 'simplecov', '< 0.18.0'
|
|
39
39
|
end
|
data/lib/legion/crypt.rb
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'openssl'
|
|
3
4
|
require 'legion/crypt/version'
|
|
4
5
|
require 'legion/crypt/settings'
|
|
5
6
|
require 'rbnacl'
|
|
6
7
|
require 'base64'
|
|
7
8
|
|
|
8
9
|
require 'legion/crypt/box'
|
|
10
|
+
require 'legion/crypt/cipher'
|
|
9
11
|
require 'legion/crypt/vault'
|
|
10
12
|
|
|
11
13
|
module Legion
|
|
12
14
|
module Crypt
|
|
13
15
|
class << self
|
|
14
|
-
attr_reader :
|
|
15
|
-
|
|
16
|
+
attr_reader :sessions
|
|
17
|
+
|
|
18
|
+
include Legion::Crypt::Cipher
|
|
16
19
|
include Legion::Crypt::Vault if Legion::Settings[:crypt][:vault][:enabled]
|
|
17
20
|
|
|
18
21
|
def start
|
|
19
22
|
Legion::Logging.debug 'Legion::Crypt is running start'
|
|
20
|
-
if Dir.exist?('./settings') && File.exist?('./settings/private.key') && File.exist?('./settings/public.key')
|
|
21
|
-
load_keys
|
|
22
|
-
else
|
|
23
|
-
delete_keys if Dir.exist? './settings'
|
|
24
|
-
create_keys
|
|
25
|
-
end
|
|
23
|
+
# load_keys if Dir.exist?('./settings') && File.exist?('./settings/private.key') && File.exist?('./settings/public.key')
|
|
26
24
|
|
|
27
|
-
connect_vault
|
|
25
|
+
# connect_vault unless Legion::Settings[:crypt][:vault][:token].nil?
|
|
28
26
|
end
|
|
29
27
|
|
|
30
28
|
def shutdown
|
data/lib/legion/crypt/box.rb
CHANGED
|
@@ -47,7 +47,7 @@ module Legion
|
|
|
47
47
|
@box.decrypt(Base64.decode64(message))
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
def setup_safe # rubocop:disable Metrics/
|
|
50
|
+
def setup_safe # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity
|
|
51
51
|
Legion::Logging.debug 'Setting up Legion::Crypt safe'
|
|
52
52
|
if Legion::Settings[:crypt][:cluster_secret].nil?
|
|
53
53
|
if Legion::Settings[:crypt][:vault][:connected] && Legion::Crypt.exist?('crypt')
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'securerandom'
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Crypt
|
|
5
|
+
module Cipher
|
|
6
|
+
def encrypt(message)
|
|
7
|
+
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
|
8
|
+
cipher.encrypt
|
|
9
|
+
cipher.key = cs
|
|
10
|
+
iv = cipher.random_iv
|
|
11
|
+
{ enciphered_message: Base64.encode64(cipher.update(message) + cipher.final), iv: Base64.encode64(iv) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def decrypt(message, iv)
|
|
15
|
+
until cs.is_a?(String) || Legion::Settings[:client][:shutting_down]
|
|
16
|
+
Legion::Logging.debug('sleeping Legion::Crypt.decrypt due to CS not being set')
|
|
17
|
+
sleep(0.5)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
decipher = OpenSSL::Cipher.new('aes-256-cbc')
|
|
21
|
+
decipher.decrypt
|
|
22
|
+
decipher.key = cs
|
|
23
|
+
decipher.iv = Base64.decode64(iv)
|
|
24
|
+
message = Base64.decode64(message)
|
|
25
|
+
decipher.update(message) + decipher.final
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def encrypt_from_keypair(message:, pub_key: public_key)
|
|
29
|
+
rsa_public_key = OpenSSL::PKey::RSA.new(pub_key)
|
|
30
|
+
|
|
31
|
+
Base64.encode64(rsa_public_key.public_encrypt(message))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def decrypt_from_keypair(message:, **_opts)
|
|
35
|
+
private_key.private_decrypt(Base64.decode64(message))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def public_key
|
|
39
|
+
@public_key ||= private_key.public_key.to_s
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def private_key
|
|
43
|
+
@private_key ||= OpenSSL::PKey::RSA.new 2048
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def cs
|
|
47
|
+
@cs ||= Digest::SHA256.digest fetch_cs
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def fetch_cs # rubocop:disable Metrics/AbcSize
|
|
51
|
+
if Legion::Settings[:crypt][:vault][:read_cluster_secret] && Legion::Settings[:crypt][:vault][:connected] && Legion::Crypt.exist?('crypt') # rubocop:disable Layout/LineLength
|
|
52
|
+
Legion::Crypt.get('crypt')[:cluster_secret]
|
|
53
|
+
elsif Legion::Settings[:crypt][:cluster_secret].is_a? String
|
|
54
|
+
Legion::Settings[:crypt][:cluster_secret]
|
|
55
|
+
elsif Legion::Transport::Queue.new('node.crypt', passive: true).consumer_count.zero?
|
|
56
|
+
Legion::Settings[:crypt][:cluster_secret] = generate_secure_random
|
|
57
|
+
elsif Legion::Transport::Queue.new('node.crypt', passive: true).consumer_count.positive?
|
|
58
|
+
require 'legion/transport/messages/request_cluster_secret'
|
|
59
|
+
Legion::Logging.info 'Requesting cluster secret via public key'
|
|
60
|
+
start = Time.now
|
|
61
|
+
Legion::Transport::Messages::RequestClusterSecret.new.publish
|
|
62
|
+
sleep_time = 0.001
|
|
63
|
+
until !Legion::Settings[:crypt][:cluster_secret].nil? || (Time.now - start) > Legion::Settings[:crypt][:cluster_secret_timeout]
|
|
64
|
+
sleep(sleep_time)
|
|
65
|
+
sleep_time *= 2 unless sleep_time > 0.5
|
|
66
|
+
end
|
|
67
|
+
unless Legion::Settings[:crypt][:cluster_secret].nil?
|
|
68
|
+
Legion::Logging.info "Received cluster secret in #{((Time.new - start) * 1000.0).round}ms"
|
|
69
|
+
end
|
|
70
|
+
Legion::Logging.warn 'Cluster secret is still nil' if Legion::Settings[:crypt][:cluster_secret].nil?
|
|
71
|
+
else
|
|
72
|
+
Legion::Settings[:crypt][:cluster_secret] = generate_secure_random
|
|
73
|
+
end
|
|
74
|
+
Legion::Settings[:crypt][:cs_encrypt_ready] = true
|
|
75
|
+
Legion::Settings[:crypt][:cluster_secret]
|
|
76
|
+
rescue StandardError => e
|
|
77
|
+
Legion::Logging.error(e.message)
|
|
78
|
+
Legion::Logging.error(e.backtrace)
|
|
79
|
+
|
|
80
|
+
Legion::Settings[:crypt][:cluster_secret] = generate_secure_random
|
|
81
|
+
Legion::Settings[:crypt][:cs_encrypt_ready] = true
|
|
82
|
+
Legion::Settings[:crypt][:cluster_secret]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def generate_secure_random
|
|
86
|
+
SecureRandom.alphanumeric(32)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
data/lib/legion/crypt/vault.rb
CHANGED
|
@@ -4,6 +4,7 @@ module Legion
|
|
|
4
4
|
module Crypt
|
|
5
5
|
module Vault
|
|
6
6
|
attr_accessor :sessions
|
|
7
|
+
|
|
7
8
|
def settings
|
|
8
9
|
Legion::Settings[:crypt][:vault]
|
|
9
10
|
end
|
|
@@ -23,24 +24,28 @@ module Legion
|
|
|
23
24
|
@renewer = Legion::Crypt::Vault::Renewer.new
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
def read(path, type = '
|
|
27
|
-
|
|
27
|
+
def read(path, type = 'legion')
|
|
28
|
+
full_path = type.nil? || type.empty? ? "#{type}/#{path}" : path
|
|
29
|
+
lease = ::Vault.logical.read(full_path)
|
|
28
30
|
add_session(path: lease.lease_id) if lease.respond_to? :lease_id
|
|
29
31
|
lease.data
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
def get(path)
|
|
33
|
-
::Vault.kv('
|
|
35
|
+
result = ::Vault.kv('legion').read(path)
|
|
36
|
+
return nil if result.nil?
|
|
37
|
+
|
|
38
|
+
result.data
|
|
34
39
|
end
|
|
35
40
|
|
|
36
41
|
def write(path, key, value)
|
|
37
42
|
hash = {}
|
|
38
43
|
hash[key.to_sym] = value
|
|
39
|
-
::Vault.kv('
|
|
44
|
+
::Vault.kv('legion').write(path, **hash)
|
|
40
45
|
end
|
|
41
46
|
|
|
42
47
|
def exist?(path)
|
|
43
|
-
!::Vault.kv('
|
|
48
|
+
!::Vault.kv('legion').read_metadata(path).nil?
|
|
44
49
|
end
|
|
45
50
|
|
|
46
51
|
def add_session(path:)
|
|
@@ -49,6 +54,8 @@ module Legion
|
|
|
49
54
|
|
|
50
55
|
def close_sessions
|
|
51
56
|
Legion::Logging.info 'Closing all Legion::Crypt vault sessions'
|
|
57
|
+
return if @sessions.nil?
|
|
58
|
+
|
|
52
59
|
@sessions.each do |session|
|
|
53
60
|
close_session(session: session)
|
|
54
61
|
end
|
|
@@ -70,7 +77,7 @@ module Legion
|
|
|
70
77
|
::Vault.sys.renew(session)
|
|
71
78
|
end
|
|
72
79
|
|
|
73
|
-
def renew_sessions
|
|
80
|
+
def renew_sessions(**_opts)
|
|
74
81
|
@sessions.each do |session|
|
|
75
82
|
renew_session(session: session)
|
|
76
83
|
end
|
data/lib/legion/crypt/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: legion-crypt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Esity
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rbnacl
|
|
@@ -39,7 +39,7 @@ dependencies:
|
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: legion
|
|
42
|
+
name: legion-logging
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - ">="
|
|
@@ -52,48 +52,34 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: legion-logging
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - ">="
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: 1.0.0
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - ">="
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: 1.0.0
|
|
69
55
|
- !ruby/object:Gem::Dependency
|
|
70
56
|
name: legion-settings
|
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
|
72
58
|
requirements:
|
|
73
59
|
- - ">="
|
|
74
60
|
- !ruby/object:Gem::Version
|
|
75
|
-
version:
|
|
61
|
+
version: '0'
|
|
76
62
|
type: :development
|
|
77
63
|
prerelease: false
|
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
65
|
requirements:
|
|
80
66
|
- - ">="
|
|
81
67
|
- !ruby/object:Gem::Version
|
|
82
|
-
version:
|
|
68
|
+
version: '0'
|
|
83
69
|
- !ruby/object:Gem::Dependency
|
|
84
70
|
name: legion-transport
|
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
|
86
72
|
requirements:
|
|
87
73
|
- - ">="
|
|
88
74
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 0
|
|
75
|
+
version: '0'
|
|
90
76
|
type: :development
|
|
91
77
|
prerelease: false
|
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
79
|
requirements:
|
|
94
80
|
- - ">="
|
|
95
81
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 0
|
|
82
|
+
version: '0'
|
|
97
83
|
- !ruby/object:Gem::Dependency
|
|
98
84
|
name: rake
|
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -136,20 +122,6 @@ dependencies:
|
|
|
136
122
|
- - ">="
|
|
137
123
|
- !ruby/object:Gem::Version
|
|
138
124
|
version: '0'
|
|
139
|
-
- !ruby/object:Gem::Dependency
|
|
140
|
-
name: simplecov
|
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
|
142
|
-
requirements:
|
|
143
|
-
- - ">="
|
|
144
|
-
- !ruby/object:Gem::Version
|
|
145
|
-
version: '0'
|
|
146
|
-
type: :development
|
|
147
|
-
prerelease: false
|
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
-
requirements:
|
|
150
|
-
- - ">="
|
|
151
|
-
- !ruby/object:Gem::Version
|
|
152
|
-
version: '0'
|
|
153
125
|
description: Integrates with Hashicorps vault and other encryption type things
|
|
154
126
|
email:
|
|
155
127
|
- matthewdiverson@gmail.com
|
|
@@ -176,6 +148,7 @@ files:
|
|
|
176
148
|
- legion-crypt.gemspec
|
|
177
149
|
- lib/legion/crypt.rb
|
|
178
150
|
- lib/legion/crypt/box.rb
|
|
151
|
+
- lib/legion/crypt/cipher.rb
|
|
179
152
|
- lib/legion/crypt/settings.rb
|
|
180
153
|
- lib/legion/crypt/vault.rb
|
|
181
154
|
- lib/legion/crypt/vault_renewer.rb
|
|
@@ -187,7 +160,7 @@ metadata:
|
|
|
187
160
|
homepage_uri: https://bitbucket.org/legion-io/legion-vault/
|
|
188
161
|
source_code_uri: https://bitbucket.org/legion-io/legion/
|
|
189
162
|
changelog_uri: https://bitbucket.org/legion-io/legion/src/master/CHANGELOG.md
|
|
190
|
-
post_install_message:
|
|
163
|
+
post_install_message:
|
|
191
164
|
rdoc_options: []
|
|
192
165
|
require_paths:
|
|
193
166
|
- lib
|
|
@@ -202,8 +175,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
202
175
|
- !ruby/object:Gem::Version
|
|
203
176
|
version: '0'
|
|
204
177
|
requirements: []
|
|
205
|
-
rubygems_version: 3.
|
|
206
|
-
signing_key:
|
|
178
|
+
rubygems_version: 3.1.2
|
|
179
|
+
signing_key:
|
|
207
180
|
specification_version: 4
|
|
208
181
|
summary: Legion::Vault is used to keep things safe
|
|
209
182
|
test_files: []
|