Traccar Relay - fresh installation, no location

jinzo 7 hours ago

So I have a fresh Pixel 8 (updated to latest Android version), with a fresh Google Account and fresh MotoTag2 paired in Find Hub. I can see the location of the tag in Find Hub. I installed Traccar Relay 1.2.0 logged in and got two devices - the pixel itself and MotoTag2. I put the tag id in my traccar and when force closing and opening the Traccar Relay I see that the tag comes online. I request a single location and get the error in log (sorry, had to clean it up a lot, as it's not possible to copy from the log on my device):

--------- beginning of main
11-27 20:36:10.665  2092  2092 I MainActivity: App opened
11-27 20:36:11.738  2092  2116 I MainViewModel: Loaded 2 devices
11-27 20:36:27.218  2092  2198 I PushNotificationService: Location requested for device 6b063dce-0000-213b-af15-10d9a224b1e6
11-27 20:36:27.915  2092  2238 E DeviceRepository: Error handling push message
11-27 20:36:27.915  2092  2238 E DeviceRepository: java.lang.IllegalArgumentException: bad base-64
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at android.util.Base64.decode(Base64.java:164)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at android.util.Base64.decode(Base64.java:139)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at android.util.Base64.decode(Base64.java:121)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.push.HttpEceDecryptor.base64Decode(HttpEceDecryptor.kt:115)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.push.HttpEceDecryptor.decrypt(HttpEceDecryptor.kt:26)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.handlePushMessage(DeviceRepository.kt:235)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.startPushConnection$lambda$0(DeviceRepository.kt:90)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.push.McsClient.handleMessage(McsClient.kt:159)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.push.McsClient.connect(McsClient.kt:62)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.startPushConnection(DeviceRepository.kt:89)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.requestAndUploadLocation$lambda$0(DeviceRepository.kt:111)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository$$ExternalSyntheticLambda4.run(D8$$SyntheticClass:0)
11-27 20:36:27.915  2092  2238 E DeviceRepository:     at java.lang.Thread.run(Thread.java:1571)
11-27 20:36:27.916  2092  2238 E DeviceRepository: Error handling push message
11-27 20:36:27.916  2092  2238 E DeviceRepository: java.lang.IllegalArgumentException: bad base-64
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at android.util.Base64.decode(Base64.java:164)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at android.util.Base64.decode(Base64.java:139)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at android.util.Base64.decode(Base64.java:121)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.push.HttpEceDecryptor.base64Decode(HttpEceDecryptor.kt:115)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.push.HttpEceDecryptor.decrypt(HttpEceDecryptor.kt:26)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.handlePushMessage(DeviceRepository.kt:235)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.startPushConnection$lambda$0(DeviceRepository.kt:90)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.push.McsClient.handleMessage(McsClient.kt:159)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.push.McsClient.connect(McsClient.kt:62)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.startPushConnection(DeviceRepository.kt:89)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.requestAndUploadLocation$lambda$0(DeviceRepository.kt:111)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository$$ExternalSyntheticLambda4.run(D8$$SyntheticClass:0)
11-27 20:36:27.916  2092  2238 E DeviceRepository:     at java.lang.Thread.run(Thread.java:1571)
11-27 20:36:36.344  2092  2238 E DeviceRepository: Error handling push message
11-27 20:36:36.344  2092  2238 E DeviceRepository: java.lang.IllegalArgumentException: bad base-64
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at android.util.Base64.decode(Base64.java:164)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at android.util.Base64.decode(Base64.java:139)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at android.util.Base64.decode(Base64.java:121)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.push.HttpEceDecryptor.base64Decode(HttpEceDecryptor.kt:115)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.push.HttpEceDecryptor.decrypt(HttpEceDecryptor.kt:26)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.handlePushMessage(DeviceRepository.kt:235)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.startPushConnection$lambda$0(DeviceRepository.kt:90)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.push.McsClient.handleMessage(McsClient.kt:159)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.push.McsClient.connect(McsClient.kt:62)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.startPushConnection(DeviceRepository.kt:89)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository.requestAndUploadLocation$lambda$0(DeviceRepository.kt:111)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at org.traccar.relay.api.DeviceRepository$$ExternalSyntheticLambda4.run(D8$$SyntheticClass:0)
11-27 20:36:36.344  2092  2238 E DeviceRepository:     at java.lang.Thread.run(Thread.java:1571)
11-27 20:36:57.902  2092  2198 W DeviceRepository: Location request timed out for device 6b063dce-0000-213b-af15-10d9a224b1e6
11-27 20:36:57.918  2092  2198 W DeviceRepository: No usable location for device 6b063dce-0000-213b-af15-10d9a224b1e6

Any idea what's happening?
Thanks!

Anton Tananaev 6 hours ago

This looks like an issue parsing the encryption headers in a location response. Could you test a debug build that logs those headers and share the log after requesting a location once?

jinzo 5 hours ago

Unfortunately I am very rusty with my Android development. After installing AndroidStudio I tried two things: running ./gradlew assembleDebug and installing the resulting build/output/apk/debug/*.apk, nothing new in logs. I also tried launching debug via AndroidStudio -> same.
So not sure what debug build actually means, but am happy to invest some more time into this if you point me in a good direction!

jinzo 5 hours ago

I had some tokens left, and put our 'new friends' to the task, and it came up with a solution - the location showed on the server.

The new logs confirmed the cause. Every push message's crypto-key header has a second value after the key:

crypto-key=dh=BFoUasI8...828Ms; p256ecdsa=BDOU99-h67Hc...

The old code only stripped the leading dh=, so ; p256ecdsa=... was left attached to the key and decoding failed. The new code reads only the dh value, so decryption works.

The code change that it did:

---
 app/src/main/java/org/traccar/relay/api/DeviceRepository.kt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/app/src/main/java/org/traccar/relay/api/DeviceRepository.kt b/app/src/main/java/org/traccar/relay/api/DeviceRepository.kt
index a915b4c..22c589f 100644
--- a/app/src/main/java/org/traccar/relay/api/DeviceRepository.kt
+++ b/app/src/main/java/org/traccar/relay/api/DeviceRepository.kt
@@ -228,7 +228,8 @@ class DeviceRepository(context: Context) {
         try {
             val appDataMap = message.app_data.associate { it.key to it.value_ }
 
-            val cryptoKey = appDataMap["crypto-key"]?.removePrefix("dh=") ?: return
+            val cryptoKey = appDataMap["crypto-key"]?.split(';')
+                ?.map { it.trim() }?.firstOrNull { it.startsWith("dh=") }?.removePrefix("dh=") ?: return
             val salt = appDataMap["encryption"]?.removePrefix("salt=") ?: return
             val rawData = message.raw_data?.toByteArray() ?: return
 
-- 

if there is any specific things you need me to run for the debug build, happy to!

Anton Tananaev 5 hours ago
jinzo 4 hours ago

Works, great thanks!