2013-07-16 2 views
0

SSL을 사용하는 LDAP 서버에 연결하려고합니다. 나는 인증을 사용하고 싶지 않아 모든 사이트를 허용하기 위해 SSLSocketFactory를 재정의했다. 나는 오류가 다음 무엇입니까 :SSL LDAP 조회가 handshake_failure를 사용하여 실패합니다.

main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: **handshake_failure** 
    javax.naming.CommunicationException: slc00ahj.us.oracle.com:3131 Root exception is javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 

at com.sun.jndi.ldap.Connection.<init>(Connection.java:209) 
at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:116) 
at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1582) 
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2678) 
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:296) 
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175) 
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193) 
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136) 
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66) 
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667) 
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) 
at javax.naming.InitialContext.init(InitialContext.java:223) 
at javax.naming.InitialContext.<init>(InitialContext.java:197) 
at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:82) 
at SumanLdapTest1.main(SumanLdapTest1.java:37) 

SSL 로그는 다음과 같습니다

Allow unsafe renegotiation: false 
    Allow legacy hello messages: true 
    Is initial handshake: true 
    Is secure renegotiation: false 
    main, setSoTimeout(120) called 
    %% No cached client session 
    ClientHello, TLSv1 
    RandomCookie: GMT: 1357201614 bytes = { 70, 133, 164, 224, 89, 101, 204, 41, 107, 201, 176, 66, 93, 118, 139, 59, 50, 176, 84, 197, 238, 236, 187, 211, 158, 43, 159, 112 } 
    Session ID: {} 
    Cipher Suites: SSL_RSA_WITH_RC4_128_MD5, SSL_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_DES_CBC_SHA, SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV 
    Compression Methods: { 0 } 
    *** 
    **main, WRITE: TLSv1 Handshake, length = 75 
    main, READ: TLSv1 Alert, length = 2 
    main, RECV TLSv1 ALERT: fatal, handshake_failure 
    main, called closeSocket()** 




**My source code:** 





    public class **SumanLdapTest1**{ 
     public static void main(String args[]){ 
     try{ 
       //System.setProperty("ldaps.protocols", "TLSv1"); 
       System.out.println("here"); 
       DirContext ctx = null; 
      String host="slc00ahj.us.oracle.com"; 
      String port="3131"; 
      String userName="cn=orcladmin"; 
      String password="welcome1"; 
      Hashtable<String, String> env = new Hashtable<String, String>(); 
      env.put(Context.INITIAL_CONTEXT_FACTORY, 
          "com.sun.jndi.ldap.LdapCtxFactory"); 
      //env.put(Context.PROVIDER_URL, "ldap://" + host + ":"+ port+ "/"); 
      env.put(Context.SECURITY_PRINCIPAL, userName); 
      env.put(Context.SECURITY_CREDENTIALS, password); 
      env.put(Context.SECURITY_AUTHENTICATION, "simple"); 
      env.put("com.sun.jndi.ldap.connect.timeout", "120"); 
      env.put(Context.PROVIDER_URL, "ldaps://" + host 
          + ":" + port); 
      env.put(Context.SECURITY_PROTOCOL, "ssl"); 
      env.put("java.naming.ldap.factory.socket","**SumanSSLFactory**"); 
      ctx = new InitialDirContext(env); 
      }catch(Exception e){ 
       e.printStackTrace(); 
      } 
     } 
    } 

    public class SumanSSLFactory extends SSLSocketFactory { 
      private SSLSocketFactory factory = null; 
     private Exception exception = null; 

     public SumanSSLFactory() { 
      System.out.println("LdapSSLFactory initialization started..."); 


      try { 
       this.factory = **getSSLSocketFactory**(); 
      } catch (Exception ex) { 
          ex.printStackTrace(); 
       System.out.println("LDAPSSLFactory Initialization error"); 
       this.factory = null; 
       this.exception = ex; 
      } 

      System.out.println("LdapSSLFactory Initialization completed."); 
     } 

     public SSLSocket createSocket() throws IOException { 
      System.out.println("LdapSSLFactory.createSocket()"); 
      if (this.factory == null) 
       throw new IOException(); 
      SSLSocket st=null; 
      try{ 


        (new Throwable()).printStackTrace(); 
        st=(SSLSocket)this.factory.createSocket(); 
        st.setEnabledProtocols(new String[] { "TLSv1", "SSLv3" }); 

         }catch(Exception e){ 
          e.printStackTrace(); 
         } 

      return st; 
     } 


     private SSLSocketFactory **getSSLSocketFactory**() 
         { 
       SSLSocketFactory sslSocketFactory = null; 
       System.out.println("Using Non Authenticated SSL Mechanism."); 
       try { 
         TrustManager[] tmA = { new X509TrustManager() { 
           public X509Certificate[] getAcceptedIssuers() { 
             X509Certificate[] issuers = new X509Certificate[0]; 
             return issuers; 
            //return null; 
           } 

           public void checkClientTrusted(X509Certificate[] chain, 
               String authType) throws CertificateException { 
           } 

           public void checkServerTrusted(X509Certificate[] chain, 
               String authType) throws CertificateException { 
           } 
         } }; 

         // get the SSLContext and factory 
         SSLContext ctx = SSLContext.getInstance("TLS"); 
         ctx.init(null, tmA, null); 
         sslSocketFactory = ctx.getSocketFactory(); 
        // System.setProperty("ldaps.protocols", "TLSv1"); 
        System.out.println("SSOSocketUtil factory created sslSocketFactory"+sslSocketFactory); 
       } catch (Exception ex) { 
        ex.printStackTrace(); 
        System.out.println("SSOSocketUtil factory exception"); 

       } 

       return sslSocketFactory; 
     } 

    } 

