Skip to content

Instantly share code, notes, and snippets.

@tjunussov
Created April 16, 2016 18:34
Show Gist options
  • Save tjunussov/734d2824d4e7ea211260b128bd6f6178 to your computer and use it in GitHub Desktop.
Save tjunussov/734d2824d4e7ea211260b128bd6f6178 to your computer and use it in GitHub Desktop.
Confluence Email Send SSL issue - Add certificate to java keystore ( Linux )
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Usage: "+SSLPoke.class.getName()+" <host> <port>");
System.exit(1);
}
try {
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1]));
InputStream in = sslsocket.getInputStream();
OutputStream out = sslsocket.getOutputStream();
// Write a test byte to get a reaction :)
out.write(1);
while (in.available() > 0) {
System.out.print(in.read());
}
System.out.println("Successfully connected");
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
@tjunussov
Copy link
Author

Test of java SSL / keystore / cert setup. Came from https://confluence.atlassian.com/download/attachments/117455/SSLPoke.java

Usage:

extract cert from server to yourcert.crt file:
openssl s_client -connect server:443

negative test cert / keytool:
java SSLPoke server 443
you should get something like
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

import cert into default keytool: ( default password for keystore "changeit" )
keytool -import -alias alias.server.com -keystore $JAVA_HOME/jre/lib/security/cacerts -file yourcert.crt

positive test cert / keytool:
java SSLPoke server 443
you should get this:
Successfully connected


  1. If you have problem with JRE ( which ) , run this,
    readlink -f $(which java)

  2. Add certificates to Confluence runtime
    /opt/atlassian/confluence/jre/lib/security/cacert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment