mirror of
https://github.com/creating2morrow/neveko.git
synced 2024-12-22 11:39:22 +00:00
patch contact nmpk lookup for decipher
This commit is contained in:
parent
696d1ad300
commit
6493cf575b
9 changed files with 64 additions and 7 deletions
14
docs/curl.md
14
docs/curl.md
|
@ -39,7 +39,7 @@ curl -iv http://bob.b32.i2p/xmr/version -H 'proof: eyJhbGciOiJIUzUxMiJ9...'
|
||||||
## add contact
|
## add contact
|
||||||
|
|
||||||
```bash
|
```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
|
## 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
|
curl -iv http://localhost:9044/contacts
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## remove contact
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -iv -X DELETE http://localhost:9044/contact/remove/<CID>
|
||||||
|
```
|
||||||
|
|
||||||
## send message
|
## send message
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -66,6 +72,12 @@ curl -iv http://alice.b32.i2p/message/rx -d '{"uid":"", "mid": "", "body": "stri
|
||||||
curl -iv http://localhost:9045/messages
|
curl -iv http://localhost:9045/messages
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## remove message
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -iv -X DELETE http://localhost:9045/message/remove/<MID>
|
||||||
|
```
|
||||||
|
|
||||||
## decipher message
|
## decipher message
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use rocket::{
|
use rocket::{
|
||||||
|
delete,
|
||||||
get,
|
get,
|
||||||
http::Status,
|
http::Status,
|
||||||
post,
|
post,
|
||||||
|
@ -37,6 +38,17 @@ pub async fn get_contacts(_token: auth::BearerToken) -> Custom<Json<Vec<Contact>
|
||||||
Custom(Status::Ok, Json(contacts))
|
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
|
/// prove payment
|
||||||
#[get("/<contact>", data = "<proof_req>")]
|
#[get("/<contact>", data = "<proof_req>")]
|
||||||
pub async fn prove_payment(
|
pub async fn prove_payment(
|
||||||
|
|
|
@ -16,6 +16,9 @@ async fn rocket() -> _ {
|
||||||
log::info!("neveko-contact is online");
|
log::info!("neveko-contact is online");
|
||||||
rocket::custom(&config)
|
rocket::custom(&config)
|
||||||
.mount("/prove", routes![controller::prove_payment])
|
.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])
|
.mount("/contacts", routes![controller::get_contacts])
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,28 @@ pub fn find(cid: &String) -> Contact {
|
||||||
Contact::from_db(String::from(cid), r)
|
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
|
/// All contact lookup
|
||||||
pub fn find_all() -> Vec<Contact> {
|
pub fn find_all() -> Vec<Contact> {
|
||||||
info!("looking up all contacts");
|
info!("looking up all contacts");
|
||||||
|
|
|
@ -317,7 +317,7 @@ async fn send_message(out: &Message, jwp: &str, m_type: MessageType) -> Result<(
|
||||||
/// Returns deciphered message
|
/// Returns deciphered message
|
||||||
pub async fn decipher_body(mid: String) -> reqres::DecipheredMessageBody {
|
pub async fn decipher_body(mid: String) -> reqres::DecipheredMessageBody {
|
||||||
let m = find(&mid);
|
let m = find(&mid);
|
||||||
let contact = contact::find(&m.from);
|
let contact = contact::find_by_i2p_address(&m.from);
|
||||||
let nmpk = contact.nmpk;
|
let nmpk = contact.nmpk;
|
||||||
let message = String::from(&m.body);
|
let message = String::from(&m.body);
|
||||||
let body = neveko25519::cipher(&nmpk, message, None).await;
|
let body = neveko25519::cipher(&nmpk, message, None).await;
|
||||||
|
|
|
@ -107,7 +107,6 @@ pub async fn generate_neveko_message_keys() -> NevekoMessageKeys {
|
||||||
monero::close_wallet(&filename, &password).await;
|
monero::close_wallet(&filename, &password).await;
|
||||||
let svk = svk_res.result.key;
|
let svk = svk_res.result.key;
|
||||||
let scalar_nmsk = hash_to_scalar(vec![&svk[..], crate::APP_NAME]);
|
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 point_nmpk = EdwardsPoint::mul_base(&scalar_nmsk);
|
||||||
let nmsk = *scalar_nmsk.as_bytes();
|
let nmsk = *scalar_nmsk.as_bytes();
|
||||||
let nmpk: [u8; 32] = *point_nmpk.compress().as_bytes();
|
let nmpk: [u8; 32] = *point_nmpk.compress().as_bytes();
|
||||||
|
|
|
@ -173,9 +173,8 @@ fn decipher_req(m: &Message, tx: Sender<String>, ctx: egui::Context) {
|
||||||
let body: String = String::from(&m.body);
|
let body: String = String::from(&m.body);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
log::info!("async decipher_req");
|
log::info!("async decipher_req");
|
||||||
let contact = contact::find(&from);
|
let contact = contact::find_by_i2p_address(&from);
|
||||||
let encipher = Some(String::from(neveko25519::ENCIPHER));
|
let deciphered = neveko25519::cipher(&contact.nmpk, body, None).await;
|
||||||
let deciphered = neveko25519::cipher(&contact.nmpk, body, encipher).await;
|
|
||||||
let _ = tx.send(deciphered);
|
let _ = tx.send(deciphered);
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use rocket::{
|
use rocket::{
|
||||||
|
delete,
|
||||||
get,
|
get,
|
||||||
http::Status,
|
http::Status,
|
||||||
post,
|
post,
|
||||||
|
@ -39,6 +40,14 @@ pub async fn get_messages(_token: auth::BearerToken) -> Custom<Json<Vec<Message>
|
||||||
Custom(Status::Ok, Json(messages))
|
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
|
/// decipher a message body
|
||||||
#[get("/<mid>")]
|
#[get("/<mid>")]
|
||||||
pub async fn decipher(
|
pub async fn decipher(
|
||||||
|
|
|
@ -15,6 +15,7 @@ async fn rocket() -> _ {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
log::info!("neveko-message is online");
|
log::info!("neveko-message is online");
|
||||||
rocket::custom(&config)
|
rocket::custom(&config)
|
||||||
|
.mount("/message/remove", routes![controller::remove_message])
|
||||||
.mount("/message/decipher", routes![controller::decipher])
|
.mount("/message/decipher", routes![controller::decipher])
|
||||||
.mount("/messages", routes![controller::get_messages])
|
.mount("/messages", routes![controller::get_messages])
|
||||||
.mount("/tx", routes![controller::send_message])
|
.mount("/tx", routes![controller::send_message])
|
||||||
|
|
Loading…
Reference in a new issue