labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r602571 - in /labs/vysper/src/main/java/org/apache/vysper: mina/ xmpp/applicationdomains/base/handler/ xmpp/protocol/ xmpp/protocol/exception/ xmpp/protocol/worker/ xmpp/server/response/ xmpp/writer/ xmpp/xmlfragment/
Date Sat, 08 Dec 2007 22:47:35 GMT
Author: berndf
Date: Sat Dec  8 14:47:34 2007
New Revision: 602571

URL: http://svn.apache.org/viewvc?rev=602571&view=rev
Log:
[vysper] StartTLS stream securing is working

Added:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/exception/TLSException.java
      - copied, changed from r542950, labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/exception/BadXMLException.java
Modified:
    labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java
    labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/base/handler/StreamStartHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ResponseWriter.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptedProtocolWorker.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptionStartedProtocolWorker.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java

Modified: labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java Sat Dec
 8 14:47:34 2007
@@ -56,7 +56,7 @@
         if (switchToTLS) {
             minaSession.setTrafficMask(TrafficMask.WRITE);
             SSLFilter filter = new SSLFilter(getServerRuntimeContext().getSslContext());
-            filter.setUseClientMode(true);
+            filter.setUseClientMode(false);
             minaSession.getFilterChain().addFirst("sslFilter", filter);
             minaSession.setAttribute(SSLFilter.DISABLE_ENCRYPTION_ONCE, Boolean.TRUE);
             minaSession.setAttribute(SSLFilter.USE_NOTIFICATION, Boolean.TRUE);

Modified: labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java Sat Dec  8
14:47:34 2007
@@ -19,6 +19,7 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.SSLFilter;
 import org.apache.vysper.xmpp.protocol.ProtocolWorker;
 import org.apache.vysper.xmpp.protocol.SessionStateHolder;
 import org.apache.vysper.xmpp.server.ServerRuntimeContext;
@@ -43,12 +44,28 @@
 
     public void messageReceived(IoSession ioSession, Object message) throws Exception {
         if (!(message instanceof Stanza)) {
-            throw new IllegalArgumentException("xmpp handler only accepts Stanza-typed messages");
+            messageReceivedNoStanza(ioSession, message);
+            return;
         }
-        Stanza stanza = (Stanza) message;
 
+        Stanza stanza = (Stanza) message;
         SessionContext session = extractSession(ioSession);
-        protocolWorker.processStanza(session, stanza, (SessionStateHolder)ioSession.getAttribute(ATTRIBUTE_VYSPER_SESSIONSTATEHOLDER));
+        SessionStateHolder stateHolder = (SessionStateHolder) ioSession.getAttribute(ATTRIBUTE_VYSPER_SESSIONSTATEHOLDER);
+
+        protocolWorker.processStanza(session, stanza, stateHolder);
+    }
+
+    private void messageReceivedNoStanza(IoSession ioSession, Object message) {
+        if (message == SSLFilter.SESSION_SECURED) {
+            SessionContext session = extractSession(ioSession);
+            SessionStateHolder stateHolder = (SessionStateHolder) ioSession.getAttribute(ATTRIBUTE_VYSPER_SESSIONSTATEHOLDER);
+            protocolWorker.processTLSEstablished(session, stateHolder);
+            return;
+        } else if (message == SSLFilter.SESSION_UNSECURED) {
+            throw new IllegalStateException("server must close session!"); // TODO
+        }
+
+        throw new IllegalArgumentException("xmpp handler only accepts Stanza-typed messages");
     }
 
     private SessionContext extractSession(IoSession ioSession) {
@@ -57,6 +74,7 @@
 
     public void messageSent(IoSession ioSession, Object o) throws Exception {
         // TODO implement
+        System.err.println("*** message sent");
     }
 
     public void sessionCreated(IoSession ioSession) throws Exception {
@@ -68,17 +86,21 @@
 
     public void sessionOpened(IoSession ioSession) throws Exception {
         // TODO implement
+        System.err.println("*** session opened");
     }
 
     public void sessionClosed(IoSession ioSession) throws Exception {
         // TODO implement
+        System.err.println("*** session closed");
     }
 
     public void sessionIdle(IoSession ioSession, IdleStatus idleStatus) throws Exception
{
         // TODO implement
+        System.err.println("*** session idle");
     }
 
     public void exceptionCaught(IoSession ioSession, Throwable throwable) throws Exception
{
         // TODO implement
+        throwable.printStackTrace(System.err);
     }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/base/handler/StreamStartHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/base/handler/StreamStartHandler.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/base/handler/StreamStartHandler.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/base/handler/StreamStartHandler.java
Sat Dec  8 14:47:34 2007
@@ -56,7 +56,8 @@
         if (clientCall && serverCall) serverCall = false; // silently ignore ambigous
attributes
         if (serverCall) sessionContext.setServerToServer(); else sessionContext.setClientToServer();
 
-        if (sessionStateHolder.getState() != SessionState.INITIATED) {
+        if (sessionStateHolder.getState() != SessionState.INITIATED && 
+            sessionStateHolder.getState() != SessionState.ENCRYPTED ) {
             return respondUnsupportedStanzaType("unexpected stream start");
         } 
         

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java Sat Dec
 8 14:47:34 2007
@@ -19,6 +19,7 @@
 
 import org.apache.vysper.xmpp.parser.ParsingException;
 import org.apache.vysper.xmpp.parser.StreamParser;
+import org.apache.vysper.xmpp.protocol.exception.TLSException;
 import org.apache.vysper.xmpp.protocol.worker.AuthenticatedProtocolWorker;
 import org.apache.vysper.xmpp.protocol.worker.EncryptedProtocolWorker;
 import org.apache.vysper.xmpp.protocol.worker.EncryptionStartedProtocolWorker;
@@ -116,6 +117,14 @@
         stateAwareProtocolWorker.processStanza(sessionContext, sessionStateHolder,
                                                stanza, stanzaHandler,
                                                responseWriter);
+    }
+    
+    public void processTLSEstablished(SessionContext sessionContext, SessionStateHolder sessionStateHolder)
{
+        if (sessionContext.getState() != SessionState.ENCRYPTION_STARTED) {
+            responseWriter.handleProtocolError(new TLSException(), sessionContext, null);
+            return;
+        }
+        sessionStateHolder.setState(SessionState.ENCRYPTED);
     }
 
 

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ResponseWriter.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ResponseWriter.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ResponseWriter.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ResponseWriter.java Sat Dec
 8 14:47:34 2007
@@ -61,7 +61,8 @@
     }
 
     public void handleProtocolError(ProtocolException protocolException, SessionContext sessionContext,
Stanza receivedStanza) {
-        Stanza errorStanza = protocolException.getErrorStanza();
+        Stanza errorStanza = null;
+        if (protocolException != null) errorStanza = protocolException.getErrorStanza();
 
         if (errorStanza == null) {
             errorStanza = ServerErrorResponses.getInstance().getError(StreamErrorCondition.BAD_FORMAT,

Copied: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/exception/TLSException.java
(from r542950, labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/exception/BadXMLException.java)
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/exception/TLSException.java?p2=labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/exception/TLSException.java&p1=labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/exception/BadXMLException.java&r1=542950&r2=602571&rev=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/exception/BadXMLException.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/exception/TLSException.java
Sat Dec  8 14:47:34 2007
@@ -22,20 +22,20 @@
 /**
  *
  */
-public class BadXMLException extends ProtocolException {
-    public BadXMLException() {
+public class TLSException extends ProtocolException {
+    public TLSException() {
         super();
     }
 
-    public BadXMLException(String string) {
+    public TLSException(String string) {
         super(string);
     }
 
-    public BadXMLException(String string, Throwable throwable) {
+    public TLSException(String string, Throwable throwable) {
         super(string, throwable);
     }
 
-    public BadXMLException(Throwable throwable) {
+    public TLSException(Throwable throwable) {
         super(throwable);
     }
-}
+}
\ No newline at end of file

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptedProtocolWorker.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptedProtocolWorker.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptedProtocolWorker.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptedProtocolWorker.java
Sat Dec  8 14:47:34 2007
@@ -23,6 +23,7 @@
 import org.apache.vysper.xmpp.server.SessionContext;
 import org.apache.vysper.xmpp.server.SessionState;
 import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.applicationdomains.base.handler.StreamStartHandler;
 
 /**
  */
@@ -33,6 +34,8 @@
     }
 
     protected boolean checkState(SessionContext sessionContext, SessionStateHolder sessionStateHolder,
Stanza stanza, StanzaHandler stanzaHandler, ResponseWriter responseWriter) {
-        throw new RuntimeException("worker not implemented");
+        if (stanzaHandler instanceof StreamStartHandler) return true;
+        responseWriter.writeStreamNotOpenedError(sessionContext);
+        return false;
     }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptionStartedProtocolWorker.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptionStartedProtocolWorker.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptionStartedProtocolWorker.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptionStartedProtocolWorker.java
Sat Dec  8 14:47:34 2007
@@ -33,6 +33,9 @@
     }
 
     protected boolean checkState(SessionContext sessionContext, SessionStateHolder sessionStateHolder,
Stanza stanza, StanzaHandler stanzaHandler, ResponseWriter responseWriter) {
+        // StartTLS is currently completely handled on the protocol side.
+        // anyway, there are no stanzas to be parsed between ENCRYPTION_STARTED and ENCRYPTED.
+        // the state change is handeld in ProtocolWorker.processTLSEstablished()
         throw new RuntimeException("worker not implemented");
     }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java
Sat Dec  8 14:47:34 2007
@@ -22,6 +22,7 @@
 import org.apache.vysper.xmpp.stanza.StanzaBuilder;
 import org.apache.vysper.xmpp.server.XMPPVersion;
 import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.server.SessionState;
 import org.apache.vysper.xmpp.addressing.Entity;
 
 /**
@@ -33,7 +34,11 @@
     }
 
     public Stanza getStreamOpener(boolean forClient, Entity from, XMPPVersion version, SessionContext
sessionContext) {
-        Stanza innerFeatureStanza = getFeaturesForEncryption(sessionContext);
+        Stanza innerFeatureStanza;
+        if (sessionContext.getState() == SessionState.INITIATED) innerFeatureStanza = getFeaturesForEncryption(sessionContext);
+        else if (sessionContext.getState() == SessionState.ENCRYPTED) innerFeatureStanza
= getFeaturesForAuthentication(); 
+        else throw new IllegalStateException("unsupported state for responding with stream
opener"); 
+        
         StanzaBuilder stanzaBuilder = getStreamOpener(forClient, from, sessionContext.getXMLLang(),
version, sessionContext.getSessionId(), innerFeatureStanza);
         
         return stanzaBuilder.getFinalStanza();

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java Sat
Dec  8 14:47:34 2007
@@ -21,6 +21,9 @@
 import org.apache.vysper.xmpp.xmlfragment.XMLText;
 import org.apache.vysper.xmpp.xmlfragment.Attribute;
 
+import java.util.List;
+import java.util.Iterator;
+
 /**
  * renders only reduced digest stanza information for logging output
  */
@@ -30,20 +33,48 @@
     private static final String EQUALS = "=";
 
     public static String render(XMLElement stanza) {
-        StringBuilder stringBuilder = new StringBuilder();
-        String outerName = stanza.getName();
-        stringBuilder.append(outerName);
-        XMLElement firstInnerElement = stanza.getFirstInnerElement();
+        try {
+            StringBuilder stringBuilder = new StringBuilder();
+            String outerName = stanza.getName();
+            stringBuilder.append(outerName);
+            XMLElement firstInnerElement = stanza.getFirstInnerElement();
+
+            if ("stream".equals(outerName)) {
+                renderStreamStart(stringBuilder, stanza, firstInnerElement);
+            } else if ("message".equals(outerName)) {
+                renderMessage(stringBuilder, stanza, firstInnerElement);
+            } else if ("error".equals(outerName)) {
+                renderError(stringBuilder, stanza, firstInnerElement);
+            } else if ("presence".equals(outerName)) {
+                renderPresence(stringBuilder, stanza, firstInnerElement);
+            }
+
+            return stringBuilder.toString();
+        } catch (Exception e) {
+            return "*render-exception*";
+        }
+    }
 
-        if ("message".equals(outerName)) {
-            renderMessage(stringBuilder, stanza, firstInnerElement);
-        } else if ("error".equals(outerName)) {
-            renderError(stringBuilder, stanza, firstInnerElement);
-        } else if ("presence".equals(outerName)) {
-            renderPresence(stringBuilder, stanza, firstInnerElement);
+    private static void renderStreamStart(StringBuilder stringBuilder, XMLElement stanza,
XMLElement firstInnerElement) {
+        try {
+            XMLElement features = stanza.getSingleInnerElementsNamed("features");
+            if (features != null) {
+                XMLElement mechanisms = features.getSingleInnerElementsNamed("mechanisms");
+                if (mechanisms != null) {
+                    stringBuilder.append(ELEMENT_SEPARATOR);
+                    stringBuilder.append("features.mechanisms[");
+                    List<XMLElement> list = mechanisms.getInnerElementsNamed("mechanism");
+                    for (Iterator<XMLElement> it = list.iterator(); it.hasNext();)
{
+                        XMLElement element = it.next();
+                        stringBuilder.append(element.getSingleInnerText().getText());
+                        if (it.hasNext()) stringBuilder.append(",");
+                    }
+                    stringBuilder.append("]");
+                }
+            }
+        } catch (XMLSemanticError xmlSemanticError) {
+            stringBuilder.append("*error*");
         }
-        
-        return stringBuilder.toString();
     }
 
     private static void renderError(StringBuilder stringBuilder, XMLElement stanza, XMLElement
firstInnerElement) {

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java?rev=602571&r1=602570&r2=602571&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java Sat Dec 
8 14:47:34 2007
@@ -129,6 +129,7 @@
     public List<XMLElement> getInnerElementsNamed(String name) {
         if (name == null) return null;
         List<XMLElement> innerElements = getInnerElements();
+        if (innerElements == null) return null;
         Iterator<XMLElement> elementIterator = innerElements.iterator(); // this List
will be modified now!
         while (elementIterator.hasNext()) {
             XMLElement xmlElement =  elementIterator.next();
@@ -139,6 +140,7 @@
 
     public XMLElement getSingleInnerElementsNamed(String name) throws XMLSemanticError {
         List<XMLElement> innerElements = getInnerElementsNamed(name);
+        if (innerElements == null) return null;
         if (innerElements.isEmpty()) return null;
         if (innerElements.size() > 1) throw new XMLSemanticError("element has more than
one inner element named: " + name);
         return innerElements.get(0);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message