ovpn-key 1.1.5 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8072a8287dcb1a2386df0d8f9a420aa7aeef64662ab9341afd23bc818f4c543b
4
- data.tar.gz: 9be53d42013002c533eb87d1128167857897dbe12f12495ef91d17d7cbf7c8cc
3
+ metadata.gz: ea36e4df1c13e126e977c4d1f6f5d57937f27186009998a4fd2ce651df6a23bb
4
+ data.tar.gz: ae5b036e02416bb85cf67261ae6c5c86af107f50e935137f036835cc3d1f3602
5
5
  SHA512:
6
- metadata.gz: 8f49b1b5c2b6b6de6c9005d7b422a3d0e41aee06215cd499f633b334db7371e6082e92ecaa530fc58f96346fb781c9686a8464c610f448714e10dc8d882a2419
7
- data.tar.gz: cdeec55d2f7ae554ef30a2904a884746fad11b0ee2929382d07e8954ba506dea51146aa38921d5b5a4d9593d5e2aa1e6daa991b4b273a95b0e30550ceb2f2f46
6
+ metadata.gz: b052653a567de6cf226737f1d250c6a4fe15026e9f6026ce9de9305935a1b5515e846b4a9eaf3b3477313a948bcf543274e7285ea1934870560223d182a89bcc
7
+ data.tar.gz: 909b63e709afdbb3d3874060f0867330ec8623b1fc5eab77a4286f05822d6ec44958053ecae9de28d81488b63faf0a3c0f3543f153eba4f0c474717721e109e3
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](#ca-variants-supported))
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, it has only one possible setting:
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
- This setting is used as a default directory if:
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
- elsif !File.exist? APP_CONF
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 rc && rc['cd']
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
- OPENVPN = settings['openvpn'] || 'openvpn'
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_TYPE && 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] ? nil : ask_password('ca')
182
- gen_key('ca', ca_pass)
183
- sign_key('ca', CN_CA, ca_pass)
184
- gen_crl(ca_pass)
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
- gen_and_sign('server', options[:generate_server], options[:no_password] ? nil : ask_password(options[:generate_server]))
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
- gen_and_sign('client', options[:generate_client], options[:no_password] ? nil : ask_password(options[:generate_client]))
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
- gen_and_sign('client', options[:generate_zip], options[:no_password] ? nil : ask_password(options[:generate_zip]))
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)
@@ -1,6 +1,3 @@
1
- openvpn: openvpn # openvpn executable, required only for --static
2
- zip_dir: '~' # directory for files generated by --zip
3
-
4
1
  encrypt: AES256
5
2
  digest: SHA384
6
3
  key_type: secp384r1 # comment this out if you want to use RSA keys
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
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- VERSION = '1.1.5'
3
+ VERSION = '1.2.1'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ovpn-key
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Korytov