mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-01-20 19:11:09 +03:00
Secure API JSON RPC ID can be integer or string (#314)
* Fix #312 * Fix tests
This commit is contained in:
parent
f09c91f626
commit
3091bd9701
3 changed files with 12 additions and 9 deletions
|
@ -142,14 +142,15 @@ pub struct EncryptedRequest {
|
||||||
/// method
|
/// method
|
||||||
pub method: String,
|
pub method: String,
|
||||||
/// id
|
/// id
|
||||||
pub id: u32,
|
#[serde(with = "secp_ser::string_or_u64")]
|
||||||
|
pub id: u64,
|
||||||
/// Body params, which includes nonce and encrypted request
|
/// Body params, which includes nonce and encrypted request
|
||||||
pub params: EncryptedBody,
|
pub params: EncryptedBody,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptedRequest {
|
impl EncryptedRequest {
|
||||||
/// from json
|
/// from json
|
||||||
pub fn from_json(id: u32, json_in: &Value, enc_key: &SecretKey) -> Result<Self, Error> {
|
pub fn from_json(id: u64, json_in: &Value, enc_key: &SecretKey) -> Result<Self, Error> {
|
||||||
Ok(EncryptedRequest {
|
Ok(EncryptedRequest {
|
||||||
jsonrpc: "2.0".to_owned(),
|
jsonrpc: "2.0".to_owned(),
|
||||||
method: "encrypted_request_v3".to_owned(),
|
method: "encrypted_request_v3".to_owned(),
|
||||||
|
@ -187,14 +188,15 @@ pub struct EncryptedResponse {
|
||||||
/// JSON RPC response
|
/// JSON RPC response
|
||||||
pub jsonrpc: String,
|
pub jsonrpc: String,
|
||||||
/// id
|
/// id
|
||||||
pub id: u32,
|
#[serde(with = "secp_ser::string_or_u64")]
|
||||||
|
pub id: u64,
|
||||||
/// result
|
/// result
|
||||||
pub result: HashMap<String, EncryptedBody>,
|
pub result: HashMap<String, EncryptedBody>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptedResponse {
|
impl EncryptedResponse {
|
||||||
/// from json
|
/// from json
|
||||||
pub fn from_json(id: u32, json_in: &Value, enc_key: &SecretKey) -> Result<Self, Error> {
|
pub fn from_json(id: u64, json_in: &Value, enc_key: &SecretKey) -> Result<Self, Error> {
|
||||||
let mut result_set = HashMap::new();
|
let mut result_set = HashMap::new();
|
||||||
result_set.insert(
|
result_set.insert(
|
||||||
"Ok".to_string(),
|
"Ok".to_string(),
|
||||||
|
@ -245,14 +247,15 @@ pub struct EncryptionErrorResponse {
|
||||||
/// JSON RPC response
|
/// JSON RPC response
|
||||||
pub jsonrpc: String,
|
pub jsonrpc: String,
|
||||||
/// id
|
/// id
|
||||||
pub id: u32,
|
#[serde(with = "secp_ser::string_or_u64")]
|
||||||
|
pub id: u64,
|
||||||
/// error
|
/// error
|
||||||
pub error: EncryptionError,
|
pub error: EncryptionError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptionErrorResponse {
|
impl EncryptionErrorResponse {
|
||||||
/// Create new response
|
/// Create new response
|
||||||
pub fn new(id: u32, code: i32, message: &str) -> Self {
|
pub fn new(id: u64, code: i32, message: &str) -> Self {
|
||||||
EncryptionErrorResponse {
|
EncryptionErrorResponse {
|
||||||
jsonrpc: "2.0".to_owned(),
|
jsonrpc: "2.0".to_owned(),
|
||||||
id: id,
|
id: id,
|
||||||
|
|
|
@ -475,7 +475,7 @@ impl OwnerV3Helpers {
|
||||||
pub fn decrypt_request(
|
pub fn decrypt_request(
|
||||||
key: Arc<Mutex<Option<SecretKey>>>,
|
key: Arc<Mutex<Option<SecretKey>>>,
|
||||||
req: &serde_json::Value,
|
req: &serde_json::Value,
|
||||||
) -> Result<(u32, serde_json::Value), serde_json::Value> {
|
) -> Result<(u64, serde_json::Value), serde_json::Value> {
|
||||||
let share_key_ref = key.lock();
|
let share_key_ref = key.lock();
|
||||||
let shared_key = share_key_ref.as_ref().unwrap();
|
let shared_key = share_key_ref.as_ref().unwrap();
|
||||||
let enc_req: EncryptedRequest = serde_json::from_value(req.clone()).map_err(|e| {
|
let enc_req: EncryptedRequest = serde_json::from_value(req.clone()).map_err(|e| {
|
||||||
|
@ -497,7 +497,7 @@ impl OwnerV3Helpers {
|
||||||
/// Encrypt a response
|
/// Encrypt a response
|
||||||
pub fn encrypt_response(
|
pub fn encrypt_response(
|
||||||
key: Arc<Mutex<Option<SecretKey>>>,
|
key: Arc<Mutex<Option<SecretKey>>>,
|
||||||
id: u32,
|
id: u64,
|
||||||
res: &serde_json::Value,
|
res: &serde_json::Value,
|
||||||
) -> Result<serde_json::Value, serde_json::Value> {
|
) -> Result<serde_json::Value, serde_json::Value> {
|
||||||
let share_key_ref = key.lock();
|
let share_key_ref = key.lock();
|
||||||
|
|
|
@ -371,7 +371,7 @@ where
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn send_request_enc<OUT>(
|
pub fn send_request_enc<OUT>(
|
||||||
sec_req_id: u32,
|
sec_req_id: u64,
|
||||||
internal_request_id: u32,
|
internal_request_id: u32,
|
||||||
dest: &str,
|
dest: &str,
|
||||||
req: &str,
|
req: &str,
|
||||||
|
|
Loading…
Reference in a new issue