web-push-libs / pywebpush

Python Webpush Data encryption library
Mozilla Public License 2.0
305 stars 52 forks source link

Select legacy GCM or actual FCM endpoint for send based on the gcm_key #110

Closed kilgoretrout1985 closed 5 years ago

kilgoretrout1985 commented 5 years ago

Hello,

As https://developers.google.com/cloud-messaging/android/android-migrate-fcm states: "As of April 10, 2018, Google has deprecated GCM. The GCM server and client APIs are deprecated and will be removed as soon as May 29, 2019." So after may 29th posting to https://android.googleapis.com/gcm/send will not work.

But, as far as I understand, we can't just change line 311 to:

endpoint = 'https://fcm.googleapis.com/fcm/send'

as stated in paragraph 4 of android-migrate-fcm, because endusers of the pywebpush lib have to manually Import their GCM projects as a Firebase projects and receive new key (paragraph 1). Just changing the endpoint will break sending for those who still haven't switched from GCM to FCM even before May 29.

jrconlin commented 5 years ago

Thanks! First off, can you please fix the flake8 issue so the tests pass? I'll go deal with the crypto warning.

As weird as it is for me to say this, but I'm not quite sure guessing based on key length is the best way to go about this.

For what it's worth, on a different project we talked with google and found out that we could send GCM messages to the FCM endpoints and they'd basically work.

I think a better patch would be to add a flag that prefers GCM to talk to the old GCM endpoint and default GCM legacy folks to the FCM endpoint.

What do you think?

kilgoretrout1985 commented 5 years ago

Key len seems ok to me because of two reasons: 1) https://stackoverflow.com/questions/41377108/what-is-the-difference-between-server-key-and-legacy-server-key-in-fcmfirebase Top answer there is theoretically from Firebase employee 2) I have 4 old GCM projects that were imported and converted to FCM. Key length obviously differs.

Flag is also a good option as I think.

jrconlin commented 5 years ago

I'll file an issue to add the flag for legacy GCM. Thanks!