Clean up messages, full first credential handling

This commit is contained in:
onyinyang 2023-02-06 13:58:24 -05:00
parent 9776e18ba2
commit a87b61849a
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 22 additions and 21 deletions

View File

@ -18,15 +18,15 @@ let open_lox_cred = await init().then(() => {
}); });
return cred; return cred;
}); });
console.log("Got request and state "+requested); console.log("Got Lox Credential and BridgeLine "+open_lox_cred);
function request_new_lox_credential(requested) { function request_new_lox_credential(requested) {
return new Promise((fulfill, reject) => { return new Promise((fulfill, reject) => {
let req = JSON.parse(requested); let req = JSON.parse(requested);
console.log("Request? "+req.request); console.log("Request? "+JSON.stringify(req.request));
loxServerPostRequest("/openreq", req.request).then((response) => { loxServerPostRequest("/openreq", req.request).then((response) => {
console.log("Got new Lox Credential: " + response); console.log("Got new Lox Credential: " + JSON.stringify(response));
fulfill(response); fulfill(JSON.stringify(response));
return; return;
}).catch(() => { }).catch(() => {
console.log("Error requesting new Lox credential from server"); console.log("Error requesting new Lox credential from server");

View File

@ -1,8 +1,7 @@
use lox::bridge_table::BridgeLine;
use lox::proto::open_invite; use lox::proto::open_invite;
use lox::{IssuerPubKey, OPENINV_LENGTH}; use lox::{IssuerPubKey, OPENINV_LENGTH};
use serde::{Deserialize, Serialize};
use serde_json; use serde_json;
use serde::{Deserialize,Serialize};
//use serde_wasm_bindgen; //use serde_wasm_bindgen;
use std::array::TryFromSliceError; use std::array::TryFromSliceError;
use std::panic; use std::panic;
@ -14,7 +13,7 @@ struct ReqState {
state: lox::proto::open_invite::State, state: lox::proto::open_invite::State,
} }
#[derive(Debug, Deserialize,Serialize)] #[derive(Debug, Deserialize, Serialize)]
struct PubKeys { struct PubKeys {
lox_pub: IssuerPubKey, lox_pub: IssuerPubKey,
migration_pub: IssuerPubKey, migration_pub: IssuerPubKey,
@ -23,7 +22,7 @@ struct PubKeys {
invitation_pub: IssuerPubKey, invitation_pub: IssuerPubKey,
} }
#[derive(Debug,Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
struct Credential { struct Credential {
lox_credential: String, lox_credential: String,
bridgeline: String, bridgeline: String,
@ -53,7 +52,7 @@ pub fn open_invite(invite: &[u8]) -> Result<String, JsValue> {
let req_state = ReqState { let req_state = ReqState {
request: request, request: request,
state: state, state: state,
}; };
unsafe { unsafe {
log(&format!( log(&format!(
"Formatted open invite request: {}", "Formatted open invite request: {}",
@ -63,39 +62,41 @@ pub fn open_invite(invite: &[u8]) -> Result<String, JsValue> {
Ok(serde_json::to_string(&req_state).unwrap()) Ok(serde_json::to_string(&req_state).unwrap())
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn handle_new_lox_credential(open_lox_result: String, open_lox_response: String, lox_pub: String) -> Result<String, JsValue> { pub fn handle_new_lox_credential(
unsafe { open_lox_result: String,
log(&format!("Using server response: {:?}", open_lox_result)); open_lox_response: String,
} lox_pub: String,
) -> Result<String, JsValue> {
let req_state: ReqState = serde_json::from_str(&open_lox_result).unwrap(); let req_state: ReqState = serde_json::from_str(&open_lox_result).unwrap();
let deserialized_state = req_state.state; let deserialized_state = req_state.state;
let deserialized_response = serde_json::from_str(&open_lox_response).unwrap(); let deserialized_response = serde_json::from_str(&open_lox_response).unwrap();
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap(); let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
unsafe { let lox_cred = match open_invite::handle_response(
log(&format!("pubkeys: {:?}", pubkeys.lox_pub)); deserialized_state,
} deserialized_response,
let lox_cred = match open_invite::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) { &pubkeys.lox_pub,
) {
Ok(lox_cred) => lox_cred, Ok(lox_cred) => lox_cred,
Err(e) => { Err(e) => {
log(&format!("Error: {:?}", e.to_string())); log(&format!("Error: {:?}", e.to_string()));
return Err(JsValue::from(e.to_string())); return Err(JsValue::from(e.to_string()));
} }
}; };
log(&format!("Did this actually work?: {:?}", lox_cred));
let lox_cred = Credential { let lox_cred = Credential {
lox_credential: serde_json::to_string(&lox_cred.0).unwrap(), lox_credential: serde_json::to_string(&lox_cred.0).unwrap(),
bridgeline: serde_json::to_string(&lox_cred.1).unwrap(), bridgeline: serde_json::to_string(&lox_cred.1).unwrap(),
}; };
unsafe { unsafe {
log(&format!("Got new Lox Credential: {}", lox_cred.lox_credential)); log(&format!(
"Got new Lox Credential: {}",
lox_cred.lox_credential
));
log(&format!("Got new bridgeline: {}", lox_cred.bridgeline)); log(&format!("Got new bridgeline: {}", lox_cred.bridgeline));
} }
Ok(serde_json::to_string(&lox_cred).unwrap()) Ok(serde_json::to_string(&lox_cred).unwrap())
} }
// This should also check the pubkey // This should also check the pubkey
fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> { fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> {
invite.try_into() invite.try_into()