lockness 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ced30afb2d1a4d26bb196185016fd0913b8060f521c3649e42b141ca1661455d
4
+ data.tar.gz: 76087b974b7b737a97f16d104aa8c8ad36c04c041051023acd4adf30339f5ddd
5
+ SHA512:
6
+ metadata.gz: 298e8af1e29199c2ad2b10c7d57f3fd579b978de8d49daf503e6b2103c41b29c59c10b33d1bf2c6a18ff53190d8b14c443c2d25cdeffce83c711985fbeeefac1
7
+ data.tar.gz: 98672ecc736d01b2ed521b3e57cc83180789531e5c6f142c3372fd7565c58dcbdbe212811ecb436e4d18d68f834e2b6f7a785e76733c2ebc90f96bd1bd19f99d
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,140 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0.2
3
+ NewCops: enable
4
+
5
+ Gemspec/RequiredRubyVersion:
6
+ Enabled: false
7
+
8
+ Layout/EmptyLinesAroundExceptionHandlingKeywords:
9
+ Enabled: false
10
+
11
+ Layout/FirstArrayElementIndentation:
12
+ Enabled: false
13
+
14
+ Layout/HashAlignment:
15
+ EnforcedColonStyle: table
16
+ EnforcedHashRocketStyle: table
17
+
18
+ Layout/EmptyLinesAroundClassBody:
19
+ EnforcedStyle: empty_lines_except_namespace
20
+
21
+ Layout/EmptyLinesAroundModuleBody:
22
+ EnforcedStyle: empty_lines_except_namespace
23
+
24
+ Layout/ExtraSpacing:
25
+ ForceEqualSignAlignment: true
26
+
27
+ Layout/LineLength:
28
+ Enabled: false
29
+
30
+ Layout/SpaceAroundMethodCallOperator:
31
+ Enabled: true
32
+
33
+ Lint/RaiseException:
34
+ Enabled: true
35
+
36
+ Lint/StructNewOverride:
37
+ Enabled: true
38
+
39
+ Layout/SpaceInLambdaLiteral:
40
+ EnforcedStyle: require_space
41
+
42
+ Lint/RescueException:
43
+ Enabled: false
44
+
45
+ Lint/ToJSON:
46
+ Enabled: false
47
+
48
+ Lint/UnusedMethodArgument:
49
+ AutoCorrect: false
50
+
51
+ Metrics/AbcSize:
52
+ Enabled: false
53
+
54
+ Metrics/BlockLength:
55
+ Enabled: false
56
+
57
+ Metrics/ClassLength:
58
+ Enabled: false
59
+
60
+ Metrics/CyclomaticComplexity:
61
+ Enabled: false
62
+
63
+ Metrics/MethodLength:
64
+ Enabled: false
65
+
66
+ Metrics/ModuleLength:
67
+ Enabled: false
68
+
69
+ Metrics/PerceivedComplexity:
70
+ Enabled: false
71
+
72
+ Metrics/ParameterLists:
73
+ Enabled: false
74
+
75
+ Naming/AccessorMethodName:
76
+ Enabled: false
77
+
78
+ Naming/RescuedExceptionsVariableName:
79
+ Enabled: false
80
+
81
+ Naming/VariableNumber:
82
+ Enabled: false
83
+
84
+ Style/CaseEquality:
85
+ Enabled: false
86
+
87
+ Style/ClassAndModuleChildren:
88
+ Enabled: false
89
+
90
+ Style/ClassVars:
91
+ Enabled: false
92
+
93
+ Style/Documentation:
94
+ Enabled: false
95
+
96
+ Style/EmptyMethod:
97
+ Enabled: true
98
+ EnforcedStyle: expanded
99
+
100
+ Style/FormatString:
101
+ Enabled: false
102
+
103
+ Style/FormatStringToken:
104
+ Enabled: false
105
+
106
+ Style/FrozenStringLiteralComment:
107
+ Enabled: false
108
+
109
+ Style/ExponentialNotation:
110
+ Enabled: true
111
+
112
+ Style/HashEachMethods:
113
+ Enabled: true
114
+
115
+ Style/HashTransformKeys:
116
+ Enabled: true
117
+
118
+ Style/HashTransformValues:
119
+ Enabled: true
120
+
121
+ Style/GlobalVars:
122
+ Enabled: false
123
+
124
+ Style/IfUnlessModifier:
125
+ Enabled: false
126
+
127
+ Style/MutableConstant:
128
+ Enabled: false
129
+
130
+ Style/NumericLiterals:
131
+ Enabled: false
132
+
133
+ Style/NumericPredicate:
134
+ Enabled: false
135
+
136
+ Style/RedundantAssignment:
137
+ Enabled: false
138
+
139
+ Style/StabbyLambdaParentheses:
140
+ EnforcedStyle: require_no_parentheses
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lockness (0.1.0)
5
+ activesupport (~> 7.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (7.0.3)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ ast (2.4.2)
16
+ coderay (1.1.3)
17
+ concurrent-ruby (1.1.10)
18
+ i18n (1.10.0)
19
+ concurrent-ruby (~> 1.0)
20
+ interesting_methods (0.1.2)
21
+ method_source (1.0.0)
22
+ minitest (5.15.0)
23
+ parallel (1.22.1)
24
+ parser (3.1.2.0)
25
+ ast (~> 2.4.1)
26
+ pry (0.14.1)
27
+ coderay (~> 1.1)
28
+ method_source (~> 1.0)
29
+ rainbow (3.1.1)
30
+ rake (13.0.6)
31
+ regexp_parser (2.5.0)
32
+ rexml (3.2.5)
33
+ rubocop (1.30.0)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.1.0.0)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml (>= 3.2.5, < 4.0)
39
+ rubocop-ast (>= 1.18.0, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.18.0)
43
+ parser (>= 3.1.1.0)
44
+ rubocop-minitest (0.20.0)
45
+ rubocop (>= 0.90, < 2.0)
46
+ rubocop-rake (0.6.0)
47
+ rubocop (~> 1.0)
48
+ ruby-progressbar (1.11.0)
49
+ tzinfo (2.0.4)
50
+ concurrent-ruby (~> 1.0)
51
+ unicode-display_width (2.1.0)
52
+
53
+ PLATFORMS
54
+ x86_64-darwin-20
55
+
56
+ DEPENDENCIES
57
+ bundler (~> 2.3)
58
+ interesting_methods (~> 0.1)
59
+ lockness!
60
+ minitest (~> 5.15)
61
+ pry (~> 0.14)
62
+ rake (~> 13.0)
63
+ rubocop (~> 1.30)
64
+ rubocop-minitest (~> 0.20)
65
+ rubocop-rake (~> 0.6)
66
+
67
+ BUNDLED WITH
68
+ 2.3.3
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Lockness
2
+
3
+ TODO
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/lockness ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'active_support/all'
4
+ require 'base64'
5
+ require 'digest/sha2'
6
+ require 'openssl'
7
+ require 'securerandom'
8
+ require 'tempfile'
9
+
10
+ lib_file_glob = "#{__dir__}/../lib/**/*.rb"
11
+
12
+ Dir.glob(lib_file_glob).each do |file|
13
+ require_relative file
14
+ end
15
+
16
+ Lockness.start
@@ -0,0 +1,38 @@
1
+ module Lockness
2
+ class Content
3
+
4
+ attr_reader :secret_file,
5
+ :message_encryptor,
6
+ :encrypted
7
+
8
+ def initialize
9
+ @secret_file = SecretFile.new
10
+ @message_encryptor = ActiveSupport::MessageEncryptor.new(MasterKey.new.read)
11
+ @encrypted = secret_file.read
12
+ end
13
+
14
+ def plain
15
+ message_encryptor.decrypt_and_verify(encrypted)
16
+ end
17
+
18
+ def update(new_plain_content)
19
+ ensure_content(new_plain_content)
20
+
21
+ encrypted_content = message_encryptor.encrypt_and_sign(new_plain_content)
22
+
23
+ secret_file.save(encrypted_content)
24
+ end
25
+
26
+ private
27
+
28
+ def ensure_content(new_plain_content)
29
+ return if new_plain_content.present?
30
+
31
+ puts 'No content provided.'
32
+ puts 'Aborting!'
33
+
34
+ exit 1
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,53 @@
1
+ module Lockness
2
+ class Edit
3
+
4
+ attr_reader :secret_file,
5
+ :content,
6
+ :temp_file
7
+
8
+ def initialize
9
+ @secret_file = SecretFile.new
10
+ @content = Content.new
11
+ @temp_file = Tempfile.new
12
+ end
13
+
14
+ def edit
15
+ ensure_temp_file_deleted
16
+
17
+ if secret_file.exist?
18
+ edit_existing
19
+ else
20
+ edit_new
21
+ end
22
+
23
+ puts "File saved: #{secret_file.encrypted_path}"
24
+ end
25
+
26
+ private
27
+
28
+ def edit_new
29
+ open_temp_file_in_editor
30
+ plain_content = temp_file.read
31
+ content.update(plain_content)
32
+ end
33
+
34
+ def edit_existing
35
+ temp_file.write(content.plain)
36
+ temp_file.close
37
+ open_temp_file_in_editor
38
+ plain_content = File.read(temp_file.path)
39
+ content.update(plain_content)
40
+ end
41
+
42
+ def open_temp_file_in_editor
43
+ `#{ENV.fetch('EDITOR')} #{temp_file.path}`
44
+ end
45
+
46
+ def ensure_temp_file_deleted
47
+ at_exit do
48
+ temp_file.unlink
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,29 @@
1
+ module Lockness
2
+ class EnsureMasterKeyGitIgnored
3
+
4
+ def ensure_master_key_git_ignored
5
+ master_key = MasterKey.new
6
+
7
+ return unless git_repo?
8
+ return unless master_key.exist?
9
+ return if ignored_files.include?('master.key')
10
+
11
+ puts "You must git ignore #{master_key.path} to use lockness."
12
+
13
+ exit 1
14
+ end
15
+
16
+ def ignored_files
17
+ files = `git status --short --ignored`
18
+
19
+ files.split("\n")
20
+ .select { |status_line| status_line.starts_with?('!!') }
21
+ .map { |status_line| status_line.split.last }
22
+ end
23
+
24
+ def git_repo?
25
+ `git -C #{Dir.pwd} rev-parse 2>/dev/null; echo $?`.chomp == '0'
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ module Lockness
2
+ module Help
3
+
4
+ def self.show
5
+ puts help
6
+ end
7
+
8
+ def self.help
9
+ <<~HELP
10
+ USAGE:
11
+
12
+ lockness init # generates a master.key
13
+ lockness edit <filename> # create or edit a new file
14
+ lockness show <filename> # view an encrypted file
15
+ lockness # show this help
16
+ HELP
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ module Lockness
2
+ class MasterKey
3
+
4
+ def read
5
+ ensure_exists
6
+
7
+ File.read(path)
8
+ end
9
+
10
+ def generate
11
+ ensure_does_not_exist
12
+
13
+ master_key = SecureRandom.hex
14
+
15
+ File.write(path, master_key)
16
+
17
+ puts "Generated master key and saved at #{path}"
18
+ end
19
+
20
+ def path
21
+ "#{Dir.pwd}/master.key"
22
+ end
23
+
24
+ def exist?
25
+ File.exist?(path)
26
+ end
27
+
28
+ private
29
+
30
+ def ensure_exists
31
+ return if exist?
32
+
33
+ puts "Expected to find #{path}"
34
+ puts 'Run `lockness init` to generate a master.key'
35
+ exit 1
36
+ end
37
+
38
+ def ensure_does_not_exist
39
+ return unless exist?
40
+
41
+ puts "Master key already exists at #{path}!"
42
+ puts 'Please delete and try again'
43
+
44
+ exit 1
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,49 @@
1
+ module Lockness
2
+ class SecretFile
3
+
4
+ attr_reader :path
5
+
6
+ def initialize
7
+ @path = build_path
8
+ end
9
+
10
+ def exist?
11
+ File.exist?(encrypted_path)
12
+ end
13
+
14
+ def unencrypted_path
15
+ path.chomp('.enc')
16
+ end
17
+
18
+ def encrypted_path
19
+ if path.ends_with?('.enc')
20
+ path
21
+ else
22
+ "#{path}.enc"
23
+ end
24
+ end
25
+
26
+ def read
27
+ return unless exist?
28
+
29
+ File.read(encrypted_path)
30
+ end
31
+
32
+ def save(encrypted_content)
33
+ File.write(encrypted_path, encrypted_content)
34
+ end
35
+
36
+ private
37
+
38
+ def build_path
39
+ path_arg = ARGV.last
40
+
41
+ if path_arg.starts_with?('/')
42
+ path_arg
43
+ else
44
+ File.join(Dir.pwd, path_arg)
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ module Lockness
2
+ class Show
3
+
4
+ attr_reader :secret_file
5
+
6
+ def initialize
7
+ @secret_file = SecretFile.new
8
+ end
9
+
10
+ def show
11
+ if secret_file.exist?
12
+ puts Content.new.plain
13
+ else
14
+ puts "No file at #{secret_file.encrypted_path}"
15
+
16
+ exit 1
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Lockness
2
+
3
+ VERSION = '0.1.0'
4
+
5
+ end
data/lib/lockness.rb ADDED
@@ -0,0 +1,20 @@
1
+ module Lockness
2
+
3
+ def self.start
4
+ EnsureMasterKeyGitIgnored.new.ensure_master_key_git_ignored
5
+
6
+ if ARGV.first == 'init' && ARGV.count == 1
7
+ MasterKey.new.generate
8
+ elsif ARGV.first == 'edit' && ARGV.count == 2
9
+ Edit.new.edit
10
+ elsif ARGV.first == 'show' && ARGV.count == 2
11
+ Show.new.show
12
+ elsif ARGV.first == 'help' && ARGV.count == 1 || ARGV.none?
13
+ Help.show
14
+ else
15
+ puts "Unable to process arguments: '#{ARGV.join(' ')}'"
16
+ exit 1
17
+ end
18
+ end
19
+
20
+ end
data/lockness.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'lockness/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'lockness'
8
+ spec.authors = ['Sean Lerner']
9
+ spec.email = ['sean@@smallcity.ca']
10
+ spec.files = `git ls-files`.split.reject { |f| f.match('test') }
11
+ spec.homepage = 'https://github.com/seanlerner/lockness'
12
+ spec.license = 'MIT'
13
+ spec.metadata['rubygems_mfa_required'] = 'true'
14
+ spec.require_paths = ['lib']
15
+ spec.summary = 'Manage encrypted secrets'
16
+ spec.version = Lockness::VERSION
17
+ spec.executables << 'lockness'
18
+
19
+ spec.add_dependency 'activesupport', '~> 7.0'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 2.3'
22
+ spec.add_development_dependency 'interesting_methods', '~> 0.1'
23
+ spec.add_development_dependency 'minitest', '~> 5.15'
24
+ spec.add_development_dependency 'pry', '~> 0.14'
25
+ spec.add_development_dependency 'rake', '~> 13.0'
26
+ spec.add_development_dependency 'rubocop', '~> 1.30'
27
+ spec.add_development_dependency 'rubocop-minitest', '~> 0.20'
28
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6'
29
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lockness
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sean Lerner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: interesting_methods
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.14'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.30'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.30'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.20'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.20'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.6'
139
+ description:
140
+ email:
141
+ - sean@@smallcity.ca
142
+ executables:
143
+ - lockness
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rubocop.yml"
149
+ - Gemfile
150
+ - Gemfile.lock
151
+ - README.md
152
+ - Rakefile
153
+ - bin/lockness
154
+ - lib/lockness.rb
155
+ - lib/lockness/content.rb
156
+ - lib/lockness/edit.rb
157
+ - lib/lockness/ensure_master_key_git_ignored.rb
158
+ - lib/lockness/help.rb
159
+ - lib/lockness/master_key.rb
160
+ - lib/lockness/secret_file.rb
161
+ - lib/lockness/show.rb
162
+ - lib/lockness/version.rb
163
+ - lockness.gemspec
164
+ homepage: https://github.com/seanlerner/lockness
165
+ licenses:
166
+ - MIT
167
+ metadata:
168
+ rubygems_mfa_required: 'true'
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubygems_version: 3.3.3
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Manage encrypted secrets
188
+ test_files: []