MirakelX / mirakel-android

Easy task management for professionals
http://mirakel.azapps.de/
386 stars 117 forks source link

Can't use self-signed certificate on Mirakel #597

Closed itadventurer closed 8 years ago

itadventurer commented 9 years ago

Original Reporter: crisoagf Environment: Taskserver running on my own server. Version: 2.8 Migrated From: https://mirakel.atlassian.net/browse/MIR-622

Hi! First of all, thank you for Mirakel, it seems very nice!

But I cannot configure it to work with my home Taskserver, that uses a self-signed certificate.

Using Taskwarrior, "task sync" on my pc works with the taskd.trust option set to strict, so the certificate probably works. On Mirakel, however, it doesn't work, showing quite the cryptic message on a Toast (My phone is in portuguese, the message is something like "Can't create socket! Did you activate the network connection?". It can be something quite distinct in English, because translations tend to do that). Using logcat, it turns out that the exception description is "Trust anchor for certification path not found.", which, as far as google tells me, is the error corresponding to a non-trusted certificate. I tried looking in the sources for why this would be happening (and what would I be doing wrong), but without luck. I even tried adding the certificate to the user trusted certificates on Android, but even that didn't work!

Shouldn't my ca.cert have been imported with the config file? Or is there a completely different why this would be happening? Am I doing something really wrong?

I am really looking forward to using Mirakel!

itadventurer commented 9 years ago

crisoagf said: I have a patch that solves this issue for me, but I am hesitant with respect to this solution.

First of all, further digging in the logs made me understand that the problem was with adding the ca certificate to the store (in tw_sync/src/de/azapps/mirakel/sync/taskwarrior/network_helper/TLSClient.java). Namely, that the string being used in generateCertificate (l. 67) was malformed. This, I came to understand, is due to the fact that, for some obscure reason, the split() method for Strings only extracts the last byte of the matched separator.

For instance,

{code:java} "--- BEGIN CERTIFICATE ---\n1\n--- END CERTIFICATE ---\n--- BEGIN CERTIFICATE ---\n2\n--- END CERTIFICATE ---".split("--- END CERTIFICATE ---") = {"--- BEGIN CERTIFICATE ---\n1\n--- END CERTIFICATE --", "\n--- BEGIN CERTIFICATE ---\n2\n--- END CERTIFICATE --"} {code}

Note that after the --- (3 -) after the END CERTIFICATE becomes only -- (2 -)

However, I could not test my patch on any other phone, seen that I don't have any available for testing. Furthermore, for lack of RAM reasons (android-studio takes up a huge amount) I couldn't even test it on an emulator. I can't even confirm that this bug is reproducible on any other phone! I couldn't even see any mention of this String.split() strangeness on any googlable place!

Be that as it may, I'll attach my patch to this bug and consider it patched for now.

EDIT: I even tried using a Pattern and the result is exactly the same. Pattern.split() also works funny.