10

I am on a fresh install of Ubuntu having just installed OpenJDK:

OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode) on Ubuntu 64 bit 10.10

Not sure if this is relevant, but I'm running it from within VMWare Fusion.

The following line:

javax.net.SSLContext.getDefault(); // same as getInstance("Default")

throws the following exception:

java.net.SocketException: java.security.NoSuchAlgorithmException: Default SSLContext not available

My colleagues and I have tried this on several machines, all fresh installs of Ubuntu, and keep getting this. I was advised to try getInstance("TLSv1"), but this threw the same error. Seems like something really fundamental to not be working so I figure we must be doing something wrong.

2 Answers 2

6

guido's answer pointed me in the right direction. It's just a matter of doing:

sudo apt-get install libbcprov-java
Sign up to request clarification or add additional context in comments.

Comments

2

openjdk shipped with ubuntu may be missing a JCE provider; download the bouncycastle crypto api from http://www.bouncycastle.org/ (its an open source project implementing JCE) and put it in your project classpath.

Then in your class refer to the following sample code:

static {
    Security.addProvider( new BouncyCastleProvider() );
}

public SSLSocket getSSLSocket() {

    // Load the Keystore
    KeyStore ks = KeyStore.getInstance(keystoreType);
    ks.load(new FileInputStream(this.keyStorePath),this.keyStorePass.toCharArray());

    // Get a KeyManager and initialize it 
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
    kmf.init(ks, this.keyStorePass.toCharArray());

    // Get a TrustManagerFactory and init with KeyStore
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509");
    tmf.init(ks);

    // Get the SSLContext to help create SSLSocketFactory
    SSLContext sslc = SSLContext.getInstance("TLS");
    sslc.init(kmf.getKeyManagers(), null, null);

    // Get SSLSocketFactory and get a SSLSocket
    SSLSocketFactory sslsf = sslc.getSocketFactory();
    SSLSocket socket = (SSLSocket) sslsf.createSocket(host, port);
    return socket;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.