Https problem: Trust anchor for certification path not found

Hi! When I trying to use https requests it failed with “java.security.cert.CertPathValidatorException: Trust anchor for certification path not found”


How can I fix that?
jvm, android, robovm, gwt work well with that server (and we use same http-related code for all that platforms).

Hi Zufar,

do you have the SSL certificates included in your project like in the RssReader sample?

Best Regards,
Gergely

How I can get that certificates? Should I just copy files from example to my project magic dir “android_root/etc/security/cacerts”?

For now, yes.

I created an issue for this on GitHub, so it will be included in the SDK by default.

Is it fixed? I see milestone 1.2.3 but issue state is open.

Dear zufarfakhurtdinov,

we had to postpone it to MOE 1.3.0 because it required more changes than we anticipated.

Hi,
i have same problem with android studio 2.2 (mac)
I copied the certificate files (from rss reaader example) to my folder my myproject/ios/src/main/resources/android_root/etc/security/cacerts but i have that exception.
What am i forgetting ?

Thanks

Dear friends,

i implement all service’s by using retrofit library for this issue.
how ever i have not any problem.

test it ->

public class ServiceGeneratorCollege {

    public static String PREF_COOKIES = "pref_cookies";

    private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

    private static Retrofit.Builder builder;

    public static <S> S createService(Class<S> serviceClass) {
        return createService(serviceClass, null);
    }

    public static <S> S createService(Class<S> serviceClass, final HashMap<String, String> headers) {

        builder = new Retrofit.Builder()
                .baseUrl("your service address")
                .addConverterFactory(GsonConverterFactory.create());

        httpClient.sslSocketFactory(getSSLSocketFactory());
        httpClient.hostnameVerifier(new HostnameVerifier() {

            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });

        OkHttpClient client = httpClient.build();
        Retrofit retrofit = builder.client(client).build();
        return retrofit.create(serviceClass);
    }

    private static SSLSocketFactory getSSLSocketFactory() {
        try {
            // Create a trust manager that does not validate certificate chains
            final TrustManager[] trustAllCerts = new TrustManager[]{
                    new X509TrustManager() {
                        @Override
                        public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
                        }

                        @Override
                        public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
                        }

                        @Override
                        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                            return new java.security.cert.X509Certificate[]{};
                        }
                    }
            };

            // Install the all-trusting trust manager
            final SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
            // Create an ssl socket factory with our all-trusting manager
            final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

            return sslSocketFactory;
        } catch (KeyManagementException | NoSuchAlgorithmException e) {
            return null;
        }

    }
}
3 Likes

very thanks.
This code solves my problem.

Thanks ! It also worked for me

Thanks. It worked :slight_smile:

someone please tell me where to place this code as I am getting same error in my app.

Thanks, it works absolutely.

Can u send the serviceClass code