lox_auth that serializes and outputs its pubkeys
This commit is contained in:
parent
3b3bbb899e
commit
2c6c9dbb7b
|
@ -1,37 +0,0 @@
|
|||
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("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!("bridge_auth_pubkey_{}", count))
|
||||
.expect("Failed to create pubkey file");
|
||||
outfile
|
||||
.write_all(&pubkey_bytes)
|
||||
.expect("Failed to write pubkey");
|
||||
}
|
||||
}
|
|
@ -4,34 +4,35 @@ use std::io::Write;
|
|||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let bridgedb_outfile_name = "bridgedb.json";
|
||||
let bridgedb_privkey_filename = "bridgedb.json";
|
||||
let bridgedb_pubkey_filename = "bridgedb_pubkey.json";
|
||||
|
||||
// If bridgedb has already been created, recreate it from file.
|
||||
// Otherwise, create new bridgedb.
|
||||
let bridgedb = if Path::new(bridgedb_outfile_name).exists() {
|
||||
let bridgedb = if Path::new(bridgedb_privkey_filename).exists() {
|
||||
// read in file
|
||||
let bridgedb_infile = File::open(bridgedb_outfile_name).unwrap();
|
||||
let bridgedb_infile = File::open(bridgedb_privkey_filename).unwrap();
|
||||
serde_json::from_reader(bridgedb_infile).unwrap()
|
||||
} else {
|
||||
// create new bridgedb (implicitly generates keys)
|
||||
let bridgedb = BridgeDb::new();
|
||||
|
||||
// output full serialized bridgedb
|
||||
let mut bridgedb_outfile =
|
||||
File::create(bridgedb_outfile_name).expect("Failed to create bridgedb.json");
|
||||
let mut bridgedb_outfile = File::create(bridgedb_privkey_filename)
|
||||
.expect("Failed to create bridgedb privkey file");
|
||||
let bridgedb_outfile_json = serde_json::to_string(&bridgedb).unwrap();
|
||||
write!(bridgedb_outfile, "{}", bridgedb_outfile_json)
|
||||
.expect("Failed to write to bridgedb.json");
|
||||
|
||||
// output bridgedb public key
|
||||
let mut bridgedb_pubkey_outfile =
|
||||
File::create("bridgedb_pubkey.json").expect("Failed to create bridgedb_pubkey.json");
|
||||
File::create(bridgedb_pubkey_filename).expect("Failed to create bridgedb pubkey file");
|
||||
write!(
|
||||
bridgedb_pubkey_outfile,
|
||||
"{}",
|
||||
serde_json::to_string(&bridgedb.pubkey).unwrap()
|
||||
)
|
||||
.expect("Failed to write to bridgedb_pubkey.json");
|
||||
.expect("Failed to write to bridgedb pubkey file");
|
||||
|
||||
// return bridgedb
|
||||
bridgedb
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
use lox::BridgeAuth;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
fn main() {
|
||||
let bridgedb_pubkey_filename = "bridgedb_pubkey.json";
|
||||
let lox_auth_privkeys_filename = "lox_auth.json";
|
||||
let lox_auth_pubkeys_filename = "lox_auth_pubkeys.json";
|
||||
|
||||
// import bridgedb pubkey
|
||||
// note: currently no checks for valid data
|
||||
let bridgedb_pubkey_infile = File::open(bridgedb_pubkey_filename).unwrap();
|
||||
let bridgedb_pubkey = serde_json::from_reader(bridgedb_pubkey_infile).unwrap();
|
||||
|
||||
// create new bridge authority (implicitly generates keys)
|
||||
let lox_auth = BridgeAuth::new(bridgedb_pubkey);
|
||||
|
||||
// TODO: serialize lox_auth private keys
|
||||
|
||||
// vector of public keys (to serialize)
|
||||
let lox_auth_pubkeys = vec![
|
||||
lox_auth.lox_pub,
|
||||
lox_auth.migration_pub,
|
||||
lox_auth.migrationkey_pub,
|
||||
lox_auth.reachability_pub,
|
||||
lox_auth.invitation_pub,
|
||||
];
|
||||
|
||||
// output lox_auth public keys
|
||||
let mut lox_auth_pubkeys_outfile =
|
||||
File::create(lox_auth_pubkeys_filename).expect("Failed to create lox_auth pubkeys file");
|
||||
write!(
|
||||
lox_auth_pubkeys_outfile,
|
||||
"{}",
|
||||
serde_json::to_string(&lox_auth_pubkeys).unwrap()
|
||||
)
|
||||
.expect("Failed to write to lox_auth pubkeys file");
|
||||
}
|
Loading…
Reference in New Issue