ovpn-key 1.2.2 → 1.2.4
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.
- checksums.yaml +4 -4
- data/bin/ovpn-key +13 -1
- data/lib/functions.rb +29 -0
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 51acb55f775aa0af543235ac57838cfaaaf63eb79b9cf1d2c2c7497ee59a49c8
|
|
4
|
+
data.tar.gz: ba52864b590e94f8e01c830ee493d8f15e7a2b8128bd986107cfc74123df7015
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 122b47f5f52f508fd8e7f7571a1550e791c94188230565ed568929208c856dbe23747ddb968d3ef0f5e72b565e750b31ab782043e6c744929eed6f82d6205a95
|
|
7
|
+
data.tar.gz: c71dcc46bd3b5815f2d0d469c072bc0825645843a1f4535e4a98be297babcb36846a2580104a875b3b2b8932736c205603cd0767ba565cb5e995c20ddb6d25d8
|
data/bin/ovpn-key
CHANGED
|
@@ -82,10 +82,14 @@ if options[:init]
|
|
|
82
82
|
else
|
|
83
83
|
begin
|
|
84
84
|
rc = YAML.load_file(File.expand_path("~/.#{APP_CONF}"))
|
|
85
|
+
rc ||= {}
|
|
86
|
+
abort "ERROR: invalid ~/.#{APP_CONF}" unless rc.is_a? Hash
|
|
85
87
|
rescue Errno::ENOENT
|
|
86
88
|
# no configuration file in home directory is not an error
|
|
89
|
+
rescue Errno::EACCES, Psych::SyntaxError => e
|
|
90
|
+
abort "ERROR: #{e}"
|
|
87
91
|
end
|
|
88
|
-
Dir.chdir File.expand_path(rc['cd']) if !File.exist?(APP_CONF) && rc['cd']
|
|
92
|
+
Dir.chdir File.expand_path(rc['cd']) if !File.exist?(APP_CONF) && rc && rc['cd']
|
|
89
93
|
end
|
|
90
94
|
|
|
91
95
|
lock_file = File.join(Dir.tmpdir, "ovpn-key-#{Digest::SHA256.hexdigest(Dir.pwd)}.lock")
|
|
@@ -118,8 +122,12 @@ end
|
|
|
118
122
|
|
|
119
123
|
begin
|
|
120
124
|
settings = YAML.load_file(APP_CONF)
|
|
125
|
+
settings ||= {}
|
|
126
|
+
abort "ERROR: invalid #{APP_CONF}" unless settings.is_a? Hash
|
|
121
127
|
rescue Errno::ENOENT
|
|
122
128
|
abort "Run `#{File.basename $PROGRAM_NAME} --init` before generating certificates"
|
|
129
|
+
rescue Errno::EACCES, Psych::SyntaxError => e
|
|
130
|
+
abort "ERROR: #{e}"
|
|
123
131
|
end
|
|
124
132
|
ZIP_DIR = settings['zip_dir'] || if rc && rc['zip_dir']
|
|
125
133
|
rc['zip_dir']
|
|
@@ -230,14 +238,17 @@ if options[:generate_static]
|
|
|
230
238
|
exe "#{OPENVPN} --genkey --secret ta.key"
|
|
231
239
|
end
|
|
232
240
|
if options[:generate_server]
|
|
241
|
+
check_ca
|
|
233
242
|
passphrase = passphrase(options[:no_password], options[:generate_server])
|
|
234
243
|
gen_and_sign('server', options[:generate_server], passphrase)
|
|
235
244
|
end
|
|
236
245
|
if options[:generate_client]
|
|
246
|
+
check_ca
|
|
237
247
|
passphrase = passphrase(options[:no_password], options[:generate_client])
|
|
238
248
|
gen_and_sign('client', options[:generate_client], passphrase)
|
|
239
249
|
end
|
|
240
250
|
if options[:generate_zip]
|
|
251
|
+
check_ca
|
|
241
252
|
ovpn_files = Dir['*.ovpn']
|
|
242
253
|
case ovpn_files.length
|
|
243
254
|
when 1
|
|
@@ -265,5 +276,6 @@ if options[:generate_zip]
|
|
|
265
276
|
end
|
|
266
277
|
end
|
|
267
278
|
if options[:revoke]
|
|
279
|
+
check_ca
|
|
268
280
|
revoke(options[:revoke])
|
|
269
281
|
end
|
data/lib/functions.rb
CHANGED
|
@@ -11,6 +11,12 @@ def check_client(name)
|
|
|
11
11
|
check_crt(name)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
def check_ca
|
|
15
|
+
return if File.exist?('ca.crt') && File.exist?('ca.key')
|
|
16
|
+
|
|
17
|
+
abort "ERROR: no `ca.crt` or `ca.key`. Run `#{File.basename $PROGRAM_NAME} --ca` first."
|
|
18
|
+
end
|
|
19
|
+
|
|
14
20
|
def usage(error)
|
|
15
21
|
abort "ERROR: #{error}\nSee `#{File.basename $PROGRAM_NAME} -h` for usage"
|
|
16
22
|
end
|
|
@@ -59,6 +65,7 @@ end
|
|
|
59
65
|
def gen_and_sign(type, certname, password)
|
|
60
66
|
gen_key(certname, password)
|
|
61
67
|
sign_key(type, certname, password)
|
|
68
|
+
create_crl
|
|
62
69
|
rescue Interrupt, SystemExit
|
|
63
70
|
cleanup certname # clean up the key if it wasn't signed due to user's interrupt
|
|
64
71
|
abort_on_interrupted
|
|
@@ -142,7 +149,9 @@ end
|
|
|
142
149
|
|
|
143
150
|
# rubocop:disable-next Metrics/AbcSize,Metrics/MethodLength
|
|
144
151
|
def revoke(certname)
|
|
152
|
+
create_crl
|
|
145
153
|
crl = OpenSSL::X509::CRL.new(File.read(CRL_FILE))
|
|
154
|
+
|
|
146
155
|
begin
|
|
147
156
|
cert = OpenSSL::X509::Certificate.new(File.read("#{certname}.crt"))
|
|
148
157
|
rescue Errno::ENOENT
|
|
@@ -168,12 +177,31 @@ def cleanup(certname)
|
|
|
168
177
|
}
|
|
169
178
|
end
|
|
170
179
|
|
|
180
|
+
# rubocop:disable-next Metrics/MethodLength
|
|
181
|
+
def create_crl
|
|
182
|
+
return if File.exist? CRL_FILE
|
|
183
|
+
|
|
184
|
+
ca_pass = ''
|
|
185
|
+
begin
|
|
186
|
+
begin
|
|
187
|
+
OpenSSL::PKey.read File.read('ca.key'), ca_pass
|
|
188
|
+
rescue OpenSSL::PKey::PKeyError
|
|
189
|
+
ca_pass = ask_password('ca')
|
|
190
|
+
end
|
|
191
|
+
rescue OpenSSL::PKey::PKeyError
|
|
192
|
+
retry
|
|
193
|
+
end
|
|
194
|
+
gen_crl(ca_pass)
|
|
195
|
+
end
|
|
196
|
+
|
|
171
197
|
def gen_crl(ca_pass)
|
|
172
198
|
return if File.exist? CRL_FILE
|
|
173
199
|
|
|
174
200
|
crl = OpenSSL::X509::CRL.new
|
|
175
201
|
crl.issuer = OpenSSL::X509::Name.new([['CN', CN_CA]] + REQ.to_a)
|
|
176
202
|
update_crl(crl, ca_pass)
|
|
203
|
+
|
|
204
|
+
warn "Created file: #{CRL_FILE}"
|
|
177
205
|
end
|
|
178
206
|
|
|
179
207
|
def update_crl(crl, ca_pass)
|
|
@@ -193,6 +221,7 @@ end
|
|
|
193
221
|
def new_serial
|
|
194
222
|
File.read(SERIAL_FILE).to_i + 1
|
|
195
223
|
rescue Errno::ENOENT
|
|
224
|
+
warn "Created file: #{SERIAL_FILE}"
|
|
196
225
|
1
|
|
197
226
|
end
|
|
198
227
|
|
data/lib/version.rb
CHANGED