title: Specifying an outbound SSL configuration programmatically using JSSEHelper on Websphere 8.0. does not work
body: <p>I am trying to create an SSL connection programmatically using a CUSTOM outbound ssl configuration configured in WAS 8.0.0.13 (IBM Websphere application server that uses java 1.6.0):
  (Security->SSL certificate and key managemement->Related Items:SSL configurations).
  The secure connection has been created successfully:a servlet that resides on the WAS server has connected to a server-side Socket listening on 127.0.0.1:1234.
  The problem is that my preferred cipher suites defined in 'Quality of Protection (QoP) settings' within SSL configuration are ignored.
  All the other properties (such as protocol or JSSE provider) are nicely regarded.</p>
  
  <p>I have implemented a Servlet which was in the role of an SSL-client.
  This Servlet used this custom SSL configuration which had the following cipher suites defined:</p>
  
  <ol>
  <li>SSL_RSA_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_RSA_WITH_AES_128_CBC_SHA      </li>
  <li>SSL_DHE_DSS_WITH_AES_128_CBC_</li>
  <li>SHA SSL_RSA_WITH_AES_128_GCM_SHA256       </li>
  <li>SSL_RSA_WITH_AES_128_CBC_SHA256 </li>
  <li>SSL_DHE_RSA_WITH_AES_128_GCM_SHA256</li>
  <li>SSL_DHE_RSA_WITH_AES_128_CBC_SHA256</li>
  <li>SSL_DHE_DSS_WITH_AES_128_GCM_SHA256   </li>
  <li>SSL_DHE_DSS_WITH_AES_128_CBC_SHA256</li>
  </ol>
  
  <p>Unfortunately, a different list of cipher suites has been provided in ClientHello request:</p>
  
  <ol>
  <li>SSL_RSA_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_RSA_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_DSS_WITH_AES_128_CBC_SHA</li>
  <li>SSL_RSA_WITH_3DES_EDE_CBC_SHA</li>
  <li>SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA</li>
  <li>SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA</li>
  <li>SSL_RSA_WITH_DES_CBC_SHA</li>
  <li>SSL_DHE_RSA_WITH_DES_CBC_SHA</li>
  <li>SSL_DHE_DSS_WITH_DES_CBC_SHA</li>
  <li>SSL_RENEGO_PROTECTION_REQUEST</li>
  </ol>
  
  <p>(This custom SSL configuration contained TLSv1.1 protocol in its definition.)</p>
  
  <p>I have also tried another protocol (TLSv1.2) with a smaller set of cipher suites:</p>
  
  <ol>
  <li>SSL_RSA_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_RSA_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_DSS_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_DSS_WITH_AES_128_CBC_SHA256</li>
  </ol>
  
  <p>Once again, a different list of cipher suites was provided in ClientHello request:</p>
  
  <ol>
  <li>SSL_RSA_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_RSA_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_DSS_WITH_AES_128_CBC_SHA</li>
  <li>SSL_RSA_WITH_3DES_EDE_CBC_SHA</li>
  <li>SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA</li>
  </ol>
  
  <p>Moreover, I have also checked cell-default cipher suites and node-default-cipher-suites and there is no 
  match between them and those provided in the ClientHello:
  Default Node Configuration/Default Cell Configuration:</p>
  
  <ol>
  <li>SSL_RSA_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_RSA_WITH_AES_128_CBC_SHA</li>
  <li>SSL_DHE_DSS_WITH_AES_128_CBC_SHA</li>
  <li>SSL_RSA_WITH_AES_128_GCM_SHA256</li>
  <li>SSL_RSA_WITH_AES_128_CBC_SHA256</li>
  <li>SSL_DHE_RSA_WITH_AES_128_GCM_SHA256</li>
  <li>SSL_DHE_RSA_WITH_AES_128_CBC_SHA256</li>
  <li>SSL_DHE_DSS_WITH_AES_128_GCM_SHA256</li>
  <li>SSL_DHE_DSS_WITH_AES_128_CBC_SHA256</li>
  </ol>
  
  <p>I have followed these instructions:
  <a href="https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.0.0/com.ibm.websphere.nd.doc/info/ae/ae/tsec_ssloutconfiguseJSSE.html" rel="nofollow noreferrer">https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.0.0/com.ibm.websphere.nd.doc/info/ae/ae/tsec_ssloutconfiguseJSSE.html</a></p>
  
  <p>and have created the following implementation. 'doGet' method is an entry point:</p>
  
  <pre><code>public class TLSv1_1 extends HttpServlet {
  private static final long serialVersionUID = 1L;
  com.ibm.websphere.ssl.JSSEHelper jsseHelper;
  
  public TLSv1_1() {
      super();
      jsseHelper = com.ibm.websphere.ssl.JSSEHelper.getInstance();
  }
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
  
      Properties existing_sslProps = null;
      try {
          String existingAlias = "TLSv1.1";
          existing_sslProps = jsseHelper.getProperties(existingAlias);
  
      } catch (com.ibm.websphere.ssl.SSLException e) {
          e.printStackTrace();
      }
      printSSLproperties(response, existing_sslProps);
      SSLSocket socket = getSslSocket(existing_sslProps);
      writeToSocket(socket, 1234);
  }
  
  public static void printSSLproperties(HttpServletResponse response, Properties sslProps) throws IOException {
      if (sslProps != null) {
          StringBuilder sb = new StringBuilder();
          Set set = sslProps.entrySet();
          Iterator it = set.iterator();
          while (it.hasNext()) {
              Map.Entry entry = (Map.Entry) it.next();
              Object value = entry.getValue();
              sb.append("key: " + entry.getKey() + ", value: " + value + "\n");
          }
          System.out.println("sslProps:    -----------\n" + sb.toString());           
      } else {
          System.out.println("sslProps == null");
          response.getWriter().append("sslProps == null");
      }
  }
  
  public SSLSocket getSslSocket(Properties sslProps) {
      Map&lt;String, Object&gt; sslMap = new HashMap&lt;String, Object&gt;();
  
      sslMap.put("com.ibm.ssl.direction", "outbound");
      sslMap.put("com.ibm.ssl.remoteHost", "127.0.0.1");
      sslMap.put("com.ibm.ssl.remotePort", "1234");
      sslMap.put("com.ibm.ssl.endPointName", "HTTP");
      SSLSocketFactory sslSocketFactory = null;
      try {
          sslSocketFactory = jsseHelper.getSSLSocketFactory(sslMap, sslProps);
      } catch (SSLException e) {
          e.printStackTrace();
      }
  
      SSLSocket socket = null;
      try {
          socket = (SSLSocket) sslSocketFactory.createSocket();
      } catch (IOException e) {
          e.printStackTrace();
      }
      return socket;
  }
  
  public static void writeToSocket(Socket socket, int port) throws IOException, UnknownHostException {
  
      InetAddress address = InetAddress.getByName("127.0.0.1");
      socket.connect(new InetSocketAddress(address, port));
      BufferedWriter stream = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
  
      for (int i = 0; i &lt; 3; i++) {
          String lineX = UUID.randomUUID().toString();
          stream.write(lineX);
          stream.newLine();
          stream.flush();
          System.out.println("NEW LINE SUCCESSFULLY WRITTEN INTO SOCKET:" + lineX);
          sleep();
      }
  }
  
  private static void sleep() {
  
      try {
          Thread.sleep(1000 * 30);
      } catch (InterruptedException e) {
  
      }
  } 
  </code></pre>
  
  <p>}</p>
  
  <p>The presence of the hash map sslMap seems to be of no importance.
  It does not matter whether is set to null or contains no values.</p>
  
  <p>I have also tried to enforce ssl properties on thread (this one has the highest preference among all the others):
  This approach also dodn't worked:</p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
  String existingAlias = "TLSv1.1";
  existing_sslProps = jsseHelper.getProperties(existingAlias);
  
  jsseHelper.setSSLPropertiesOnThread(existing_sslProps);
  
  CommonIO.printSSLproperties(response, existing_sslProps);       
  SSLSocket socket = getSslSocket(existing_sslProps);
  CommonIO.writeToSocket(socket, 1234);
  
  jsseHelper.setSSLPropertiesOnThread(null);
  }
  </code></pre>
  
  <p>Finally, I have tried not to bind to any SSL configuration present in WAS server SSL configs, but only wire up a custom configuration with my java code:</p>
  
  <pre><code>sslProps.setProperty("com.ibm.ssl.protocol", "TLSv1.1");
      sslProps.setProperty("com.ibm.ssl.enabledCipherSuites",
              "SSL_DHE_DSS_WITH_AES_128_CBC_SHA SSL_DHE_DSS_WITH_AES_128_GCM_SHA256 SSL_DHE_DSS_WITH_AES_128_CBC_SHA256");
      sslProps.setProperty("com.ibm.ssl.trustStore",
              "/opt/IBM/Websphere/profiles/AppSrv01/config/cells/localhostCell01/nodes/localhostNode01/trust.p12");
      sslProps.setProperty("com.ibm.ssl.trustStorePassword", "***");
      sslProps.setProperty("com.ibm.ssl.trustStoreType", "PKCS12");
      sslProps.setProperty("com.ibm.ssl.keyStore",
              "/opt/IBM/Websphere/profiles/AppSrv01/config/cells/localhostCell01/key.p12");
      sslProps.setProperty("com.ibm.ssl.keyStorePassword", "***");
      sslProps.setProperty("com.ibm.ssl.keyStoreType", "PKCS12");
  
      sslProps.setProperty("security.provider.1", "com.ibm.jsse2.IBMJSSEProvider2");
      sslProps.setProperty("ssl.SocketFactory.provider", "com.ibm.jsse2.SSLSocketFactoryImpl");
  </code></pre>
  
  <p>But this approach also did not work.
  Could you please help me? I suppose I missed something principal or custom SSL configuration does not exist in this product.</p>