Recreate lox_auth from file
This commit is contained in:
parent
45811d8489
commit
a117e79e18
|
@ -1,10 +1,11 @@
|
||||||
use lox::BridgeAuth;
|
use lox::BridgeAuth;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let bridgedb_pubkey_filename = "bridgedb_pubkey.json";
|
let bridgedb_pubkey_filename = "bridgedb_pubkey.json";
|
||||||
let lox_auth_privkeys_filename = "lox_auth.json";
|
let lox_auth_filename = "lox_auth.json";
|
||||||
let lox_auth_pubkeys_filename = "lox_auth_pubkeys.json";
|
let lox_auth_pubkeys_filename = "lox_auth_pubkeys.json";
|
||||||
|
|
||||||
// import bridgedb pubkey
|
// import bridgedb pubkey
|
||||||
|
@ -12,23 +13,40 @@ fn main() {
|
||||||
let bridgedb_pubkey_infile = File::open(bridgedb_pubkey_filename).unwrap();
|
let bridgedb_pubkey_infile = File::open(bridgedb_pubkey_filename).unwrap();
|
||||||
let bridgedb_pubkey = serde_json::from_reader(bridgedb_pubkey_infile).unwrap();
|
let bridgedb_pubkey = serde_json::from_reader(bridgedb_pubkey_infile).unwrap();
|
||||||
|
|
||||||
// create new bridge authority (implicitly generates keys)
|
// If lox_auth has already been created, recreate it from file.
|
||||||
let lox_auth = BridgeAuth::new(bridgedb_pubkey);
|
// Otherwise, create new lox authority.
|
||||||
|
let lox_auth = if Path::new(lox_auth_filename).exists() {
|
||||||
|
// read in file
|
||||||
|
let lox_auth_infile = File::open(lox_auth_filename).unwrap();
|
||||||
|
serde_json::from_reader(lox_auth_infile).unwrap()
|
||||||
|
} else {
|
||||||
|
// create new lox_auth (implicitly generates keys)
|
||||||
|
BridgeAuth::new(bridgedb_pubkey)
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: serialize lox_auth private keys
|
// output full serialized lox_auth if it doesn't exist
|
||||||
|
if !Path::new(lox_auth_filename).exists() {
|
||||||
|
let mut lox_auth_outfile =
|
||||||
|
File::create(lox_auth_filename).expect("Failed to create lox_auth file");
|
||||||
|
let lox_auth_outfile_json = serde_json::to_string(&lox_auth).unwrap();
|
||||||
|
write!(lox_auth_outfile, "{}", lox_auth_outfile_json)
|
||||||
|
.expect("Failed to write to lox_auth file");
|
||||||
|
}
|
||||||
|
|
||||||
|
// output lox_auth pubkeys if the file doesn't exist
|
||||||
|
if !Path::new(lox_auth_pubkeys_filename).exists() {
|
||||||
// vector of public keys (to serialize)
|
// vector of public keys (to serialize)
|
||||||
let lox_auth_pubkeys = vec![
|
let lox_auth_pubkeys = vec![
|
||||||
lox_auth.lox_pub,
|
&lox_auth.lox_pub,
|
||||||
lox_auth.migration_pub,
|
&lox_auth.migration_pub,
|
||||||
lox_auth.migrationkey_pub,
|
&lox_auth.migrationkey_pub,
|
||||||
lox_auth.reachability_pub,
|
&lox_auth.reachability_pub,
|
||||||
lox_auth.invitation_pub,
|
&lox_auth.invitation_pub,
|
||||||
];
|
];
|
||||||
|
|
||||||
// output lox_auth public keys
|
// output lox_auth public keys
|
||||||
let mut lox_auth_pubkeys_outfile =
|
let mut lox_auth_pubkeys_outfile = File::create(lox_auth_pubkeys_filename)
|
||||||
File::create(lox_auth_pubkeys_filename).expect("Failed to create lox_auth pubkeys file");
|
.expect("Failed to create lox_auth pubkeys file");
|
||||||
write!(
|
write!(
|
||||||
lox_auth_pubkeys_outfile,
|
lox_auth_pubkeys_outfile,
|
||||||
"{}",
|
"{}",
|
||||||
|
@ -36,3 +54,4 @@ fn main() {
|
||||||
)
|
)
|
||||||
.expect("Failed to write to lox_auth pubkeys file");
|
.expect("Failed to write to lox_auth pubkeys file");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue