symmetric-encryption 4.3.0 → 4.3.1

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: d5499f0c6e33fc5eee0a2295623edd3bf35a247e1a6263a3e93f2c4e57219f22
4
- data.tar.gz: ea3495cf8f5fe6b388725cd424ed13dc8b982c4ad225e78c7056f8d0f0d70cab
3
+ metadata.gz: 860217558341999072c177c7d848fa6315667a7fcb12d9e1d9a518ecda43a2c4
4
+ data.tar.gz: f0aa6a3419a15edfba8fcc37b72a1282057efbbe09653a7a04ff4687dcc87bd6
5
5
  SHA512:
6
- metadata.gz: a8a920045c6b813bb55e8a518727ffdaf03b0b5857f5326d8b6003946d81fb162f28eea69617934622626de66cbfbeaf27b464c5d7baa21e07332e2c7098f7e4
7
- data.tar.gz: bb2a832909e3a81b1e357a4ec650e7f1fd93e81ab08a0a0f3664b586bc0bf60f1a821c26831f456138e77a7a29575bc976890f608ac10461a51e5fd86dbd2699
6
+ metadata.gz: 870814f9d0d82dbd3edb405da82017c1d3533c4c7402e7ed0f9ac5e797a3c5e98500ac81912926076c84ddb90e3f287c097db65e5ff5202a22e5b053cfd83ba5
7
+ data.tar.gz: eba6e94c5ed7755795ac8bbfcf83cd0a08d6206888bcfbdc30d33bcc61dcb7403ae7afe0c6d187608cf02550f0a3bce6eeefeb464ac860b1b1d64282e4d047be
@@ -51,7 +51,7 @@ module SymmetricEncryption
51
51
  random_iv = true if random_iv.nil? && SymmetricEncryption.randomize_iv?
52
52
 
53
53
  if random_iv.nil?
54
- warn("attr_encrypted() no longer allows a default value for option `random_iv`. Add `random_iv: false` if it is required.")
54
+ warn('attr_encrypted() no longer allows a default value for option `random_iv`. Add `random_iv: false` if it is required.')
55
55
  end
56
56
 
57
57
  attributes.each do |attribute|
@@ -202,7 +202,7 @@ module SymmetricEncryption
202
202
  def self.camelize(term)
203
203
  string = term.to_s
204
204
  string = string.sub(/^[a-z\d]*/, &:capitalize)
205
- string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
205
+ string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
206
206
  string.gsub!('/'.freeze, '::'.freeze)
207
207
  string
208
208
  end
@@ -77,7 +77,7 @@ module SymmetricEncryption
77
77
  app_name:,
78
78
  environment:,
79
79
  key_path:,
80
- **args)
80
+ **_args)
81
81
 
82
82
  # TODO: Also support generating environment variables instead of files.
83
83
 
@@ -7,7 +7,7 @@ module SymmetricEncryption
7
7
  # Returns [Hash] a new keystore configuration after generating the data key.
8
8
  #
9
9
  # Increments the supplied version number by 1.
10
- def self.generate_data_key(cipher_name:, app_name:, environment:, version: 0, dek: nil, **args)
10
+ def self.generate_data_key(cipher_name:, app_name:, environment:, version: 0, dek: nil, **_args)
11
11
  version >= 255 ? (version = 1) : (version += 1)
12
12
 
13
13
  kek = SymmetricEncryption::Key.new(cipher_name: cipher_name)
@@ -8,7 +8,7 @@ module SymmetricEncryption
8
8
  # Returns [Hash] a new keystore configuration after generating the data key.
9
9
  #
10
10
  # Increments the supplied version number by 1.
11
- def self.generate_data_key(key_path:, cipher_name:, app_name:, environment:, version: 0, dek: nil, **args)
11
+ def self.generate_data_key(key_path:, cipher_name:, app_name:, environment:, version: 0, dek: nil, **_args)
12
12
  version >= 255 ? (version = 1) : (version += 1)
13
13
 
14
14
  dek ||= SymmetricEncryption::Key.new(cipher_name: cipher_name)
@@ -47,11 +47,15 @@ module SymmetricEncryption
47
47
 
48
48
  # Returns the Encryption key in the clear.
49
49
  def read
