diff --git a/Cargo.lock b/Cargo.lock index a1cf0e5..a4ced72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,18 +72,24 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" -[[package]] -name = "base64" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d1ccbaf7d9ec9537465a97bf19edc1a4e158ecb49fc16178202238c569cc42" - [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bumpalo" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5356f1d23ee24a1f785a56d1d1a5f0fd5b0f6a0c0fb2412ce11da71649ab78f6" + +[[package]] +name = "cc" +version = "1.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" + [[package]] name = "cfg-if" version = "0.1.10" @@ -103,9 +109,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.0" +version = "2.33.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" dependencies = [ "ansi_term", "atty", @@ -312,11 +318,12 @@ dependencies = [ [[package]] name = "ilmp" version = "0.1.0" +source = "git+https://github.com/izzabelle/ilmp#cb0257e9665b6fc9f0004c928ec043662ea275e0" dependencies = [ "chrono", "futures", "futures-util", - "orion", + "ring", "serde", "serde_json", "uuid", @@ -337,6 +344,15 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" +[[package]] +name = "js-sys" +version = "0.3.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa5a448de267e7358beaf4a5d849518fe9a0c13fce7afd44b06e68550e5562a7" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -364,9 +380,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005" +checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" [[package]] name = "log" @@ -450,7 +466,7 @@ dependencies = [ "futures-util", "ilmp", "lazy_static", - "orion", + "ring", "serde", "serde_json", "structopt", @@ -500,36 +516,24 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" - -[[package]] -name = "orion" -version = "0.15.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2dd0d645e94ec75aacc27460cb68438263342f4e4e1aeaf7af67847687e7a8" -dependencies = [ - "base64", - "getrandom", - "subtle", - "zeroize", -] +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" [[package]] name = "pin-project" -version = "0.4.15" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c50dab4a05419117fe00216df4731e387ae616cd2a5f5dda1d8b02d863ac63d" +checksum = "81d480cb4e89522ccda96d0eed9af94180b7a5f93fb28f66e1fd7d68431663d1" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.15" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c27e5ac1d4c76777afd4d47b8fe9c602b44bcf6f999d34e300bba5560c9837b" +checksum = "a82996f11efccb19b685b14b5df818de31c1edcee3daa256ab5775dd98e72feb" dependencies = [ "proc-macro2", "quote", @@ -603,9 +607,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7" +checksum = "42934bc9c8ab0d3b273a16d8551c8f0fcff46be73276ca083ec2414c15c4ba5e" dependencies = [ "proc-macro2", ] @@ -651,6 +655,21 @@ dependencies = [ "rand_core", ] +[[package]] +name = "ring" +version = "0.16.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703516ae74571f24b465b4a1431e81e2ad51336cb0ded733a55a1aa3eccac196" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi 0.3.8", +] + [[package]] name = "ryu" version = "1.0.4" @@ -700,6 +719,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "strsim" version = "0.8.0" @@ -730,17 +755,11 @@ dependencies = [ "syn", ] -[[package]] -name = "subtle" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c65d530b10ccaeac294f349038a597e435b18fb456aadd0840a623f83b9e941" - [[package]] name = "syn" -version = "1.0.19" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e5aa70697bb26ee62214ae3288465ecec0000f05182f039b477001f08f5ae7" +checksum = "4696caa4048ac7ce2bcd2e484b3cef88c1004e41b8e945a277e2c25dc0b72060" dependencies = [ "proc-macro2", "quote", @@ -804,6 +823,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "uuid" version = "0.8.1" @@ -831,6 +856,70 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasm-bindgen" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c7d40d09cdbf0f4895ae58cf57d92e1e57a9dd8ed2e8390514b54a47cc5551" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3972e137ebf830900db522d6c8fd74d1900dcfc733462e9a12e942b00b4ac94" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cd85aa2c579e8892442954685f0d801f9129de24fa2136b2c6a539c76b65776" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb197bd3a47553334907ffd2f16507b4f4f01bbec3ac921a7719e0decdfe72a" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a91c2916119c17a8e316507afaaa2dd94b47646048014bbdf6bef098c1bb58ad" + +[[package]] +name = "web-sys" +version = "0.3.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bc359e5dd3b46cb9687a051d50a2fdd228e4ba7cf6fcf861a5365c3d671a642" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.2.8" @@ -874,9 +963,3 @@ dependencies = [ "winapi 0.2.8", "winapi-build", ] - -[[package]] -name = "zeroize" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8" diff --git a/Cargo.toml b/Cargo.toml index a787cbb..e29c824 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,5 @@ structopt = "0.3.14" chrono = "0.4.11" futures = "0.3.5" toml = "0.5.6" -orion = "0.15.1" -ilmp = {path = "./ilmp"} +ilmp = { git = "https://github.com/izzabelle/ilmp" } +ring = "0.16.13" diff --git a/ilmp/.gitignore b/ilmp/.gitignore deleted file mode 100644 index 96ef6c0..0000000 --- a/ilmp/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -Cargo.lock diff --git a/ilmp/Cargo.toml b/ilmp/Cargo.toml deleted file mode 100644 index 8d05511..0000000 --- a/ilmp/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "ilmp" -version = "0.1.0" -authors = ["Isabelle L. "] -edition = "2018" - -[dependencies] -orion = "0.15.1" -serde = { version = "1.0.110", features = ["derive"]} -serde_json = "1.0.53" -futures = "0.3.5" -futures-util = "0.3.5" -uuid = { version = "0.8.1", features = ["v4"] } -chrono = "0.4.11" diff --git a/ilmp/LICENSE b/ilmp/LICENSE deleted file mode 100644 index 8c86aec..0000000 --- a/ilmp/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright 2020 Isabelle L. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CO \ No newline at end of file diff --git a/ilmp/README.md b/ilmp/README.md deleted file mode 100644 index 61018b8..0000000 --- a/ilmp/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Isabelle's Lazy Message Protocol -idfk lol \ No newline at end of file diff --git a/ilmp/src/lib.rs b/ilmp/src/lib.rs deleted file mode 100644 index ccff7d3..0000000 --- a/ilmp/src/lib.rs +++ /dev/null @@ -1,133 +0,0 @@ -//! # Isabelle's Lazy Message Protocol -#![allow(dead_code)] - -use futures_util::io::{AsyncReadExt, AsyncWriteExt}; -use orion::aead; -use std::convert::TryInto; -use std::marker::Unpin; - -mod message; -pub use message::Message; - -/// lazy error -pub type Error = Box; -/// lazy result -pub type Result = std::result::Result; - -struct NetworkPacket(Vec); - -/// A type of data that can be sent -pub trait Sendable: Sized { - fn to_packet(self) -> Result; - fn from_packet(packet: Packet) -> Result; -} - -/// Data to be sent -pub struct Packet { - kind: PacketKind, - contents: Vec, -} - -impl Packet { - /// Create a new `Packet` - pub fn new(kind: PacketKind, contents: Vec) -> Packet { - Packet { kind, contents } - } - - fn to_network_packet(self) -> NetworkPacket { - let mut contents: Vec = Vec::new(); - - // write packet kind byte - contents.push(self.kind as u8); - // write the packet length - let contents_length = self.contents.len() as u32; - contents.extend_from_slice(&contents_length.to_le_bytes()); - // write contents - contents.extend_from_slice(&self.contents); - - NetworkPacket(contents) - } -} - -/// reads a `Packet` from a stream -/// -/// if `Ok(None)` is returned the stream has been disconnected. -pub async fn read(stream: &mut S) -> Result> -where - S: AsyncReadExt + Unpin, -{ - let mut info_buf = [0u8; 5]; - let check = stream.read(&mut info_buf).await?; - if check == 0 { - return Ok(None); - } - - let packet_kind = PacketKind::from_u8(info_buf[0]).unwrap(); - let length = u32::from_le_bytes(info_buf[1..5].try_into().unwrap()) as usize; - - let mut contents: Vec = vec![0; length]; - stream.read(&mut contents).await?; - - let packet = Packet::new(packet_kind, contents); - - Ok(Some(packet)) -} - -/// reads a `Packet` from a stream and decrypts -/// -/// if `Ok(None)` is returned the stream has been disconnected. -pub async fn read_encrypted(stream: &mut S, key: &aead::SecretKey) -> Result> -where - S: AsyncReadExt + Unpin, -{ - let packet = read(stream).await?; - match packet { - None => Ok(packet), - Some(mut packet) => { - packet.contents = aead::open(&key, &packet.contents)?; - Ok(Some(packet)) - } - } -} - -/// Writes a `Sendable` packet to a stream -pub async fn write(stream: &mut S, packet: P) -> Result<()> -where - S: AsyncWriteExt + Unpin, - P: Sendable, -{ - let network_packet = packet.to_packet()?.to_network_packet(); - stream.write(&network_packet.0).await?; - Ok(()) -} - -/// Writes an encrypted `Sendable` packet to a stream -pub async fn write_encrypted(stream: &mut S, packet: P, key: &aead::SecretKey) -> Result<()> -where - S: AsyncWriteExt + Unpin, - P: Sendable, -{ - let mut packet = packet.to_packet()?; - packet.contents = aead::seal(&key, &packet.contents)?; - let network_packet = packet.to_network_packet(); - stream.write(&network_packet.0).await?; - Ok(()) -} - -/// Kinds of packets that can be sent -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(u8)] -pub enum PacketKind { - Message = 0, - PublicKey = 1, -} - -impl PacketKind { - /// returns `Option given valid matching variant - pub fn from_u8(kind: u8) -> Option { - match kind { - 0 => Some(PacketKind::Message), - _ => None, - } - } -} diff --git a/ilmp/src/message.rs b/ilmp/src/message.rs deleted file mode 100644 index 10778c1..0000000 --- a/ilmp/src/message.rs +++ /dev/null @@ -1,42 +0,0 @@ -use crate::{Packet, PacketKind, Result}; -use chrono::prelude::*; -use serde::{Deserialize, Serialize}; -use uuid::Uuid; - -/// a standard message from a user -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Message { - pub timestamp: i64, - pub message_id: u128, - pub username: String, - pub contents: String, -} - -impl Message { - /// create a new message - pub fn new(username: String, contents: String) -> Message { - let timestamp = Utc::now().timestamp(); - let message_id = Uuid::new_v4().as_u128(); - - Message { - username, - message_id, - timestamp, - contents, - } - } -} - -impl crate::Sendable for Message { - fn to_packet(self) -> Result { - let contents: Vec = serde_json::to_string(&self)?.into_bytes(); - let kind = PacketKind::Message; - - Ok(Packet { kind, contents }) - } - fn from_packet(packet: Packet) -> Result { - let contents = &String::from_utf8(packet.contents)?; - let message: Message = serde_json::from_str(contents)?; - Ok(message) - } -}