iceiix / stevenarella

Multi-protocol Minecraft-compatible client written in Rust
Apache License 2.0
1.46k stars 60 forks source link

feather: RSA Issue "RSA error: message representative out of range"', src\server\mod.rs:203:80 #507

Open ColdIce1605 opened 3 years ago

ColdIce1605 commented 3 years ago

Seems it doesn't like 3rd party servers. ie Feather

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "RSA error: message representative out of range"', src\server\mod.rs:203:80

I'll also Open a feather issue

Reported by Feather

2021-02-21 18:23:36,603 DEBUG [feather_server::initial_handler] _COLDICE_ is logging in
2021-02-21 18:23:36,603 DEBUG [feather_server::initial_handler] Authenticating _COLDICE_
2021-02-21 18:23:36,604 DEBUG [feather_server::connection_worker] Initial handling failed: read 0 bytes
2021-02-21 18:23:36,605 TRACE [mio::poll] deregistering event source from poller
2021-02-21 18:26:45,860 TRACE [mio::poll] registering event source with poller: token=Token(100663297), interests=READABLE | WRITABLE
2021-02-21 18:26:45,860 TRACE [mio::poll] deregistering event source from poller
2021-02-21 18:26:48,663 TRACE [mio::poll] registering event source with poller: token=Token(117440513), interests=READABLE | WRITABLE
2021-02-21 18:26:48,663 TRACE [mio::poll] deregistering event source from poller
2021-02-21 18:26:50,696 TRACE [mio::poll] registering event source with poller: token=Token(134217729), interests=READABLE | WRITABLE
ColdIce1605 commented 3 years ago

https://github.com/feather-rs/feather/issues/345

iceiix commented 3 years ago

Some investigation of this issue in https://github.com/iceiix/stevenarella/issues/465#issuecomment-781740317:

       let shared_e = rsa_public_encrypt_pkcs1::encrypt(&public_key, &shared).unwrap();

this is from my other module (a quick-and-dirty RSA encryption library to replace the more heavyweight OpenSSL dependency I wanted to get rid of, but couldn't find a similarly lightweight Rust library replacement - maybe there is one now): https://github.com/iceiix/rsa_public_encrypt_pkcs1/blob/master/src/lib.rs#L110

where I added this check based on RFC8017:

   // https://tools.ietf.org/html/rfc8017#section-5.1.1
   /* 1.  If the message representative m is not between 0 and n - 1,
    *     output "message representative out of range" and stop.
    */
   if m.sign() != num::bigint::Sign::Plus || m > n - 1 {
       return Err("RSA error: message representative out of range".to_string());
   }

I wonder which condition is failing (m is negative, or greater than n - 1?)

but I wasn't able to reproduce this issue myself with https://github.com/feather-rs/feather branch 1.16 commit 56dce3188d75c40085cc94f58887eec37f80e6e4

ColdIce1605 commented 3 years ago

still happens on latest, still no way to rep, both on latest feather and stevenarella.

Supermath101 commented 3 years ago

I've got these working together on Manjaro Linux. However, there's a glitch: Photo of Glitch

iceiix commented 3 years ago

@Supermath101 for that glitch, it often means there was an issue loading the world, or placing the player into the world (for example, maybe they spawned inside a block? can other players see the player? teleport to a new location? etc.)