ovpn-key 0.9.1 → 1.0.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 +4 -4
- data/NOTICE +1 -1
- data/README.md +113 -27
- data/bin/ovpn-key +5 -2
- data/defaults/ovpn-key.yml +8 -4
- data/lib/functions.rb +26 -14
- data/lib/version.rb +1 -1
- metadata +12 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8fbc29965d3aded7a257e8dc7d16979becb819dada33f08f010cb201ffc603ad
|
|
4
|
+
data.tar.gz: 85d1c3be6c281e20244d8e348b789e5a60560cf71e4ab55fb5f9124dabe1ac0b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6a17007e2a8f83304697c830b95086da066790295067528a324249ab70cbba38d95ed7b06aded3e39e01f3e7069b66473129b400e667d1a370da031e0b91ddc5
|
|
7
|
+
data.tar.gz: 2d6c527c44f6ac366ef3579f2f6141417f965cc3ba80bd732956cd4c0a24dbd80209270002a7da761a552e01ec76e82f1517b79bfae5fa2918c3b77c0f8e9729
|
data/NOTICE
CHANGED
data/README.md
CHANGED
|
@@ -1,48 +1,70 @@
|
|
|
1
1
|
## ovpn-key: key management for OpenVPN [](http://badge.fury.io/rb/ovpn-key)
|
|
2
2
|
|
|
3
|
-
This utility is designed as [easy-rsa](https://github.com/OpenVPN/easy-rsa) replacement
|
|
3
|
+
This utility is designed as [easy-rsa](https://github.com/OpenVPN/easy-rsa) replacement.
|
|
4
|
+
Comes with ease of use and sane defaults.
|
|
4
5
|
|
|
5
|
-
It's
|
|
6
|
+
It's a wrapper around OpenSSL API to:
|
|
6
7
|
* create a self-signed CA
|
|
7
|
-
* create
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* create server certificates
|
|
9
|
+
* create client certificates and optionally pack them to ZIP files along with the OpenVPN config
|
|
10
|
+
* revoke the certificates when needed
|
|
10
11
|
|
|
11
|
-
It
|
|
12
|
-
|
|
13
|
-
It can be used with a non-self signed CA, just place your `ca.key` and `ca.crt` in the keys directory and skip the `--ca` step.
|
|
14
|
-
|
|
15
|
-
It can be used to manage a non-OpenVPN CA, in that case `--zip` and `--static` steps will be useless, but all others will work.
|
|
16
|
-
|
|
17
|
-
OpenVPN static keys are supported partially, as they should be used for `tls-auth`/`tls-crypt` only.
|
|
18
|
-
Please note that they are not encrypted regardless of `--nopass` option.
|
|
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.
|
|
12
|
+
It also can be used to manage a non-OpenVPN or non-self signed CA.
|
|
22
13
|
|
|
23
14
|
### Installation
|
|
24
15
|
|
|
25
|
-
1. Get [Ruby](https://www.ruby-lang.org/en/documentation/installation/)
|
|
16
|
+
1. Get [Ruby](https://www.ruby-lang.org/en/documentation/installation/) (3.0 or greater is supported)
|
|
26
17
|
2. Run `gem install ovpn-key`
|
|
27
18
|
|
|
28
19
|
### Usage
|
|
29
20
|
|
|
30
|
-
1. `ovpn-key --init`
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
1. `ovpn-key --init` to initialize current directory
|
|
22
|
+
or `ovpn-key --init some/dir` to create the working directory
|
|
23
|
+
2. edit the `ovpn-key.yml` (see [docs](#ca-variants-supported))
|
|
24
|
+
3. `ovpn-key --ca`
|
|
33
25
|
4. `ovpn-key --server --nopass`
|
|
34
|
-
5. `ovpn-key --client somebody
|
|
26
|
+
5. `ovpn-key --client somebody --nopass`
|
|
35
27
|
6. `ovpn-key --revoke somebody`
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
|
|
29
|
+
### --server
|
|
30
|
+
|
|
31
|
+
You can have multiple servers. You can omit the name and it will be just `server.crt`.
|
|
32
|
+
|
|
33
|
+
### --nopass
|
|
34
|
+
|
|
35
|
+
Don't encrypt `.key` files with a passphrase. It can be used with `--ca`, `--server`, `--client` or `--zip`.
|
|
36
|
+
|
|
37
|
+
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
|
+
|
|
39
|
+
### ZIP files
|
|
40
|
+
|
|
41
|
+
Add client OpenVPN configuration with `.ovpn` extension to the directory.
|
|
42
|
+
There should be only one. It should contain every setting except for `cert` and `key`.
|
|
43
|
+
|
|
44
|
+
Then you can use `ovpn-key --zip somebody` to generate a ZIP file
|
|
45
|
+
that the end user can easily import in his VPN client without any modifications.
|
|
46
|
+
|
|
47
|
+
The file will be named `somebody.tblk.zip` (if you specified `somebody` as name)
|
|
48
|
+
and would be written in `zip_dir` (home directory by default).
|
|
49
|
+
It will contain:
|
|
50
|
+
|
|
51
|
+
1. `ca.crt`
|
|
52
|
+
2. user's VPN configuration
|
|
53
|
+
3. user's certificate and key, latter being encrypted with a passphrase unless `--nopass` was used
|
|
54
|
+
4. `ta.key` if it exists
|
|
55
|
+
|
|
56
|
+
### Additional helpers
|
|
57
|
+
|
|
58
|
+
* `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.
|
|
60
|
+
* `ovpn-key --dh` generates a `dh.pem` file.
|
|
61
|
+
Its' usage is discouraged to use in modern OpenVPN configurations in favor of ECDH.
|
|
40
62
|
|
|
41
63
|
### Configuration
|
|
42
64
|
|
|
43
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).
|
|
44
66
|
|
|
45
|
-
ovpn-key also processes `~/.ovpn-key.yml` file,
|
|
67
|
+
ovpn-key also processes `~/.ovpn-key.yml` file, it has only one possible setting:
|
|
46
68
|
```yaml
|
|
47
69
|
cd: ~/some/path
|
|
48
70
|
```
|
|
@@ -51,4 +73,68 @@ This setting is used as a default directory if:
|
|
|
51
73
|
1. current directory does not have `ovpn-key.yml`
|
|
52
74
|
2. `--init` is not specified
|
|
53
75
|
|
|
54
|
-
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
|
|
76
|
+
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.
|
|
77
|
+
|
|
78
|
+
### CA variants supported
|
|
79
|
+
|
|
80
|
+
We still support the old RSA mode, but it's not recommended to use in new configurations,
|
|
81
|
+
NIST curves are recommended if you're starting afresh at the moment, unless you have a very legacy deployment.
|
|
82
|
+
|
|
83
|
+
1. OpenVPN 2.4+ supports NIST curves
|
|
84
|
+
2. RHEL 8+ supports NIST curves
|
|
85
|
+
3. Ubuntu 20+ supports NIST curves
|
|
86
|
+
|
|
87
|
+
Thus, we expect all current and even some EOL systems to support NIST curves that we use by default.
|
|
88
|
+
|
|
89
|
+
Example configurations:
|
|
90
|
+
|
|
91
|
+
#### NIST P-384, default since v1.0
|
|
92
|
+
```yaml
|
|
93
|
+
key_type: secp384r1
|
|
94
|
+
digest: SHA384
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### NIST P-521, probably an overkill
|
|
98
|
+
```yaml
|
|
99
|
+
key_type: secp521r1
|
|
100
|
+
digest: SHA512
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### NIST P-256, the fastest
|
|
104
|
+
```yaml
|
|
105
|
+
key_type: secp256r1
|
|
106
|
+
digest: SHA256
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### ed25519, least compatible
|
|
110
|
+
```yaml
|
|
111
|
+
key_type: ed25519
|
|
112
|
+
#digest: not used
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### RSA 3K, a compromise if you still require RSA
|
|
116
|
+
```yaml
|
|
117
|
+
#key_type: # commented out
|
|
118
|
+
key_size: 3072
|
|
119
|
+
digest: SHA256
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### RSA 4K, the slowest
|
|
123
|
+
```yaml
|
|
124
|
+
#key_type: # commented out
|
|
125
|
+
key_size: 4096
|
|
126
|
+
digest: SHA384
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Note: your configuration might still use the 2K RSA, this will work, but we recommend to phase out those deployments,
|
|
130
|
+
as they're currently under NIST baseline.
|
|
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.
|
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
|
+
CN_CA = settings['ca_name'] || 'Certification Authority'
|
|
94
95
|
ENCRYPT = settings['encrypt'] || 'AES256'
|
|
95
|
-
DIGEST = settings['digest'] || 'SHA256'
|
|
96
96
|
KEY_SIZE = settings['key_size'] || 3072
|
|
97
|
-
|
|
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?
|
data/defaults/ovpn-key.yml
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
openvpn: openvpn # openvpn executable, required only for --static
|
|
2
|
+
zip_dir: '~' # directory for files generated by --zip
|
|
3
|
+
|
|
3
4
|
encrypt: AES256
|
|
4
|
-
digest:
|
|
5
|
-
|
|
5
|
+
digest: SHA384 # change this to 256 if using sub-4k RSA keys or P-256
|
|
6
|
+
key_type: secp384r1 # comment this out if you want to use RSA keys
|
|
7
|
+
key_size: 3072 # RSA and DH keys only
|
|
8
|
+
|
|
6
9
|
expire: # days
|
|
7
10
|
ca: 3650
|
|
8
11
|
crl: 3650
|
|
9
12
|
server: 3650
|
|
10
13
|
client: 3650
|
|
14
|
+
|
|
11
15
|
ca_name: Certification Authority
|
|
12
16
|
x509:
|
|
13
17
|
C: US
|
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
|
|
32
|
-
rescue OpenSSL::PKey::
|
|
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
|
|
34
|
+
OpenSSL::PKey.read File.read('ca.key'), ask_password('ca')
|
|
35
35
|
end
|
|
36
|
-
rescue OpenSSL::PKey::
|
|
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 =
|
|
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.
|
|
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
|
|
60
|
+
key = OpenSSL::PKey.read File.read("#{certname}.key"), password
|
|
55
61
|
serial = new_serial
|
|
56
|
-
cert = gen_cert(type, cn, key
|
|
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,
|
|
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,
|
|
71
|
+
def gen_cert(type, cn, key, serial)
|
|
66
72
|
cert = basic_cert(type, cn)
|
|
67
|
-
cert.public_key =
|
|
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,
|
|
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
|
|
@@ -152,6 +164,6 @@ end
|
|
|
152
164
|
def create_dir(name)
|
|
153
165
|
return if Dir.exist? name
|
|
154
166
|
|
|
155
|
-
|
|
167
|
+
FileUtils.mkdir_p name
|
|
156
168
|
puts "Created directory: #{name}"
|
|
157
169
|
end
|
data/lib/version.rb
CHANGED
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.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vasily Korytov
|
|
@@ -23,8 +23,16 @@ dependencies:
|
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '3.0'
|
|
26
|
-
description:
|
|
27
|
-
|
|
26
|
+
description: |
|
|
27
|
+
ovpn-key is a modern, easy-to-use alternative to Easy-RSA for managing
|
|
28
|
+
OpenVPN PKI.
|
|
29
|
+
|
|
30
|
+
It provides sensible security defaults and streamlined workflows for
|
|
31
|
+
creating certificate authorities, issuing and revoking certificates,
|
|
32
|
+
and managing keys and certificates.
|
|
33
|
+
|
|
34
|
+
Unlike tools that shell out to the openssl command-line utility,
|
|
35
|
+
ovpn-key uses the OpenSSL API directly through Ruby bindings.
|
|
28
36
|
email: v.korytov@outlook.com
|
|
29
37
|
executables:
|
|
30
38
|
- ovpn-key
|
|
@@ -58,5 +66,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
58
66
|
requirements: []
|
|
59
67
|
rubygems_version: 4.0.23
|
|
60
68
|
specification_version: 4
|
|
61
|
-
summary:
|
|
69
|
+
summary: An easy-to-use PKI tool with secure defaults and automatic key encryption
|
|
62
70
|
test_files: []
|