diff --git a/kinode/src/keygen.rs b/kinode/src/keygen.rs index 1b05f6f6..bd1885e0 100644 --- a/kinode/src/keygen.rs +++ b/kinode/src/keygen.rs @@ -53,7 +53,7 @@ pub fn encode_keyfile( let jwtciphertext: Vec = cipher.encrypt(&jwt_nonce, jwt).unwrap(); let fileciphertext: Vec = cipher.encrypt(&file_nonce, file_key.as_ref()).unwrap(); - bincode::serialize(&( + serde_json::to_vec(&( username.clone(), routers.clone(), salt.to_vec(), @@ -68,8 +68,15 @@ pub fn decode_keyfile(keyfile: &[u8], password: &str) -> Result, Vec, Vec, Vec, Vec)>(keyfile) - .map_err(|_| "failed to deserialize keyfile")?; + serde_json::from_slice::<(String, Vec, Vec, Vec, Vec, Vec)>( + keyfile, + ) + .or_else(|_| { + bincode::deserialize::<(String, Vec, Vec, Vec, Vec, Vec)>( + keyfile, + ) + }) + .map_err(|_| "failed to deserialize keyfile")?; // rederive disk key let mut disk_key: DiskKey = [0u8; CREDENTIAL_LEN]; @@ -138,9 +145,16 @@ pub fn generate_jwt( #[cfg(not(feature = "simulation-mode"))] pub fn get_username_and_routers(keyfile: &[u8]) -> Result<(String, Vec), &'static str> { - let (username, routers, _salt, _key_enc, _jwt_enc) = - bincode::deserialize::<(String, Vec, Vec, Vec, Vec)>(keyfile) - .map_err(|_| "failed to deserialize keyfile")?; + let (username, routers, _salt, _key_enc, _jwt_enc, _file_enc) = + serde_json::from_slice::<(String, Vec, Vec, Vec, Vec, Vec)>( + keyfile, + ) + .or_else(|_| { + bincode::deserialize::<(String, Vec, Vec, Vec, Vec, Vec)>( + keyfile, + ) + }) + .map_err(|_| "failed to deserialize keyfile")?; Ok((username, routers)) } diff --git a/kinode/src/register.rs b/kinode/src/register.rs index 2c1a5e69..1ff37419 100644 --- a/kinode/src/register.rs +++ b/kinode/src/register.rs @@ -124,15 +124,24 @@ pub async fn register( .or(warp::path("our").and(warp::get()).and(keyfile.clone()).map( move |keyfile: Option>| { if let Some(keyfile) = keyfile { - if let Ok((username, _, _, _, _, _)) = bincode::deserialize::<( + if let Ok((username, _, _, _, _, _)) = serde_json::from_slice::<( String, Vec, Vec, Vec, Vec, Vec, - )>(keyfile.as_ref()) - { + )>(&keyfile) + .or_else(|_| { + bincode::deserialize::<( + String, + Vec, + Vec, + Vec, + Vec, + Vec, + )>(&keyfile) + }) { return warp::reply::html(username); } }