enregistrement avec serveur

This commit is contained in:
TIBERGHIEN corentin
2025-12-16 22:43:49 +01:00
parent 721d52a028
commit 002a667837
6 changed files with 968 additions and 10 deletions

887
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -9,3 +9,12 @@ tokio = { version = "1", features = ["full"] }
rand = "0.10.0-rc.5"
hex = "0.4.3"
sha2 = "0.10.9"
ecdsa = "0.16.9"
getrandom = "0.3.4"
p256 = "0.13.2"
rand_core = "0.6"
os-rng = "0.0.0"
rand_os = "0.2.2"
http = "1.4.0"
reqwest = "0.12.24"
bytes = "1.11.0"

View File

@@ -1,4 +1,5 @@
mod data;
mod protocol;
/// Messages sent to the Network thread by the GUI.
pub enum NetworkCommand {

View File

@@ -0,0 +1,49 @@
use http::{Request, Response};
use p256::ecdsa::{
Signature, SigningKey, VerifyingKey,
signature::{Signer, Verifier},
};
use rand_core::OsRng;
struct KeyRegistration {
priv_key: SigningKey,
pub_key: VerifyingKey,
username: String,
}
impl KeyRegistration {
fn new(username: String) -> KeyRegistration {
let priv_key = SigningKey::random(&mut OsRng);
let pub_key = VerifyingKey::from(&priv_key);
KeyRegistration {
priv_key: priv_key,
pub_key: pub_key,
username: username,
}
}
}
async fn register_with_the_server(key: KeyRegistration) -> Result<bytes::Bytes, reqwest::Error> {
let client = reqwest::Client::new();
let pubkey_ser = key.pub_key.to_encoded_point(false);
let pubkey_str = hex::encode(pubkey_ser);
let uri = format!("https://jch.irif.fr:8443/peers/{}/key", key.username);
let resp = client.put(uri).send().await?.error_for_status()?;
resp.bytes().await
}
/*#[cfg(test)]
mod tests {
use super::*;
#[test]
fn key_genereation() {
let keys = KeyRegistration::new();
let pubkey = keys.pub_key;
let pubkey_ser = pubkey.to_encoded_point(false);
println!("string pubkey: {}", hex::encode(pubkey_ser));
println!("string privkey: {}", hex::encode(keys.priv_key.to_bytes()))
}
}*/

BIN
project.pdf Normal file

Binary file not shown.

32
todo.md Normal file
View File

@@ -0,0 +1,32 @@
# Todo :
## peer discovery
- get rsquest to the uri /peers/
## registration with the server
- generation of the cryptographic key
- put request to the uri (check if the peer is already connected) OK
- get request to the uri /peers/key to get the public key of a peer
- get request to the uri /peers/key/addresses
## handshake
- handshake structure
- 5min timeout after handshake
- matain connection every 4 min
## data transfer
- request structure
- root/root reply structure
- datum/nodatum and datum structures
- nattraversal 1 and 2 structures
- setting in gui to act as a relay
- chunk, directory, big, bigdirectory structures
fonctionnalités :
s'enregistrer avec le serveur OK
rechercher un pair
generer une clé publique
rechercher les fichiers d'un pair
telechargement des fichiers
choisir un dossier à partager
se deconnecter du réseau