Any help on this will be appreciated  

답변

2

나는 우선 코드를 사용하지 않고 테스트하는 것입니다. 예를 들어, LDAP Utils 바이너리 중 하나 (예 : ldapsearch, ldapwhoami 등)를 사용하여 일종의 SSL 작업을 테스트 해보십시오. SSL/TLS가 그렇게 작동하는지 확인하십시오.

작동하지 않는 경우 로컬 시스템 LDAP 설정을 확인하고 서버에서 사용중인 인증서가 만료되지 않고 자체 서명되지 않았 음을 확인하십시오 (자체 서명 된 인증서를 허용하지만 추가 구성이 필요함) .

또한 서버가 LDAP가 아닌 LDAPS를 통해 특수 포트 (3131?)에서 수신 대기하는지 확인하십시오. 리스너에 일반 LDAP가 사용되는 경우 SSL은 지원되지 않지만 TLS (StartTLS)는 지원됩니다. LDAP SSL은 기술적으로 TLS에 찬성하여 사용되지 않습니다. SSL 대신 TLS를 사용할 수있는 능력이 있어야합니다.

마지막으로 서버 측에서 RootDSE에 TLS/SSL 지원 (1.3.6.1.4.1.1466.20037)의 OID가 표시되는지 확인하십시오. 이 부분이 보이지 않으면 SSL/TLS가 서버에서 지원되지 않습니다 (최소한 OpenLDAP에서는 마찬가지입니다).

명령 줄 이진 테스트가 작동하면 코드 자체 또는 코드가 실행되는 호스트의 시스템 LDAP 설정을 가정해야합니다. 아니면 둘다.

저는 Java로 숙련 된 사람이 아니지만 어쨌든 코드를 살펴본 결과 명백하게 잘못된 것을 보지 못했습니다. 코드 자체에 직접적인 문제가있는 경우, 나는 틀린 사람입니다. =)

코드를 수정할 수 없다면 코드를 변경하여 SSL/TLS를 사용하지 않도록하십시오. 적어도 보안 전송이 아닌 코드의 의도 된 기능이 작동하는지 확인할 수 있습니다. 그것은 최소한 그것을 상당히 좁혔습니다. 물론 이러한 유형의 테스트에 대한 보안 문제가있는 경우 특수한 조치를 취해야합니다 (예 : stunnel을 사용하거나 LDAP 서버에서 로컬로 스크립트를 실행하는 등). 난이 도움이되기를 바랍니다

...

최대

관련 문제