-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working key handshake, client subcommands, just need to start encrypt…
…ing and sending content
- Loading branch information
Showing
22 changed files
with
667 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use crate::NetSettings; | ||
|
||
pub fn download(net_settings: NetSettings) | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::net::SocketAddr; | ||
use std::sync::{Arc, Mutex}; | ||
use std::thread; | ||
use std::time::Duration; | ||
use log::info; | ||
use rand::RngCore; | ||
use dnstplib::client_crypto_context::ClientCryptoContext; | ||
use dnstplib::DomainConfig; | ||
use dnstplib::message::DNSMessage; | ||
use dnstplib::net::{DNSSocket, NetworkMessage}; | ||
use dnstplib::processor::ResponseProcesor; | ||
use crate::NetSettings; | ||
|
||
pub fn send_test_requests(args: NetSettings) | ||
{ | ||
let address = SocketAddr::from(([127, 0, 0, 1], 0)); | ||
|
||
let mut socket = DNSSocket::new(vec!(address)); | ||
socket.bind(); | ||
socket.run_tx(); | ||
|
||
let tx_channel = socket.get_tx_message_channel().unwrap(); | ||
|
||
let crypto_context = Arc::new(Mutex::new(ClientCryptoContext::new())); | ||
let mut processor = ResponseProcesor::new(crypto_context.clone()); | ||
processor.run(); | ||
|
||
socket.run_rx(processor.get_message_channel().expect("couldn't get message processing channel")); | ||
|
||
let domain_config = DomainConfig { | ||
base_domain: args.base_domain, | ||
key_endpoint: args.key_endpoint | ||
}; | ||
|
||
let domain = domain_config.get_fq_key_endpoint(); | ||
|
||
let mut rng = rand::thread_rng(); | ||
loop { | ||
info!("sending..."); | ||
|
||
let message = DNSMessage::req_from_hostname(address, rng.next_u32() as u16, domain.clone()); | ||
|
||
let bytes = message.to_bytes(); | ||
|
||
tx_channel.send(Box::new(NetworkMessage { | ||
buffer: Box::new(bytes), | ||
peer: args.address.parse().unwrap() | ||
})); | ||
|
||
thread::sleep(Duration::from_secs(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use std::net::SocketAddr; | ||
use std::sync::{Arc, Mutex}; | ||
use std::thread; | ||
use std::time::Duration; | ||
use log::info; | ||
use rand::RngCore; | ||
use rand::rngs::OsRng; | ||
use dnstplib::client_crypto_context::ClientCryptoContext; | ||
use dnstplib::{DomainConfig, send_message}; | ||
use dnstplib::message::{Direction, DNSHeader, DNSMessage, DNSQuestion, Opcode, QClass, QType, ResponseCode}; | ||
use dnstplib::net::DNSSocket; | ||
use dnstplib::processor::ResponseProcesor; | ||
use crate::NetSettings; | ||
|
||
pub fn upload(net_settings: NetSettings, value: String) | ||
{ | ||
let address = SocketAddr::from(([127, 0, 0, 1], 0)); | ||
|
||
let mut socket = DNSSocket::new(vec!(address)); | ||
socket.bind(); | ||
socket.run_tx(); | ||
|
||
let tx_channel = socket.get_tx_message_channel().unwrap(); | ||
|
||
let crypto_context = Arc::new(Mutex::new(ClientCryptoContext::new())); | ||
let mut processor = ResponseProcesor::new(crypto_context.clone()); | ||
processor.run(); | ||
|
||
socket.run_rx(processor.get_message_channel().expect("couldn't get message processing channel")); | ||
|
||
let domain_config = DomainConfig { | ||
base_domain: net_settings.base_domain, | ||
key_endpoint: net_settings.key_endpoint | ||
}; | ||
|
||
info!("sending handshake..."); | ||
|
||
let message = DNSMessage { | ||
header: DNSHeader { | ||
id: OsRng.next_u32() as u16, | ||
direction: Direction::Request, | ||
opcode: Opcode::Query, | ||
authoritative: false, | ||
truncation: false, | ||
recursion_desired: false, | ||
recursion_available: false, | ||
valid_zeroes: true, | ||
response: ResponseCode::NoError, | ||
question_count: 2, | ||
answer_record_count: 0, | ||
authority_record_count: 0, | ||
additional_record_count: 0, | ||
}, | ||
questions: vec![ | ||
DNSQuestion { | ||
qname: domain_config.get_fq_key_endpoint(), | ||
qtype: QType::A, | ||
qclass: QClass::Internet, | ||
}, | ||
DNSQuestion { | ||
qname: crypto_context.lock().unwrap().get_public_key_domain(&domain_config.base_domain), | ||
qtype: QType::A, | ||
qclass: QClass::Internet, | ||
} | ||
], | ||
answer_records: vec![], | ||
authority_records: vec![], | ||
additional_records: vec![], | ||
peer: net_settings.address.parse().unwrap(), | ||
}; | ||
|
||
send_message(message, &tx_channel); | ||
|
||
while !crypto_context.lock().unwrap().is_complete() { | ||
info!("waiting for crypto completion..."); | ||
|
||
thread::sleep(Duration::from_millis(100)); | ||
} | ||
|
||
info!("crypto complete, sending data"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use aes_gcm_siv::Aes256GcmSiv; | ||
use p256::ecdh::EphemeralSecret; | ||
use crate::crypto::{get_random_asym_pair, trim_public_key}; | ||
use crate::string::append_base_domain_to_key; | ||
|
||
/// Represents the server from the perspective of a client | ||
pub struct ClientCryptoContext { | ||
pub shared_key: Option<Aes256GcmSiv>, | ||
pub client_private: EphemeralSecret, | ||
pub client_public: String, | ||
pub server_public: Option<String> | ||
} | ||
|
||
impl ClientCryptoContext { | ||
pub fn new() -> Self { | ||
let (client_private, client_public) = get_random_asym_pair(); | ||
|
||
Self { | ||
shared_key: None, | ||
client_private, | ||
client_public, | ||
server_public: None | ||
} | ||
} | ||
|
||
pub fn is_complete(&self) -> bool | ||
{ | ||
self.server_public.is_some() && self.shared_key.is_some() | ||
} | ||
|
||
pub fn get_public_key_domain(&self, base_domain: &String) -> String | ||
{ | ||
append_base_domain_to_key( | ||
trim_public_key(&self.client_public), | ||
base_domain | ||
) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.