manageiq-password 0.3.0 → 1.0.0

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: 21eeaae385f4eadc2ca2cd9bebd5127e3139a8392a54eeb767e8b2481ada3f11
4
- data.tar.gz: 92ea5e0fd4d9a2609cc960025cb0f4537049d9efa11c75a7d97120faed516854
3
+ metadata.gz: 9a506e65c484778a8b89cc16300e5145922de810e612499fe5046015e8668915
4
+ data.tar.gz: 5322663567882ef7b24f4275d9a6f21e1d967bd086de0afe64dcdf45d67e868d
5
5
  SHA512:
6
- metadata.gz: 00ee2ce9764d6420633663fabfb255ce39288c131869472fd5d7b510767156ea90a37cf200f1516b21b66745d934264f2dee3dcaf1eac4f6e4b463561aca18e7
7
- data.tar.gz: 905c37a40c89f39d99cfdc7503d3b4ac5d6056bb81192ee149dd7157348e74286a211172607071100ed59c22e74aa5664b3cd0f766499500f70bf5793f1d1edc
6
+ metadata.gz: 3ea27faaef7f610f5f07f67e19c1b27739c43f418f9662cfbf558d6a05168f0002b8697a1ec782b540b29b99e67a9d25996b03e1ad5cf9044d3644b5b3aaa9cb
7
+ data.tar.gz: 4b5e896206731cdd5895b1a90165c69af0bbdd789bf86509e2d4e1568a7a3437b794e043094a9183d09612717a67b278b5d32733523e3652698abcb637dd5ad0
data/.codeclimate.yml CHANGED
@@ -1,11 +1,14 @@
1
- ---
2
1
  version: '2'
3
2
  prepare:
4
3
  fetch:
5
- - url: https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml
4
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_base.yml
6
5
  path: ".rubocop_base.yml"
7
- - url: https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_cc_base.yml
6
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_cc_base.yml
8
7
  path: ".rubocop_cc_base.yml"
8
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/base.yml
9
+ path: styles/base.yml
10
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/cc_base.yml
11
+ path: styles/cc_base.yml
9
12
  checks:
10
13
  argument-count:
11
14
  enabled: false
@@ -28,3 +31,4 @@ plugins:
28
31
  rubocop:
29
32
  enabled: true
30
33
  config: ".rubocop_cc.yml"
34
+ channel: rubocop-0-82
data/.rubocop.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  inherit_from:
2
- - https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml
3
- - .rubocop_local.yml
2
+ - ".rubocop_local.yml"
3
+ inherit_gem:
4
+ manageiq-style: ".rubocop_base.yml"
data/.rubocop_cc.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  inherit_from:
2
- - .rubocop_base.yml
3
- - .rubocop_cc_base.yml
4
- - .rubocop_local.yml
2
+ - ".rubocop_base.yml"
3
+ - ".rubocop_cc_base.yml"
4
+ - ".rubocop_local.yml"
data/.travis.yml CHANGED
@@ -1,12 +1,10 @@
1
1
  ---
2
2
  language: ruby
3
- sudo: false
4
3
  cache: bundler
5
4
  rvm:
6
- - 2.4.5
7
- - 2.5.3
8
- before_install:
9
- - gem install bundler
5
+ - 2.6.7
6
+ - 2.7.3
7
+ - 3.0.1
10
8
  before_script:
