Skip to content

Commit

Permalink
Update aes and block-modes crates.
Browse files Browse the repository at this point in the history
  • Loading branch information
jq-rs committed Sep 19, 2021
1 parent 93f0f3e commit ce379b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mles-webproxy"
version = "0.8.6"
version = "0.8.7"
authors = ["jq-rs"]
edition = "2018"

Expand All @@ -14,7 +14,6 @@ mles-utils = "1.1.0"
bytes = "0.4"
x509-parser = "0.7"
blake2 = "0.9"
aes-ctr = "0.4"
aes = "0.5"
block-modes = "0.6"
aes = { version = "0.7", features = ["ctr"] }
block-modes = "0.8"
base64 = "0.12"
24 changes: 11 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ use tokio_io::codec::{Decoder as TokioDecoder, Encoder as TokioEncoder};
use std::collections::HashMap;
use std::str::FromStr;

use aes::block_cipher::generic_array::GenericArray;
use aes::Aes128;
use aes::cipher::generic_array::GenericArray;
use aes::cipher::{NewCipher,StreamCipher};
use aes::{Aes128, Aes128Ctr};
use blake2::{Blake2s, Digest};
use block_modes::block_padding::Pkcs7;
use block_modes::{BlockMode, Ecb};
type Aes128Ecb = Ecb<Aes128, Pkcs7>;

use base64::{decode as b64decode, encode as b64encode};

use aes_ctr::stream_cipher::{NewStreamCipher, SyncStreamCipher};
use aes_ctr::Aes128Ctr;

use mles_utils::*;
use std::time::Duration;
use tokio::timer::Interval;
Expand Down Expand Up @@ -457,7 +455,7 @@ fn run_websocket_proxy(
let duid;
let dchannel;
if let Ok(uid) = b64decode(uid) {
let cipher = Aes128Ecb::new_var(aesecbkey, Default::default()).unwrap();
let cipher = Aes128Ecb::new_from_slices(aesecbkey, Default::default()).unwrap();
if let Ok(uid) = cipher.decrypt_vec(&uid) {
duid = uid;
} else {
Expand All @@ -467,7 +465,7 @@ fn run_websocket_proxy(
return Ok(());
}
if let Ok(channel) = b64decode(channel) {
let cipher = Aes128Ecb::new_var(aesecbkey, Default::default()).unwrap();
let cipher = Aes128Ecb::new_from_slices(aesecbkey, Default::default()).unwrap();
if let Ok(channel) = cipher.decrypt_vec(&channel) {
dchannel = channel;
} else {
Expand Down Expand Up @@ -552,9 +550,9 @@ fn run_websocket_proxy(
let aeskey = GenericArray::from_slice(&aeschannel_ecb_locked.0);
let aesecbkey = &aeschannel_ecb_locked.1;

let cipher = Aes128Ecb::new_var(&aesecbkey, Default::default()).unwrap();
let cipher = Aes128Ecb::new_from_slices(&aesecbkey, Default::default()).unwrap();
let cuid = cipher.encrypt_vec(&uid.into_bytes());
let cipher = Aes128Ecb::new_var(&aesecbkey, Default::default()).unwrap();
let cipher = Aes128Ecb::new_from_slices(&aesecbkey, Default::default()).unwrap();
let cchannel = cipher.encrypt_vec(&channel.clone().into_bytes());

decoded_message = decoded_message.set_uid(b64encode(&cuid));
Expand Down Expand Up @@ -646,9 +644,9 @@ fn run_websocket_proxy(
aeschannel_ecb_locked.1 = hasher_ecb_final.finalize().as_slice().to_vec();
aeschannel_ecb_locked.1.truncate(AES_NONCELEN);

let cipher = Aes128Ecb::new_var(&aeschannel_ecb_locked.1, Default::default()).unwrap();
let cipher = Aes128Ecb::new_from_slices(&aeschannel_ecb_locked.1, Default::default()).unwrap();
let cuid = cipher.encrypt_vec(&uid_clone.into_bytes());
let cipher = Aes128Ecb::new_var(&aeschannel_ecb_locked.1, Default::default()).unwrap();
let cipher = Aes128Ecb::new_from_slices(&aeschannel_ecb_locked.1, Default::default()).unwrap();
let cchannel = cipher.encrypt_vec(&channel_clone.into_bytes());

//create hash for verification
Expand All @@ -667,9 +665,9 @@ fn run_websocket_proxy(
let aeskey = GenericArray::from_slice(&aeschannel_ecb_locked.0);
let aesecbkey = &aeschannel_ecb_locked.1;

let cipher = Aes128Ecb::new_var(&aesecbkey, Default::default()).unwrap();
let cipher = Aes128Ecb::new_from_slices(&aesecbkey, Default::default()).unwrap();
let cuid = cipher.encrypt_vec(&uid.clone().into_bytes());
let cipher = Aes128Ecb::new_var(&aesecbkey, Default::default()).unwrap();
let cipher = Aes128Ecb::new_from_slices(&aesecbkey, Default::default()).unwrap();
let cchannel = cipher.encrypt_vec(&channel.clone().into_bytes());

decoded_message = decoded_message.set_uid(b64encode(&cuid));
Expand Down

0 comments on commit ce379b4

Please sign in to comment.