Use sha1 module for hashing instead of openssl, part of https://github.com/iceiix/steven/issues/2

This commit is contained in:
ice_iix 2018-09-29 22:23:48 -07:00
parent 47aeb83da2
commit 163556fbf1
4 changed files with 16 additions and 8 deletions

7
Cargo.lock generated
View File

@ -16,6 +16,7 @@ dependencies = [
"sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"steven_blocks 0.0.1",
"steven_gl 0.0.1",
"steven_resources 0.1.0",
@ -537,6 +538,11 @@ dependencies = [
"serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sha1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "solicit"
version = "0.4.4"
@ -755,6 +761,7 @@ dependencies = [
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
"checksum serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0e0732aa8ec4267f61815a396a942ba3525062e3bd5520aa8419927cfc0a92"
"checksum serde_json 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b22e8a0554f31cb0f501e027de07b253553b308124f61c57598b9678dba35c0b"
"checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
"checksum solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "172382bac9424588d7840732b250faeeef88942e37b6e35317dce98cafdd75b2"
"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6"
"checksum time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7ec6d62a20df54e07ab3b78b9a3932972f4b7981de295563686849eb3989af"

View File

@ -10,6 +10,7 @@ authors = [ "Thinkofdeath <thinkofdeath@spigotmc.org>" ]
opt-level = 1
[dependencies]
sha1 = "0.6.0"
sdl2 = "0.31.0"
byteorder = "0.5.0"
hyper = "0.8.0"

View File

@ -22,6 +22,7 @@ extern crate time;
extern crate byteorder;
extern crate serde_json;
extern crate openssl;
extern crate sha1;
extern crate hyper;
extern crate flate2;
extern crate rand;

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use openssl::crypto::hash;
use sha1;
use serde_json;
use serde_json::builder::ObjectBuilder;
use hyper;
@ -101,12 +101,11 @@ impl Profile {
}
pub fn join_server(&self, server_id: &str, shared_key: &[u8], public_key: &[u8]) -> Result<(), super::Error> {
use std::io::Write;
let mut sha1 = hash::Hasher::new(hash::Type::SHA1);
sha1.write_all(server_id.as_bytes()).unwrap();
sha1.write_all(shared_key).unwrap();
sha1.write_all(public_key).unwrap();
let mut hash = sha1.finish();
let mut sha1 = sha1::Sha1::new();
sha1.update(server_id.as_bytes());
sha1.update(shared_key);
sha1.update(public_key);
let mut hash = sha1.digest().bytes();
// Mojang uses a hex method which allows for
// negatives so we have to account for that.
@ -147,7 +146,7 @@ impl Profile {
}
}
fn twos_compliment(data: &mut Vec<u8>) {
fn twos_compliment(data: &mut [u8]) {
let mut carry = true;
for i in (0..data.len()).rev() {
data[i] = !data[i];