ovpn-key 1.1.5 → 1.2.0
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/README.md +11 -3
- data/bin/ovpn-key +48 -11
- data/defaults/ovpn-key.yml +0 -3
- data/lib/functions.rb +22 -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: 12a8dfc02e3752450ea384809f2174f37ab15808c11112c0ffa863e2881acb6e
|
|
4
|
+
data.tar.gz: bc4a6989271bd77f26443a15df2baa4780bfdeeffd4c1100e664d6d59c26d9ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 04dfd8d8865bdeada6f61a8ef907cc3074310341322037e1b3d680031194a39f7954cd31f876901d29b5266247cbc68b290d506b619e7b413ab56d4f6dfa05db
|
|
7
|
+
data.tar.gz: 2f870ea24a12261deb32381405752836893713d0905e57bfbcd36a7ad7a0e6cb936ce9916b831ac4694430ba0a2e7533a693e6144ebaa0bf147fc923f5161daf
|
data/README.md
CHANGED
|
@@ -39,7 +39,7 @@ Generating a certificate with existing name will fail, no harm will be done.
|
|
|
39
39
|
|
|
40
40
|
1. `ovpn-key --init` to initialize current directory
|
|
41
41
|
or `ovpn-key --init some/dir` to create the working directory
|
|
42
|
-
2. edit the `ovpn-key.yml` (see [docs](#
|
|
42
|
+
2. edit the `ovpn-key.yml` (see [docs](#configuration))
|
|
43
43
|
3. create the CA (once)
|
|
44
44
|
`ovpn-key --ca`
|
|
45
45
|
4. generate and sign a server certificate (once per server)
|
|
@@ -105,17 +105,25 @@ It will contain:
|
|
|
105
105
|
|
|
106
106
|
It's just a single simple YAML file named [`ovpn-key.yml`](defaults/ovpn-key.yml).
|
|
107
107
|
|
|
108
|
-
ovpn-key also processes `~/.ovpn-key.yml` file
|
|
108
|
+
ovpn-key also processes `~/.ovpn-key.yml` file with three possible settings:
|
|
109
109
|
```yaml
|
|
110
110
|
cd: ~/some/path
|
|
111
|
+
zip_dir: ~
|
|
112
|
+
openvpn: openvpn
|
|
111
113
|
```
|
|
112
114
|
|
|
113
|
-
|
|
115
|
+
The `cd` setting is used as a default working directory if:
|
|
114
116
|
1. current directory does not have `ovpn-key.yml`
|
|
115
117
|
2. `--init` is not specified
|
|
116
118
|
|
|
117
119
|
If you specify the default directory, you don't need to travel to it every time you want to launch `ovpn-key`, i.e. you can sign and revoke certs without traveling to the directory with certs.
|
|
118
120
|
|
|
121
|
+
The `zip_dir` is the directory for `--zip` files, can be overridden in work directory `ovpn-key.yml`.
|
|
122
|
+
Default is `~`, i.e. user's home directory.
|
|
123
|
+
|
|
124
|
+
`openvpn` is path to OpenVPN binary for generating `--static` keys, it can be overridden in work directory `ovpn-key.yml`.
|
|
125
|
+
If you have `openvpn` in `$PATH`, no need to specify this.
|
|
126
|
+
|
|
119
127
|
### CA variants supported
|
|
120
128
|
|
|
121
129
|
We still support the old RSA mode, but it's not recommended to use in new configurations,
|
data/bin/ovpn-key
CHANGED
|
@@ -79,13 +79,13 @@ if options[:init]
|
|
|
79
79
|
FileUtils.copy_file(File.expand_path("defaults/#{APP_CONF}", "#{__dir__}/.."), "./#{APP_CONF}")
|
|
80
80
|
warn "Created file: #{APP_CONF}"
|
|
81
81
|
end
|
|
82
|
-
|
|
82
|
+
else
|
|
83
83
|
begin
|
|
84
84
|
rc = YAML.load_file(File.expand_path("~/.#{APP_CONF}"))
|
|
85
85
|
rescue Errno::ENOENT
|
|
86
86
|
# no configuration file in home directory is not an error
|
|
87
87
|
end
|
|
88
|
-
Dir.chdir File.expand_path(rc['cd']) if
|
|
88
|
+
Dir.chdir File.expand_path(rc['cd']) if !File.exist?(APP_CONF) && rc['cd']
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
lock_file = File.join(Dir.tmpdir, "ovpn-key-#{Digest::SHA256.hexdigest(Dir.pwd)}.lock")
|
|
@@ -121,8 +121,16 @@ begin
|
|
|
121
121
|
rescue Errno::ENOENT
|
|
122
122
|
abort "Run `#{File.basename $PROGRAM_NAME} --init` before generating certificates"
|
|
123
123
|
end
|
|
124
|
-
ZIP_DIR = settings['zip_dir']
|
|
125
|
-
|
|
124
|
+
ZIP_DIR = settings['zip_dir'] || if rc && rc['zip_dir']
|
|
125
|
+
rc['zip_dir']
|
|
126
|
+
else
|
|
127
|
+
'~'
|
|
128
|
+
end
|
|
129
|
+
OPENVPN = settings['openvpn'] || if rc && rc['openvpn']
|
|
130
|
+
rc['openvpn']
|
|
131
|
+
else
|
|
132
|
+
'openvpn'
|
|
133
|
+
end
|
|
126
134
|
CN_CA = settings['ca_name'] || 'Certification Authority'
|
|
127
135
|
ENCRYPT = settings['encrypt'] || 'AES256'
|
|
128
136
|
KEY_SIZE = settings['key_size'] || 3072
|
|
@@ -177,11 +185,37 @@ if File.exist? 'openssl.ini'
|
|
|
177
185
|
warn 'WARNING: openssl.ini file is not used anymore. you can remove it'
|
|
178
186
|
end
|
|
179
187
|
|
|
188
|
+
phase_out = nil
|
|
189
|
+
unless ENCRYPT.casecmp? 'AES256'
|
|
190
|
+
warn "WARNING: your CA uses #{ENCRYPT}, not AES256"
|
|
191
|
+
phase_out = true
|
|
192
|
+
end
|
|
193
|
+
unless DIGEST&.match?(/\Asha(384|512)\z/i)
|
|
194
|
+
warn "WARNING: your CA uses #{DIGEST}; SHA384 or SHA512 are recommended instead"
|
|
195
|
+
phase_out = true
|
|
196
|
+
end
|
|
197
|
+
if KEY_TYPE && !KEY_TYPE&.match?(/\A(secp(384|521)r1|ML-DSA-87)\z/i)
|
|
198
|
+
warn "WARNING: your CA uses #{KEY_TYPE}, we recommend using secp384r1, secp521r1, ML-DSA-87 or RSA"
|
|
199
|
+
phase_out = true
|
|
200
|
+
end
|
|
201
|
+
if KEY_SIZE < 3072
|
|
202
|
+
warn "WARNING: your CA uses #{KEY_SIZE}-bit keys, 3072 is a recommended minimum"
|
|
203
|
+
phase_out = true
|
|
204
|
+
end
|
|
205
|
+
if phase_out
|
|
206
|
+
warn "WARNING: it's recommended to phase out this deployment and start afresh with better security"
|
|
207
|
+
end
|
|
208
|
+
|
|
180
209
|
if options[:generate_ca]
|
|
181
|
-
ca_pass = options[:no_password]
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
210
|
+
ca_pass = passphrase(options[:no_password], 'ca')
|
|
211
|
+
begin
|
|
212
|
+
gen_key('ca', ca_pass)
|
|
213
|
+
sign_key('ca', CN_CA, ca_pass)
|
|
214
|
+
gen_crl(ca_pass)
|
|
215
|
+
rescue Interrupt, SystemExit
|
|
216
|
+
cleanup 'ca' # delete the CA it it's not complete
|
|
217
|
+
abort_on_interrupted
|
|
218
|
+
end
|
|
185
219
|
end
|
|
186
220
|
if options[:generate_dh]
|
|
187
221
|
File.open('dh.pem', 'w') do |f|
|
|
@@ -194,10 +228,12 @@ if options[:generate_static]
|
|
|
194
228
|
exe "#{OPENVPN} --genkey --secret ta.key"
|
|
195
229
|
end
|
|
196
230
|
if options[:generate_server]
|
|
197
|
-
|
|
231
|
+
passphrase = passphrase(options[:no_password], options[:generate_server])
|
|
232
|
+
gen_and_sign('server', options[:generate_server], passphrase)
|
|
198
233
|
end
|
|
199
234
|
if options[:generate_client]
|
|
200
|
-
|
|
235
|
+
passphrase = passphrase(options[:no_password], options[:generate_client])
|
|
236
|
+
gen_and_sign('client', options[:generate_client], passphrase)
|
|
201
237
|
end
|
|
202
238
|
if options[:generate_zip]
|
|
203
239
|
ovpn_files = Dir['*.ovpn']
|
|
@@ -210,7 +246,8 @@ if options[:generate_zip]
|
|
|
210
246
|
abort 'More than one .ovpn files in current directory, aborting'
|
|
211
247
|
end
|
|
212
248
|
|
|
213
|
-
|
|
249
|
+
passphrase = passphrase(options[:no_password], options[:generate_zip])
|
|
250
|
+
gen_and_sign('client', options[:generate_zip], passphrase)
|
|
214
251
|
|
|
215
252
|
zip_file = File.join(File.expand_path(ZIP_DIR), "#{File.basename ovpn_file, '.ovpn'}.tblk.zip")
|
|
216
253
|
FileUtils.rm_f(zip_file)
|
data/defaults/ovpn-key.yml
CHANGED
data/lib/functions.rb
CHANGED
|
@@ -19,6 +19,21 @@ def exe(cmd)
|
|
|
19
19
|
system(cmd) || abort("error executing: #{cmd}")
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
def passphrase(no_pass, cert_name)
|
|
23
|
+
return if no_pass
|
|
24
|
+
|
|
25
|
+
begin
|
|
26
|
+
passphrase = ask_password(cert_name)
|
|
27
|
+
rescue Interrupt, SystemExit
|
|
28
|
+
abort_on_interrupted
|
|
29
|
+
end
|
|
30
|
+
passphrase
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def abort_on_interrupted
|
|
34
|
+
abort "\nInterrupted, aborting!"
|
|
35
|
+
end
|
|
36
|
+
|
|
22
37
|
def ask_password(name)
|
|
23
38
|
password = ''
|
|
24
39
|
loop do
|
|
@@ -44,6 +59,9 @@ end
|
|
|
44
59
|
def gen_and_sign(type, certname, password)
|
|
45
60
|
gen_key(certname, password)
|
|
46
61
|
sign_key(type, certname, password)
|
|
62
|
+
rescue Interrupt, SystemExit
|
|
63
|
+
cleanup certname # clean up the key if it wasn't signed due to user's interrupt
|
|
64
|
+
abort_on_interrupted
|
|
47
65
|
end
|
|
48
66
|
|
|
49
67
|
def gen_key(certname, password)
|
|
@@ -137,6 +155,10 @@ def revoke(certname)
|
|
|
137
155
|
crl.next_update = time_after_days(EXPIRE['crl'])
|
|
138
156
|
crl.add_revoked(revoke)
|
|
139
157
|
update_crl(crl, '')
|
|
158
|
+
cleanup certname
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def cleanup(certname)
|
|
140
162
|
%w[crt key].each {|ext|
|
|
141
163
|
begin
|
|
142
164
|
File.delete "#{certname}.#{ext}"
|
data/lib/version.rb
CHANGED