ovpn-key 1.1.3 → 1.1.5

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: '029bea57b6acb1762d94c9c87d5c03983bf4da6b52cff67f5fbdcc965dfd27a0'
4
- data.tar.gz: b8464f78442918e7df3ab32510e51d75acb0aa18076a2bf58cc9cce2d8d7824c
3
+ metadata.gz: 8072a8287dcb1a2386df0d8f9a420aa7aeef64662ab9341afd23bc818f4c543b
4
+ data.tar.gz: 9be53d42013002c533eb87d1128167857897dbe12f12495ef91d17d7cbf7c8cc
5
5
  SHA512:
6
- metadata.gz: bd946dd12497109fbef9de13ea480c194d14c4fcc84066a9b5115d5eb9eac1f6f49cab18b4dccbb117305d13c21d5058c6b3dbfffde2c61a0fed5b158b208448
7
- data.tar.gz: 61d2dfb09af2f3f8a6d71b5144634e959367fe392227bd4053121e17c856740b3ceba1d3fa93eec718b943f5da4a314643aa905cf8c8f7d65e7d38c6d93ec866
6
+ metadata.gz: 8f49b1b5c2b6b6de6c9005d7b422a3d0e41aee06215cd499f633b334db7371e6082e92ecaa530fc58f96346fb781c9686a8464c610f448714e10dc8d882a2419
7
+ data.tar.gz: cdeec55d2f7ae554ef30a2904a884746fad11b0ee2929382d07e8954ba506dea51146aa38921d5b5a4d9593d5e2aa1e6daa991b4b273a95b0e30550ceb2f2f46
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,49 @@ 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](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
+ ### Existing certificates
54
+
55
+ We recommend to start afresh with new better keys.
56
+ However, you may want to import the pre-existing CA to `ovpn-key`, see [docs](pre-existing-keys.md).
28
57
 
29
58
  ### --server
30
59
 
31
- You can have multiple servers. You can omit the name and it will be just `server.crt`.
60
+ You can have multiple servers with `--server name`.
61
+ You can omit the name (`--server`) and it will be just `server.crt`.
32
62
 
33
63
  ### --nopass
34
64
 
@@ -36,15 +66,26 @@ Don't encrypt `.key` files with a passphrase. It can be used with `--ca`, `--ser
36
66
 
37
67
  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
68
 
39
- ### ZIP files
69
+ ### --revoke
70
+
71
+ This revokes the certificate, updates `crl.pem` and removes the corresponding `.crt` and `.key` files.
72
+
73
+ Make sure the updated `crl.pem` is available to the OpenVPN server and that its configuration includes
74
+ `crl-verify crl.pem`
75
+
76
+ OpenVPN uses the CRL to reject revoked certificates during authentication.
77
+ Revoking a certificate does not necessarily terminate an already established VPN connection.
78
+
79
+ ### --zip
40
80
 
41
81
  Add client OpenVPN configuration with `.ovpn` extension to the directory.
42
82
  There should be only one. It should contain every setting except for `cert` and `key`.
43
83
 
44
- Then you can use `ovpn-key --zip somebody` to generate a ZIP file
84
+ Then you can use `ovpn-key --zip charlie` to generate a client certificate and pack it to ZIP file
45
85
  that the end user can easily import in his VPN client without any modifications.
86
+ It does not package an existing certificate.
46
87
 
47
- The file will be named `somebody.tblk.zip` (if you specified `somebody` as name)
88
+ The file will be named `charlie.tblk.zip` (if you specified `charlie` as name)
48
89
  and would be written in `zip_dir` (home directory by default).
49
90
  It will contain:
50
91
 
@@ -56,13 +97,13 @@ It will contain:
56
97
  ### Additional helpers
57
98
 
58
99
  * `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.
100
+ as `tls-crypt`/`tls-auth` pre-shared secret.
60
101
  * `ovpn-key --dh` generates a `dh.pem` file.
61
- Its' usage is discouraged to use in modern OpenVPN configurations in favor of ECDH.
102
+ Its usage is discouraged in modern OpenVPN configurations in favor of ECDH.
62
103
 
63
104
  ### Configuration
64
105
 
65
- It's just a single simple YAML file named [`ovpn-key.yml`](https://github.com/chillum/ovpn-key/blob/master/defaults/ovpn-key.yml).
106
+ It's just a single simple YAML file named [`ovpn-key.yml`](defaults/ovpn-key.yml).
66
107
 
67
108
  ovpn-key also processes `~/.ovpn-key.yml` file, it has only one possible setting:
68
109
  ```yaml
@@ -127,14 +168,4 @@ as they're currently under NIST baseline.
127
168
 
128
169
  2. `ed25519` and `secp256r1` can be used as a `key_type`, but also not recommended (don't satisfy CNSA 1.0 baseline).
129
170
 
130
- 3. `SHA256` and `AES128` are under CNSA 1.0 baseline, so also not adviced.
131
-
132
- ### Mixed mode
133
-
134
- You can start your CA as RSA and generate newer keys in ECC.
135
-
136
- Uncomment the `key_type` before you need the ECC key and that's it.
137
-
138
- ### Usage with a non-self-signed CA
139
-
140
- Place your `ca.key` and `ca.crt` in the keys directory and skip the `--ca` step.
171
+ 3. `SHA256` and `AES128` are under CNSA 1.0 baseline, so also not advised.
data/bin/ovpn-key CHANGED
@@ -16,53 +16,58 @@ SERIAL_FILE = 'serial'
16
16
 
17
17
  options = {}
18
18
  # rubocop:disable-next Metrics/BlockLength
19
- OptionParser.new do |opts|
20
- opts.banner = "Usage: #{File.basename $PROGRAM_NAME} <options> [--nopass]"
21
- opts.on('--init [directory]', 'Init a CA directory (defaults to current)') do |v|
22
- options[:init] = v || '.'
23
- end
24
- opts.on('--ca', 'Generate a CA (ca.crt)') do |v|
25
- check_crt('ca')
26
- options[:generate_ca] = v
27
- end
28
- opts.on('--dh', 'Generate a DH keyfile (dh.pem)') do |v|
29
- # it's safe to overwrite this file
30
- options[:generate_dh] = v
31
- end
32
- opts.on('--static', 'Generate OpenVPN static key (ta.key)') do |v|
33
- options[:generate_static] = v
34
- check_crt('ta')
35
- end
36
- opts.on('--server [name]', "Generate a server key (defaults to 'server')") do |v|
37
- options[:generate_server] = v || 'server'
38
- check_crt(options[:generate_server])
39
- end
40
- opts.on('--client [name]', 'Generate a client key and sign it') do |v|
41
- check_client(v)
42
- options[:generate_client] = v
43
- end
44
- opts.on('--zip [name]', 'Ditto plus pack it to ZIP with OpenVPN config') do |v|
45
- check_client(v)
46
- options[:generate_zip] = v
47
- end
48
- opts.on('--revoke [name]', "Revoke a certificate (using #{CRL_FILE}) and delete it") do |v|
49
- abort 'Please specify what certificate to revoke' unless v
50
- options[:revoke] = v
51
- end
52
- opts.on('--nopass', "Don't protect .key files with a password") do |v|
53
- options[:no_password] = v
54
- end
55
- end.parse!
19
+ begin
20
+ OptionParser.new do |opts|
21
+ opts.banner = "Usage: #{File.basename $PROGRAM_NAME} <options> [--nopass]"
22
+ opts.on('--init [directory]', 'Init a CA directory (defaults to current)') do |v|
23
+ options[:init] = v || '.'
24
+ end
25
+ opts.on('--ca', 'Generate a CA (ca.crt)') do |v|
26
+ check_crt('ca')
27
+ options[:generate_ca] = v
28
+ end
29
+ opts.on('--dh', 'Generate a DH keyfile (dh.pem)') do |v|
30
+ # it's safe to overwrite this file
31
+ options[:generate_dh] = v
32
+ end
33
+ opts.on('--static', 'Generate OpenVPN static key (ta.key)') do |v|
34
+ options[:generate_static] = v
35
+ check_crt('ta')
36
+ end
37
+ opts.on('--server [name]', "Generate a server key (defaults to 'server')") do |v|
38
+ options[:generate_server] = v || 'server'
39
+ check_crt(options[:generate_server])
40
+ end
41
+ opts.on('--client [name]', 'Generate a client key and sign it') do |v|
42
+ check_client(v)
43
+ options[:generate_client] = v
44
+ end
45
+ opts.on('--zip [name]', 'Ditto plus pack it to ZIP with OpenVPN config') do |v|
46
+ check_client(v)
47
+ options[:generate_zip] = v
48
+ end
49
+ opts.on('--revoke [name]', "Revoke a certificate (using #{CRL_FILE}) and delete it") do |v|
50
+ abort 'Please specify what certificate to revoke' unless v
51
+ abort "ERROR: cannot revoke ca.crt, it's the root cert" if v == 'ca'
52
+ options[:revoke] = v
53
+ end
54
+ opts.on('--nopass', "Don't protect .key files with a password") do |v|
55
+ options[:no_password] = v
56
+ end
57
+ end.parse!
58
+ rescue OptionParser::ParseError => e
59
+ usage e.message
60
+ end
56
61
  if ARGV.length.positive?
57
- abort "Error: invalid args: #{ARGV.join ' '}\nSee `#{File.basename $PROGRAM_NAME} -h` for help"
62
+ usage "invalid args: #{ARGV.join ' '}"
58
63
  end
59
64
  unless options[:init] || options[:generate_ca] || options[:generate_dh] || options[:generate_static] \
60
65
  || options[:generate_server] || options[:generate_client] || options[:generate_zip] || options[:revoke]
61
- abort "See `#{File.basename $PROGRAM_NAME} -h` for usage"
66
+ usage 'no action provided'
62
67
  end
63
68
  if options[:generate_client] && options[:generate_zip]
64
69
  # I assume that user likely wants one of them and is confused with usage
65
- abort 'There can be only one: --client or --zip'
70
+ abort 'ERROR: there can be only one: --client or --zip'
66
71
  end
67
72
 
68
73
  if options[:init]
data/lib/functions.rb CHANGED
@@ -2,15 +2,19 @@
2
2
 
3
3
  def check_crt(filename)
4
4
  %w[key crt].each {|ext|
5
- abort "#{filename}.#{ext} already exists, exiting" if File.exist? "#{filename}.#{ext}"
5
+ abort "#{filename}.#{ext} already exists, aborting" if File.exist? "#{filename}.#{ext}"
6
6
  }
7
7
  end
8
8
 
9
9
  def check_client(name)
10
- abort 'Error: client should have an alphanumeric name' unless name
10
+ abort 'ERROR: client should have an alphanumeric name' unless name
11
11
  check_crt(name)
12
12
  end
13
13
 
14
+ def usage(error)
15
+ abort "ERROR: #{error}\nSee `#{File.basename $PROGRAM_NAME} -h` for usage"
16
+ end
17
+
14
18
  def exe(cmd)
15
19
  system(cmd) || abort("error executing: #{cmd}")
16
20
  end
@@ -118,10 +122,14 @@ def customize_cert(type, cert)
118
122
  cert
119
123
  end
120
124
 
121
- # rubocop:disable-next Metrics/AbcSize
125
+ # rubocop:disable-next Metrics/AbcSize,Metrics/MethodLength
122
126
  def revoke(certname)
123
127
  crl = OpenSSL::X509::CRL.new(File.read(CRL_FILE))
124
- cert = OpenSSL::X509::Certificate.new(File.read("#{certname}.crt"))
128
+ begin
129
+ cert = OpenSSL::X509::Certificate.new(File.read("#{certname}.crt"))
130
+ rescue Errno::ENOENT
131
+ abort "#{certname}.crt doesn't exist, aborting"
132
+ end
125
133
  revoke = OpenSSL::X509::Revoked.new.tap {|rev|
126
134
  rev.serial = cert.serial
127
135
  rev.time = Time.now
@@ -129,7 +137,13 @@ def revoke(certname)
129
137
  crl.next_update = time_after_days(EXPIRE['crl'])
130
138
  crl.add_revoked(revoke)
131
139
  update_crl(crl, '')
132
- %w[crt key].each {|ext| File.delete "#{certname}.#{ext}" }
140
+ %w[crt key].each {|ext|
141
+ begin
142
+ File.delete "#{certname}.#{ext}"
143
+ rescue Errno::ENOENT
144
+ next
145
+ end
146
+ }
133
147
  end
134
148
 
135
149
  def gen_crl(ca_pass)
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- VERSION = '1.1.3'
3
+ VERSION = '1.1.5'
@@ -0,0 +1,25 @@
1
+ # Importing a pre-existing CA
2
+
3
+ To import an existing CA instead of creating a new one,
4
+ place the following files in the working directory:
5
+
6
+ * `ca.crt`: CA certificate
7
+ * `ca.key`: CA private key
8
+ * `crl.pem`: if the existing CA has revoked certificates, preserve its CRL.
9
+ Starting with a new CRL would lose the existing revocation information.
10
+
11
+ Skip the `--ca` step.
12
+
13
+ ## Certificate serial numbers
14
+
15
+ 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`
16
+
17
+ If the existing CA uses random or non-sequential serial numbers (or serial numbers that cannot be represented as integers),
18
+ you can omit this step. `ovpn-key` will initialize the counter and start issuing certificates from `1`.
19
+
20
+ ## Revoking pre-existing certificates
21
+
22
+ Existing certificates remain valid and can continue to be used.
23
+
24
+ To revoke an existing certificate using `ovpn-key --revoke`, its `.crt` file must also be present in the working directory.
25
+ For example, to revoke `alice`, place `alice.crt` there.
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.3
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Korytov
@@ -45,6 +45,7 @@ files:
45
45
  - defaults/ovpn-key.yml
46
46
  - lib/functions.rb
47
47
  - lib/version.rb
48
+ - pre-existing-keys.md
48
49
  homepage: https://github.com/chillum/ovpn-key
49
50
  licenses:
50
51
  - Apache-2.0