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 +4 -4
- data/README.md +54 -23
- data/bin/ovpn-key +45 -40
- data/lib/functions.rb +19 -5
- data/lib/version.rb +1 -1
- data/pre-existing-keys.md +25 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8072a8287dcb1a2386df0d8f9a420aa7aeef64662ab9341afd23bc818f4c543b
|
|
4
|
+
data.tar.gz: 9be53d42013002c533eb87d1128167857897dbe12f12495ef91d17d7cbf7c8cc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
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
|
-
###
|
|
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
|
|
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 `
|
|
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
|
|
100
|
+
as `tls-crypt`/`tls-auth` pre-shared secret.
|
|
60
101
|
* `ovpn-key --dh` generates a `dh.pem` file.
|
|
61
|
-
Its
|
|
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`](
|
|
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
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 '
|
|
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,
|
|
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 '
|
|
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
|
-
|
|
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|
|
|
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
|
@@ -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.
|
|
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
|