50
- raise(SymmetricEncryption::ConfigError,
51
- "Symmetric Encryption key file: '#{file_name}' not found") unless ::File.exists?(file_name)
52
- raise(SymmetricEncryption::ConfigError,
53
- "Symmetric Encryption key file '#{file_name}' has the wrong "\
54
- "permissions: #{::File.stat(file_name).mode.to_s(8)}. Expected 100600 or 100400.") unless correct_permissions?
50
+ unless ::File.exist?(file_name)
51
+ raise(SymmetricEncryption::ConfigError,
52
+ "Symmetric Encryption key file: '#{file_name}' not found")
53
+ end
54
+ unless correct_permissions?
55
+ raise(SymmetricEncryption::ConfigError,
56
+ "Symmetric Encryption key file '#{file_name}' has the wrong "\
57
+ "permissions: #{::File.stat(file_name).mode.to_s(8)}. Expected 100600 or 100400.")
58
+ end
55
59
 
56
60
  data = read_from_file(file_name)
57
61
  key_encrypting_key ? key_encrypting_key.decrypt(data) : data
@@ -71,7 +75,7 @@ module SymmetricEncryption
71
75
  def correct_permissions?
72
76
  stat = ::File.stat(file_name)
73
77
 
74
- stat.owned? && %w(100600 100400).include?(stat.mode.to_s(8))
78
+ stat.owned? && %w[100600 100400].include?(stat.mode.to_s(8))
75
79
  end
76
80
  end
77
81
  end
@@ -1,4 +1,4 @@
1
- require "google/cloud/kms/v1"
1
+ require 'google/cloud/kms/v1'
2
2
 
3
3
  module SymmetricEncryption
4
4
  module Keystore
@@ -8,9 +8,9 @@ module SymmetricEncryption
8
8
  def self.generate_data_key(version: 0, cipher_name:, app_name:, environment:, key_path:)
9
9
  version >= 255 ? (version = 1) : (version += 1)
10
10
 
11
- dek = SymmetricEncryption::Key.new(cipher_name: cipher_name)
11
+ dek = SymmetricEncryption::Key.new(cipher_name: cipher_name)
12
12
  file_name = "#{key_path}/#{app_name}_#{environment}_v#{version}.encrypted_key"
