Home  >  Article  >  Java  >  Why am I receiving an \"SSLHandshakeException: no cipher suites in common\" when using an SSLServerSocket?

Why am I receiving an \"SSLHandshakeException: no cipher suites in common\" when using an SSLServerSocket?

DDD
DDDOriginal
2024-11-03 17:14:30295browse

Why am I receiving an

Java SSLHandshakeException "no cipher suites in common"

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:

  1. Load the keystore containing your certificates:
KeyStore ks = KeyStore.getInstance("JKS");
InputStream ksIs = new FileInputStream("...");
ks.load(ksIs, "password".toCharArray());
  1. Initialize a KeyManagerFactory with the keystore:
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, "keypassword".toCharArray());
  1. Update the SSLContext initialization to use the KeyManagers:
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn