public static boolean verifyReceivedKey(Element doc, Connection connection) {
        String verifyFROM = doc.attributeValue("from");
        String verifyTO = doc.attributeValue("to");
        String key = doc.getTextTrim();
        StreamID streamID = BasicStreamIDFactory.createStreamID( doc.attributeValue("id") );

        final Logger log = LoggerFactory.getLogger( Log.getName() + "[Acting as Authoritative Server: Verify key sent by RS: " + verifyFROM + " (id " + streamID+ ")]" );

        log.debug( "Verifying key... ");

        // TODO If the value of the 'to' address does not match a recognized hostname,
        // then generate a <host-unknown/> stream error condition
        // TODO If the value of the 'from' address does not match the hostname
        // represented by the Receiving Server when opening the TCP connection, then
        // generate an <invalid-from/> stream error condition

        if (!ServerDialback.isEnabled() && !ServerDialback.isEnabledForSelfSigned()) {
            Log.info("Unable to verify the Dialback key as Dialback has been disabled by configuration.");
            StringBuilder sb = new StringBuilder();
            sb.append("<db:verify");
            sb.append(" from=\"").append(verifyTO).append("\"");
            sb.append(" to=\"").append(verifyFROM).append("\"");
            sb.append(" type=\"error\"");
            sb.append(" id=\"").append(streamID.getID()).append("\">");
            sb.append("<error type=\"cancel\"><policy-violation xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/></error>");
            sb.append("</db:verify>");
            connection.deliverRawText(sb.toString());
            return false;
        }

        // Verify the received key
        // Created the expected key based on the received ID value and the shared secret
        String expectedKey = AuthFactory.createDigest(streamID.getID(), getSecretkey());
        boolean verified = expectedKey.equals(key);

        // Send the result of the key verification
        StringBuilder sb = new StringBuilder();
        sb.append("<db:verify");
        sb.append(" from=\"").append(verifyTO).append("\"");
        sb.append(" to=\"").append(verifyFROM).append("\"");
        sb.append(" type=\"");
        sb.append(verified ? "valid" : "invalid");
        sb.append("\" id=\"").append(streamID.getID()).append("\"/>");
        connection.deliverRawText(sb.toString());
        log.debug("Verification successful! Key was: " + (verified ? "VALID" : "INVALID"));
        return verified;
    }
Verifies the key sent by a Receiving Server. This server will be acting as the
Authoritative Server when executing this method. The remote server may have established
a new connection to the Authoritative Server (i.e. this server) for verifying the key
or it may be reusing an existing incoming connection.

@param doc the Element that contains the key to verify.
@param connection the connection to use for sending the verification result
@return true if the key was verified.
xmppserver/src/main/java/org/jivesoftware/openfire/server/ServerDialback.java