rapid-vaults 1.1.2 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 928d90da27078d0b09c9a933e3054d8a3b26183dc5f0dc88e70fe84d2726c6cb
4
- data.tar.gz: 1a4c48a2dbcba14708170f0209105a5523d6fd1286e7ee6ef5d6509c728fe96a
3
+ metadata.gz: ff3321864a63230a5cb7c5c3b57dfbfc403e2cc06f4c903e78c3bcbf4f52a4c3
4
+ data.tar.gz: 302469d5ba1c2306c16a438552a47dcf895423f3b661f76088ac1c8eaab21770
5
5
  SHA512:
6
- metadata.gz: 248e094660ee327365c43feebd24361ef99038b83b8b52ad8efde76fa1f6727b2f275c1ca0e5a5caae39cefa5fc4423c1aeee6616e4798e3fb461e9507af3047
7
- data.tar.gz: 4b56a0496557448fb94d6e4c4ba5277448972a0c1518bac0a0c21e2cdfb5f6aecbefb9e9dc4289b3575c20c63874cb3dc227e300a643e406eab71e0563cc7130
6
+ metadata.gz: 6668ff3eb490e4b68335f602693ba84ffa9b2079bf614c9f730d006a26d8ac66caa324bdf8b29dd4a15141c3ae8bb230192d97255c124930c31f296038c5f3d1
7
+ data.tar.gz: d79506278d8708890866ee20a742a60cb9d36d4c75f552ff0e5d051ae32f1923cbf2094bb5b0ab580677be2c36e49d458b9e90a7f9cf4091cbad689693576392
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ ### 1.3.0
2
+ - Bump minimum Ruby version to 2.6.
3
+ - Code optimization and validation improvements.
4
+
5
+ ### 1.2.0
6
+ - Add GRPC support (alpha).
7
+ - Bump minimum Ruby version to 2.5.
8
+ - Add additional validation for key, nonce, and encrypted file contents.
9
+ - Fix erroneous argument validations for GPG when action is `generate`.
10
+
11
+ ### 1.1.2
12
+ - Added checks on input files and directories.
13
+ - Fix bugs blocking bindings output.
14
+
15
+ ### 1.1.1
16
+ - Added Puppet and Chef bindings.
17
+ - Add `outdir` CLI option.
18
+
19
+ ### 1.1.0
20
+ - Added capability to encrypt and decrypt with GNUPG/GPG.
21
+
22
+ ### 1.0.0
23
+ - Initial Release
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2018 Matt Schuchard
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,13 +1,12 @@
1
1
  # Rapid Vaults
