ovpn-key 0.9 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c238454ae4b09b3347372b17daae8776013c98fa67df0b8ddc32bab1cbc2ae26
4
- data.tar.gz: 5dbaed34ee69c576b0a9378d822dcfe65b3f87616d67229a5620b0565bceca3a
3
+ metadata.gz: c99917758e757e94de38c31fdf7677d509b0f0436653e93b49d31b3a461479d5
4
+ data.tar.gz: b1b8e23b8f548e068e92d4a1fe98671aa32347dd36e848d712723b5c2294cfc5
5
5
  SHA512:
6
- metadata.gz: 7397aa70d0825d2e2cf98d06844a2d30defa42e4f5bf5fec6e2d3d48a4a484caf380fdf2da90bc33432258fad953d21324f4d06a75559e854c745be62deed562
7
- data.tar.gz: 30c7e1efa60f707a96550c64281916546ff9f73a747a84325af54a3e5cae3c58e0c5258d836291b9219569d567ec84daf15b31a9770d358e2d7ecbaf40cb1306
6
+ metadata.gz: '09dbcde90d8bb4774f36ad0b5a2ad1dae4705d5beb40004acbf4dd05a57c5e6f3898b7046daf03a6f40e64eb008a8a0ac6c5939a7869c3eab19831e5e1b8d4d4'
7
+ data.tar.gz: a26b9e0f97cc9a930fc0fd8e6ae2b46ac3eae15df8ffc3e99661f9fd35b25f08aae48f883fa5f7c9a1c8489ff28a1fd586a2f5f17013db5676168ddfc5dea5cf
data/NOTICE CHANGED
@@ -1,6 +1,6 @@
1
1
  ovpn-key: https://github.com/chillum/ovpn-key
2
2
 
3
- Copyright 2018-2021 Vasily Korytov
3
+ Copyright 2018-2026 Vasily Korytov
4
4
 
5
5
  Licensed under the Apache License, Version 2.0 (the "License");
6
6
  you may not use this software except in compliance with the License.
data/README.md CHANGED
@@ -6,7 +6,7 @@ It's basically a wrapper around OpenSSL API to:
6
6
  * create a self-signed CA
7
7
  * create client and server certificates and pack them to ZIP files along with the OpenVPN config
8
8
  * revoke the certificates
9
- * create a DH keyfile
9
+ * create a DH keyfile (note: discouraged to use in modern OpenVPN configurations)
10
10
 
11
11
  It supports encrypting `.key` files with a passphrase (there is an option to disable that).
12
12
 
@@ -17,9 +17,6 @@ It can be used to manage a non-OpenVPN CA, in that case `--zip` and `--static` s
17
17
  OpenVPN static keys are supported partially, as they should be used for `tls-auth`/`tls-crypt` only.
18
18
  Please note that they are not encrypted regardless of `--nopass` option.
19
19
 
20
- For now this utility should be considered experimental and rather undocumented.
21
- If you're brave, [let me know](https://github.com/chillum/ovpn-key/issues), where the problems are.
22
-
23
20
  ### Installation
24
21
 
