diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8bee8c6..9e421ad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,9 @@ jobs: - name: Test with pytest run: | pytest + - name: Check type stubs against the library + run: | + python -m mypy.stubtest biscuit_auth --allowlist stubtest-allowlist.txt - name: Test documentation run: | pip install sphinx sphinx-rtd-theme diff --git a/CHANGELOG.md b/CHANGELOG.md index b19a2b9..4680f78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 0.5.0 + +- biscuit-rust 7.0.0 +- support for configurable step limits +- `AuthorizerLimits` is now exported from the module +- BREAKING: `KeyPair` is removed, use `PrivateKey` directly instead + # 0.4.0 - biscuit-rust 6.0.0 diff --git a/Cargo.lock b/Cargo.lock index 2f3c730..cc3f7a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,9 +40,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "base16ct" -version = "0.2.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" [[package]] name = "base64" @@ -50,6 +50,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64ct" version = "1.6.0" @@ -58,28 +64,23 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "biscuit-auth" -version = "6.0.0" +version = "7.0.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5884fc86b3e21f5649ef4326e17ef729b3096e6502deaf13db7b7fb05bb992b" +checksum = "0596a4c8b69a9538b8b1d160b9f94df2d970f4c0fb2657cb2fdf20239ac7eac7" dependencies = [ - "base64", + "base64 0.22.1", "biscuit-parser", "biscuit-quote", - "ecdsa", "ed25519-dalek", - "elliptic-curve", - "getrandom", "hex", "nom", "p256", - "pkcs8 0.9.0", "prost", "prost-types", "rand", "rand_core", "regex", "serde_json", - "sha2 0.9.9", "thiserror", "time", "zeroize", @@ -87,9 +88,9 @@ dependencies = [ [[package]] name = "biscuit-parser" -version = "0.2.0" +version = "0.3.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d7cafdbc8c30e1f0fb87df7161bec77f6f00da652cc33f102b0f95bd1cbc0fa" +checksum = "9614806ae155af29e36a5f8b4aa424906b1bb038af9f940fb89c7bfc453112e5" dependencies = [ "hex", "nom", @@ -103,7 +104,7 @@ dependencies = [ name = "biscuit-python" version = "0.4.0" dependencies = [ - "base64", + "base64 0.13.1", "biscuit-auth", "chrono", "hex", @@ -112,33 +113,24 @@ dependencies = [ [[package]] name = "biscuit-quote" -version = "0.3.0" +version = "0.4.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49d2332c742a07a846f1fb2760e58a0ee60f2bc30987046fcea816b40630335a" +checksum = "3182989e95b57de8d4cbbb84fbf9448b9b112c4cde95f439163ddd284a766a1e" dependencies = [ "biscuit-parser", - "proc-macro-error2", + "manyhow", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.119", ] [[package]] name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -147,12 +139,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - [[package]] name = "bytes" version = "1.8.0" @@ -174,6 +160,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures", + "rand_core", +] + [[package]] name = "chrono" version = "0.4.38" @@ -188,11 +185,17 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + [[package]] name = "const-oid" -version = "0.9.6" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" [[package]] name = "core-foundation-sys" @@ -200,22 +203,32 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" dependencies = [ "libc", ] [[package]] name = "crypto-bigint" -version = "0.5.5" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +checksum = "914c195c4d7fbc5ed7f88d14cbf85914d5c664967658d43404b263913a477e82" dependencies = [ - "generic-array", + "cpubits", + "ctutils", + "getrandom", + "hybrid-array", + "num-traits", "rand_core", "subtle", "zeroize", @@ -223,25 +236,37 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ - "generic-array", - "typenum", + "getrandom", + "hybrid-array", + "rand_core", +] + +[[package]] +name = "ctutils" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f" +dependencies = [ + "cmov", + "subtle", ] [[package]] name = "curve25519-dalek" -version = "4.1.3" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +checksum = "b5eed333089e2e1c1ac8c6c0398e5e2497b4c9926ca6d0365ed1e099afa5bc23" dependencies = [ "cfg-if", "cpufeatures", "curve25519-dalek-derive", - "digest 0.10.7", + "digest", "fiat-crypto", + "rand_core", "rustc_version", "subtle", "zeroize", @@ -255,23 +280,14 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", -] - -[[package]] -name = "der" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" -dependencies = [ - "const-oid", + "syn 2.0.119", ] [[package]] name = "der" -version = "0.7.9" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +checksum = "6a996a108feb8b427a6e12fcf6af4aa83409b79d72c15337d7741368131ee004" dependencies = [ "const-oid", "pem-rfc7468", @@ -289,61 +305,54 @@ dependencies = [ [[package]] name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" -version = "0.10.7" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ - "block-buffer 0.10.4", + "block-buffer", "const-oid", "crypto-common", - "subtle", + "ctutils", ] [[package]] name = "ecdsa" -version = "0.16.9" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +checksum = "c0681a4fc24c767085329728d8dfba959af91228aa4610cca4f8ce317ba46ae0" dependencies = [ - "der 0.7.9", - "digest 0.10.7", + "der", + "digest", "elliptic-curve", "rfc6979", "serdect", "signature", - "spki 0.7.3", + "spki", + "zeroize", ] [[package]] name = "ed25519" -version = "2.2.3" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +checksum = "29fcf32e6c73d1079f83ab4d782de2d81620346a5f38c6237a86a22f8368980a" dependencies = [ - "pkcs8 0.10.2", + "pkcs8", "signature", ] [[package]] name = "ed25519-dalek" -version = "2.1.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +checksum = "6ebaa1a2bf1290ab3bfe5a7b771d050ebffab2711c19a81691c683a5144a25de" dependencies = [ "curve25519-dalek", "ed25519", "rand_core", "serde", - "sha2 0.10.8", + "sha2", + "signature", "subtle", "zeroize", ] @@ -356,18 +365,19 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elliptic-curve" -version = "0.13.8" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +checksum = "900f37e7e18d74a2347389af6cd69e3a30d5cc9e697f40004865679aa75e9c7c" dependencies = [ "base16ct", "crypto-bigint", - "digest 0.10.7", + "crypto-common", + "digest", "ff", - "generic-array", "group", + "hybrid-array", "pem-rfc7468", - "pkcs8 0.10.2", + "pkcs8", "rand_core", "sec1", "serdect", @@ -377,9 +387,9 @@ dependencies = [ [[package]] name = "ff" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +checksum = "a1f686ab92a9fb0eaf188f6c6c87b89490baa6fdb0db4544ba4dc47f7942489f" dependencies = [ "rand_core", "subtle", @@ -387,37 +397,27 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" - -[[package]] -name = "generic-array" -version = "0.14.7" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] +checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24" [[package]] name = "getrandom" -version = "0.2.15" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", "libc", - "wasi", + "r-efi", + "rand_core", ] [[package]] name = "group" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +checksum = "7fd1a1c7a5206c5b7a3f5a0d7ccd3ff85d0c8f5133d62a02680255b0004af5f4" dependencies = [ "ff", "rand_core", @@ -438,11 +438,22 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hmac" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" dependencies = [ - "digest 0.10.7", + "digest", +] + +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "subtle", + "typenum", + "zeroize", ] [[package]] @@ -505,25 +516,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] -name = "memchr" -version = "2.7.4" +name = "manyhow" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "b33efb3ca6d3b07393750d4030418d594ab1139cee518f0dc88db70fec873587" +dependencies = [ + "manyhow-macros", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "manyhow-macros" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fce34d199b78b6e6073abf984c9cf5fd3e9330145a93ee0738a7443e371495" +dependencies = [ + "proc-macro-utils", + "proc-macro2", + "quote", +] [[package]] -name = "minimal-lexical" -version = "0.2.1" +name = "memchr" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "nom" -version = "7.1.3" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" dependencies = [ "memchr", - "minimal-lexical", ] [[package]] @@ -547,51 +574,37 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" -[[package]] -name = "opaque-debug" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" - [[package]] name = "p256" -version = "0.13.2" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +checksum = "d2c9239b2dbc807adbbe147e8cf72ea7450c3a0aabe62cb8e75ff4ec22e1f72a" dependencies = [ "ecdsa", "elliptic-curve", + "primefield", "primeorder", - "sha2 0.10.8", + "serdect", + "sha2", ] [[package]] name = "pem-rfc7468" -version = "0.7.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" dependencies = [ "base64ct", ] [[package]] name = "pkcs8" -version = "0.9.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7" dependencies = [ - "der 0.6.1", - "spki 0.6.0", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der 0.7.9", - "spki 0.7.3", + "der", + "spki", ] [[package]] @@ -607,59 +620,57 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] -name = "ppv-lite86" -version = "0.2.20" +name = "primefield" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +checksum = "c555a6e4eb7d4e158fcb028c835c3b8642206ddc279b5c6b202ef9a8bdb592f4" dependencies = [ - "zerocopy", + "crypto-bigint", + "crypto-common", + "ff", + "rand_core", + "subtle", + "zeroize", ] [[package]] name = "primeorder" -version = "0.13.6" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +checksum = "5c9f42978c78a00e3d68f69fc03e57a234debae69da4020a4fb588fcdcd07b06" dependencies = [ "elliptic-curve", + "once_cell", + "primefield", + "serdect", + "wnaf", ] [[package]] -name = "proc-macro-error-attr2" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" -dependencies = [ - "proc-macro2", - "quote", -] - -[[package]] -name = "proc-macro-error2" -version = "2.0.1" +name = "proc-macro-utils" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" +checksum = "eeaf08a13de400bc215877b5bdc088f241b12eb42f0a548d3390dc1c56bb7071" dependencies = [ - "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.85", + "smallvec", ] [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" dependencies = [ "unicode-ident", ] [[package]] name = "prost" -version = "0.10.4" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71adf41db68aa0daaefc69bb30bcd68ded9b9abaad5d1fbb6304c4fb390e083e" +checksum = "528ac67416ff8646872a3c02cad9cc4ee5dc9f9540c9b10771855c95cb2e5ae1" dependencies = [ "bytes", "prost-derive", @@ -667,24 +678,23 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.10.1" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b670f45da57fb8542ebdbb6105a925fe571b67f9e7ed9f47a06a84e72b4e7cc" +checksum = "b570b25f7617e43d59005d0990ccb79e950a423952cea19671b7a876da390adf" dependencies = [ "anyhow", "itertools", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.119", ] [[package]] name = "prost-types" -version = "0.10.1" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d0a014229361011dc8e69c8a1ec6c2e8d0f2af7c91e3ea3f5b2170298461e68" +checksum = "f94967dc7688f3054c7fac87473ffae4cc4c3904800e2d9f5b857246d8963b0a" dependencies = [ - "bytes", "prost", ] @@ -731,7 +741,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.85", + "syn 2.0.119", ] [[package]] @@ -744,7 +754,7 @@ dependencies = [ "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.85", + "syn 2.0.119", ] [[package]] @@ -757,34 +767,27 @@ dependencies = [ ] [[package]] -name = "rand" -version = "0.8.5" +name = "r-efi" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" [[package]] -name = "rand_chacha" -version = "0.3.1" +name = "rand" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" dependencies = [ - "ppv-lite86", + "chacha20", + "getrandom", "rand_core", ] [[package]] name = "rand_core" -version = "0.6.4" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" [[package]] name = "regex" @@ -817,12 +820,12 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rfc6979" -version = "0.4.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +checksum = "b4a459cddafb3fe76b31fd8f1108007566c40301feb64dc7b54656eb7388172b" dependencies = [ + "crypto-bigint", "hmac", - "subtle", ] [[package]] @@ -842,14 +845,14 @@ checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" [[package]] name = "sec1" -version = "0.7.3" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +checksum = "d56d437c2f19203ce5f7122e507831de96f3d2d4d3be5af44a0b0a09d8a80e4d" dependencies = [ "base16ct", - "der 0.7.9", - "generic-array", - "pkcs8 0.10.2", + "ctutils", + "der", + "hybrid-array", "serdect", "subtle", "zeroize", @@ -878,7 +881,7 @@ checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.119", ] [[package]] @@ -895,9 +898,9 @@ dependencies = [ [[package]] name = "serdect" -version = "0.2.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a84f14a19e9a014bb9f4512488d9829a68e04ecabffb0f9904cd1ace94598177" +checksum = "66cf8fedced2fcf12406bcb34223dffb92eaf34908ede12fed414c82b7f00b3e" dependencies = [ "base16ct", "serde", @@ -905,26 +908,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - -[[package]] -name = "sha2" -version = "0.10.8" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.7", + "digest", ] [[package]] @@ -935,31 +925,28 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signature" -version = "2.2.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +checksum = "28d567dcbaf0049cb8ac2608a76cd95ff9e4412e1899d389ee400918ca7537f5" dependencies = [ - "digest 0.10.7", + "digest", "rand_core", ] [[package]] -name = "spki" -version = "0.6.0" +name = "smallvec" +version = "1.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" -dependencies = [ - "der 0.6.1", -] +checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46" [[package]] name = "spki" -version = "0.7.3" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +checksum = "7ef958a98b9d5da290cfc78946e9f3e61e1e62a18db0d92cac0b83cc161491a9" dependencies = [ "base64ct", - "der 0.7.9", + "der", ] [[package]] @@ -970,9 +957,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" dependencies = [ "proc-macro2", "quote", @@ -981,9 +968,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.85" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" dependencies = [ "proc-macro2", "quote", @@ -998,22 +985,22 @@ checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" [[package]] name = "thiserror" -version = "1.0.65" +version = "2.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.65" +version = "2.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 3.0.10", ] [[package]] @@ -1049,9 +1036,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.17.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "unicode-ident" @@ -1059,18 +1046,6 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wasm-bindgen" version = "0.2.95" @@ -1093,7 +1068,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.119", "wasm-bindgen-shared", ] @@ -1115,7 +1090,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.119", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1200,24 +1175,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] -name = "zerocopy" -version = "0.7.35" +name = "wnaf" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +checksum = "795ca18b3fdb5e62bf982199278341ddcf7ebf7d32e25e212ad05d496e95f6fa" dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.85", + "ff", + "group", + "hybrid-array", + "primefield", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4ddbb97..5db434b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ name = "biscuit_auth" crate-type = ["cdylib"] [dependencies] -biscuit-auth = { version = "6.0.0", features = ["pem"] } +biscuit-auth = { version = "7.0.0-alpha.1", features = ["pem"] } pyo3 = { version = "0.28.2", features = ["extension-module", "chrono"] } hex = "0.4" base64 = "0.13.0" diff --git a/biscuit_auth.pyi b/biscuit_auth.pyi index da07790..340cb7d 100644 --- a/biscuit_auth.pyi +++ b/biscuit_auth.pyi @@ -3,7 +3,38 @@ Type stubs for lib.rs """ from __future__ import annotations -from typing import Callable, Optional, Mapping, Any, List, Union, TypeAlias +from datetime import timedelta +from typing import Callable, Optional, Mapping, Any, List, Union, TypeAlias, final + +__all__ = [ + "PublicKey", + "PrivateKey", + "Biscuit", + "BiscuitBuilder", + "BlockBuilder", + "Authorizer", + "AuthorizerBuilder", + "AuthorizerLimits", + "Fact", + "Rule", + "Check", + "Policy", + "UnverifiedBiscuit", + "Algorithm", + "ThirdPartyRequest", + "ThirdPartyBlock", + "DataLogError", + "AuthorizationError", + "BiscuitBuildError", + "BiscuitBlockError", + "BiscuitValidationError", + "BiscuitSerializationError", + "Parameters", + "ScopeParameters", + "PublicKeyProvider", + "ExternFunc", + "Term", +] class DataLogError(Exception): pass @@ -23,19 +54,28 @@ class BiscuitSerializationError(Exception): class BiscuitBlockError(Exception): pass +# Also defined at runtime, in add_type_aliases (src/lib.rs). Keep both in sync. + +#: A datalog term, as a python value: `int`, `str`, `bytes`, `bool`, `datetime` (with a timezone), +#: a `set` of those, a `list` of terms, or a `dict` with `str` or `int` keys and term values Term: TypeAlias = Any +#: Values for the parameters (`{name}`) in a datalog snippet, indexed by parameter name Parameters: TypeAlias = Optional[Mapping[str, Term]] +#: Public keys for the public key parameters (`trusting {name}`) in a datalog snippet, indexed by parameter name ScopeParameters: TypeAlias = Optional[Mapping[str, PublicKey]] -PrivateKeyProvider: TypeAlias = Union[ - Callable[[], PrivateKey], Callable[[int], PrivateKey] -] -PublicKeyProvider: TypeAlias = Union[ - Callable[[], PublicKey], Callable[[int], PublicKey] -] - +#: A function selecting the root public key used to verify a token. It is called +#: with the token's root key id (or `None` if it does not have one) +PublicKeyProvider: TypeAlias = Callable[[Optional[int]], PublicKey] +#: An external function, called by the datalog `.extern::name()` operations. It is called +#: with one argument for unary operations and two for binary operations, and returns a term +ExternFunc: TypeAlias = Union[Callable[[Term], Term], Callable[[Term, Term], Term]] + +@final class Algorithm: - pass + Ed25519: Algorithm + Secp256r1: Algorithm +@final class BiscuitBuilder: # Create a builder from a datalog snippet and optional parameter values # @@ -58,7 +98,7 @@ class BiscuitBuilder: # :type root: PrivateKey # :return: a biscuit token # :rtype: Biscuit - def build(self, root: PrivateKey | PrivateKeyProvider) -> Biscuit: ... + def build(self, root: PrivateKey) -> Biscuit: ... # Add code to the builder, using the provided parameters. # @@ -70,7 +110,7 @@ class BiscuitBuilder: # :type scope_parameters: dict, optional def add_code( self, - source: Optional[str] = None, + source: str, parameters: Parameters = None, scope_parameters: ScopeParameters = None, ) -> None: ... @@ -108,6 +148,7 @@ class BiscuitBuilder: # :type root_key_id: int def set_root_key_id(self, root_key_id: int) -> None: ... +@final class Biscuit: # Creates a BiscuitBuilder # @@ -147,8 +188,8 @@ class Biscuit: # Serializes to raw bytes # # :return: the serialized biscuit - # :rtype: list - def to_bytes(self) -> List[int]: ... + # :rtype: bytes + def to_bytes(self) -> bytes: ... # Serializes to URL safe base 64 data # @@ -207,9 +248,18 @@ class Biscuit: # :param index: the block index # :type index: int # :return: the public key if it exists - # :rtype: str | None - def block_external_key(self, index: int) -> str | None: ... - + # :rtype: PublicKey | None + def block_external_key(self, index: int) -> Optional[PublicKey]: ... + +# Runtime limits of the authorizer +@final +class AuthorizerLimits: + max_facts: int + max_iterations: int + max_time: timedelta + max_steps: int + +@final class AuthorizerBuilder: # Create a new authorizer from a datalog snippet and optional parameter values # @@ -236,7 +286,7 @@ class AuthorizerBuilder: # :type scope_parameters: dict, optional def add_code( self, - source: Optional[str] = None, + source: str, parameters: Parameters = None, scope_parameters: ScopeParameters = None, ) -> None: ... @@ -269,11 +319,22 @@ class AuthorizerBuilder: # :type policy: Policy def add_policy(self, policy: Policy) -> None: ... - # Merge another `Authorizer` in this `Authorizer`. The `Authorizer` argument will not be modified + # Returns the runtime limits of the authorizer + def limits(self) -> AuthorizerLimits: ... + + # Sets the runtime limits of the authorizer + # + # Those limits cover all the executions under the `authorize`, `query` and `query_all` methods + def set_limits(self, limits: AuthorizerLimits) -> None: ... + + # adds a fact `time($current_time)` with the current time + def set_time(self) -> None: ... + + # Merge another `AuthorizerBuilder` in this `AuthorizerBuilder`. The `AuthorizerBuilder` argument will not be modified # - # :param builder: an Authorizer - # :type builder: Authorizer - def merge(self, builder: Authorizer) -> None: ... + # :param builder: an AuthorizerBuilder + # :type builder: AuthorizerBuilder + def merge(self, builder: AuthorizerBuilder) -> None: ... # Merge a `BlockBuilder` in this `Authorizer`. The `BlockBuilder` will not be modified # @@ -281,6 +342,15 @@ class AuthorizerBuilder: # :type builder: BlockBuilder def merge_block(self, builder: BlockBuilder) -> None: ... + # Register an external function, called by the datalog `.extern::name()` operations + def register_extern_func(self, name: str, func: ExternFunc) -> None: ... + + # Register several external functions + def register_extern_funcs(self, funcs: Mapping[str, ExternFunc]) -> None: ... + + # Replace all the registered external functions + def set_extern_funcs(self, funcs: Mapping[str, ExternFunc]) -> None: ... + # Take a snapshot of the authorizer builder and return it, base64-encoded # # :return: a snapshot as a base64-encoded string @@ -311,12 +381,21 @@ class AuthorizerBuilder: @classmethod def from_raw_snapshot(cls, input: bytes) -> AuthorizerBuilder: ... - # Add a `Biscuit` to this `Authorizer` + # Build the `AuthorizerBuilder` with the provided `Biscuit` # # :param token: the token to authorize # :type token: Biscuit + # :return: the authorizer + # :rtype: Authorizer def build(self, token: Biscuit) -> Authorizer: ... + # Build the `AuthorizerBuilder` without a token + # + # :return: the authorizer + # :rtype: Authorizer + def build_unauthenticated(self) -> Authorizer: ... + +@final class Authorizer: # Runs the authorization checks and policies # @@ -370,10 +449,19 @@ class Authorizer: def from_raw_snapshot(cls, input: bytes) -> Authorizer: ... # Builder class allowing to create a block meant to be appended to an existing token +@final class BlockBuilder: + # Create a builder from a datalog snippet and optional parameter values + # + # :param source: a datalog snippet + # :type source: str, optional + # :param parameters: values for the parameters in the datalog snippet + # :type parameters: dict, optional + # :param scope_parameters: public keys for the public key parameters in the datalog snippet + # :type scope_parameters: dict, optional def __new__( cls, - source: Optional[str], + source: Optional[str] = None, parameters: Parameters = None, scope_parameters: ScopeParameters = None, ) -> BlockBuilder: ... @@ -415,66 +503,30 @@ class BlockBuilder: # :type scope_parameters: dict, optional def add_code( self, - source: Optional[str], + source: str, parameters: Parameters = None, scope_parameters: ScopeParameters = None, ) -> None: ... -# ed25519 keypair -class KeyPair: - # Generate a random keypair - def __new__(cls) -> KeyPair: ... - - # Generate a keypair from a private key - # - # :param private_key: the private key - # :type private_key: PrivateKey - # :return: the corresponding keypair - # :rtype: KeyPair - @classmethod - def from_private_key(cls, private_key: PrivateKey) -> KeyPair: ... - - # Generate a keypair from a DER buffer - # - # :param bytes: private key bytes in DER format - # :type private_key: PrivateKey - # :return: the corresponding keypair - # :rtype: KeyPair - @classmethod - def from_private_key_der(cls, der: bytes) -> KeyPair: ... - - # - # :param bytes: private key bytes in PEM format - # :type private_key: PrivateKey - # :return: the corresponding keypair - # :rtype: KeyPair - @classmethod - def from_private_key_pem(cls, pem: str) -> KeyPair: ... - - # The public key part - @property - def public_key(self) -> PublicKey: ... - - # The private key part - @property - def private_key(self) -> PrivateKey: ... - -# ed25519 public key +# public key +@final class PublicKey: # Serializes a public key to raw bytes # # :return: the public key bytes - # :rtype: list + # :rtype: bytes def to_bytes(self) -> bytes: ... # Deserializes a public key from raw bytes # # :param data: the raw bytes # :type data: bytes + # :param alg: the key algorithm + # :type alg: Algorithm # :return: the public key # :rtype: PublicKey @classmethod - def from_bytes(cls, data: bytes) -> PublicKey: ... + def from_bytes(cls, data: bytes, alg: Algorithm) -> PublicKey: ... # Deserializes a public key from a hexadecimal string # @@ -484,22 +536,43 @@ class PublicKey: # :rtype: PublicKey def __new__(cls, data: str) -> PublicKey: ... -# ed25519 private key + # Deserializes a public key from a DER buffer + # + # :param der: the DER buffer + # :type der: bytes + # :return: the public key + # :rtype: PublicKey + @classmethod + def from_der(cls, der: bytes) -> PublicKey: ... + + # Deserializes a public key from a PEM string + # + # :param pem: the PEM string + # :type pem: str + # :return: the public key + # :rtype: PublicKey + @classmethod + def from_pem(cls, pem: str) -> PublicKey: ... + +# private key +@final class PrivateKey: - # Serializes a public key to raw bytes + # Serializes a private key to raw bytes # - # :return: the public key bytes - # :rtype: list + # :return: the private key bytes + # :rtype: bytes def to_bytes(self) -> bytes: ... # Deserializes a private key from raw bytes # # :param data: the raw bytes # :type data: bytes + # :param alg: the key algorithm + # :type alg: Algorithm # :return: the private key # :rtype: PrivateKey @classmethod - def from_bytes(cls, data: bytes) -> PrivateKey: ... + def from_bytes(cls, data: bytes, alg: Algorithm) -> PrivateKey: ... # Deserializes a private key from a hexadecimal string # @@ -509,12 +582,39 @@ class PrivateKey: # :rtype: PrivateKey def __new__(cls, data: str) -> PrivateKey: ... + # Deserializes a private key from a DER buffer + # + # :param der: the DER buffer + # :type der: bytes + # :return: the private key + # :rtype: PrivateKey + @classmethod + def from_der(cls, der: bytes) -> PrivateKey: ... + + # Deserializes a private key from a PEM string + # + # :param pem: the PEM string + # :type pem: str + # :return: the private key + # :rtype: PrivateKey + @classmethod + def from_pem(cls, pem: str) -> PrivateKey: ... + + # Generate a random ed25519 private key + @classmethod + def random(cls) -> PrivateKey: ... + + # The public key part + @property + def public_key(self) -> PublicKey: ... + # A single datalog Fact # # :param source: a datalog fact (without the ending semicolon) # :type source: str # :param parameters: values for the parameters in the datalog fact # :type parameters: dict, optional +@final class Fact: # Build a datalog fact from the provided source and optional parameter values def __new__(cls, source: str, parameters: Parameters = None) -> Fact: ... @@ -535,6 +635,7 @@ class Fact: # :type parameters: dict, optional # :param scope_parameters: public keys for the public key parameters in the datalog rule # :type scope_parameters: dict, optional +@final class Rule: # Build a rule from the source and optional parameter values def __new__( @@ -552,6 +653,7 @@ class Rule: # :type parameters: dict, optional # :param scope_parameters: public keys for the public key parameters in the datalog check # :type scope_parameters: dict, optional +@final class Check: # Build a check from the source and optional parameter values def __new__( @@ -569,6 +671,7 @@ class Check: # :type parameters: dict, optional # :param scope_parameters: public keys for the public key parameters in the datalog policy # :type scope_parameters: dict, optional +@final class Policy: # Build a check from the source and optional parameter values def __new__( @@ -579,6 +682,7 @@ class Policy: ) -> Policy: ... # Representation of a biscuit token that has been parsed but not cryptographically verified +@final class UnverifiedBiscuit: # Deserializes a token from URL safe base 64 data # @@ -622,9 +726,17 @@ class UnverifiedBiscuit: # The revocation ids of the token, encoded as hexadecimal strings @property def revocation_ids(self) -> List[str]: ... - def verify(self, root: PublicKey) -> Biscuit: ... + + # Verifies the token signature using the provided root key (or function) + # + # :param root: either a public key or a function taking an integer (or `None`) and returning an public key + # :type root: function,PublicKey + # :return: the verified biscuit + # :rtype: Biscuit + def verify(self, root: PublicKey | PublicKeyProvider) -> Biscuit: ... # Third party block request +@final class ThirdPartyRequest: # Create a third-party block # @@ -643,5 +755,6 @@ class ThirdPartyRequest: ) -> ThirdPartyBlock: ... # Third party block contents +@final class ThirdPartyBlock: pass diff --git a/biscuit_test.py b/biscuit_test.py index 9ec6d06..67295b2 100644 --- a/biscuit_test.py +++ b/biscuit_test.py @@ -4,7 +4,7 @@ import pytest -from biscuit_auth import Algorithm, KeyPair, Authorizer, AuthorizerBuilder, Biscuit, BiscuitBuilder, BlockBuilder, Check, Fact, KeyPair, Policy, PrivateKey, PublicKey, Rule, UnverifiedBiscuit +from biscuit_auth import Algorithm, Authorizer, AuthorizerBuilder, Biscuit, BiscuitBuilder, BlockBuilder, Check, Fact, Policy, PrivateKey, PublicKey, Rule, UnverifiedBiscuit def test_fact(): fact = Fact('fact(1, true, "", "Test", hex:aabbcc, 2023-04-29T01:00:00Z)') @@ -30,7 +30,7 @@ def test_query_collection_terms(): assert facts[0].terms == [{1, 2, 3}, [4, 5], {"k": 6}, None] def test_biscuit_builder(): - kp = KeyPair() + private_key = PrivateKey.random() pubkey = PublicKey("ed25519/acdd6d5b53bfee478bf689f8e012fe7988bf755e3d7c5152947abc149bc20189") builder = BiscuitBuilder( @@ -95,7 +95,7 @@ def test_biscuit_builder(): check if add_code(true, true) trusting ed25519/acdd6d5b53bfee478bf689f8e012fe7988bf755e3d7c5152947abc149bc20189; """ - builder.build(kp.private_key) + builder.build(private_key) assert True def test_block_builder(): @@ -219,26 +219,27 @@ def test_authorizer_limits(): auth = AuthorizerBuilder() limits = auth.limits() limits.max_time = timedelta(microseconds=2000) + limits.max_steps = 42 auth.set_limits(limits) limits = auth.limits() assert limits.max_time.microseconds == 2000 + assert limits.max_steps == 42 def test_key_selection(): private_key = PrivateKey("ed25519-private/473b5189232f3f597b5c2f3f9b0d5e28b1ee4e7cce67ec6b7fbf5984157a6b97") - root = KeyPair.from_private_key(private_key) - other_root = KeyPair() + other_private_key = PrivateKey.random() def choose_key(kid): if kid is None: - return other_root.public_key + return other_private_key.public_key elif kid == 1: - return root.public_key + return private_key.public_key else: raise Exception("Unknown key identifier") biscuit_builder0 = BiscuitBuilder("user({id})", { 'id': "1234" }) - token0 = biscuit_builder0.build(other_root.private_key).to_base64() + token0 = biscuit_builder0.build(other_private_key).to_base64() biscuit_builder1 = BiscuitBuilder("user({id})", { 'id': "1234" }) biscuit_builder1.set_root_key_id(1) token1 = biscuit_builder1.build(private_key).to_base64() @@ -248,7 +249,7 @@ def choose_key(kid): Biscuit.from_base64(token0, choose_key) - Biscuit.from_base64(token0, other_root.public_key) + Biscuit.from_base64(token0, other_private_key.public_key) Biscuit.from_base64(token1, choose_key) try: Biscuit.from_base64(token2, choose_key) @@ -257,7 +258,6 @@ def choose_key(kid): def test_complete_lifecycle(): private_key = PrivateKey("ed25519-private/473b5189232f3f597b5c2f3f9b0d5e28b1ee4e7cce67ec6b7fbf5984157a6b97") - root = KeyPair.from_private_key(private_key) biscuit_builder = BiscuitBuilder("user({id})", { 'id': "1234" }) @@ -266,7 +266,7 @@ def test_complete_lifecycle(): token = biscuit_builder.build(private_key).append(BlockBuilder('check if user($u)')).to_base64() - parsedToken = Biscuit.from_base64(token, root.public_key) + parsedToken = Biscuit.from_base64(token, private_key.public_key) authorizer = AuthorizerBuilder("allow if user({id})", { 'id': "1234" }) @@ -286,7 +286,6 @@ def test_complete_lifecycle(): def test_snapshot(): private_key = PrivateKey("ed25519-private/473b5189232f3f597b5c2f3f9b0d5e28b1ee4e7cce67ec6b7fbf5984157a6b97") - root = KeyPair.from_private_key(private_key) biscuit_builder = BiscuitBuilder("user({id})", { 'id': "1234" }) @@ -295,7 +294,7 @@ def test_snapshot(): token = biscuit_builder.build(private_key).append(BlockBuilder('check if user($u)')).to_base64() - parsedToken = Biscuit.from_base64(token, root.public_key) + parsedToken = Biscuit.from_base64(token, private_key.public_key) authorizer = AuthorizerBuilder("allow if user({id})", { 'id': "1234" }) @@ -385,7 +384,7 @@ def test_private_keys(): def test_biscuit_inspection(): - kp = KeyPair() + private_key = PrivateKey.random() pubkey = PublicKey("ed25519/acdd6d5b53bfee478bf689f8e012fe7988bf755e3d7c5152947abc149bc20189") builder = BiscuitBuilder( @@ -398,11 +397,11 @@ def test_biscuit_inspection(): ) print(builder) - token1 = builder.build(kp.private_key) + token1 = builder.build(private_key) print(token1.to_base64()) builder.set_root_key_id(42) - token2 = builder.build(kp.private_key).append(BlockBuilder('test(false);')) + token2 = builder.build(private_key).append(BlockBuilder('test(false);')) print(token2.to_base64()) utoken1 = UnverifiedBiscuit.from_base64(token1.to_base64()) @@ -453,15 +452,15 @@ def test_append_on_unverified(): def test_keypair_from_private_key_der(): private_key_der = bytes.fromhex("302e020100300506032b6570042204200499694d0da05dcac40052663e71d50c1539465f8926dfe92033cf7aaad53d65") private_key_hex = "ed25519-private/0499694d0da05dcac40052663e71d50c1539465f8926dfe92033cf7aaad53d65" - kp = KeyPair.from_private_key(PrivateKey.from_der(der=private_key_der)) - assert repr(kp.private_key) == private_key_hex + private_key = PrivateKey.from_der(der=private_key_der) + assert repr(private_key) == private_key_hex def test_keypair_from_private_key_pem(): private_key_pem = "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIASZaU0NoF3KxABSZj5x1QwVOUZfiSbf6SAzz3qq1T1l\n-----END PRIVATE KEY-----" private_key_hex = "ed25519-private/0499694d0da05dcac40052663e71d50c1539465f8926dfe92033cf7aaad53d65" - kp = KeyPair.from_private_key(PrivateKey.from_pem(pem=private_key_pem)) - assert repr(kp.private_key) == private_key_hex + private_key = PrivateKey.from_pem(pem=private_key_pem) + assert repr(private_key) == private_key_hex def test_extern_func(): def test(left, right): @@ -482,32 +481,32 @@ def test(left, right): assert policy == 0 def test_append_third_party(): - root_kp = KeyPair() + root_private_key = PrivateKey.random() biscuit_builder = BiscuitBuilder("user({id})", { 'id': "1234" }) - biscuit = biscuit_builder.build(root_kp.private_key) + biscuit = biscuit_builder.build(root_private_key) - third_party_kp = KeyPair() + third_party_private_key = PrivateKey.random() new_block = BlockBuilder("external_fact({fact})", { 'fact': "56" }) third_party_request = biscuit.third_party_request() - third_party_block = third_party_request.create_block(third_party_kp.private_key, new_block) - biscuit_with_third_party_block = biscuit.append_third_party(third_party_kp.public_key, third_party_block) + third_party_block = third_party_request.create_block(third_party_private_key, new_block) + biscuit_with_third_party_block = biscuit.append_third_party(third_party_private_key.public_key, third_party_block) - assert repr(biscuit_with_third_party_block.block_external_key(1)) == repr(third_party_kp.public_key) + assert repr(biscuit_with_third_party_block.block_external_key(1)) == repr(third_party_private_key.public_key) def test_read_third_party_facts(): - root_kp = KeyPair() + root_private_key = PrivateKey.random() biscuit_builder = BiscuitBuilder("user({id})", { 'id': "1234" }) - biscuit = biscuit_builder.build(root_kp.private_key) + biscuit = biscuit_builder.build(root_private_key) - third_party_kp = KeyPair() + third_party_private_key = PrivateKey.random() new_block = BlockBuilder("external_fact({fact})", { 'fact': "56" }) third_party_request = biscuit.third_party_request() - third_party_block = third_party_request.create_block(third_party_kp.private_key, new_block) - biscuit_with_third_party_block = biscuit.append_third_party(third_party_kp.public_key, third_party_block) + third_party_block = third_party_request.create_block(third_party_private_key, new_block) + biscuit_with_third_party_block = biscuit.append_third_party(third_party_private_key.public_key, third_party_block) authorizer = AuthorizerBuilder("allow if true").build(biscuit_with_third_party_block) - rule = Rule(f"ext_fact($fact) <- external_fact($fact) trusting {third_party_kp.public_key}") + rule = Rule(f"ext_fact($fact) <- external_fact($fact) trusting {third_party_private_key.public_key}") facts = authorizer.query(rule) assert facts[0].terms[0] == "56" diff --git a/docs/basic-use.rst b/docs/basic-use.rst index dec4413..e3bee11 100644 --- a/docs/basic-use.rst +++ b/docs/basic-use.rst @@ -2,26 +2,23 @@ Basic use ========= ->>> from biscuit_auth import Authorizer, AuthorizerBuilder, Biscuit, BiscuitBuilder, BlockBuilder, KeyPair, PrivateKey, PublicKey, Rule, UnverifiedBiscuit +>>> from biscuit_auth import Authorizer, AuthorizerBuilder, Biscuit, BiscuitBuilder, BlockBuilder, PrivateKey, PublicKey, Rule, UnverifiedBiscuit >>> from datetime import datetime, timedelta, timezone -Create and manage keypairs --------------------------- +Create and manage keys +---------------------- ->>> # random keypair ->>> keypair = KeyPair() ->>> # serialize a keypair to hexadecimal strings ->>> private_key_str = repr(keypair.private_key) ->>> public_key_str = repr(keypair.public_key) +>>> # random private key +>>> private_key = PrivateKey.random() +>>> # serialize keys to hexadecimal strings +>>> private_key_str = repr(private_key) +>>> public_key_str = repr(private_key.public_key) >>> # parse a private key from an hex string >>> parsed_private_key = PrivateKey("ed25519-private/23d9d45b32899eefd4cde9a2caecdd41f0449c95ee1e4c6b53ef38cb957dd690") >>> # parse a public key from an hex string >>> parsed_public_key = PublicKey("ed25519/9e124fbb46ff99a87219aef4b09f4f6c3b7fd96b7bd279e38af3ef429a101c69") ->>> # build a keypair from a private key ->>> parsed_keypair = KeyPair.from_private_key(parsed_private_key) ->>> parsed_keypair.private_key -ed25519-private/23d9d45b32899eefd4cde9a2caecdd41f0449c95ee1e4c6b53ef38cb957dd690 ->>> parsed_keypair.public_key +>>> # get the public key from a private key +>>> parsed_private_key.public_key ed25519/9e124fbb46ff99a87219aef4b09f4f6c3b7fd96b7bd279e38af3ef429a101c69 Build a biscuit token @@ -121,8 +118,8 @@ Save and load snapshots Third-party blocks ------------------ ->>> external_keypair = KeyPair() +>>> external_private_key = PrivateKey.random() >>> third_party_request = token.third_party_request() >>> new_block = BlockBuilder("external(true)") ->>> third_party_block = third_party_request.create_block(external_keypair.private_key, new_block) ->>> new_biscuit = token.append_third_party(external_keypair.public_key, third_party_block) +>>> third_party_block = third_party_request.create_block(external_private_key, new_block) +>>> new_biscuit = token.append_third_party(external_private_key.public_key, third_party_block) diff --git a/docs/conf.py b/docs/conf.py index 1dbc275..8f2fd72 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,6 +2,20 @@ import sys sys.path.insert(0, pathlib.Path(__file__).parents[2].resolve().as_posix()) +# biscuit_auth is a compiled module, so autodoc can't find its source by itself. +# Point it to the type stub, so that `#:` comments there are used as documentation. +from sphinx.pycode import ModuleAnalyzer # type: ignore[import-not-found] + +_stub_path = (pathlib.Path(__file__).parents[1] / "biscuit_auth.pyi").as_posix() +_for_module = ModuleAnalyzer.for_module + +def _for_module_with_stub(modname): + if modname == "biscuit_auth": + return ModuleAnalyzer.for_file(_stub_path, modname) + return _for_module(modname) + +ModuleAnalyzer.for_module = _for_module_with_stub # type: ignore[method-assign] + # Configuration file for the Sphinx documentation builder. # # For the full list of built-in configuration values, see the documentation: diff --git a/src/lib.rs b/src/lib.rs index ab08894..a6ad30e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ use std::str::FromStr; use std::sync::Arc; use ::biscuit_auth::{ - builder, error, Authorizer, AuthorizerLimits, Biscuit, KeyPair, PrivateKey, PublicKey, + builder, error, Authorizer, AuthorizerLimits, Biscuit, PrivateKey, PublicKey, }; use pyo3::exceptions::PyValueError; @@ -89,6 +89,8 @@ struct PyKeyProvider { } impl RootKeyProvider for PyKeyProvider { + type Key = PublicKey; + fn choose(&self, kid: Option) -> Result { Python::attach(|py| { let bound = self.py_value.bind(py); @@ -152,12 +154,11 @@ impl PyBiscuitBuilder { /// :return: a biscuit token /// :rtype: Biscuit pub fn build(&self, root: &PyPrivateKey) -> PyResult { - let keypair = KeyPair::from(&root.0); Ok(PyBiscuit( self.0 .clone() .expect("builder already consumed") - .build(&keypair) + .build(&root.0) .map_err(|e| BiscuitBuildError::new_err(e.to_string()))?, )) } @@ -190,7 +191,7 @@ impl PyBiscuitBuilder { if let Some(scope_parameters) = scope_parameters { scope_params = scope_parameters .iter() - .map(|(k, v)| (k.to_string(), v.0)) + .map(|(k, v)| (k.to_string(), v.0.into())) .collect(); } else { scope_params = HashMap::new(); @@ -478,6 +479,8 @@ pub struct PyAuthorizerLimits { pub max_iterations: u64, #[pyo3(get, set)] pub max_time: Duration, + #[pyo3(get, set)] + pub max_steps: u64, } #[pymethods] @@ -532,7 +535,7 @@ impl PyAuthorizerBuilder { if let Some(scope_parameters) = scope_parameters { scope_params = scope_parameters .iter() - .map(|(k, v)| (k.to_string(), v.0)) + .map(|(k, v)| (k.to_string(), v.0.into())) .collect(); } else { scope_params = HashMap::new(); @@ -629,6 +632,7 @@ impl PyAuthorizerBuilder { max_facts: limits.max_facts, max_iterations: limits.max_iterations, max_time: Duration::from_std(limits.max_time).expect("Duration out of range"), + max_steps: limits.max_steps, }) } @@ -641,6 +645,7 @@ impl PyAuthorizerBuilder { max_facts: limits.max_facts, max_iterations: limits.max_iterations, max_time: Duration::to_std(&limits.max_time).expect("Duration out of range"), + max_steps: limits.max_steps, }, )); @@ -1040,7 +1045,7 @@ impl PyBlockBuilder { if let Some(scope_parameters) = scope_parameters { scope_params = scope_parameters .iter() - .map(|(k, v)| (k.to_string(), v.0)) + .map(|(k, v)| (k.to_string(), v.0.into())) .collect(); } else { scope_params = HashMap::new(); @@ -1101,48 +1106,6 @@ impl PyThirdPartyRequest { #[pyclass(name = "ThirdPartyBlock")] pub struct PyThirdPartyBlock(ThirdPartyBlock); -/// ed25519 keypair -#[pyclass(name = "KeyPair")] -pub struct PyKeyPair(KeyPair); - -#[pymethods] -impl PyKeyPair { - /// Generate a random keypair - #[new] - pub fn new() -> Self { - PyKeyPair(KeyPair::new()) - } - - /// Generate a keypair from a private key - /// - /// :param private_key: the private key - /// :type private_key: PrivateKey - /// :return: the corresponding keypair - /// :rtype: KeyPair - #[classmethod] - pub fn from_private_key(_: &Bound, private_key: PyPrivateKey) -> Self { - PyKeyPair(KeyPair::from(&private_key.0)) - } - - /// The public key part - #[getter] - pub fn public_key(&self) -> PyPublicKey { - PyPublicKey(self.0.public()) - } - - /// The private key part - #[getter] - pub fn private_key(&self) -> PyPrivateKey { - PyPrivateKey(self.0.private()) - } -} - -impl Default for PyKeyPair { - fn default() -> Self { - Self::new() - } -} - /// ed25519 public key #[derive(Clone)] #[pyclass(name = "PublicKey", from_py_object)] @@ -1301,6 +1264,18 @@ impl PyPrivateKey { Err(error) => Err(PyValueError::new_err(error.to_string())), } } + + /// Generate a random keypair + #[classmethod] + pub fn random(_: &Bound) -> Self { + PyPrivateKey(PrivateKey::new()) + } + + /// The public key part + #[getter] + pub fn public_key(&self) -> PyPublicKey { + PyPublicKey(self.0.public()) + } } /// Datalog term that can occur in a set @@ -1719,7 +1694,6 @@ impl PyUnverifiedBiscuit { /// Main module for the biscuit_auth lib #[pymodule] pub fn biscuit_auth(py: Python, m: &Bound) -> PyResult<()> { - m.add_class::()?; m.add_class::()?; m.add_class::()?; m.add_class::()?; @@ -1727,6 +1701,7 @@ pub fn biscuit_auth(py: Python, m: &Bound) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; m.add_class::()?; m.add_class::()?; m.add_class::()?; @@ -1749,5 +1724,48 @@ pub fn biscuit_auth(py: Python, m: &Bound) -> PyResult<()> { py.get_type::(), )?; + add_type_aliases(py, m)?; + + Ok(()) +} + +/// Runtime versions of the type aliases defined in biscuit_auth.pyi. +/// Keep both definitions in sync: stubtest only checks the names exist. +fn add_type_aliases(py: Python, m: &Bound) -> PyResult<()> { + let typing = py.import("typing")?; + let any = typing.getattr("Any")?; + let optional = typing.getattr("Optional")?; + let mapping = typing.getattr("Mapping")?; + let callable = typing.getattr("Callable")?; + let union = typing.getattr("Union")?; + let str_type = py.get_type::(); + let int_type = py.get_type::(); + let public_key = py.get_type::(); + + let term = any; + m.add( + "Parameters", + optional.get_item(mapping.get_item((&str_type, &term))?)?, + )?; + m.add( + "ScopeParameters", + optional.get_item(mapping.get_item((&str_type, &public_key))?)?, + )?; + m.add( + "PublicKeyProvider", + callable.get_item(( + PyList::new(py, [optional.get_item(&int_type)?])?, + &public_key, + ))?, + )?; + m.add( + "ExternFunc", + union.get_item(( + callable.get_item((PyList::new(py, [&term])?, &term))?, + callable.get_item((PyList::new(py, [&term, &term])?, &term))?, + ))?, + )?; + m.add("Term", term)?; + Ok(()) } diff --git a/stubtest-allowlist.txt b/stubtest-allowlist.txt new file mode 100644 index 0000000..b975726 --- /dev/null +++ b/stubtest-allowlist.txt @@ -0,0 +1,2 @@ +# compiled submodule, re-exported by the maturin-generated __init__.py +biscuit_auth.biscuit_auth