Issue Details (XML | Word | Printable)

Key: DIRMINA-40
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Trustin Lee
Reporter: Vinod Panicker
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
MINA

Filter API needs callback for enabled notification

Created: 16/May/05 07:58 PM   Updated: 01/Dec/05 02:47 PM
Return to search
Component/s: None
Affects Version/s: 0.7.0, 0.7.1
Fix Version/s: 0.9.0

Time Tracking:
Not Specified

Environment: All

Resolution Date: 12/Jun/05 10:14 PM


 Description  « Hide
The Filter api currently assumes that it would be applied only on unopened sessions. Eg - the SSL filter currently starts its work on the sessionOpened() callback. This is an incorrect assumption since the SSL filter could be applied on an existing plain TCP connection as well.

It would be great if there were new callbacks defined - something like filterEnabled() and filterDisabled()

This would allow us to use the filters on existing sessions as well.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Trustin Lee added a comment - 17/May/05 02:43 PM
I modified SSLFilter to create SSLHandler at every events to resolve that issue. SSLHandler is created when SSLHandler interface is not found in its internal map now.

FilterEnabled() and filterDisabled() is a good idea, but adding a filter to an acceptor causes some problem:

* A lot of events are fired at once to cause overload
* SessionManagers have to manage the list of sessions, and we have to handle concurrecy issues while iterating session list.

I think it is best for filter developers to check any data associated with session is initialized before filtering IMHO.

Trustin Lee added a comment - 17/May/05 03:28 PM
Please look at DIRMINA-43. I forgot to call createSSLSessionHandler instead of getSSLSessionHandler.

Vinod Panicker added a comment - 17/May/05 05:36 PM
Your fix solves the problem. Thanks.

My rationale behind having filterEnabled() and filterDisabled() was to have something like a constructor/destructor for a filter. The filter programmer can do all setup/teardown work in the respective callbacks.

Even if the filter gets applied to an Acceptor, filterEnabled() would get called only once for its lifetime and not for each accepted connection.

This helps a lot in having a clean filter implementation IMO.

Trustin Lee added a comment - 18/May/05 08:38 AM
There was init() and destroy() method long time ago. But I removed them because a filter instances can be used by more than one session managers. For example, thread pool filters could be shared by all acceptors and connectors. filter chains will have to maintain the glocal reference count of filters to call init() and destroy() only once for each. Do you agree?

Vinod Panicker added a comment - 18/May/05 03:42 PM
The SSL/TLS filter needs to do a handshake when it is applied to a session and also may need to discard sensitive data when it is being removed. Currently this is not possible as isolated activities because if the filter is applied on an active session, the handshake process will not start unless any data is sent/received over the session.

Your previous comment also reminded me about something -The definition of a "Filter". For me, a filter is something that taps the session and monitors/modifies the data flowing over it. I've not been able to digest a ThreadPoolFilter. Thats actually an implementation of a concurrency mechanism rather than a Filter (according to my definition). Maybe if we separate it out into a separate entity, the problem with init() and destroy() might also be solved?

I'll have to check on the current implementation to grok what u're talking abt (filter chain reference counting et al.). Will do that and get back to you on other possible alternatives.

Vinod Panicker added a comment - 25/May/05 11:27 PM
This fix doesn't work in required circumstances.

Basically this depends on one of the endpoints writing some data on to the session to start the ssl/tls handshake process.

According to the SSL/TLS RFC, the client initiates the handshake process. If the handshake fails for some reason, the connection is typically terminated.

In the case of the MINA SSLFilter, the handshake can begin only when one of the entities writes data to the session. And if the server writes data first, that data is never sent across since the handshake is pending. In other words, it becomes imperative that the client send some data first. If the application protocol mandates that the server first write some data, the MINA SSLFilter won't work.

The only good fix would be to move the handshake process into an init() method that would get called automatically when the filter is applied. destroy() should also be provided to remove any sensitive information that is stored. Also, the filter should have a callback mechanism by way of which it can notify the handler that the initialization process is complete and actual data transmission can take place. This would be required for proper error handling in the application protocol.

Trustin Lee added a comment - 12/Jun/05 10:14 PM
I added init() and destroy() callback to IoFilter. They are automatically called when a filter is added to or removed from filter chain. AbstractIoFilterChain counts reference count of filters to prevent chain from calling init() or destroy() multiple times in case that filters are added more than once to different chain.

Vinod Panicker added a comment - 18/Jun/05 08:07 PM
init() and destroy() without any input parameters are not useful esp for filters such as the SSLFilter.

Taking the example of SSLFilter, an instance of SSLHandler should be logically created in init() if the filter is being applied on a Session that is already active. But in this case, since no Session object is being passed, the filter cant do anything. Also, what should be passed in init() when the filter is being applied on an Acceptor?

Trustin Lee added a comment - 05/Jul/05 01:22 PM
I replaced ini() and destroy() with filterAdded() and filterRemoved() as you requested. Please check my changes in the trunk. It now passes IoSession or IoSessionManager as a parameter whenever it is added to them. :)

Please close this issue after reviewing it.

Vinod Panicker added a comment - 05/Jul/05 02:53 PM
SSLFilter will need to be updated to use filterAdded and filterRemoved.

Trustin Lee added a comment - 26/Oct/05 04:49 PM
I've renamed IoFilter.filterAdded() and filterRemoved() to init() and destroy() to avoid name confusion.