25
22
  1. Get [Ruby](https://www.ruby-lang.org/en/documentation/installation/)
@@ -29,7 +26,7 @@ If you're brave, [let me know](https://github.com/chillum/ovpn-key/issues), wher
29
26
 
30
27
  1. `ovpn-key --init`
31
28
  2. edit `ovpn-key.yml`
32
- 3. `ovpn-key --ca --dh`
29
+ 3. `ovpn-key --ca [--dh]`
33
30
  4. `ovpn-key --server --nopass`
34
31
  5. `ovpn-key --client somebody [--nopass]`
35
32
  6. `ovpn-key --revoke somebody`
@@ -52,3 +49,63 @@ This setting is used as a default directory if:
52
49
  2. `--init` is not specified
53
50
 
54
51
  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 use it from your home directory or any other, as long as requirements above are met.
52
+
53
+ ### CA variants supported
54
+
55
+ We still support the old RSA mode, but it's not recommended to use in new configurations,
56
+ NIST curves are recommended if you're starting afresh at the moment, unless you have a very legacy deployment.
57
+
58
+ 1. OpenVPN 2.4+ support NIST curves
59
+ 2. RHEL 8+ supports NIST curves
60
+ 3. Ubuntu 20+ supports NIST curves
61
+
62
+ Thus, we expect all current and even some EOL systems to support NIST curves that we use by default.
63
+
64
+ Example configurations:
65
+
66
+ #### NIST P-384, default since v1.0
67
+ ```yaml
68
+ key_type: secp384r1
69
+ digest: SHA384
70
+ ```
71
+
72
+ #### NIST P-521, probably an overkill
73
+ ```yaml
74
+ key_type: secp521r1
75
+ digest: SHA512
76
+ ```
77
+
78
+ #### NIST P-256, the fastest
79
+ ```yaml
80
+ key_type: secp256r1
81
+ digest: SHA256
82
+ ```
83
+
84
+ #### ed25519, least compatible
85
+ ```yaml
86
+ key_type: ed25519
87
+ #digest: not used
88
+ ```
89
+
90
+ #### RSA 3K, a compromise if you still require RSA
91
+ ```yaml
92
+ #key_type: # commented out
93
+ digest: SHA256
94
+ key_size: 3072
95
+ ```
96
+
97
+ #### RSA 4K, the slowest
98
+ ```yaml
99
+ #key_type: # commented out
100
+ digest: SHA384
101
+ key_size: 4096
102
+ ```
103
+
104
+ Note: your configuration might still use the 2K RSA, this will work, but we recommend to phase out those deployments,
105
+ as they're currently under NIST baseline.
106
+
107
+ ### Mixed mode
108
+
109
+ You can start your CA as RSA and generate newer keys in ECC.
110
+
111
+ Uncomment the `key_type` before you need the ECC key and that's it.
data/bin/ovpn-key CHANGED
@@ -91,10 +91,13 @@ rescue Errno::ENOENT
91
91
  end
92
92
  ZIP_DIR = settings['zip_dir'] || '~'
93
93
  OPENVPN = settings['openvpn'] || 'openvpn'
94
- ENCRYPT = settings['encrypt'] || 'aes128'
95
- DIGEST = settings['digest'] || 'sha256'
96
- KEY_SIZE = settings['key_size'] || 2048
97
94
  CN_CA = settings['ca_name'] || 'Certification Authority'
95
+ ENCRYPT = settings['encrypt'] || 'AES256'
96
+ KEY_SIZE = settings['key_size'] || 3072
97
+ KEY_TYPE = settings['key_type'] # if that's not set, we assume a legacy install with RSA
98
+ DIGEST = unless KEY_TYPE&.casecmp? 'ed25519'
99
+ settings['digest'] || 'SHA384'
100
+ end
98
101
 
99
102
  unless settings['ca_days'].nil?
100
103
  if settings['expire'].nil?
@@ -1,8 +1,9 @@
1
1
  zip_dir: '~'
2
2
  openvpn: openvpn
3
- encrypt: AES128
4
- digest: SHA256
5
- key_size: 2048
3
+ encrypt: AES256
4
+ key_type: secp384r1 # comment this out if you want to use RSA keys
5
+ digest: SHA384 # change this to 256 if using sub-4k RSA keys or P-256
6
+ key_size: 3072 # RSA and DH keys only
6
7
  expire: # days
7
8
  ca: 3650
8
9
  crl: 3650
data/lib/functions.rb CHANGED
@@ -28,12 +28,12 @@ end
28
28
 
29
29
  def unencrypt_ca_key(pass = '')
30
30
  begin
31
- OpenSSL::PKey::RSA.new File.read('ca.key'), pass
32
- rescue OpenSSL::PKey::RSAError
31
+ OpenSSL::PKey.read File.read('ca.key'), pass
32
+ rescue OpenSSL::PKey::PKeyError
33
33
  # this means pass is wrong, so ask for it
34
- OpenSSL::PKey::RSA.new File.read('ca.key'), ask_password('ca')
34
+ OpenSSL::PKey.read File.read('ca.key'), ask_password('ca')
35
35
  end
36
- rescue OpenSSL::PKey::RSAError
36
+ rescue OpenSSL::PKey::PKeyError
37
37
  retry
38
38
  end
39
39
 
@@ -43,28 +43,34 @@ def gen_and_sign(type, certname, password)
43
43
  end
44
44
 
45
45
  def gen_key(certname, password)
46
- key = OpenSSL::PKey::RSA.new(KEY_SIZE)
46
+ key = if KEY_TYPE&.casecmp? 'ed25519'
47
+ OpenSSL::PKey.generate_key(KEY_TYPE)
48
+ elsif KEY_TYPE
49
+ OpenSSL::PKey::EC.generate(KEY_TYPE)
50
+ else
51
+ OpenSSL::PKey::RSA.new(KEY_SIZE)
52
+ end
47
53
  File.write("#{certname}.key",
48
- password ? key.to_pem(OpenSSL::Cipher.new(ENCRYPT), password) : key)
54
+ password ? key.private_to_pem(OpenSSL::Cipher.new(ENCRYPT), password) : key.private_to_pem)
49
55
  end
