Change pubkey passing, handling credentials still broken

This commit is contained in:
onyinyang 2023-02-01 00:42:49 -05:00
parent dfa2ae4c6f
commit 8cc9d3d5d3
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 23 additions and 8 deletions

View File

@ -2,7 +2,6 @@ import init, { open_invite, handle_new_lox_credential, set_panic_hook } from "./
let pubkeys = await request_pubkeys();
console.log(pubkeys);
let requested = await init().then(() => {
set_panic_hook();
let requested = request_open_invite().then((token) => {
@ -22,9 +21,9 @@ let open_lox_cred = await init().then(() => {
console.log("Got request and state "+requested);
function request_new_lox_credential(requested) {
return new Promise((fulfill, reject) => {
let req = JSON.parse(requested);
console.log("Request? "+req.request);
return new Promise((fulfill, reject) => {
loxServerPostRequest("/openreq", req.request).then((response) => {
console.log("Got new Lox Credential: " + response);
fulfill(response);
@ -52,8 +51,8 @@ function request_open_invite() {
function request_pubkeys() {
return new Promise((fulfill, reject) => {
loxServerGetRequest("/pubkeys").then((response) => {
console.log("Got pubkeys: " + response);
fulfill(JSON.parse(response));
console.log("Got pubkeys: " + JSON.stringify(response));
fulfill(JSON.stringify(response));
return;
}).catch(() => {
console.log("Error requesting open invite from Lox server");
@ -104,7 +103,6 @@ function loxServerPostRequest(data, payload) {
return;
}
const response = JSON.parse(xhr.responseText);
console.log("Received: "+response);
fulfill(response);
return;
};

View File

@ -14,6 +14,15 @@ struct ReqState {
state: lox::proto::open_invite::State,
}
#[derive(Debug, Deserialize,Serialize)]
struct PubKeys {
lox_pub: IssuerPubKey,
migration_pub: IssuerPubKey,
migrationkey_pub: IssuerPubKey,
reachability_pub: IssuerPubKey,
invitation_pub: IssuerPubKey,
}
#[derive(Debug,Deserialize, Serialize)]
struct Credential {
lox_credential: String,
@ -63,11 +72,18 @@ pub fn handle_new_lox_credential(open_lox_result: String, open_lox_response: Str
let req_state: ReqState = serde_json::from_str(&open_lox_result).unwrap();
let deserialized_state = req_state.state;
let deserialized_response = serde_json::from_str(&open_lox_response).unwrap();
let deserialized_pubkey = serde_json::from_str(&lox_pub).unwrap();
let lox_cred = match open_invite::handle_response(deserialized_state, deserialized_response, &deserialized_pubkey) {
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
unsafe {
log(&format!("pubkeys: {:?}", pubkeys.lox_pub));
}
let lox_cred = match open_invite::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
Err(e) => {
log(&format!("Error: {:?}", e.to_string()));
return Err(JsValue::from(e.to_string()));
}
};
log(&format!("Did this actually work?: {:?}", lox_cred));
let lox_cred = Credential {
lox_credential: serde_json::to_string(&lox_cred.0).unwrap(),
bridgeline: serde_json::to_string(&lox_cred.1).unwrap(),
@ -79,6 +95,7 @@ pub fn handle_new_lox_credential(open_lox_result: String, open_lox_response: Str
Ok(serde_json::to_string(&lox_cred).unwrap())
}
// This should also check the pubkey
fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> {
invite.try_into()