Drop steven_openssl in favor of using the openssl crate (Closes #31)
This commit is contained in:
parent
5614fa07b5
commit
d1b3180e9a
|
@ -14,7 +14,7 @@
|
|||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use openssl;
|
||||
use openssl::crypto::symm;
|
||||
use serde_json;
|
||||
use hyper;
|
||||
|
||||
|
@ -720,13 +720,16 @@ pub struct Conn {
|
|||
direction: Direction,
|
||||
pub state: State,
|
||||
|
||||
cipher: Option<openssl::EVPCipher>,
|
||||
cipher: Option<symm::Crypter>,
|
||||
|
||||
compression_threshold: i32,
|
||||
compression_read: Option<ZlibDecoder<io::Cursor<Vec<u8>>>>,
|
||||
compression_write: Option<ZlibEncoder<io::Cursor<Vec<u8>>>>,
|
||||
}
|
||||
|
||||
// Needed because symm::Crypter isn't send
|
||||
unsafe impl Send for Conn {}
|
||||
|
||||
impl Conn {
|
||||
pub fn new(target: &str) -> Result<Conn, Error> {
|
||||
// TODO SRV record support
|
||||
|
@ -832,7 +835,9 @@ impl Conn {
|
|||
}
|
||||
|
||||
pub fn enable_encyption(&mut self, key: &[u8], decrypt: bool) {
|
||||
self.cipher = Option::Some(openssl::EVPCipher::new(key, key, decrypt));
|
||||
let cipher = symm::Crypter::new(symm::Type::AES_128_CFB8);
|
||||
cipher.init(if decrypt { symm::Mode::Decrypt } else { symm::Mode::Encrypt }, key, key);
|
||||
self.cipher = Option::Some(cipher);
|
||||
}
|
||||
|
||||
pub fn set_compresssion(&mut self, threshold: i32) {
|
||||
|
@ -940,7 +945,7 @@ impl Read for Conn {
|
|||
Option::None => self.stream.read(buf),
|
||||
Option::Some(cipher) => {
|
||||
let ret = try!(self.stream.read(buf));
|
||||
let data = cipher.decrypt(&buf[..ret]);
|
||||
let data = cipher.update(&buf[..ret]);
|
||||
for i in 0..ret {
|
||||
buf[i] = data[i];
|
||||
}
|
||||
|
@ -955,7 +960,7 @@ impl Write for Conn {
|
|||
match self.cipher.as_mut() {
|
||||
Option::None => self.stream.write(buf),
|
||||
Option::Some(cipher) => {
|
||||
let data = cipher.encrypt(buf);
|
||||
let data = cipher.update(buf);
|
||||
try!(self.stream.write_all(&data[..]));
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use openssl;
|
||||
use openssl::crypto::hash;
|
||||
use serde_json;
|
||||
use serde_json::builder::ObjectBuilder;
|
||||
use hyper;
|
||||
|
@ -101,11 +101,12 @@ impl Profile {
|
|||
}
|
||||
|
||||
pub fn join_server(&self, server_id: &str, shared_key: &[u8], public_key: &[u8]) -> Result<(), super::Error> {
|
||||
let mut sha1 = openssl::SHA1::new();
|
||||
sha1.update(server_id.as_bytes());
|
||||
sha1.update(shared_key);
|
||||
sha1.update(public_key);
|
||||
let mut hash = sha1.bytes();
|
||||
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();
|
||||
|
||||
// Mojang uses a hex method which allows for
|
||||
// negatives so we have to account for that.
|
||||
|
|
Loading…
Reference in New Issue