Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework WebDavSocketFactory to use DefaultTrustedSocketFactory #1182

Closed
wants to merge 6 commits into from
Closed

Rework WebDavSocketFactory to use DefaultTrustedSocketFactory #1182

wants to merge 6 commits into from

Conversation

philipwhiuk
Copy link
Contributor

Here we go. I've unpicked the chaos, documented the odd behaviour and reverted the change I made for the reasons I've documented.

I've moved to using the DefaultTrustedSocketFactory directly, which means it's less prone to error. I've also added tests for the expected behaviour.

@philipwhiuk philipwhiuk changed the title SSL Rework Rework WebDavSocketFactory to use DefaultTrustedSocketFactory Mar 15, 2016
@cketti
Copy link
Member

cketti commented Mar 29, 2016

It's probably better than what we currently have. But I'm not too happy with this. Using SSLSocketFactory in WebDavSocketFactory is an accident waiting to happen.

I made some adjustments here: https://github.com/k9mail/k-9/tree/WebDavSocketFactory_rewrite
Can you please check if the modified code works with a real server?

PS: In the long term I want us moving away from the Apache HTTP API to OkHttp.

@philipwhiuk
Copy link
Contributor Author

Yep sure I'll pull the branch and let you know.

@philipwhiuk
Copy link
Contributor Author

After I fixed a NPE caused by not setting the trusted socket factory (a bug in my original commit I think) - see https://github.com/philipwhiuk/k-9/commit/cbe6e3b9b1c7820194b5f437ee6f54910d785713 I got the following stacktrace.

But this also seems to happen with my original PR too :( Obviously I didn't test it properly....

I'm going to close this and re-work it I think. I may just move us straight to OkHttp3 - it might be easier.

Thanks anyway

03-29 09:28:21.117 26357-26396/com.fsck.k9.debug E/k9: synchronizeMailbox
com.fsck.k9.mail.MessagingException: IOException
    at com.fsck.k9.mail.store.webdav.WebDavStore.doInitialConnection(WebDavStore.java:739)
    at com.fsck.k9.mail.store.webdav.WebDavStore.authenticate(WebDavStore.java:638)
    at com.fsck.k9.mail.store.webdav.WebDavStore.sendRequest(WebDavStore.java:1002)
    at com.fsck.k9.mail.store.webdav.WebDavStore.processRequest(WebDavStore.java:1080)
    at com.fsck.k9.mail.store.webdav.WebDavStore.processRequest(WebDavStore.java:1055)
    at com.fsck.k9.mail.store.webdav.WebDavFolder.getMessageCount(WebDavFolder.java:159)
    at com.fsck.k9.mail.store.webdav.WebDavFolder.getMessageCount(WebDavFolder.java:173)
    at com.fsck.k9.controller.MessagingController.synchronizeMailboxSynchronous(MessagingController.java:873)
    at com.fsck.k9.controller.MessagingController.access$300(MessagingController.java:99)
    at com.fsck.k9.controller.MessagingController$8.run(MessagingController.java:754)
    at com.fsck.k9.controller.MessagingController.run(MessagingController.java:257)
    at java.lang.Thread.run(Thread.java:818)
 Caused by: org.apache.http.conn.HttpHostConnectException: Connection to https://webmaildr.flextrade.com:443 refused
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:193)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
    at com.fsck.k9.mail.store.webdav.WebDavHttpClient.executeOverride(WebDavHttpClient.java:69)
    at com.fsck.k9.mail.store.webdav.WebDavStore.doInitialConnection(WebDavStore.java:701)
    at com.fsck.k9.mail.store.webdav.WebDavStore.authenticate(WebDavStore.java:638) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.sendRequest(WebDavStore.java:1002) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.processRequest(WebDavStore.java:1080) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.processRequest(WebDavStore.java:1055) 
    at com.fsck.k9.mail.store.webdav.WebDavFolder.getMessageCount(WebDavFolder.java:159) 
    at com.fsck.k9.mail.store.webdav.WebDavFolder.getMessageCount(WebDavFolder.java:173) 
    at com.fsck.k9.controller.MessagingController.synchronizeMailboxSynchronous(MessagingController.java:873) 
    at com.fsck.k9.controller.MessagingController.access$300(MessagingController.java:99) 
    at com.fsck.k9.controller.MessagingController$8.run(MessagingController.java:754) 
    at com.fsck.k9.controller.MessagingController.run(MessagingController.java:257) 
    at java.lang.Thread.run(Thread.java:818) 
 Caused by: java.net.ConnectException: Socket is closed
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:190)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169) 
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124) 
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492) 
    at com.fsck.k9.mail.store.webdav.WebDavHttpClient.executeOverride(WebDavHttpClient.java:69) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.doInitialConnection(WebDavStore.java:701) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.authenticate(WebDavStore.java:638) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.sendRequest(WebDavStore.java:1002) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.processRequest(WebDavStore.java:1080) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.processRequest(WebDavStore.java:1055) 
    at com.fsck.k9.mail.store.webdav.WebDavFolder.getMessageCount(WebDavFolder.java:159) 
    at com.fsck.k9.mail.store.webdav.WebDavFolder.getMessageCount(WebDavFolder.java:173) 
    at com.fsck.k9.controller.MessagingController.synchronizeMailboxSynchronous(MessagingController.java:873) 
    at com.fsck.k9.controller.MessagingController.access$300(MessagingController.java:99) 
    at com.fsck.k9.controller.MessagingController$8.run(MessagingController.java:754) 
    at com.fsck.k9.controller.MessagingController.run(MessagingController.java:257) 
    at java.lang.Thread.run(Thread.java:818) 
 Caused by: java.net.SocketException: Socket is closed
    at com.android.org.conscrypt.OpenSSLSocketImpl.checkOpen(OpenSSLSocketImpl.java:247)
    at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:573)
    at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:75)
    at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:88)
    at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:175)
    at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:112)
    at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:134)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169) 
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124) 
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492) 
    at com.fsck.k9.mail.store.webdav.WebDavHttpClient.executeOverride(WebDavHttpClient.java:69) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.doInitialConnection(WebDavStore.java:701) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.authenticate(WebDavStore.java:638) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.sendRequest(WebDavStore.java:1002) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.processRequest(WebDavStore.java:1080) 
    at com.fsck.k9.mail.store.webdav.WebDavStore.processRequest(WebDavStore.java:1055) 
    at com.fsck.k9.mail.store.webdav.WebDavFolder.getMessageCount(WebDavFolder.java:159) 
    at com.fsck.k9.mail.store.webdav.WebDavFolder.getMessageCount(WebDavFolder.java:173) 
    at com.fsck.k9.controller.MessagingController.synchronizeMailboxSynchronous(MessagingController.java:873) 
    at com.fsck.k9.controller.MessagingController.access$300(MessagingController.java:99) 
    at com.fsck.k9.controller.MessagingController$8.run(MessagingController.java:754) 
    at com.fsck.k9.controller.MessagingController.run(MessagingController.java:257) 
    at java.lang.Thread.run(Thread.java:818) 
03-29 09:28:21.227 26357-26396/com.fsck.k9.debug E/k9: Failed synchronizing folder Work:Inbox @ Tue Mar 29 09:28:21 GMT+01:00 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants