ovpn-key 0.7 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ovpn-key +11 -22
  3. data/lib/functions.rb +12 -2
  4. data/lib/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75b4b86d88cbfbac55deafa5ab94d8f306efa10c001e2107bfdb04ac29515969
4
- data.tar.gz: bab07249832317c9281f055772f0f33ffeb8474be7200bf477b78e3481dea06b
3
+ metadata.gz: da769c59267c3c1bc605a2da314d55b0599e56de6e48dc25ef17ea56ed1af960
4
+ data.tar.gz: eb106210d91f8e5ba367d20d94e72e74f27e1a53a8abd3cf58cf61fc7580f0fb
5
5
  SHA512:
6
- metadata.gz: b28955c734a4f52a445fd278a9de148c64ffc2ed67584364d9466d62ce110981779a8a43d90d3de4d573dd03f2d85a23972d289bcdd2093d2dfb89ac342b1eb9
7
- data.tar.gz: a15d392159908b1d8f2a7a9a95e395ea3ebe875a3ca1df255ec0e622d42aa5e6cf6bef73bdd52ce2cfeac3b566ec1eded257e212a1ee1071d095d012515acb81
6
+ metadata.gz: 44b34a49e1730f3c9bff11022fa63e8cf1426c85a6f737c84b68cafa50be8c4e05110202d40dc1e1bfbfda36d29df02003b6ebd07c489fa21a76dcd8afea8d94
7
+ data.tar.gz: c4370cde04518bc151c64f2fb329718d68eed360080987807ed201103d55f999a84b0fcfd4d96634bc1124e96f419956b2c497046ab9bf957e55590e2882724c
data/bin/ovpn-key CHANGED
@@ -13,35 +13,26 @@ options = {}
13
13
  OptionParser.new do |opts|
14
14
  opts.banner = "Usage: #{File.basename $0} <options> [--nopass]"
15
15
  opts.on("--init [directory]", "Init a CA directory (defaults to current)") do |v|
16
- if v
17
- options[:init] = v
18
- else
19
- options[:init] = "."
20
- end
16
+ options[:init] = v ? v : "."
21
17
  end
22
18
  opts.on("--ca", "Generate a CA (ca.crt)") do |v|
23
19
  check_crt('ca')
24
20
  options[:generate_ca] = v
25
21
  end
26
22
  opts.on("--dh", "Generate a DH keyfile (dh.pem)") do |v|
23
+ # it's safe to rewrite this file
27
24
  options[:generate_dh] = v
28
25
  end
29
26
  opts.on("--server [name]", "Generate a server key (defaults to 'server')") do |v|
30
- if v
31
- options[:generate_server] = v
32
- else
33
- options[:generate_server] = "server"
34
- end
27
+ options[:generate_server] = v ? v : "server"
35
28
  check_crt(options[:generate_server])
36
29
  end
37
30
  opts.on("--client [name]", "Generate a client key and sign it") do |v|
38
- abort "Error: client should have an alphanumeric name" unless v
39
- check_crt(v)
31
+ check_client(v)
40
32
  options[:generate_client] = v
41
33
  end
42
34
  opts.on("--zip [name]", "Ditto plus pack it to ZIP with OpenVPN config") do |v|
43
- abort "Error: client should have an alphanumeric name" unless v
44
- check_crt(v)
35
+ check_client(v)
45
36
  options[:generate_zip] = v
46
37
  end
47
38
  opts.on("--revoke [name]", "Revoke a certificate (using crl.pem) and delete it") do |v|
@@ -81,6 +72,7 @@ elsif !File.exist? 'ovpn-key.yml'
81
72
  begin
82
73
  rc = YAML.load_file(File.expand_path '~/.ovpn-key.yml')
83
74
  rescue Errno::ENOENT
75
+ # no configuration file in home directory is not an error
84
76
  end
85
77
  Dir.chdir File.expand_path(rc['cd']) if rc && rc['cd']
86
78
  end
@@ -98,20 +90,18 @@ CN_CA = settings['ca_name'] || 'Certification Authority'
98
90
  REQ = settings['details']
99
91
 
100
92
  if options[:generate_ca]
101
- genrsa('ca', 'ca', options[:no_password])
102
- req('ca', 'ca', CN_CA)
93
+ gen_key('ca', 'ca', options[:no_password])
94
+ sign_key('ca', 'ca', CN_CA)
103
95
  gen_crl
104
96
  end
105
97
  if options[:generate_dh]
106
98
  exe "#{OPENSSL} dhparam -out dh.pem #{KEY_SIZE}"
107
99
  end
108
100
  if options[:generate_server]
109
- genrsa('server', options[:generate_server], options[:no_password])
110
- req('server', options[:generate_server], options[:generate_server])
101
+ gen_and_sign('server', options[:generate_server], options[:no_password])
111
102
  end
112
103
  if options[:generate_client]
113
- genrsa('client', options[:generate_client], options[:no_password])
114
- req('client', options[:generate_client], options[:generate_client])
104
+ gen_and_sign('client', options[:generate_client], options[:no_password])
115
105
  end
116
106
  if options[:generate_zip]
117
107
  ovpn_files = Dir['*.ovpn']
@@ -124,8 +114,7 @@ if options[:generate_zip]
124
114
  abort "More than one .ovpn files in current directory, aborting"
125
115
  end
126
116
 
127
- genrsa('client', options[:generate_zip], options[:no_password])
128
- req('client', options[:generate_zip], options[:generate_zip])
117
+ gen_and_sign('client', options[:generate_zip], options[:no_password])
129
118
 
130
119
  zip_file = File.join(File.expand_path(ZIP_DIR), "#{File.basename ovpn_file, '.ovpn'}.tblk.zip")
131
120
  File.delete(zip_file) if File.exist?(zip_file)
data/lib/functions.rb CHANGED
@@ -4,11 +4,21 @@ def check_crt filename
4
4
  }
5
5
  end
6
6
 
7
+ def check_client name
8
+ abort "Error: client should have an alphanumeric name" unless name
9
+ check_crt(name)
10
+ end
11
+
7
12
  def exe cmd
8
13
  system(cmd) or abort "error executing: #{cmd}"
9
14
  end
10
15
 
11
- def genrsa type, certname, no_password
16
+ def gen_and_sign type, certname, no_password
17
+ gen_key(type, certname, no_password)
18
+ sign_key(type, certname, certname)
19
+ end
20
+
21
+ def gen_key type, certname, no_password
12
22
  if no_password
13
23
  exe "#{OPENSSL} genrsa -out '#{certname}.key' #{KEY_SIZE} -config #{SSL_CONF} -extensions ext.#{type}"
14
24
  else
@@ -16,7 +26,7 @@ def genrsa type, certname, no_password
16
26
  end
17
27
  end
18
28
 
19
- def req type, certname, cn
29
+ def sign_key type, certname, cn
20
30
  if certname == 'ca'
21
31
  exe "#{OPENSSL} req -new -x509 -key '#{certname}.key' -out '#{certname}.crt' -config #{SSL_CONF} -subj '/CN=#{cn}#{REQ}' -extensions ext.#{type}"
22
32
  else
data/lib/version.rb CHANGED
@@ -1 +1 @@
1
- ::Version = '0.7'
1
+ ::Version = '0.7.1'
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.7'
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Korytov