syncthing / syncthing-android

Wrapper of syncthing for Android.
https://syncthing.net/
Mozilla Public License 2.0
3.52k stars 396 forks source link

generating secure keys stuck. #405

Closed grinapo closed 6 years ago

grinapo commented 9 years ago

First time install from Gmarket today, got welcome dialog, go "Generating secure keys. This may take a few minutes." dialog. For the last few hours. If I kill it off the start gives "Loading" until I lose patience and kill it off again. [This is a fairly powerful phone, I doubt the generation should take more than a couple of seconds.]

Nutomic commented 9 years ago

Can you see if there's anything in the logs?

grinapo commented 9 years ago

If you kindly instruct me towards its folder I will try harder.

Zillode commented 9 years ago

Use adb logcat. See http://forum.xda-developers.com/showthread.php?t=1726238

syadykin commented 9 years ago

I expect this happens because of wrong permissions on libsyncthing.so file - I still have this issue on my lenovo p780.

Nutomic commented 9 years ago

That is unlikely, the file should always have the executable flag.

Can you post a log as described above?

syadykin commented 9 years ago

It fails with something like this:

[ 06-23 11:12:18.693  5548:0x15ac E/SyncthingRunnable ]
Failed to execute syncthing binary or read output
java.io.IOException: Error running exec(). Command: [/data/data/com.nutomic.syncthingandroid/lib/libsyncthing.so, -generate, /data/data/com.nutomic.syncthingandroid/files] Working Directory: null Environment: [STTRACE=, ANDROID_ROOT=/system, BOOTCLASSPATH_EX=/system/framework/mediatek-op.jar, EMULATED_STORAGE_SOURCE=/mnt/shell/emulated, USBOTG_STORAGE=/storage/usbotg, LOOP_MOUNTPOINT=/mnt/obb, EMULATED_STORAGE_TARGET=/storage/emulated, ANDROID_BOOTLOGO=1, STNORESTART=1, STGUIAUTH=Lenovo P780:WLagxYpUDHKnVXi1m9Gj, LD_LIBRARY_PATH=/vendor/lib:/system/lib:/custom/lib, EXTERNAL_STORAGE=/storage/sdcard0, ANDROID_SOCKET_zygote=9, ANDROID_DATA=/data, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ANDROID_ASSETS=/system/app, ASEC_MOUNTPOINT=/mnt/asec, HOME=/storage/sdcard0, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework2.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/webviewchromium.jar:/system/framework/mediatek-common.jar:/system/framework/mediatek-framework.jar:/system/framework/CustomProperties.jar:/system/framework/mediatek-telephony-common.jar:/system/framework/mediatek-tablet.jar, ANDROID_PROPERTY_WORKSPACE=8,0, STNOUPGRADE=1, ANDROID_STORAGE=/storage]
        at java.lang.ProcessManager.exec(ProcessManager.java:211)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:195)
        at com.nutomic.syncthingandroid.syncthing.SyncthingRunnable.run(SyncthingRunnable.java:115)
        at com.nutomic.syncthingandroid.util.ConfigXml.generateKeysConfig(ConfigXml.java:90)
        at com.nutomic.syncthingandroid.util.ConfigXml.<init>(ConfigXml.java:75)
        at com.nutomic.syncthingandroid.syncthing.SyncthingService.updateState(SyncthingService.java:214)
        at com.nutomic.syncthingandroid.syncthing.SyncthingService.onStartCommand(SyncthingService.java:171)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2906)
        at android.app.ActivityThread.access$2100(ActivityThread.java:155)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1428)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5395)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:837)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653)
        at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.IOException: Permission denied
        at java.lang.ProcessManager.exec(Native Method)
        at java.lang.ProcessManager.exec(ProcessManager.java:209)
        ... 17 more

I also noticed that file itself has no executable bit:

root@P780_ROW:/ # ls -l /data/data/com.nutomic.syncthingandroid/lib/           
-rw-r--r-- system   system    9076808 2015-07-19 20:24 libsyncthing.so

