Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jwt_compact::traits::Algorithm is not implemented for Ed25519 #10

Open
supchuck opened this issue Jul 9, 2023 · 10 comments
Open

jwt_compact::traits::Algorithm is not implemented for Ed25519 #10

supchuck opened this issue Jul 9, 2023 · 10 comments

Comments

@supchuck
Copy link

supchuck commented Jul 9, 2023

I am currently receiving the error mentioned above when I try to compile code utilizing a TokenSigner, however did not receive any such error when using a CookieSigner. This only began after recently updating to version 0.3.0. My code is as follows:

let token_signer = TokenSigner::<UserJWT, _>::new()
        .signing_key(key_pair.sk.clone())
        .access_token_name("user_access_token")
        //Token's lifespan is 2 hours, then requires reauthentication
        .refresh_token_lifetime(chrono::Duration::minutes(120))
        .algorithm(Ed25519)
        .build()
        .unwrap();

The full error output is as follows (this output is also produced if I copy and paste the example code on docs.rs for a TokenSigner):

error[E0277]: the trait bound `Ed25519: jwt_compact::traits::Algorithm` is not satisfied
   --> src/main.rs:157:24
    |
157 |     let token_signer = TokenSigner::<UserJWT, _>::new()
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `jwt_compact::traits::Algorithm` is not implemented for `Ed25519`
    |
    = help: the following other types implement trait `jwt_compact::traits::Algorithm`:
              jwt_compact::alg::StrongAlg<T>
              jwt_compact::alg::hmacs::Hs256
              jwt_compact::alg::hmacs::Hs384
              jwt_compact::alg::hmacs::Hs512
              jwt_compact::traits::Renamed<A>
note: required by a bound in `TokenSigner::<Claims, Algorithm>::new`
   --> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-jwt-auth-middleware-0.3.0/src/token_signer.rs:129:16
    |
129 |     Algorithm: jwt_compact::Algorithm + Clone,
    |                ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `TokenSigner::<Claims, Algorithm>::new`

error[E0277]: the trait bound `Ed25519: jwt_compact::traits::Algorithm` is not satisfied
   --> src/main.rs:157:24
    |
157 |     let token_signer = TokenSigner::<UserJWT, _>::new()
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `jwt_compact::traits::Algorithm` is not implemented for `Ed25519`
    |
    = help: the following other types implement trait `jwt_compact::traits::Algorithm`:
              jwt_compact::alg::StrongAlg<T>
              jwt_compact::alg::hmacs::Hs256
              jwt_compact::alg::hmacs::Hs384
              jwt_compact::alg::hmacs::Hs512
              jwt_compact::traits::Renamed<A>
note: required by a bound in `TokenSigner`
   --> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-jwt-auth-middleware-0.3.0/src/token_signer.rs:57:11
    |
57  |     Algo: Algorithm,
    |           ^^^^^^^^^ required by this bound in `TokenSigner`

error[E0277]: the trait bound `Ed25519: jwt_compact::traits::Algorithm` is not satisfied
   --> src/main.rs:158:10
    |
158 |         .signing_key(key_pair.sk.clone())
    |          ^^^^^^^^^^^ the trait `jwt_compact::traits::Algorithm` is not implemented for `Ed25519`
    |
    = help: the following other types implement trait `jwt_compact::traits::Algorithm`:
              jwt_compact::alg::StrongAlg<T>
              jwt_compact::alg::hmacs::Hs256
              jwt_compact::alg::hmacs::Hs384
              jwt_compact::alg::hmacs::Hs512
              jwt_compact::traits::Renamed<A>
note: required by a bound in `TokenSignerBuilder::<Claims, Algo>::signing_key`
   --> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-jwt-auth-middleware-0.3.0/src/token_signer.rs:57:11
    |
57  |     Algo: Algorithm,
    |           ^^^^^^^^^ required by this bound in `TokenSignerBuilder::<Claims, Algo>::signing_key`

error[E0277]: the trait bound `Ed25519: jwt_compact::traits::Algorithm` is not satisfied
   --> src/main.rs:159:10
    |
159 |         .access_token_name("user_access_token")
    |          ^^^^^^^^^^^^^^^^^ the trait `jwt_compact::traits::Algorithm` is not implemented for `Ed25519`
    |
    = help: the following other types implement trait `jwt_compact::traits::Algorithm`:
              jwt_compact::alg::StrongAlg<T>
              jwt_compact::alg::hmacs::Hs256
              jwt_compact::alg::hmacs::Hs384
              jwt_compact::alg::hmacs::Hs512
              jwt_compact::traits::Renamed<A>
