rapid-vaults 1.3.1 → 1.3.2
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/CHANGELOG.md +6 -0
- data/lib/rapid-vaults/binding.rb +2 -2
- data/lib/rapid-vaults/bindings/puppet_ssl_decrypt.rb +1 -1
- data/lib/rapid-vaults/bindings/puppet_ssl_encrypt.rb +1 -1
- data/lib/rapid-vaults/cli.rb +2 -1
- data/lib/rapid-vaults/decrypt.rb +22 -4
- data/lib/rapid-vaults/encrypt.rb +24 -5
- data/lib/rapid-vaults/generate.rb +18 -3
- data/lib/rapid_vaults.rb +0 -1
- data/rapid-vaults.gemspec +1 -1
- data/spec/rapid-vaults/binding_spec.rb +2 -2
- data/spec/rapid-vaults/cli_spec.rb +4 -1
- data/spec/rapid-vaults/decrypt_spec.rb +10 -14
- data/spec/rapid-vaults/encrypt_spec.rb +9 -9
- data/spec/rapid-vaults/generate_spec.rb +9 -9
- data/spec/rapid_vaults_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -6
- data/spec/system/system_spec.rb +14 -14
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b0cdeb7f71f3f2a7ded9f820beb5ca0783be43de7601b513dfc678d78cc838d
|
|
4
|
+
data.tar.gz: b5b89f9d9842f9e52272e146635dcb173b3cbe6213b20b057e8d431f175fe318
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2499dc4629ed310eda5a6dc925576b7eba089ea541864ae43adbcb925162e77c97d6cc0a81c52d0b5052a9f809aa1a1e44e9173ae463b32213b0fab00ca87c56
|
|
7
|
+
data.tar.gz: dce32b3c164c16779bbaee284987d3884f8304f197d215d51c5a7ce9c68966afe114225ca1c0e8c66be5dc3bf8cb04a50d0fea461d5e8d32a2c71cac13aa99f1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
### 1.3.2
|
|
2
|
+
- Add `--force` CLI flag, and do not overwrite files by default.
|
|
3
|
+
- Improve output file pathing.
|
|
4
|
+
- Fix password file setting in Puppet bindings.
|
|
5
|
+
- Fix longform output directory CLI argument.
|
|
6
|
+
|
|
1
7
|
### 1.3.1
|
|
2
8
|
- Fix GPG keys output path message.
|
|
3
9
|
- Fix encrypted data validation.
|
data/lib/rapid-vaults/binding.rb
CHANGED
|
@@ -10,7 +10,7 @@ class Binding
|
|
|
10
10
|
CRYPT.each do |algo|
|
|
11
11
|
ACTION.each do |action|
|
|
12
12
|
content = File.read("#{__dir__}/bindings/puppet_#{algo}_#{action}.rb")
|
|
13
|
-
File.write(
|
|
13
|
+
File.write(File.join(settings[:outdir], "puppet_#{algo}_#{action}.rb"), content)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|
|
@@ -19,6 +19,6 @@ class Binding
|
|
|
19
19
|
def self.chef(settings)
|
|
20
20
|
# output chef bindings to output directory
|
|
21
21
|
content = File.read("#{__dir__}/bindings/chef.rb")
|
|
22
|
-
File.write(
|
|
22
|
+
File.write(File.join(settings[:outdir], 'chef.rb'), content)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -28,7 +28,7 @@ Puppet::Functions.create_function(:ssl_decrypt) do
|
|
|
28
28
|
# initialize settings
|
|
29
29
|
settings = { action: :decrypt, file: file, key: key, nonce: nonce, tag: tag }
|
|
30
30
|
# update settings with password if input
|
|
31
|
-
settings[pw
|
|
31
|
+
settings[:pw] = File.read(password_file) unless password_file.nil?
|
|
32
32
|
|
|
33
33
|
RapidVaults::API.main(settings)
|
|
34
34
|
end
|
|
@@ -27,7 +27,7 @@ Puppet::Functions.create_function(:ssl_encrypt) do
|
|
|
27
27
|
settings = { action: :encrypt, file: file, key: key, nonce: nonce }
|
|
28
28
|
return_hash = {}
|
|
29
29
|
# update settings with password if input
|
|
30
|
-
settings[pw
|
|
30
|
+
settings[:pw] = File.read(password_file) unless password_file.nil?
|
|
31
31
|
|
|
32
32
|
return_hash[:encrypted_contents], return_hash[:tag] = RapidVaults::API.main(settings)
|
|
33
33
|
|
data/lib/rapid-vaults/cli.rb
CHANGED
|
@@ -70,10 +70,11 @@ class RapidVaults::CLI
|
|
|
70
70
|
raise "GPG Parameters file #{arg} is not an existing readable file!" unless File.readable?(arg)
|
|
71
71
|
settings[:gpgparams] = File.read(arg)
|
|
72
72
|
end
|
|
73
|
-
opts.on('-o --outdir', String, 'Optional output directory for generated files (default: pwd). (GPG: optional)') do |arg|
|
|
73
|
+
opts.on('-o', '--outdir output_directory', String, 'Optional output directory for generated files (default: pwd). (GPG: optional)') do |arg|
|
|
74
74
|
raise "The output directory #{arg} does not exist or is not a directory!" unless File.directory?(arg)
|
|
75
75
|
settings[:outdir] = arg
|
|
76
76
|
end
|
|
77
|
+
opts.on('--force', 'Force overwrite of existing files during generation, encryption, and decryption.') { settings[:force] = true }
|
|
77
78
|
end
|
|
78
79
|
|
|
79
80
|
# parse args and return settings
|
data/lib/rapid-vaults/decrypt.rb
CHANGED
|
@@ -14,9 +14,18 @@ class Decrypt
|
|
|
14
14
|
# output the decryption
|
|
15
15
|
case settings[:ui]
|
|
16
16
|
when :cli
|
|
17
|
+
# efficiency assignment
|
|
18
|
+
outdir = settings[:outdir]
|
|
19
|
+
decryptfile = File.join(outdir, 'decrypted.txt')
|
|
20
|
+
|
|
21
|
+
# check if already exists and no force flag
|
|
22
|
+
if File.exist?(decryptfile)
|
|
23
|
+
raise "decrypted.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
|
|
24
|
+
end
|
|
25
|
+
|
|
17
26
|
# output to file
|
|
18
|
-
File.write(
|
|
19
|
-
puts "Your decrypted.txt has been written out to #{
|
|
27
|
+
File.write(decryptfile, decipher.update(settings[:file]) + decipher.final)
|
|
28
|
+
puts "Your decrypted.txt has been written out to #{outdir}."
|
|
20
29
|
when :api
|
|
21
30
|
# output to string
|
|
22
31
|
decipher.update(settings[:file]) + decipher.final
|
|
@@ -37,9 +46,18 @@ class Decrypt
|
|
|
37
46
|
# output the decryption
|
|
38
47
|
case settings[:ui]
|
|
39
48
|
when :cli
|
|
49
|
+
# efficiency assignment
|
|
50
|
+
outdir = settings[:outdir]
|
|
51
|
+
decryptfile = File.join(outdir, 'decrypted.txt')
|
|
52
|
+
|
|
53
|
+
# check if already exists and no force flag
|
|
54
|
+
if File.exist?(decryptfile)
|
|
55
|
+
raise "decrypted.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
|
|
56
|
+
end
|
|
57
|
+
|
|
40
58
|
# output to file
|
|
41
|
-
File.write(
|
|
42
|
-
puts "Your decrypted.txt has been written out to #{
|
|
59
|
+
File.write(decryptfile, crypto.decrypt(encrypted, password: settings[:pw]).read)
|
|
60
|
+
puts "Your decrypted.txt has been written out to #{outdir}."
|
|
43
61
|
when :api
|
|
44
62
|
# output to string
|
|
45
63
|
crypto.decrypt(encrypted, password: settings[:pw]).read
|
data/lib/rapid-vaults/encrypt.rb
CHANGED
|
@@ -13,10 +13,20 @@ class Encrypt
|
|
|
13
13
|
# output the encryption and associated tag
|
|
14
14
|
case settings[:ui]
|
|
15
15
|
when :cli
|
|
16
|
+
# efficiency assignment
|
|
17
|
+
outdir = settings[:outdir]
|
|
18
|
+
encryptfile = File.join(outdir, 'encrypted.txt')
|
|
19
|
+
tagfile = File.join(outdir, 'tag.txt')
|
|
20
|
+
|
|
21
|
+
# check if already exists and no force flag
|
|
22
|
+
if File.exist?(encryptfile) || File.exist?(tagfile)
|
|
23
|
+
raise "encrypted.txt or tag.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
|
|
24
|
+
end
|
|
25
|
+
|
|
16
26
|
# output to file
|
|
17
|
-
File.write(
|
|
18
|
-
File.write(
|
|
19
|
-
puts "Your encrypted.txt and associated tag.txt for this encryption have been generated in #{
|
|
27
|
+
File.write(encryptfile, cipher.update(settings[:file]) + cipher.final)
|
|
28
|
+
File.write(tagfile, cipher.auth_tag)
|
|
29
|
+
puts "Your encrypted.txt and associated tag.txt for this encryption have been generated in #{outdir}."
|
|
20
30
|
when :api
|
|
21
31
|
# return as array
|
|
22
32
|
[cipher.update(settings[:file]) + cipher.final, cipher.auth_tag]
|
|
@@ -36,9 +46,18 @@ class Encrypt
|
|
|
36
46
|
# output the encryption and associated tag
|
|
37
47
|
case settings[:ui]
|
|
38
48
|
when :cli
|
|
49
|
+
# efficiency assignment
|
|
50
|
+
outdir = settings[:outdir]
|
|
51
|
+
encryptfile = File.join(outdir, 'encrypted.txt')
|
|
52
|
+
|
|
53
|
+
# check if already exists and no force flag
|
|
54
|
+
if File.exist?(encryptfile)
|
|
55
|
+
raise "encrypted.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
|
|
56
|
+
end
|
|
57
|
+
|
|
39
58
|
# output to file
|
|
40
|
-
File.write(
|
|
41
|
-
puts "Your encrypted.txt for this encryption has been generated in #{
|
|
59
|
+
File.write(encryptfile, crypto.encrypt(settings[:file], symmetric: true, password: settings[:pw]).read)
|
|
60
|
+
puts "Your encrypted.txt for this encryption has been generated in #{outdir}."
|
|
42
61
|
when :api
|
|
43
62
|
# return as string
|
|
44
63
|
crypto.encrypt(settings[:file], symmetric: true, password: settings[:pw]).read
|
|
@@ -9,10 +9,20 @@ class Generate
|
|
|
9
9
|
|
|
10
10
|
case settings[:ui]
|
|
11
11
|
when :cli
|
|
12
|
+
# efficiency assignment
|
|
13
|
+
outdir = settings[:outdir]
|
|
14
|
+
keyfile = File.join(outdir, 'key.txt')
|
|
15
|
+
noncefile = File.join(outdir, 'nonce.txt')
|
|
16
|
+
|
|
17
|
+
# check if already exists and no force flag
|
|
18
|
+
if File.exist?(keyfile) || File.exist?(noncefile)
|
|
19
|
+
raise "key.txt or nonce.txt already exists in #{outdir}. Use the --force flag to overwrite existing files." unless settings[:force]
|
|
20
|
+
end
|
|
21
|
+
|
|
12
22
|
# output to file
|
|
13
|
-
File.write(
|
|
14
|
-
File.write(
|
|
15
|
-
puts "Your key.txt and nonce.txt have been generated in #{
|
|
23
|
+
File.write(keyfile, cipher.random_key)
|
|
24
|
+
File.write(noncefile, cipher.random_iv)
|
|
25
|
+
puts "Your key.txt and nonce.txt have been generated in #{outdir}."
|
|
16
26
|
when :api
|
|
17
27
|
# return as array
|
|
18
28
|
[cipher.random_key, cipher.random_iv]
|
|
@@ -26,6 +36,11 @@ class Generate
|
|
|
26
36
|
# ensure we have a place to store these output files
|
|
27
37
|
raise 'Environment variable "GNUPGHOME" was not set.' unless ENV.fetch('GNUPGHOME', false)
|
|
28
38
|
|
|
39
|
+
# check if already exists and no force flag
|
|
40
|
+
if Dir.exist?(ENV['GNUPGHOME']) && !Dir.empty?(ENV['GNUPGHOME'])
|
|
41
|
+
raise "GPG keyring in #{ENV['GNUPGHOME']} already exists and is not empty. Use the --force flag to overwrite existing files." unless settings[:force]
|
|
42
|
+
end
|
|
43
|
+
|
|
29
44
|
# create gpg keys
|
|
30
45
|
GPGME::Ctx.new.generate_key(settings[:gpgparams], nil, nil)
|
|
31
46
|
puts "Your GPG keys have been generated in #{ENV.fetch('GNUPGHOME')}." if settings[:ui] == :cli
|
data/lib/rapid_vaults.rb
CHANGED
data/rapid-vaults.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |spec|
|
|
2
2
|
spec.name = 'rapid-vaults'
|
|
3
|
-
spec.version = '1.3.
|
|
3
|
+
spec.version = '1.3.2'
|
|
4
4
|
spec.authors = ['Matt Schuchard']
|
|
5
5
|
spec.description = 'Ad-hoc encrypt and decrypt data behind multiple layers of protection via OpenSSL or GPG.'
|
|
6
6
|
spec.summary = 'Ad-hoc encrypt and decrypt data.'
|
|
@@ -8,7 +8,7 @@ describe Binding do
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it 'outputs the puppet bindings to the specified directory' do
|
|
11
|
-
Binding.puppet({})
|
|
11
|
+
Binding.puppet({outdir: Dir.pwd})
|
|
12
12
|
%w[puppet_gpg_decrypt.rb puppet_gpg_encrypt.rb puppet_ssl_decrypt.rb puppet_ssl_encrypt.rb].each do |file|
|
|
13
13
|
expect(File.file?(file)).to be true
|
|
14
14
|
end
|
|
@@ -21,7 +21,7 @@ describe Binding do
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it 'outputs the chef bindings to the specified directory' do
|
|
24
|
-
Binding.chef({})
|
|
24
|
+
Binding.chef({outdir: Dir.pwd})
|
|
25
25
|
expect(File.file?('chef.rb')).to be true
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -16,11 +16,14 @@ describe RapidVaults::CLI do
|
|
|
16
16
|
expect(RapidVaults::CLI.parse(%w[-g -o .])).to eq(ui: :cli, action: :generate, outdir: '.')
|
|
17
17
|
end
|
|
18
18
|
it 'correctly parses the arguments for gpg generate' do
|
|
19
|
-
expect(RapidVaults::CLI.parse(%W[--gpg -g --gpgparams #{
|
|
19
|
+
expect(RapidVaults::CLI.parse(%W[--gpg -g --gpgparams #{FIXTURES_DIR}/file.yaml])).to eq(algorithm: :gpgme, ui: :cli, action: :generate, gpgparams: "foo: bar\n")
|
|
20
20
|
end
|
|
21
21
|
it 'correctly parses the arguments for puppet bindings' do
|
|
22
22
|
expect(RapidVaults::CLI.parse(%w[-b puppet -o .])).to eq(ui: :cli, action: :binding, binding: :puppet, outdir: '.')
|
|
23
23
|
end
|
|
24
|
+
it 'correctly parses the arguments with force option' do
|
|
25
|
+
expect(RapidVaults::CLI.parse(%w[--force])).to eq(ui: :cli, force: true)
|
|
26
|
+
end
|
|
24
27
|
it 'raises an error for a nonexistent password file' do
|
|
25
28
|
expect { RapidVaults::CLI.parse(%w[-f /nopasswordhere]) }.to raise_error('Password file /nopasswordhere is not an existing readable file!')
|
|
26
29
|
end
|
|
@@ -3,6 +3,10 @@ require_relative '../../lib/rapid-vaults/encrypt'
|
|
|
3
3
|
require_relative '../../lib/rapid-vaults/decrypt'
|
|
4
4
|
|
|
5
5
|
describe Decrypt do
|
|
6
|
+
after(:all) do
|
|
7
|
+
%w[tag.txt encrypted.txt decrypted.txt].each { |file| File.delete(file) }
|
|
8
|
+
end
|
|
9
|
+
|
|
6
10
|
context '.openssl' do
|
|
7
11
|
require 'openssl'
|
|
8
12
|
cipher = OpenSSL::Cipher.new('aes-256-gcm').encrypt
|
|
@@ -10,20 +14,16 @@ describe Decrypt do
|
|
|
10
14
|
nonce = cipher.random_iv
|
|
11
15
|
|
|
12
16
|
before(:all) do
|
|
13
|
-
Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
after(:all) do
|
|
17
|
-
%w[tag.txt encrypted.txt decrypted.txt].each { |file| File.delete(file) }
|
|
17
|
+
Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce, outdir: Dir.pwd)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'outputs a decrypted file with the key, nonce, and tag from the cli' do
|
|
21
|
-
Decrypt.openssl(ui: :cli, file: File.read('encrypted.txt'), key: key, nonce: nonce, tag: File.read('tag.txt'))
|
|
21
|
+
Decrypt.openssl(ui: :cli, file: File.read('encrypted.txt'), key: key, nonce: nonce, tag: File.read('tag.txt'), outdir: Dir.pwd)
|
|
22
22
|
expect(File.file?('decrypted.txt')).to be true
|
|
23
23
|
expect(File.read('decrypted.txt')).to eq("foo: bar\n")
|
|
24
24
|
end
|
|
25
25
|
it 'outputs decrypted content with the key, nonce, and tag from the api' do
|
|
26
|
-
decrypt = Decrypt.openssl(ui: :api, file: File.read('encrypted.txt'), key: key, nonce: nonce, tag: File.read('tag.txt'))
|
|
26
|
+
decrypt = Decrypt.openssl(ui: :api, file: File.read('encrypted.txt'), key: key, nonce: nonce, tag: File.read('tag.txt'), outdir: Dir.pwd)
|
|
27
27
|
expect(decrypt).to be_a(String)
|
|
28
28
|
expect(decrypt).to eq("foo: bar\n")
|
|
29
29
|
end
|
|
@@ -31,20 +31,16 @@ describe Decrypt do
|
|
|
31
31
|
|
|
32
32
|
context '.gpgme' do
|
|
33
33
|
before(:all) do
|
|
34
|
-
Encrypt.gpgme(ui: :cli, file: "foo: bar\n", key: '', pw: 'foo')
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
after(:all) do
|
|
38
|
-
%w[encrypted.txt decrypted.txt].each { |file| File.delete(file) }
|
|
34
|
+
Encrypt.gpgme(ui: :cli, file: "foo: bar\n", key: '', pw: 'foo', outdir: Dir.pwd, force: true)
|
|
39
35
|
end
|
|
40
36
|
|
|
41
37
|
it 'outputs a decrypted file with the key from the cli' do
|
|
42
|
-
Decrypt.gpgme(ui: :cli, file: File.read('encrypted.txt'), key: '', pw: 'foo')
|
|
38
|
+
Decrypt.gpgme(ui: :cli, file: File.read('encrypted.txt'), key: '', pw: 'foo', outdir: Dir.pwd, force: true)
|
|
43
39
|
expect(File.file?('decrypted.txt')).to be true
|
|
44
40
|
expect(File.read('decrypted.txt')).to eq("foo: bar\n")
|
|
45
41
|
end
|
|
46
42
|
it 'outputs decrypted content with the key from the api' do
|
|
47
|
-
decrypt = Decrypt.gpgme(ui: :api, file: File.read('encrypted.txt'), key: '', pw: 'foo')
|
|
43
|
+
decrypt = Decrypt.gpgme(ui: :api, file: File.read('encrypted.txt'), key: '', pw: 'foo', outdir: Dir.pwd)
|
|
48
44
|
expect(decrypt).to be_a(String)
|
|
49
45
|
expect(decrypt).to eq("foo: bar\n")
|
|
50
46
|
end
|
|
@@ -2,28 +2,28 @@ require_relative '../spec_helper'
|
|
|
2
2
|
require_relative '../../lib/rapid-vaults/encrypt'
|
|
3
3
|
|
|
4
4
|
describe Encrypt do
|
|
5
|
+
after(:all) do
|
|
6
|
+
%w[tag.txt encrypted.txt].each { |file| File.delete(file) }
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
context '.openssl' do
|
|
6
10
|
require 'openssl'
|
|
7
11
|
cipher = OpenSSL::Cipher.new('aes-256-gcm').encrypt
|
|
8
12
|
key = cipher.random_key
|
|
9
13
|
nonce = cipher.random_iv
|
|
10
14
|
|
|
11
|
-
after(:all) do
|
|
12
|
-
%w[tag.txt encrypted.txt].each { |file| File.delete(file) }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
15
|
it 'outputs an encrypted file with the key and nonce from the cli' do
|
|
16
|
-
Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce)
|
|
16
|
+
Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce, outdir: Dir.pwd)
|
|
17
17
|
expect(File.file?('tag.txt')).to be true
|
|
18
18
|
expect(File.file?('encrypted.txt')).to be true
|
|
19
19
|
end
|
|
20
20
|
it 'outputs an encrypted file with the key, nonce, and password from the cli' do
|
|
21
|
-
Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce, pw: 'password')
|
|
21
|
+
Encrypt.openssl(ui: :cli, file: "foo: bar\n", key: key, nonce: nonce, pw: 'password', outdir: Dir.pwd, force: true)
|
|
22
22
|
expect(File.file?('tag.txt')).to be true
|
|
23
23
|
expect(File.file?('encrypted.txt')).to be true
|
|
24
24
|
end
|
|
25
25
|
it 'outputs an array of encrypted content and tag with the key and nonce from the api' do
|
|
26
|
-
encrypt = Encrypt.openssl(ui: :api, file: "foo: bar\n", key: key, nonce: nonce)
|
|
26
|
+
encrypt = Encrypt.openssl(ui: :api, file: "foo: bar\n", key: key, nonce: nonce, outdir: Dir.pwd)
|
|
27
27
|
expect(encrypt).to be_a(Array)
|
|
28
28
|
expect(encrypt.length).to eq(2)
|
|
29
29
|
expect(encrypt[0]).to be_a(String)
|
|
@@ -33,11 +33,11 @@ describe Encrypt do
|
|
|
33
33
|
|
|
34
34
|
context '.gpgme' do
|
|
35
35
|
it 'outputs an encrypted file with the key from the cli' do
|
|
36
|
-
Encrypt.gpgme(ui: :cli, file: "foo: bar\n", key: '', pw: 'foo')
|
|
36
|
+
Encrypt.gpgme(ui: :cli, file: "foo: bar\n", key: '', pw: 'foo', outdir: Dir.pwd, force: true)
|
|
37
37
|
expect(File.file?('encrypted.txt')).to be true
|
|
38
38
|
end
|
|
39
39
|
it 'outputs a string of encrypted content with the key from the api' do
|
|
40
|
-
encrypt = Encrypt.gpgme(ui: :api, file: "foo: bar\n", key: '', pw: 'foo')
|
|
40
|
+
encrypt = Encrypt.gpgme(ui: :api, file: "foo: bar\n", key: '', pw: 'foo', outdir: Dir.pwd)
|
|
41
41
|
expect(encrypt).to be_a(String)
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -8,7 +8,7 @@ describe Generate do
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it 'generates the key and nonce files from the cli' do
|
|
11
|
-
Generate.openssl(ui: :cli)
|
|
11
|
+
Generate.openssl(ui: :cli, outdir: Dir.pwd)
|
|
12
12
|
expect(File.file?('key.txt')).to be true
|
|
13
13
|
expect(File.file?('nonce.txt')).to be true
|
|
14
14
|
expect(File.read('key.txt')).to be_a(String)
|
|
@@ -25,23 +25,23 @@ describe Generate do
|
|
|
25
25
|
|
|
26
26
|
context '.gpgme' do
|
|
27
27
|
it 'raises an error for a missing GNUPGHOME variable' do
|
|
28
|
-
expect { Generate.gpgme(gpgparams: File.read("#{
|
|
28
|
+
expect { Generate.gpgme(gpgparams: File.read("#{FIXTURES_DIR}/gpgparams.txt")) }.to raise_error('Environment variable "GNUPGHOME" was not set.')
|
|
29
29
|
end
|
|
30
30
|
it 'generates the key files' do
|
|
31
31
|
require 'fileutils'
|
|
32
32
|
|
|
33
|
-
ENV['GNUPGHOME'] =
|
|
33
|
+
ENV['GNUPGHOME'] = FIXTURES_DIR
|
|
34
34
|
|
|
35
|
-
Generate.gpgme(gpgparams: File.read("#{
|
|
35
|
+
Generate.gpgme(gpgparams: File.read("#{FIXTURES_DIR}/gpgparams.txt"), force: true)
|
|
36
36
|
%w[trustdb.gpg pubring.kbx pubring.kbx~].each do |file|
|
|
37
|
-
expect(File.file?("#{
|
|
38
|
-
File.delete("#{
|
|
37
|
+
expect(File.file?("#{FIXTURES_DIR}/#{file}")).to be true
|
|
38
|
+
File.delete("#{FIXTURES_DIR}/#{file}")
|
|
39
39
|
end
|
|
40
40
|
%w[openpgp-revocs.d private-keys-v1.d].each do |dir|
|
|
41
|
-
expect(File.directory?("#{
|
|
42
|
-
FileUtils.rm_r("#{
|
|
41
|
+
expect(File.directory?("#{FIXTURES_DIR}/#{dir}")).to be true
|
|
42
|
+
FileUtils.rm_r("#{FIXTURES_DIR}/#{dir}")
|
|
43
43
|
end
|
|
44
|
-
%w[S.gpg-agent random_seed].each { |file| File.delete("#{
|
|
44
|
+
%w[S.gpg-agent random_seed].each { |file| File.delete("#{FIXTURES_DIR}/#{file}") if File.file?(file) }
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
end
|
data/spec/rapid_vaults_spec.rb
CHANGED
|
@@ -51,10 +51,10 @@ describe RapidVaults do
|
|
|
51
51
|
expect { RapidVaults.process(algorithm: :gpgme, action: :encrypt, file: 'a', pw: 'password') }.to raise_error('Input file \'a\' for argument \'file\' is not an existing readable file.')
|
|
52
52
|
end
|
|
53
53
|
it 'raises an error for an invalid key size' do
|
|
54
|
-
expect { RapidVaults.process(action: :encrypt, file: "#{
|
|
54
|
+
expect { RapidVaults.process(action: :encrypt, file: "#{FIXTURES_DIR}file.yaml", key: 'key_bad.txt', nonce: 'nonce_good.txt') }.to raise_error('The key is not a valid 32 byte key.')
|
|
55
55
|
end
|
|
56
56
|
it 'raises an error for an invalid nonce size' do
|
|
57
|
-
expect { RapidVaults.process(action: :encrypt, file: "#{
|
|
57
|
+
expect { RapidVaults.process(action: :encrypt, file: "#{FIXTURES_DIR}file.yaml", key: 'key_good.txt', nonce: 'nonce_bad.txt') }.to raise_error('The nonce is not a valid 12 byte nonce.')
|
|
58
58
|
end
|
|
59
59
|
it 'raises an error for an invalid tag size' do
|
|
60
60
|
expect { RapidVaults.process(action: :decrypt, file: 'encrypted_good.txt', key: 'key_good.txt', nonce: 'nonce_good.txt', tag: 'tag_bad.txt') }.to raise_error('Tag is not 16 bytes.')
|
|
@@ -66,7 +66,7 @@ describe RapidVaults do
|
|
|
66
66
|
expect { RapidVaults.process(action: :decrypt, file: 'encrypted_good.txt', key: 'key_good.txt', nonce: 'nonce_good.txt', tag: 'tag_good.txt', pw: 'password') }.not_to raise_exception
|
|
67
67
|
end
|
|
68
68
|
it 'reads in all input files correctly for gpgme decryption' do
|
|
69
|
-
dummy = "#{
|
|
69
|
+
dummy = "#{FIXTURES_DIR}file.yaml"
|
|
70
70
|
expect { RapidVaults.process(algorithm: :gpgme, action: :decrypt, file: dummy, pw: 'password') }.not_to raise_exception
|
|
71
71
|
end
|
|
72
72
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
require 'rspec'
|
|
2
2
|
|
|
3
3
|
# for path to fixtures
|
|
4
|
-
|
|
5
|
-
extend RSpec::SharedContext
|
|
6
|
-
|
|
7
|
-
let(:fixtures_dir) { "#{File.dirname(__FILE__)}/fixtures/" }
|
|
8
|
-
end
|
|
4
|
+
FIXTURES_DIR = "#{File.dirname(__FILE__)}/fixtures/".freeze
|
|
9
5
|
|
|
10
6
|
RSpec.configure do |config|
|
|
11
|
-
config.include Variables
|
|
12
7
|
config.color = true
|
|
13
8
|
end
|
data/spec/system/system_spec.rb
CHANGED
|
@@ -16,7 +16,7 @@ describe RapidVaults do
|
|
|
16
16
|
context 'executed with openssl algorithm as a system from the CLI with settings and a file to be processed' do
|
|
17
17
|
it 'generates key and nonce, encrypts a file, and then decrypts a file in order' do
|
|
18
18
|
# generate and utilize files inside suitable directory
|
|
19
|
-
Dir.chdir(
|
|
19
|
+
Dir.chdir(FIXTURES_DIR)
|
|
20
20
|
|
|
21
21
|
# generate key and nonce
|
|
22
22
|
RapidVaults::CLI.main(%w[-g])
|
|
@@ -38,7 +38,7 @@ describe RapidVaults do
|
|
|
38
38
|
context 'executed with openssl algorithm as a system from the API with settings and a file to be processed' do
|
|
39
39
|
it 'generates key and nonce, encrypts a file, and then decrypts a file in order' do
|
|
40
40
|
# generate and utilize files inside suitable directory
|
|
41
|
-
Dir.chdir(
|
|
41
|
+
Dir.chdir(FIXTURES_DIR)
|
|
42
42
|
|
|
43
43
|
# generate key and nonce
|
|
44
44
|
RapidVaults::API.main(action: :generate)
|
|
@@ -63,18 +63,18 @@ describe RapidVaults do
|
|
|
63
63
|
unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
|
|
64
64
|
context 'executed wtih gpg algorithm as a system from the CLI with settings and a file to be processed' do
|
|
65
65
|
it 'encrypts a file and then decrypts a file in order' do
|
|
66
|
-
ENV['GNUPGHOME'] =
|
|
66
|
+
ENV['GNUPGHOME'] = FIXTURES_DIR
|
|
67
67
|
|
|
68
68
|
# generate and utilize files inside suitable directory
|
|
69
|
-
Dir.chdir(
|
|
69
|
+
Dir.chdir(FIXTURES_DIR)
|
|
70
70
|
|
|
71
71
|
# generate keys
|
|
72
|
-
RapidVaults::CLI.main(%w[-g --gpg --gpgparams gpgparams.txt])
|
|
73
|
-
%w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{
|
|
74
|
-
%w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{
|
|
72
|
+
RapidVaults::CLI.main(%w[-g --gpg --force --gpgparams gpgparams.txt])
|
|
73
|
+
%w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{FIXTURES_DIR}/#{file}")).to be true }
|
|
74
|
+
%w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{FIXTURES_DIR}/#{dir}")).to be true }
|
|
75
75
|
|
|
76
76
|
# generate encrypted file
|
|
77
|
-
RapidVaults::CLI.main(%w[--gpg -e -p foo file.yaml])
|
|
77
|
+
RapidVaults::CLI.main(%w[--gpg -e --force -p foo file.yaml])
|
|
78
78
|
expect(File.file?('encrypted.txt')).to be true
|
|
79
79
|
|
|
80
80
|
# generate decrypted file
|
|
@@ -86,15 +86,15 @@ describe RapidVaults do
|
|
|
86
86
|
|
|
87
87
|
context 'executed with gpg algorithm as a system from the API with settings and a file to be processed' do
|
|
88
88
|
it 'encrypts a file and then decrypts a file in order' do
|
|
89
|
-
ENV['GNUPGHOME'] =
|
|
89
|
+
ENV['GNUPGHOME'] = FIXTURES_DIR
|
|
90
90
|
|
|
91
91
|
# generate and utilize files inside suitable directory
|
|
92
|
-
Dir.chdir(
|
|
92
|
+
Dir.chdir(FIXTURES_DIR)
|
|
93
93
|
|
|
94
94
|
# generate keys
|
|
95
|
-
RapidVaults::API.main(action: :generate, algorithm: :gpgme, gpgparams: File.read('gpgparams.txt'))
|
|
96
|
-
%w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{
|
|
97
|
-
%w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{
|
|
95
|
+
RapidVaults::API.main(action: :generate, algorithm: :gpgme, force: true, gpgparams: File.read('gpgparams.txt'))
|
|
96
|
+
%w[trustdb.gpg pubring.kbx pubring.kbx~].each { |file| expect(File.file?("#{FIXTURES_DIR}/#{file}")).to be true }
|
|
97
|
+
%w[openpgp-revocs.d private-keys-v1.d].each { |dir| expect(File.directory?("#{FIXTURES_DIR}/#{dir}")).to be true }
|
|
98
98
|
|
|
99
99
|
# generate encrypted file
|
|
100
100
|
encrypt = RapidVaults::API.main(algorithm: :gpgme, action: :encrypt, file: 'file.yaml', pw: 'password')
|
|
@@ -112,7 +112,7 @@ describe RapidVaults do
|
|
|
112
112
|
context 'executed as a system to output bindings from the CLI' do
|
|
113
113
|
it 'outputs the puppet and chef bindings' do
|
|
114
114
|
# generate and utilize files inside suitable directory
|
|
115
|
-
Dir.chdir(
|
|
115
|
+
Dir.chdir(FIXTURES_DIR)
|
|
116
116
|
|
|
117
117
|
# generate bindings
|
|
118
118
|
RapidVaults::CLI.main(%w[-b puppet])
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rapid-vaults
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Schuchard
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-03-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: gpgme
|