diff --git a/Cargo.lock b/Cargo.lock index 5ab8dfef..105a657d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,6 +105,16 @@ dependencies = [ "polyval 0.7.3", ] +[[package]] +name = "aes-kw" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41ac571010bd60765c56085a4f1d412012a9be2663b1a2f2b19b49318653fd0d" +dependencies = [ + "aes 0.9.3", + "const-oid 0.10.2", +] + [[package]] name = "ahash" version = "0.8.12" @@ -591,6 +601,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +[[package]] +name = "base16ct" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" + [[package]] name = "base32" version = "0.5.1" @@ -603,6 +619,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64" version = "0.22.1" @@ -1347,11 +1369,11 @@ dependencies = [ "opentelemetry-otlp", "opentelemetry-semantic-conventions", "opentelemetry_sdk", - "p256", - "p384", + "p256 0.13.2", + "p384 0.13.1", "parking_lot", "pem 4.0.0", - "pkcs8", + "pkcs8 0.10.2", "privdrop", "prometheus", "proxy-header", @@ -1365,7 +1387,7 @@ dependencies = [ "registry", "reqwest 0.13.5", "rkyv", - "rsa", + "rsa 0.9.10", "rustls", "rustls-pemfile", "rustls-pki-types", @@ -1659,6 +1681,23 @@ dependencies = [ "zeroize", ] +[[package]] +name = "crypto-bigint" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "914c195c4d7fbc5ed7f88d14cbf85914d5c664967658d43404b263913a477e82" +dependencies = [ + "cpubits", + "ctutils", + "getrandom 0.4.3", + "hybrid-array 0.4.15", + "num-traits", + "rand_core 0.10.1", + "serdect 0.4.3", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.7" @@ -1681,6 +1720,52 @@ dependencies = [ "rand_core 0.10.1", ] +[[package]] +name = "crypto-glue" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2199036d1ea8b42f94ec872d69dc641ec8b603ef12f9da7874cf8bfef419cb7" +dependencies = [ + "aes 0.9.3", + "aes-gcm 0.11.1", + "aes-kw", + "argon2 0.5.3", + "base64 0.23.1", + "cbc 0.2.1", + "cipher 0.5.2", + "const-oid 0.10.2", + "crypto-common 0.2.2", + "cts", + "der 0.8.3", + "digest 0.11.3", + "ecdsa 0.17.0", + "elliptic-curve 0.14.3", + "hex", + "hkdf 0.13.0", + "hmac 0.13.0", + "hybrid-array 0.4.15", + "kbkdf", + "md5", + "p256 0.14.0", + "p384 0.14.0", + "p521 0.14.0", + "pbkdf2", + "pkcs8 0.11.0", + "rand 0.10.3", + "rsa 0.10.0-rc.19", + "sec1 0.8.1", + "serde", + "sha1 0.11.0", + "sha2 0.11.1", + "signature 3.0.0", + "spki 0.8.1", + "subtle", + "tracing", + "uuid", + "x509-cert", + "zeroize", +] + [[package]] name = "crypto-mac" version = "0.10.0" @@ -1691,6 +1776,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "crypto-primes" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3633a51a39c69ebbaa4feaa694bd83d241e4093901c84a0963b19d9bb3f0cf8f" +dependencies = [ + "crypto-bigint 0.7.11", + "rand_core 0.10.1", +] + [[package]] name = "csv" version = "1.4.0" @@ -1731,12 +1826,22 @@ dependencies = [ ] [[package]] -name = "ctutils" -version = "0.4.3" +name = "cts" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03bb0e1cc970d482d121d9a1744999169b69a07470b3d644a7894e53fcaf4574" +checksum = "e6ae47d18aa4f3701bc9b644cf9a74a45e6eace39feabeab15864728aa1e45a9" +dependencies = [ + "cipher 0.5.2", +] + +[[package]] +name = "ctutils" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f" dependencies = [ "cmov", + "subtle", ] [[package]] @@ -1749,7 +1854,7 @@ dependencies = [ "cpufeatures 0.2.17", "curve25519-dalek-derive", "digest 0.10.7", - "fiat-crypto", + "fiat-crypto 0.2.9", "rustc_version", "subtle", "zeroize", @@ -1772,8 +1877,8 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c0cf476284b03eb6c10e78787b21c7abb7d7d43cb2f02532ba6b831ed892fa" dependencies = [ - "crypto-bigint", - "elliptic-curve", + "crypto-bigint 0.5.5", + "elliptic-curve 0.13.8", "rand_core 0.6.4", "sha3 0.10.9", "signature 2.2.0", @@ -2032,7 +2137,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ "const-oid 0.9.6", - "pem-rfc7468", + "pem-rfc7468 0.7.0", + "zeroize", +] + +[[package]] +name = "der" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a996a108feb8b427a6e12fcf6af4aa83409b79d72c15337d7741368131ee004" +dependencies = [ + "const-oid 0.10.2", + "der_derive", + "flagset", + "pem-rfc7468 1.0.0", "zeroize", ] @@ -2050,6 +2168,17 @@ dependencies = [ "rusticata-macros", ] +[[package]] +name = "der_derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59600e2c2d636fde9b65e99cc6445ac770c63d3628195ff39932b8d6d7409903" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "deranged" version = "0.5.9" @@ -2245,8 +2374,8 @@ dependencies = [ "digest 0.10.7", "num-bigint-dig", "num-traits", - "pkcs8", - "rfc6979", + "pkcs8 0.10.2", + "rfc6979 0.4.0", "sha2 0.10.9", "signature 2.2.0", "zeroize", @@ -2292,12 +2421,27 @@ version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ - "der", + "der 0.7.10", "digest 0.10.7", - "elliptic-curve", - "rfc6979", + "elliptic-curve 0.13.8", + "rfc6979 0.4.0", "signature 2.2.0", - "spki", + "spki 0.7.3", +] + +[[package]] +name = "ecdsa" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0681a4fc24c767085329728d8dfba959af91228aa4610cca4f8ce317ba46ae0" +dependencies = [ + "der 0.8.3", + "digest 0.11.3", + "elliptic-curve 0.14.3", + "rfc6979 0.6.0", + "signature 3.0.0", + "spki 0.8.1", + "zeroize", ] [[package]] @@ -2324,7 +2468,7 @@ version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ - "pkcs8", + "pkcs8 0.10.2", "signature 2.2.0", ] @@ -2355,25 +2499,47 @@ version = "0.13.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ - "base16ct", + "base16ct 0.2.0", "base64ct", - "crypto-bigint", + "crypto-bigint 0.5.5", "digest 0.10.7", - "ff", + "ff 0.13.1", "generic-array 0.14.7", - "group", + "group 0.13.0", "hkdf 0.12.4", - "pem-rfc7468", - "pkcs8", + "pem-rfc7468 0.7.0", + "pkcs8 0.10.2", "rand_core 0.6.4", - "sec1", + "sec1 0.7.3", "serde_json", - "serdect", + "serdect 0.2.0", "subtle", "tap", "zeroize", ] +[[package]] +name = "elliptic-curve" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900f37e7e18d74a2347389af6cd69e3a30d5cc9e697f40004865679aa75e9c7c" +dependencies = [ + "base16ct 1.0.0", + "crypto-bigint 0.7.11", + "crypto-common 0.2.2", + "digest 0.11.3", + "ff 0.14.0", + "group 0.14.0", + "hkdf 0.13.0", + "hybrid-array 0.4.15", + "pem-rfc7468 1.0.0", + "pkcs8 0.11.0", + "rand_core 0.10.1", + "sec1 0.8.1", + "subtle", + "zeroize", +] + [[package]] name = "email" version = "27.1.0-rc.31" @@ -2397,7 +2563,7 @@ dependencies = [ "rasn-pkix", "registry", "rkyv", - "rsa", + "rsa 0.9.10", "sequoia-openpgp", "sieve-rs", "store", @@ -2604,12 +2770,28 @@ dependencies = [ "subtle", ] +[[package]] +name = "ff" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f686ab92a9fb0eaf188f6c6c87b89490baa6fdb0db4544ba4dc47f7942489f" +dependencies = [ + "rand_core 0.10.1", + "subtle", +] + [[package]] name = "fiat-crypto" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" +[[package]] +name = "fiat-crypto" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24" + [[package]] name = "find-msvc-tools" version = "0.1.14" @@ -2633,6 +2815,12 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" +[[package]] +name = "flagset" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7ac824320a75a52197e8f2d787f6a38b6718bb6897a35142d749af3c0e8f4fe" + [[package]] name = "flate2" version = "1.1.10" @@ -3062,11 +3250,22 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ff", + "ff 0.13.1", "rand_core 0.6.4", "subtle", ] +[[package]] +name = "group" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fd1a1c7a5206c5b7a3f5a0d7ccd3ff85d0c8f5133d62a02680255b0004af5f4" +dependencies = [ + "ff 0.14.0", + "rand_core 0.10.1", + "subtle", +] + [[package]] name = "groupware" version = "27.1.0-rc.31" @@ -3114,6 +3313,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "cfg-if", + "crunchy", + "zerocopy 0.8.63", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -3399,6 +3609,8 @@ dependencies = [ "trc", "types", "utils", + "webauthn-rs", + "webauthn-rs-proto", ] [[package]] @@ -3495,6 +3707,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" dependencies = [ "ctutils", + "serde", + "subtle", "typenum", "zeroize", ] @@ -4381,7 +4595,7 @@ dependencies = [ "mail-builder 1.0.0", "mail-parser", "nlp", - "p256", + "p256 0.13.2", "rand 0.10.3", "registry", "reqwest 0.13.5", @@ -4557,6 +4771,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "kbkdf" +version = "0.1.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ac93c9768b8d587407881c98b0c3a5d3e3049daa73408ebe5bfb1ab1cb9c84" +dependencies = [ + "digest 0.11.3", +] + [[package]] name = "keccak" version = "0.1.6" @@ -4906,7 +5129,7 @@ dependencies = [ "quick-xml 0.42.0", "rand 0.10.3", "rkyv", - "rsa", + "rsa 0.9.10", "rustls-pki-types", "serde", "serde_json", @@ -5760,38 +5983,79 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" dependencies = [ - "ecdsa", - "elliptic-curve", - "primeorder", + "ecdsa 0.16.9", + "elliptic-curve 0.13.8", + "primeorder 0.13.6", "sha2 0.10.9", ] +[[package]] +name = "p256" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c9239b2dbc807adbbe147e8cf72ea7450c3a0aabe62cb8e75ff4ec22e1f72a" +dependencies = [ + "ecdsa 0.17.0", + "elliptic-curve 0.14.3", + "primefield", + "primeorder 0.14.0", + "sha2 0.11.1", +] + [[package]] name = "p384" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe42f1670a52a47d448f14b6a5c61dd78fce51856e68edaa38f7ae3a46b8d6b6" dependencies = [ - "ecdsa", - "elliptic-curve", - "primeorder", + "ecdsa 0.16.9", + "elliptic-curve 0.13.8", + "primeorder 0.13.6", "sha2 0.10.9", ] +[[package]] +name = "p384" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d17b851e6b3e378ab4ecb07fa2ed23f4d15f075735f8fec9fa1e7bdce5f8301f" +dependencies = [ + "ecdsa 0.17.0", + "elliptic-curve 0.14.3", + "fiat-crypto 0.3.0", + "primefield", + "primeorder 0.14.0", + "sha2 0.11.1", +] + [[package]] name = "p521" version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fc9e2161f1f215afdfce23677034ae137bbd45016a880c2eb3ba8eb95f085b2" dependencies = [ - "base16ct", - "ecdsa", - "elliptic-curve", - "primeorder", + "base16ct 0.2.0", + "ecdsa 0.16.9", + "elliptic-curve 0.13.8", + "primeorder 0.13.6", "rand_core 0.6.4", "sha2 0.10.9", ] +[[package]] +name = "p521" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ad64cc32c2dc466317c12ee5853e61f159f9eab1fe7efade0395dc2e7b43449" +dependencies = [ + "base16ct 1.0.0", + "ecdsa 0.17.0", + "elliptic-curve 0.14.3", + "primefield", + "primeorder 0.14.0", + "sha2 0.11.1", +] + [[package]] name = "parking" version = "2.2.1" @@ -5914,6 +6178,15 @@ dependencies = [ "base64ct", ] +[[package]] +name = "pem-rfc7468" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.2" @@ -6090,9 +6363,36 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" dependencies = [ - "der", - "pkcs8", - "spki", + "der 0.7.10", + "pkcs8 0.10.2", + "spki 0.7.3", +] + +[[package]] +name = "pkcs1" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6250dd7321adbe93d12b750aee0ced159fd13e77f625edcdf1cb6f83cd99f650" +dependencies = [ + "der 0.8.3", + "spki 0.8.1", +] + +[[package]] +name = "pkcs5" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63d440a804ec8d6fafbb6b84471e013286658d373248927692ab3366686220ca" +dependencies = [ + "aes 0.9.3", + "aes-gcm 0.11.1", + "cbc 0.2.1", + "der 0.8.3", + "pbkdf2", + "rand_core 0.10.1", + "scrypt", + "sha2 0.11.1", + "spki 0.8.1", ] [[package]] @@ -6101,8 +6401,20 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der", - "spki", + "der 0.7.10", + "spki 0.7.3", +] + +[[package]] +name = "pkcs8" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7" +dependencies = [ + "der 0.8.3", + "pkcs5", + "rand_core 0.10.1", + "spki 0.8.1", ] [[package]] @@ -6314,13 +6626,40 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "primefield" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c555a6e4eb7d4e158fcb028c835c3b8642206ddc279b5c6b202ef9a8bdb592f4" +dependencies = [ + "crypto-bigint 0.7.11", + "crypto-common 0.2.2", + "ff 0.14.0", + "rand_core 0.10.1", + "subtle", + "zeroize", +] + [[package]] name = "primeorder" version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" dependencies = [ - "elliptic-curve", + "elliptic-curve 0.13.8", +] + +[[package]] +name = "primeorder" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c9f42978c78a00e3d68f69fc03e57a234debae69da4020a4fb588fcdcd07b06" +dependencies = [ + "elliptic-curve 0.14.3", + "once_cell", + "primefield", + "serdect 0.4.3", + "wnaf", ] [[package]] @@ -6748,6 +7087,16 @@ dependencies = [ "rand_core 0.9.5", ] +[[package]] +name = "rand_chacha" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e6af7f3e25ded52c41df4e0b1af2d047e45896c2f3281792ed68a1c243daedb" +dependencies = [ + "ppv-lite86", + "rand_core 0.10.1", +] + [[package]] name = "rand_core" version = "0.5.1" @@ -7157,6 +7506,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "rfc6979" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a459cddafb3fe76b31fd8f1108007566c40301feb64dc7b54656eb7388172b" +dependencies = [ + "crypto-bigint 0.7.11", + "hmac 0.13.0", +] + [[package]] name = "ring" version = "0.17.14" @@ -7281,16 +7640,35 @@ dependencies = [ "num-bigint-dig", "num-integer", "num-traits", - "pkcs1", - "pkcs8", + "pkcs1 0.7.5", + "pkcs8 0.10.2", "rand_core 0.6.4", "sha2 0.10.9", "signature 2.2.0", - "spki", + "spki 0.7.3", "subtle", "zeroize", ] +[[package]] +name = "rsa" +version = "0.10.0-rc.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33405e321e16ef941ca66e254f6904c3aafd3c7ff001fb88bf11c73eb75c2b85" +dependencies = [ + "const-oid 0.10.2", + "crypto-bigint 0.7.11", + "crypto-primes", + "digest 0.11.3", + "pkcs1 0.8.0", + "pkcs8 0.11.0", + "rand_core 0.10.1", + "sha2 0.11.1", + "signature 3.0.0", + "spki 0.8.1", + "zeroize", +] + [[package]] name = "rsqlite-vfs" version = "0.1.1" @@ -7667,11 +8045,25 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ - "base16ct", - "der", + "base16ct 0.2.0", + "der 0.7.10", "generic-array 0.14.7", - "pkcs8", - "serdect", + "pkcs8 0.10.2", + "serdect 0.2.0", + "subtle", + "zeroize", +] + +[[package]] +name = "sec1" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56d437c2f19203ce5f7122e507831de96f3d2d4d3be5af44a0b0a09d8a80e4d" +dependencies = [ + "base16ct 1.0.0", + "ctutils", + "der 0.8.3", + "hybrid-array 0.4.15", "subtle", "zeroize", ] @@ -7742,7 +8134,7 @@ dependencies = [ "dyn-clone", "eax", "ecb", - "ecdsa", + "ecdsa 0.16.9", "ed25519", "ed25519-dalek", "getrandom 0.2.17", @@ -7759,14 +8151,14 @@ dependencies = [ "num-bigint-dig", "num-integer", "ocb3", - "p256", - "p384", - "p521", + "p256 0.13.2", + "p384 0.13.1", + "p521 0.13.3", "rand 0.10.3", "regex", "regex-syntax", "ripemd", - "rsa", + "rsa 0.9.10", "sha1collisiondetection", "sha2 0.10.9", "sha3 0.10.9", @@ -7798,6 +8190,16 @@ dependencies = [ "serde_core", ] +[[package]] +name = "serde_cbor_2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aec2709de9078e077090abd848e967abab63c9fb3fdb5d4799ad359d8d482c" +dependencies = [ + "half", + "serde", +] + [[package]] name = "serde_core" version = "1.0.229" @@ -7939,7 +8341,17 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a84f14a19e9a014bb9f4512488d9829a68e04ecabffb0f9904cd1ace94598177" dependencies = [ - "base16ct", + "base16ct 0.2.0", + "serde", +] + +[[package]] +name = "serdect" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66cf8fedced2fcf12406bcb34223dffb92eaf34908ede12fed414c82b7f00b3e" +dependencies = [ + "base16ct 1.0.0", "serde", ] @@ -7994,7 +8406,7 @@ dependencies = [ "mail-parser", "memory-stats", "nlp", - "p256", + "p256 0.13.2", "psl", "registry", "reqwest 0.13.5", @@ -8210,6 +8622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d567dcbaf0049cb8ac2608a76cd95ff9e4412e1899d389ee400918ca7537f5" dependencies = [ "digest 0.11.3", + "rand_core 0.10.1", ] [[package]] @@ -8277,7 +8690,7 @@ dependencies = [ "digest 0.10.7", "hmac 0.12.1", "hybrid-array 0.3.1", - "pkcs8", + "pkcs8 0.10.2", "rand_core 0.6.4", "sha2 0.10.9", "sha3 0.10.9", @@ -8441,7 +8854,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", - "der", + "der 0.7.10", +] + +[[package]] +name = "spki" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef958a98b9d5da290cfc78946e9f3e61e1e62a18db0d92cac0b83cc161491a9" +dependencies = [ + "base64ct", + "der 0.8.3", + "digest 0.11.3", + "sha2 0.11.1", ] [[package]] @@ -8829,6 +9254,7 @@ dependencies = [ "rcgen", "registry", "reqwest 0.13.5", + "ring", "rkyv", "rust-s3", "rustls", @@ -8996,6 +9422,27 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "tls_codec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de2e01245e2bb89d6f05801c564fa27624dbd7b1846859876c7dad82e90bf6b" +dependencies = [ + "tls_codec_derive", + "zeroize", +] + +[[package]] +name = "tls_codec_derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d2e76690929402faae40aebdda620a2c0e25dd6d3b9afe48867dfd95991f4bd" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "token-cell" version = "2.1.1" @@ -9941,6 +10388,71 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webauthn-attestation-ca" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29cf6bdd3a9dba27c82ccb27df26fe7d98d7593c0c45ddddf85166a117b50301" +dependencies = [ + "crypto-glue", + "serde", + "serde_with", + "tracing", + "uuid", +] + +[[package]] +name = "webauthn-rs" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13a354e6b2ef6edc62835901fc18dd413b1370d624c8cd1aa328493bd809249b" +dependencies = [ + "serde", + "tracing", + "url", + "uuid", + "webauthn-rs-core", +] + +[[package]] +name = "webauthn-rs-core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d13e555c106095051abd70415b88546a0d3757a7990e05b4659b4fba19e46ac" +dependencies = [ + "base64 0.21.7", + "crypto-glue", + "der-parser", + "hex", + "nom", + "rand 0.10.3", + "rand_chacha 0.10.0", + "serde", + "serde_cbor_2", + "serde_json", + "serde_with", + "thiserror 1.0.69", + "tracing", + "url", + "uuid", + "webauthn-attestation-ca", + "webauthn-rs-proto", + "x509-parser", +] + +[[package]] +name = "webauthn-rs-proto" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5555714098cd069e3c8b31e58ac14250b9ae185e949c21416bccb55ce8ac8a5c" +dependencies = [ + "base64 0.21.7", + "serde", + "serde_json", + "serde_with", + "url", +] + [[package]] name = "webpki-root-certs" version = "1.0.12" @@ -10289,6 +10801,18 @@ version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" +[[package]] +name = "wnaf" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "795ca18b3fdb5e62bf982199278341ddcf7ebf7d32e25e212ad05d496e95f6fa" +dependencies = [ + "ff 0.14.0", + "group 0.14.0", + "hybrid-array 0.4.15", + "primefield", +] + [[package]] name = "writeable" version = "0.6.4" @@ -10318,6 +10842,20 @@ dependencies = [ "zeroize", ] +[[package]] +name = "x509-cert" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "105ef4642d9cb137ef83d623d0e4bf08b8adf69e9918ca904a174adb6d3d038b" +dependencies = [ + "const-oid 0.10.2", + "der 0.8.3", + "sha1 0.11.0", + "signature 3.0.0", + "spki 0.8.1", + "tls_codec", +] + [[package]] name = "x509-parser" version = "0.18.1" @@ -10827,7 +11365,7 @@ dependencies = [ "lz4_flex 0.10.0", "rand 0.8.8", "ringbuffer-spsc", - "rsa", + "rsa 0.9.10", "serde", "sha3 0.10.9", "tokio", @@ -10943,6 +11481,7 @@ version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" dependencies = [ + "serde", "zeroize_derive", ] diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 01fc1ff1..76edbb35 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -150,6 +150,8 @@ pub const KV_PORT_REACHABILITY: u8 = 200; pub const KV_OAUTH_DEVICE: u8 = 201; // inbuxa: K-S4: revoked OAuth tokens, one list per account pub const KV_OAUTH_REVOKED: u8 = 202; +// inbuxa: passkeys: a registration or sign-in between its two steps +pub const KV_PASSKEY_CEREMONY: u8 = 203; #[derive(Clone)] pub struct Server { diff --git a/crates/features/src/passkey/mod.rs b/crates/features/src/passkey/mod.rs index 5011b704..dbea9802 100644 --- a/crates/features/src/passkey/mod.rs +++ b/crates/features/src/passkey/mod.rs @@ -11,8 +11,8 @@ //! - `p` + account id + number: the passkey's `Passkey` record. //! - `c` + credential id: the account and number it belongs to, so sign-in //! finds a passkey without loading accounts. -//! - `h` + account id: the account's user handle, 32 random bytes the -//! authenticator keeps as the user id. +//! - `h` + account id: the account's user handle, 16 random bytes the +//! authenticator keeps as the user id (a UUID, as webauthn-rs wants it). //! - `u` + user handle: the account it belongs to. //! - `t` + SHA-256 of a registration ticket: the pending passkey it opens //! (PK-6). @@ -46,7 +46,7 @@ pub const TICKET_SECONDS: u64 = 600; /// The longest name (PK-5). pub const MAX_NAME: usize = 64; /// The length of a user handle. -pub const HANDLE_LEN: usize = 32; +pub const HANDLE_LEN: usize = 16; const CREATE_ATTEMPTS: usize = 5; #[derive(Debug, Clone, Copy, PartialEq, Eq, SerdeSerialize, SerdeDeserialize)] @@ -85,7 +85,8 @@ pub struct Passkey { /// The authenticator's credential id. #[serde(default)] pub credential_id: Vec, - /// The public key, as COSE. + /// The credential as the WebAuthn library keeps it (JSON): the COSE + /// public key, the counter and the flags it checks at sign-in. #[serde(default)] pub public_key: Vec, #[serde(default)] @@ -380,6 +381,81 @@ pub async fn account_of_handle(data: &Store, handle: &[u8]) -> trc::Result trc::Result> { + if let Some(handle) = user_handle(data, account_id).await? { + return Ok(handle); + } + let record = class(KIND_HANDLE, &account_id.to_be_bytes()); + let mut batch = BatchBuilder::new(); + batch.assert_value(record.clone(), AssertValue::None); + batch.set(record, fresh.to_vec()); + batch.set( + class(KIND_HANDLE_ACCOUNT, &fresh), + account_id.to_be_bytes().to_vec(), + ); + match data.write(batch.build_all()).await { + Ok(_) => Ok(fresh.to_vec()), + Err(err) + if matches!( + err.as_ref(), + trc::EventType::Store(trc::StoreEvent::AssertValueFailed) + ) => + { + user_handle(data, account_id) + .await? + .ok_or_else(|| err.caused_by(trc::location!())) + } + Err(err) => Err(err.caused_by(trc::location!())), + } +} + +pub enum Activated { + Done(Passkey), + /// The credential id is already registered, to this or another account. + Taken, +} + +/// Finishes a registration (PK-7): the pending passkey turns active with +/// what the authenticator gave, its credential id is indexed, and the ticket +/// is spent. A credential id registered before is refused. +pub async fn activate(data: &Store, ticket: &str, passkey: Passkey) -> trc::Result { + let credential = class(KIND_CREDENTIAL, &passkey.credential_id); + if passkey.credential_id.is_empty() + || by_credential(data, &passkey.credential_id).await?.is_some() + { + return Ok(Activated::Taken); + } + let mut batch = BatchBuilder::new(); + batch.assert_value(credential.clone(), AssertValue::None); + batch.set( + credential, + pair(passkey.account_id, passkey.number).to_vec(), + ); + batch.set( + class(KIND_PASSKEY, &pair(passkey.account_id, passkey.number)), + to_json(&passkey)?, + ); + batch.clear(class(KIND_TICKET, &ticket_hash(ticket))); + match data.write(batch.build_all()).await { + Ok(_) => Ok(Activated::Done(passkey)), + Err(err) + if matches!( + err.as_ref(), + trc::EventType::Store(trc::StoreEvent::AssertValueFailed) + ) => + { + Ok(Activated::Taken) + } + Err(err) => Err(err.caused_by(trc::location!())), + } +} + /// How many times the account's passkeys were removed (PK-15). pub async fn epoch(data: &Store, account_id: u32) -> trc::Result { Ok(data diff --git a/crates/http/Cargo.toml b/crates/http/Cargo.toml index 23922f32..839db243 100644 --- a/crates/http/Cargo.toml +++ b/crates/http/Cargo.toml @@ -40,6 +40,8 @@ form-data = { version = "0.6.0", features = ["sync"], default-features = false } mime = "0.3.17" percent-encoding = "2.3.2" hashify = { version = "0.2" } +webauthn-rs = { version = "0.6.2", features = ["danger-allow-state-serialisation", "danger-credential-internals", "conditional-ui"] } # inbuxa: passkeys +webauthn-rs-proto = "0.6.2" # inbuxa: passkeys [dev-dependencies] flate2 = "1.1" diff --git a/crates/http/src/api/mod.rs b/crates/http/src/api/mod.rs index 76f87f2e..8acf8548 100644 --- a/crates/http/src/api/mod.rs +++ b/crates/http/src/api/mod.rs @@ -11,7 +11,8 @@ pub mod diagnose; use crate::{ api::diagnose::{DeliveryStage, parse_delivery_target, spawn_delivery_diagnose}, auth::{ - authenticate::Authenticator, oauth::auth::OAuthApiHandler, permissions::AccountApiHandler, + authenticate::Authenticator, oauth::auth::OAuthApiHandler, + passkey::PasskeyRegistrationHandler, permissions::AccountApiHandler, }, }; use common::{ @@ -74,6 +75,16 @@ impl ManagementApi for Server { )) .await } + // inbuxa: passkeys: the registration page's two steps (PK-6 to PK-8) + "passkey" if is_post && path.get(1).copied() == Some("register") => { + self.is_http_anonymous_request_allowed(session.remote_ip) + .await?; + Box::pin(self.handle_passkey_registration( + session, + body.ok_or_else(|| trc::LimitEvent::SizeRequest.into_err())?, + )) + .await + } "calendar" if is_post && path.get(1).copied() == Some("rsvp") diff --git a/crates/http/src/auth/mod.rs b/crates/http/src/auth/mod.rs index fae13e08..ff62293f 100644 --- a/crates/http/src/auth/mod.rs +++ b/crates/http/src/auth/mod.rs @@ -8,5 +8,6 @@ pub mod authenticate; pub mod oauth; +pub mod passkey; // inbuxa: passkeys pub mod permissions; pub mod token_only; diff --git a/crates/http/src/auth/passkey.rs b/crates/http/src/auth/passkey.rs new file mode 100644 index 00000000..0b2ecea0 --- /dev/null +++ b/crates/http/src/auth/passkey.rs @@ -0,0 +1,356 @@ +/* + * SPDX-FileCopyrightText: 2026 Coffey Labs LLC + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +//! inbuxa: passkey registration (passkeys spec, PK-6 to PK-8). +//! +//! `inbuxa:Passkey/set` create hands back a URL to `/passkey/register` with +//! a single-use ticket. That page posts here twice: +//! +//! 1. `start`, with the ticket and the account's password (and TOTP code +//! when it has one). The answer is the options for the browser's +//! `navigator.credentials.create`. A stolen session token can start a +//! registration, but without the password it can't get this far (PK-8). +//! 2. `finish`, with the ticket and what the browser made. The passkey +//! turns active (PK-7). +//! +//! What `start` began waits in the in-memory store under the ticket, so any +//! node can answer `finish`, and it's deleted as it's read: it's good once. + +use common::{ + KV_PASSKEY_CEREMONY, Server, + auth::{AccessToken, AuthRequest}, +}; +use directory::Credentials; +use http_proto::{HttpResponse, HttpSessionData, JsonResponse, ToHttpResponse}; +use inbuxa_features::passkey::{self, Activated, HANDLE_LEN, Passkey}; +use serde::{Deserialize, Serialize}; +use store::{ + dispatch::lookup::KeyValue, + rand::{RngExt, rng}, + write::now, +}; +use trc::AddContext; +use webauthn_rs::prelude::{ + CreationChallengeResponse, Credential, CredentialID, PasskeyRegistration, + RegisterPublicKeyCredential, Url, Uuid, Webauthn, WebauthnBuilder, +}; +use webauthn_rs_proto::ResidentKeyRequirement; + +/// How long the browser has between `start` and `finish`. +const CEREMONY_SECONDS: u64 = 300; + +#[derive(Debug, Deserialize)] +#[serde(tag = "step", rename_all = "camelCase")] +pub enum RegisterRequest { + #[serde(rename_all = "camelCase")] + Start { + ticket: String, + password: String, + #[serde(default)] + mfa_token: Option, + }, + #[serde(rename_all = "camelCase")] + Finish { + ticket: String, + credential: Box, + }, +} + +#[derive(Debug, Serialize)] +#[serde(tag = "type", rename_all = "camelCase")] +pub enum RegisterResponse { + /// The options for `navigator.credentials.create`. + #[serde(rename_all = "camelCase")] + Options { + name: String, + account_name: String, + options: Box, + }, + #[serde(rename_all = "camelCase")] + Registered { + name: String, + }, + /// The ticket is unknown, used or out of time. + Expired, + MfaRequired, + /// The password or code was wrong. + Failure, + /// The authenticator's answer didn't check out, or that passkey is + /// already registered. + #[serde(rename_all = "camelCase")] + Refused { + reason: String, + }, +} + +/// What waits between `start` and `finish`. +#[derive(Serialize, Deserialize)] +struct Ceremony { + account_id: u32, + number: u32, + rp_id: String, + state: PasskeyRegistration, +} + +/// The WebAuthn relying party for this server (PK-3): the host of its public +/// HTTPS URL, which is also the only origin it accepts. +pub fn relying_party(server: &Server) -> trc::Result<(Webauthn, String)> { + let rp_id = jmap::inbuxa::passkey::current_rp_id(server); + let origin = Url::parse(&server.core.network.http.url_https).map_err(|err| { + trc::AuthEvent::Error + .into_err() + .details("The server's public URL isn't a URL.") + .reason(err) + })?; + let webauthn = WebauthnBuilder::new(&rp_id, &origin) + .and_then(|builder| builder.rp_name("inbuxa").build()) + .map_err(|err| { + trc::AuthEvent::Error + .into_err() + .details("Passkeys need the server's public URL to name a host.") + .reason(err) + })?; + Ok((webauthn, rp_id)) +} + +fn ceremony_key(ticket: &str) -> Vec { + KeyValue::<()>::build_key(KV_PASSKEY_CEREMONY, passkey::ticket_hash(ticket)) +} + +pub trait PasskeyRegistrationHandler: Sync + Send { + fn handle_passkey_registration( + &self, + session: &HttpSessionData, + body: Vec, + ) -> impl Future> + Send; +} + +impl PasskeyRegistrationHandler for Server { + async fn handle_passkey_registration( + &self, + session: &HttpSessionData, + body: Vec, + ) -> trc::Result { + let request = serde_json::from_slice::(&body).map_err(|err| { + trc::EventType::Resource(trc::ResourceEvent::BadParameters).from_json_error(err) + })?; + let response = match request { + RegisterRequest::Start { + ticket, + password, + mfa_token, + } => start(self, session, &ticket, password, mfa_token).await?, + RegisterRequest::Finish { ticket, credential } => { + finish(self, &ticket, &credential).await? + } + }; + Ok(JsonResponse::new(response).no_cache().into_http_response()) + } +} + +async fn start( + server: &Server, + session: &HttpSessionData, + ticket: &str, + password: String, + mfa_token: Option, +) -> trc::Result { + let Some(pending) = passkey::by_ticket(server.store(), ticket, now()).await? else { + return Ok(RegisterResponse::Expired); + }; + let account = server + .account(pending.account_id) + .await + .caused_by(trc::location!())?; + + // PK-8: the password (and code) first. The sign-in limits and the + // failure counting are the ones every sign-in goes through. + let access_token: AccessToken = match server + .authenticate(&AuthRequest { + credentials: Credentials::Basic { + username: account.name.to_string(), + secret: password, + mfa_token, + }, + session_id: session.session_id, + remote_ip: session.remote_ip, + }) + .await + { + Ok(access_token) => access_token, + Err(err) => { + return match *err.as_ref() { + trc::EventType::Auth(trc::AuthEvent::MfaRequired) => { + trc::error!(err.span_id(session.session_id)); + Ok(RegisterResponse::MfaRequired) + } + trc::EventType::Auth(_) | trc::EventType::Security(_) => { + trc::error!(err.span_id(session.session_id)); + Ok(RegisterResponse::Failure) + } + _ => Err(err), + }; + } + }; + if access_token.account_id() != pending.account_id { + return Ok(RegisterResponse::Failure); + } + + let (webauthn, rp_id) = relying_party(server)?; + let fresh = rng().random::<[u8; HANDLE_LEN]>(); + let handle = passkey::ensure_user_handle(server.store(), pending.account_id, fresh).await?; + let user_id = Uuid::from_slice(&handle).map_err(|err| { + trc::StoreEvent::DataCorruption + .into_err() + .details("Invalid passkey user handle") + .reason(err) + })?; + // Registering the same authenticator twice is refused by the browser + let exclude = passkey::all(server.store(), pending.account_id) + .await? + .into_iter() + .filter(|p| !p.credential_id.is_empty()) + .map(|p| CredentialID::from(p.credential_id)) + .collect::>(); + let display_name = account + .description + .as_deref() + .filter(|name| !name.trim().is_empty()) + .unwrap_or(&account.name); + let (mut options, state) = webauthn + .start_passkey_registration( + user_id, + &account.name, + display_name, + (!exclude.is_empty()).then_some(exclude), + ) + .map_err(|err| { + trc::AuthEvent::Error + .into_err() + .details("Failed to start a passkey registration") + .reason(err) + })?; + + // PK-1: discoverable, so the login page can offer it before anyone + // types a name. The library leaves it optional. + let selection = options + .public_key + .authenticator_selection + .get_or_insert_with(Default::default); + selection.resident_key = Some(ResidentKeyRequirement::Required); + selection.require_resident_key = true; + + let ceremony = serde_json::to_string(&Ceremony { + account_id: pending.account_id, + number: pending.number, + rp_id, + state, + }) + .map_err(|err| { + trc::StoreEvent::UnexpectedError + .into_err() + .details("Failed to serialize a passkey registration") + .reason(err) + })?; + let left = pending.ticket_expires.saturating_sub(now()).max(1); + server + .in_memory_store() + .key_set( + KeyValue::new(ceremony_key(ticket), ceremony.into_bytes()) + .expires(left.min(CEREMONY_SECONDS)), + ) + .await?; + + Ok(RegisterResponse::Options { + name: pending.name, + account_name: account.name.to_string(), + options: Box::new(options), + }) +} + +async fn finish( + server: &Server, + ticket: &str, + credential: &RegisterPublicKeyCredential, +) -> trc::Result { + // Good once: read and deleted + let key = ceremony_key(ticket); + let Some(ceremony) = server + .in_memory_store() + .key_get::(key.clone()) + .await? + else { + return Ok(RegisterResponse::Expired); + }; + server.in_memory_store().key_delete(key).await?; + let ceremony = serde_json::from_str::(&ceremony).map_err(|err| { + trc::StoreEvent::DataCorruption + .into_err() + .details("Invalid passkey registration") + .reason(err) + })?; + let Some(pending) = passkey::by_ticket(server.store(), ticket, now()) + .await? + .filter(|p| p.account_id == ceremony.account_id && p.number == ceremony.number) + else { + return Ok(RegisterResponse::Expired); + }; + + let (webauthn, rp_id) = relying_party(server)?; + if rp_id != ceremony.rp_id { + return Ok(RegisterResponse::Expired); + } + let made = match webauthn.finish_passkey_registration(credential, &ceremony.state) { + Ok(made) => made, + Err(err) => { + trc::event!( + Auth(trc::AuthEvent::Failed), + AccountId = pending.account_id, + Details = "Passkey registration refused", + Reason = err.to_string(), + ); + return Ok(RegisterResponse::Refused { + reason: "The passkey couldn't be checked. Try again.".to_string(), + }); + } + }; + let public_key = serde_json::to_vec(&made).map_err(|err| { + trc::StoreEvent::UnexpectedError + .into_err() + .details("Failed to serialize a passkey") + .reason(err) + })?; + // The attestation isn't asked for (PK-2), so there's no AAGUID to keep + let backed_up = Credential::from(made.clone()).backup_state; + let transports = credential + .response + .transports + .iter() + .flatten() + .filter_map(|t| serde_json::to_value(t).ok()) + .filter_map(|t| t.as_str().map(str::to_string)) + .collect(); + + let name = pending.name.clone(); + let active = Passkey { + state: passkey::State::Active, + ticket_expires: 0, + rp_id, + credential_id: made.cred_id().to_vec(), + public_key, + sign_count: 0, + transports, + backed_up, + aaguid: Vec::new(), + ..pending + }; + match passkey::activate(server.store(), ticket, active).await? { + Activated::Done(_) => Ok(RegisterResponse::Registered { name }), + Activated::Taken => Ok(RegisterResponse::Refused { + reason: "That passkey is already registered.".to_string(), + }), + } +} diff --git a/crates/http/src/request.rs b/crates/http/src/request.rs index b7c7d7b6..dcffe90a 100644 --- a/crates/http/src/request.rs +++ b/crates/http/src/request.rs @@ -62,6 +62,12 @@ static RSVP_PAGE: &[u8] = include_bytes!(concat!( "/../../resources/html-templates/calendar-rsvp.html.min.gz" )); +// inbuxa: passkeys: where a passkey is registered (PK-6) +static PASSKEY_PAGE: &[u8] = include_bytes!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../resources/html-templates/passkey.html.min.gz" +)); + static LOGIN_PAGE: &[u8] = include_bytes!(concat!( env!("CARGO_MANIFEST_DIR"), "/../../resources/html-templates/login.html.min.gz" @@ -681,6 +687,12 @@ impl ParseHttp for Server { } } } + "passkey" if path.next() == Some("register") => { + return Ok(HttpResponse::new(StatusCode::OK) + .with_content_type("text/html; charset=utf-8") + .with_header(CONTENT_ENCODING, "gzip") + .with_binary_body(PASSKEY_PAGE)); + } "login" | "device" => { return Ok(HttpResponse::new(StatusCode::OK) .with_content_type("text/html; charset=utf-8") @@ -981,7 +993,7 @@ mod tests { use flate2::read::GzDecoder; use std::io::Read; - const PAGES: [(&str, &[u8], &str); 2] = [ + const PAGES: [(&str, &[u8], &str); 3] = [ ( "calendar-rsvp.html", super::RSVP_PAGE, @@ -990,6 +1002,14 @@ mod tests { "/../../resources/html-templates/calendar-rsvp.html.min" )), ), + ( + "passkey.html", + super::PASSKEY_PAGE, + include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../resources/html-templates/passkey.html.min" + )), + ), ( "login.html", super::LOGIN_PAGE, diff --git a/docs/spec/features/passkeys.md b/docs/spec/features/passkeys.md index 3528d7ab..75360c96 100644 --- a/docs/spec/features/passkeys.md +++ b/docs/spec/features/passkeys.md @@ -88,7 +88,8 @@ passwords. - **PK-1.** Registration and sign-in use discoverable credentials (`residentKey: required`) with user verification required. Attestation is - `none`. Algorithms: ES256, EdDSA, RS256, in that order. + `none`. Algorithms: ES256, ES384, RS256, in that order: the set the + WebAuthn library (webauthn-rs) calls tested. EdDSA waits until it does. - **PK-2.** The origin of every ceremony must be `https://` with a host that equals the relying-party id or ends with `.` plus it, and is one of the server's own HTTP hostnames. Anything else is refused. @@ -263,7 +264,13 @@ Building, one PR each: default), removal ending the account's sessions through the credential version, and account deletion. Pending ones expire after 10 minutes. The limit is fixed at 10 until the settings arrive (step 4). -2. The registration page. +2. The registration page: `/passkey/register` served by the server, and + `POST /api/passkey/register` with a `start` step (ticket and password, + plus the TOTP code when the account has one; anonymous, limited like the + other sign-in requests) and a `finish` step. What `start` began waits in + the in-memory store for up to 5 minutes and is good once. Until sign-in + with a passkey exists (step 3), the page asks for the password only; the + "or an active passkey" of PK-8 comes with it. 3. Sign-in in the authorization-code flow, with autofill. 4. The device flow, the settings and policy, and the sign-in events. diff --git a/resources/html-templates/passkey.html b/resources/html-templates/passkey.html new file mode 100644 index 00000000..4895bb91 --- /dev/null +++ b/resources/html-templates/passkey.html @@ -0,0 +1,531 @@ + + + + + + + + + Add a passkey · inbuxa + + + + + +
+
+ +
+

Add a passkey

+

Confirm it's you, then create the passkey on this device.

+ + + +
+ +
+ + +
+ + +
+
+ + + + + diff --git a/resources/html-templates/passkey.html.min b/resources/html-templates/passkey.html.min new file mode 100644 index 00000000..752f1e3f --- /dev/null +++ b/resources/html-templates/passkey.html.min @@ -0,0 +1,481 @@ + + + + + + + +Add a passkey · inbuxa + + + + +
+
+ +
+

Add a passkey

+

Confirm it's you, then create the passkey on this device.

+ +
+ +
+ + +
+ + +
+
+ + + diff --git a/resources/html-templates/passkey.html.min.gz b/resources/html-templates/passkey.html.min.gz new file mode 100644 index 00000000..c1e8fb06 Binary files /dev/null and b/resources/html-templates/passkey.html.min.gz differ diff --git a/tests/Cargo.toml b/tests/Cargo.toml index ddff2ffb..3abe76ea 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -87,6 +87,7 @@ dns-update = { version = "0.6", features = ["test_provider"] } x509-parser = "0.18" rcgen = "0.14" sha2 = "0.11" +ring = "0.17" # inbuxa: a software authenticator for the passkey tests zip = "8.6" # inbuxa: reading legal hold exports time = "0.3" testcontainers = { version = "0.28", features = ["reusable-containers"] } diff --git a/tests/src/system/passkeys.rs b/tests/src/system/passkeys.rs index cd205271..eb2fe750 100644 --- a/tests/src/system/passkeys.rs +++ b/tests/src/system/passkeys.rs @@ -4,15 +4,27 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -//! `inbuxa:Passkey` management (passkeys spec, PK-5, PK-14 to PK-17): -//! starting a registration, the limit per account, renaming, removing, who -//! reaches whose passkeys, and the audit log. +//! Passkeys (passkeys spec): `inbuxa:Passkey` management (PK-5, PK-14 to +//! PK-17): starting a registration, the limit per account, renaming, +//! removing, who reaches whose passkeys, and the audit log. Registration on +//! the server's page (PK-6 to PK-8), with a software authenticator. use crate::utils::{ account::Account, + http::HttpRequest, server::{TestServer, TestServerBuilder}, }; +use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD}; +use ring::{ + rand::SystemRandom, + signature::{ECDSA_P256_SHA256_ASN1_SIGNING, EcdsaKeyPair, KeyPair}, +}; use serde_json::{Value, json}; +use sha2::{Digest, Sha256}; + +/// The page's origin: the test server's public URL. +const ORIGIN: &str = "https://localhost:8899"; +const RP_ID: &str = "localhost"; const USING: &[&str] = &[ "urn:ietf:params:jmap:core", @@ -231,6 +243,262 @@ pub async fn test(test: &mut TestServer) { .any(|e| e["action"] == "destroy" && e["target"]["name"] == "Work phone"), "no removal recorded by name: {response}" ); + + registration(&user).await; +} + +/// A software authenticator: one P-256 key, user verification always done. +pub struct SoftKey { + pub key: EcdsaKeyPair, + pub credential_id: Vec, +} + +impl SoftKey { + pub fn new(credential_id: &[u8]) -> Self { + let rng = SystemRandom::new(); + let pkcs8 = EcdsaKeyPair::generate_pkcs8(&ECDSA_P256_SHA256_ASN1_SIGNING, &rng).unwrap(); + SoftKey { + key: EcdsaKeyPair::from_pkcs8(&ECDSA_P256_SHA256_ASN1_SIGNING, pkcs8.as_ref(), &rng) + .unwrap(), + credential_id: credential_id.to_vec(), + } + } + + /// What `navigator.credentials.create` hands the page, for `options`. + pub fn create(&self, options: &Value) -> Value { + let challenge = options["publicKey"]["challenge"].as_str().unwrap(); + let client_data = json!({ + "type": "webauthn.create", + "challenge": challenge, + "origin": ORIGIN, + "crossOrigin": false + }) + .to_string(); + + // COSE EC2 key: kty 2, alg -7 (ES256), crv 1 (P-256), x, y + let point = self.key.public_key().as_ref(); + let mut cose = Vec::new(); + cbor_head(&mut cose, 5, 5); + cbor_int(&mut cose, 1); + cbor_int(&mut cose, 2); + cbor_int(&mut cose, 3); + cbor_int(&mut cose, -7); + cbor_int(&mut cose, -1); + cbor_int(&mut cose, 1); + cbor_int(&mut cose, -2); + cbor_bytes(&mut cose, &point[1..33]); + cbor_int(&mut cose, -3); + cbor_bytes(&mut cose, &point[33..65]); + + let mut auth_data = Sha256::digest(RP_ID.as_bytes()).to_vec(); + // UP, UV, backup eligible, backed up, attested credential data + auth_data.push(0x01 | 0x04 | 0x08 | 0x10 | 0x40); + auth_data.extend_from_slice(&0u32.to_be_bytes()); + auth_data.extend_from_slice(&[0u8; 16]); + auth_data.extend_from_slice(&(self.credential_id.len() as u16).to_be_bytes()); + auth_data.extend_from_slice(&self.credential_id); + auth_data.extend_from_slice(&cose); + + // Attestation `none` (PK-1) + let mut attestation = Vec::new(); + cbor_head(&mut attestation, 5, 3); + cbor_text(&mut attestation, "fmt"); + cbor_text(&mut attestation, "none"); + cbor_text(&mut attestation, "attStmt"); + cbor_head(&mut attestation, 5, 0); + cbor_text(&mut attestation, "authData"); + cbor_bytes(&mut attestation, &auth_data); + + let id = URL_SAFE_NO_PAD.encode(&self.credential_id); + json!({ + "id": id, + "rawId": id, + "type": "public-key", + "response": { + "attestationObject": URL_SAFE_NO_PAD.encode(&attestation), + "clientDataJSON": URL_SAFE_NO_PAD.encode(client_data.as_bytes()), + "transports": ["internal"] + }, + "extensions": {} + }) + } +} + +fn cbor_head(out: &mut Vec, major: u8, len: u64) { + let major = major << 5; + match len { + 0..=23 => out.push(major | len as u8), + 24..=0xff => out.extend_from_slice(&[major | 24, len as u8]), + 0x100..=0xffff => { + out.push(major | 25); + out.extend_from_slice(&(len as u16).to_be_bytes()); + } + _ => { + out.push(major | 26); + out.extend_from_slice(&(len as u32).to_be_bytes()); + } + } +} + +fn cbor_int(out: &mut Vec, n: i64) { + if n >= 0 { + cbor_head(out, 0, n as u64); + } else { + cbor_head(out, 1, (-1 - n) as u64); + } +} + +fn cbor_bytes(out: &mut Vec, bytes: &[u8]) { + cbor_head(out, 2, bytes.len() as u64); + out.extend_from_slice(bytes); +} + +fn cbor_text(out: &mut Vec, text: &str) { + cbor_head(out, 3, text.len() as u64); + out.extend_from_slice(text.as_bytes()); +} + +async fn register(body: Value) -> Value { + HttpRequest::new() + .post::("/api/passkey/register", &body) + .await + .unwrap_or_else(|err| panic!("{body}: {err}")) +} + +/// Starts a registration through JMAP and returns its id and ticket. +async fn start_registration(user: &Account, name: &str) -> (String, String) { + let (_, response) = call( + user, + "inbuxa:Passkey/set", + json!({"create": {"k": {"name": name}}}), + ) + .await; + let created = &response["created"]["k"]; + let url = created["registrationUrl"] + .as_str() + .unwrap_or_else(|| panic!("{response}")); + assert!(url.starts_with(ORIGIN), "{url}"); + ( + created["id"].as_str().unwrap().to_string(), + url.split_once("ticket=").unwrap().1.to_string(), + ) +} + +/// PK-6 to PK-8: the registration page's two steps. +async fn registration(user: &Account) { + let (laptop_id, ticket) = start_registration(user, "Laptop").await; + + // The server serves the page itself + let page = reqwest::Client::builder() + .danger_accept_invalid_certs(true) + .build() + .unwrap() + .get(format!( + "https://127.0.0.1:8899/passkey/register?ticket={ticket}" + )) + .send() + .await + .unwrap(); + assert_eq!(page.status(), 200); + assert!(page.text().await.unwrap().contains("/api/passkey/register")); + + // PK-8: nothing without the password + let response = register(json!({ + "step": "start", "ticket": ticket, "password": "wrong-password" + })) + .await; + assert_eq!(response["type"], "failure", "{response}"); + let key = SoftKey::new(b"soft-key-laptop-0001"); + let response = register(json!({ + "step": "finish", "ticket": ticket, "credential": key.create(&json!({ + "publicKey": {"challenge": URL_SAFE_NO_PAD.encode(b"made-up")} + })) + })) + .await; + assert_eq!(response["type"], "expired", "{response}"); + let response = register(json!({ + "step": "start", "ticket": "not-a-ticket", "password": "passkey-secret-5521" + })) + .await; + assert_eq!(response["type"], "expired", "{response}"); + + // PK-1: discoverable, user verification, attestation none + let response = register(json!({ + "step": "start", "ticket": ticket, "password": "passkey-secret-5521" + })) + .await; + assert_eq!(response["type"], "options", "{response}"); + assert_eq!(response["name"], "Laptop"); + assert_eq!(response["accountName"], "passkey-user@example.com"); + let options = &response["options"]; + let selection = &options["publicKey"]["authenticatorSelection"]; + assert_eq!(selection["residentKey"], "required", "{options}"); + assert_eq!(selection["userVerification"], "required", "{options}"); + assert_eq!(options["publicKey"]["rp"]["id"], RP_ID, "{options}"); + assert_eq!(options["publicKey"]["attestation"], "none", "{options}"); + + // A wrong origin is refused, and the step is used up + let mut forged = key.create(options); + forged["response"]["clientDataJSON"] = URL_SAFE_NO_PAD + .encode( + json!({ + "type": "webauthn.create", + "challenge": options["publicKey"]["challenge"], + "origin": "https://evil.example", + "crossOrigin": false + }) + .to_string(), + ) + .into(); + let response = + register(json!({"step": "finish", "ticket": ticket, "credential": forged})).await; + assert_eq!(response["type"], "refused", "{response}"); + assert_eq!(list(user, user).await[0]["state"], "pending"); + + // PK-7: done, the passkey is active + let response = register(json!({ + "step": "start", "ticket": ticket, "password": "passkey-secret-5521" + })) + .await; + let response = register(json!({ + "step": "finish", "ticket": ticket, "credential": key.create(&response["options"]) + })) + .await; + assert_eq!(response["type"], "registered", "{response}"); + assert_eq!(response["name"], "Laptop"); + let mine = list(user, user).await; + let laptop = mine.iter().find(|p| p["id"] == laptop_id.as_str()).unwrap(); + assert_eq!(laptop["state"], "active", "{laptop}"); + assert_eq!(laptop["usable"], true, "{laptop}"); + assert_eq!(laptop["rpId"], RP_ID, "{laptop}"); + assert_eq!(laptop["backedUp"], true, "{laptop}"); + assert_eq!(laptop["transports"], json!(["internal"]), "{laptop}"); + + // The ticket is good once + let response = register(json!({ + "step": "start", "ticket": ticket, "password": "passkey-secret-5521" + })) + .await; + assert_eq!(response["type"], "expired", "{response}"); + + // PK-7: a credential id already registered is refused; the browser is + // told which ones the account has + let (_, ticket) = start_registration(user, "Again").await; + let response = register(json!({ + "step": "start", "ticket": ticket, "password": "passkey-secret-5521" + })) + .await; + let excluded = &response["options"]["publicKey"]["excludeCredentials"]; + assert_eq!( + excluded[0]["id"], + URL_SAFE_NO_PAD.encode(b"soft-key-laptop-0001"), + "{response}" + ); + let response = register(json!({ + "step": "finish", "ticket": ticket, "credential": key.create(&response["options"]) + })) + .await; + assert_eq!(response["type"], "refused", "{response}"); } #[ignore] @@ -238,6 +506,7 @@ pub async fn test(test: &mut TestServer) { pub async fn passkey_tests() { let mut test = TestServerBuilder::new("passkey_tests") .await + .with_public_host("localhost") .with_default_listeners() .await .build() diff --git a/tests/src/utils/server.rs b/tests/src/utils/server.rs index b5662e0a..22b8b1cb 100644 --- a/tests/src/utils/server.rs +++ b/tests/src/utils/server.rs @@ -94,6 +94,8 @@ pub struct TestServerBuilder { capture_queue: bool, capture_reporting: bool, disable_services: bool, + // inbuxa: the host in the public URL; WebAuthn wants a name, not an IP + public_host: &'static str, } impl TestServerBuilder { @@ -138,6 +140,7 @@ impl TestServerBuilder { capture_queue: false, capture_reporting: false, disable_services: false, + public_host: "127.0.0.1", } } @@ -259,6 +262,12 @@ impl TestServerBuilder { self } + // inbuxa: passkeys need a host name in the public URL + pub fn with_public_host(mut self, host: &'static str) -> Self { + self.public_host = host; + self + } + pub async fn insert_object(&self, object: impl Into) -> Id { self.bootstrap .registry @@ -331,10 +340,10 @@ impl TestServerBuilder { servers.bind_and_drop_priv(&mut self.bootstrap); // Set HTTP port - self.bootstrap.registry = self - .bootstrap - .registry - .clone_with_public_url(format!("https://127.0.0.1:{}", self.http_listener_port)); + self.bootstrap.registry = self.bootstrap.registry.clone_with_public_url(format!( + "https://{}:{}", + self.public_host, self.http_listener_port + )); if init_store { // Add safe defaults if missing