note: required by a bound in `TokenSignerBuilder::<Claims, Algo>::access_token_name`
   --> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-jwt-auth-middleware-0.3.0/src/token_signer.rs:57:11
    |
57  |     Algo: Algorithm,
    |           ^^^^^^^^^ required by this bound in `TokenSignerBuilder::<Claims, Algo>::access_token_name`

error[E0277]: the trait bound `Ed25519: jwt_compact::traits::Algorithm` is not satisfied
   --> src/main.rs:161:10
    |
161 |         .refresh_token_lifetime(chrono::Duration::minutes(120))
    |          ^^^^^^^^^^^^^^^^^^^^^^ the trait `jwt_compact::traits::Algorithm` is not implemented for `Ed25519`
    |
    = help: the following other types implement trait `jwt_compact::traits::Algorithm`:
              jwt_compact::alg::StrongAlg<T>
              jwt_compact::alg::hmacs::Hs256
              jwt_compact::alg::hmacs::Hs384
              jwt_compact::alg::hmacs::Hs512
              jwt_compact::traits::Renamed<A>
note: required by a bound in `TokenSignerBuilder::<Claims, Algo>::refresh_token_lifetime`
   --> /home//.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-jwt-auth-middleware-0.3.0/src/token_signer.rs:57:11
    |
57  |     Algo: Algorithm,
    |           ^^^^^^^^^ required by this bound in `TokenSignerBuilder::<Claims, Algo>::refresh_token_lifetime`

error[E0277]: the trait bound `Ed25519: jwt_compact::traits::Algorithm` is not satisfied
   --> src/main.rs:162:10
    |
162 |         .algorithm(Ed25519)
    |          ^^^^^^^^^ the trait `jwt_compact::traits::Algorithm` is not implemented for `Ed25519`
    |
    = help: the following other types implement trait `jwt_compact::traits::Algorithm`:
              jwt_compact::alg::StrongAlg<T>
              jwt_compact::alg::hmacs::Hs256
              jwt_compact::alg::hmacs::Hs384
              jwt_compact::alg::hmacs::Hs512
              jwt_compact::traits::Renamed<A>
note: required by a bound in `TokenSignerBuilder::<Claims, Algo>::algorithm`
   --> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-jwt-auth-middleware-0.3.0/src/token_signer.rs:57:11
    |
57  |     Algo: Algorithm,
    |           ^^^^^^^^^ required by this bound in `TokenSignerBuilder::<Claims, Algo>::algorithm`

error[E0599]: the method `build` exists for struct `TokenSignerBuilder<UserJWT, Ed25519>`, but its trait bounds were not satisfied
   --> src/main.rs:163:10
    |
157 |       let token_signer = TokenSigner::<UserJWT, _>::new()
    |  ________________________-
158 | |         .signing_key(key_pair.sk.clone())
159 | |         .access_token_name("user_access_token")
160 | |         //Token's lifespan is 2 hours, then requires reauthentication
161 | |         .refresh_token_lifetime(chrono::Duration::minutes(120))
162 | |         .algorithm(Ed25519)
163 | |         .build()
    | |         -^^^^^ method cannot be called on `TokenSignerBuilder<UserJWT, Ed25519>` due to unsatisfied trait bounds
    | |_________|
    | 
    |
   ::: /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jwt-compact-0.8.0-beta.1/src/alg/eddsa_compact.rs:36:1
    |
36  |   pub struct Ed25519;
    |   ------------------ doesn't satisfy `Ed25519: jwt_compact::traits::Algorithm`
    |
    = note: the following trait bounds were not satisfied:
            `Ed25519: jwt_compact::traits::Algorithm`
@michaelvanstraten
Copy link
Owner

Im gone take a look at it when I get home in about 10 hours.

@michaelvanstraten
Copy link
Owner

Have you added one of the Features respective to their implementation?

@supchuck
Copy link
Author

supchuck commented Jul 9, 2023

Using exonum-crypto, I tried:

jwt-compact = {version = "0.7.0", features=["exonum-crypto"]}

as well as the beta version, just to see if there was any difference,

jwt-compact = {version = "0.8.0-beta.1", features=["exonum-crypto"]}

both of which led to the error.

Since, I've switched to ed25519-compact and received the error on 0.8.0-beta.1 of JWT-compact but when I used the current version (0.7.0), I do appear to have any issue.

jwt-compact = {version = "0.7.0", features=["ed25519-compact"]}

