From aa7fae385c737ed42539683c4b2fdfb4196379a6 Mon Sep 17 00:00:00 2001 From: Vecna Date: Thu, 27 Oct 2022 22:44:54 -0400 Subject: [PATCH] Beginnings of bridge_auth --- bridge_auth/Cargo.toml | 10 ++++++++++ bridge_auth/src/main.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 bridge_auth/Cargo.toml create mode 100644 bridge_auth/src/main.rs diff --git a/bridge_auth/Cargo.toml b/bridge_auth/Cargo.toml new file mode 100644 index 0000000..d825e2f --- /dev/null +++ b/bridge_auth/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "bridge_auth" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +lox = { git = "https://git-crysp.uwaterloo.ca/iang/lox.git" } +ed25519-dalek = "1" diff --git a/bridge_auth/src/main.rs b/bridge_auth/src/main.rs new file mode 100644 index 0000000..cbdc640 --- /dev/null +++ b/bridge_auth/src/main.rs @@ -0,0 +1,37 @@ +use ed25519_dalek::PublicKey; +use lox::BridgeAuth; +use std::fs::File; +use std::io::BufReader; +use std::io::Read; +use std::io::Write; + +fn main() { + // import bridgedb pubkey + // note: currently no checks for valid data + let infile = std::fs::File::open("../pubkeys/bridgedb_pubkey").unwrap(); + let mut reader = BufReader::new(infile); + let mut buffer = Vec::new(); + reader + .read_to_end(&mut buffer) + .expect("Failed to read pubkey from file"); + let bridgedb_pubkey = PublicKey::from_bytes(&buffer).unwrap(); + + // create new bridge authority (implicitly generates keys) + let bridge_auth = BridgeAuth::new(bridgedb_pubkey); + + // output public keys to new files + // I think this approach is too hacky because it requires multiple + // files, one per key... + let mut count = 0; + // TODO: Figure out how to deal with X being private + for pubkey in bridge_auth.lox_pub.X { + count += 1; + let pubkey_bytes = pubkey.compress().to_bytes(); + // Is this the proper way to concatenate an integer and a string? + let mut outfile = File::create(format!("{}{}", "../pubkeys/bridge_auth_pubkey_", count)) + .expect("Failed to create pubkey file"); + outfile + .write_all(&pubkey_bytes) + .expect("Failed to write pubkey"); + } +}