pimeys / rust-web-push

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

web push without pem file. #8

Closed Jarves42 closed 3 years ago

Jarves42 commented 5 years ago

I am trying to run your sample_send.rs example but problem i do have pem file but I do have private and public key. I checked your the pem file in resource folder. Creating the exact same format file with my private key is not working. I am attaching stack backtrace. Can u guide any alternative to build vapidSignature from private key so that I can use ur library?

thread 'main' panicked at 'called Result::unwrap() on an Err value: SslError', src/libcore/result.rs:997:5 stack backtrace: 0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39 1: std::sys_common::backtrace::_print at src/libstd/sys_common/backtrace.rs:71 2: std::panicking::default_hook::{{closure}} at src/libstd/sys_common/backtrace.rs:59 at src/libstd/panicking.rs:197 3: std::panicking::default_hook at src/libstd/panicking.rs:211 4: <std::panicking::begin_panic::PanicPayload as core::panic::BoxMeUp>::get at src/libstd/panicking.rs:474 5: std::panicking::continue_panic_fmt at src/libstd/panicking.rs:381 6: std::panicking::try::do_call at src/libstd/panicking.rs:308 7: ::type_id at src/libcore/panicking.rs:85 8: core::result::unwrap_failed at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libcore/macros.rs:18 9: core::result::Result<T,E>::unwrap at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libcore/result.rs:798 10: simple_send::main at examples/simple_send.rs:80 11: std::rt::lang_start::{{closure}} at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libstd/rt.rs:64 12: std::panicking::try::do_call at src/libstd/rt.rs:49 at src/libstd/panicking.rs:293 13: panic_unwind::dwarf::eh::read_encoded_pointer at src/libpanic_unwind/lib.rs:87 14: std::panicking::update_count_then_panic at src/libstd/panicking.rs:272 at src/libstd/panic.rs:388 at src/libstd/rt.rs:48 15: std::rt::lang_start at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libstd/rt.rs:64 16: simple_send::main

pimeys commented 5 years ago

Uh, this is so long ago already that I need to remember how to create the signatures... Not working on push systems anymore, so please forgive me if I don't remember everything :)

At least Mozilla is giving some examples how to create these keys. Also try to search their archives on key usage. It was very helpful when I was implementing this feature.

https://blog.mozilla.org/services/2016/04/04/using-vapid-with-webpush/

andyblarblar commented 3 years ago

Closing this issue due to inactivity. For the record, this crate can currently accept both pkcs8 and SEC1 formatted PEM keys. This may have not been true in the past, causing this error. You will need either a PEM or DER key to use payloads, as it allows for the web push API servers to verify the authenticity of push notifications, as well as encrypt the payload for secrecy. These are generally saved on disk, but could theoretically be generated on boot in a testing environment, although that would be ill advised in a production environment for a few reasons. The readme has instructions for generating these files.