Browse Source

Merge remote-tracking branch 'origin/master'

master
Andrew Onuchowski 1 year ago
parent
commit
2a229ff1c8
2 changed files with 9 additions and 19 deletions
  1. 7
    17
      src/bin/client.rs
  2. 2
    2
      src/bin/message.rs

+ 7
- 17
src/bin/client.rs View File

@@ -4,11 +4,14 @@ use crypto_box::{
};
use std::io::Write;
use std::net::TcpStream;
use crate::message::*;

mod message;

fn main() {
let port: u32 = 7878; // Port Server
//let stream = TcpStream::connect("172.30.16.1:8080");
//let stream = TcpStream::connect("27.0.0.1:8080");
// Server Port
let port: u32 = 7878;
match TcpStream::connect(format!("localhost:{}", port)) {
Ok(mut stream) => {
println!("Successfully connected to server");
@@ -49,6 +52,7 @@ fn main() {

// Encrypt the message using the box
let ciphertext = salsa_box.encrypt(&nonce, &plaintext[..]).expect("Fehler");
let message = Message::new(0,0,4, PayloadType::Msg);

println!("Sending {0} as {1:?}", buffer.trim(), plaintext);
stream.write(buffer.as_bytes()).unwrap();
@@ -82,17 +86,3 @@ fn main() {
}
println!("Terminated.");
}

fn generate_box(partner_public_key: PublicKey) -> (SalsaBox, PublicKey) {
// Generate a random secret key.
// NOTE: The secret key bytes can be accessed by calling `secret_key.as_bytes()`
let own_secret_key = SecretKey::generate(&mut OsRng);

// Get the public key for the secret key we just generated
let own_public_key = own_secret_key.public_key().clone();

// Create a `SalsaBox` by performing Diffie-Hellman key agreement between
// the two keys.
let salsa_box = SalsaBox::new(&partner_public_key, &own_secret_key);
(salsa_box, own_public_key)
}

+ 2
- 2
src/bin/message.rs View File

@@ -35,7 +35,7 @@ pub struct Message {
}

impl Message {
fn new(src_id: u32, dest_id: u32, size: u16, msg_type: PayloadType) -> Message {
pub fn new(src_id: u32, dest_id: u32, size: u16, msg_type: PayloadType) -> Message {
let mut msg = Message {
src_id: src_id,
dest_id: dest_id,
@@ -66,7 +66,7 @@ impl Message {
vec
}

fn recive(stream: TcpStream) -> Message {
fn receive(stream: TcpStream) -> Message {
let buffreader = BufReader::new(stream);
let mut byte_iterator = buffreader.bytes();
let byte1 = byte_iterator.next().unwrap().unwrap();

Loading…
Cancel
Save