uhide 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/uhide.rb +150 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ff1922c774fe0ee1689c5e439ea89e7feb84aa4e1fd247abedbb6b19b64cb22d
4
+ data.tar.gz: 722655053c515950060d854a6e3a9be18a229e40444729bf9c86d572573df506
5
+ SHA512:
6
+ metadata.gz: 296ce7ce84cc4821c69adfc71b91fbb77052de38c95aa8a29b5dc64a8171c036e2b86196ab6f11df2b96e7e479ba2db5834c511200bd6ce7c2746f6ceeabb3ab
7
+ data.tar.gz: e36acce65f04f65f7fd9cd80e7abd4195f6ee9fe266f59b52bd581eaf0270e3ec99bdc5a19caa341f8a6fb85cf88fad47485775fb03b3dc92f36e3d71d3e110d
data/lib/uhide.rb ADDED
@@ -0,0 +1,150 @@
1
+ require 'io/console'
2
+ require 'securerandom'
3
+ require 'active_support'
4
+ require 'colorize'
5
+ require 'yaml'
6
+
7
+ โ˜” = " โ˜” > "
8
+ $๐Ÿ”‘ = " ๐Ÿ”‘ > "
9
+ $๐Ÿง‚ = (lambda { ๐Ÿ—ƒ๏ธ '๐Ÿง‚', SecureRandom.random_bytes })
10
+ $๐Ÿ“ = lambda { ๐Ÿ—ƒ๏ธ '๐Ÿ“', ActiveSupport::MessageEncryptor.key_len }
11
+ INVALID_KEY = 'invalid key'.colorize(:red)
12
+ $cache = {}
13
+
14
+ def password?
15
+ ๐Ÿงผ STDIN.noecho(&:gets)
16
+ end
17
+
18
+ def ๐Ÿšฝ
19
+ print "\r"
20
+ $stdout.flush
21
+ end
22
+
23
+ def โ“ ๐Ÿ”‘, simple: true
24
+ print ๐Ÿ”‘
25
+ password = password?
26
+ $password = password if simple
27
+ ๐Ÿšฝ
28
+ return password
29
+ end
30
+
31
+ def ๐Ÿงผ ๐Ÿ—‘๏ธ
32
+ ๐Ÿ—‘๏ธ.chomp
33
+ end
34
+
35
+ def ๐Ÿ”“ ๐Ÿท๏ธ: nil
36
+ if ๐Ÿท๏ธ.nil?
37
+ puts $cache['ddllv']
38
+ else
39
+ puts $cache['ddllv'][๐Ÿท๏ธ]
40
+ end
41
+
42
+ ๐Ÿ“• = File.read './๐Ÿง‚'
43
+ if ๐Ÿ“•.empty?
44
+ ๐Ÿ”€ = SecureRandom.random_bytes $๐Ÿ“.call
45
+ File.write './๐Ÿง‚', Marshal.dump(๐Ÿ”€)
46
+ return $cache['๐Ÿง‚'] = ๐Ÿ”€
47
+ else
48
+ return $cache['๐Ÿง‚'] = Marshal.load(File.read './๐Ÿง‚')
49
+ end
50
+
51
+ end
52
+
53
+ def ๐Ÿ”’ ๐Ÿท๏ธ, ๐Ÿ’Ž
54
+ $cache['ddllv'][๐Ÿท๏ธ] = ๐Ÿ’Ž
55
+ ๐Ÿ’พ
56
+ end
57
+
58
+ def ๐Ÿค– ๐Ÿ—ฃ๏ธ
59
+ ๐Ÿ‘พ, ๐Ÿท๏ธ, ๐Ÿ’Ž = ๐Ÿ—ฃ๏ธ.split
60
+
61
+ case ๐Ÿ‘พ.to_sym
62
+ when :get
63
+ if ๐Ÿท๏ธ
64
+ ๐Ÿ”“ ๐Ÿท๏ธ: ๐Ÿท๏ธ
65
+ else
66
+ ๐Ÿ”“
67
+ end
68
+
69
+ when :set
70
+ ๐Ÿ”’ ๐Ÿท๏ธ, ๐Ÿ’Ž
71
+
72
+ when :reset
73
+ if โ“($๐Ÿ”‘, simple: false) == $password
74
+ ['ddllv', '๐Ÿง‚', '๐Ÿ“'].each_entry{ |item| File.delete "./#{item}" }
75
+ exit!
76
+ else
77
+ puts INVALID_KEY
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ def ๐Ÿ’พ
85
+ โš›๏ธ = ActiveSupport::MessageEncryptor.new(
86
+ ActiveSupport::KeyGenerator.new($password).generate_key($๐Ÿง‚.call, $๐Ÿ“.call)
87
+ )
88
+
89
+ was_bootstrapped = !(not $cache['ddllv'])
90
+ ๐Ÿ“– = ๐Ÿ—ƒ๏ธ 'ddllv', {}, โš›๏ธ: โš›๏ธ
91
+ ๐Ÿ“€ 'ddllv', ๐Ÿ“–, โš›๏ธ: โš›๏ธ if was_bootstrapped
92
+ end
93
+
94
+ def ๐Ÿ“€ ๐Ÿ—‚๏ธ, ๐Ÿ“–, โš›๏ธ: false
95
+ if โš›๏ธ
96
+ ๐Ÿ“• = โš›๏ธ.encrypt_and_sign ๐Ÿ“–
97
+ else
98
+ ๐Ÿ“• = ๐Ÿ“–
99
+ end
100
+
101
+ ๐Ÿ“• = Marshal.dump(๐Ÿ“•)
102
+ File.write "./#{๐Ÿ—‚๏ธ}", ๐Ÿ“•
103
+ return ๐Ÿ“•
104
+ end
105
+
106
+ def ๐Ÿ—ƒ๏ธ ๐Ÿ—‚๏ธ, ๐Ÿ”€, โš›๏ธ: false
107
+ if $cache[๐Ÿ—‚๏ธ]
108
+ return $cache[๐Ÿ—‚๏ธ]
109
+ end
110
+
111
+ begin
112
+ ๐Ÿ“• = File.read "./#{๐Ÿ—‚๏ธ}"
113
+ rescue Errno::ENOENT
114
+ ๐Ÿ“• = ๐Ÿ“€ ๐Ÿ—‚๏ธ, ๐Ÿ”€, โš›๏ธ: โš›๏ธ
115
+ end
116
+
117
+ if not ๐Ÿ“•.empty?
118
+ ๐Ÿ“• = Marshal.load ๐Ÿ“•
119
+
120
+ if โš›๏ธ
121
+ begin
122
+ ๐Ÿ“– = โš›๏ธ.decrypt_and_verify ๐Ÿ“•
123
+ rescue ActiveSupport::MessageVerifier::InvalidSignature
124
+ puts INVALID_KEY
125
+ exit!
126
+ end
127
+
128
+ else
129
+ ๐Ÿ“– = ๐Ÿ“•
130
+ end
131
+
132
+ end
133
+
134
+ return $cache[๐Ÿ—‚๏ธ] = ๐Ÿ“–
135
+ end
136
+
137
+ begin
138
+ โ“ $๐Ÿ”‘
139
+
140
+ ๐Ÿ’พ
141
+
142
+ loop do
143
+ print โ˜”
144
+ ๐Ÿค–(๐Ÿงผ gets)
145
+ end
146
+
147
+ rescue SystemExit, Interrupt
148
+ ๐Ÿšฝ
149
+ exit!
150
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uhide
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Keen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Allows a regular person to maintain a named list of secrets that's encrypted
14
+ at rest
15
+ email: mwk@mikekeen.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/uhide.rb
21
+ homepage: https://github.com/mkeen/uhide
22
+ licenses:
23
+ - ISC (BSD2/MIT)
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.2.0.rc.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: "โ˜‚๏ธ: Personal encryption fit for a spy"
44
+ test_files: []