Grizzly WebSocket SSL

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Grizzly WebSocket SSL

Victor Antonio Barzana
Hi dear Grizzly users,
Can anyone tell me how do I configure a SSL WebSockets server in Grizzly, I find no example over internet, I need to register an application to listen calls on port 9797 using wss, as well it would be very nice if you tell me where I can find some documentation about it.

Thanks a lot for your support,
Victor

Reply | Threaded
Open this post in threaded view
|

Re: Grizzly WebSocket SSL

oleksiys
Administrator
Hi Victor,

can you pls. share the code where you instantiate WebSocket server, it
would be easier to help.

Thanks.

WBR,
Alexey.

On 19.12.13 12:51, Victor Antonio Barzana wrote:
> Hi dear Grizzly users,
> Can anyone tell me how do I configure a SSL WebSockets server in
> Grizzly, I find no example over internet, I need to register an
> application to listen calls on port 9797 using wss, as well it would
> be very nice if you tell me where I can find some documentation about it.
>
> Thanks a lot for your support,
> Victor
>

Reply | Threaded
Open this post in threaded view
|

Re: Grizzly WebSocket SSL

Victor Antonio Barzana
Thanks Oleksiy for your quickly response, here is my code of how I am creating my server:

// Create encrypted (SSL) server socket for wss:// protocol
if (mGrizzlySSLPort > 0) {
if (mLog.isDebugEnabled()) {
mLog.debug("Trying to initiate SSL on port " + mGrizzlySSLPort + "...");
}
if (mKeyStore != null && !mKeyStore.isEmpty()
&& mKeyStorePassword != null && !mKeyStorePassword.isEmpty()) {
if (mLog.isDebugEnabled()) {
mLog.debug("Using keystore " + mKeyStore + "...");
mLog.debug("Starting Grizzly SSL engine '"
+ getId()
+ "' at port " + mGrizzlySSLPort + ","
+ " with default timeout "
+ (mSessionTimeout > 0 ? mSessionTimeout + "ms" : "infinite")
+ "...");
}
try {
mGrizzlySSLServer = HttpServer.createSimpleServer(lDocumentRoot, mGrizzlySSLPort);
SSLContextConfigurator sslContext = new SSLContextConfigurator();
sslContext.setKeyStoreFile(lKeyStorePath);
sslContext.setKeyStorePass(mKeyStorePassword);
SSLEngineConfigurator lEngineConfigurator = new SSLEngineConfigurator(sslContext, false, false, false);
mGrizzlySSLServer.getListener("grizzly").setSSLEngineConfig(lEngineConfigurator);
mGrizzlySSLServer.getListener("grizzly").registerAddOn(new WebSocketAddOn());

// The WebSocketApplication will control the incoming and
//outgoing flow, connection, listeners, etc...
final WebSocketApplication lGrizzlyApplication = new GrizzlyWebSocketApplication(this);
// Registering grizzly jWebSocket Wrapper Application into grizzly WebSocketEngine
WebSocketEngine.getEngine().register("/jWebSocket", "/jWebSocket", lGrizzlyApplication);
mGrizzlySSLServer.start();
} catch (IOException lEx) {
mLog.error(Logging.getSimpleExceptionMessage(lEx, "instantiating SSL engine"));
}
} else {
mLog.error("SSL engine could not be instantiated due to missing configuration,"
+ " please set sslport, keystore and password options.");
}
}

When I try to connect from any browser client the response doesn't even arrive to my grizzly listeners inside the websocket application, what could be happening? 

Thanks a lot, by the way, grizzly is a super good product, I am member of the jWebSocket team and we have one of our WebSocket engines based in Grizzly, very fast and reliable, as well scalable. My best regards to you guys.

Thanks,
Victor
Reply | Threaded
Open this post in threaded view
|

Re: Grizzly WebSocket SSL

oleksiys
Administrator
Hi Victor,

I think you missed
mGrizzlySSLServer.getListener("grizzly").setSecure(true);

Anyway, I added a WebSocket Server over SSL sample here [1]. The server initialization code is here [2].

WBR,
Alexey.

[1] https://java.net/projects/grizzly/sources/git/content/samples/websockets/chat-ssl
[2] https://java.net/projects/grizzly/sources/git/content/samples/websockets/chat-ssl/src/main/java/org/glassfish/grizzly/samples/websockets/ChatWebSocketSecuredServer.java

On 19.12.13 22:31, Victor Antonio Barzana wrote:
Thanks Oleksiy for your quickly response, here is my code of how I am creating my server:

// Create encrypted (SSL) server socket for <a class="moz-txt-link-freetext" href="wss://">wss:// protocol
if (mGrizzlySSLPort > 0) {
if (mLog.isDebugEnabled()) {
mLog.debug("Trying to initiate SSL on port " + mGrizzlySSLPort + "...");
}
if (mKeyStore != null && !mKeyStore.isEmpty()
&& mKeyStorePassword != null && !mKeyStorePassword.isEmpty()) {
if (mLog.isDebugEnabled()) {
mLog.debug("Using keystore " + mKeyStore + "...");
mLog.debug("Starting Grizzly SSL engine '"
+ getId()
+ "' at port " + mGrizzlySSLPort + ","
+ " with default timeout "
+ (mSessionTimeout > 0 ? mSessionTimeout + "ms" : "infinite")
+ "...");
}
try {
mGrizzlySSLServer = HttpServer.createSimpleServer(lDocumentRoot, mGrizzlySSLPort);
SSLContextConfigurator sslContext = new SSLContextConfigurator();
sslContext.setKeyStoreFile(lKeyStorePath);
sslContext.setKeyStorePass(mKeyStorePassword);
SSLEngineConfigurator lEngineConfigurator = new SSLEngineConfigurator(sslContext, false, false, false);
mGrizzlySSLServer.getListener("grizzly").setSSLEngineConfig(lEngineConfigurator);
mGrizzlySSLServer.getListener("grizzly").registerAddOn(new WebSocketAddOn());

// The WebSocketApplication will control the incoming and
//outgoing flow, connection, listeners, etc...
final WebSocketApplication lGrizzlyApplication = new GrizzlyWebSocketApplication(this);
// Registering grizzly jWebSocket Wrapper Application into grizzly WebSocketEngine
WebSocketEngine.getEngine().register("/jWebSocket", "/jWebSocket", lGrizzlyApplication);
mGrizzlySSLServer.start();
} catch (IOException lEx) {
mLog.error(Logging.getSimpleExceptionMessage(lEx, "instantiating SSL engine"));
}
} else {
mLog.error("SSL engine could not be instantiated due to missing configuration,"
+ " please set sslport, keystore and password options.");
}
}

When I try to connect from any browser client the response doesn't even arrive to my grizzly listeners inside the websocket application, what could be happening? 

Thanks a lot, by the way, grizzly is a super good product, I am member of the jWebSocket team and we have one of our WebSocket engines based in Grizzly, very fast and reliable, as well scalable. My best regards to you guys.

Thanks,
Victor