ulock 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/ulock +87 -0
- data/lib/ulock.rb +138 -0
- data/lib/version.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7f962e828747aa4fdf94e494e0cac0caa7b3cb86d84318a7a2c81172db334429
|
4
|
+
data.tar.gz: 38b27e0a0ab8656a964474f69a7dd9200d6a25b5f16f01c8d241e11628bac3fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7056bafc47eb763b0479a4450e5bb5ba5deb432001f05d17e7a5d12685af4820561c0ea4cab59ccb22f3e39ad4584fa78fcc09d6115f978f11b225fc9e96b935
|
7
|
+
data.tar.gz: a54838014ae02a88748e44021865b1bb78ef0a6340f47a2d711d2b6fd76352f681d9c31c803769cda4575da417ed0b5daa904e97918adf3afc9bb346a792660e
|
data/bin/ulock
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'ulock'
|
4
|
+
require 'commander'
|
5
|
+
|
6
|
+
Commander.configure do
|
7
|
+
program :name, 'ulock'
|
8
|
+
program :version, '0.1.3'
|
9
|
+
program :description, 'lock and unlock files. Tiny wrapper around gpg'
|
10
|
+
|
11
|
+
command :status do |c|
|
12
|
+
c.syntax = 'ulock status'
|
13
|
+
c.summary = 'list files need encrypting and decrypting'
|
14
|
+
c.action do |args, options|
|
15
|
+
i = Ulock::Interface.new
|
16
|
+
i.status
|
17
|
+
i.shorthelp
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
alias_command :list, :status
|
22
|
+
|
23
|
+
command :encrypt do |c|
|
24
|
+
c.syntax = 'ulock encrypt [-r recipient] file [..other files]'
|
25
|
+
c.summary = 'encrypt a file'
|
26
|
+
c.example 'description', 'ulock encrypt secret.py'
|
27
|
+
c.option '-r', 'recipient'
|
28
|
+
c.action do |args, options|
|
29
|
+
if args.empty?
|
30
|
+
Ulock::PROMPT.say "no file specified"
|
31
|
+
else
|
32
|
+
i = Ulock::Interface.new(options['recipient'])
|
33
|
+
args.each do |file|
|
34
|
+
i.encrypt(file)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
command :decrypt do |c|
|
41
|
+
c.syntax = 'ulock decrypt [file] [...other files]'
|
42
|
+
c.summary = 'decrypt a file'
|
43
|
+
c.example 'decrypt locked file', 'ulock decrypt locked/file.gpg'
|
44
|
+
c.action do |args, options|
|
45
|
+
i = Ulock::Interface.new
|
46
|
+
args.each do |file|
|
47
|
+
i.decrypt(file)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
command :'fix all' do |c|
|
53
|
+
c.syntax = 'ulock fix all [-r recipient]'
|
54
|
+
c.summary = 'encrypt and decrypt all'
|
55
|
+
c.option '-r', 'recipient'
|
56
|
+
c.example 'with a recipient', 'ulock fix all -r owner@example.com'
|
57
|
+
c.action do |args, options|
|
58
|
+
i = Ulock::Interface.new(options.r)
|
59
|
+
i.status
|
60
|
+
if i.any?
|
61
|
+
if !Ulock::PROMPT.no?("Encrypt and decrypt all?")
|
62
|
+
i.fix_all
|
63
|
+
end
|
64
|
+
else
|
65
|
+
i.shorthelp
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
command :'interactive' do |c|
|
71
|
+
c.syntax = 'ulock interactive [-r]'
|
72
|
+
c.summary = 'interactively encrypt and decrypt'
|
73
|
+
c.option '-r STRING', String, 'recipient'
|
74
|
+
c.example 'with a recipient', 'ulock interactive -r owner@example.com'
|
75
|
+
c.action do |args, options|
|
76
|
+
i = Ulock::Interface.new(options.r)
|
77
|
+
if i.any?
|
78
|
+
i.interactive
|
79
|
+
else
|
80
|
+
Ulock::PROMPT.say "There are no files to encrypt or decrypt"
|
81
|
+
i.shorthelp
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
default_command :status
|
87
|
+
end
|
data/lib/ulock.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'tty-prompt'
|
2
|
+
require 'tty-progressbar'
|
3
|
+
|
4
|
+
module Ulock
|
5
|
+
PROMPT = TTY::Prompt.new
|
6
|
+
EXCLUDE_EXTENSIONS = ['.md', '.txt']
|
7
|
+
class << self
|
8
|
+
def files(glob)
|
9
|
+
Dir.glob(glob).reject { |f| File.directory?(f) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def encrypted_files
|
13
|
+
files('**/*.gpg')
|
14
|
+
end
|
15
|
+
|
16
|
+
def other_files
|
17
|
+
glb = "**/*[!.gpg,#{EXCLUDE_EXTENSIONS.join(",")}]"
|
18
|
+
files(glb)
|
19
|
+
end
|
20
|
+
|
21
|
+
def missing_decrypted_version
|
22
|
+
of = other_files
|
23
|
+
encrypted_files.select { |filename| !of.include?(filename.gsub(/.gpg/, '')) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def missing_encrypted_version
|
27
|
+
ef = encrypted_files
|
28
|
+
other_files.select { |filename| !ef.include?(filename + '.gpg') }
|
29
|
+
end
|
30
|
+
|
31
|
+
def encrypt_file(filename, recipient)
|
32
|
+
`gpg -r #{recipient} -e #{filename}`
|
33
|
+
end
|
34
|
+
|
35
|
+
def decrypt_file(encrypted_filename)
|
36
|
+
dest_filename = encrypted_filename.gsub('.gpg', '')
|
37
|
+
`gpg -d #{encrypted_filename} > #{dest_filename}`
|
38
|
+
end
|
39
|
+
|
40
|
+
def decrypt_multiple(filenames)
|
41
|
+
bar = TTY::ProgressBar.new("Decrypting :filename [:bar]", total: filenames.length * 5)
|
42
|
+
filenames.each do |file|
|
43
|
+
decrypt_file file
|
44
|
+
bar.advance 5, filename: file
|
45
|
+
end
|
46
|
+
bar.finish
|
47
|
+
end
|
48
|
+
|
49
|
+
def encrypt_multiple(filenames, recipient)
|
50
|
+
bar = TTY::ProgressBar.new("Encrypting :filename [:bar]", total: filenames.length * 5)
|
51
|
+
filenames.each do |file|
|
52
|
+
bar.advance 5, filename: file
|
53
|
+
encrypt_file file, recipient
|
54
|
+
end
|
55
|
+
bar.finish
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Interface
|
60
|
+
def initialize(recipient=nil)
|
61
|
+
@recipient = recipient
|
62
|
+
end
|
63
|
+
|
64
|
+
def status
|
65
|
+
ef = Ulock.missing_decrypted_version
|
66
|
+
if ef.any?
|
67
|
+
PROMPT.say "#{ef.count} files to be decrypted:", color: :bright_magenta
|
68
|
+
PROMPT.say ef.join("\n"), color: :magenta
|
69
|
+
puts "\n"
|
70
|
+
else
|
71
|
+
PROMPT.say "No files to be decrypted"
|
72
|
+
end
|
73
|
+
|
74
|
+
df = Ulock.missing_encrypted_version
|
75
|
+
if df.any?
|
76
|
+
PROMPT.say "#{df.count} files to be encrypted: \r", color: :bright_blue
|
77
|
+
PROMPT.say df.join("\n"), color: :blue
|
78
|
+
puts "\n"
|
79
|
+
else
|
80
|
+
PROMPT.say "No files to be encrypted"
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def shorthelp
|
86
|
+
if any?
|
87
|
+
PROMPT.say "#{$0} fix all #encrypt and decrypt all", color: :red
|
88
|
+
PROMPT.say "#{$0} interactive #encrypt and decrypt interactively", color: :red
|
89
|
+
end
|
90
|
+
|
91
|
+
PROMPT.say "#{$0} --help #for more", color: :red
|
92
|
+
end
|
93
|
+
|
94
|
+
def any?
|
95
|
+
Ulock.missing_encrypted_version.any? || Ulock.missing_decrypted_version.any?
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_recipient!
|
99
|
+
if !@recipient
|
100
|
+
@recipient = PROMPT.ask("Encryption recipient: ")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def fix_all
|
105
|
+
get_recipient!
|
106
|
+
PROMPT.say "Encrypting and Decrypting all the files"
|
107
|
+
Ulock.encrypt_multiple(Ulock.missing_encrypted_version, @recipient)
|
108
|
+
Ulock.decrypt_multiple(Ulock.missing_decrypted_version)
|
109
|
+
end
|
110
|
+
|
111
|
+
def encrypt(filename)
|
112
|
+
get_recipient!
|
113
|
+
PROMPT.say "adding an encrypted version of #{filename} (r: #{recipient})"
|
114
|
+
Ulock.encrypt_file(filename, @recipient)
|
115
|
+
end
|
116
|
+
|
117
|
+
def decrypt(filename)
|
118
|
+
PROMPT.say "decrypting #{encrypted_filename} to #{encrypted_filename.gsub('.gpg', '')}"
|
119
|
+
Ulock.decrypt_file(filename)
|
120
|
+
end
|
121
|
+
|
122
|
+
private def prompt_encrypt
|
123
|
+
PROMPT.multi_select "Select files for encryption", Ulock.missing_encrypted_version
|
124
|
+
end
|
125
|
+
|
126
|
+
private def prompt_decrypt
|
127
|
+
PROMPT.multi_select "Select files for decryption", Ulock.missing_decrypted_version
|
128
|
+
end
|
129
|
+
|
130
|
+
def interactive
|
131
|
+
get_recipient!
|
132
|
+
to_encrypt = prompt_encrypt
|
133
|
+
to_decrypt = prompt_decrypt
|
134
|
+
Ulock.encrypt_multiple(to_encrypt, @recipient)
|
135
|
+
Ulock.decrypt_multiple(to_decrypt)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ulock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Cobb
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: tty-prompt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: tty-progressbar
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- rwcobbjr@gmail.com
|
86
|
+
executables:
|
87
|
+
- ulock
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- bin/ulock
|
92
|
+
- lib/ulock.rb
|
93
|
+
- lib/version.rb
|
94
|
+
homepage:
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements:
|
113
|
+
- gpg
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.7.6
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Teensy wrapper around gpg, mostly to make it easier to lock up my project
|
119
|
+
euler files
|
120
|
+
test_files: []
|