pimeys / rust-web-push

A Web Push library for Rust
Apache License 2.0
114 stars 21 forks source link

The request is having invalid cryptographic keys #38

Closed Oreganon closed 1 year ago

Oreganon commented 1 year ago

When sending out notification requests I get the following error: The request is having invalid cryptographic keys. The logging does not give any more information.

How the keys are generated: https://github.com/Oreganon/bedge/blob/main/keygen.sh

The code: https://github.com/Oreganon/bedge/blob/main/src/main.rs#L22

Subscription info:

[src/main.rs:31] &subscription_info = SubscriptionInfo {
    endpoint: "https://updates.push.services.mozilla.com/wpush/v2/gAAAAABkAP__REPLACED__PL5lQ0U",
    keys: SubscriptionKeys {
        p256dh: "Qk5ja1ZXdlhm__REPLACED__bXY0ZmNaTl9B",
        auth: "aFU1bm__REPLACED__U9jNXJjZw",
    },
}
andyblarblar commented 1 year ago

It looks like you are double Base64 encrypting your SubscriptionInfo object.

Your code:

    let subscription_info = SubscriptionInfo::new(
        s.endpoint,
        engine.encode(s.keys.p256dh),
        engine.encode(s.keys.auth)
    );

base64 encodes the already base64 encoded text from the client.

FYI, I would highly reccommend simply Serde deserializing directly into the rust_web_push SubscriptionInfo struct, rather than rolling your own, since this one already has serde support.

Oreganon commented 1 year ago

Ah thanks a lot. Working off the example I got it to work.