ovpn-key 1.0.0 → 1.1.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 +4 -4
- data/README.md +57 -28
- data/bin/ovpn-key +41 -14
- data/defaults/ovpn-key.yml +6 -3
- data/lib/functions.rb +4 -9
- 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: 8dc2ed89356336d073903adcf02042627a96a9e17121a8bc92a9895dc49619dc
|
|
4
|
+
data.tar.gz: f43642cede6402d002d253e15907ec77399857701c2e58fa92d89247a94cee25
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff92f8688ede4fd4fa0825e9775e73b7dfae4007585a2884d7e991b1237e3b24b89e979f76278476758cdf3464cca750b2236f93853c3129683608bc1099ab8f
|
|
7
|
+
data.tar.gz: 94aabcd73b590ff2ed9a20d9ecf7b39899d25339353b81c868e9390dd17ca1a44ac1f5b6de9cc92e8dcbb55b8e4a7299288b20268504e4b9f2ced9a26364c881
|
data/README.md
CHANGED
|
@@ -1,45 +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.
|
|
12
|
+
It also can be used to manage a non-OpenVPN or non-self signed CA.
|
|
19
13
|
|
|
20
14
|
### Installation
|
|
21
15
|
|
|
22
|
-
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)
|
|
23
17
|
2. Run `gem install ovpn-key`
|
|
24
18
|
|
|
25
19
|
### Usage
|
|
26
20
|
|
|
27
|
-
1. `ovpn-key --init`
|
|
28
|
-
|
|
29
|
-
|
|
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`
|
|
30
25
|
4. `ovpn-key --server --nopass`
|
|
31
|
-
5. `ovpn-key --client somebody
|
|
26
|
+
5. `ovpn-key --client somebody --nopass`
|
|
32
27
|
6. `ovpn-key --revoke somebody`
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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.
|
|
37
62
|
|
|
38
63
|
### Configuration
|
|
39
64
|
|
|
40
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).
|
|
41
66
|
|
|
42
|
-
ovpn-key also processes `~/.ovpn-key.yml` file,
|
|
67
|
+
ovpn-key also processes `~/.ovpn-key.yml` file, it has only one possible setting:
|
|
43
68
|
```yaml
|
|
44
69
|
cd: ~/some/path
|
|
45
70
|
```
|
|
@@ -48,14 +73,14 @@ This setting is used as a default directory if:
|
|
|
48
73
|
1. current directory does not have `ovpn-key.yml`
|
|
49
74
|
2. `--init` is not specified
|
|
50
75
|
|
|
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
|
|
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.
|
|
52
77
|
|
|
53
78
|
### CA variants supported
|
|
54
79
|
|
|
55
80
|
We still support the old RSA mode, but it's not recommended to use in new configurations,
|
|
56
81
|
NIST curves are recommended if you're starting afresh at the moment, unless you have a very legacy deployment.
|
|
57
82
|
|
|
58
|
-
1. OpenVPN 2.4+
|
|
83
|
+
1. OpenVPN 2.4+ supports NIST curves
|
|
59
84
|
2. RHEL 8+ supports NIST curves
|
|
60
85
|
3. Ubuntu 20+ supports NIST curves
|
|
61
86
|
|
|
@@ -84,21 +109,21 @@ digest: SHA256
|
|
|
84
109
|
#### ed25519, least compatible
|
|
85
110
|
```yaml
|
|
86
111
|
key_type: ed25519
|
|
87
|
-
#digest:
|
|
112
|
+
#digest: not used
|
|
88
113
|
```
|
|
89
114
|
|
|
90
115
|
#### RSA 3K, a compromise if you still require RSA
|
|
91
116
|
```yaml
|
|
92
117
|
#key_type: # commented out
|
|
93
|
-
digest: SHA256
|
|
94
118
|
key_size: 3072
|
|
119
|
+
digest: SHA256
|
|
95
120
|
```
|
|
96
121
|
|
|
97
122
|
#### RSA 4K, the slowest
|
|
98
123
|
```yaml
|
|
99
124
|
#key_type: # commented out
|
|
100
|
-
digest: SHA384
|
|
101
125
|
key_size: 4096
|
|
126
|
+
digest: SHA384
|
|
102
127
|
```
|
|
103
128
|
|
|
104
129
|
Note: your configuration might still use the 2K RSA, this will work, but we recommend to phase out those deployments,
|
|
@@ -109,3 +134,7 @@ as they're currently under NIST baseline.
|
|
|
109
134
|
You can start your CA as RSA and generate newer keys in ECC.
|
|
110
135
|
|
|
111
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
|
@@ -15,9 +15,8 @@ CRL_FILE = 'crl.pem'
|
|
|
15
15
|
SERIAL_FILE = 'serial'
|
|
16
16
|
|
|
17
17
|
options = {}
|
|
18
|
-
# rubocop:disable Metrics/BlockLength
|
|
18
|
+
# rubocop:disable-next Metrics/BlockLength
|
|
19
19
|
OptionParser.new do |opts|
|
|
20
|
-
# rubocop:enable Metrics/BlockLength
|
|
21
20
|
opts.banner = "Usage: #{File.basename $PROGRAM_NAME} <options> [--nopass]"
|
|
22
21
|
opts.on('--init [directory]', 'Init a CA directory (defaults to current)') do |v|
|
|
23
22
|
options[:init] = v || '.'
|
|
@@ -73,7 +72,7 @@ if options[:init]
|
|
|
73
72
|
end
|
|
74
73
|
unless File.exist? APP_CONF
|
|
75
74
|
FileUtils.copy_file(File.expand_path("defaults/#{APP_CONF}", "#{__dir__}/.."), "./#{APP_CONF}")
|
|
76
|
-
|
|
75
|
+
warn "Created file: #{APP_CONF}"
|
|
77
76
|
end
|
|
78
77
|
elsif !File.exist? APP_CONF
|
|
79
78
|
begin
|
|
@@ -84,6 +83,34 @@ elsif !File.exist? APP_CONF
|
|
|
84
83
|
Dir.chdir File.expand_path(rc['cd']) if rc && rc['cd']
|
|
85
84
|
end
|
|
86
85
|
|
|
86
|
+
lock_file = File.join(Dir.tmpdir, "ovpn-key-#{Digest::SHA256.hexdigest(Dir.pwd)}.lock")
|
|
87
|
+
# rubocop:disable-next Style/FileOpen
|
|
88
|
+
lock = File.open(lock_file, File::RDWR | File::CREAT, 0o644)
|
|
89
|
+
|
|
90
|
+
# Exit if lock not acquired in 1 minute.
|
|
91
|
+
# The longest process is `--dh` generation, it takes 46s on my laptop.
|
|
92
|
+
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 60
|
|
93
|
+
waiting = false
|
|
94
|
+
|
|
95
|
+
until lock.flock(File::LOCK_EX | File::LOCK_NB)
|
|
96
|
+
unless waiting
|
|
97
|
+
warn "Waiting for lock: #{lock_file}"
|
|
98
|
+
waiting = true
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
|
|
102
|
+
raise "Timeout waiting for lock: #{lock_file}"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
sleep 0.5
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
at_exit {lock&.close}
|
|
109
|
+
|
|
110
|
+
%w[HUP TERM].each do |signal|
|
|
111
|
+
Signal.trap(signal) { exit }
|
|
112
|
+
end
|
|
113
|
+
|
|
87
114
|
begin
|
|
88
115
|
settings = YAML.load_file(APP_CONF)
|
|
89
116
|
rescue Errno::ENOENT
|
|
@@ -101,14 +128,14 @@ DIGEST = unless KEY_TYPE&.casecmp? 'ed25519'
|
|
|
101
128
|
|
|
102
129
|
unless settings['ca_days'].nil?
|
|
103
130
|
if settings['expire'].nil?
|
|
104
|
-
|
|
105
|
-
|
|
131
|
+
warn 'Migrating pre-0.8 configuration to new format: ca_days'
|
|
132
|
+
warn "WARNING: if you tweaked `default_days` or `default_days_crl` in #{SSL_CONF}, edit #{APP_CONF}"
|
|
106
133
|
File.open(APP_CONF, 'a') do |f|
|
|
107
134
|
f.write "# ca_days is not used anymore, you can remove it\nexpire:\n"
|
|
108
135
|
f.write " ca: #{settings['ca_days']}\n crl: 3650\n server: 3650\n client: 3650\n"
|
|
109
136
|
end
|
|
110
137
|
else
|
|
111
|
-
|
|
138
|
+
warn "WARNING: `ca_days` setting is deprecated, remove it from #{APP_CONF}"
|
|
112
139
|
end
|
|
113
140
|
end
|
|
114
141
|
|
|
@@ -120,7 +147,7 @@ settings['expire']['client'] ||= 3650
|
|
|
120
147
|
EXPIRE = settings['expire']
|
|
121
148
|
|
|
122
149
|
if settings['x509'].nil? && !settings['details'].nil?
|
|
123
|
-
|
|
150
|
+
warn 'Migrating pre-0.8 configuration to new format: details'
|
|
124
151
|
REQ = OpenSSL::X509::Name.parse(settings['details']).to_a
|
|
125
152
|
File.open(APP_CONF, 'a') do |f|
|
|
126
153
|
f.write "# details is not used anymore, you can remove it\nx509:\n"
|
|
@@ -128,21 +155,21 @@ if settings['x509'].nil? && !settings['details'].nil?
|
|
|
128
155
|
end
|
|
129
156
|
else
|
|
130
157
|
REQ = settings['x509']
|
|
131
|
-
|
|
158
|
+
warn "WARNING: `details` section is deprecated, remove it from #{APP_CONF}" unless settings['details'].nil?
|
|
132
159
|
end
|
|
133
160
|
if settings['openssl']
|
|
134
|
-
|
|
161
|
+
warn "WARNING: `openssl` setting is deprecated, remove it from #{APP_CONF}"
|
|
135
162
|
end
|
|
136
163
|
|
|
137
164
|
if !File.exist?(SERIAL_FILE) && File.exist?('meta/serial')
|
|
138
165
|
FileUtils.copy_file('meta/serial', SERIAL_FILE)
|
|
139
|
-
|
|
166
|
+
warn 'Copied meta/serial to serial'
|
|
140
167
|
end
|
|
141
168
|
%w[certs meta].each {|dir|
|
|
142
|
-
|
|
169
|
+
warn "WARNING: #{dir} directory is not used anymore. you can remove it" if File.exist? dir
|
|
143
170
|
}
|
|
144
171
|
if File.exist? 'openssl.ini'
|
|
145
|
-
|
|
172
|
+
warn 'WARNING: openssl.ini file is not used anymore. you can remove it'
|
|
146
173
|
end
|
|
147
174
|
|
|
148
175
|
if options[:generate_ca]
|
|
@@ -153,9 +180,9 @@ if options[:generate_ca]
|
|
|
153
180
|
end
|
|
154
181
|
if options[:generate_dh]
|
|
155
182
|
File.open('dh.pem', 'w') do |f|
|
|
156
|
-
|
|
183
|
+
warn 'Generating dh.pem. This will take a while'
|
|
157
184
|
f.write OpenSSL::PKey::DH.new(KEY_SIZE)
|
|
158
|
-
|
|
185
|
+
warn '. Done'
|
|
159
186
|
end
|
|
160
187
|
end
|
|
161
188
|
if options[:generate_static]
|
data/defaults/ovpn-key.yml
CHANGED
|
@@ -1,14 +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
|
-
key_type: secp384r1 # comment this out if you want to use RSA keys
|
|
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
|
|
6
7
|
key_size: 3072 # RSA and DH keys only
|
|
8
|
+
|
|
7
9
|
expire: # days
|
|
8
10
|
ca: 3650
|
|
9
11
|
crl: 3650
|
|
10
12
|
server: 3650
|
|
11
13
|
client: 3650
|
|
14
|
+
|
|
12
15
|
ca_name: Certification Authority
|
|
13
16
|
x509:
|
|
14
17
|
C: US
|
data/lib/functions.rb
CHANGED
|
@@ -92,12 +92,8 @@ def time_after_days(days)
|
|
|
92
92
|
Time.now + (days * 86_400) # days to seconds
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
# rubocop:disable Metrics/MethodLength
|
|
96
|
-
# rubocop:disable Metrics/AbcSize
|
|
95
|
+
# rubocop:disable-next Metrics/AbcSize, Metrics/MethodLength
|
|
97
96
|
def customize_cert(type, cert)
|
|
98
|
-
# rubocop:enable Metrics/AbcSize
|
|
99
|
-
# rubocop:enable Metrics/MethodLength
|
|
100
|
-
|
|
101
97
|
ef = OpenSSL::X509::ExtensionFactory.new nil, cert
|
|
102
98
|
ef.issuer_certificate = type == 'ca' ? cert : OpenSSL::X509::Certificate.new(File.read('ca.crt'))
|
|
103
99
|
|
|
@@ -118,9 +114,8 @@ def customize_cert(type, cert)
|
|
|
118
114
|
cert
|
|
119
115
|
end
|
|
120
116
|
|
|
121
|
-
# rubocop:disable Metrics/AbcSize
|
|
117
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
122
118
|
def revoke(certname)
|
|
123
|
-
# rubocop:enable Metrics/AbcSize
|
|
124
119
|
crl = OpenSSL::X509::CRL.new(File.read(CRL_FILE))
|
|
125
120
|
cert = OpenSSL::X509::Certificate.new(File.read("#{certname}.crt"))
|
|
126
121
|
revoke = OpenSSL::X509::Revoked.new.tap {|rev|
|
|
@@ -164,6 +159,6 @@ end
|
|
|
164
159
|
def create_dir(name)
|
|
165
160
|
return if Dir.exist? name
|
|
166
161
|
|
|
167
|
-
|
|
168
|
-
|
|
162
|
+
FileUtils.mkdir_p name
|
|
163
|
+
warn "Created directory: #{name}"
|
|
169
164
|
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: 1.
|
|
4
|
+
version: 1.1.0
|
|
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: []
|