lockbox 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 723ecf0e8367d053e2e80afddfa954559901f1b8c44d3a7cdb3ad562b3f5135a
4
- data.tar.gz: 6c512616214fa1fdca743539769e1d2bd5f91135337a904b89ba58273dc9dbc5
3
+ metadata.gz: 4ba37bc916c02e18555640f29e47483898a96e04b75639b49ce9a0003fbaa443
4
+ data.tar.gz: 750a53ca3201e51b6dc0221305d4c021d64716a163a2e0cfc98c11ec8d1b6af8
5
5
  SHA512:
6
- metadata.gz: 440177ac7cbe84f4e20eeedffe3045060debab17f178631bcba0b631e2e4c656bce1c0977f3af9dc84ce06788cf370626fed9053d3a4503632bc3daa0b6ab43d
7
- data.tar.gz: ab23683aa75ff078b88cdfb65f29564691f5785b49549fa1d9286baf11a9959f7d49f0a21a7c84d10dd7d181c8affd05ca739769cdbe68193e4fb211f9a932af
6
+ metadata.gz: b4e23752c311bf6b161e6817ab204ba0b5936594db5c2509c3f5ef6e354c169097a1c799d7b5147daa0d68982f072d1d22363019c6881566403517f97a5f2c45
7
+ data.tar.gz: 51ab913facdc34aea3e3ef263dab2fa5c3852aa052de80804ec29019c2517df9244eefb8c15e6f2c1ca0059bfd4f9cc020ce00fff543874f6461faeec1e78443
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.6.2 (2020-02-08)
2
+
3
+ - Added `inet` type
4
+ - Fixed error when `lockbox` key in Rails credentials has a string value
5
+ - Fixed deprecation warning with Active Record 6.1
6
+
1
7
  ## 0.6.1 (2020-12-03)
2
8
 
3
9
  - Added integration with Rails credentials
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-2020 Andrew Kane
3
+ Copyright (c) 2018-2021 Andrew Kane
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -27,7 +27,7 @@ Generate a key
27
27
  Lockbox.generate_key
28
28
  ```
29
29
 
30
- Store the key with your other secrets. This is typically Rails credentials or an environment variable ([dotenv](https://github.com/bkeepers/dotenv) is great for this). Be sure to use different keys in development and production. Keys don’t need to be hex-encoded, but it’s often easier to store them this way.
30
+ Store the key with your other secrets. This is typically Rails credentials or an environment variable ([dotenv](https://github.com/bkeepers/dotenv) is great for this). Be sure to use different keys in development and production.
31
31
 
32
32
  Set the following environment variable with your key (you can use this one in development)
33
33
 
@@ -121,6 +121,7 @@ class User < ApplicationRecord
121
121
  encrypts :properties, type: :json
122
122
  encrypts :settings, type: :hash
123
123
  encrypts :messages, type: :array
124
+ encrypts :ip, type: :inet
124
125
  end
125
126
  ```
126
127
 
@@ -1086,12 +1087,29 @@ end
1086
1087
 
1087
1088
  ## Upgrading
1088
1089
 
1090
+ ### 0.6.0
1091
+
1092
+ 0.6.0 adds `encrypted: true` to Active Storage metadata for new files. This field is informational, but if you prefer to add it to existing files, use:
1093
+
1094
+ ```ruby
1095
+ User.with_attached_license.find_each do |user|
1096
+ next unless user.license.attached?
1097
+
1098
+ metadata = user.license.metadata
1099
+ unless metadata["encrypted"]
1100
+ user.license.blob.update!(metadata: metadata.merge("encrypted" => true))
1101
+ end
1102
+ end
1103
+ ```
1104
+
1089
1105
  ### 0.3.6
1090
1106
 
1091
1107
  0.3.6 makes content type detection more reliable for Active Storage. You can check and update the content type of existing files with:
1092
1108
 
