attr_keyring 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -64
- data/.travis.yml +14 -6
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/attr_keyring.gemspec +8 -2
- data/bin/console +1 -0
- data/examples/active_record_sample.rb +2 -0
- data/examples/keyring_sample.rb +2 -0
- data/examples/sequel_sample.rb +2 -0
- data/gemfiles/5_2.gemfile +5 -0
- data/gemfiles/6_0.gemfile +5 -0
- data/lib/attr_keyring.rb +26 -7
- data/lib/attr_keyring/active_record.rb +2 -0
- data/lib/attr_keyring/sequel.rb +2 -0
- data/lib/attr_keyring/version.rb +3 -1
- data/lib/keyring.rb +2 -0
- data/lib/keyring/encryptor/aes.rb +5 -1
- data/lib/keyring/key.rb +6 -2
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0a2294de1107eb98157861c1fd9dc4fca1d6c9aa7926838fd461a23965888c8
|
4
|
+
data.tar.gz: 62d4023dfc004823610c281ad5cdc1ac9bdc04d753152fc21b334f0fa99db170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eb8b45d47089caf95ea24d4b3ac1783f0b7dfbda7f1d40f7c178ea03c17cf9a69e1c23df69c073e35b3d27aa0f9bb4c561dfd6f1ea2711f43311b75b7ee0629
|
7
|
+
data.tar.gz: 04bed2be91c97585d3cf64730feab4e8eabea97d52b89e562e1130cdd5676f04c2a85468b93762b4a5b061643475a6063a5c959ade817514be9deb42e0b22ef1
|
data/.rubocop.yml
CHANGED
@@ -1,73 +1,19 @@
|
|
1
|
+
---
|
2
|
+
inherit_gem:
|
3
|
+
rubocop-fnando: .rubocop.yml
|
4
|
+
|
1
5
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
3
|
-
Include:
|
4
|
-
- '**/*.gemspec'
|
5
|
-
- '**/*.podspec'
|
6
|
-
- '**/*.jbuilder'
|
7
|
-
- '**/*.rake'
|
8
|
-
- '**/*.opal'
|
9
|
-
- '**/config.ru'
|
10
|
-
- '**/Gemfile'
|
11
|
-
- '**/Rakefile'
|
12
|
-
- '**/Capfile'
|
13
|
-
- '**/Guardfile'
|
14
|
-
- '**/Podfile'
|
15
|
-
- '**/Thorfile'
|
16
|
-
- '**/Vagrantfile'
|
17
|
-
- '**/Berksfile'
|
18
|
-
- '**/Cheffile'
|
19
|
-
- '**/Vagabondfile'
|
6
|
+
TargetRubyVersion: 2.6
|
20
7
|
|
21
|
-
|
8
|
+
Metrics/AbcSize:
|
22
9
|
Enabled: false
|
23
10
|
|
24
|
-
Style/StringLiterals:
|
25
|
-
EnforcedStyle: double_quotes
|
26
|
-
|
27
|
-
Layout/SpaceInsideBlockBraces:
|
28
|
-
EnforcedStyle: space
|
29
|
-
EnforcedStyleForEmptyBraces: space
|
30
|
-
SpaceBeforeBlockParameters: false
|
31
|
-
|
32
|
-
Layout/SpaceInsideHashLiteralBraces:
|
33
|
-
EnforcedStyle: no_space
|
34
|
-
EnforcedStyleForEmptyBraces: no_space
|
35
|
-
|
36
|
-
Layout/FirstArrayElementLineBreak:
|
37
|
-
Enabled: true
|
38
|
-
|
39
|
-
Layout/FirstHashElementLineBreak:
|
40
|
-
Enabled: true
|
41
|
-
|
42
|
-
Style/SymbolArray:
|
43
|
-
Enabled: true
|
44
|
-
|
45
|
-
Style/PercentLiteralDelimiters:
|
46
|
-
PreferredDelimiters:
|
47
|
-
'%': '[]'
|
48
|
-
'%i': '[]'
|
49
|
-
'%q': '[]'
|
50
|
-
'%Q': '[]'
|
51
|
-
'%r': '{}'
|
52
|
-
'%s': '[]'
|
53
|
-
'%w': '[]'
|
54
|
-
'%W': '[]'
|
55
|
-
'%x': '[]'
|
56
|
-
|
57
11
|
Metrics/LineLength:
|
58
|
-
|
12
|
+
Exclude:
|
13
|
+
- test/**/*
|
59
14
|
|
60
|
-
|
61
|
-
EnforcedStyle: expanded
|
62
|
-
|
63
|
-
Style/FrozenStringLiteralComment:
|
15
|
+
Metrics/MethodLength:
|
64
16
|
Enabled: false
|
65
17
|
|
66
|
-
|
67
|
-
EnforcedStyle: inline
|
68
|
-
|
69
|
-
Style/Alias:
|
70
|
-
EnforcedStyle: prefer_alias_method
|
71
|
-
|
72
|
-
Style/TrailingUnderscoreVariable:
|
18
|
+
Metrics/ClassLength:
|
73
19
|
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,17 +1,25 @@
|
|
1
|
+
---
|
2
|
+
|
1
3
|
language: ruby
|
2
4
|
cache: bundler
|
3
5
|
sudo: false
|
4
6
|
notifications:
|
5
7
|
email: false
|
6
8
|
rvm:
|
7
|
-
- 2.5
|
9
|
+
- 2.6.5
|
10
|
+
- 2.5.7
|
11
|
+
services:
|
12
|
+
- postgresql
|
13
|
+
gemfiles:
|
14
|
+
- gemfiles/6_0.gemfile
|
15
|
+
- gemfiles/5_2.gemfile
|
8
16
|
before_script:
|
9
|
-
- createdb test
|
10
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
-
- chmod +x ./cc-test-reporter
|
12
|
-
- "./cc-test-reporter before-build"
|
17
|
+
- createdb test
|
18
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
19
|
+
- chmod +x ./cc-test-reporter
|
20
|
+
- "./cc-test-reporter before-build"
|
13
21
|
after_script:
|
14
|
-
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
22
|
+
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
15
23
|
env:
|
16
24
|
global:
|
17
25
|
secure: c0y7opFgX78UQL0dVq2gciMr3Ca4y4Aw4cSbQMnUwGecwuzOPUhjV98yy4b6EpQ0bLVbVcSPtx/PCVV750nxJPQsz9tWS0yGxQPBXuh2w0AX+ErYJVYaF6+hTjovEiHB86Q9g8YCD29CIMLZs2yeUrB+ORJWQcuAn8fw475Zskk8d8BWqR8CDdonFKlwS0Bx6rOqkyVy0JiNbOM4+trV/RzrNC+dc1geqOo45ceTYiGzkkMU1XANjNhzl/v0DYtCWLF/Dj1s8da96btqU6msZDfsBM73zKWtu0KJMnzqa8Ba4Tjc39kd2ro6Zb22cELBdXOFBvNCAEjbmZIaJ2OC45fES1OGZnB66SjAScdVdxKy2jOWjlFvrRiHu3Zrbl5tFTEaJ/PMHueQn4AzneK1wU2kzjq5iCwBZtMp/iJtCvz0V6qBt77qJe65YuENhcj26cDMqQkhKd0QBTWNs8r02KY3HFKcprgM+2TXxVSvfDu2cbiMInvc3K+uFNnEbu/1piTyStKWGd64WHixV6CEFpHxLU04IUNB62mSvUZtZ6V782X9kawoRyUg6lWvXmnGUUvczdJdpSR5/3gVXOWHireYy/qA6Zqoup27PPoaNgnKCa/fWvN/aJDvrGJb9OWpiK8DGi6T35V5gtDF+vd8mVzyPnYJznlWLgA5m7FSzLg=
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/attr_keyring.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "./lib/attr_keyring/version"
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
@@ -12,9 +14,12 @@ Gem::Specification.new do |spec|
|
|
12
14
|
spec.license = "MIT"
|
13
15
|
|
14
16
|
# Specify which files should be added to the gem when it is released.
|
15
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
18
|
+
# into git.
|
16
19
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
-
`git ls-files -z
|
20
|
+
`git ls-files -z`
|
21
|
+
.split("\x0")
|
22
|
+
.reject {|f| f.match(%r{^(test|spec|features)/}) }
|
18
23
|
end
|
19
24
|
spec.bindir = "exe"
|
20
25
|
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
@@ -29,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
29
34
|
spec.add_development_dependency "pry-meta"
|
30
35
|
spec.add_development_dependency "rake"
|
31
36
|
spec.add_development_dependency "rubocop"
|
37
|
+
spec.add_development_dependency "rubocop-fnando"
|
32
38
|
spec.add_development_dependency "sequel"
|
33
39
|
spec.add_development_dependency "simplecov"
|
34
40
|
end
|
data/bin/console
CHANGED
data/examples/keyring_sample.rb
CHANGED
data/examples/sequel_sample.rb
CHANGED
data/lib/attr_keyring.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module AttrKeyring
|
2
4
|
require "attr_keyring/version"
|
3
5
|
require "keyring"
|
@@ -73,33 +75,48 @@ module AttrKeyring
|
|
73
75
|
value = value.to_s
|
74
76
|
|
75
77
|
previous_keyring_id = public_send(self.class.keyring_column_name)
|
76
|
-
encrypted_value, keyring_id, digest =
|
78
|
+
encrypted_value, keyring_id, digest =
|
79
|
+
self.class.keyring.encrypt(value, previous_keyring_id)
|
77
80
|
|
78
81
|
public_send("#{self.class.keyring_column_name}=", keyring_id)
|
79
82
|
public_send("encrypted_#{attribute}=", encrypted_value)
|
80
|
-
|
83
|
+
|
84
|
+
return unless respond_to?("#{attribute}_digest=")
|
85
|
+
|
86
|
+
public_send("#{attribute}_digest=", digest)
|
81
87
|
end
|
82
88
|
|
83
89
|
private def attr_decrypt_column(attribute)
|
84
90
|
cache_name = :"@#{attribute}"
|
85
|
-
|
91
|
+
if instance_variable_defined?(cache_name)
|
92
|
+
return instance_variable_get(cache_name)
|
93
|
+
end
|
86
94
|
|
87
95
|
encrypted_value = public_send("encrypted_#{attribute}")
|
96
|
+
|
88
97
|
return unless encrypted_value
|
89
98
|
|
90
|
-
decrypted_value = self.class.keyring.decrypt(
|
99
|
+
decrypted_value = self.class.keyring.decrypt(
|
100
|
+
encrypted_value,
|
101
|
+
public_send(self.class.keyring_column_name)
|
102
|
+
)
|
91
103
|
|
92
104
|
instance_variable_set(cache_name, decrypted_value)
|
93
105
|
end
|
94
106
|
|
95
107
|
private def clear_decrypted_column_cache(attribute)
|
96
108
|
cache_name = :"@#{attribute}"
|
97
|
-
|
109
|
+
|
110
|
+
return unless instance_variable_defined?(cache_name)
|
111
|
+
|
112
|
+
remove_instance_variable(cache_name)
|
98
113
|
end
|
99
114
|
|
100
115
|
private def reset_encrypted_column(attribute)
|
101
116
|
public_send("encrypted_#{attribute}=", nil)
|
102
|
-
|
117
|
+
if respond_to?("#{attribute}_digest=")
|
118
|
+
public_send("#{attribute}_digest=", nil)
|
119
|
+
end
|
103
120
|
nil
|
104
121
|
end
|
105
122
|
|
@@ -113,7 +130,9 @@ module AttrKeyring
|
|
113
130
|
encrypted_value, _, digest = self.class.keyring.encrypt(value)
|
114
131
|
|
115
132
|
public_send("encrypted_#{attribute}=", encrypted_value)
|
116
|
-
|
133
|
+
if respond_to?("#{attribute}_digest")
|
134
|
+
public_send("#{attribute}_digest=", digest)
|
135
|
+
end
|
117
136
|
end
|
118
137
|
|
119
138
|
public_send("#{self.class.keyring_column_name}=", keyring_id)
|
data/lib/attr_keyring/sequel.rb
CHANGED
data/lib/attr_keyring/version.rb
CHANGED
data/lib/keyring.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Keyring
|
2
4
|
module Encryptor
|
3
5
|
module AES
|
@@ -35,7 +37,9 @@ module Keyring
|
|
35
37
|
|
36
38
|
expected_hmac = hmac_digest(key.signing_key, encrypted_payload)
|
37
39
|
|
38
|
-
|
40
|
+
unless verify_signature(expected_hmac, hmac)
|
41
|
+
raise InvalidAuthentication, "Expected HMAC to be #{Base64.strict_encode64(expected_hmac)}; got #{Base64.strict_encode64(hmac)} instead" # rubocop:disable Metrics/LineLength
|
42
|
+
end
|
39
43
|
|
40
44
|
cipher.iv = iv
|
41
45
|
cipher.key = key.encryption_key
|
data/lib/keyring/key.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Keyring
|
2
4
|
class Key
|
3
5
|
attr_reader :id, :signing_key, :encryption_key
|
@@ -11,13 +13,15 @@ module Keyring
|
|
11
13
|
def to_s
|
12
14
|
"#<Keyring::Key id=#{id.inspect}>"
|
13
15
|
end
|
14
|
-
|
16
|
+
alias inspect to_s
|
15
17
|
|
16
18
|
private def parse_key(key)
|
17
19
|
expected_key_size = @key_size * 2
|
18
20
|
secret = decode_key(key, expected_key_size)
|
19
21
|
|
20
|
-
|
22
|
+
unless secret.bytesize == expected_key_size
|
23
|
+
raise InvalidSecret, "Secret must be #{expected_key_size} bytes, instead got #{secret.bytesize}" # rubocop:disable Metrics/LineLength
|
24
|
+
end
|
21
25
|
|
22
26
|
signing_key = secret[0...@key_size]
|
23
27
|
encryption_key = secret[@key_size..-1]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_keyring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-fnando
|
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'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: sequel
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,6 +201,8 @@ files:
|
|
187
201
|
- examples/active_record_sample.rb
|
188
202
|
- examples/keyring_sample.rb
|
189
203
|
- examples/sequel_sample.rb
|
204
|
+
- gemfiles/5_2.gemfile
|
205
|
+
- gemfiles/6_0.gemfile
|
190
206
|
- lib/attr_keyring.rb
|
191
207
|
- lib/attr_keyring/active_record.rb
|
192
208
|
- lib/attr_keyring/sequel.rb
|