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

adding signal-android devices #20

Closed
Trolldemorted opened this issue Jul 7, 2016 · 8 comments
Closed

adding signal-android devices #20

Trolldemorted opened this issue Jul 7, 2016 · 8 comments

Comments

@Trolldemorted
Copy link
Contributor

is it possible to add signal for android as a non-master device?

i know that the android devices cannot display a tsdevice link, but since it is nothing but an encoded public key (?) i guess i can construct it manually with a self-compiled signal android.

did you try it yet and do you know any imminent problems?

@AsamK
Copy link
Owner

AsamK commented Jul 7, 2016

It's possible, if you implement it yourself. You need to build Signal-Android with a libsignal-service-java version, that contains the following PR: signalapp/libsignal-service-java#21 .
And then you have modify Signal-Android to create the tsdevice link, call the appropriate provisioning methods in libsignal-service-java and make Signal-Android send its deviceId in all server requests. here's the commit that adds provisioning as non-master to signal-cli: 33956bd
Also contact and group synchronization need to be implemented.

So I guess it's a lot of work and I'm not sure if it's going to be merged upstream.
I haven't attempted it and anyway, it's not a signal-cli issue.

@AsamK AsamK closed this as completed Jul 7, 2016
@Trolldemorted
Copy link
Contributor Author

Would you be willing to help, though?

I have managed to make Signal-Android produce tsdevice links, finish the device link, and append its received deviceid to all requests so far.

sending and receiving personal and group messages is working fine, but the initial group and contact synchronization is troubling me. When i send a sync-request like you did here, the api throws a MismatchedDevicesException:

07-13 00:55:10.536 3398-3427/org.thoughtcrime.securesms W/SignalServiceMessageSender: org.whispersystems.signalservice.internal.push.exceptions.MismatchedDevicesException
  at org.whispersystems.signalservice.internal.push.PushServiceSocket.makeRequest(PushServiceSocket.java:538)
  at org.whispersystems.signalservice.internal.push.PushServiceSocket.sendMessage(PushServiceSocket.java:207)
  at org.whispersystems.signalservice.api.SignalServiceMessageSender.sendMessage(SignalServiceMessageSender.java:358)
  at org.whispersystems.signalservice.api.SignalServiceMessageSender.sendMessage(SignalServiceMessageSender.java:213)
  at org.thoughtcrime.securesms.jobs.GroupSyncRequestJob.onRun(GroupSyncRequestJob.java:48)
  at org.thoughtcrime.securesms.jobs.MasterSecretJob.onRun(MasterSecretJob.java:18)
  at org.whispersystems.jobqueue.JobConsumer.runJob(JobConsumer.java:76)
  at org.whispersystems.jobqueue.JobConsumer.run(JobConsumer.java:46)

could you give me a hint what a MismatchedDevicesException is supposed to indicate? I cannot catch it, since jobs run in different threads, i suppose.

@AsamK
Copy link
Owner

AsamK commented Jul 13, 2016

Nice work!
I think a mismatched device exception occurs, when the client tries to send a message, that is not encrypted for all of the linked devices or for a device that is not linked anymore. You could check if the send methods called for the sync messages are the same as in signal-cli and also if the deviceId is always set for the sync messages.
If you push your code to your fork, I could have a look

@Trolldemorted
Copy link
Contributor Author

I cleaned up the source code as much as i could, here is the commit: Trolldemorted/Signal-Android@8ac7f52

Don't forget to build against signalapp/libsignal-service-java#21 - i did not want to waste time on figuring how gradle/maven work, so i dropped my compiled jars manually into my gradle cache. If you know an easy and better solution, please elaborate :)

@AsamK
Copy link
Owner

AsamK commented Jul 13, 2016

The exception is raised because Signal-Android creates a session for its own deviceId, and the server doesn't like that.
I've added a workaround in libsignal-service-java, which should prevent the MismatchedDevicesException: Turasa/libsignal-service-java@f5c4e7c

