Skip to content

Commit

Permalink
SSL enhancements:
Browse files Browse the repository at this point in the history
- new SSL related events: start handshake, complete handshake, secure closed-
- enhance SSL state machine
- add unit tests
  • Loading branch information
jeffmaury committed Dec 12, 2014
1 parent db8d5ff commit 9fe463d
Show file tree
Hide file tree
Showing 15 changed files with 905 additions and 77 deletions.
22 changes: 22 additions & 0 deletions core/src/main/java/org/apache/mina/api/AbstractIoFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,26 @@ public void messageWriting(IoSession session, WriteRequest message, WriteFilterC
@Override
public void messageSent(final IoSession session, final Object message) {
}

/**
* {@inheritDoc}
*/
@Override
public void handshakeStarted(IoSession session) {
}

/**
* {@inheritDoc}
*/
@Override
public void handshakeCompleted(IoSession session) {
}

/**
* {@inheritDoc}
*/
@Override
public void secureClosed(IoSession session) {
}

}
21 changes: 21 additions & 0 deletions core/src/main/java/org/apache/mina/api/AbstractIoHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,25 @@ public void exceptionCaught(final IoSession session, final Exception cause) {
LOG.error("Unexpected exception, we close the session : ", cause);
session.close(true);
}

/**
* {@inheritDoc}
*/
@Override
public void handshakeStarted(IoSession abstractIoSession) {
}

/**
* {@inheritDoc}
*/
@Override
public void handshakeCompleted(IoSession session) {
}

/**
* {@inheritDoc}
*/
@Override
public void secureClosed(IoSession session) {
}
}
22 changes: 22 additions & 0 deletions core/src/main/java/org/apache/mina/api/IoFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,26 @@ public interface IoFilter {
* @param message the incoming message to process
*/
void messageSent(IoSession session, Object message);

/**
* Invoked when a secure handshake has been started.
*
* @param session {@link IoSession} associated with the invocation
*/
void handshakeStarted(IoSession session);

/**
* Invoked when a secure handshake has been completed.
*
* @param session {@link IoSession} associated with the invocation
*/
void handshakeCompleted(IoSession session);

/**
* Invoked when a secure context has been closed.
*
* @param session {@link IoSession} associated with the invocation
*/
void secureClosed(IoSession session);

}
21 changes: 21 additions & 0 deletions core/src/main/java/org/apache/mina/api/IoHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,25 @@ public interface IoHandler {
* @param cause the caught exception
*/
void exceptionCaught(IoSession session, Exception cause);

/**
* Invoked for secured session when the handshake has been started. May be called
* several times for a single session in case of rehandshake.
* @param session {@link IoSession} associated with the invocation
*/
void handshakeStarted(IoSession abstractIoSession);

/**
* Invoked for secured session when the handshake has been completed. May be called
* several times for a single session in case of rehandshake.
* @param session {@link IoSession} associated with the invocation
*/
void handshakeCompleted(IoSession session);

/**
* Invoked for secured session when underlying SSL/TLS session has been closed.
* @param session {@link IoSession} associated with the invocation
*/
void secureClosed(IoSession session);

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ public interface EventVisitor {
void visit(SentEvent event);

void visit(IdleEvent event);

void visit(HandshakeStartedEvent event);

void visit(HandshakeCompletedEvent handshakeCompletedEvent);

void visit(SecureClosedEvent secureClosedEvent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,34 @@ public void visit(SentEvent event) {
session.getService().getIoHandler().exceptionCaught(session, e);
}
}

@Override
public void visit(HandshakeStartedEvent event) {
IoSession session = event.getSession();
try {
session.getService().getIoHandler().handshakeStarted(session);
} catch (Exception e) {
session.getService().getIoHandler().exceptionCaught(session, e);
}
}

@Override
public void visit(HandshakeCompletedEvent event) {
IoSession session = event.getSession();
try {
session.getService().getIoHandler().handshakeCompleted(session);
} catch (Exception e) {
session.getService().getIoHandler().exceptionCaught(session, e);
}
}

@Override
public void visit(SecureClosedEvent event) {
IoSession session = event.getSession();
try {
session.getService().getIoHandler().secureClosed(session);
} catch (Exception e) {
session.getService().getIoHandler().exceptionCaught(session, e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Founimport org.apache.mina.api.IoSession;
tributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.service.executor;

import org.apache.mina.api.IoSession;

/**
* An {@link IoSession} handshake started {@link Event}
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class HandshakeCompletedEvent implements Event {
private final IoSession session;

public HandshakeCompletedEvent(final IoSession session) {
this.session = session;
}

/**
* {@inheritDoc}
*/
@Override
public IoSession getSession() {
return session;
}

@Override
public void visit(EventVisitor visitor) {
visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Founimport org.apache.mina.api.IoSession;
tributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.service.executor;

import org.apache.mina.api.IoSession;

/**
* An {@link IoSession} handshake started {@link Event}
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class HandshakeStartedEvent implements Event {
private final IoSession session;

public HandshakeStartedEvent(final IoSession session) {
this.session = session;
}

/**
* {@inheritDoc}
*/
@Override
public IoSession getSession() {
return session;
}

@Override
public void visit(EventVisitor visitor) {
visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Founimport org.apache.mina.api.IoSession;
tributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.service.executor;

import org.apache.mina.api.IoSession;

/**
* An {@link IoSession} secure closed {@link Event}
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class SecureClosedEvent implements Event {
private final IoSession session;

public SecureClosedEvent(final IoSession session) {
this.session = session;
}

/**
* {@inheritDoc}
*/
@Override
public IoSession getSession() {
return session;
}

@Override
public void visit(EventVisitor visitor) {
visitor.visit(this);
}
}
Loading

0 comments on commit 9fe463d

Please sign in to comment.