private boolean negotiateEncryption(final Element features) throws IOException
        {
            log("Negotiating encryption...");
            final Element startTLSel = features.element(QName.get("starttls", "urn:ietf:params:xml:ns:xmpp-tls"));
            final boolean peerSupportsStartTLS = startTLSel != null;
            final boolean peerRequiresStartTLS = peerSupportsStartTLS && startTLSel.element("required") != null;
            log("Openfire " + (peerRequiresStartTLS ? "requires" : (peerSupportsStartTLS ? "supports" : "does not support" )) + " StartTLS. Our own policy: " + encryptionPolicy + ".");

            switch (encryptionPolicy) {
                case disabled:
                    if (peerRequiresStartTLS) {
                        final Document outbound = DocumentHelper.createDocument();
                        final Namespace namespace = new Namespace("stream", "http://etherx.jabber.org/streams");
                        final Element root = outbound.addElement(QName.get("stream", namespace));
                        root.add(Namespace.get("jabber:server"));
                        final Element error = root.addElement(QName.get("error", "stream", "http://etherx.jabber.org/streams"));
                        error.addElement(QName.get("undefined-condition", "urn:ietf:params:xml:ns:xmpp-streams"));

                        markLastStreamIDasProcessed(); // Prevents the code from waiting on this stream to be registered with session manager during test fixture teardown.

                        send(root.asXML().substring(root.asXML().indexOf(">")+1));
                        throw new InterruptedIOException("Openfire requires TLS, we disabled it.");
                    }
                    return false;
                case optional:
                    if (peerSupportsStartTLS) {
                        initiateTLS();
                        return true;
                    }
                    return false;
                case required:
                    if (!peerSupportsStartTLS) {
                        final Document outbound = DocumentHelper.createDocument();
                        final Namespace namespace = new Namespace("stream", "http://etherx.jabber.org/streams");
                        final Element root = outbound.addElement(QName.get("stream", namespace));
                        root.add(Namespace.get("jabber:server"));
                        final Element error = root.addElement(QName.get("error", "stream", "http://etherx.jabber.org/streams"));
                        error.addElement(QName.get("undefined-condition", "urn:ietf:params:xml:ns:xmpp-streams"));

                        markLastStreamIDasProcessed(); // Prevents the code from waiting on this stream to be registered with session manager during test fixture teardown.

                        send(root.asXML().substring(root.asXML().indexOf(">")+1));
                        throw new InterruptedIOException("Openfire disabled TLS, we require it.");
                    }
                    else
                    {
                        initiateTLS();
                        return true;
                    }
                default:
                    throw new IllegalStateException("This implementation does not supported encryption policy: " + encryptionPolicy);
            }
        }
Returns 'true' if negotiation was started, false if no negotiation was started.
xmppserver/src/test/java/org/jivesoftware/openfire/session/RemoteInitiatingServerDummy.java