You can use ./gradlew installArchives to install libsignal-service-java to your local maven repository which is picked up by Signal-Android with the mavenLocal() entry.

@Trolldemorted
Copy link
Contributor Author

Thanks a lot for your quick help!

Since i use your libsignal-service no more MismatchedDevicesExceptions are popping up - you might want to overload setAccountAttributes and verifyAccountWithCode though, since the RegistrationService, RegistrationProgressActivity and RefreshAttributesJob classes won't compile due to calls with missing parameters. Do you think you will manage to convice OWS to merge your fixes into their master branch?

As for signal-cli:
when receiving a contact sync request, signal-cli prints out an appropriate message:

Envelope from: +491XXXXXXXXX (device: 4)
Timestamp: 1468456960583
Received a sync message
Received sync request
 - contacts request

Naturally it would be great if it would respond to it (either automatically or by explicit command - i guess calling pushContacts after loading the config still works, so at least i got a workaround for now).

when receiving a group sync request, signal-cli prints a NullPointerException:

Exception in thread "main" java.lang.NullPointerException
    at org.whispersystems.signalservice.internal.push.SignalServiceProtos$GroupDetails$Avatar$Builder.setContentType(SignalServiceProtos.java:11333)
    at org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsOutputStream.writeGroupDetails(DeviceGroupsOutputStream.java:41)
    at org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsOutputStream.write(DeviceGroupsOutputStream.java:17)
    at org.asamk.signal.Manager.sendGroups(Manager.java:1017)
    at org.asamk.signal.Manager.receiveMessages(Manager.java:809)
    at org.asamk.signal.Main.main(Main.java:360)

but i cannot yet tell whether my request is malformed or signal-cli is crashing on a correct request.

@AsamK
Copy link
Owner

AsamK commented Jul 14, 2016

Probably not, so far none of my libsignal-service-java PRs have been merged or even been comment on.

signal-cli should already send the sync contacts after receiving a contact sync request.
The same happens for group requests. The error you get there was caused when sending the sync groups, by an avatar image, of which java couldn't detect the content type. This should be fixed in the master branch now.

@Trolldemorted
Copy link
Contributor Author

Trolldemorted commented Jul 14, 2016

[here was nuisance]

Unfortunately signal-cli deleted my contactstore and some point (don't know when and which version, just noticed the fact).

After linking a new Signal-Desktop device, responding to the sync requests with an empty contactstore, adding myself and one other old contact to the contact list, and performing a manually sync, signal-cli crashed while decrypting the sync requests:

org.whispersystems.libsignal.InvalidMessageException: No valid sessions.
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:287)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:246)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:214)
        at org.whispersystems.signalservice.api.crypto.SignalServiceCipher.decrypt(SignalServiceCipher.java:152)
        at org.whispersystems.signalservice.api.crypto.SignalServiceCipher.decrypt(SignalServiceCipher.java:124)
        at org.asamk.signal.Manager.decryptMessage(Manager.java:718)
        at org.asamk.signal.Manager.receiveMessages(Manager.java:810)
        at org.asamk.signal.Main.handleCommands(Main.java:371)
        at org.asamk.signal.Main.main(Main.java:69)
Caused by: org.whispersystems.libsignal.InvalidMessageException: Bad Mac!
        at org.whispersystems.libsignal.protocol.SignalMessage.verifyMac(SignalMessage.java:132)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:311)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:265)
        ... 8 more

Now i reinstalled S-D again, and noticed that if the contactstore is not empty when syncing while linking, the next manually requested sync works. Groups are still not synchronized though, neither while linking, nor by a manually requested sync.

Edit: looks like i have to correct myself: S-D apparently DID receive and parse the group, but did just not display them until the next received group message. Sorry for bothering you, i assumed S-D's import works flawlessly -.- The InvalidMessageException issues and the disappearing contactstore problem is still valid though.

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

No branches or pull requests

2 participants