11
9
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
10
  - chmod +x ./cc-test-reporter
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [1.0.0] - 2021-05-05
8
+ ### Removed
9
+ - **BREAKING**: Drop support for legacy v0 and v1 keys [[#14](https://github.com/ManageIQ/manageiq-password/pull/14)]
10
+ - **BREAKING**: Drop add_legacy_key and related methods [[#15](https://github.com/ManageIQ/manageiq-password/pull/15)]
11
+ - Legacy key support via recrypt should now pass the legacy key to the recrypt
12
+ method as a parameter, as ManageIQ::Password will no longer store the legacy
13
+ key
14
+ - **BREAKING**: Drop deprecated methods [[#16](https://github.com/ManageIQ/manageiq-password/pull/16)]
15
+
16
+ [Unreleased]: https://github.com/ManageIQ/more_core_extensions/compare/v1.0.0...HEAD
17
+ [1.0.0]: https://github.com/ManageIQ/more_core_extensions/compare/v1.0.0...v0.3.0
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ManageIQ Password
2
2
 
3
- [![Build Status](https://travis-ci.org/ManageIQ/manageiq-password.svg)](https://travis-ci.org/ManageIQ/manageiq-password)
3
+ [![Build Status](https://travis-ci.com/ManageIQ/manageiq-password.svg)](https://travis-ci.com/ManageIQ/manageiq-password)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/85064711d083dea96636/maintainability)](https://codeclimate.com/github/ManageIQ/manageiq-password/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/85064711d083dea96636/test_coverage)](https://codeclimate.com/github/ManageIQ/manageiq-password/test_coverage)
6
6
 
@@ -1,4 +1,5 @@
1
1
  require "manageiq/password/version"
2
+ require "manageiq/password/password_mixin"
2
3
 
3
4
  require 'openssl'
4
5
  require 'base64'
@@ -8,9 +9,8 @@ module ManageIQ
8
9
  class Password
9
10
  class PasswordError < StandardError; end
10
11
 
11
- CURRENT_VERSION = "2"
12
- REGEXP = /v([0-2]):\{([^}]*)\}/
13
- REGEXP_PASSWORD = /v[0-2](:\{[^}]*\}|%3A%7B.*?%7D)/ # for "v2:{...}" or its URL encoded string
12
+ REGEXP = /v2:\{([^}]*)\}/
13
+ REGEXP_PASSWORD = /v2(:\{[^}]*\}|%3A%7B.*?%7D)/ # for "v2:{...}" or its URL encoded string
14
14
  REGEXP_START_LINE = /^#{REGEXP}/
15
15
  MASK = '********'.freeze
16
16
 
@@ -22,58 +22,47 @@ module ManageIQ
22
22
  @encStr = encrypt(str)
23
23
  end
24
24
 
25
- def encrypt(str, ver = "v2", key = self.class.keys[ver])
26
- value = key.encrypt64(str).delete("\n") unless str.nil? || str.empty?
27
- "#{ver}:{#{value}}"
28
- end
25
+ def encrypt(str, key = self.class.key)
26
+ return str if str.nil?
29
27
 
30
- def decrypt(str, legacy = false)
31
- if str.nil? || str.empty?
32
- str
33
- else
34
- ver, enc = self.class.split(str)
35
- return "" if enc.empty?
28
+ enc = key.encrypt64(str).delete("\n") unless str.empty?
29
+ self.class.wrap(enc)
30
+ end
36
31
 
37
- ver ||= "0" # if we don't know what it is, just assume legacy
38
- key_name = (ver == "2" && legacy) ? "alt" : "v#{ver}"
32
+ def decrypt(str, key = self.class.key)
33
+ enc = self.class.unwrap(str)
34
+ return enc if enc.nil? || enc.empty?
39
35
 
40
- begin
41
- self.class.keys[key_name].decrypt64(enc).force_encoding('UTF-8')
42
- rescue
43
- raise PasswordError, "can not decrypt v#{ver}_key encrypted string"
44
- end
36
+ begin
37
+ key.decrypt64(enc).force_encoding('UTF-8')
38
+ rescue
39
+ raise PasswordError, "cannot decrypt encrypted string"
45
40
  end
46
41
  end
47
42
 
48
- def recrypt(str)
49
- return str if str.nil? || str.empty?
50
- decrypted_str =
51
- begin
52
- # if a legacy v2 key exists, give decrypt the option to use that
53
- decrypt(str, self.class.keys["alt"])
54
- rescue
55
- source_version = self.class.split(str).first || "0"
56
- if source_version == "0" # it probably wasn't encrypted
57
- return str
58
- elsif source_version == "2" # tried with an alt key, see if regular v2 key works
59
- decrypt(str)
60
- else
61
- raise
62
- end
63
- end
43
+ def recrypt(str, prior_key = nil)
44
+ return str if str.nil?
45
+
46
+ decrypted_str = decrypt(str, prior_key) if prior_key rescue nil
47
+ decrypted_str ||= decrypt(str)
64
48
  encrypt(decrypted_str)
65
49
  end
66
50
 
67
- def self.encrypt(str)
68
- new.encrypt(str) if str
51
+ def self.encrypt(*args)
52
+ new.encrypt(*args)
53
+ end
54
+
55
+ def self.decrypt(*args)
56
+ new.decrypt(*args)
69
57
  end
70
58
 
71
- def self.decrypt(str)
72
- new.decrypt(str)
59
+ def self.recrypt(*args)
60
+ new.recrypt(*args)
73
61
  end
74
62
 
75
63
  def self.encrypted?(str)
76
- !!split(str).first
64
+ return false if str.nil? || str.empty?
65
+ !!unwrap(str)
77
66
  end
78
67
 
79
68
  def self.md5crypt(str)
@@ -101,52 +90,21 @@ module ManageIQ
101
90
  encrypted?(str) ? str : encrypt(str)
102
91
  end
103
92
 
104
- # @returns [ver, enc]
105
- def self.split(encrypted_str)
106
- if encrypted_str.nil? || encrypted_str.empty?
107
- [nil, encrypted_str]
108
- else
109
- if encrypted_str =~ REGEXP_START_LINE
110
- [$1, $2]
111
- elsif legacy = extract_erb_encrypted_value(encrypted_str)
112
- if legacy =~ REGEXP_START_LINE
113
- [$1, $2]
114
- else
115
- ["0", legacy]
116
- end
117
- else
118
- [nil, encrypted_str]
119
- end
120
- end
121
- end
122
-
123
93
  def self.key_root
124
94
  @@key_root ||= ENV["KEY_ROOT"]
125
95
  end
126
96
 
127
97
  def self.key_root=(key_root)
128
- clear_keys
98
+ @@key = nil
129
99
  @@key_root = key_root
130
100
  end
131
101
 
132
- def self.clear_keys
133
- @@all_keys = nil
134
- end
135
-
136
- def self.all_keys
137
- keys.values
138
- end
139
-
140
- def self.keys
141
- @@all_keys ||= {"v2" => load_v2_key}.delete_if { |_n, v| v.nil? }
102
+ def self.key=(key)
103
+ @@key = key
142
104
  end
143
105
 
144
- def self.v2_key
145
- keys["v2"]
146
- end
147
-
148
- def self.load_v2_key
149
- load_key_file("v2_key") || begin
106
+ def self.key
107
+ @@key ||= load_key_file("v2_key") || begin
150
108
  key_file = File.expand_path("v2_key", key_root)
151
109
  msg = <<-EOS
152
110
  #{key_file} doesn't exist!
@@ -158,46 +116,42 @@ module ManageIQ
158
116
  passwords in your database.
159
117
  EOS
160
118
  Kernel.warn msg
119
+ nil
161
120
  end
162
121
  end
163
122
 
164
- def self.add_legacy_key(filename, type = "alt")
165
- key = load_key_file(filename, type != :v0)
166
- keys[type.to_s] = key if key
167
- key
123
+ def self.generate_symmetric(filename = nil)
124
+ Key.new.tap { |key| store_key_file(filename, key) if filename }
168
125
  end
169
126
 
170
- # used by tests only
171
- def self.v2_key=(key)
172
- (@@all_keys ||= {})["v2"] = key
127
+ protected
128
+
129
+ def self.wrap(encrypted_str)
130
+ "v2:{#{encrypted_str}}"
173
131
  end
174
132
 
175
- def self.generate_symmetric(filename = nil)
176
- Key.new.tap { |key| store_key_file(filename, key) if filename }
133
+ def self.unwrap(str)
134
+ _unwrap(str) || _unwrap(extract_erb_encrypted_value(str))
177
135
  end
178
136
 
179
- protected
137
+ private_class_method def self._unwrap(str)
138
+ return str if str.nil? || str.empty?
139
+ str.match(REGEXP_START_LINE)&.public_send(:[], 1)
140
+ end
180
141
 
181
142
  def self.store_key_file(filename, key)
182
143
  File.write(filename, key.to_h.to_yaml)
183
144
  end
184
145
 
185
- def self.load_key_file(filename, recent = true)
146
+ def self.load_key_file(filename)
186
147
  return filename if filename.respond_to?(:decrypt64)
187
148
 
188
149
  # if it is an absolute path, or relative to pwd, leave as is
189
150
  # otherwise, look in key root for it
190
151
  filename = File.expand_path(filename, key_root) unless File.exist?(filename)
191
- if !File.exist?(filename)
192
- nil
193
- elsif recent
194
- params = YAML.load_file(filename)
195
- Key.new(*params.values_at(:algorithm, :key, :iv))
196
- else
197
- params = YAML.load_file(filename)
198
- algorithm, key, iv = params.values_at(:algorithm, :key, :iv)
199
- Key.new(algorithm, key && Base64.encode64(key), iv && Base64.encode64(iv))
200
- end
152
+ return nil unless File.exist?(filename)
153
+
154
+ Key.new(*YAML.load_file(filename).values_at(:algorithm, :key, :iv))
201
155
  end
202
156
 
203
157
  def self.extract_erb_encrypted_value(value)
@@ -1,5 +1,3 @@
1
- require "manageiq-password"
2
-
3
1
  module ManageIQ
4
2
  class Password
5
3
  module PasswordMixin
@@ -1,3 +1,2 @@
1
1
  require "manageiq/password/rspec_matchers/be_decrypted"
2
2
  require "manageiq/password/rspec_matchers/be_encrypted"
3
- require "manageiq/password/rspec_matchers/be_encrypted_version"
@@ -25,6 +25,6 @@ RSpec::Matchers.define :be_encrypted do |expected|
25
25
  end
26
26
 
27
27
  description do
28
- "expect to be an encrypted v2 password (with optional encrypted value)"
28
+ "expect to be an encrypted password (with optional encrypted value)"
29
29
  end
30
30
  end
@@ -1,5 +1,5 @@
1
1
  module ManageIQ
2
2
  class Password
3
- VERSION = "0.3.0".freeze
3
+ VERSION = "1.0.0".freeze
4
4
  end
5
5
  end
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec", "~> 3.0"
22
+ spec.add_development_dependency "manageiq-style"
23
+ spec.add_development_dependency "rake", ">= 12.3.3"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
24
25
  spec.add_development_dependency "simplecov"
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-password
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Authors
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,20 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: manageiq-style
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: '10.0'
47
+ version: 12.3.3
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: '10.0'
54
+ version: 12.3.3
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,8 +80,8 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
- description:
70
- email:
83
+ description:
84
+ email:
71
85
  executables: []
72
86
  extensions: []
73
87
  extra_rdoc_files: []
@@ -79,6 +93,7 @@ files:
79
93
  - ".rubocop_cc.yml"
80
94
  - ".rubocop_local.yml"
81
95
  - ".travis.yml"
96
+ - CHANGELOG.md
82
97
  - CODE_OF_CONDUCT.md
83
98
  - Gemfile
84
99
  - LICENSE.txt
@@ -92,14 +107,13 @@ files:
92
107
  - lib/manageiq/password/rspec_matchers.rb
93
108
  - lib/manageiq/password/rspec_matchers/be_decrypted.rb
94
109
  - lib/manageiq/password/rspec_matchers/be_encrypted.rb
95
- - lib/manageiq/password/rspec_matchers/be_encrypted_version.rb
96
110
  - lib/manageiq/password/version.rb
97
111
  - manageiq-password.gemspec
98
112
  homepage: https://github.com/ManageIQ/manageiq-password
99
113
  licenses:
100
114
  - Apache-2.0
101
115
  metadata: {}
102
- post_install_message:
116
+ post_install_message:
103
117
  rdoc_options: []
104
118
  require_paths:
105
119
  - lib
@@ -114,9 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
128
  - !ruby/object:Gem::Version
115
129
  version: '0'
116
130
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.7.6
119
- signing_key:
131
+ rubygems_version: 3.1.4
132
+ signing_key:
120
133
  specification_version: 4
121
134
  summary: A simple encryption util for storing passwords in a database.
122
135
  test_files: []
@@ -1,21 +0,0 @@
1
- require "manageiq-password"
2
-
3
- RSpec::Matchers.define :be_encrypted_version do |expected|
4
- match do |actual|
5
- ManageIQ::Password.split(actual).first == expected.to_s
6
- end
7
-
8
- failure_message do |actual|
9
- actual_version = ManageIQ::Password.split(actual).first
10
- actual_version_text = actual_version ? "encrypted with version #{actual_version}" : "not encrypted"
11
- "expected: #{actual.inspect} to be encrypted with version #{expected} but is #{actual_version_text}"
12
- end
13
-
14
- failure_message_when_negated do |actual|
15
- "expected: #{actual.inspect} not to be encrypted with version #{expected}"
16
- end
17
-
18
- description do
19
- "expect to be encrypted with a particular version of miq password (e.g.: 2)"
20
- end
21
- end