Javamail java.security.cert.CertPathValidatorException when receiving mail from pop3

564 views Asked by At

So I'm trying to build an Android app that cheks email from my university's server. It works fine with Gmail. I added the certificate (.cer file) to keystore, I tried with the following properties:

        Properties properties = new Properties();
        properties.put("mail.store.protocol", "pop3");
        properties.put("mail.pop3.host", pop3Host);
        properties.put("mail.pop3.port", "995");
        properties.put("mail.pop3.starttls.enable", "true");
        properties.put("mail.pop3.ssl.checkserveridentity", "false");
        properties.put("mail.pop3.ssl.trust", "*");
        Session emailSession = Session.getDefaultInstance(properties);  

...and nothing :(

DEBUG:

stefan.studmail I/System.out﹕ DEBUG: setDebug: JavaMail version 1.5.3
stefan.studmail I/System.out﹕ DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle]
stefan.studmail W/art﹕ Before Android 4.1, method javax.mail.Session com.sun.mail.pop3.POP3Store.getSession() would have incorrectly overridden the package-private method in javax.mail.Service
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.rsetbeforequit: false
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.disabletop: false
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.forgettopheaders: false
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.cachewriteto: false
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.filecache.enable: false
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.keepmessagecontent: false
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.starttls.enable: false
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.starttls.required: false
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.apop.enable: false
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.disablecapa: false
stefan.studmail I/System.out﹕ DEBUG POP3: connecting to host "stud.usv.ro", port 995, isSSL true
stefan.studmail I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@37e721f4 time:14882263
stefan.studmail E/StudMail:﹕ Connect failed
stefan.studmail W/System.err﹕ javax.mail.MessagingException: Connect failed;
stefan.studmail W/System.err﹕ nested exception is:
stefan.studmail W/System.err﹕ javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
stefan.studmail W/System.err﹕ at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:213)
stefan.studmail W/System.err﹕ at javax.mail.Service.connect(Service.java:364)
stefan.studmail W/System.err﹕ at javax.mail.Service.connect(Service.java:245)
stefan.studmail W/System.err﹕ at senegeac.stefan.studmail.FetchPop.fetch(FetchPop.java:75)
stefan.studmail W/System.err﹕ at senegeac.stefan.studmail.FetchPop.doInBackground(FetchPop.java:145)
stefan.studmail W/System.err﹕ at senegeac.stefan.studmail.FetchPop.doInBackground(FetchPop.java:39)
stefan.studmail W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:297)
stefan.studmail W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
stefan.studmail W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
stefan.studmail W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
stefan.studmail W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
stefan.studmail W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
stefan.studmail W/System.err﹕ Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:306)
stefan.studmail W/System.err﹕ at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:574)
stefan.studmail W/System.err﹕ at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:369)
stefan.studmail W/System.err﹕ at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)
stefan.studmail W/System.err﹕ at com.sun.mail.pop3.Protocol.<init>(Protocol.java:112)
stefan.studmail W/System.err﹕ at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:264)
stefan.studmail W/System.err﹕ at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:207)
stefan.studmail W/System.err﹕ ... 11 more
stefan.studmail W/System.err﹕ Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:323)
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:224)
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:113)
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:525)
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302)
stefan.studmail W/System.err﹕ ... 17 more
stefan.studmail W/System.err﹕ Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
stefan.studmail W/System.err﹕ ... 23 more
1

There are 1 answers

2
Bill Shannon On

Try using Session.getInstance.

If that doesn't help, post the debug output.