Class: VPN::Config::Generator
- Inherits:
-
Object
- Object
- VPN::Config::Generator
- Defined in:
- lib/vpn/config/generator.rb
Instance Attribute Summary collapse
-
#auth_name ⇒ Object
Returns the value of attribute auth_name.
-
#auth_pass ⇒ Object
Returns the value of attribute auth_pass.
-
#certificate_pass ⇒ Object
Returns the value of attribute certificate_pass.
-
#certificate_path ⇒ Object
Returns the value of attribute certificate_path.
-
#data_file ⇒ Object
Returns the value of attribute data_file.
-
#endpoints ⇒ Object
Returns the value of attribute endpoints.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#provider ⇒ Object
Returns the value of attribute provider.
Instance Method Summary collapse
- #enabled_vpns ⇒ Object
- #generate_plist ⇒ Object
- #generate_signed_plist ⇒ Object
-
#initialize(auth_name: nil, auth_pass: nil, identifier: nil, certificate_path: nil, certificate_pass: nil, provider: nil, endpoints: nil, data_file: nil) ⇒ Generator
constructor
A new instance of Generator.
- #providers ⇒ Object
- #selected_provider ⇒ Object
- #vpns ⇒ Object
Constructor Details
#initialize(auth_name: nil, auth_pass: nil, identifier: nil, certificate_path: nil, certificate_pass: nil, provider: nil, endpoints: nil, data_file: nil) ⇒ Generator
Returns a new instance of Generator.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vpn/config/generator.rb', line 11 def initialize(auth_name: nil, auth_pass: nil, identifier: nil, certificate_path: nil, certificate_pass: nil, provider: nil, endpoints: nil, data_file: nil) @auth_name = auth_name @auth_pass = auth_pass @identifier = identifier || "com.example.vpn" @certificate_path = certificate_path @certificate_pass = certificate_pass @provider = provider || "Private Internet Access" @endpoints = endpoints @data_file = data_file || VPN::Config::PROVIDERS_PATH end |
Instance Attribute Details
#auth_name ⇒ Object
Returns the value of attribute auth_name.
8 9 10 |
# File 'lib/vpn/config/generator.rb', line 8 def auth_name @auth_name end |
#auth_pass ⇒ Object
Returns the value of attribute auth_pass.
8 9 10 |
# File 'lib/vpn/config/generator.rb', line 8 def auth_pass @auth_pass end |
#certificate_pass ⇒ Object
Returns the value of attribute certificate_pass.
8 9 10 |
# File 'lib/vpn/config/generator.rb', line 8 def certificate_pass @certificate_pass end |
#certificate_path ⇒ Object
Returns the value of attribute certificate_path.
8 9 10 |
# File 'lib/vpn/config/generator.rb', line 8 def certificate_path @certificate_path end |
#data_file ⇒ Object
Returns the value of attribute data_file.
8 9 10 |
# File 'lib/vpn/config/generator.rb', line 8 def data_file @data_file end |
#endpoints ⇒ Object
Returns the value of attribute endpoints.
8 9 10 |
# File 'lib/vpn/config/generator.rb', line 8 def endpoints @endpoints end |
#identifier ⇒ Object
Returns the value of attribute identifier.
8 9 10 |
# File 'lib/vpn/config/generator.rb', line 8 def identifier @identifier end |
#provider ⇒ Object
Returns the value of attribute provider.
8 9 10 |
# File 'lib/vpn/config/generator.rb', line 8 def provider @provider end |
Instance Method Details
#enabled_vpns ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/vpn/config/generator.rb', line 43 def enabled_vpns if endpoints && endpoints.any? vpns.select {|e| endpoints.include? e["name"] } else vpns end end |
#generate_plist ⇒ Object
51 52 53 |
# File 'lib/vpn/config/generator.rb', line 51 def generate_plist config.to_plist end |
#generate_signed_plist ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vpn/config/generator.rb', line 55 def generate_signed_plist private_key = p12.key signing_cert = p12.certificate private_key = p12.key intermediate_certs = p12.ca_certs signing_cert = p12.certificate # Read configuration profile configuration_profile_data = generate_plist # Sign the configuration profile signing_flags = OpenSSL::PKCS7::BINARY signature = OpenSSL::PKCS7.sign(signing_cert, private_key, configuration_profile_data, intermediate_certs, signing_flags) signature.to_der end |
#providers ⇒ Object
24 25 26 |
# File 'lib/vpn/config/generator.rb', line 24 def providers @providers ||= YAML.load_file(data_file)["providers"] end |
#selected_provider ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vpn/config/generator.rb', line 28 def selected_provider @selected_provider ||= begin prov = providers.find {|pr| pr["name"] == provider } if prov prov else raise ArgumentError, "Provider '#{provider}' not found" end end end |
#vpns ⇒ Object
39 40 41 |
# File 'lib/vpn/config/generator.rb', line 39 def vpns @vpns ||= selected_provider["endpoints"] end |