lockness 0.1.0 → 0.2.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: ced30afb2d1a4d26bb196185016fd0913b8060f521c3649e42b141ca1661455d
4
- data.tar.gz: 76087b974b7b737a97f16d104aa8c8ad36c04c041051023acd4adf30339f5ddd
3
+ metadata.gz: b98cede040b3978d3e632eed0ef4c419705aa575830f89a0f833924d335dc9aa
4
+ data.tar.gz: a9f960a5295d0616f78a31652514043d34cffa4bdcc84d645bc7e7e81735c023
5
5
  SHA512:
6
- metadata.gz: 298e8af1e29199c2ad2b10c7d57f3fd579b978de8d49daf503e6b2103c41b29c59c10b33d1bf2c6a18ff53190d8b14c443c2d25cdeffce83c711985fbeeefac1
7
- data.tar.gz: 98672ecc736d01b2ed521b3e57cc83180789531e5c6f142c3372fd7565c58dcbdbe212811ecb436e4d18d68f834e2b6f7a785e76733c2ebc90f96bd1bd19f99d
6
+ metadata.gz: 15b2444f0d0751ac5c027cd652e75d49f63e3219dfc651079a135d6253984d8a19f8c7eb6f97ae0f2608278002b18723663917c203322a58023e7d1d2c51c1c6
7
+ data.tar.gz: ac6de43d94d50c0d053d772ce5c283aaadba92b07f0bbda97a6dbafba2b51c36656118a475c4a127cfabc4a8a4b34ad79ec4ddbf56eac3edeff42f211e468a41
data/README.md CHANGED
@@ -1,3 +1,20 @@
1
1
  # Lockness
2
2
 
3
- TODO
3
+ Lockness manages encrypted files from the command line and from within your program.
4
+
5
+ It provides similar functionality to the `rails credentials:show` and `rails credentials:edit` tasks but can be used for any file in a plain old ruby app.
6
+
7
+ # Usage -- Command Line
8
+
9
+ ```
10
+ lockness init # generates a master.key
11
+ lockness edit <filename> # create or edit a new file
12
+ lockness show <filename> # view an encrypted file
13
+ lockness # show this help
14
+ ```
15
+
16
+ # Usage -- Within application
17
+
18
+ ```ruby
19
+ Lockness.decrypt('<path to encrypted file>')
20
+ ```
data/bin/lockness CHANGED
@@ -1,16 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
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
3
+ require_relative '../lib/lockness'
15
4
 
16
5
  Lockness.start
@@ -1,18 +1,25 @@
1
1
  module Lockness
2
2
  class Content
3
3
 
4
- attr_reader :secret_file,
4
+ attr_reader :encrypted_file,
5
5
  :message_encryptor,
6
6
  :encrypted
7
7
 
8
- def initialize
9
- @secret_file = SecretFile.new
8
+ def initialize(encrypted_file:)
9
+ @encrypted_file = encrypted_file
10
10
  @message_encryptor = ActiveSupport::MessageEncryptor.new(MasterKey.new.read)
11
- @encrypted = secret_file.read
11
+ @encrypted = encrypted_file.read
12
12
  end
13
13
 
14
14
  def plain
15
15
  message_encryptor.decrypt_and_verify(encrypted)
16
+
17
+ rescue ActiveSupport::MessageVerifier::InvalidSignature => exception
18
+ puts "Unable to decrypt using the master.key."
19
+ puts
20
+ puts "Please double check that the master.key is correct."
21
+
22
+ exit 1
16
23
  end
17
24
 
18
25
  def update(new_plain_content)
@@ -20,7 +27,7 @@ module Lockness
20
27
 
21
28
  encrypted_content = message_encryptor.encrypt_and_sign(new_plain_content)
22
29
 
23
- secret_file.save(encrypted_content)
30
+ encrypted_file.save(encrypted_content)
24
31
  end
25
32
 
26
33
  private
@@ -0,0 +1,23 @@
1
+ module Lockness
2
+ class Decrypt
3
+
4
+ attr_reader :encrypted_file
5
+
6
+ def initialize(path:)
7
+ @encrypted_file = EncryptedFile.new(path: path)
8
+
9
+ file_not_found unless encrypted_file.exist?
10
+ end
11
+
12
+ def decrypt
13
+ Content.new(encrypted_file: encrypted_file).plain
14
+ end
15
+
16
+ private
17
+
18
+ def file_not_found
19
+ raise "Could not find the file '#{encrypted_file.path}'"
20
+ end
21
+
22
+ end
23
+ end
data/lib/lockness/edit.rb CHANGED
@@ -1,26 +1,26 @@
1
1
  module Lockness
2
2
  class Edit
3
3
 
4
- attr_reader :secret_file,
4
+ attr_reader :encrypted_file,
5
5
  :content,
6
6
  :temp_file
7
7
 
8
8
  def initialize
