'Verify the given host key for the given IP and host, asking for
confirmation from, and notifying, the given UI about changes to this
file.
@param ui: The user interface to request an IP address from.
@param hostname: The hostname that the user requested to connect to.
@param ip: The string representation of the IP address that is actually
being connected to.
@param key: The public key of the server.
@return: a L{Deferred} that fires with True when the key has been
verified, or fires with an errback when the key either cannot be
verified or has changed.
@rtype: L{Deferred}'

def verifyHostKey(self, ui, hostname, ip, key):

    hhk = defer.maybeDeferred(self.hasHostKey, hostname, key)
    def gotHasKey(result):
        if result:
            if (not self.hasHostKey(ip, key)):
                ui.warn(("Warning:    Permanently    added    the    %s    host    key    for    IP    address    '%s'    to    the    list    of    known    hosts." % (key.type(), nativeString(ip))))
                self.addHostKey(ip, key)
                self.save()
            return result
        else:
            def promptResponse(response):
                if response:
                    self.addHostKey(hostname, key)
                    self.addHostKey(ip, key)
                    self.save()
                    return response
                else:
                    raise UserRejectedKey()
            keytype = key.type()
            if (keytype is 'EC'):
                keytype = 'ECDSA'
            prompt = ("The    authenticity    of    host    '%s    (%s)'    can't    be    established.\n%s    key    fingerprint    is    SHA256:%s.\nAre    you    sure    you    want    to    continue    connecting    (yes/no)?    " % (nativeString(hostname), nativeString(ip), keytype, key.fingerprint(format=FingerprintFormats.SHA256_BASE64)))
            proceed = ui.prompt(prompt.encode(sys.getdefaultencoding()))
            return proceed.addCallback(promptResponse)
    return hhk.addCallback(gotHasKey)
