mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-23 00:21:38 +03:00
Merge pull request #479 from kinode-dao/dr/keyfile-serde-json
keyfile: encode/decode as JSON for better cross-lang support, keep bincode as backup
This commit is contained in:
commit
aacaff6306
@ -53,7 +53,7 @@ pub fn encode_keyfile(
|
||||
let jwtciphertext: Vec<u8> = cipher.encrypt(&jwt_nonce, jwt).unwrap();
|
||||
let fileciphertext: Vec<u8> = cipher.encrypt(&file_nonce, file_key.as_ref()).unwrap();
|
||||
|
||||
bincode::serialize(&(
|
||||
serde_json::to_vec(&(
|
||||
username.clone(),
|
||||
routers.clone(),
|
||||
salt.to_vec(),
|
||||
@ -68,7 +68,14 @@ pub fn decode_keyfile(keyfile: &[u8], password: &str) -> Result<Keyfile, &'stati
|
||||
use generic_array::GenericArray;
|
||||
|
||||
let (username, routers, salt, key_enc, jwt_enc, file_enc) =
|
||||
bincode::deserialize::<(String, Vec<String>, Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>)>(keyfile)
|
||||
serde_json::from_slice::<(String, Vec<String>, Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>)>(
|
||||
keyfile,
|
||||
)
|
||||
.or_else(|_| {
|
||||
bincode::deserialize::<(String, Vec<String>, Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>)>(
|
||||
keyfile,
|
||||
)
|
||||
})
|
||||
.map_err(|_| "failed to deserialize keyfile")?;
|
||||
|
||||
// rederive disk key
|
||||
@ -138,8 +145,15 @@ pub fn generate_jwt(
|
||||
|
||||
#[cfg(not(feature = "simulation-mode"))]
|
||||
pub fn get_username_and_routers(keyfile: &[u8]) -> Result<(String, Vec<String>), &'static str> {
|
||||
let (username, routers, _salt, _key_enc, _jwt_enc) =
|
||||
bincode::deserialize::<(String, Vec<String>, Vec<u8>, Vec<u8>, Vec<u8>)>(keyfile)
|
||||
let (username, routers, _salt, _key_enc, _jwt_enc, _file_enc) =
|
||||
serde_json::from_slice::<(String, Vec<String>, Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>)>(
|
||||
keyfile,
|
||||
)
|
||||
.or_else(|_| {
|
||||
bincode::deserialize::<(String, Vec<String>, Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>)>(
|
||||
keyfile,
|
||||
)
|
||||
})
|
||||
.map_err(|_| "failed to deserialize keyfile")?;
|
||||
|
||||
Ok((username, routers))
|
||||
|
@ -124,15 +124,24 @@ pub async fn register(
|
||||
.or(warp::path("our").and(warp::get()).and(keyfile.clone()).map(
|
||||
move |keyfile: Option<Vec<u8>>| {
|
||||
if let Some(keyfile) = keyfile {
|
||||
if let Ok((username, _, _, _, _, _)) = bincode::deserialize::<(
|
||||
if let Ok((username, _, _, _, _, _)) = serde_json::from_slice::<(
|
||||
String,
|
||||
Vec<String>,
|
||||
Vec<u8>,
|
||||
Vec<u8>,
|
||||
Vec<u8>,
|
||||
Vec<u8>,
|
||||
)>(keyfile.as_ref())
|
||||
{
|
||||
)>(&keyfile)
|
||||
.or_else(|_| {
|
||||
bincode::deserialize::<(
|
||||
String,
|
||||
Vec<String>,
|
||||
Vec<u8>,
|
||||
Vec<u8>,
|
||||
Vec<u8>,
|
||||
Vec<u8>,
|
||||
)>(&keyfile)
|
||||
}) {
|
||||
return warp::reply::html(username);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user