mirror of
https://github.com/creating2morrow/neveko.git
synced 2025-01-05 10:29:31 +00:00
add secure order retrieval
This commit is contained in:
parent
348725ad4c
commit
3255b15c9a
5 changed files with 56 additions and 20 deletions
|
@ -5,7 +5,7 @@ NEVidebla-EKOnomia (invisible economy)
|
||||||
[![cargo-build](https://github.com/creating2morrow/neveko/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/creating2morrow/neveko/actions/workflows/rust.yml)
|
[![cargo-build](https://github.com/creating2morrow/neveko/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/creating2morrow/neveko/actions/workflows/rust.yml)
|
||||||
[![cargo-audit](https://github.com/creating2morrow/neveko/actions/workflows/audit.yml/badge.svg?branch=main)](https://github.com/creating2morrow/neveko/actions/workflows/audit.yml)
|
[![cargo-audit](https://github.com/creating2morrow/neveko/actions/workflows/audit.yml/badge.svg?branch=main)](https://github.com/creating2morrow/neveko/actions/workflows/audit.yml)
|
||||||
|
|
||||||
### gpg and i2p made simple for end-to-end encrypted, secure marketplace, messaging and more
|
### gpg and i2p made simple for E2EE marketplace, messaging and more
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
|
|
|
@ -101,8 +101,13 @@ pub async fn verify_login(aid: String, uid: String, signature: String) -> Author
|
||||||
return create(&address);
|
return create(&address);
|
||||||
}
|
}
|
||||||
let data: String = String::from(&f_auth.rnd);
|
let data: String = String::from(&f_auth.rnd);
|
||||||
let sig_address: String =
|
let is_valid_sig: bool =
|
||||||
monero::verify(String::from(&address), data, String::from(&signature)).await;
|
monero::verify(String::from(&address), data, String::from(&signature)).await;
|
||||||
|
let sig_address: String = if is_valid_sig {
|
||||||
|
String::from(&address)
|
||||||
|
} else {
|
||||||
|
utils::ApplicationErrors::LoginError.value()
|
||||||
|
};
|
||||||
if sig_address == utils::ApplicationErrors::LoginError.value() {
|
if sig_address == utils::ApplicationErrors::LoginError.value() {
|
||||||
error!("signature validation failed");
|
error!("signature validation failed");
|
||||||
monero::close_wallet(&wallet_name, &wallet_password).await;
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
|
@ -155,8 +160,13 @@ async fn verify_access(address: &String, signature: &String) -> bool {
|
||||||
}
|
}
|
||||||
// verify signature on the data if not expired
|
// verify signature on the data if not expired
|
||||||
let data = f_auth.rnd;
|
let data = f_auth.rnd;
|
||||||
let sig_address: String =
|
let is_valid_sig: bool =
|
||||||
monero::verify(String::from(address), data, String::from(signature)).await;
|
monero::verify(String::from(address), data, String::from(signature)).await;
|
||||||
|
let sig_address: String = if is_valid_sig {
|
||||||
|
String::from(address)
|
||||||
|
} else {
|
||||||
|
utils::ApplicationErrors::LoginError.value()
|
||||||
|
};
|
||||||
if sig_address == utils::ApplicationErrors::LoginError.value() {
|
if sig_address == utils::ApplicationErrors::LoginError.value() {
|
||||||
debug!("signing failed");
|
debug!("signing failed");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -135,8 +135,7 @@ pub fn start_daemon() {
|
||||||
debug!("{:?}", output.stdout);
|
debug!("{:?}", output.stdout);
|
||||||
} else {
|
} else {
|
||||||
let args = [
|
let args = [
|
||||||
"
|
"--data-dir",
|
||||||
--data-dir",
|
|
||||||
&blockchain_dir,
|
&blockchain_dir,
|
||||||
"--tx-proxy",
|
"--tx-proxy",
|
||||||
&tx_proxy,
|
&tx_proxy,
|
||||||
|
@ -302,7 +301,7 @@ pub async fn check_rpc_connection() -> () {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs the xmr rpc 'verify' method
|
/// Performs the xmr rpc 'verify' method
|
||||||
pub async fn verify(address: String, data: String, signature: String) -> String {
|
pub async fn verify(address: String, data: String, signature: String) -> bool {
|
||||||
info!("executing {}", RpcFields::Verify.value());
|
info!("executing {}", RpcFields::Verify.value());
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let host = get_rpc_host();
|
let host = get_rpc_host();
|
||||||
|
@ -330,15 +329,15 @@ pub async fn verify(address: String, data: String, signature: String) -> String
|
||||||
match res {
|
match res {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
if res.result.good {
|
if res.result.good {
|
||||||
req.params.address
|
true
|
||||||
} else {
|
} else {
|
||||||
utils::ApplicationErrors::LoginError.value()
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => utils::ApplicationErrors::LoginError.value(),
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => utils::ApplicationErrors::LoginError.value(),
|
Err(_e) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
|
contact,
|
||||||
db,
|
db,
|
||||||
models::*,
|
models::*,
|
||||||
monero,
|
monero,
|
||||||
|
@ -16,7 +17,7 @@ use rocket::serde::json::Json;
|
||||||
TODOs(c2m):
|
TODOs(c2m):
|
||||||
- API to validate payment and import multisig info, update to multisig complete
|
- API to validate payment and import multisig info, update to multisig complete
|
||||||
- API to upload gpg encrypted tracking number, update order to shipped
|
- API to upload gpg encrypted tracking number, update order to shipped
|
||||||
release tracking (locker code?) when txset is released, update to delivered
|
- release tracking (locker code?) when txset is released, update to delivered
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum StatusType {
|
enum StatusType {
|
||||||
|
@ -167,6 +168,33 @@ pub async fn sign_and_submit_multisig(
|
||||||
r_submit
|
r_submit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// In order for the order (...ha) to only be accessed by the customer
|
||||||
|
///
|
||||||
|
/// they must sign the order id with their NEVEKO wallet instance. This means
|
||||||
|
///
|
||||||
|
/// that the mediator can see order id for disputes without being able to access
|
||||||
|
///
|
||||||
|
/// the details of said order.
|
||||||
|
pub async fn retrieve_order(orid: &String, signature: &String) -> Order {
|
||||||
|
// get customer address for NEVEKO NOT order wallet
|
||||||
|
let m_order: Order = find(&orid);
|
||||||
|
let mut xmr_address: String = String::new();
|
||||||
|
let a_customers: Vec<Contact> = contact::find_all();
|
||||||
|
for customer in a_customers {
|
||||||
|
if customer.i2p_address == m_order.cid {
|
||||||
|
xmr_address = customer.xmr_address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// send address, orid and signature to verify()
|
||||||
|
let id: String = String::from(&m_order.orid);
|
||||||
|
let sig: String = String::from(signature);
|
||||||
|
let is_valid_signature = monero::verify(xmr_address, id, sig).await;
|
||||||
|
if !is_valid_signature {
|
||||||
|
return Default::default();
|
||||||
|
}
|
||||||
|
m_order
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn validate_order_for_ship() -> bool {
|
pub async fn validate_order_for_ship() -> bool {
|
||||||
info!("validating order for shipment");
|
info!("validating order for shipment");
|
||||||
// import multisig info
|
// import multisig info
|
||||||
|
|
|
@ -98,22 +98,21 @@ pub async fn create_order(
|
||||||
Custom(Status::Created, Json(m_order))
|
Custom(Status::Created, Json(m_order))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO(c2m): Customer order retreival. Must send `signature`
|
/// Customer order retreival. Must send `signature`
|
||||||
///
|
///
|
||||||
/// which is the order id signed by the wallet.
|
/// which is the order id signed by the NEVEKO wallet.
|
||||||
///
|
///
|
||||||
/// Protected: true
|
/// Protected: true
|
||||||
#[get("/order/retrieve/<orid>/<_signature>")]
|
#[get("/order/retrieve/<orid>/<signature>")]
|
||||||
pub async fn retrieve_order(
|
pub async fn retrieve_order(
|
||||||
orid: String,
|
orid: String,
|
||||||
_signature: String,
|
signature: String,
|
||||||
_jwp: proof::PaymentProof,
|
_jwp: proof::PaymentProof,
|
||||||
) -> Custom<Json<models::Order>> {
|
) -> Custom<Json<models::Order>> {
|
||||||
// get customer address
|
let m_order = order::retrieve_order(&orid, &signature).await;
|
||||||
|
if m_order.cid == utils::empty_string() {
|
||||||
// send address, orid and signature to verify()
|
return Custom(Status::BadRequest, Json(Default::default()));
|
||||||
|
}
|
||||||
let m_order: models::Order = order::find(&orid);
|
|
||||||
Custom(Status::Created, Json(m_order))
|
Custom(Status::Created, Json(m_order))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue