-
Notifications
You must be signed in to change notification settings - Fork 54
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
401 "Request did not validate missing authorization header" when header present #42
Comments
Hi, Looks like one of the problems is that a printed byte string is being sent as the crypto-key.
(Note the I'll take a look at the library code as well and see if I broke something with the latest push. |
AH! I think I see the problem, and it's in the py_vapid library. THANK YOU! |
Thanks for the quick response, that does look like a problem - note that I did change the code given in the mozilla link from Also, I'm on Python 3.5.2, and now that you mention it it does seem like a problem on my end instead of the library (hopefully!) Changed
I get the feeling something is up with my keys, though. Compared to the ones generated in the node library, the keys I have aren't the same length, and when trying to use keys generated by node in the python libraries, I get a wrong key length error. edit: Oops didn't see your update above. No problem (?) :) |
Yeah, I've seen that before. The problem is that some frameworks use different encodings for the public key types. (Probably more info than you want: The ECDSA public key is a pair of 32byte octets, thus the 64 bytes. It's prefixed by a "RAW" key flag (the The spec requires that the public key be in RAW DER format (`\x04' + 2*32 bytes). More fun news! The VAPID format is changing soon. Draft02 moves stuff as a prefix for the AUTH key. No, really, feel free to use a library to deal with this nonsense. You have a life. You should spend more time enjoying it. (Well, unless you find this sort of sadness fun, in which case, feel free to pitch in over on the VAPID libs) |
Sounds good (and yeah, "excited" to hear Vapid 02 is on its way soon, ha). I'll check out py_vapid's releases to sign that header (noticed you've already pushed some changes regarding this - can confirm python3 is busted). Thanks for all your work! Closing this issue now. |
@jrconlin Sorry to bump this again, but my existing problem wasn't resolved with latest version of py_vapid (0.7.1). The issue I have currently is how to use the public key generated by py_vapid as the client's applicationServerKey, which is supposed to be a length 65 UInt8Array after converting from the original base64 form. I've been using the latest py_vapid to generate my keys and sign claims (and pywebpush to send notifications). It seems straightforward and I'm following the steps, but the public key always comes up as invalid on Chrome. (Fails the public key UInt8Array length check for validity) I tried this for changing the public key: I generated a key for example, to go over the steps from the beginning: Becomes I subscribe from the client as below:
Then on the backend I send an update to the push API providers as below:
Log of
The response from a Chrome/FCM endpoint: The response from a Firefox endpoint: |
Unfortunately, converting between a public PEM and a raw key can involve more than just stripping data. Because encryption, there are several different formats that keys can be stored in. Just clipping out the last 64 octets off the key is usually "OK" in the same way that using duct tape to fix your rear bumper is "OK". It's really far better to decode the PEM using ASN1 to get the values, but that's overkill for now. That said, there are a few things a play here that may be tripping you up. Chrome's WebPush requires a few more steps than Firefox does, and has a different auth mechanism. In short you don't use VAPID with Chrome's WebPush, you use FCM. So, for your example, you'd need to create a
The RegistrationIds are provided from the last segment of the endpointURL (Probably should note the extra conditions for older versions of Chrome) I've tried out the code sample above and have been able to send a message through to Chrome. I'm a bit sad that they're taking this approach rather than VAPID, but then VAPID isn't yet formalized as a standard and FCM already works, so I'm not going to ding them about it. Now, as for the 401/109 you're seeing for firefox, I'm not sure I know why that failed. It may be that you're not properly encoding the public key (again, just stripping off octets may not do what you think). |
Got it, I'll check out more formal procedures than removing octets. I thought the FCM-proprietary method was for older versions (Chrome 53 and below) and that recent versions of chrome supported Web Push just like Firefox, from their post here: https://developers.google.com/web/updates/2016/07/web-push-interop-wins
EDIT: I think there may be an issue with |
Huh, I had not seen that post. Ok, let me experiment a bit and see if I can figure out what's going on there. thanks! |
Welp, if it's any help, I'm now getting the ever helpful I pulled the public key from my py_vapid library and was able to request a restricted endpoint, but when I try to submit a vapid header that is signed using that key, it bounces. |
Yeah, it seems like some other people had this problem, reading this is where I thought something could be up with the signature: http://stackoverflow.com/questions/39336523/webpushvapid-request-fails-with-400-unauthorizedregistration Edit: I tried my code with the example keys in test_vapid.py copied over and it didn't work with same errors, which is highly confusing and makes me think there's something wrong on my end. Not sure what could be going wrong - All tests passed on py_vapid on my setup too |
* uses lastest ece(1.7.2) and vapid libraries (1.2.1) * Will attempt to autofill vapid `aud` from the endpoint if VAPID requested * Allows for the older `'aesgcm'` and newer, albeit not as widely supported `'aes128gcm'` encryption content types. * Includes fixes provided by https://github.com/Flimm NOTE: Currently BLOCKED due to web-push-libs/encrypted-content-encoding#36 closes: #49, #48, #42
* uses lastest ece(1.7.2) and vapid libraries (1.2.1) * Will attempt to autofill vapid `aud` from the endpoint if VAPID requested * Allows for the older `'aesgcm'` and newer, albeit not as widely supported `'aes128gcm'` encryption content types. * Includes fixes provided by https://github.com/Flimm NOTE: Currently BLOCKED due to web-push-libs/encrypted-content-encoding#36 closes: #49, #48, #42
* uses lastest ece(1.7.2) and vapid libraries (1.2.1) * Will attempt to autofill vapid `aud` from the endpoint if VAPID requested * Allows for the older `'aesgcm'` and newer, albeit not as widely supported `'aes128gcm'` encryption content types. * Includes fixes provided by https://github.com/Flimm NOTE: Currently BLOCKED due to web-push-libs/encrypted-content-encoding#36 closes: #49, #48, #42
* uses lastest ece(1.7.2) and vapid libraries (1.2.1) * Will attempt to autofill vapid `aud` from the endpoint if VAPID requested * Allows for the older `'aesgcm'` and newer, albeit not as widely supported `'aes128gcm'` encryption content types. * Includes fixes provided by https://github.com/Flimm NOTE: Currently BLOCKED due to web-push-libs/encrypted-content-encoding#36 closes: #49, #48, #42
OBE by #53 (Thanks!) |
This might be a StackOverflow-type question but I'm constantly getting
401 Unauthorized
, errcode 109 (Invalid authentication) and message: "Request did not validate missing authorization header". I'm using VAPID headers to a Mozilla push endpoint as suggested in #30I use this line to send the notification:
x = pywebpush.WebPusher(subscription_info).send(data, vapid_headers, 60*60)
The authorization header appears to be present (logged
x.request.headers
):{ 'Accept': '*/*', 'authorization': 'WebPush eyJ0eXAiOi...', 'crypto-key': "p256ecdsa=b'Nz2H1lIDt...7b7OAfMA-bwZP6qk_WonOnahzw7iDx4rA';keyid=p256dh;dh=BCvGo_YbulU_xUnT-U...", 'ttl': '3600', 'Accept-Encoding': 'gzip, deflate', 'content-encoding': 'aesgcm', 'encryption': 'keyid=p256dh;salt=azMk5vK0...', 'User-Agent': 'python-requests/2.11.1', 'Connection': 'keep-alive', 'Content-Length': '370' }
The lengthy details (sorry) below show what I do:
subscription_info = {'endpoint': 'https://updates.push.services.mozilla.com/wpush/v2/gAA...', 'keys': {'p256dh': 'BJv7nI...p31z4Qvt86+oeQMfZk5Nb/fhko...wmPXvo99A=', 'auth': '2Y4...+WA=='}}
data = json.loads({'abc': 'def'})
vapid_headers = _make_vapid_headers(endpoint)
(endpoint
is fromsubscription_info
)Relevant definitions below (and possibly where an error lies, as I attempted to fix an issue I got in python3 running the original code from https://blog.mozilla.org/services/2016/04/04/using-vapid-with-webpush/ )
I followed the instructions for getting the public key to send to the frontend from https://blog.mozilla.org/services/2016/08/23/sending-vapid-identified-webpush-notifications-via-mozillas-push-service/ where I removed
-----BEGIN PUBLIC KEY
, made the key urlsafe, etc.The text was updated successfully, but these errors were encountered: