1 Reply Latest reply on Feb 6, 2009 5:38 AM by 843851

    Help Client Authentification SSL

      Hi everybody,
      First excuse me for my English because it is not my natural language.

      Mi problem is that I am trying to create an SSL communication with client authentication, PC is the server and STB is the client, if I didn't put this sentence in the server "sslServerSocket.setNeedClientAuth(true);" the comunication is OK, but in the moment that I include this line the server return me an error saying "null cert chain", Anyone know why?

      This is my code

      MHP client code
      try {
                     SSLSocketFactory sslsocketfactory = null;
                     SSLContext ctx;
      KeyManagerFactory kmf;
      TrustManagerFactory tmf;
      KeyStore ks;
      char[] passphrase = "importkey".toCharArray();
      try {
       ctx = SSLContext.getInstance("TLS");
             kmf = DVBKeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
             tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
             ks = KeyStore.getInstance("JKS");
             ks.load(new FileInputStream("./data/keystore"), passphrase);
             kmf.init(ks, passphrase);
       sslsocketfactory = ctx.getSocketFactory();
             KeyManager[] key = kmf.getKeyManagers();
             for(int i=0;i<key.length;i++)
           Enumeration enumeration = ks.aliases();
                          while (enumeration.hasMoreElements()) {

                          String alias = enumeration.nextElement().toString();
                          java.security.cert.Certificate[] certs = ks.getCertificateChain( alias );
      } catch (Exception e) {

      throw new IOException(e.getMessage());


      SSLSocket sslSocket = (SSLSocket)sslsocketfactory.createSocket(this.TLS_SERVER_IP,this.TLS_SERVER_PORT);

           System.out.println("Certificate the server&keystore:Before the getSession");
                     SSLSession session=sslSocket.getSession();
                     System.out.println("Chiper used: "+session.getCipherSuite());
                     // Create an OutputStream

                               System.out.println("Before ObjectOutputStream y ObjectInputStream");
                               ObjectOutputStream out = null;
                               out = new ObjectOutputStream(sslSocket.getOutputStream());
                     ObjectInputStream stdIn = null;
                     stdIn = new ObjectInputStream(sslSocket.getInputStream());
                     //Envio del Objeto
                          Resultado r = new Resultado();
                          r.setError("come on sdor");
                          logger.info("Before send Obj.");
                          logger.info("Before read Obj. Result");
                          Resultado obj= (Resultado)stdIn.readObject();
                          System.out.println("Objet arrived :"+obj.getError());
                                    // Closing the Streams and the Socket
                }catch (Exception e) {
                     System.out.println("Exception occured: " +e);
      *SSL Server*
      System.setProperty("javax.net.ssl.keyStore", "C://keystore");
      System.setProperty("javax.net.ssl.keyStorePassword", "importkey");
      System.setProperty("javax.net.ssl.trustStore", "C://keystore");     
      System.setProperty("javax.net.ssl.trustStorePassword", "importkey");

      SSLServerSocketFactory sslServerSocketFactory =
           (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();

      SSLServerSocket sslServerSocket =
      (SSLServerSocket) sslServerSocketFactory.createServerSocket(serverPort);


      SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();

      String[] enumeration = sslSocket.getEnabledCipherSuites();
                     for(int i=0;i<enumeration.length;i++)
                          logger.info("cipher exis "+enumeration[i]);
                     enumeration = sslSocket.getSupportedCipherSuites();
                     for(int i=0;i<enumeration.length;i++)
                          logger.info("cipher supor "+enumeration[i]);
                     enumeration = sslSocket.getSupportedProtocols();
                     for(int i=0;i<enumeration.length;i++)
                          logger.info("protocol supor "+enumeration[i]);

      ObjectOutputStream out = new ObjectOutputStream(sslSocket.getOutputStream());
      ObjectInputStream in = new ObjectInputStream(sslSocket.getInputStream());

      if (null != in && null != out){
                System.out.println("Somethig has arrived!!");
                System.out.println("I'm going to send something!!");

      } catch (IOException ioe) {
      logger.info("Secure Server End");
      Thanks in advance for your help.
      P.D: I'm using MHP 1.1.2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
        • 1. Re: Help Client Authentification SSL
          Hello, Before I review your code snippet in details, let me share.
          In SSL communication, server authentication is default operation
          achieved before any secure channel is opened between a client and a server.
          It means before you "setNeedClientAuth(true)" server authentication was carried out, maybe you didn't noticed.

          But once you require client authentication also by your calling "setNeedClientAuth(true)" which is optional operation,
          you need certification chain also in STB. You seems already have certification chain in PC but not in STB now.

          I hope this helps you.