users@grizzly.java.net

Re: Problem with SSL

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Tue, 30 Sep 2008 14:55:20 +0200

Hi,

ok, now it looks more clear for me :)

>
> I have a map in server's class
> private ConcurrentHashMap<SelectionKey, Client> _clientsMap;
>
> which I update from a class extending SSLSelectorHandler when i get
> Accept
> interest
>
> @Override
> public boolean onAcceptInterest(SelectionKey key, Context ctx)
> throws
> IOException
> {
> SelectableChannel _channel = acceptWithoutRegistration(key);
> if (_channel != null)
> {
> configureChannel(_channel);
> SelectionKey readKey = _channel.register(selector,
> SelectionKey.OP_READ);
> readKey.attach(System.currentTimeMillis());
> Server.getInstance().addClient(readKey); //here is where
> i add
> the key to collection
> }
> return false;
> }
>
> Or should i make any check of the result of handshaking before
> dealing with
> that key?
Usually when we build SSL available server, we do that using
ProtocolChain, where include SSLReadFilter.

         final Controller controller = new Controller();

         SSLSelectorHandler selectorHandler = new SSLSelectorHandler();
         selectorHandler.setPort(PORT);

         final SSLReadFilter readFilter = new SSLReadFilter();
         readFilter.setSSLContext(sslContext);

         controller.setSelectorHandler(selectorHandler);

         controller.setProtocolChainInstanceHandler(new
DefaultProtocolChainInstanceHandler() {

             @Override
             public ProtocolChain poll() {
                 ProtocolChain protocolChain = protocolChains.poll();
                 if (protocolChain == null) {
                     protocolChain = new DefaultProtocolChain();
                     protocolChain.addFilter(readFilter);
                     protocolChain.addFilter(echoFilter);
                 }
                 return protocolChain;
             }
         });

So, I would suggest you to move logic, which adds Client to map
Server.getInstance().addClient(readKey);

to a custom Filter, which will be executed after SSLReadFilter. This
way you'll be sure, that connection you have passed handshake and
ready for processing.


> I thought, that even if handshake has failed, i would
> cancel/remove that key later during the first isValid() check. Am I
> wrong,
> isn't the key i store in my collection the right one to perform write
> operations with?
Well, key.isValid() just checks the key to be valid, it doesn't have
any knowledge about SSL.

> Do I have to attach something to this key?
Ideally you should not care about attachments :)

Thanks.
And let me know, if you have questions.

WBR,
Alexey.

>
>
> Thank you,
> -- Quende
>
>
> Oleksiy Stashok wrote:
>>
>> Hi Quende,
>>
>> according to your example... how do you create client connection,
>> where you take clientSelectionKey?
>> Cause client connection should pass the handshake phase, which
>> probably is missed in your scenario.
>>
>> If you can share more code, it could help! :)
>>
>> Thank you.
>>
>> WBR,
>> Alexey.
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Problem-with-SSL-tp19709902p19739385.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>