Also it seems it mounts to a different place before run:

root@P780_ROW:/ # mount | grep syncth                                          
/dev/block/dm-1 /mnt/asec/com.nutomic.syncthingandroid-1 ext4 ro,dirsync,seclabel,nosuid,nodev,noatime 0 0
root@P780_ROW:/ #
Nutomic commented 9 years ago

That is really weird. It should actually break all apps that use native code.

As a workaround, you could chmod 755 libsyncthing.so.

syadykin commented 9 years ago

Can you provide an example of such app (with native code) and i'll test it.

Nutomic commented 9 years ago

Firefox for example.

syadykin commented 9 years ago

Firefox works w/out any problem. I also noticed next thing:

 root@P780_ROW:/data/data # ls -l org.mozilla.firefox/
…
lrwxrwxrwx install  install           2015-06-23 14:25 lib -> /data/app-lib/org.mozilla.firefox-1
…
root@P780_ROW:/data/data # ls -l com.nutomic.syncthingandroid/
…
lrwxrwxrwx install  install           2015-06-23 11:08 lib -> /mnt/asec/com.nutomic.syncthingandroid-1/lib
…

so these apps have different mount point. Of course firefox libs have executable bit set as well:

root@P780_ROW:/data/data/org.mozilla.firefox/lib # ls -l 
-rwxr-xr-x system   system     354412 2015-06-28 06:51 libmozglue.so
-rwxr-xr-x system   system       5416 2015-06-28 05:51 libplugin-container.so
root@P780_ROW:/data/data/org.mozilla.firefox/lib #

Hope this helps.

Nutomic commented 9 years ago

This is really weird. Maybe a reinstall fixes it? Where did you get the syncthing apk from?

syadykin commented 9 years ago

I reinstalled it this morning. APK came from play store as well.

syadykin commented 9 years ago

I moved app from SD card where it has been installed by default into phone memory and lib now has executable bit set — everything started to work fine!

Nutomic commented 9 years ago

Sounds like #87.

@grinapo Does this also fix the problem for you?

Nutomic commented 9 years ago

Actually, it shouldn't even be possible to move the app to sdcard. Did you use a third party app for that?

syadykin commented 9 years ago

Nope — i didn't do anything to move the app to SD card, it has been installed there by default.

Nutomic commented 9 years ago

According to Android docs, this should never happen for syncthing-android (because of manifest flags). Seems like your phone vendor isn't following the spec there. So there's nothing we can do afaik.

syadykin commented 9 years ago

Some of apps even impossible to move to SD card (skype e.g.) while syncthing-android installs to SD by default. Is it possible that you missed something in manifest?

Nutomic commented 9 years ago

It's this attribute. We currently don't have it set, so the app should only be installed to internal storage. However, I'll also set it explicitly now to be sure.

licaon-kter commented 8 years ago

Seeing this on 0.6.6 and 0.7.0-beta2, it will get a key eventually (aka after an hour or so).

During the key gen retries I will eventually stop trying to keep the screen on so I'll let the screen go off and the lock screen activate, so I'll guess it will be at the mercy of whatever the powersaving features do.

When I'll open the device again it will either be still at generating or it will be closed like it did FC all by itself. So I'll open it again only to see a white screen, after a while Android will prompt me to kill or wait. I kill it and retry and then it's back to generating.

I tried to bypass this by copying an old /data/data/com.syncthing folder (except lib) but to no avail, it still tries to generate the key.

I'll generate a log later.

/LE: I got a glimpse at the toaster that appears when it closes, it's this issue, although the device is rooted on Android 5, I did not give it permissions since I know that's troublesome. Looking in the folders no file was modified, after deleting the folders it worked ok, key generation went fast.

/LE2: figured out a bit what happened, I uninstalled 0.6.6 since I needed the github 0.7.0-beta 2 ( 0.12 compatibility ), the folders where left there, I backup them just in case, but their permissions where wrong, hence the new installed version could not access it. I've overwriten files & _sharedprefs, chmod 600 the files and 771 the folders, chown to the new user _u0aXXX and lo and behold, it works as it should.

