ovpn-key 0.7.5 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -6
  3. data/bin/ovpn-key +31 -29
  4. data/lib/functions.rb +15 -13
  5. data/lib/version.rb +3 -1
  6. metadata +10 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b44e2fdcdb2fc4a47b18a47bfb5ea09f349555a2547614b595c944581178e970
4
- data.tar.gz: 97877899e12ab51f09a1e94c29995feb9e53156d42182349dc8cbe8e86143a86
3
+ metadata.gz: 13681f4cf8c6abc0badce3feceacf4ce489daab4ff9ea7b177bdca7c3fe983ed
4
+ data.tar.gz: 621ad232db5032b90b1b631f7765dc15aca7b8131465bb2658408c13a7c1d8b0
5
5
  SHA512:
6
- metadata.gz: 47a2f7e26dd576ec913750834d45e3305466ae186489e99acf4e252acb0dcf81c16d0e0510505cef36c9dbd10bd30ee3fc759a6d4c19557cbad24f2891c5dfd9
7
- data.tar.gz: 971a6d5befb69c5e6098969e42df5f2cd1c0e14173c2bab1ded94e40231c091243177dd8a65704cebcd5a7dfafde067c82758e39047517237222e8ba3e3f0a89
6
+ metadata.gz: cc2d031bd9f8a595fa1efd862c2e5e371643928d34c7d7398db179466b655e48d412dd5494cfc6d705e614114846acbcce717b1117026df685bac5a4eb6e65b7
7
+ data.tar.gz: d31fd3d8936ab9bbd94daed1db9f2334925e073dfb9319d6d96aabfa1db566bd2f340144dd0190ee27ee2652d64ef70d59e6c0a6a1c63af6392dfdba0191073e
data/README.md CHANGED
@@ -29,13 +29,14 @@ If you're brave, [let me know](https://github.com/chillum/ovpn-key/issues), wher
29
29
 
30
30
  1. `ovpn-key --init`
31
31
  2. edit `ovpn-key.yml` and `openssl.ini`
32
- 3. `ovpn-key --ca --dh --server --nopass`
33
- 4. `ovpn-key --client somebody [--nopass]`
34
- 5. `ovpn-key --revoke somebody`
35
- 6. `ovpn-key --static` (generates `ta.key`)
36
- 7. add a file with `.ovpn` extension to the directory
32
+ 3. `ovpn-key --ca --dh`
33
+ 4. `ovpn-key --server --nopass`
34
+ 5. `ovpn-key --client somebody [--nopass]`
35
+ 6. `ovpn-key --revoke somebody`
36
+ 7. `ovpn-key --static` (generates `ta.key`)
37
+ 8. add a file with `.ovpn` extension to the directory
37
38
  it should contain every setting except for `cert` and `key`
38
- 8. `ovpn-key --zip somebody-else [--nopass]`
39
+ 9. `ovpn-key --zip somebody-else [--nopass]`
39
40
 
40
41
  ### Configuration
41
42
 
data/bin/ovpn-key CHANGED
@@ -1,71 +1,73 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'optparse'
3
5
  require 'fileutils'
4
6
  require 'yaml'
5
7
  require 'zip'
6
- require_relative '../lib/version.rb'
7
- require_relative '../lib/functions.rb'
8
+ require_relative '../lib/version'
9
+ require_relative '../lib/functions'
8
10
 
9
11
  SSL_CONF = 'openssl.ini'
10
12
  APP_CONF = 'ovpn-key.yml'
11
13
 
12
14
  options = {}
13
15
  OptionParser.new do |opts|
14
- opts.banner = "Usage: #{File.basename $0} <options> [--nopass]"
15
- opts.on("--init [directory]", "Init a CA directory (defaults to current)") do |v|
16
- options[:init] = v ? v : "."
16
+ opts.banner = "Usage: #{File.basename $PROGRAM_NAME} <options> [--nopass]"
17
+ opts.on('--init [directory]', 'Init a CA directory (defaults to current)') do |v|
18
+ options[:init] = v || '.'
17
19
  end
18
- opts.on("--ca", "Generate a CA (ca.crt)") do |v|
20
+ opts.on('--ca', 'Generate a CA (ca.crt)') do |v|
19
21
  check_crt('ca')
20
22
  options[:generate_ca] = v
21
23
  end
22
- opts.on("--dh", "Generate a DH keyfile (dh.pem)") do |v|
24
+ opts.on('--dh', 'Generate a DH keyfile (dh.pem)') do |v|
23
25
  # it's safe to overwrite this file
24
26
  options[:generate_dh] = v
25
27
  end
26
- opts.on("--static", "Generate OpenVPN static key (ta.key)") do |v|
28
+ opts.on('--static', 'Generate OpenVPN static key (ta.key)') do |v|
27
29
  options[:generate_static] = v
28
- check_crt("ta")
30
+ check_crt('ta')
29
31
  end
