From 3decf2d78d2bf33bd2204c0a5a686693b432a814 Mon Sep 17 00:00:00 2001 From: DanGould Date: Wed, 4 Sep 2024 16:54:00 -0400 Subject: [PATCH] Depend on bitcoin-ohttp Which in turn depends on bitcoin-hpke and libsecp256k1 C bindings --- Cargo.lock | 197 ++++++++-------------------------- payjoin-directory/Cargo.toml | 2 +- payjoin-directory/src/lib.rs | 2 +- payjoin/Cargo.toml | 2 +- payjoin/src/receive/v2/mod.rs | 2 +- payjoin/src/uri/url_ext.rs | 8 +- payjoin/src/v2.rs | 2 +- payjoin/tests/integration.rs | 2 +- 8 files changed, 57 insertions(+), 160 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b9b777df..29b6539d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,22 +69,8 @@ dependencies = [ "aead 0.4.3", "aes 0.7.5", "cipher 0.3.0", - "ctr 0.7.0", - "ghash 0.4.4", - "subtle", -] - -[[package]] -name = "aes-gcm" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" -dependencies = [ - "aead 0.5.2", - "aes 0.8.4", - "cipher 0.4.4", - "ctr 0.9.2", - "ghash 0.5.1", + "ctr", + "ghash", "subtle", ] @@ -242,6 +228,25 @@ dependencies = [ "serde", ] +[[package]] +name = "bitcoin-hpke" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d37a54c486727c1d1ae9cc28dcf78b6e6ba20dcb88e8c892f1437d9ce215dc8c" +dependencies = [ + "aead 0.5.2", + "chacha20poly1305 0.10.1", + "digest 0.10.7", + "generic-array", + "hkdf 0.12.4", + "hmac 0.12.1", + "rand_core", + "secp256k1", + "sha2 0.10.8", + "subtle", + "zeroize", +] + [[package]] name = "bitcoin-internals" version = "0.3.0" @@ -257,6 +262,29 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" +[[package]] +name = "bitcoin-ohttp" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87a803a4b54e44635206b53329c78c0029d0c70926288ac2f07f4bb1267546cb" +dependencies = [ + "aead 0.4.3", + "aes-gcm", + "bitcoin-hpke", + "byteorder", + "chacha20poly1305 0.8.0", + "hex", + "hkdf 0.11.0", + "lazy_static", + "log", + "rand", + "serde", + "serde_derive", + "sha2 0.9.9", + "thiserror", + "toml", +] + [[package]] name = "bitcoin-units" version = "0.1.2" @@ -649,40 +677,6 @@ dependencies = [ "cipher 0.3.0", ] -[[package]] -name = "ctr" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" -dependencies = [ - "cipher 0.4.4", -] - -[[package]] -name = "curve25519-dalek" -version = "4.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" -dependencies = [ - "cfg-if", - "cpufeatures 0.2.13", - "curve25519-dalek-derive", - "fiat-crypto", - "rustc_version", - "subtle", -] - -[[package]] -name = "curve25519-dalek-derive" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", -] - [[package]] name = "darling" version = "0.13.4" @@ -794,12 +788,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" -[[package]] -name = "fiat-crypto" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" - [[package]] name = "filetime" version = "0.2.24" @@ -973,17 +961,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" dependencies = [ "opaque-debug", - "polyval 0.5.3", -] - -[[package]] -name = "ghash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" -dependencies = [ - "opaque-debug", - "polyval 0.6.2", + "polyval", ] [[package]] @@ -1096,27 +1074,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "hpke" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e04a5933a381bb81f00b083fce6b4528e16d735dbeecbb2bdb45e0dbbf3f7e17" -dependencies = [ - "aead 0.5.2", - "aes-gcm 0.10.3", - "byteorder", - "chacha20poly1305 0.10.1", - "digest 0.10.7", - "generic-array", - "hkdf 0.12.4", - "hmac 0.12.1", - "rand_core", - "sha2 0.10.8", - "subtle", - "x25519-dalek", - "zeroize", -] - [[package]] name = "http" version = "1.1.0" @@ -1510,29 +1467,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "ohttp" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea87785aa505c77b1447f9092b1bd583402bc5d986f8f36c7963df17eef9c8f" -dependencies = [ - "aead 0.4.3", - "aes-gcm 0.9.2", - "byteorder", - "chacha20poly1305 0.8.0", - "hex", - "hkdf 0.11.0", - "hpke", - "lazy_static", - "log", - "rand", - "serde", - "serde_derive", - "sha2 0.9.9", - "thiserror", - "toml", -] - [[package]] name = "ohttp-relay" version = "0.0.8" @@ -1667,11 +1601,11 @@ dependencies = [ "bhttp", "bip21", "bitcoin", + "bitcoin-ohttp", "bitcoind", "chacha20poly1305 0.10.1", "http", "log", - "ohttp", "ohttp-relay", "once_cell", "payjoin-directory", @@ -1731,12 +1665,12 @@ dependencies = [ "anyhow", "bhttp", "bitcoin", + "bitcoin-ohttp", "futures", "http-body-util", "hyper", "hyper-rustls 0.26.0", "hyper-util", - "ohttp", "redis", "rustls 0.22.4", "tokio", @@ -1896,18 +1830,6 @@ dependencies = [ "universal-hash 0.4.0", ] -[[package]] -name = "polyval" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" -dependencies = [ - "cfg-if", - "cpufeatures 0.2.13", - "opaque-debug", - "universal-hash 0.5.1", -] - [[package]] name = "powerfmt" version = "0.2.0" @@ -2244,15 +2166,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - [[package]] name = "rustix" version = "0.38.34" @@ -2431,12 +2344,6 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" - [[package]] name = "serde" version = "1.0.208" @@ -3395,16 +3302,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "x25519-dalek" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277" -dependencies = [ - "curve25519-dalek", - "rand_core", -] - [[package]] name = "xattr" version = "1.3.1" diff --git a/payjoin-directory/Cargo.toml b/payjoin-directory/Cargo.toml index 1394c1b3..051e8a65 100644 --- a/payjoin-directory/Cargo.toml +++ b/payjoin-directory/Cargo.toml @@ -25,7 +25,7 @@ http-body-util = "0.1.2" hyper = { version = "1", features = ["http1", "server"] } hyper-rustls = { version = "0.26", optional = true } hyper-util = { version = "0.1", features = ["tokio"] } -ohttp = "0.5.1" +ohttp = { package = "bitcoin-ohttp", version = "0.6.0"} redis = { version = "0.23.3", features = ["aio", "tokio-comp"] } rustls = { version = "0.22.4", optional = true } tokio = { version = "1.12.0", features = ["full"] } diff --git a/payjoin-directory/src/lib.rs b/payjoin-directory/src/lib.rs index 13aeeee9..075a1082 100644 --- a/payjoin-directory/src/lib.rs +++ b/payjoin-directory/src/lib.rs @@ -132,7 +132,7 @@ fn init_ohttp() -> Result { use ohttp::{KeyId, SymmetricSuite}; const KEY_ID: KeyId = 1; - const KEM: Kem = Kem::X25519Sha256; + const KEM: Kem = Kem::K256Sha256; const SYMMETRIC: &[SymmetricSuite] = &[SymmetricSuite::new(Kdf::HkdfSha256, Aead::ChaCha20Poly1305)]; diff --git a/payjoin/Cargo.toml b/payjoin/Cargo.toml index 4ccf61a2..821d59de 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -30,7 +30,7 @@ chacha20poly1305 = { version = "0.10.1", optional = true } log = { version = "0.4.14"} http = { version = "1", optional = true } bhttp = { version = "=0.5.1", optional = true } -ohttp = { version = "0.5.1", optional = true } +ohttp = { package = "bitcoin-ohttp", version = "0.6.0", optional = true } serde = { version = "1.0.186", default-features = false, optional = true } reqwest = { version = "0.12", default-features = false, optional = true } rustls = { version = "0.22.4", optional = true } diff --git a/payjoin/src/receive/v2/mod.rs b/payjoin/src/receive/v2/mod.rs index 4312aa5e..ec9cd819 100644 --- a/payjoin/src/receive/v2/mod.rs +++ b/payjoin/src/receive/v2/mod.rs @@ -663,7 +663,7 @@ mod test { use ohttp::hpke::{Aead, Kdf, Kem}; use ohttp::{KeyId, SymmetricSuite}; const KEY_ID: KeyId = 1; - const KEM: Kem = Kem::X25519Sha256; + const KEM: Kem = Kem::K256Sha256; const SYMMETRIC: &[SymmetricSuite] = &[ohttp::SymmetricSuite::new(Kdf::HkdfSha256, Aead::ChaCha20Poly1305)]; diff --git a/payjoin/src/uri/url_ext.rs b/payjoin/src/uri/url_ext.rs index 12d13a7d..d7d3a55b 100644 --- a/payjoin/src/uri/url_ext.rs +++ b/payjoin/src/uri/url_ext.rs @@ -91,11 +91,11 @@ mod tests { let mut url = Url::parse("https://example.com").unwrap(); let ohttp_keys = - OhttpKeys::from_str("AQAg3WpRjS0aqAxQUoLvpas2VYjT2oIg6-3XSiB-QiYI1BAABAABAAM").unwrap(); + OhttpKeys::from_str("AQAWBG3fkg7fQCN-bafc-BEJOSnDfq8k1M9Cy1kgQZX42GVOvI0bWVAciTaJCy2A_wy7R7VxtU88xej692bv0uXgt98ABAABAAM").unwrap(); let _ = url.set_ohttp(Some(ohttp_keys.clone())); assert_eq!( url.fragment(), - Some("ohttp=AQAg3WpRjS0aqAxQUoLvpas2VYjT2oIg6-3XSiB-QiYI1BAABAABAAM") + Some("ohttp=AQAWBG3fkg7fQCN-bafc-BEJOSnDfq8k1M9Cy1kgQZX42GVOvI0bWVAciTaJCy2A_wy7R7VxtU88xej692bv0uXgt98ABAABAAM") ); assert_eq!(url.ohttp(), Some(ohttp_keys)); @@ -124,7 +124,7 @@ mod tests { // fragment is not percent encoded so `&ohttp=` is parsed as a query parameter, not a fragment parameter let uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01\ &pj=https://example.com\ - #exp=1720547781&ohttp=AQAg3WpRjS0aqAxQUoLvpas2VYjT2oIg6-3XSiB-QiYI1BAABAABAAM"; + #exp=1720547781&ohttp=AQAWBG3fkg7fQCN-bafc-BEJOSnDfq8k1M9Cy1kgQZX42GVOvI0bWVAciTaJCy2A_wy7R7VxtU88xej692bv0uXgt98ABAABAAM"; let uri = Uri::try_from(uri).unwrap().assume_checked().check_pj_supported().unwrap(); assert!(uri.extras.endpoint().ohttp().is_none()); } @@ -133,7 +133,7 @@ mod tests { fn test_valid_v2_url_fragment_on_bip21() { let uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01\ &pj=https://example.com\ - #ohttp%3DAQAg3WpRjS0aqAxQUoLvpas2VYjT2oIg6-3XSiB-QiYI1BAABAABAAM%26exp%3D1720547781"; + #ohttp%3DAQAWBG3fkg7fQCN-bafc-BEJOSnDfq8k1M9Cy1kgQZX42GVOvI0bWVAciTaJCy2A_wy7R7VxtU88xej692bv0uXgt98ABAABAAM"; let uri = Uri::try_from(uri).unwrap().assume_checked().check_pj_supported().unwrap(); assert!(uri.extras.endpoint().ohttp().is_some()); } diff --git a/payjoin/src/v2.rs b/payjoin/src/v2.rs index cf21b8e0..a8770023 100644 --- a/payjoin/src/v2.rs +++ b/payjoin/src/v2.rs @@ -351,7 +351,7 @@ mod test { use ohttp::hpke::{Aead, Kdf, Kem}; use ohttp::{KeyId, SymmetricSuite}; const KEY_ID: KeyId = 1; - const KEM: Kem = Kem::X25519Sha256; + const KEM: Kem = Kem::K256Sha256; const SYMMETRIC: &[SymmetricSuite] = &[ohttp::SymmetricSuite::new(Kdf::HkdfSha256, Aead::ChaCha20Poly1305)]; let keys = OhttpKeys(ohttp::KeyConfig::new(KEY_ID, KEM, Vec::from(SYMMETRIC)).unwrap()); diff --git a/payjoin/tests/integration.rs b/payjoin/tests/integration.rs index a46c9032..f61f8757 100644 --- a/payjoin/tests/integration.rs +++ b/payjoin/tests/integration.rs @@ -105,7 +105,7 @@ mod integration { #[tokio::test] async fn test_bad_ohttp_keys() { let bad_ohttp_keys = - OhttpKeys::from_str("AQAg3WpRjS0aqAxQUoLvpas2VYjT2oIg6-3XSiB-QiYI1BAABAABAAM") + OhttpKeys::from_str("AQAWBG3fkg7fQCN-bafc-BEJOSnDfq8k1M9Cy1kgQZX42GVOvI0bWVAciTaJCy2A_wy7R7VxtU88xej692bv0uXgt98ABAABAAM") .expect("Invalid OhttpKeys"); let (cert, key) = local_cert_key();