Nutomic commented 8 years ago

Okay your issue seems a different from OP's (he installed the app for the first time). I don't think we can change the fact that files will be owned by root when you run as superuser, and we can't do anything to delete them on uninstall, either. The next best thing might be checking the permissions explicitly before starting, and show a warning if the permissions are wrong.

licaon-kter commented 8 years ago

Like I said, I wasn't running it as root in the first place

On uninstall /data/data/appname folder is left there as junk? The app gets a new user/group on each reinstall? Is that linked to the signed key (I uninstalled the F-Droid version thinking that installing the Github beta over it will fail since they're signed by different keys)?

Nutomic commented 8 years ago

Oh I assumed that you ran Syncthing as root, and Android wasn't able to delete the data folder.

Afaik, the /data/data/appname folder should always be deleted on uninstall. What Android version are you running? Stock or custom ROM?

lkwg82 commented 8 years ago

Stale. Close?

Nutomic commented 8 years ago

Is anyone still getting this problem with the latest version?

akrone commented 8 years ago

Yes, I do. This issue is persistent on my device. Android 5 Regards Armin

Am 10. April 2016 16:51:04 MESZ, schrieb Felix Ableitner notifications@github.com:

Is anyone still getting this problem with the latest version?


You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/syncthing/syncthing-android/issues/405#issuecomment-207995722

Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

Segment0895 commented 8 years ago

generating secure keys stuck

Yes I had this problem just now -- and fixed it. I have no SD card though. What I did have was a backup in Google's servers (the normal Android backup) which was restored.

Deleting all the storage, removing the app and reinstalling fixed the issue.

OS: CyanogenMod snapshot 1 (first 'beta' towards CyanogenOS 12, which is Android 6.0).

grinapo commented 8 years ago

@Nutomic yes, latest Gplay version (0.7.18) did the same: key generates forever; after killing and restarting it's "loading" forever. It was a reinstall again since the last one was factory reset. I have +x on the lib and it's not symlinked away. I try to figure out how you ppl get logs ;) [okay, logcat is ok, I'll see what is visible]

So the logs show me nothing, except that "loading" means that the daemon runs but the GUI isn't coming. I have opened the localhost link [found in the log] in firefox and I got the gui, got the id, added to the linux server as peer and then the GUI magically woke up and asked me about anon reporting. Since then it seems to run fine.

This may be problem: 05-26 15:12:07.201 21959 21989 W SyncthingNativeCode: 2016/05/26 13:12:07 http: TLS handshake error from 127.0.0.1:51367: remote error: unknown certificate authority 05-26 15:15:30.933 21959 21989 W SyncthingNativeCode: 2016/05/26 13:15:30 http: TLS handshake error from 127.0.0.1:58360: remote error: unknown certificate 05-26 15:15:30.972 21959 21989 W SyncthingNativeCode: 2016/05/26 13:15:30 http: TLS handshake error from 127.0.0.1:57550: remote error: unknown certificate

05-26 15:22:17.021 21959 29710 W SyncthingNativeCode: ionice: exec 29688: Permission denied 05-26 15:22:17.023 21959 29693 I SyncthingRunnableIoNice: ionice performed on libsyncthing.so 05-26 15:22:17.023 21959 29693 E SyncthingRunnableIoNice: Failed to set ionice 127

DavidPost-1 commented 8 years ago

I'm having a similar problem. In addition to everything that's been said it only seems to be an issue when I'm using mobile data. When connected to wifi generating a key happens without a problem and I don't have the persistent 'loading'.

Switching wifi on without killing the app while it's 'loading' seems to make everything work without a problem. I've double checked firewall settings, my install has got access to mobile data.

I'm using CyanogenMod 13.0, Android 6.0.1.

Catfriend1 commented 6 years ago

Root and non root first start key generation got improved meanwhilst. To sum up, the app should be (re)installed to the phone memory instead of sdcard to get it executing the core binary properly.