I have a requirement to convert certain bash
scripts to java
and one such script connects to a server using openssl
with a vanity-url
as a parameter to check if that is connectable using that vanity-url
. See command below
/usr/bin/openssl s_client -connect api.sys.found1.cf.company.com:443 -servername www.app.company.com 2>/dev/null
I wanted to do the similar activity in java
and test the connectivity. Any ideas on how to make a open-ssl
connection using Java .. Is this something that I need to use external Library ?
call isAliasExists with your values ,
isAliasExists("api.sys.found1.cf.company.com","www.app.company.com");
Without really knowing what SNI was I tried to get some insight with the test-program shown below.
I don't know the output from the
openssl s_client
command, but the test-program might prove to be a starting point. When thejavax.net.debug
output is turned on a lot of output is dumped of which only a few lines are relevant (see also the comments). That is a bit annoying and I do not have an easy solution for that. TheTrustAllServers
class can be reworked to inspect the certificates you expect to receive from the server (a.ka. host) for a particular domain. There might be other options (e.g. the socket's handshake methods) but this is as far as I got.I was able to achieve this by referring the document over here
Basically, a
SSLEngine
needs to be created and make a successful handshake along withSNI
After creating SSLEngine, the
handShake
has to beginOnce the
handShake
is done. you can get thePrincipal
object