Skip to content

Commit 0e153ba

Browse files
committed
Add AES encryption to AUTH application.
1 parent 01f9212 commit 0e153ba

5 files changed

Lines changed: 26 additions & 2 deletions

File tree

db/src/master.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl Master {
300300
}
301301

302302
// Next, populate the actual records.
303-
for i in 1..records {
303+
for i in 0..records {
304304
let mut key = vec![0; K_LEN as usize];
305305
let mut val = vec![0; V_LEN as usize];
306306

ext/auth/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ crate-type = ["dylib"]
99
[dependencies]
1010
sandstorm = { path = "../../sandstorm" }
1111
rust-crypto = "0.2.36"
12+
openssl = "0.10.24"

ext/auth/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
extern crate crypto;
2121
#[macro_use]
2222
extern crate sandstorm;
23+
extern crate openssl;
24+
25+
use openssl::aes::{aes_ige, AesKey};
26+
use openssl::symm::Mode;
2327

2428
use crypto::bcrypt::bcrypt;
2529

@@ -55,6 +59,11 @@ pub fn init(db: Rc<DB>) -> Box<Generator<Yield = u64, Return = u64>> {
5559
let mut status = INVALIDARG;
5660
let mut username: Vec<u8> = Vec::with_capacity(30);
5761
let mut password: Vec<u8> = Vec::with_capacity(72);
62+
let key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
63+
let mut iv = *b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\
64+
\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
65+
let ekey = AesKey::new_decrypt(key).unwrap();
66+
let mut output = [0u8; 16];
5867

5968
{
6069
// First off, retrieve the arguments to the extension.
@@ -76,6 +85,8 @@ pub fn init(db: Rc<DB>) -> Box<Generator<Yield = u64, Return = u64>> {
7685
let (userid, pass) = remain_args.split_at(30);
7786
username.extend_from_slice(userid);
7887
password.extend_from_slice(pass);
88+
aes_ige(&password[0..16], &mut output, &ekey, &mut iv, Mode::Decrypt);
89+
password[0..16].copy_from_slice(&output[0..16]);
7990

8091
// Get the table id from the unwrapped arguments.
8192
for (idx, e) in s_table.iter().enumerate() {

splinter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ spin = "0.4.7" # Consider using parking lot?
7373
bytes = "0.4.7"
7474
env_logger = "0.3"
7575
libloading = "0.3"
76+
openssl = "0.10.24"
7677
rustlearn = "0.5.0"
7778
serde = "1.0.37"
7879
serde_derive = "1.0.37"

splinter/src/bin/client/auth.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
extern crate crypto;
1919
extern crate db;
20+
extern crate openssl;
2021
extern crate rand;
2122
extern crate sandstorm;
2223
extern crate spin;
2324
extern crate splinter;
2425
extern crate time;
2526
extern crate zipf;
2627

28+
use openssl::aes::{aes_ige, AesKey};
29+
use openssl::symm::Mode;
30+
2731
mod setup;
2832

2933
use std::cell::RefCell;
@@ -308,6 +312,12 @@ where
308312
return;
309313
}
310314

315+
let key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
316+
let mut iv = *b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\
317+
\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
318+
let ekey = AesKey::new_encrypt(key).unwrap();
319+
let mut output = [0u8; 16];
320+
311321
while self.outstanding < 32 && self.manager.borrow().get_queue_len() < 32 {
312322
// Get the current time stamp so that we can determine if it is time to issue the next RPC.
313323
let curr = cycles::rdtsc();
@@ -338,7 +348,8 @@ where
338348
// extension name (4 bytes), the table id (8 bytes), Just write
339349
// in the first 4 bytes of the key and first 4 bytes of value.
340350
p_get[12..16].copy_from_slice(&key[0..4]);
341-
p_get[42..46].copy_from_slice(&key[0..4]);
351+
aes_ige(&key[0..16], &mut output, &ekey, &mut iv, Mode::Encrypt);
352+
p_get[42..58].copy_from_slice(&output[0..16]);
342353
self.manager.borrow_mut().create_task(
343354
curr,
344355
&p_get,

0 commit comments

Comments
 (0)