From 77c8d8ff2fe6aa7d6b5801875c6e16150afe77ce Mon Sep 17 00:00:00 2001 From: nain-F49FF806 <126972030+nain-F49FF806@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:13:48 +0200 Subject: [PATCH] Use a sequence of bytes (representing AriesMessage) as input for EncryptionEnvelope::create (#1007) * Use a sequence of bytes (representing AriesMessage) as input for EncryptionEnvelope::create Signed-off-by: Naian <126972030+nain-F49FF806@users.noreply.github.com> --- aries_vcx/src/protocols/connection/generic/mod.rs | 8 +++++++- aries_vcx/src/protocols/connection/mod.rs | 8 +++++++- aries_vcx/src/utils/encryption_envelope.rs | 10 +++++----- aries_vcx/src/utils/mod.rs | 13 ++++++++++--- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/aries_vcx/src/protocols/connection/generic/mod.rs b/aries_vcx/src/protocols/connection/generic/mod.rs index cc9e981743..93bdd45c25 100644 --- a/aries_vcx/src/protocols/connection/generic/mod.rs +++ b/aries_vcx/src/protocols/connection/generic/mod.rs @@ -180,7 +180,13 @@ impl GenericConnection { AriesVcxErrorKind::NotReady, "No DidDoc present", ))?; - EncryptionEnvelope::create(wallet, message, Some(sender_verkey), did_doc).await + EncryptionEnvelope::create( + wallet, + json!(message).to_string().as_bytes(), + Some(sender_verkey), + did_doc, + ) + .await } pub async fn send_message( diff --git a/aries_vcx/src/protocols/connection/mod.rs b/aries_vcx/src/protocols/connection/mod.rs index 71b3ec506f..5368355451 100644 --- a/aries_vcx/src/protocols/connection/mod.rs +++ b/aries_vcx/src/protocols/connection/mod.rs @@ -100,7 +100,13 @@ where message: &AriesMessage, ) -> VcxResult { let sender_verkey = &self.pairwise_info().pw_vk; - EncryptionEnvelope::create(wallet, message, Some(sender_verkey), self.their_did_doc()).await + EncryptionEnvelope::create( + wallet, + json!(message).to_string().as_bytes(), + Some(sender_verkey), + self.their_did_doc(), + ) + .await } pub fn remote_did(&self) -> &str { diff --git a/aries_vcx/src/utils/encryption_envelope.rs b/aries_vcx/src/utils/encryption_envelope.rs index 1818f96f10..342fabb385 100644 --- a/aries_vcx/src/utils/encryption_envelope.rs +++ b/aries_vcx/src/utils/encryption_envelope.rs @@ -14,9 +14,11 @@ use crate::{errors::error::prelude::*, global::settings, utils::constants}; pub struct EncryptionEnvelope(pub Vec); impl EncryptionEnvelope { + /// Create an Encryption Envelope from a plaintext AriesMessage encoded as sequence of bytes. + /// If did_doc includes routing_keys, then also wrap in appropriate layers of forward message. pub async fn create( wallet: &impl BaseWallet, - message: &AriesMessage, + message: &[u8], pw_verkey: Option<&str>, did_doc: &AriesDidDoc, ) -> VcxResult { @@ -41,12 +43,10 @@ impl EncryptionEnvelope { async fn encrypt_for_pairwise( wallet: &impl BaseWallet, - message: &AriesMessage, + message: &[u8], pw_verkey: Option<&str>, did_doc: &AriesDidDoc, ) -> VcxResult> { - let message = json!(message).to_string(); - let receiver_keys = json!(did_doc.recipient_keys()?).to_string(); debug!( @@ -55,7 +55,7 @@ impl EncryptionEnvelope { ); wallet - .pack_message(pw_verkey, &receiver_keys, message.as_bytes()) + .pack_message(pw_verkey, &receiver_keys, message) .await .map_err(|err| err.into()) } diff --git a/aries_vcx/src/utils/mod.rs b/aries_vcx/src/utils/mod.rs index b747d5368d..2733ef25d2 100644 --- a/aries_vcx/src/utils/mod.rs +++ b/aries_vcx/src/utils/mod.rs @@ -56,8 +56,14 @@ pub async fn send_message( message, &did_doc ); - let EncryptionEnvelope(envelope) = - EncryptionEnvelope::create(wallet, &message, Some(&sender_verkey), &did_doc).await?; + + let EncryptionEnvelope(envelope) = EncryptionEnvelope::create( + wallet, + json!(message).to_string().as_bytes(), + Some(&sender_verkey), + &did_doc, + ) + .await?; // TODO: Extract from agency client agency_client::httpclient::post_message( @@ -81,7 +87,8 @@ pub async fn send_message_anonymously( &did_doc ); let EncryptionEnvelope(envelope) = - EncryptionEnvelope::create(wallet, message, None, did_doc).await?; + EncryptionEnvelope::create(wallet, json!(message).to_string().as_bytes(), None, did_doc) + .await?; agency_client::httpclient::post_message( envelope,