ovpn-key 1.1.2 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d515fee311a6e6b14bf198a846cb815c3db731d86470376f1a86e63e623af283
4
- data.tar.gz: c47751c735bf76b63fefad045156619f8ce12f6481fc2dab10879cfff8d0db83
3
+ metadata.gz: d7c9c65faa9894017f0452d5635b065a3caaa363ee7ded648200f46180a78102
4
+ data.tar.gz: 7814a7ad2ead53e20b6c72be3e3eabef7abda62d70fb9e6fcafa4a6429b20215
5
5
  SHA512:
6
- metadata.gz: bd97b1f2c774d19a798cc95f85dc3db594642ddd4ef4a6eade66e778e3afa90a6104ec2b624ead4d2726fa62b1fabe965d1b6aa079f98c40fd34109031c33d45
7
- data.tar.gz: b26e0ad49688ae7b059c2cdacabd7a398b9f08cb84dda0bfb78127c50f803123991972c081201e41a8cfaa4a9c38f3e03b822ab882752b9e9852f8ca3c1236a6
6
+ metadata.gz: 62d5d6cb60f781a9936d78b5eedd33c4fa5e148561fcb2a1843f675ceffd1af4e8c17b83c2b3a3f02277f99065e1db71b6d1dbdbe7d27856618b92c9528ef1d3
7
+ data.tar.gz: 27101a8464276930606d1b65825805eed56efecd28f56ace804ef37b67b28b0ef44bc962fef7f8b3564a79a8783ab4065e060d384bfde6afdcf6e0d15098b98d
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  This utility is designed as [easy-rsa](https://github.com/OpenVPN/easy-rsa) replacement.
4
4
  Comes with ease of use and sane defaults.
5
5
 
6
- It's a wrapper around OpenSSL API to:
6
+ It uses the OpenSSL API to:
7
7
  * create a self-signed CA
8
8
  * create server certificates
9
9
  * create client certificates and optionally pack them to ZIP files along with the OpenVPN config
@@ -16,19 +16,69 @@ It also can be used to manage a non-OpenVPN or non-self signed CA.
16
16
  1. Get [Ruby](https://www.ruby-lang.org/en/documentation/installation/) (3.0 or greater is supported)
17
17
  2. Run `gem install ovpn-key`
18
18
 
19
+ ### Working directory structure
20
+
21
+ The working directory contains everything needed to manage the CA and its certificates. Keep it backed up.
22
+
23
+ Important: `ca.key` is the CA's private key. Protect it carefully and never distribute it to VPN clients.
24
+ Losing it means you can no longer issue certificates or generate updated CRLs for this CA.
25
+
26
+ There's a flat directory with configuration, generated keys and metadata:
27
+ * `ovpn-key.yml`: [configuration](https://github.com/chillum/ovpn-key/blob/master/defaults/ovpn-key.yml)
28
+ * `serial`: incremental counter
29
+ * `crl.pem`: certificate revocation list, `crl-verify` in OpenVPN's config
30
+ * `ca.crt`: public key for the CA
31
+ * `ca.key`: private key for the CA
32
+
33
+ When a certificate named `server` is created, `server.crt` and `server.key` are created.
34
+ The private key is encrypted unless `--nopass` is used.
35
+ When a certificate is revoked, its `.crt` and `.key` files are automatically removed.
36
+ Generating a certificate with existing name will fail, no harm will be done.
37
+
19
38
  ### Usage
20
39
 
21
40
  1. `ovpn-key --init` to initialize current directory
22
41
  or `ovpn-key --init some/dir` to create the working directory
23
42
  2. edit the `ovpn-key.yml` (see [docs](#ca-variants-supported))
24
- 3. `ovpn-key --ca`
25
- 4. `ovpn-key --server --nopass`
26
- 5. `ovpn-key --client somebody --nopass`
27
- 6. `ovpn-key --revoke somebody`
43
+ 3. create the CA (once)
44
+ `ovpn-key --ca`
45
+ 4. generate and sign a server certificate (once per server)
46
+ `ovpn-key --server --nopass`
47
+ 5. generate and sign client certificates whenever needed
48
+ `ovpn-key --client alice`
49
+ `ovpn-key --client bob`
50
+ 6. revoke a client certificate
51
+ `ovpn-key --revoke alice`
52
+
53
+ ### Switching from Easy-RSA
54
+
55
+ To import an existing CA instead of creating a new one, place the following files in the working directory:
56
+
57
+ * `ca.crt`: CA certificate
58
+ * `ca.key`: CA private key
59
+ * `crl.pem`: if the existing CA has revoked certificates, preserve its CRL.
60
+ Starting with a new CRL would lose the existing revocation information.
61
+
62
+ Skip the `--ca` step.
63
+
64
+ #### Certificate serial numbers
65
+
66
+ If the existing CA uses sequential integer serial numbers, initialize the `serial` file with the serial number of the latest issued certificate. For example, if the latest certificate has serial number `2`, run `echo -n 2 > serial`
67
+
68
+ If the existing CA uses random or non-sequential serial numbers (or serial numbers that cannot be represented as integers),
69
+ you can omit this step. `ovpn-key` will initialize the counter and start issuing certificates from `1`.
70
+
71
+ #### Revoking pre-existing certificates
72
+
73
+ Existing certificates remain valid and can continue to be used.
74
+
75
+ To revoke an existing certificate using `ovpn-key --revoke`, its `.crt` file must also be present in the working directory.
76
+ For example, to revoke `alice`, place `alice.crt` there.
28
77
 
29
78
  ### --server
30
79
 
31
- You can have multiple servers. You can omit the name and it will be just `server.crt`.
80
+ You can have multiple servers with `--server name`.
81
+ You can omit the name (`--server`) and it will be just `server.crt`.
32
82
 
33
83
  ### --nopass
34
84
 
@@ -36,15 +86,26 @@ Don't encrypt `.key` files with a passphrase. It can be used with `--ca`, `--ser
36
86
 
37
87
  You'll want to have your CA key encrypted. If `ovpn-key` is run just from the trunk of the OpenVPN server, you'll likely want server's key unencrypted. Client keys are advised to be encrypted if used interactively. Use a different passphrase for different keys.
38
88
 
39
- ### ZIP files
89
+ ### --revoke
90
+
91
+ This revokes the certificate, updates `crl.pem` and removes the corresponding `.crt` and `.key` files.
92
+
93
+ Make sure the updated `crl.pem` is available to the OpenVPN server and that its configuration includes
94
+ `crl-verify crl.pem`
95
+
96
+ OpenVPN uses the CRL to reject revoked certificates during authentication.
97
+ Revoking a certificate does not necessarily terminate an already established VPN connection.
98
+
99
+ ### --zip
40
100
 
41
101
  Add client OpenVPN configuration with `.ovpn` extension to the directory.
42
102
  There should be only one. It should contain every setting except for `cert` and `key`.
43
103
 
44
- Then you can use `ovpn-key --zip somebody` to generate a ZIP file
104
+ Then you can use `ovpn-key --zip charlie` to generate a client certificate and pack it to ZIP file
45
105
  that the end user can easily import in his VPN client without any modifications.
106
+ It does not package an existing certificate.
46
107
 
47
- The file will be named `somebody.tblk.zip` (if you specified `somebody` as name)
108
+ The file will be named `charlie.tblk.zip` (if you specified `charlie` as name)
48
109
  and would be written in `zip_dir` (home directory by default).
49
110
  It will contain:
50
111
 
@@ -56,9 +117,9 @@ It will contain:
56
117
  ### Additional helpers
57
118
 
58
119
  * `ovpn-key --static` generates a static unencrypted key: `ta.key`, intended to be used
59
- as `tls-crypt-v2`/`tls-crypt`/`tls-auth` pre-shared secret.
120
+ as `tls-crypt`/`tls-auth` pre-shared secret.
60
121
  * `ovpn-key --dh` generates a `dh.pem` file.
61
- Its' usage is discouraged to use in modern OpenVPN configurations in favor of ECDH.
122
+ Its usage is discouraged in modern OpenVPN configurations in favor of ECDH.
62
123
 
63
124
  ### Configuration
64
125
 
@@ -114,6 +175,12 @@ key_size: 4096
114
175
  digest: SHA384
115
176
  ```
116
177
 
178
+ #### ML-DSA-87, post-quantum safe
179
+ ```yaml
180
+ key_type: ML-DSA-87
181
+ #digest: not used
182
+ ```
183
+
117
184
  ### Configurations to avoid
118
185
 
119
186
  1. You might have an old configuration that still uses the `2K RSA`, this will work, but we recommend to phase out those deployments,
@@ -121,14 +188,4 @@ as they're currently under NIST baseline.
121
188
 
122
189
  2. `ed25519` and `secp256r1` can be used as a `key_type`, but also not recommended (don't satisfy CNSA 1.0 baseline).
123
190
 
124
- 3. `SHA256` and `AES128` are under CNSA 1.0 baseline, so also not adviced.
125
-
126
- ### Mixed mode
127
-
128
- You can start your CA as RSA and generate newer keys in ECC.
129
-
130
- Uncomment the `key_type` before you need the ECC key and that's it.
131
-
132
- ### Usage with a non-self-signed CA
133
-
134
- Place your `ca.key` and `ca.crt` in the keys directory and skip the `--ca` step.
191
+ 3. `SHA256` and `AES128` are under CNSA 1.0 baseline, so also not advised.
data/bin/ovpn-key CHANGED
@@ -122,7 +122,7 @@ CN_CA = settings['ca_name'] || 'Certification Authority'
122
122
  ENCRYPT = settings['encrypt'] || 'AES256'
123
123
  KEY_SIZE = settings['key_size'] || 3072
124
124
  KEY_TYPE = settings['key_type'] # if that's not set, we assume a legacy install with RSA
125
- DIGEST = unless KEY_TYPE&.casecmp? 'ed25519'
125
+ DIGEST = unless internal_digest?
126
126
  settings['digest'] || 'SHA384'
127
127
  end
128
128
 
data/lib/functions.rb CHANGED
@@ -43,7 +43,7 @@ def gen_and_sign(type, certname, password)
43
43
  end
44
44
 
45
45
  def gen_key(certname, password)
46
- key = if KEY_TYPE&.casecmp? 'ed25519'
46
+ key = if internal_digest?
47
47
  OpenSSL::PKey.generate_key(KEY_TYPE)
48
48
  elsif KEY_TYPE
49
49
  OpenSSL::PKey::EC.generate(KEY_TYPE)
@@ -118,10 +118,14 @@ def customize_cert(type, cert)
118
118
  cert
119
119
  end
120
120
 
121
- # rubocop:disable-next Metrics/AbcSize
121
+ # rubocop:disable-next Metrics/AbcSize,Metrics/MethodLength
122
122
  def revoke(certname)
123
123
  crl = OpenSSL::X509::CRL.new(File.read(CRL_FILE))
124
- cert = OpenSSL::X509::Certificate.new(File.read("#{certname}.crt"))
124
+ begin
125
+ cert = OpenSSL::X509::Certificate.new(File.read("#{certname}.crt"))
126
+ rescue Errno::ENOENT
127
+ abort "#{certname}.crt doesn't exist"
128
+ end
125
129
  revoke = OpenSSL::X509::Revoked.new.tap {|rev|
126
130
  rev.serial = cert.serial
127
131
  rev.time = Time.now
@@ -129,7 +133,13 @@ def revoke(certname)
129
133
  crl.next_update = time_after_days(EXPIRE['crl'])
130
134
  crl.add_revoked(revoke)
131
135
  update_crl(crl, '')
132
- %w[crt key].each {|ext| File.delete "#{certname}.#{ext}" }
136
+ %w[crt key].each {|ext|
137
+ begin
138
+ File.delete "#{certname}.#{ext}"
139
+ rescue Errno::ENOENT
140
+ next
141
+ end
142
+ }
133
143
  end
134
144
 
135
145
  def gen_crl(ca_pass)
@@ -166,3 +176,7 @@ def create_dir(name)
166
176
  FileUtils.mkdir_p name
167
177
  warn "Created directory: #{name}"
168
178
  end
179
+
180
+ def internal_digest?
181
+ KEY_TYPE&.casecmp?('ed25519') || KEY_TYPE&.casecmp?('ml-dsa-87')
182
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- VERSION = '1.1.2'
3
+ VERSION = '1.1.4'
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.2
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Korytov