50
56
 
51
57
  # type is one of: 'ca', 'server', 'client'
52
58
  def sign_key(type, cn, password)
53
59
  certname = type == 'ca' ? 'ca' : cn
54
- key = OpenSSL::PKey::RSA.new File.read("#{certname}.key"), password
60
+ key = OpenSSL::PKey.read File.read("#{certname}.key"), password
55
61
  serial = new_serial
56
- cert = gen_cert(type, cn, key.public_key, serial)
62
+ cert = gen_cert(type, cn, key, serial)
57
63
 
58
64
  ca_key = type == 'ca' ? key : unencrypt_ca_key
59
- cert.sign ca_key, OpenSSL::Digest.new(DIGEST)
65
+ cert.sign ca_key, digest
60
66
 
61
67
  File.write(SERIAL_FILE, serial)
62
68
  File.write("#{certname}.crt", cert.to_pem)
63
69
  end
64
70
 
65
- def gen_cert(type, cn, pubkey, serial)
71
+ def gen_cert(type, cn, key, serial)
66
72
  cert = basic_cert(type, cn)
67
- cert.public_key = pubkey
73
+ cert.public_key = key
68
74
  cert.serial = serial
69
75
 
70
76
  customize_cert(type, cert)
@@ -93,7 +99,7 @@ def customize_cert(type, cert)
93
99
  # rubocop:enable Metrics/MethodLength
94
100
 
95
101
  ef = OpenSSL::X509::ExtensionFactory.new nil, cert
96
- ef.issuer_certificate = cert
102
+ ef.issuer_certificate = type == 'ca' ? cert : OpenSSL::X509::Certificate.new(File.read('ca.crt'))
97
103
 
98
104
  cert.add_extension ef.create_extension('subjectKeyIdentifier', 'hash')
99
105
  cert.add_extension ef.create_extension('authorityKeyIdentifier', 'keyid,issuer:always')
@@ -139,10 +145,16 @@ def update_crl(crl, ca_pass)
139
145
  ca_key = unencrypt_ca_key(ca_pass)
140
146
  crl.last_update = Time.now
141
147
  crl.next_update = time_after_days(EXPIRE['crl'])
142
- crl.sign(ca_key, OpenSSL::Digest.new(DIGEST))
148
+ crl.sign(ca_key, digest)
143
149
  File.write(CRL_FILE, crl.to_pem)
144
150
  end
145
151
 
152
+ def digest
153
+ return unless DIGEST
154
+
155
+ OpenSSL::Digest.new(DIGEST)
156
+ end
157
+
146
158
  def new_serial
147
159
  File.read(SERIAL_FILE).to_i + 1
148
160
  rescue Errno::ENOENT
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- VERSION = '0.9'
3
+ VERSION = '1.0.0'
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: '0.9'
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Korytov
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
- rubygems_version: 4.0.21
59
+ rubygems_version: 4.0.23
60
60
  specification_version: 4
61
61
  summary: Key management utility for OpenVPN
62
62
  test_files: []