30
- opts.on("--server [name]", "Generate a server key (defaults to 'server')") do |v|
31
- options[:generate_server] = v ? v : "server"
32
+ opts.on('--server [name]', "Generate a server key (defaults to 'server')") do |v|
33
+ options[:generate_server] = v || 'server'
32
34
  check_crt(options[:generate_server])
33
35
  end
34
- opts.on("--client [name]", "Generate a client key and sign it") do |v|
36
+ opts.on('--client [name]', 'Generate a client key and sign it') do |v|
35
37
  check_client(v)
36
38
  options[:generate_client] = v
37
39
  end
38
- opts.on("--zip [name]", "Ditto plus pack it to ZIP with OpenVPN config") do |v|
40
+ opts.on('--zip [name]', 'Ditto plus pack it to ZIP with OpenVPN config') do |v|
39
41
  check_client(v)
40
42
  options[:generate_zip] = v
41
43
  end
42
- opts.on("--revoke [name]", "Revoke a certificate (using crl.pem) and delete it") do |v|
43
- abort "Please specify what certificate to revoke" unless v
44
+ opts.on('--revoke [name]', 'Revoke a certificate (using crl.pem) and delete it') do |v|
45
+ abort 'Please specify what certificate to revoke' unless v
44
46
  options[:revoke] = v
45
47
  end
46
- opts.on("--nopass", "Don't protect .key files with a password") do |v|
48
+ opts.on('--nopass', "Don't protect .key files with a password") do |v|
47
49
  options[:no_password] = v
48
50
  end
49
51
  end.parse!
50
- if ARGV.length > 0
51
- abort "Error: invalid args: #{ARGV.join ' '}\nSee `#{File.basename $0} -h` for help"
52
+ if ARGV.length.positive?
53
+ abort "Error: invalid args: #{ARGV.join ' '}\nSee `#{File.basename $PROGRAM_NAME} -h` for help"
52
54
  end
53
55
  unless options[:init] || options[:generate_ca] || options[:generate_dh] || options[:generate_static] \
54
56
  || options[:generate_server] || options[:generate_client] || options[:generate_zip] || options[:revoke]
55
- abort "See `#{File.basename $0} -h` for usage"
57
+ abort "See `#{File.basename $PROGRAM_NAME} -h` for usage"
56
58
  end
57
- if options[:generate_client] and options[:generate_zip]
59
+ if options[:generate_client] && options[:generate_zip]
58
60
  # I assume that user likely wants one of them and is confused with usage
59
- abort "There can be only one: --client or --zip"
61
+ abort 'There can be only one: --client or --zip'
60
62
  end
61
- umask = File.umask 0077
63
+ umask = File.umask 0o077
62
64
 
63
65
  if options[:init]
64
66
  unless options[:init] == '.'
65
67
  create_dir options[:init]
66
68
  Dir.chdir options[:init]
67
69
  end
68
- ['certs', 'meta'].each {|dir| create_dir dir}
70
+ %w[certs meta].each {|dir| create_dir dir}
69
71
  ['meta/index.txt', 'meta/index.txt.attr', 'meta/serial', SSL_CONF, APP_CONF].each {|file|
70
72
  unless File.exist? file
71
73
  FileUtils.copy_file(File.expand_path("defaults/#{file}", "#{__dir__}/.."), "./#{file}")
@@ -74,7 +76,7 @@ if options[:init]
74
76
  }
75
77
  elsif !File.exist? APP_CONF
76
78
  begin
77
- rc = YAML.load_file(File.expand_path "~/.#{APP_CONF}")
79
+ rc = YAML.load_file(File.expand_path("~/.#{APP_CONF}"))
78
80
  rescue Errno::ENOENT
79
81
  # no configuration file in home directory is not an error
80
82
  end
@@ -84,7 +86,7 @@ end
84
86
  begin
85
87
  settings = YAML.load_file(APP_CONF)
86
88
  rescue Errno::ENOENT
87
- abort "Run `#{File.basename $0} --init` before generating certificates"
89
+ abort "Run `#{File.basename $PROGRAM_NAME} --init` before generating certificates"
88
90
  end
89
91
  ZIP_DIR = settings['zip_dir'] || '~'
90
92
  OPENVPN = settings['openvpn'] || 'openvpn'
@@ -118,9 +120,9 @@ if options[:generate_zip]
118
120
  when 1
119
121
  ovpn_file = ovpn_files.first
120
122
  when 0
121
- abort "No .ovpn file in current directory, please add one"
123
+ abort 'No .ovpn file in current directory, please add one'
122
124
  else
123
- abort "More than one .ovpn files in current directory, aborting"
125
+ abort 'More than one .ovpn files in current directory, aborting'
124
126
  end
125
127
 
126
128
  gen_and_sign('client', options[:generate_zip], options[:no_password])
