Working backplane dns client/server
This commit is contained in:
@@ -42,6 +42,11 @@ OptionParser.new do |opts|
|
||||
"Check for a public IPv6 and register with the backplane.") do
|
||||
options[:ipv6] = true
|
||||
end
|
||||
|
||||
opts.on("-f", "--sshfp",
|
||||
"Register host SSH key fingerprints with the backplane.") do
|
||||
options[:sshfp] = true
|
||||
end
|
||||
end.parse!
|
||||
|
||||
def error(msg)
|
||||
@@ -98,10 +103,12 @@ class XMPPClient
|
||||
def send(msg_content)
|
||||
msg_id = SecureRandom::uuid
|
||||
encoded_payload = payload(msg_content, msg_id).to_json
|
||||
puts "payload: #{encoded_payload}"
|
||||
msg = Jabber::Message.new(@service_jid, encoded_payload)
|
||||
msg.type = :chat
|
||||
@client.send(msg)
|
||||
response = receive_response(msg_id)
|
||||
puts "response: #{response}"
|
||||
response and response["status"] == "OK"
|
||||
end
|
||||
|
||||
@@ -109,6 +116,10 @@ class XMPPClient
|
||||
send(ip_payload(ip))
|
||||
end
|
||||
|
||||
def send_sshfp(fps)
|
||||
send(sshfp_payload(fps))
|
||||
end
|
||||
|
||||
def payload(req, msg_id)
|
||||
{
|
||||
version: 1,
|
||||
@@ -126,6 +137,14 @@ class XMPPClient
|
||||
}
|
||||
end
|
||||
|
||||
def sshfp_payload(fp)
|
||||
{
|
||||
request: :change_sshfp,
|
||||
domain: @domain,
|
||||
sshfp: fp
|
||||
}
|
||||
end
|
||||
|
||||
def register_response_callback
|
||||
@client.add_message_callback do |msg|
|
||||
enqueue_message(JSON.parse(msg.body))
|
||||
@@ -198,6 +217,13 @@ def interface_addresses(interface)
|
||||
end
|
||||
end
|
||||
|
||||
def host_sshfp
|
||||
keys = `ssh-keygen -r hostname`.split("\n").map do |k|
|
||||
k.match(/[0-9] [0-9] [a-fA-F0-9]{32,64}$/)[0]
|
||||
end
|
||||
keys.compact
|
||||
end
|
||||
|
||||
client = XMPPClient::new(options[:domain],
|
||||
Socket::gethostname,
|
||||
options[:server],
|
||||
@@ -243,6 +269,21 @@ begin
|
||||
puts "#{options[:server]}: no valid public IPv6 found on the local host"
|
||||
end
|
||||
end
|
||||
|
||||
if options[:sshfp]
|
||||
fps = host_sshfp
|
||||
if not fps.empty?
|
||||
puts "#{options[:server]}: #{Socket::gethostname}.#{options[:domain]} IN SSHFP => #{fps}"
|
||||
if client.send_sshfp(fps)
|
||||
puts "OK"
|
||||
else
|
||||
puts "ERROR"
|
||||
success = false
|
||||
end
|
||||
else
|
||||
puts "#{options[:server]}: no valid sshfps found"
|
||||
end
|
||||
end
|
||||
ensure
|
||||
client.disconnect
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user