2
- [![Build Status](https://travis-ci.org/mschuchard/rapid-vaults.svg?branch=master)](https://travis-ci.org/mschuchard/rapid-vaults)
3
-
4
2
  - [Description](#description)
5
3
  - [Usage](#usage)
6
4
  - [CLI](#cli)
7
5
  - [API](#api)
6
+ - [gRPC](#grpc)
7
+ - [Docker](#docker)
8
8
  - [Ansible](#ansible)
9
9
  - [Puppet](#puppet)
10
- - [Hiera](#hiera)
11
10
  - [Chef](#chef)
12
11
  - [Contributing](#contributing)
13
12
 
@@ -21,7 +20,7 @@ Ansible-Vault is very similar to Rapid Vaults. Both are streamlined and easy to
21
20
 
22
21
  ### Non-Comparative Software
23
22
 
24
- Rapid Vaults is not similar to tools like RbNaCl or Hashicorp's Vault. RbNaCl offers advanced encryption techniques by providing bindings to libsodium. Rapid Vaults relies upon AES-256-GCM (OpenSSL) or GPG's algorithms (RSA, SHA-512, etc.). Hashicorp's Vault is Enterprise level software with many powerful features and conveniences. Rapid Vaults is a lightweight and narrowly focused tool.
23
+ Rapid Vaults is not similar to tools like RbNaCl or Hashicorp's Vault. RbNaCl offers advanced encryption techniques by providing bindings to libsodium. Rapid Vaults relies upon AES-256-GCM (OpenSSL) or GPG's algorithms (RSA, SHA-512, etc.). Hashicorp's Vault is Enterprise level software with many powerful features and conveniences. Rapid Vaults is a lightweight and narrowly focused tool. However, Rapid Vaults can be considered algorithmically very similar to Vault's Transit secret engine.
25
24
 
26
25
  ## Usage
27
26
 
@@ -50,11 +49,11 @@ usage: rapid-vaults [options] file
50
49
 
51
50
  #### Encrypt File with SSL
52
51
 
53
- `rapid-vaults -e -k cert.key -n nonce.txt -p secret -o /output/dir unencrypted.txt`
52
+ `rapid-vaults -e -k key.txt -n nonce.txt -p secret -o /output/dir unencrypted.txt`
54
53
 
55
54
  #### Decrypt a File with SSL
56
55
 
57
- `rapid-vaults -d -k cert.key -n nonce.txt -t tag.txt -p secret -o /output/dir encrypted.txt`
56
+ `rapid-vaults -d -k key.txt -n nonce.txt -t tag.txt -p secret -o /output/dir encrypted.txt`
58
57
 
59
58
  #### Generate Keys with GPG
60
59
  This is the only situation where a `--gpgparams` flag and argument is required or utilized. The file provided as the argument should look like the following:
@@ -97,8 +96,7 @@ Currently you set the path to the keys and other files via the environment varia
97
96
  ```ruby
98
97
  require 'rapid-vaults'
99
98
 
100
- options = {}
101
- options[:action] = :generate
99
+ options = { action: :generate }
102
100
  key, nonce = RapidVaults::API.main(options)
103
101
  File.write('key.txt', key)
104
102
  File.write('nonce.txt', nonce)
@@ -109,12 +107,13 @@ File.write('nonce.txt', nonce)
109
107
  ```ruby
110
108
  require 'rapid-vaults'
111
109
 
112
- options = {}
113
- options[:action] = :encrypt
114
- options[:file] = '/path/to/data.txt'
115
- options[:key] = '/path/to/cert.key'
116
- options[:nonce] = '/path/to/nonce.txt'
117
- options[:pw] = File.read('/path/to/password.txt') # optional
110
+ options = {
111
+ action: :encrypt,
112
+ file: '/path/to/data.txt',
113
+ key: '/path/to/key.txt',
114
+ nonce: '/path/to/nonce.txt',
115
+ pw: File.read('/path/to/password.txt') # optional
116
+ }
118
117
  encrypted_contents, tag = RapidVaults::API.main(options)
119
118
  ```
120
119
 
@@ -123,13 +122,14 @@ encrypted_contents, tag = RapidVaults::API.main(options)
123
122
  ```ruby
124
123
  require 'rapid-vaults'
125
124
 
126
- options = {}
127
- options[:action] = :decrypt
128
- options[:file] = '/path/to/encrypted_data.txt'
129
- options[:key] = '/path/to/cert.key'
130
- options[:nonce] = '/path/to/nonce.txt'
131
- options[:tag] = '/path/to/tag.txt'
132
- options[:pw] = File.read('/path/to/password.txt') # optional
125
+ options = {
126
+ action: :decrypt,
127
+ file: '/path/to/encrypted_data.txt',
128
+ key: '/path/to/key.txt',
129
+ nonce: '/path/to/nonce.txt',
130
+ tag: '/path/to/tag.txt',
131
+ pw: File.read('/path/to/password.txt') # optional
132
+ }
133
133
  decrypted_contents = RapidVaults::API.main(options)
134
134
  ```
135
135
 
@@ -139,10 +139,11 @@ require 'rapid-vaults'
139
139
 
140
140
  ENV['GNUPGHOME'] = '/home/alice/.gnupg'
141
141
 
142
- options = {}
143
- options[:action] = :generate
144
- options[:algorithm] = :gpgme
145
- options[:gpgparams] = File.read('gpgparams.txt')
142
+ options = {
143
+ action: :generate,
144
+ algorithm: :gpgme,
145
+ gpgparams: File.read('gpgparams.txt')
146
+ }
146
147
  RapidVaults::API.main(options)
147
148
  ```
148
149
 
@@ -169,11 +170,12 @@ require 'rapid-vaults'
169
170
 
170
171
  ENV['GNUPGHOME'] = '/home/bob/.gnupg' # optional
171
172
 
172
- options = {}
173
- options[:action] = :encrypt
174
- options[:algorithm] = :gpgme
175
- options[:file] = '/path/to/data.txt'
176
- options[:pw] = File.read('/path/to/password.txt')
173
+ options = {
174
+ action: :encrypt,
175
+ algorithm: :gpgme,
176
+ file: '/path/to/data.txt',
177
+ pw: File.read('/path/to/password.txt')
178
+ }
177
179
  encrypted_contents = RapidVaults::API.main(options)
178
180
  ```
179
181
 
@@ -184,14 +186,23 @@ require 'rapid-vaults'
184
186
 
185
187
  ENV['GNUPGHOME'] = '/home/chris/.gnupg' # optional
186
188
 
187
- options = {}
188
- options[:action] = :decrypt
189
- options[:algorithm] = :gpgme
190
- options[:file] = '/path/to/encrypted_data.txt'
191
- options[:pw] = File.read('/path/to/password.txt')
189
+ options = {
190
+ action: :decrypt,
191
+ algorithm: :gpgme,
192
+ file: '/path/to/encrypted_data.txt',
193
+ pw: File.read('/path/to/password.txt')
194
+ }
192
195
  decrypted_contents = RapidVaults::API.main(options)
193
196
  ```
194
197
 
198
+ ### Docker
199
+
200
+ A supported [Docker image](https://hub.docker.com/r/matthewschuchard/rapid-vaults) of Rapid-Vaults is now available from the public Docker Hub registry. Please consult the repository documentation for further usage information.
201
+
202
+ ### gRPC
203
+
204
+ forthcoming
205
+
195
206
  ### Ansible
196
207
 
197
208
  forthcoming
@@ -1,17 +1,16 @@
1
- require_relative '../rapid-vaults'
1
+ require_relative '../rapid_vaults'
2
2
 
3
3
  # provides an application programming interface to interact with rapid vaults
4
4
  class RapidVaults::API
5
5
  # lightweight api
6
6
  def self.main(settings)
7
- # parse settings for api and run RapidVaults with specified settings
7
+ # parse pass-by-value settings for api and run RapidVaults with specified settings
8
8
  RapidVaults.new.main(parse(settings))
9
9
  end
10
10
 
11
- # parse api options
11
+ # parse api options; this is mostly here for unit testing
12
12
  def self.parse(settings)
13
13
  # establish settings for api and denote using api
14
- settings[:ui] = :api
15
- settings
14
+ settings.merge({ ui: :api })
16
15
  end
17
16
  end
@@ -1,10 +1,14 @@
1
1
  # class to output bindings with other software
2
2
  class Binding
3
+ # bindings matrix consts
4
+ CRYPT = %w[gpg ssl].freeze
5
+ ACTION = %w[encrypt decrypt].freeze
6
+
3
7
  # outputs puppet bindings
4
8
  def self.puppet(settings)
5
9
  # output puppet bindings to output directory
6
- %w[gpg ssl].each do |algo|
7
- %w[encrypt decrypt].each do |action|
10
+ CRYPT.each do |algo|
11
+ ACTION.each do |action|
8
12
  content = File.read("#{__dir__}/bindings/puppet_#{algo}_#{action}.rb")
9
13
  File.write("#{settings[:outdir]}puppet_#{algo}_#{action}.rb", content)
10
14
  end
@@ -2,31 +2,32 @@ require 'rapid-vaults'
2
2
 
3
3
  # returns key, nonce
4
4
  def ssl_generate
5
- options = {}
6
- options[:action] = :generate
5
+ options = { action: :generate }
7
6
  RapidVaults::API.main(options)
8
7
  end
9
8
 
10
9
  # returns encrypted_contents, tag
11
10
  def ssl_encrypt
12
- options = {}
13
- options[:action] = :encrypt
14
- options[:file] = '/path/to/data.txt'
15
- options[:key] = '/path/to/cert.key'
16
- options[:nonce] = '/path/to/nonce.txt'
17
- options[:pw] = File.read('/path/to/password.txt') # optional
11
+ options = {
12
+ action: :encrypt,
13
+ file: '/path/to/data.txt',
14
+ key: '/path/to/key.txt',
15
+ nonce: '/path/to/nonce.txt',
16
+ pw: File.read('/path/to/password.txt') # optional
17
+ }
18
18
  RapidVaults::API.main(options)
19
19
  end
20
20
 
21
21
  # returns decrypted_contents
22
22
  def ssl_decrypt
23
- options = {}
24
- options[:action] = :decrypt
25
- options[:file] = '/path/to/encrypted_data.txt'
26
- options[:key] = '/path/to/cert.key'
27
- options[:nonce] = '/path/to/nonce.txt'
28
- options[:tag] = '/path/to/tag.txt'
29
- options[:pw] = File.read('/path/to/password.txt') # optional
23
+ options = {
24
+ action: :decrypt,
25
+ file: '/path/to/encrypted_data.txt',
26
+ key: '/path/to/key.txt',
27
+ nonce: '/path/to/nonce.txt',
28
+ tag: '/path/to/tag.txt',
29
+ pw: File.read('/path/to/password.txt') # optional
30
+ }
30
31
  RapidVaults::API.main(options)
31
32
  end
32
33
 
@@ -34,10 +35,11 @@ end
34
35
  def gpg_generate
35
36
  ENV['GNUPGHOME'] = '/home/alice/.gnupg'
36
37
 
37
- options = {}
38
- options[:action] = :generate
39
- options[:algorithm] = :gpgme
40
- options[:gpgparams] = File.read('gpgparams.txt')
38
+ options = {
39
+ action: :generate,
40
+ algorithm: :gpgme,
41
+ gpgparams: File.read('gpgparams.txt')
42
+ }
41
43
  RapidVaults::API.main(options)
42
44
  end
43
45
 
@@ -45,11 +47,12 @@ end
45
47
  def gpg_encrypt
46
48
  ENV['GNUPGHOME'] = '/home/bob/.gnupg'
47
49
 
48
- options = {}
49
- options[:action] = :encrypt
50
- options[:algorithm] = :gpgme
51
- options[:file] = '/path/to/data.txt'
52
- options[:pw] = File.read('/path/to/password.txt')
50
+ options = {
51
+ action: :encrypt,
52
+ algorithm: :gpgme,
53
+ file: '/path/to/data.txt',
54
+ pw: File.read('/path/to/password.txt')
55
+ }
53
56
  RapidVaults::API.main(options)
54
57
  end
55
58
 
@@ -57,10 +60,11 @@ end
57
60
  def gpg_decrypt
58
61
  ENV['GNUPGHOME'] = '/home/chris/.gnupg'
59
62
 
60
- options = {}
61
- options[:action] = :decrypt
62
- options[:algorithm] = :gpgme
63
- options[:file] = '/path/to/encrypted_data.txt'
64
- options[:pw] = File.read('/path/to/password.txt')
63
+ options = {
64
+ action: :decrypt,
65
+ algorithm: :gpgme,
66
+ file: '/path/to/encrypted_data.txt',
67
+ pw: File.read('/path/to/password.txt')
68
+ }
65
69
  RapidVaults::API.main(options)
66
70
  end
@@ -1,5 +1,5 @@
1
1
  # mymodule/lib/puppet/functions/gpg_decrypt.rb
2
- Puppet::Functions.create_function(:'gpg_decrypt') do
2
+ Puppet::Functions.create_function(:gpg_decrypt) do
3
3
  # Decrypts a file with GnuPG.
4
4
  # @param [String] file The file to decrypt.
5
5
  # @param [String] gpghome The path to the GnuPG home directory containing the credentials.
@@ -1,5 +1,5 @@
1
1
  # mymodule/lib/puppet/functions/gpg_encrypt.rb
2
- Puppet::Functions.create_function(:'gpg_encrypt') do
2
+ Puppet::Functions.create_function(:gpg_encrypt) do
3
3
  # Encrypts a file with GnuPG.
4
4
  # @param [String] file The file to encrypt.
5
5
  # @param [String] gpghome The path to the GnuPG home directory containing the credentials.
@@ -1,5 +1,5 @@
1
1
  # mymodule/lib/puppet/functions/ssl_decrypt.rb
2
- Puppet::Functions.create_function(:'ssl_decrypt') do
2
+ Puppet::Functions.create_function(:ssl_decrypt) do
3
3
  # Decrypts a file with OpenSSL.
4
4
  # @param [String] file The file to decrypt.
5
5
  # @param [String] key The key file to use for decryption.
@@ -25,10 +25,11 @@ Puppet::Functions.create_function(:'ssl_decrypt') do
25
25
  raise 'Rapid Vaults is required to be installed on the puppet master to use this custom function!'
26
26
  end
27
27
 
28
- if password_file.nil?
29
- RapidVaults::API.main(action: :decrypt, file: file, key: key, nonce: nonce, tag: tag)
30
- else
31
- RapidVaults::API.main(action: :encrypt, file: file, key: key, nonce: nonce, tag: tag, pw: File.read(password_file))
32
- end
28
+ # initialize settings
29
+ settings = { action: :decrypt, file: file, key: key, nonce: nonce, tag: tag }
30
+ # update settings with password if input
31
+ settings[pw: File.read(password_file)] unless password_file.nil?
32
+
33
+ RapidVaults::API.main(settings)
33
34
  end
34
35
  end
@@ -1,5 +1,5 @@
1
1
  # mymodule/lib/puppet/functions/ssl_encrypt.rb
2
- Puppet::Functions.create_function(:'ssl_encrypt') do
2
+ Puppet::Functions.create_function(:ssl_encrypt) do
3
3
  # Encrypts a file with OpenSSL.
4
4
  # @param [String] file The file to encrypt.
5
5
  # @param [String] key The key file to use for encryption.
@@ -23,12 +23,14 @@ Puppet::Functions.create_function(:'ssl_encrypt') do
23
23
  raise 'Rapid Vaults is required to be installed on the puppet master to use this custom function!'
24
24
  end
25
25
 
26
- hash = {}
27
- if password_file.nil?
28
- hash[:encrypted_contents], hash[:tag] = RapidVaults::API.main(action: :encrypt, file: file, key: key, nonce: nonce)
29
- else
30
- hash[:encrypted_contents], hash[:tag] = RapidVaults::API.main(action: :encrypt, file: file, key: key, nonce: nonce, pw: File.read(password_file))
31
- end
32
- hash
26
+ # initialize settings and return
27
+ settings = { action: :encrypt, file: file, key: key, nonce: nonce }
28
+ return_hash = {}
29
+ # update settings with password if input
30
+ settings[pw: File.read(password_file)] unless password_file.nil?
31
+
32
+ return_hash[:encrypted_contents], return_hash[:tag] = RapidVaults::API.main(settings)
33
+
34
+ return_hash
33
35
  end
34
36
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: rapid_vaults.proto
4
+
5
+ require 'google/protobuf'
6
+
7
+
8
+ descriptor_data = "\n\x12rapid_vaults.proto\x12\x0brapidvaults\"\x0b\n\tGenInputs\"(\n\nGenOutputs\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05nonce\x18\x02 \x01(\t\"I\n\x0bUnencrypted\x12\x0c\n\x04text\x18\x01 \x01(\t\x12\x0b\n\x03key\x18\x02 \x01(\t\x12\r\n\x05nonce\x18\x03 \x01(\t\x12\x10\n\x08password\x18\x04 \x01(\t\"&\n\tEncrypted\x12\x0c\n\x04text\x18\x01 \x01(\t\x12\x0b\n\x03tag\x18\x02 \x01(\t\"V\n\x0bUndecrypted\x12\x0c\n\x04text\x18\x01 \x01(\t\x12\x0b\n\x03key\x18\x02 \x01(\t\x12\r\n\x05nonce\x18\x03 \x01(\t\x12\x0b\n\x03tag\x18\x04 \x01(\t\x12\x10\n\x08password\x18\x05 \x01(\t\"\x19\n\tDecrypted\x12\x0c\n\x04text\x18\x01 \x01(\t2\x99\x03\n\x0bRapidVaults\x12@\n\x0bSSLGenerate\x12\x16.rapidvaults.GenInputs\x1a\x17.rapidvaults.GenOutputs\"\x00\x12@\n\x0bGPGGenerate\x12\x16.rapidvaults.GenInputs\x1a\x17.rapidvaults.GenOutputs\"\x00\x12@\n\nSSLEncrypt\x12\x18.rapidvaults.Unencrypted\x1a\x16.rapidvaults.Encrypted\"\x00\x12@\n\nGPGEncrypt\x12\x18.rapidvaults.Unencrypted\x1a\x16.rapidvaults.Encrypted\"\x00\x12@\n\nSSLDecrypt\x12\x18.rapidvaults.Undecrypted\x1a\x16.rapidvaults.Decrypted\"\x00\x12@\n\nGPGDecrypt\x12\x18.rapidvaults.Undecrypted\x1a\x16.rapidvaults.Decrypted\"\x00\x62\x06proto3"
9
+
10
+ pool = Google::Protobuf::DescriptorPool.generated_pool
11
+ pool.add_serialized_file(descriptor_data)
12
+
13
+ module Rapidvaults
14
+ GenInputs = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("rapidvaults.GenInputs").msgclass
15
+ GenOutputs = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("rapidvaults.GenOutputs").msgclass
16
+ Unencrypted = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("rapidvaults.Unencrypted").msgclass
17
+ Encrypted = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("rapidvaults.Encrypted").msgclass
18
+ Undecrypted = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("rapidvaults.Undecrypted").msgclass
19
+ Decrypted = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("rapidvaults.Decrypted").msgclass
20
+ end
@@ -0,0 +1,33 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: rapid_vaults.proto for package 'rapidvaults'
3
+
4
+ require 'grpc'
5
+ require_relative 'rapid_vaults_pb'
6
+
7
+ module Rapidvaults
8
+ module RapidVaults
9
+ class Service
10
+
11
+ include ::GRPC::GenericService
12
+
13
+ self.marshal_class_method = :encode
14
+ self.unmarshal_class_method = :decode
15
+ self.service_name = 'rapidvaults.RapidVaults'
16
+
17
+ # generate SSL key and nonce
18
+ rpc :SSLGenerate, ::Rapidvaults::GenInputs, ::Rapidvaults::GenOutputs
19
+ # generate GPG key and nonce
20
+ rpc :GPGGenerate, ::Rapidvaults::GenInputs, ::Rapidvaults::GenOutputs
21
+ # encrypt with SSL
22
+ rpc :SSLEncrypt, ::Rapidvaults::Unencrypted, ::Rapidvaults::Encrypted
23
+ # encrypt with GPG
24
+ rpc :GPGEncrypt, ::Rapidvaults::Unencrypted, ::Rapidvaults::Encrypted
25
+ # decrypt with SSL
26
+ rpc :SSLDecrypt, ::Rapidvaults::Undecrypted, ::Rapidvaults::Decrypted
27
+ # decrypt with GPG
28
+ rpc :GPGDecrypt, ::Rapidvaults::Undecrypted, ::Rapidvaults::Decrypted
29
+ end
30
+
31
+ Stub = Service.rpc_stub_class
32
+ end
33
+ end
@@ -1,4 +1,4 @@
1
- require_relative '../rapid-vaults'
1
+ require_relative '../rapid_vaults'
2
2
 
3
3
  # provides a command line interface to interact with rapid vaults
4
4
  class RapidVaults::CLI
@@ -6,7 +6,7 @@ class RapidVaults::CLI
6
6
  def self.main(args)
7
7
  # parse args in cli and denote using cli
8
8
  settings = parse(args)
9
- if settings[:action] == :encrypt || settings[:action] == :decrypt
9
+ if %i[encrypt decrypt].include?(settings[:action])
10
10
  args.empty? ? (raise 'rapid-vaults: no file specified; try using --help') : settings[:file] = args.first
11
11
  end
12
12
 
@@ -22,10 +22,8 @@ class RapidVaults::CLI
22
22
  # show help message if no args specified
23
23
  args = %w[-h] if args.empty?
24
24
 
25
- # init settings
26
- settings = {}
27
- # specify cli being used
28
- settings[:ui] = :cli
25
+ # init settings with cli setting
26
+ settings = { ui: :cli }
29
27
 
30
28
  opt_parser = OptionParser.new do |opts|
31
29
  # usage
@@ -33,7 +31,9 @@ class RapidVaults::CLI
33
31
 
34
32
  # base options
35
33
  opts.on('--version', 'Display the current version.') do
36
- puts 'rapid-vaults 1.1.2'
34
+ require 'rubygems'
35
+
36
+ puts Gem::Specification.load("#{File.dirname(__FILE__)}/../../rapid-vaults.gemspec").version
37
37
  exit 0
38
38
  end
39
39
 
@@ -51,7 +51,7 @@ class RapidVaults::CLI
51
51
  opts.on('-t', '--tag tag', String, 'Tag file to be used for decryption (GPG: n/a).') { |arg| settings[:tag] = arg }
52
52
  opts.on('-p', '--password password', String, '(optional) Password to be used for encryption or decryption (GPG: required).') { |arg| settings[:pw] = arg }
53
53
  opts.on('-f', '--file-password password.txt', String, '(optional) Text file containing a password to be used for encryption or decryption (GPG: required).') do |arg|
54
- raise "Password file #{arg} is not an existing file!" unless File.file?(arg)
54
+ raise "Password file #{arg} is not an existing readable file!" unless File.readable?(arg)
55
55
  settings[:pw] = File.read(arg)
56
56
  end
57
57
 
@@ -63,7 +63,7 @@ class RapidVaults::CLI
63
63
 
64
64
  # other
65
65
  opts.on('--gpgparams params.txt', String, 'GPG Key params input file used during generation of keys.') do |arg|
66
- raise "GPG Parameters file #{arg} is not an existing file!" unless File.file?(arg)
66
+ raise "GPG Parameters file #{arg} is not an existing readable file!" unless File.readable?(arg)
67
67
  settings[:gpgparams] = File.read(arg)
68
68
  end
69
69
  opts.on('-o --outdir', String, 'Optional output directory for generated files (default: pwd). (GPG: optional)') do |arg|
@@ -4,9 +4,6 @@ class Decrypt
4
4
  def self.openssl(settings)
5
5
  require 'openssl'
6
6
 
7
- # check tag size
8
- raise 'Tag is not 16 bytes.' unless settings[:tag].bytesize == 16
9
-
10
7
  # setup the decryption parameters
11
8
  decipher = OpenSSL::Cipher.new('aes-256-gcm').decrypt
12
9
  decipher.key = settings[:key]
@@ -15,11 +12,12 @@ class Decrypt
15
12
  decipher.auth_data = settings.key?(:pw) ? settings[:pw] : ''
16
13
 
17
14
  # output the decryption
18
- if settings[:ui] == :cli
15
+ case settings[:ui]
16
+ when :cli
19
17
  # output to file
20
18
  File.write("#{settings[:outdir]}decrypted.txt", decipher.update(settings[:file]) + decipher.final)
21
19
  puts "Your decrypted.txt has been written out to #{settings[:outdir]}."
22
- elsif settings[:ui] == :api
20
+ when :api
23
21
  # output to string
24
22
  decipher.update(settings[:file]) + decipher.final
25
23
  end
@@ -30,18 +28,19 @@ class Decrypt
30
28
  require 'gpgme'
31
29
 
32
30
  # check if GPGHOME env was set
33
- puts "Environment variable 'GNUPGHOME' was not set. Files in #{ENV['HOME']}/.gnupg will be used for authentication." unless ENV['GNUPGHOME']
31
+ puts "Environment variable 'GNUPGHOME' was not set. Files in #{Dir.home}/.gnupg will be used for authentication." unless ENV.fetch('GNUPGHOME', false)
34
32
 
35
33
  # setup the decryption parameters
36
34
  encrypted = GPGME::Data.new(settings[:file])
37
35
  crypto = GPGME::Crypto.new(armor: true, pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK)
38
36
 
39
37
  # output the decryption
40
- if settings[:ui] == :cli
38
+ case settings[:ui]
39
+ when :cli
41
40
  # output to file
42
41
  File.write("#{settings[:outdir]}decrypted.txt", crypto.decrypt(encrypted, password: settings[:pw]).read)
43
42
  puts "Your decrypted.txt has been written out to #{settings[:outdir]}."
44
- elsif settings[:ui] == :api
43
+ when :api
45
44
  # output to string
46
45
  crypto.decrypt(encrypted, password: settings[:pw]).read
47
46
  end
@@ -11,13 +11,14 @@ class Encrypt
11
11
  cipher.auth_data = settings.key?(:pw) ? settings[:pw] : ''
12
12
 
13
13
  # output the encryption and associated tag
14
- if settings[:ui] == :cli
14
+ case settings[:ui]
15
+ when :cli
15
16
  # output to file
16
17
  File.write("#{settings[:outdir]}encrypted.txt", cipher.update(settings[:file]) + cipher.final)
17
18
  File.write("#{settings[:outdir]}tag.txt", cipher.auth_tag)
18
19
  puts "Your encrypted.txt and associated tag.txt for this encryption have been generated in #{settings[:outdir]}."
19
- elsif settings[:ui] == :api
20
- # output to array
20
+ when :api
21
+ # return as array
21
22
  [cipher.update(settings[:file]) + cipher.final, cipher.auth_tag]
22
23
  end
23
24
  end
@@ -27,18 +28,19 @@ class Encrypt
27
28
  require 'gpgme'
28
29
 
29
30
  # check if GPGHOME env was set
30
- puts "Environment variable 'GNUPGHOME' was not set. Files in #{ENV['HOME']}/.gnupg will be used for authentication." unless ENV['GNUPGHOME']
31
+ puts "Environment variable 'GNUPGHOME' was not set. Files in #{Dir.home}/.gnupg will be used for authentication." unless ENV.fetch('GNUPGHOME', false)
31
32
 
32
33
  # setup the encryption parameters
33
34
  crypto = GPGME::Crypto.new(armor: true, pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK)
34
35
 
35
36
  # output the encryption and associated tag
36
- if settings[:ui] == :cli
37
+ case settings[:ui]
38
+ when :cli
37
39
  # output to file
38
40
  File.write("#{settings[:outdir]}encrypted.txt", crypto.encrypt(settings[:file], symmetric: true, password: settings[:pw]).read)
39
- puts "Your encrypted.txt for this encryption have been generated in #{settings[:outdir]}."
40
- elsif settings[:ui] == :api
41
- # output to string
41
+ puts "Your encrypted.txt for this encryption has been generated in #{settings[:outdir]}."
42
+ when :api
43
+ # return as string
42
44
  crypto.encrypt(settings[:file], symmetric: true, password: settings[:pw]).read
43
45
  end
44
46
  end
@@ -7,13 +7,14 @@ class Generate
7
7
  # setup parameters
8
8
  cipher = OpenSSL::Cipher.new('aes-256-gcm').encrypt
9
9
 
10
- if settings[:ui] == :cli
10
+ case settings[:ui]
11
+ when :cli
11
12
  # output to file
12
13
  File.write("#{settings[:outdir]}key.txt", cipher.random_key)
13
14
  File.write("#{settings[:outdir]}nonce.txt", cipher.random_iv)
14
15
  puts "Your key.txt and nonce.txt have been generated in #{settings[:outdir]}."
15
- elsif settings[:ui] == :api
16
- # output to string
16
+ when :api
17
+ # return as array
17
18
  [cipher.random_key, cipher.random_iv]
18
19
  end
19
20
  end
@@ -23,10 +24,10 @@ class Generate
23
24
  require 'gpgme'
24
25
 
25
26
  # ensure we have a place to store these output files
26
- raise 'Environment variable "GNUPGHOME" was not set.' unless ENV['GNUPGHOME']
27
+ raise 'Environment variable "GNUPGHOME" was not set.' unless ENV.fetch('GNUPGHOME', false)
27
28
 
28
29
  # create gpg keys
29
30
  GPGME::Ctx.new.generate_key(settings[:gpgparams], nil, nil)
30
- puts "Your GPG keys have been generated in #{ENV['GNUPGHOME']}." if settings[:ui] == :cli
31
+ puts "Your GPG keys have been generated in #{ENV.fetch['GNUPGHOME']}." if settings[:ui] == :cli
31
32
  end
32
33
  end