13
- keystore = new(
13
+ keystore = new(
14
14
  key_file: file_name,
15
15
  app_name: app_name,
16
16
  environment: environment
@@ -18,21 +18,21 @@ module SymmetricEncryption
18
18
  keystore.write(dek.key)
19
19
 
20
20
  {
21
- keystore: :gcp,
22
- cipher_name: dek.cipher_name,
23
- version: version,
24
- key_file: file_name,
25
- iv: dek.iv,
26
- crypto_key: keystore.crypto_key
21
+ keystore: :gcp,
22
+ cipher_name: dek.cipher_name,
23
+ version: version,
24
+ key_file: file_name,
25
+ iv: dek.iv,
26
+ crypto_key: keystore.crypto_key
27
27
  }
28
28
  end
29
29
 
30
30
  def initialize(key_file:, app_name: nil, environment: nil, key_encrypting_key: nil, crypto_key: nil, project_id: nil, credentials: nil, location_id: nil)
31
- @crypto_key = crypto_key
32
- @app_name = app_name
31
+ @crypto_key = crypto_key
32
+ @app_name = app_name
33
33
  @environment = environment
34
- @file_name = key_file
35
- @project_id = project_id
34
+ @file_name = key_file
35
+ @project_id = project_id
36
36
  @credentials = credentials
37
37
  @location_id = location_id
38
38
  end
@@ -68,19 +68,21 @@ module SymmetricEncryption
68
68
  end
69
69
 
70
70
  def project_id
71
- @project_id ||= ENV["GOOGLE_CLOUD_PROJECT"]
71
+ @project_id ||= ENV['GOOGLE_CLOUD_PROJECT']
72
72
  raise 'GOOGLE_CLOUD_PROJECT must be set' if @project_id.nil?
73
+
73
74
  @project_id
74
75
  end
75
76
 
76
77
  def credentials
77
78
  @credentials ||= ENV['GOOGLE_CLOUD_KEYFILE']
78
79
  raise 'GOOGLE_CLOUD_KEYFILE must be set' if @credentials.nil?
80
+
79
81
  @credentials
80
82
  end
81
83
 
82
84
  def location_id
83
- @location_id ||= ENV["GOOGLE_CLOUD_LOCATION"] || 'global'
85
+ @location_id ||= ENV['GOOGLE_CLOUD_LOCATION'] || 'global'
84
86
  end
85
87
  end
86
88
  end
@@ -12,7 +12,7 @@ module SymmetricEncryption
12
12
  # Notes:
13
13
  # * For development and testing purposes only!!
14
14
  # * Never store the encrypted encryption key in the source code / config file.
15
- def self.generate_data_key(cipher_name:, app_name:, environment:, version: 0, dek: nil, **args)
15
+ def self.generate_data_key(cipher_name:, app_name:, environment:, version: 0, dek: nil, **_args)
16
16
  version >= 255 ? (version = 1) : (version += 1)
17
17
 
18
18
  kek = SymmetricEncryption::Key.new(cipher_name: cipher_name)
@@ -29,7 +29,8 @@ module SymmetricEncryption #:nodoc:
29
29
  config.before_configuration do
30
30
  # Check if already configured
31
31
  unless ::SymmetricEncryption.cipher?
32
- app_name = Rails::Application.subclasses.first.parent.to_s.underscore
32
+ parent_method = Module.method_defined?(:module_parent) ? 'module_parent' : 'parent'
33
+ app_name = Rails::Application.subclasses.first.send(parent_method).to_s.underscore
33
34
  env_var = ENV['SYMMETRIC_ENCRYPTION_CONFIG']
34
35
  config_file =
35
36
  if env_var
@@ -41,11 +42,11 @@ module SymmetricEncryption #:nodoc:
41
42
  if config_file.file?
42
43
  begin
43
44
  ::SymmetricEncryption::Config.load!(file_name: config_file, env: ENV['SYMMETRIC_ENCRYPTION_ENV'] || Rails.env)
44
- rescue ArgumentError => exc
45
+ rescue ArgumentError => e
45
46
  puts "\nSymmetric Encryption not able to read keys."
46
- puts "#{exc.class.name} #{exc.message}"
47
+ puts "#{e.class.name} #{e.message}"
47
48
  puts "To generate a new config file and key files: symmetric-encryption --generate --app-name #{app_name}\n\n"
48
- raise(exc)
49
+ raise(e)
49
50
  end
50
51
  end
51
52
 
@@ -301,5 +301,5 @@ module SymmetricEncryption
301
301
  @cipher = nil
302
302
  @secondary_ciphers = []
303
303
  @select_cipher = nil
304
- @random_iv = false
304
+ @randomize_iv = false
305
305
  end
@@ -98,8 +98,6 @@ module SymmetricEncryption
98
98
 
99
99
  private
100
100
 
101
- attr_reader :client
102
-
103
101
  def whoami
104
102
  @whoami ||= `whoami`.strip
105
103
  rescue StandardError
@@ -31,7 +31,7 @@ module SymmetricEncryption
31
31
  key_path = ::File.dirname(file_name)
32
32
  ::FileUtils.mkdir_p(key_path) unless ::File.directory?(key_path)
33
33
  ::File.rename(file_name, "#{file_name}.#{Time.now.to_i}") if ::File.exist?(file_name)
34
- ::File.open(file_name, 'wb', 0600) { |file| file.write(data) }
34
+ ::File.open(file_name, 'wb', 0o600) { |file| file.write(data) }
35
35
  end
36
36
 
37
37
  # Read from the file, raising an exception if it is not found
@@ -117,8 +117,8 @@ module SymmetricEncryption
117
117
  begin
118
118
  count = re_encrypt_contents(file_name)
119
119
  puts "Re-encrypted #{count} encrypted value(s) in: #{file_name}" if count.positive?
120
- rescue StandardError => exc
121
- puts "Failed re-encrypting the file contents of: #{file_name}. #{exc.class.name}: #{exc.message}"
120
+ rescue StandardError => e
121
+ puts "Failed re-encrypting the file contents of: #{file_name}. #{e.class.name}: #{e.message}"
122
122
  end
123
123
  end
124
124
  end
@@ -127,7 +127,7 @@ module SymmetricEncryption
127
127
  private
128
128
 
129
129
  def regexp
130
- @regexp ||= /#{SymmetricEncryption.cipher.encoded_magic_header}([A-Za-z0-9+\/]+[=\\n]*)/
130
+ @regexp ||= %r{#{SymmetricEncryption.cipher.encoded_magic_header}([A-Za-z0-9+/]+[=\\n]*)}
131
131
  end
132
132
 
133
133
  # Returns [Integer] encrypted file key version.
@@ -1,3 +1,3 @@
1
1
  module SymmetricEncryption
2
- VERSION = '4.3.0'.freeze
2
+ VERSION = '4.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symmetric-encryption
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-02 00:00:00.000000000 Z
11
+ date: 2019-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coercible