~vpzom/shoved

a0bb2cbba53d4abd490b033d4daee21852375afe — Colin Reeder 1 year, 19 days ago 562caa4
very temporary things
3 files changed, 123 insertions(+), 5 deletions(-)

M Cargo.lock
M Cargo.toml
M src/main.rs
M Cargo.lock => Cargo.lock +74 -0
@@ 15,6 15,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"

[[package]]
name = "base64"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"

[[package]]
name = "base64"
version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"

[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 102,6 114,25 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
 "block-buffer",
 "crypto-common",
 "subtle",
]

[[package]]
name = "ece"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dd5463ffecc0677adcd786c4481f73b215714d4757edf2eb37a573c03d00459"
dependencies = [
 "base64 0.13.1",
 "byteorder",
 "hex",
 "hkdf",
 "lazy_static",
 "once_cell",
 "openssl",
 "serde",
 "sha2",
 "thiserror",
]

[[package]]


@@ 236,6 267,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"

[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"

[[package]]
name = "hkdf"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437"
dependencies = [
 "hmac",
]

[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
 "digest",
]

[[package]]
name = "http"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 573,10 628,23 @@ dependencies = [
]

[[package]]
name = "sha2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
dependencies = [
 "cfg-if",
 "cpufeatures",
 "digest",
]

[[package]]
name = "shoved"
version = "0.1.0"
dependencies = [
 "anyhow",
 "base64 0.21.2",
 "ece",
 "futures-util",
 "serde",
 "serde_json",


@@ 605,6 673,12 @@ dependencies = [
]

[[package]]
name = "subtle"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"

[[package]]
name = "syn"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"

M Cargo.toml => Cargo.toml +2 -0
@@ 7,6 7,8 @@ edition = "2021"

[dependencies]
anyhow = "1.0.71"
base64 = "0.21.2"
ece = "2.2.0"
futures-util = { version = "0.3.28", features = ["sink"] }
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"

M src/main.rs => src/main.rs +47 -5
@@ 1,3 1,4 @@
use base64::Engine;
use futures_util::{SinkExt, StreamExt, TryStreamExt};

mod types;


@@ 10,7 11,9 @@ enum ConnectionMessageOut {
}

#[derive(Debug)]
enum ConnectionMessageIn {}
enum ConnectionMessageIn {
    Notification { channel_id: String, data: String },
}

async fn handle_connection(
    channel_tx: tokio::sync::mpsc::UnboundedSender<ConnectionMessageIn>,


@@ 51,8 54,26 @@ async fn handle_connection(

    futures_util::try_join!(
        stream.try_for_each(|msg| {
            println!("{:?}", msg);
            futures_util::future::ok(())
            let channel_tx = channel_tx.clone();
            async move {
                println!("{:?}", msg);

                match msg {
                    types::MozillaPushMessageS2A::Notification {
                        channel_id,
                        data: Some(data),
                        ..
                    } => {
                        channel_tx.send(ConnectionMessageIn::Notification {
                            channel_id,
                            data: data.data,
                        })?;
                    }
                    _ => {}
                }

                Ok(())
            }
        }),
        async {
            while let Some(msg) = channel_rx.recv().await {


@@ 75,13 96,34 @@ async fn handle_connection(

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let (in_tx, in_rx) = tokio::sync::mpsc::unbounded_channel();
    let (in_tx, mut in_rx) = tokio::sync::mpsc::unbounded_channel();
    let (out_tx, out_rx) = tokio::sync::mpsc::unbounded_channel();
    let handle = tokio::spawn(handle_connection(in_tx, out_rx));

    let (keypair, auth_secret) = ece::generate_keypair_and_auth_secret().unwrap();

    let b64e = base64::engine::GeneralPurpose::new(
        &base64::alphabet::URL_SAFE,
        base64::engine::general_purpose::NO_PAD,
    );

    println!("{}", b64e.encode(keypair.pub_as_raw().unwrap()));
    println!("{}", b64e.encode(auth_secret));

    out_tx
        .send(ConnectionMessageOut::Register { request_id: 0 })
        .unwrap();

    handle.await;
    tokio::spawn(async move {
        while let Some(msg) = in_rx.recv().await {
            match msg {
                ConnectionMessageIn::Notification { channel_id, data } => {
                    let data = ece::decrypt(&keypair.raw_components().unwrap(), &auth_secret, &b64e.decode(&data).unwrap());
                    println!("{:?}", data);
                }
            }
        }
    });

    handle.await.unwrap().unwrap();
}