9
- @secret_file = SecretFile.new
10
- @content = Content.new
9
+ @encrypted_file = EncryptedFile.new(path: PathBuilder.path)
10
+ @content = Content.new(encrypted_file: encrypted_file)
11
11
  @temp_file = Tempfile.new
12
12
  end
13
13
 
14
14
  def edit
15
15
  ensure_temp_file_deleted
16
16
 
17
- if secret_file.exist?
17
+ if encrypted_file.exist?
18
18
  edit_existing
19
19
  else
20
20
  edit_new
21
21
  end
22
22
 
23
- puts "File saved: #{secret_file.encrypted_path}"
23
+ puts "File saved: #{encrypted_file.encrypted_path}"
24
24
  end
25
25
 
26
26
  private
@@ -1,10 +1,10 @@
1
1
  module Lockness
2
- class SecretFile
2
+ class EncryptedFile
3
3
 
4
4
  attr_reader :path
5
5
 
6
- def initialize
7
- @path = build_path
6
+ def initialize(path:)
7
+ @path = path
8
8
  end
9
9
 
10
10
  def exist?
@@ -33,17 +33,5 @@ module Lockness
33
33
  File.write(encrypted_path, encrypted_content)
34
34
  end
35
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
36
  end
49
37
  end
@@ -4,7 +4,7 @@ module Lockness
4
4
  def read
5
5
  ensure_exists
6
6
 
7
- File.read(path)
7
+ File.read(path).strip
8
8
  end
9
9
 
10
10
  def generate
@@ -0,0 +1,15 @@
1
+ module Lockness
2
+ module PathBuilder
3
+
4
+ def self.path
5
+ path_arg = ARGV.last
6
+
7
+ if path_arg.starts_with?('/')
8
+ path_arg
9
+ else
10
+ File.join(Dir.pwd, path_arg)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module Lockness
2
+ module Setup
3
+
4
+ def self.setup
5
+ require 'active_support/all'
6
+ require 'base64'
7
+ require 'digest/sha2'
8
+ require 'openssl'
9
+ require 'securerandom'
10
+ require 'tempfile'
11
+
12
+ require_relative '../lockness'
13
+
14
+ Dir.glob("#{__dir__}/*.rb").each do |file|
15
+ require_relative file
16
+ end
17
+ end
18
+
19
+ end
20
+ end
data/lib/lockness/show.rb CHANGED
@@ -1,21 +1,33 @@
1
1
  module Lockness
2
2
  class Show
3
3
 
4
- attr_reader :secret_file
4
+ attr_reader :encrypted_file
5
5
 
6
6
  def initialize
7
- @secret_file = SecretFile.new
7
+ @encrypted_file = EncryptedFile.new(path: PathBuilder.path)
8
8
  end
9
9
 
10
10
  def show
11
- if secret_file.exist?
12
- puts Content.new.plain
11
+ if encrypted_file.exist?
12
+ puts Content.new(encrypted_file: encrypted_file).plain
13
13
  else
14
- puts "No file at #{secret_file.encrypted_path}"
14
+ puts "No file at #{encrypted_file.encrypted_path}"
15
15
 
16
16
  exit 1
17
17
  end
18
18
  end
19
19
 
20
+ private
21
+
22
+ def build_path
23
+ path_arg = ARGV.last
24
+
25
+ if path_arg.starts_with?('/')
26
+ path_arg
27
+ else
28
+ File.join(Dir.pwd, path_arg)
29
+ end
30
+ end
31
+
20
32
  end
21
33
  end
@@ -1,5 +1,5 @@
1
1
  module Lockness
2
2
 
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
 
5
5
  end
data/lib/lockness.rb CHANGED
@@ -17,4 +17,12 @@ module Lockness
17
17
  end
18
18
  end
19
19
 
20
+ def self.decrypt(path)
21
+ Decrypt.new(path: path).decrypt
22
+ end
23
+
20
24
  end
25
+
26
+ require "lockness/setup"
27
+
28
+ Lockness::Setup.setup
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Lerner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-30 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -153,11 +153,14 @@ files:
153
153
  - bin/lockness
154
154
  - lib/lockness.rb
155
155
  - lib/lockness/content.rb
156
+ - lib/lockness/decrypt.rb
156
157
  - lib/lockness/edit.rb
158
+ - lib/lockness/encrypted_file.rb
157
159
  - lib/lockness/ensure_master_key_git_ignored.rb
158
160
  - lib/lockness/help.rb
159
161
  - lib/lockness/master_key.rb
160
- - lib/lockness/secret_file.rb
162
+ - lib/lockness/path_builder.rb
163
+ - lib/lockness/setup.rb
161
164
  - lib/lockness/show.rb
162
165
  - lib/lockness/version.rb
163
166
  - lockness.gemspec
@@ -181,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
184
  - !ruby/object:Gem::Version
182
185
  version: '0'
183
186
  requirements: []
184
- rubygems_version: 3.3.3
187
+ rubygems_version: 3.3.7
185
188
  signing_key:
186
189
  specification_version: 4
187
190
  summary: Manage encrypted secrets