Here is the way to go.. I have solved the problem using the below method. See java.net.ssl.* documentation for better idea.
1. Create a class which implements HostnameVerifier and override the method verify() such a way it always returns true; 2. Create a class which implements X509TrustManager and override the following method getAcceptedIssuers() returns a empty array and remaining leave.. 3. Implement the method TrustAllHosts() which install all trusting hostnames HttpsURLConnection.setDefaultHostnameVerifier(yourhostnameverifier --> From step1 ) 4. Implement the method TrustAllCertificates() where do the following i. get an instance of Trustmanger --> From step2 ii. Get an SSLContext instalnce say SSLContext context = SSLContext.getInstance("TLS") - Ref API Documentation iii. init the context with your trustmanger got from (i) ( context.init(null,myTrustmangers, new SecureRandom()); iv. Set the SSLSocketFactory ( HttpsURLConnection.setDefaultSSLSocketFactory(context. getSocketFactory());) In your main code ( where you use URL) you can simply call TrustAllHosts() and TrustAllCertificates() and then do the URL fetching.. related stuff. Have a fun. Best regards, Bala On Jan 8, 3:51 pm, AnuR <anura...@gmail.com> wrote: > I was not able to fix the error the error is still there. > > I tried to disable the cretificate verification using the code > > from :http://www.exampledepot.com/egs/javax.net.ssl/TrustAll.html? > l=rel > > // Create a trust manager that does not validate certificate chains > TrustManager[] trustAllCerts = new TrustManager[]{ > new X509TrustManager() { > public java.security.cert.X509Certificate[] > getAcceptedIssuers() { > return null; > } > public void checkClientTrusted( > java.security.cert.X509Certificate[] certs, String > authType) { > } > public void checkServerTrusted( > java.security.cert.X509Certificate[] certs, String > authType) { > } > } > }; > > // Install the all-trusting trust manager > try { > SSLContext sc = SSLContext.getInstance("SSL"); > sc.init(null, trustAllCerts, new java.security.SecureRandom > ()); > HttpsURLConnection.setDefaultSSLSocketFactory > (sc.getSocketFactory()); > } catch (Exception e) { > } > > // Now you can access an https URL without having the certificate > in the truststore > try { > URL url = new URL("https://hostname/index.html"); > } catch (MalformedURLException e) { > } > and also tried to retrive the cretificate > form the help available from the > sitehttp://www.exampledepot.com/egs/javax.net.ssl/GetCert.html?l=rel > > try { > // Create the client socket > int port = 443; > String hostname = "hostname"; > SSLSocketFactory factory = > HttpsURLConnection.getDefaultSSLSocketFactory(); > SSLSocket socket = (SSLSocket)factory.createSocket(hostname, > port); > > // Connect to the server > socket.startHandshake(); > > // Retrieve the server's certificate chain > java.security.cert.Certificate[] serverCerts = > socket.getSession().getPeerCertificates(); > > // Close the socket > socket.close(); > } catch (SSLPeerUnverifiedException e) { > } catch (IOException e) { > } > > but noe of then helped me..... > > please help to fix this issue... > > thanks and regards > ANUR > > On Nov 21 2008, 1:30 am, Anders Rundgren <anders.rundg...@telia.com> > wrote: > > > Are you using a commercial SSL cert vendor like VeriSign. > > If not you need to either disable certficate validation or install the > > trust anchor of the SSL cert. I don't have the G1 som I only know how > > to do it on the emulator. It wasn't easy BTW since Android does not > > use the standard SUN format but a BouncyCastle variant. I did a > > converter since I have so many stores in SUN > > format:http://groups.google.com/group/android-developers/browse_thread/threa... > > > Anders > > > On Nov 20, 11:13 am, AnuR <anura...@gmail.com> wrote: > > > > Hi, > > > > While I am trying to post a web page using > > > > DefaultHttpClient httpclient = new DefaultHttpClient(); > > > CookieStore cookies = httpclient.getCookieStore(); > > > HttpPost Postmethod = new HttpPost("https://urltopost");// Submiting > > > I agree page > > > ArrayList<BasicNameValuePair> nvpairs = new ArrayList(); > > > vpairs.add(new BasicNameValuePair("name1", "value1")); > > > nvpairs.add(new BasicNameValuePair("name2", "value2")); > > > nvpairs.add(new BasicNameValuePair("name3", "value3")); > > > httpclient.setCookieStore(cookies); > > > UrlEncodedFormEntity p_entityIAgree = new UrlEncodedFormEntity > > > (nvpairs); > > > Postmethod .setEntity(new UrlEncodedFormEntity(nvpairs, HTTP.UTF_8)); > > > Postmethod .setEntity(p_entityIAgree); > > > ResponseHandler<String> IAgreeresponseHandler = new > > > BasicResponseHandler(); > > > > String IAgreeSubmitresponseBody = httpclient.execute(Postmethod , > > > IAgreeresponseHandler); > > > > I am getting an error > > > > 11-20 12:36:22.589: WARN/System.err(366): javax.net.ssl.SSLException: > > > Not trusted server certificate. > > > > why is it caused ? how Can i solve it? > > > _________________ > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---