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

'Incorrect padding' on APNS notification request #129

Closed
myoussef89 opened this issue Jun 29, 2020 · 14 comments
Closed

'Incorrect padding' on APNS notification request #129

myoussef89 opened this issue Jun 29, 2020 · 14 comments

Comments

@myoussef89
Copy link

myoussef89 commented Jun 29, 2020

it was working on Sygnal v0.6.0 , although I send the token as a string, what is wrong with it ?

{
"notification": {
"event_id": "$hUG6SS47Lgms90h363Iwji7g6EJDMAe8SuNgtO-MnLU",
"room_id": "!DxDVMhkbmjTMTdbHsJ:friends-groups.com",
"type": "m.room.message",
"sender": "@xxxxxxxxxx:xxxxxxxxxx.com",
"sender_display_name": "Major Tom",
"room_name": "Mission Control",
"room_alias": "@xxxxxxxxxx:xxxxxxxxxx.com",
"prio": "high",
"content": {
"msgtype": "m.text",
"body": "I'm floating in a most peculiar way."
},
"counts": {
"unread": 2,
"missed_calls": 1
},
"devices": [
{
"app_id": "com.xxxxxxxxxx:xxxxxxxxxx.matrix",
"pushkey": "APA91bHPRgkF3JUikC4ENAHEeMrd41Zxv3hVZjC9KtT8OvPVGJ-hQMRKRrZuJAEcl7B338qju59zJMjw2DELjzEvxwYv7hH5Ynpc1ODQ0aT4U4OFEeco8ohsN5PjL1iC2dNtk2BAokeMCg2ZXKqpc8FXKmhX94kIxQ",
"pushkey_ts": 12345678,
"data": {
"payload": "hello"
},
"tweaks": {
"sound": "bing"
}
}
]
}
}

version: Sygnal v0.7.0

Jun 29 18:40:42 ip-172-31-11-241 python3[12784]: Traceback (most recent call last):
Jun 29 18:40:42 ip-172-31-11-241 python3[12784]:   File "/home/ubuntu/sygnal/sygnal/http.py", line 265, in _handle_dispatch
Jun 29 18:40:42 ip-172-31-11-241 python3[12784]:     result = await pushkin.dispatch_notification(notif, d, context)
Jun 29 18:40:42 ip-172-31-11-241 python3[12784]:   File "/home/ubuntu/sygnal/sygnal/apnspushkin.py", line 256, in dispatch_notification
Jun 29 18:40:42 ip-172-31-11-241 python3[12784]:     log, span, device, shaved_payload, prio
Jun 29 18:40:42 ip-172-31-11-241 python3[12784]:   File "/home/ubuntu/sygnal/sygnal/apnspushkin.py", line 174, in _dispatch_request
Jun 29 18:40:42 ip-172-31-11-241 python3[12784]:     device_token = base64.b64decode(device.pushkey).hex()
Jun 29 18:40:42 ip-172-31-11-241 python3[12784]:   File "/home/ubuntu/.sygnal/lib/python3.6/base64.py", line 87, in b64decode
Jun 29 18:40:42 ip-172-31-11-241 python3[12784]:     return binascii.a2b_base64(s)
Jun 29 18:40:42 ip-172-31-11-241 python3[12784]: binascii.Error: Incorrect padding
@reivilibre
Copy link
Contributor

Plainly, your device token seems to be wrong.

Oddly, I get a different error to you:

>>> pk = "APA91bHPRgkF3JUikC4ENAHEeMrd41Zxv3hVZjC9KtT8OvPVGJ-hQMRKRrZuJAEcl7B338qju59zJMjw2DELjzEvxwYv7hH5Ynpc1ODQ0aT4U4OFEeco8ohsN5PjL1iC2dNtk2BAokeMCg2ZXKqpc8FXKmhX94kIxQ"                                                                

>>> base64.b64decode(pk)                                                                                                                                                                                                                     
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/base64.py", line 87, in b64decode
    return binascii.a2b_base64(s)
binascii.Error: Invalid base64-encoded string: number of data characters (161) cannot be 1 more than a multiple of 4

Invalid base64-encoded string: number of data characters (161) cannot be 1 more than a multiple of 4

Without knowing specifics about how you're getting your device tokens, it's hard to offer any advice.

Something is going wrong with your base64 encoding...

@myoussef89
Copy link
Author

are you sending it to Sygnal as a string or encoded?

@Mohamed-Ramadan
Copy link

@myoussef89 the above pk is 'fcmToken' srting that i got from Firebase ,and i send it as a string not b64decode.

@reivilibre
Copy link
Contributor

I'm afraid I'm rather confused, are you two related in some way?

@myoussef89 the above pk is 'fcmToken' srting that i got from Firebase ,and i send it as a string not b64decode.

Firebase FCM (once known as GCM, typically used for Android) and APNs (used for iOS) are two different systems.

If you give Sygnal a FCM token, it needs to be for a FCM app ID.

i.e. "app_id": "com.xxxxxxxxxx:xxxxxxxxxx.matrix", then com.xxxxxxxxxx:xxxxxxxxxx.matrix in your config needs to refer to a GCM/FCM-type app.

@myoussef89
Copy link
Author

yes, we are working together on the same project.

Does that mean IOS is only working with APNS, Not supported on firebase ?

@reivilibre
Copy link
Contributor

You are using iOS with FCM?

@myoussef89
Copy link
Author

we tried to use it for FCM because we are having trouble receiving notification with APNS. before IOS 13.3 it was working after Apple's last updates we are not receiving VOIP notifications or text notifications anymore.

@reivilibre
Copy link
Contributor

OK so my understanding is:

  • When you use FCM on iOS, FCM will talk to APNs on your behalf.
    • so you should not configure Sygnal with APNs
    • You need to give your APNs credentials to FCM
    • then you can try configuring Sygnal to use FCM (GCM) for your iOS app
      • I don't know if anyone has tried this, but after skimming FCM's documentation, it seems like it stands a chance

I don't know if going through FCM will help your problem, though.

@myoussef89
Copy link
Author

yes, that exactly what we are trying to do.

@reivilibre
Copy link
Contributor

Your error message indicates that Sygnal is configured with type: apns when it needs to be type: gcm if you are using FCM.

@myoussef89
Copy link
Author

myoussef89 commented Jun 30, 2020

Your error message indicates that Sygnal is configured with type: apns when it needs to be type: gcm if you are using FCM.

yes, I think we messed up the tokens when we were trying on APNS.

@reivilibre
Copy link
Contributor

Is this now resolved? :)

@myoussef89
Copy link
Author

Is this now resolved? :)

I think for the current error yes

@Sphinix1
Copy link

Sphinix1 commented Oct 5, 2022

how did you finally resolve it ?, can you share the structure of your sygnal.yaml ? i seem to have the same problem

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

4 participants