@@ -133,7 +135,7 @@ if options[:generate_zip]
133
135
  File.open(ovpn_file).each {|line| f.write line}
134
136
  f.write "cert #{options[:generate_zip]}.crt\nkey #{options[:generate_zip]}.key\n"
135
137
  }
136
- [ 'ca.crt', "#{options[:generate_zip]}.crt", "#{options[:generate_zip]}.key"].each {|i|
138
+ ['ca.crt', "#{options[:generate_zip]}.crt", "#{options[:generate_zip]}.key"].each {|i|
137
139
  zip.add(i, i)
138
140
  }
139
141
  zip.add('ta.key', 'ta.key') if File.exist? 'ta.key'
@@ -142,5 +144,5 @@ end
142
144
  if options[:revoke]
143
145
  exe "#{OPENSSL} ca -revoke '#{options[:revoke]}.crt' -config #{SSL_CONF}"
144
146
  gen_crl
145
- ['crt', 'key'].each {|ext| File.delete "#{options[:revoke]}.#{ext}"}
147
+ %w[crt key].each {|ext| File.delete "#{options[:revoke]}.#{ext}"}
146
148
  end
data/lib/functions.rb CHANGED
@@ -1,24 +1,26 @@
1
- def check_crt filename
2
- ['key', 'crt'].each {|ext|
1
+ # frozen_string_literal: true
2
+
3
+ def check_crt(filename)
4
+ %w[key crt].each {|ext|
3
5
  abort "#{filename}.#{ext} already exists, exiting" if File.exist? "#{filename}.#{ext}"
4
6
  }
5
7
  end
6
8
 
7
- def check_client name
8
- abort "Error: client should have an alphanumeric name" unless name
9
+ def check_client(name)
10
+ abort 'Error: client should have an alphanumeric name' unless name
9
11
  check_crt(name)
10
12
  end
11
13
 
12
- def exe cmd
14
+ def exe(cmd)
13
15
  system(cmd) or abort "error executing: #{cmd}"
14
16
  end
15
17
 
16
- def gen_and_sign type, certname, no_password
18
+ def gen_and_sign(type, certname, no_password)
17
19
  gen_key(certname, no_password)
18
20
  sign_key(type, certname, certname)
19
21
  end
20
22
 
21
- def gen_key certname, no_password
23
+ def gen_key(certname, no_password)
22
24
  if no_password
23
25
  exe "#{OPENSSL} genrsa -out '#{certname}.key' #{KEY_SIZE}"
24
26
  else
@@ -26,7 +28,7 @@ def gen_key certname, no_password
26
28
  end
27
29
  end
28
30
 
29
- def sign_key type, certname, cn
31
+ def sign_key(type, certname, cn)
30
32
  if certname == 'ca'
31
33
  exe "#{OPENSSL} req -new -x509 -key '#{certname}.key' -out '#{certname}.crt' -config #{SSL_CONF} -subj '/CN=#{cn}#{REQ}' -extensions ext.#{type} -days #{CA_DAYS}"
32
34
  else
@@ -40,9 +42,9 @@ def gen_crl
40
42
  exe "#{OPENSSL} ca -gencrl -out crl.pem -config #{SSL_CONF}"
41
43
  end
42
44
 
43
- def create_dir name
44
- unless Dir.exist? name
45
- Dir.mkdir name
46
- puts "Created directory: #{name}"
47
- end
45
+ def create_dir(name)
46
+ return if Dir.exist? name
47
+
48
+ Dir.mkdir name
49
+ puts "Created directory: #{name}"
48
50
  end
data/lib/version.rb CHANGED
@@ -1 +1,3 @@
1
- ::Version = '0.7.5'
1
+ # frozen_string_literal: true
2
+
3
+ ::VERSION = '0.7.7'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ovpn-key
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Korytov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-26 00:00:00.000000000 Z
11
+ date: 2021-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -16,17 +16,17 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '2.0'
27
27
  description: Generates and revokes certificates, also packs them to ZIP files with
28
28
  OpenVPN configuration
29
- email: vasily.korytov@icloud.com
29
+ email: v.korytov@outlook.com
30
30
  executables:
31
31
  - ovpn-key
32
32
  extensions: []
@@ -46,7 +46,7 @@ homepage: https://github.com/chillum/ovpn-key
46
46
  licenses:
47
47
  - Apache-2.0
48
48
  metadata: {}
49
- post_install_message:
49
+ post_install_message:
50
50
  rdoc_options: []
51
51
  require_paths:
52
52
  - lib
@@ -54,16 +54,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: '2.0'
57
+ version: '2.4'
58
58
  required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubyforge_project:
65
- rubygems_version: 2.7.7
66
- signing_key:
64
+ rubygems_version: 3.2.3
65
+ signing_key:
67
66
  specification_version: 4
68
67
  summary: Key management utility for OpenVPN
69
68
  test_files: []