I plan to test it further tonight as well but am not able to access my computer at the moment (away from the house).

@michaelvanstraten
Copy link
Owner

It would be great if you could share a minimal example to reproduce the error.

@supchuck
Copy link
Author

supchuck commented Jul 10, 2023

Here is the version that works; I commented out the exonum-crypto that always fails so you can uncomment it and switch between the two.. When Cargo.toml (below) is switched to 0.8.0-beta.1 for jwt-compact using ed25519-compact, it will fail. It fails each time when using exonum-crypto for jwt-compact in versions 0.7.0 or 0.8.0-beta.1. I do have a working program using jwt-compact 0.7.0 with ed25519-compact. I also just found out that exonum-crypto is no longer available for linux so I'm not that concerned about continuing its use but thought I would still pass this along.

src/main.rs:

use actix_jwt_auth_middleware::{AuthenticationService, Authority, FromRequest, TokenSigner};
use actix_web::{
    cookie::time::Duration,
    web::{self, Data},
    App, HttpServer,
};
use jwt_compact::alg::Ed25519;

//Exonum-crypto example
//use exonum_crypto::KeyPair;

//ed25519-compact example
use ed25519_compact::{KeyPair, Seed};

use serde::Serialize;

#[derive(Serialize)]
pub struct UserJWT {
    pub id: i32,
}

#[actix_rt::main]
async fn main() -> std::io::Result<()> {

/*
    //exonum-cryptro minimal test  
    //Create the key pair to be used with the token signer.
    let key_pair = KeyPair::random();

    //Used for the JWT
    let token_signer = TokenSigner::<UserJWT, _>::new()
        .signing_key(key_pair.secret_key().clone())
        .access_token_name("user_access_token")
        //Token's lifespan is 2 hours, then requires reauthentication
        .refresh_token_lifetime(chrono::Duration::minutes(120))
        .algorithm(Ed25519)
        .build()
    .unwrap();
*/
    //######################################################
    
    //ed25519-compact minimal test (works for jwt-compact 0.7.0 but not 0.8.0-beta.1)
    //Create the key pair to be used with the token signer.
    let key_pair = KeyPair::from_seed(Seed::default());

    //Used for the JWT
    let token_signer = TokenSigner::<UserJWT, _>::new()
        .signing_key(key_pair.sk.clone())
        .access_token_name("user_access_token")
        //Token's lifespan is 2 hours, then requires reauthentication
        .refresh_token_lifetime(chrono::Duration::minutes(120))
        .algorithm(Ed25519)
        .build()
        .unwrap();

     HttpServer::new(move || {
        //Create the web app
        App::new()
           
    })
    //Bind to the local address on port 8888
    .bind("127.0.0.1:8888")?
    .run()
    .await
}

Cargo.toml:

[package]
name = "min_reproducable"
version = "0.1.0"
edition = "2021"

[dependencies]
actix-rt = "2.8.0"
actix-web = {version = "4.3.1", features=["openssl"]}
actix-jwt-auth-middleware = "0.3.0"

#Exonum fails for both 0.7.0 & 0.8.0 Beta
#exonum-crypto = "1.0.0"
#jwt-compact = {version = "0.7.0", features=["exonum-crypto"]}
#jwt-compact = {version = "0.8.0-beta.1", features=["exonum-crypto"]}

#This works when jwt-compact version = 0.7.0, but not 0.8.0 Beta
ed25519-compact = "2.0.4"
jwt-compact = {version = "0.7.0", features=["ed25519-compact"]}
#jwt-compact = {version = "0.8.0-beta.1", features=["ed25519-compact"]}

chrono = {version = "0.4.26", features = ["serde"]}
serde = "1.0.166"

@michaelvanstraten
Copy link
Owner

michaelvanstraten commented Jul 28, 2023

Sorry Mate, your minimal example compiles on my system just fine.

Here is the head of my os-release (x64):

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Could you share some info about your system?

I would also try to delete the cargo build cache:

cargo clean

@michaelvanstraten
Copy link
Owner

@supchuck does this issue still a cure?

@supchuck
Copy link
Author

supchuck commented Aug 11, 2023 via email

@Apollo-XIV
Copy link

I've been having this same issue, resolved it by reverting back to jwt_compact to 0.7.0. I've been stuck on this for a few days now and I can't make any sense of what must be going wrong. I can only assume that jwt_compact 0.8 introduced some module layout changes.

@michaelvanstraten
Copy link
Owner

I will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants