diff --git a/Cargo.lock b/Cargo.lock index 69f2985..fbcf2cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,11 +17,17 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64ct" -version = "1.6.0" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" [[package]] name = "bindgen" @@ -45,15 +51,35 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.6.0" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "531a9155a481e2ee699d4f98f43c0ca4ff8ee1bfd55c31e9e98fb29d2b176fe0" +dependencies = [ + "memchr", + "regex-automata 0.4.9", + "serde", +] [[package]] name = "bumpalo" -version = "3.16.0" +version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" [[package]] name = "byteorder" @@ -73,6 +99,18 @@ dependencies = [ "web-time", ] +[[package]] +name = "cargo_metadata" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202" +dependencies = [ + "semver", + "serde", + "serde_derive", + "serde_json", +] + [[package]] name = "cexpr" version = "0.6.0" @@ -99,6 +137,18 @@ dependencies = [ "libloading", ] +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "windows-sys", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -121,6 +171,37 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "der" version = "0.7.9" @@ -130,6 +211,7 @@ dependencies = [ "const-oid", "der_derive", "flagset", + "pem-rfc7468", "zeroize", ] @@ -144,11 +226,89 @@ dependencies = [ "syn", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + [[package]] name = "either" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pem-rfc7468", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + +[[package]] +name = "errno" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "ff" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] [[package]] name = "flagset" @@ -156,23 +316,68 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3ea1ec5f8307826a5b71094dd91fc04d4ae75d5709b20ad351c7fb4815c86ec" +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + [[package]] name = "getrandom" -version = "0.3.0" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71393ecc86efbf00e4ca13953979ba8b94cfe549a4b74cc26d8b62f4d8feac2b" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", - "wasi", - "windows-targets", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", ] [[package]] name = "glob" -version = "0.3.1" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" + +[[package]] +name = "goldenfile" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf39e208efa110ca273f7255aea02485103ffcb7e5dfa5e4196b05a02411618e" +dependencies = [ + "scopeguard", + "similar-asserts", + "tempfile", + "yansi", +] + +[[package]] +name = "group" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] [[package]] name = "hashbrown" @@ -186,6 +391,15 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "itertools" version = "0.13.0" @@ -195,12 +409,19 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + [[package]] name = "js-sys" -version = "0.3.72" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ + "once_cell", "wasm-bindgen", ] @@ -209,23 +430,38 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] [[package]] name = "libc" -version = "0.2.162" +version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", "windows-targets", ] +[[package]] +name = "libm" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" + +[[package]] +name = "linux-raw-sys" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413" + [[package]] name = "lock_api" version = "0.4.12" @@ -238,9 +474,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" [[package]] name = "matchers" @@ -268,12 +504,16 @@ name = "native-pkcs11" version = "0.2.26" dependencies = [ "cached", + "goldenfile", "native-pkcs11-core", "native-pkcs11-keychain", "native-pkcs11-traits", "native-pkcs11-windows", + "p256", "pkcs11-sys", + "rsa", "serial_test", + "test-cdylib", "thiserror", "tracing", "tracing-error", @@ -317,7 +557,7 @@ dependencies = [ name = "native-pkcs11-traits" version = "0.2.25" dependencies = [ - "rand", + "rand 0.9.0", "x509-cert", ] @@ -349,11 +589,58 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand 0.8.5", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + [[package]] name = "once_cell" -version = "1.20.2" +version = "1.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" [[package]] name = "overload" @@ -361,6 +648,18 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2", +] + [[package]] name = "parking_lot" version = "0.12.3" @@ -384,11 +683,20 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "pin-project-lite" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "pkcs1" @@ -397,6 +705,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" dependencies = [ "der", + "pkcs8", "spki", ] @@ -419,50 +728,85 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.20" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" dependencies = [ - "zerocopy 0.7.35", + "zerocopy", ] [[package]] name = "prettyplease" -version = "0.2.25" +version = "0.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +checksum = "5316f57387668042f561aae71480de936257848f9c43ce528e311d89a07cadeb" dependencies = [ "proc-macro2", "syn", ] +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.37" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + [[package]] name = "rand" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" dependencies = [ - "rand_chacha", - "rand_core", - "zerocopy 0.8.14", + "rand_chacha 0.9.0", + "rand_core 0.9.3", + "zerocopy", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", ] [[package]] @@ -472,24 +816,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.3", ] [[package]] name = "rand_core" -version = "0.9.0" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.15", +] + +[[package]] +name = "rand_core" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b08f3c9802962f7e1b25113931d94f43ed9725bebc59db9d0c3e9a23b67e15ff" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom", - "zerocopy 0.8.14", + "getrandom 0.3.2", ] [[package]] name = "redox_syscall" -version = "0.5.7" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" dependencies = [ "bitflags", ] @@ -538,23 +890,72 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "rsa" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78928ac1ed176a5ca1d17e578a1825f3d81ca54cf41053a592584b020cfd691b" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core 0.6.4", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rustc-hash" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustix" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7178faa4b75a30e269c71e61c353ce2748cf3d76f0c44c393f4e60abf49b825" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] [[package]] name = "rustversion" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "scc" -version = "2.2.4" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8d25269dd3a12467afe2e510f69fb0b46b698e5afb296b59f2145259deaf8e8" +checksum = "ea091f6cac2595aa38993f04f4ee692ed43757035c36e67c180b6828356385b1" dependencies = [ "sdd", ] @@ -567,9 +968,23 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sdd" -version = "3.0.4" +version = "3.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "584e070911c7017da6cb2eb0788d09f43d789029b5877d3e5ecc8acf86ceee21" + +[[package]] +name = "sec1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49c1eeaf4b6a87c7479688c6d52b9f1153cedd3c489300564f932b065c6eab95" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] [[package]] name = "security-framework" @@ -594,6 +1009,54 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", + "serde", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "serial_test" version = "3.2.0" @@ -617,6 +1080,17 @@ dependencies = [ "syn", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -632,11 +1106,47 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + +[[package]] +name = "similar" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" +dependencies = [ + "bstr", + "unicode-segmentation", +] + +[[package]] +name = "similar-asserts" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b441962c817e33508847a22bd82f03a30cff43642dc2fae8b050566121eb9a" +dependencies = [ + "console", + "similar", +] + [[package]] name = "smallvec" -version = "1.13.2" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" + +[[package]] +name = "spin" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "spki" @@ -667,17 +1177,48 @@ dependencies = [ "syn", ] +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" -version = "2.0.87" +version = "2.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488960f40a3fd53d72c2a29a58722561dee8afdd175bd88e3db4677d7b2ba600" +dependencies = [ + "fastrand", + "getrandom 0.3.2", + "once_cell", + "rustix", + "windows-sys", +] + +[[package]] +name = "test-cdylib" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8f41b1f729f5ff5177beab62e5a9251e318df8386e260ab3c944cff502ee78d" +dependencies = [ + "cargo_metadata", + "serde", + "serde_json", + "toml", +] + [[package]] name = "thiserror" version = "2.0.12" @@ -708,6 +1249,15 @@ dependencies = [ "once_cell", ] +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + [[package]] name = "tracing" version = "0.1.41" @@ -790,32 +1340,56 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "typenum" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" + [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "valuable" -version = "0.1.0" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "version_check" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" -version = "0.13.3+wasi-0.2.2" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" dependencies = [ "wit-bindgen-rt", ] [[package]] name = "wasm-bindgen" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", @@ -824,13 +1398,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn", @@ -839,9 +1412,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -849,9 +1422,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", @@ -862,9 +1435,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "web-time" @@ -999,6 +1575,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -1065,9 +1650,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "wit-bindgen-rt" -version = "0.33.0" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" dependencies = [ "bitflags", ] @@ -1084,40 +1669,25 @@ dependencies = [ ] [[package]] -name = "zerocopy" -version = "0.7.35" +name = "yansi" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive 0.7.35", -] +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" -version = "0.8.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a367f292d93d4eab890745e75a778da40909cab4d6ff8173693812f79c4a2468" -dependencies = [ - "zerocopy-derive 0.8.14", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" +version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +checksum = "fd97444d05a4328b90e75e503a34bad781f14e28a823ad3557f0750df1ebcbc6" dependencies = [ - "proc-macro2", - "quote", - "syn", + "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.14" +version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3931cb58c62c13adec22e38686b559c86a30565e16ad6e8510a337cedc611e1" +checksum = "6352c01d0edd5db859a63e2605f4ea3183ddbd15e2c4a9e7d32184df75e4f154" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 1c78427..c633633 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [workspace] resolver = "2" members = [ - "native-pkcs11", "native-pkcs11-core", - "native-pkcs11-traits", "native-pkcs11-keychain", - "pkcs11-sys", + "native-pkcs11-traits", "native-pkcs11-windows", + "native-pkcs11", + "pkcs11-sys", ] [workspace.package] diff --git a/native-pkcs11-fake/Cargo.toml b/native-pkcs11-fake/Cargo.toml new file mode 100644 index 0000000..700132a --- /dev/null +++ b/native-pkcs11-fake/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "native-pkcs11-fake" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +rust-version.workspace = true +repository.workspace = true +license.workspace = true + +[lib] +crate-type = ["cdylib"] + + +[dependencies] +native-pkcs11 = { path = "../native-pkcs11", features = [ + "custom-function-list", +] } +native-pkcs11-traits = { path = "../native-pkcs11-traits" } +test-cdylib = "1.1.0" diff --git a/native-pkcs11-fake/src/lib.rs b/native-pkcs11-fake/src/lib.rs new file mode 100644 index 0000000..ec4a8d5 --- /dev/null +++ b/native-pkcs11-fake/src/lib.rs @@ -0,0 +1,64 @@ +use std::ptr::addr_of_mut; + +use native_pkcs11::{CKR_OK, CK_FUNCTION_LIST_PTR_PTR, CK_RV, FUNC_LIST}; +use native_pkcs11_traits::{register_backend, Backend}; + +#[allow(non_snake_case)] +#[no_mangle] +#[allow(clippy::missing_safety_doc)] +pub unsafe extern "C" fn C_GetFunctionList(ppFunctionList: CK_FUNCTION_LIST_PTR_PTR) -> CK_RV { + register_backend(Box::new(FakeBackend {})); + unsafe { *ppFunctionList = addr_of_mut!(FUNC_LIST) }; + CKR_OK +} + +struct FakeBackend {} + +impl Backend for FakeBackend { + fn name(&self) -> String { + todo!() + } + + fn find_all_certificates( + &self, + ) -> native_pkcs11_traits::Result>> { + todo!() + } + + fn find_private_key( + &self, + _query: native_pkcs11_traits::KeySearchOptions, + ) -> native_pkcs11_traits::Result>> + { + todo!() + } + + fn find_public_key( + &self, + _query: native_pkcs11_traits::KeySearchOptions, + ) -> native_pkcs11_traits::Result>> { + todo!() + } + + fn find_all_private_keys( + &self, + ) -> native_pkcs11_traits::Result>> + { + todo!() + } + + fn find_all_public_keys( + &self, + ) -> native_pkcs11_traits::Result>> + { + todo!() + } + + fn generate_key( + &self, + _algorithm: native_pkcs11_traits::KeyAlgorithm, + _label: Option<&str>, + ) -> native_pkcs11_traits::Result> { + todo!() + } +} diff --git a/native-pkcs11/Cargo.toml b/native-pkcs11/Cargo.toml index a4f40f0..ce61ced 100644 --- a/native-pkcs11/Cargo.toml +++ b/native-pkcs11/Cargo.toml @@ -10,6 +10,7 @@ license.workspace = true [features] custom-function-list = [] +fake-backend = ["custom-function-list"] [dependencies] cached = { version = "~0.55", default-features = false } @@ -21,12 +22,17 @@ tracing = "0.1.41" tracing-error = "0.2.1" tracing-journald = "0.3" tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } +# TODO only for fake-backend feature +p256 = "0.13.2" +rsa = "0.9.7" [lib] -crate-type = ["lib", "cdylib"] +crate-type = ["cdylib", "lib"] [dev-dependencies] +goldenfile = "1.8.0" serial_test = { version = "3.2.0", default-features = false } +test-cdylib = "1.1.0" tracing = { version = "0.1.41", default-features = false } tracing-subscriber = { version = "0.3.19", default-features = false, features = [ "env-filter", diff --git a/native-pkcs11/src/fake_backend.rs b/native-pkcs11/src/fake_backend.rs new file mode 100644 index 0000000..0c1ff53 --- /dev/null +++ b/native-pkcs11/src/fake_backend.rs @@ -0,0 +1,158 @@ +use std::{ptr::addr_of_mut, sync::Arc}; + +use native_pkcs11_traits::{Backend, KeyAlgorithm, register_backend}; +use p256::{ecdsa::SigningKey, elliptic_curve::rand_core::OsRng}; +use rsa::RsaPrivateKey; + +use crate::{CK_FUNCTION_LIST_PTR_PTR, CK_RV, CKR_OK, FUNC_LIST}; + +#[allow(non_snake_case)] +#[unsafe(no_mangle)] +#[allow(clippy::missing_safety_doc)] +pub unsafe extern "C" fn C_GetFunctionList(ppFunctionList: CK_FUNCTION_LIST_PTR_PTR) -> CK_RV { + register_backend(Box::new(FakeBackend {})); + unsafe { *ppFunctionList = addr_of_mut!(FUNC_LIST) }; + CKR_OK +} + +struct FakeBackend {} + +impl Backend for FakeBackend { + fn name(&self) -> String { + "native-pkcs11 fake backend".to_string() + } + + fn find_all_certificates( + &self, + ) -> native_pkcs11_traits::Result>> { + Ok(vec![]) + } + + fn find_private_key( + &self, + query: native_pkcs11_traits::KeySearchOptions, + ) -> native_pkcs11_traits::Result>> + { + match query { + native_pkcs11_traits::KeySearchOptions::Label(label) => { + Ok(Some(Arc::new(PrivateKey::new(&label, KeyAlgorithm::Ecc)))) + } + native_pkcs11_traits::KeySearchOptions::PublicKeyHash(_) => { + Ok(Some(Arc::new(PrivateKey::new("TODO", KeyAlgorithm::Ecc)))) + } + } + } + + fn find_public_key( + &self, + query: native_pkcs11_traits::KeySearchOptions, + ) -> native_pkcs11_traits::Result>> { + match query { + native_pkcs11_traits::KeySearchOptions::Label(_) => todo!(), + native_pkcs11_traits::KeySearchOptions::PublicKeyHash(_) => { + Ok(Some(Box::new(PrivateKey::new("TODO", KeyAlgorithm::Ecc)))) + } + } + } + + fn find_all_private_keys( + &self, + ) -> native_pkcs11_traits::Result>> + { + Ok(vec![]) + } + + fn find_all_public_keys( + &self, + ) -> native_pkcs11_traits::Result>> + { + todo!() + } + + fn generate_key( + &self, + algorithm: native_pkcs11_traits::KeyAlgorithm, + _label: Option<&str>, + ) -> native_pkcs11_traits::Result> { + let key = Arc::new(PrivateKey::new("TODO", algorithm)); + Ok(key) + } +} + +#[allow(clippy::large_enum_variant)] +#[allow(dead_code)] +#[derive(Debug)] +enum PrivateKey { + Ecc(String, SigningKey), + Rsa(String, RsaPrivateKey), +} + +impl PrivateKey { + fn new(label: &str, algorithm: KeyAlgorithm) -> Self { + match algorithm { + KeyAlgorithm::Rsa => { + Self::Rsa(label.to_owned(), RsaPrivateKey::new(&mut OsRng, 2048).unwrap()) + } + KeyAlgorithm::Ecc => Self::Ecc(label.to_owned(), SigningKey::random(&mut OsRng)), + } + } +} + +impl native_pkcs11_traits::PrivateKey for PrivateKey { + fn public_key_hash(&self) -> Vec { + vec![0; 20] + } + + fn label(&self) -> String { + match self { + Self::Ecc(label, _) => label.clone(), + Self::Rsa(label, _) => label.clone(), + } + } + + fn sign( + &self, + _algorithm: &native_pkcs11_traits::SignatureAlgorithm, + _data: &[u8], + ) -> native_pkcs11_traits::Result> { + todo!() + } + + fn delete(&self) {} + + fn algorithm(&self) -> native_pkcs11_traits::KeyAlgorithm { + match self { + Self::Ecc(..) => KeyAlgorithm::Ecc, + Self::Rsa(..) => KeyAlgorithm::Rsa, + } + } +} + +impl native_pkcs11_traits::PublicKey for PrivateKey { + fn public_key_hash(&self) -> Vec { + todo!() + } + + fn label(&self) -> String { + todo!() + } + + fn to_der(&self) -> Vec { + todo!() + } + + fn verify( + &self, + _algorithm: &native_pkcs11_traits::SignatureAlgorithm, + _data: &[u8], + _signature: &[u8], + ) -> native_pkcs11_traits::Result<()> { + todo!() + } + + fn delete(self: Box) {} + + fn algorithm(&self) -> KeyAlgorithm { + todo!() + } +} diff --git a/native-pkcs11/src/lib.rs b/native-pkcs11/src/lib.rs index 29659a5..d0f4c9b 100644 --- a/native-pkcs11/src/lib.rs +++ b/native-pkcs11/src/lib.rs @@ -16,15 +16,6 @@ #![allow(clippy::missing_safety_doc)] #![deny(unsafe_op_in_unsafe_fn)] -pub use native_pkcs11_core::Error; -use native_pkcs11_traits::backend; -use tracing::metadata::LevelFilter; -use tracing_error::ErrorLayer; -use tracing_subscriber::{EnvFilter, Registry, fmt::format::FmtSpan, prelude::*}; -mod object_store; -mod sessions; -mod utils; - use std::{ cmp, slice, @@ -34,18 +25,29 @@ use std::{ }, }; +pub use native_pkcs11_core::Error; use native_pkcs11_core::{ attribute::{Attribute, Attributes}, mechanism::{SUPPORTED_SIGNATURE_MECHANISMS, parse_mechanism}, object::{self, Object}, }; +use native_pkcs11_traits::backend; use pkcs11_sys::*; +use tracing::metadata::LevelFilter; +use tracing_error::ErrorLayer; +use tracing_subscriber::{EnvFilter, Registry, fmt::format::FmtSpan, prelude::*}; use crate::{ sessions::{FindContext, SignContext}, utils::right_pad_string_to_array, }; +#[cfg(feature = "fake-backend")] +mod fake_backend; +mod object_store; +mod sessions; +mod utils; + const LIBRARY_DESCRIPTION: &[u8; 32] = b" "; const MANUFACTURER_ID: &[u8; 32] = b"google "; const SLOT_DESCRIPTION: &[u8; 64] = diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_interfaces.stderr.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_interfaces.stderr.txt new file mode 100644 index 0000000..7d5c261 --- /dev/null +++ b/native-pkcs11/tests/goldens/pkcs11-tool/list_interfaces.stderr.txt @@ -0,0 +1 @@ +Interfaces are supported only in PKCS #11 3.0 and newer diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_interfaces.stdout.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_interfaces.stdout.txt new file mode 100644 index 0000000..e69de29 diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_mechanisms.stderr.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_mechanisms.stderr.txt new file mode 100644 index 0000000..c55db56 --- /dev/null +++ b/native-pkcs11/tests/goldens/pkcs11-tool/list_mechanisms.stderr.txt @@ -0,0 +1 @@ +Using slot 0 with a present token (0x1) diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_mechanisms.stdout.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_mechanisms.stdout.txt new file mode 100644 index 0000000..41764d1 --- /dev/null +++ b/native-pkcs11/tests/goldens/pkcs11-tool/list_mechanisms.stdout.txt @@ -0,0 +1,8 @@ +Supported mechanisms: + RSA-PKCS, sign + SHA1-RSA-PKCS, sign + SHA256-RSA-PKCS, sign + SHA384-RSA-PKCS, sign + SHA512-RSA-PKCS, sign + ECDSA, sign + RSA-PKCS-PSS, sign diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_objects.stderr.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_objects.stderr.txt new file mode 100644 index 0000000..c55db56 --- /dev/null +++ b/native-pkcs11/tests/goldens/pkcs11-tool/list_objects.stderr.txt @@ -0,0 +1 @@ +Using slot 0 with a present token (0x1) diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_objects.stdout.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_objects.stdout.txt new file mode 100644 index 0000000..7dade10 --- /dev/null +++ b/native-pkcs11/tests/goldens/pkcs11-tool/list_objects.stdout.txt @@ -0,0 +1,2 @@ +Profile object 1 + profile_id: CKP_BASELINE_PROVIDER (1) diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_slots.stderr.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_slots.stderr.txt new file mode 100644 index 0000000..e69de29 diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_slots.stdout.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_slots.stdout.txt new file mode 100644 index 0000000..fa7d2ad --- /dev/null +++ b/native-pkcs11/tests/goldens/pkcs11-tool/list_slots.stdout.txt @@ -0,0 +1,11 @@ +Available slots: +Slot 0 (0x1): Platform Cryptography Support + token label : native-pkcs11 fake backend + token manufacturer : google + token model : software + token flags : PIN pad present, token initialized, readonly + hardware version : 0.0 + firmware version : 0.0 + serial num : 0000000000000000 + pin min/max : 0/0 + uri : pkcs11:model=software;manufacturer=google;serial=0000000000000000;token=native-pkcs11%20fake%20backend diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_token_slots.stderr.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_token_slots.stderr.txt new file mode 100644 index 0000000..e69de29 diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/list_token_slots.stdout.txt b/native-pkcs11/tests/goldens/pkcs11-tool/list_token_slots.stdout.txt new file mode 100644 index 0000000..fa7d2ad --- /dev/null +++ b/native-pkcs11/tests/goldens/pkcs11-tool/list_token_slots.stdout.txt @@ -0,0 +1,11 @@ +Available slots: +Slot 0 (0x1): Platform Cryptography Support + token label : native-pkcs11 fake backend + token manufacturer : google + token model : software + token flags : PIN pad present, token initialized, readonly + hardware version : 0.0 + firmware version : 0.0 + serial num : 0000000000000000 + pin min/max : 0/0 + uri : pkcs11:model=software;manufacturer=google;serial=0000000000000000;token=native-pkcs11%20fake%20backend diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/show_info.stderr.txt b/native-pkcs11/tests/goldens/pkcs11-tool/show_info.stderr.txt new file mode 100644 index 0000000..c55db56 --- /dev/null +++ b/native-pkcs11/tests/goldens/pkcs11-tool/show_info.stderr.txt @@ -0,0 +1 @@ +Using slot 0 with a present token (0x1) diff --git a/native-pkcs11/tests/goldens/pkcs11-tool/show_info.stdout.txt b/native-pkcs11/tests/goldens/pkcs11-tool/show_info.stdout.txt new file mode 100644 index 0000000..7c3821f --- /dev/null +++ b/native-pkcs11/tests/goldens/pkcs11-tool/show_info.stdout.txt @@ -0,0 +1,3 @@ +Cryptoki version 3.1 +Manufacturer google +Library (ver 0.1) diff --git a/native-pkcs11/tests/pkcs11_tool.rs b/native-pkcs11/tests/pkcs11_tool.rs new file mode 100644 index 0000000..d5faa8b --- /dev/null +++ b/native-pkcs11/tests/pkcs11_tool.rs @@ -0,0 +1,36 @@ +use std::{collections::HashMap, io::Write}; + +use goldenfile::Mint; + +#[test] +fn test_pkcs11_tool() { + let mut mint = Mint::new("tests/goldens/pkcs11-tool"); + let dylib_path = test_cdylib::build_current_project(); + + let mut test_cases = HashMap::new(); + test_cases.insert("show_info", "--show-info"); + test_cases.insert("list_slots", "--list-slots"); + test_cases.insert("list_token_slots", "--list-token-slots"); + test_cases.insert("list_mechanisms", "--list-mechanisms"); + test_cases.insert("list_objects", "--list-objects"); + test_cases.insert("list_interfaces", "--list-interfaces"); + + for (test_name, args) in test_cases { + eprintln!("Running pkcs11-tool {}", test_name); + let output = std::process::Command::new("pkcs11-tool") + .arg("--module") + .arg(&dylib_path) + .arg(args) + .output() + .expect("Failed to execute pkcs11-tool"); + + mint.new_goldenfile(format!("{}.stdout.txt", test_name)) + .unwrap() + .write_all(&output.stdout) + .unwrap(); + mint.new_goldenfile(format!("{}.stderr.txt", test_name)) + .unwrap() + .write_all(&output.stderr) + .unwrap(); + } +}