parallaxsecond / rust-cryptoki

Rust wrapper for the PKCS #11 API, Cryptoki
https://docs.rs/cryptoki/
Apache License 2.0
75 stars 61 forks source link

Wasm support #189

Open Tartopoms opened 1 year ago

Tartopoms commented 1 year ago

Cannot compile cryptoki-sys to wasm target

Related to: Cannot compile dependency: could not find Library in libloading #1641

When I build, watch & serve a Rust WASM app with cryptoki, its dependency cryptoki-sys raise a compilation error.

The error is:

# cargo check --target wasm32-unknown-unknown
    Checking ...
    Checking cryptoki-sys v0.1.7 (registry `custom-regsitry`)
error[E0433]: failed to resolve: could not find `Library` in `libloading`
    --> /root/.cargo/registry/src/custom-regsitry-url/cryptoki-sys-0.1.7/src/bindings/generic.rs:2164:37
     |
2164 |         let library = ::libloading::Library::new(path)?;
     |                                     ^^^^^^^ could not find `Library` in `libloading`

error[E0412]: cannot find type `Library` in crate `libloading`
    --> /root/.cargo/registry/src/custom-regsitry-url/cryptoki-sys-0.1.7/src/bindings/generic.rs:1634:30
     |
1634 |     __library: ::libloading::Library,
     |                              ^^^^^^^ not found in `libloading`

error[E0412]: cannot find type `Library` in crate `libloading`
    --> /root/.cargo/registry/src/custom-regsitry-url/cryptoki-sys-0.1.7/src/bindings/generic.rs:2169:31
     |
2169 |         L: Into<::libloading::Library>,
     |                               ^^^^^^^ not found in `libloading`

Some errors have detailed explanations: E0412, E0433.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `cryptoki-sys` (lib) due to 3 previous errors

Steps To Reproduce

Expected behavior

Being able to compile after running dx serve:

Project Reloaded: Changed 1 files. [xx:xx:xx]

        > Local : http://localhost:8080/
        > Network : http://<IP>:8080/
        > HTTPS : Disabled

        > Profile : Debug
        > Hot Reload : Normal
        > Index Template : Default
        > URL Rewrite [index_on_404] : False

        > Build Time Use : 1190 millis

[INFO] A perfect compilation!

Environment:

I'm working on a Docker Container, offline, with a custom Rust toolchain and a custom registry. I've been working with them for 3 months and have never had a problem so far, so I want to remove these two from the possible error case.

With my toolchain and registry: I have two full Rust apps working. One with an Axum server and Dioxus client, communicating with REST and WebSockets. Another with cryptoki (RSA PKCS#11), without any issue so far.

Questionnaire

wiktor-k commented 1 year ago

Just out of curiosity what would be the use case? Cryptoki frequently needs PKCS11 driver anyway and you'd have to be able to access the device somehow (eg. via pcsclite).

Tartopoms commented 1 year ago

I'm working on a light web client to interact with an HSM and a database.