1093
1109
  ```ruby
1094
- User.find_each do |user|
1110
+ User.with_attached_license.find_each do |user|
1111
+ next unless user.license.attached?
1112
+
1095
1113
  license = user.license
1096
1114
  content_type = Marcel::MimeType.for(license.download, name: license.filename.to_s)
1097
1115
  if content_type != license.content_type
@@ -16,9 +16,7 @@ module Lockbox
16
16
  end
17
17
 
18
18
  def data_type
19
- # use connection_config instead of connection.adapter
20
- # so database connection isn't needed
21
- case ActiveRecord::Base.connection_config[:adapter].to_s
19
+ case adapter
22
20
  when /postg/i # postgres, postgis
23
21
  "jsonb"
24
22
  when /mysql/i
@@ -27,6 +25,16 @@ module Lockbox
27
25
  "text"
28
26
  end
29
27
  end
28
+
29
+ # use connection_config instead of connection.adapter
30
+ # so database connection isn't needed
31
+ def adapter
32
+ if ActiveRecord::VERSION::STRING.to_f >= 6.1
33
+ ActiveRecord::Base.connection_db_config.adapter.to_s
34
+ else
35
+ ActiveRecord::Base.connection_config[:adapter].to_s
36
+ end
37
+ end
30
38
  end
31
39
  end
32
40
  end
data/lib/lockbox/model.rb CHANGED
@@ -22,7 +22,8 @@ module Lockbox
22
22
  # end
23
23
 
24
24
  custom_type = options[:type].respond_to?(:serialize) && options[:type].respond_to?(:deserialize)
25
- raise ArgumentError, "Unknown type: #{options[:type]}" unless custom_type || [nil, :string, :boolean, :date, :datetime, :time, :integer, :float, :binary, :json, :hash, :array].include?(options[:type])
25
+ valid_types = [nil, :string, :boolean, :date, :datetime, :time, :integer, :float, :binary, :json, :hash, :array, :inet]
26
+ raise ArgumentError, "Unknown type: #{options[:type]}" unless custom_type || valid_types.include?(options[:type])
26
27
 
27
28
  activerecord = defined?(ActiveRecord::Base) && self < ActiveRecord::Base
28
29
  raise ArgumentError, "Type not supported yet with Mongoid" if options[:type] && !activerecord
@@ -426,6 +427,14 @@ module Lockbox
426
427
  message = ActiveRecord::Type::Float.new.serialize(message)
427
428
  # double precision, big endian
428
429
  message = [message].pack("G") unless message.nil?
430
+ when :inet
431
+ unless message.nil?
432
+ ip = message.is_a?(IPAddr) ? message : (IPAddr.new(message) rescue nil)
433
+ # same format as Postgres, with ipv4 padded to 16 bytes
434
+ # family, netmask, ip
435
+ # return nil for invalid IP like Active Record
436
+ message = ip ? [ip.ipv4? ? 0 : 1, ip.prefix, ip.hton].pack("CCa16") : nil
437
+ end
429
438
  when :string, :binary
430
439
  # do nothing
431
440
  # encrypt will convert to binary
@@ -472,6 +481,11 @@ module Lockbox
472
481
  when :binary
473
482
  # do nothing
474
483
  # decrypt returns binary string
484
+ when :inet
485
+ family, prefix, addr = message.unpack("CCa16")
486
+ len = family == 0 ? 4 : 16
487
+ message = IPAddr.new_ntoh(addr.first(len))
488
+ message.prefix = prefix
475
489
  else
476
490
  # use original name for serialized attributes
477
491
  type = (try(:attribute_types) || {})[original_name.to_s]
@@ -2,7 +2,8 @@ module Lockbox
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "lockbox" do |app|
4
4
  if defined?(Rails.application.credentials)
5
- Lockbox.master_key ||= Rails.application.credentials.dig(:lockbox, :master_key)
5
+ # needs to work when lockbox key has a string value
6
+ Lockbox.master_key ||= Rails.application.credentials.try(:lockbox).try(:fetch, :master_key, nil)
6
7
  end
7
8
 
8
9
  require "lockbox/carrier_wave_extensions" if defined?(CarrierWave)
@@ -1,3 +1,3 @@
1
1
  module Lockbox
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
metadata CHANGED
@@ -1,199 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-04 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: carrierwave
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: combustion
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '1.3'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '1.3'
55
- - !ruby/object:Gem::Dependency
56
- name: rails
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '5'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '5'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rbnacl
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '6'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '6'
111
- - !ruby/object:Gem::Dependency
112
- name: sqlite3
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: pg
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: mysql2
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
- - !ruby/object:Gem::Dependency
154
- name: shrine
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: shrine-mongoid
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: benchmark-ips
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
+ dependencies: []
195
13
  description:
196
- email: andrew@chartkick.com
14
+ email: andrew@ankane.org
197
15
  executables: []
198
16
  extensions: []
199
17
  extra_rdoc_files: []
@@ -240,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
58
  - !ruby/object:Gem::Version
241
59
  version: '0'
242
60
  requirements: []
243
- rubygems_version: 3.1.4
61
+ rubygems_version: 3.2.3
244
62
  signing_key:
245
63
  specification_version: 4
246
64
  summary: Modern encryption for Ruby and Rails