Module: EnfCli

Defined in:
lib/enfcli/version.rb,
lib/enfcli.rb,
lib/enfthor.rb,
lib/enfcli/commands/xcr.rb,
lib/enfcli/commands/xfw.rb,
lib/enfcli/commands/user.rb,
lib/enfcli/commands/xdns.rb,
lib/enfcli/commands/xiam.rb,
lib/enfcli/commands/captive.rb

Overview

Copyright 2018-2020 Xaptum,Inc

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Modules: Cmd, Shell Classes: CLI, CTX, ERROR, EnfThor, IPV6, IPV6Cidr

Constant Summary collapse

CONFIG_FILE =
"#{Dir.home() + "/.xaptum_config.json"}"
FIREWALL_CMD =
"firewall"
IAM_CMD =
"iam"
NETWORK_CMD =
"network"
USER_CMD =
"user"
CAPTIVE_CMD =
"captive"
DNS_CMD =
"dns"
VERSION =
"5.0.4"

Class Method Summary collapse

Class Method Details

.ask_password(prompt = nil) ⇒ Object



114
115
116
117
118
# File 'lib/enfcli.rb', line 114

def self.ask_password(prompt = nil)
  prompt ||= "Enter Password: "
  password = IO::console.getpass prompt
  return password
end

.expand_env(str) ⇒ Object



141
142
143
# File 'lib/enfcli.rb', line 141

def self.expand_env(str)
  str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) { ENV[$1] }
end

.expand_path(file) ⇒ Object



137
138
139
# File 'lib/enfcli.rb', line 137

def self.expand_path(file)
  new_file = File.expand_path(EnfCli::expand_env(file))
end

.generate_ec_cert(key, ipv6) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/enfcli.rb', line 120

def self.generate_ec_cert(key, ipv6)
  # monkey patch
  OpenSSL::PKey::EC.send(:alias_method, :private?, :private_key?)

  # Generate cert
  cert = OpenSSL::X509::Certificate.new
  cert.subject = cert.issuer = OpenSSL::X509::Name.new([["CN", ipv6.to_s]])
  cert.not_before = Time.now
  cert.not_after = Time.now + 365 * 24 * 60 * 60
  cert.public_key = key
  cert.serial = SecureRandom.random_number(2 ** 159 - 2) + 1
  cert.version = 2

  cert.sign key, OpenSSL::Digest::SHA256.new
  cert
end

.to_canonical_ipv6(ipv6) ⇒ Object



145
146
147
148
# File 'lib/enfcli.rb', line 145

def self.to_canonical_ipv6(ipv6)
  ip = EnfCli::IPV6.new ipv6
  ip.to_s
end