Home >Java >javaTutorial >Why am I receiving an \'SSLHandshakeException: no cipher suites in common\' when using an SSLServerSocket?
Question:
I am unable to establish SSL connections using an SSLServerSocket. Despite enabling all possible cipher suites and protocols, I receive an SSLHandshakeException stating "no cipher suites in common."
Answer:
The issue lies in the initialization of the SSLContext. Providing a null KeyManager array results in an empty KeyManager that lacks RSA or DSA certificates. This disallows the use of default cipher suites that rely on these certificates and ultimately leads to the error. To fix this:
KeyStore ks = KeyStore.getInstance("JKS"); InputStream ksIs = new FileInputStream("..."); ks.load(ksIs, "password".toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(ks, "keypassword".toCharArray());
SSLContext sc = SSLContext.getInstance("TLSv1.2"); sc.init(kmf.getKeyManagers(), null, new SecureRandom());
The above is the detailed content of Why am I receiving an \'SSLHandshakeException: no cipher suites in common\' when using an SSLServerSocket?. For more information, please follow other related articles on the PHP Chinese website!