patch contact nmpk lookup for decipher

This commit is contained in:
creating2morrow 2024-04-11 20:59:15 -04:00
parent 696d1ad300
commit 6493cf575b
9 changed files with 64 additions and 7 deletions

View file

@ -39,7 +39,7 @@ curl -iv http://bob.b32.i2p/xmr/version -H 'proof: eyJhbGciOiJIUzUxMiJ9...'
## add contact
```bash
curl -iv -X POST http://localhost:9044/contact -d '{"cid": "KEEP EMPTY", "npmk": "string", "i2p_address": "", "xmr_address": ""}' -H 'Content-Type: application/json'
curl -iv -X POST http://localhost:9044/contact -d '{"cid": "KEEP EMPTY", "nmpk": "string", "i2p_address": "", "xmr_address": "", "is_vendor": false}' -H 'Content-Type: application/json'
```
## view contacts
@ -48,6 +48,12 @@ curl -iv -X POST http://localhost:9044/contact -d '{"cid": "KEEP EMPTY", "npmk":
curl -iv http://localhost:9044/contacts
```
## remove contact
```bash
curl -iv -X DELETE http://localhost:9044/contact/remove/<CID>
```
## send message
```bash
@ -66,6 +72,12 @@ curl -iv http://alice.b32.i2p/message/rx -d '{"uid":"", "mid": "", "body": "stri
curl -iv http://localhost:9045/messages
```
## remove message
```bash
curl -iv -X DELETE http://localhost:9045/message/remove/<MID>
```
## decipher message
```bash

View file

@ -1,6 +1,7 @@
#![allow(non_snake_case)]
use rocket::{
delete,
get,
http::Status,
post,
@ -37,6 +38,17 @@ pub async fn get_contacts(_token: auth::BearerToken) -> Custom<Json<Vec<Contact>
Custom(Status::Ok, Json(contacts))
}
/// Delete a contact by CID
#[delete("/remove/<contact>")]
pub async fn remove_contact(
contact: String,
_token: auth::BearerToken,
) -> Custom<Json<Vec<Contact>>> {
contact::delete(&contact);
let contacts = contact::find_all();
Custom(Status::Ok, Json(contacts))
}
/// prove payment
#[get("/<contact>", data = "<proof_req>")]
pub async fn prove_payment(

View file

@ -16,6 +16,9 @@ async fn rocket() -> _ {
log::info!("neveko-contact is online");
rocket::custom(&config)
.mount("/prove", routes![controller::prove_payment])
.mount("/contact", routes![controller::add_contact])
.mount(
"/contact",
routes![controller::add_contact, controller::remove_contact],
)
.mount("/contacts", routes![controller::get_contacts])
}

View file

@ -80,6 +80,28 @@ pub fn find(cid: &String) -> Contact {
Contact::from_db(String::from(cid), r)
}
/// Contact lookup
pub fn find_by_i2p_address(i2p_address: &String) -> Contact {
let contacts = find_all();
for c in contacts {
if c.i2p_address == String::from(i2p_address) {
return c;
}
}
Default::default()
}
/// Contact deletion
pub fn delete(cid: &String) {
let s = db::Interface::open();
let r = db::Interface::read(&s.env, &s.handle, &String::from(cid));
if r == utils::empty_string() {
error!("contact not found");
return;
}
db::Interface::delete(&s.env, &s.handle, &cid);
}
/// All contact lookup
pub fn find_all() -> Vec<Contact> {
info!("looking up all contacts");

View file

@ -317,7 +317,7 @@ async fn send_message(out: &Message, jwp: &str, m_type: MessageType) -> Result<(
/// Returns deciphered message
pub async fn decipher_body(mid: String) -> reqres::DecipheredMessageBody {
let m = find(&mid);
let contact = contact::find(&m.from);
let contact = contact::find_by_i2p_address(&m.from);
let nmpk = contact.nmpk;
let message = String::from(&m.body);
let body = neveko25519::cipher(&nmpk, message, None).await;

View file

@ -107,7 +107,6 @@ pub async fn generate_neveko_message_keys() -> NevekoMessageKeys {
monero::close_wallet(&filename, &password).await;
let svk = svk_res.result.key;
let scalar_nmsk = hash_to_scalar(vec![&svk[..], crate::APP_NAME]);
log::debug!("scalar_nmsk: {:?}", &scalar_nmsk);
let point_nmpk = EdwardsPoint::mul_base(&scalar_nmsk);
let nmsk = *scalar_nmsk.as_bytes();
let nmpk: [u8; 32] = *point_nmpk.compress().as_bytes();

View file

@ -173,9 +173,8 @@ fn decipher_req(m: &Message, tx: Sender<String>, ctx: egui::Context) {
let body: String = String::from(&m.body);
tokio::spawn(async move {
log::info!("async decipher_req");
let contact = contact::find(&from);
let encipher = Some(String::from(neveko25519::ENCIPHER));
let deciphered = neveko25519::cipher(&contact.nmpk, body, encipher).await;
let contact = contact::find_by_i2p_address(&from);
let deciphered = neveko25519::cipher(&contact.nmpk, body, None).await;
let _ = tx.send(deciphered);
ctx.request_repaint();
});

View file

@ -1,6 +1,7 @@
#![allow(non_snake_case)]
use rocket::{
delete,
get,
http::Status,
post,
@ -39,6 +40,14 @@ pub async fn get_messages(_token: auth::BearerToken) -> Custom<Json<Vec<Message>
Custom(Status::Ok, Json(messages))
}
/// Delete a message by mid
#[delete("/<mid>")]
pub async fn remove_message(mid: String, _token: auth::BearerToken) -> Custom<Json<Vec<Message>>> {
message::delete(&mid);
let messages = message::find_all();
Custom(Status::Ok, Json(messages))
}
/// decipher a message body
#[get("/<mid>")]
pub async fn decipher(

View file

@ -15,6 +15,7 @@ async fn rocket() -> _ {
env_logger::init();
log::info!("neveko-message is online");
rocket::custom(&config)
.mount("/message/remove", routes![controller::remove_message])
.mount("/message/decipher", routes![controller::decipher])
.mount("/messages", routes![controller::get_messages])
.mount("/tx", routes![controller::send_message])