Netty Socketio SSL - java

I cant seem to get the sslchatlauncher from netty socketio demo
I already did this to my server
config.setHostname("localhost");
config.setPort(9092);
config.setKeyStorePassword("password");
InputStream stream = new FileInputStream("C:/keystore.jks");
config.setKeyStore(stream);
While on the javascript client
var socket = io.connect('https://localhost:9092',{secure: true});
Still, the client can't connect to the server. Is there any item i am missing?thanks.

Related

Vert.x websocket client - 400 Bad Request

How can I connect Cex.IO websocket API from my Java verticles?
The problem is that Vert.x doesn't provide me with a way to connect only with WsURI as Node.JS does. I have to specify port and host and get HTTP 400 Bad Request exception.
With Node.js you do:
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.connect("wss://ws.cex.io/ws/");
With Vert.x you have to do
int host = 443; // That's defaults
String host = "cex.io"; // Am I right by specifying this host?
HttpClient client = Vertx.vertx().createHttpClient();
client.websocket(port, host, "wss://ws.cex.io/ws/", ws -> { ...});
This HttpClient#websocket method takes a relative URI as third parameter.
You should be able to connect like this:
client = vertx.createHttpClient(new HttpClientOptions()
.setDefaultHost("ws.cex.io")
.setDefaultPort(443)
.setSsl(true));
client.websocket("/ws", ws -> {
// Work with the websocket
});

Mockserver not responding running over https

My mockserver is running on a apache https connector over port 8443. But when I try to load the expectation using the following it does nothing. However when I use http connector it works like a charm.
new MockServerClient(ip, Integer.parseInt(port), contextPath)
.when(request, times, timeToLive)
.respond(response);
Based on my understanding it will use the http connector so I also tried
MockServerClient client = new MockServerClient(ip, Integer.parseInt(port), contextPath);
HttpForward httpForward = new HttpForward()
.withHost(ip)
.withPort(Integer.parseInt(port))
.withScheme(HttpForward.Scheme.HTTPS);
// when
ForwardChainExpectation forwardChainExpectation = client.when(request);
forwardChainExpectation.forward(httpForward);
What am I missing?
Can the mock server work over a https connector?

SSL Handshake and Server Response

I want to know that if the website content change during SSL handshake or TCP handshake what happen?
For example:
The TCP or SSL handshake start exactly at 16:02:00 o'clock between the client and server.And some reason the handshake take a long time.Let's say 5 seconds.
So handshake finish at 16:02:05 with some latency but succesfully.And client start to the take content.
But if the site content change while ssl handshake.For example if it change at 16:02:03 what happen?
Let's say at 16:02:00 the site content is: "ABCD" (when ssl or tcp handshake start)
And at 16:02:03 it changes to: "ABCD1234"(while handshake continue)
So the client get which one of them; "ABCD" or "ABCD1234" ?
And here is the my client side java code for get the server response:
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
URL obj = new URL(url); // url is https
HttpURLConnection con = (HttpURLConnection) obj.openConnection(proxy);
con.setConnectTimeout(10000);
con.setReadTimeout(15000);
int responseCode = con.getResponseCode();
InputStream is = con.getInputStream();
The server sends the response which is current at the time it opens the response file (or wherever it gets the response from). The full URL is only known after the server received the HTTP request. This request is only done after the SSL handshake inside the established SSL tunnel. Thus it will not serve the version from before the handshake.
Your code included in your post doesn't use clearly SSL, but with SSL, handshake must be done before anything else. No content will be downloaded before handshake is done (and valid) because no request can be done before that. Handskake must be finished to encode and decode correctly the request.

SMTP client using BouncyCastle's lightweight TLS API

I need to add TLS support to a simple Java-based SMTP client. The client implements the SMTP protocol over java.net.Socket, i.e. it does not use Java Mail or other high level APIs.
I would like to use BouncyCastle's lightweight TLS API for this task. I have been looking for examples but haven't been able to find too much. Can anyone give any pointers?
Turns out this was much easier than I expected. I could establish a secure SSL connection to a SMTP mail server by just modifying the original SMTP client code from this:
Socket s = new Socket(server, port);
InputStream is = s.getInputStream();
InputStream os = s.getOutputStream();
[...]
To this:
Socket s = new Socket(server, port);
TlsProtocolHandler handler = new TlsProtocolHandler(s.getInputStream(),
s.getOutputStream());
handler.connect(new AlwaysValidVerifyer());
InputStream is = handler.getInputStream();
InputStream os = handler.getOutputStream();
[...]
The server's certificate is not being verified yet (AlwaysValidVerifier is a dummy verifier that will accept anything) but this is a good start already.

How to handle TLS certificate using Smack XMPP library in java

HI everyone. I've just started to play a little with XMPP in java, both server and client side.
On the server side I'm using Apache Vysper 0.7 and on client side I'm using Ignite Smack 3.1.0
I'm using a small XMPP embedded server from the apache vysper demo page using a TLS certificate that comes with the source code:
XMPPServer server = new XMPPServer("localhost");
StorageProviderRegistry providerRegistry = new MemoryStorageProviderRegistry();
AccountManagement accountManagement = (AccountManagement) providerRegistry.retrieve(AccountManagement.class);
Entity user = EntityImpl.parseUnchecked("user#localhost");
accountManagement.addUser(user, "password");
server.setStorageProviderRegistry(providerRegistry);
server.addEndpoint(new TCPEndpoint());
server.setTLSCertificateInfo(new File("bogus_mina_tls.cert"), "boguspw");
server.start();
System.out.println("Vysper server is running...");
The problem is that this is not a correct/valid certificate. If I test my server using pidgin an alert window pops up and tells me the certificate is invalid and a button in case I want to add an exception for this.
What I want is to do the same thing with the Smack api, but I don't know how.
on my smack api I'm using something like this:
ConnectionConfiguration config = new ConnectionConfiguration("localhost",5222, "localhost");
config.setSASLAuthenticationEnabled(false);
connection = new XMPPConnection(config);
connection.connect();
connection.login(userName, password);
So here it is. What do I need to do to accept or decline invalid certificates ?
Thanks for your help.
In the integration tests in Apache Vysper, we use something like:
ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("localhost", 5222);
connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
connectionConfiguration.setSASLAuthenticationEnabled(true);
connectionConfiguration.setKeystorePath("src/main/resources/bogus_mina_tls.cert");
connectionConfiguration.setTruststorePath("src/main/resources/bogus_mina_tls.cert");
connectionConfiguration.setTruststorePassword("boguspw");
See for example: https://svn.apache.org/repos/asf/mina/vysper/trunk/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/AbstractIntegrationTestCase.java
I think you are looking for
config.setSelfSignedCertificateEnabled(true)

Categories