Class: Net::Openvpn::Generators::Keys::Client

Inherits:
Base
  • Object
show all
Defined in:
lib/net/openvpn/generators/keys/client.rb

Instance Attribute Summary

Attributes inherited from Base

#props

Instance Method Summary collapse

Methods inherited from Base

#exist?, #revoke!, #valid?

Constructor Details

#initialize(name, **props) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/net/openvpn/generators/keys/client.rb', line 7

def initialize(name, **props)
  super(name, props)
end

Instance Method Details

#certificateObject



38
39
40
# File 'lib/net/openvpn/generators/keys/client.rb', line 38

def certificate
  "#{@props[:key_dir]}/#{@name}.crt"
end

#filepathsObject

Returns an array containing the paths to the generated keys



34
35
36
# File 'lib/net/openvpn/generators/keys/client.rb', line 34

def filepaths
  [ key, certificate ]
end

#generateObject

Generates the certificates for a VPN client

Raises ‘Net::Openvpn::Errors::KeyGeneration` if there were problems

Returns true if the generation was successful



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/net/openvpn/generators/keys/client.rb', line 17

def generate
  @key_dir.exist?  or raise Errors::KeyGeneration, "Key directory has not been generated yet"
  Authority.exist? or raise Errors::KeyGeneration, "Certificate Authority has not been created"

  revoke! if valid?

  FileUtils.cd(@props[:easy_rsa]) do
    system "#{cli_prop_vars} ./pkitool #{@name}"
  end

  exist? or raise Errors::KeyGeneration, "Keys do not exist"
  valid? or raise Errors::KeyGeneration, "keys are not valid"

  true
end

#keyObject



42
43
44
# File 'lib/net/openvpn/generators/keys/client.rb', line 42

def key
  "#{@props[:key_dir]}/#{@name}.key"
end