# encoding: UTF-8 module Vines # A module for utility methods with no better home. module Kit # Create a hex-encoded, SHA-512 HMAC of the data, using the secret key. def self.hmac(key, data) digest = OpenSSL::Digest::Digest.new("sha512") OpenSSL::HMAC.hexdigest(digest, key, data) end # Generates a random uuid per rfc 4122 that's useful for including in # stream, iq, and other xmpp stanzas. def self.uuid SecureRandom.uuid end # Generates a random 128 character authentication token. def self.auth_token SecureRandom.hex(64) end def self.local_ip orig = Socket.do_not_reverse_lookup Socket.do_not_reverse_lookup = true UDPSocket.open do |s| s.connect '64.223.187.99', 1 s.addr.last end ensure Socket.do_not_reverse_lookup = orig end # Generates dialback key as described in XEP-0185 def self.dialback_key(receiving_server, originating_server, stream_id) sha = Digest::SHA2.new(256) sha.update("#{receiving_server} #{originating_server} #{stream_id}") sha.to_s end end end