Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - SSL Not Trusted Server Certificate

SSL Not Trusted Server Certificate

Put your problem here if it does not fit any of the other categories.

SSL Not Trusted Server Certificate

Postby timweicker » Fri Jun 26, 2009 7:19 pm

Hi Guys,

im having a really big problem. I m currently working on a project for a startup company. They have a api to their database. Unfortunately it does work on the android programm because it uses a certificate which is not verisigned. So there is this Exception "Not trusted Server Certificate". I tried to switch the Certificate Trusting off in the Android Default Settings but apparrently there is not such a function. So i tried to find a way to use this certificate anyway by overwriting the SSL classes. I read several tutorials but they all dont work at all. This is my Code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         String help = "https://dev.dellaware.com/api/verifyCredentials.xml?key=abc";
  2.  
  3.  
  4.  
  5.                         Authenticator.setDefault(new Authenticator() {
  6.  
  7.                             protected PasswordAuthentication getPasswordAuthentication() {
  8.  
  9.                                 return new PasswordAuthentication ("testuser12", "asdfasdf12".toCharArray());
  10.  
  11.                             }
  12.  
  13.                         });
  14.  
  15.        
  16.  
  17.  
  18.  
  19.                        
  20.  
  21.                         //////
  22.  
  23.                        
  24.  
  25.                     // Create a trust manager that does not validate certificate chains
  26.  
  27.                     TrustManager[] trustAllCerts = new TrustManager[]{
  28.  
  29.                         new X509TrustManager() {
  30.  
  31.                             public java.security.cert.X509Certificate[] getAcceptedIssuers() {
  32.  
  33.                                 return null;
  34.  
  35.                             }
  36.  
  37.                             public void checkClientTrusted(
  38.  
  39.                                 java.security.cert.X509Certificate[] certs, String authType) {
  40.  
  41.                             }
  42.  
  43.                             public void checkServerTrusted(
  44.  
  45.                                 java.security.cert.X509Certificate[] certs, String authType) {
  46.  
  47.                             }
  48.  
  49.                         }
  50.  
  51.                     };
  52.  
  53.                    
  54.  
  55.                     // Install the all-trusting trust manager
  56.  
  57.                     try {
  58.  
  59.                         SSLContext sc = SSLContext.getInstance("SSL");
  60.  
  61.                         sc.init(null, trustAllCerts, new java.security.SecureRandom());
  62.  
  63.                         HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
  64.  
  65.                     } catch (Exception e) {
  66.  
  67.                     }
  68.  
  69.                    
  70.  
  71.                    
  72.  
  73.                     try{
  74.  
  75.                         //Remplace le vérifieur de nom d'hôte par un autre moins restrictif
  76.  
  77.                         HostnameVerifier hostnameVerifier=new HostnameVerifier(){
  78.  
  79.                             public boolean verify(String urlHostName,SSLSession session){
  80.  
  81.                                 return true;
  82.  
  83.                             }
  84.  
  85.                         };
  86.  
  87.                         HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
  88.  
  89.                        
  90.  
  91.                         //Remplace le vérifieur de certificat par un autre moins restrictif
  92.  
  93.                         TrustManager[] trustAllCerts1=new TrustManager[]{
  94.  
  95.                             new X509TrustManager(){
  96.  
  97.                                 public java.security.cert.X509Certificate[] getAcceptedIssuers(){return null;}
  98.  
  99.                                 public void checkClientTrusted(java.security.cert.X509Certificate[] certs,String authType){}
  100.  
  101.                                 public void checkServerTrusted(java.security.cert.X509Certificate[] certs,String authType){}
  102.  
  103.                             }
  104.  
  105.                         };
  106.  
  107.                         SSLContext sslContext=SSLContext.getInstance("SSL");
  108.  
  109.                         sslContext.init(null,trustAllCerts1,new java.security.SecureRandom());
  110.  
  111.                         HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());            
  112.  
  113.                      
  114.  
  115.                        
  116.  
  117.                         //Chargement de la page...
  118.  
  119.                         URLConnection conn=new URL(help).openConnection();
  120.  
  121.                         BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
  122.  
  123.                         do{
  124.  
  125.                             String ligne=br.readLine();
  126.  
  127.                             if(ligne==null)break;
  128.  
  129.                             System.out.println(ligne);
  130.  
  131.                         }while(true);
  132.  
  133.                        
  134.  
  135.                     }catch(Exception ex){
  136.  
  137.                         System.err.println(ex);
  138.  
  139.                     }
  140.  
  141.                    
  142.  
  143.                    
  144.  
  145.                     try {
  146.  
  147.                         // Create the client socket
  148.  
  149.                         int port = 80;
  150.  
  151.                         String hostname = "http://test.gloveler.com/de/login";
  152.  
  153.                         SSLSocketFactory factory = HttpsURLConnection.getDefaultSSLSocketFactory();
  154.  
  155.                         SSLSocket socket = (SSLSocket)factory.createSocket(hostname, port);
  156.  
  157.                    
  158.  
  159.                         // Connect to the server
  160.  
  161.                         socket.startHandshake();
  162.  
  163.                    
  164.  
  165.                         // Retrieve the server's certificate chain
  166.  
  167.                         java.security.cert.Certificate[] serverCerts =
  168.  
  169.                             socket.getSession().getPeerCertificates();
  170.  
  171.                    
  172.  
  173.                         // Close the socket
  174.  
  175.                         socket.close();
  176.  
  177.                     } catch (SSLPeerUnverifiedException e) {
  178.  
  179.                     } catch (IOException e) {
  180.  
  181.                     }
  182.  
  183.                        
  184.  
  185.                        
  186.  
  187.                         //////
  188.  
  189.                        
  190.  
  191.                        
  192.  
  193.                         URL url = new URL(help);
Parsed in 0.020 seconds, using GeSHi 1.0.8.4


You see that i tried several methods but the all dont work. If somebody can help me, i would be really grateful.
timweicker
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Jun 10, 2009 7:55 pm

Top

Postby padde » Fri Jun 26, 2009 11:21 pm

padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby timweicker » Wed Jul 01, 2009 6:11 pm

thanks a lot^^ it finally works now
timweicker
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Jun 10, 2009 7:55 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 11 guests