TealessSSLContextBuilder { public void setCipherSuites(String[] cipherSuites) throws IllegalArgumentException { final SSLEngine sslEngine = defaultContext.createSSLEngine(); for (String cipherSuite : cipherSuites) { if (!isValidCipherSuite(cipherSuite)) { try { sslEngine.setEnabledCipherSuites(new String[]{"TLS_RSA_WITH_AES_256_CBC_SHA256"}); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Unsupported ciphersuite " + cipherSuite)) { throw new IllegalArgumentException(e.getMessage() + ". Supported cipher suites are: " + Arrays.asList(defaultContext.getSupportedSSLParameters().getCipherSuites())); } else if (e.getMessage().equals("Cannot support " + cipherSuite + " with currently installed providers")) { if (System.getProperty("java.runtime.name").equals(ORACLE_JVM_RUNTIME_NAME)) { throw new IllegalArgumentException(e.getMessage() + ". This probably means you need to install the Oracle Java Cryptography Extension Unlimited Strength Cryptographic Policy. Supported cipher suites are: " + Arrays.asList(defaultContext.getSupportedSSLParameters().getCipherSuites())); } else { throw new IllegalArgumentException(e.getMessage() + ". Supported cipher suites are: " + Arrays.asList(defaultContext.getSupportedSSLParameters().getCipherSuites())); } } } throw new IllegalArgumentException("The cipher suite '" + cipherSuite + "' is not supported. Supported cipher suites are: " + Arrays.asList(defaultContext.getSupportedSSLParameters().getCipherSuites())); } } this.cipherSuites = cipherSuites; }  void setTracker(SSLCertificateVerificationTracker tracker); KeyStore getTrustStore(); void setTrustStore(KeyStore trustStore); SSLContext build(); void setKeyManagerFactory(KeyManagerFactory keyManagerFactory); void setCipherSuites(String[] cipherSuites); void setProtocols(String[] protocols);  }
@Test void setCipherSuitesWithInvalidCipherSuite() { assertThrows(IllegalArgumentException.class, () -> builder.setCipherSuites(new String[]{"foo"})); }
@Test void setCipherSuitesWithValidCipherSuite() { builder.setCipherSuites(new String[]{"TLS_RSA_WITH_AES_128_CBC_SHA256"}); }
@Test void setCipherSuitesThatMayRequireJCEUnlimitedStrengthCrypto() throws NoSuchAlgorithmException { String aes256suite = "TLS_RSA_WITH_AES_256_CBC_SHA256"; SSLContext context = SSLContext.getDefault(); List<String> supportedCiphers = Arrays.asList(context.getSupportedSSLParameters().getCipherSuites()); assumeFalse(supportedCiphers.contains(aes256suite)); try { builder.setCipherSuites(new String[]{aes256suite}); fail("setCipherSuites([" + aes256suite + "]) should fail when it is not in the supported ciphers list."); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), CoreMatchers.containsString("Java Cryptography Extension")); } }