From 02e8f03d2656927afdacbdf8823ca8b7e07ad7fb Mon Sep 17 00:00:00 2001 From: Zachary Edgell Date: Wed, 20 Mar 2024 05:27:50 -0400 Subject: [PATCH 01/14] Added Crypto functionality. Signed-off-by: Zachary Edgell --- Cargo.toml | 9 ++- examples/crypto/components/local-storage.yml | 11 +++ examples/crypto/image.png | Bin 0 -> 3958 bytes examples/crypto/main.rs | 74 ++++++++++++++++++ src/client.rs | 13 ++-- src/crypto.rs | 78 +++++++++++++++++++ src/lib.rs | 11 +-- 7 files changed, 183 insertions(+), 13 deletions(-) create mode 100644 examples/crypto/components/local-storage.yml create mode 100644 examples/crypto/image.png create mode 100644 examples/crypto/main.rs create mode 100644 src/crypto.rs diff --git a/Cargo.toml b/Cargo.toml index 4f4a4893..e9fb7fe5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,4 @@ +workspace = { members = ["durabletask"] } [package] name = "dapr" version = "0.14.0" @@ -10,7 +11,7 @@ readme = "README.md" keywords = ["microservices", "dapr"] [dependencies] -dapr-macros = {version="0.14.0", path = "macros" } +dapr-macros = { version = "0.14.0", path = "macros" } futures = "0.3" tonic = "0.11.0" prost = "0.12.3" @@ -33,7 +34,7 @@ axum-test = "14.3.0" once_cell = "1.18.0" tokio = { version = "1", features = ["full"] } uuid = { version = "1.4.0", features = ["v4"] } -dapr = {path="./"} +dapr = { path = "./" } tokio-test = "0.4.2" tokio-stream = { version = "0.1" } @@ -76,3 +77,7 @@ path = "examples/actors/client.rs" [[example]] name = "actor-server" path = "examples/actors/server.rs" + +[[example]] +name = "crypto" +path = "examples/crypto/main.rs" diff --git a/examples/crypto/components/local-storage.yml b/examples/crypto/components/local-storage.yml new file mode 100644 index 00000000..5a2d84e7 --- /dev/null +++ b/examples/crypto/components/local-storage.yml @@ -0,0 +1,11 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: localstorage +spec: + type: crypto.dapr.localstorage + version: v1 + metadata: + - name: path + # Path is relative to the folder where the example is located + value: ./examples/crypto/keys \ No newline at end of file diff --git a/examples/crypto/image.png b/examples/crypto/image.png new file mode 100644 index 0000000000000000000000000000000000000000..7bdad7f19dab4b2d8962099e1a37cd1730968fcd GIT binary patch literal 3958 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 bM`#-D&=f?2bM`EqJ9LJ6W{=8rAQArq5pA)g literal 0 HcmV?d00001 diff --git a/examples/crypto/main.rs b/examples/crypto/main.rs new file mode 100644 index 00000000..68a8f19c --- /dev/null +++ b/examples/crypto/main.rs @@ -0,0 +1,74 @@ +use std::fs; + +use tokio::time::sleep; + +use dapr::dapr::dapr::proto::runtime::v1::{DecryptRequestOptions, EncryptRequestOptions}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + sleep(std::time::Duration::new(2, 0)).await; + let port: u16 = std::env::var("DAPR_GRPC_PORT")?.parse()?; + let addr = format!("https://127.0.0.1:{}", port); + + let mut client = dapr::Client::::connect(addr).await?; + + let encrypted = client + .encrypt( + &"Test".to_string(), + EncryptRequestOptions { + component_name: "localstorage".to_string(), + key_name: "rsa-private-key.pem".to_string(), + key_wrap_algorithm: "RSA".to_string(), + data_encryption_cipher: "aes-gcm".to_string(), + omit_decryption_key_name: false, + decryption_key_name: "rsa-private-key.pem".to_string(), + }, + ) + .await + .unwrap(); + + let decrypted = client + .decrypt( + encrypted, + DecryptRequestOptions { + component_name: "localstorage".to_string(), + key_name: "rsa-private-key.pem".to_string(), + }, + ) + .await + .unwrap(); + + assert_eq!(String::from_utf8(decrypted).unwrap().as_str(), "Test"); + + let image = fs::read("./examples/crypto/image.png").unwrap(); + + let encrypted = client + .encrypt( + &image, + EncryptRequestOptions { + component_name: "localstorage".to_string(), + key_name: "rsa-private-key.pem".to_string(), + key_wrap_algorithm: "RSA".to_string(), + data_encryption_cipher: "aes-gcm".to_string(), + omit_decryption_key_name: false, + decryption_key_name: "rsa-private-key.pem".to_string(), + }, + ) + .await + .unwrap(); + + let decrypted = client + .decrypt( + encrypted, + DecryptRequestOptions { + component_name: "localstorage".to_string(), + key_name: "rsa-private-key.pem".to_string(), + }, + ) + .await + .unwrap(); + + assert_eq!(decrypted, image); + + Ok(()) +} diff --git a/src/client.rs b/src/client.rs index 8b4d675f..a32ecc77 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,15 +1,16 @@ -use crate::dapr::dapr::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1}; -use prost_types::Any; use std::collections::HashMap; -use tonic::Streaming; -use tonic::{transport::Channel as TonicChannel, Request}; -use crate::error::Error; use async_trait::async_trait; +use prost_types::Any; use serde::{Deserialize, Serialize}; +use tonic::{Request, transport::Channel as TonicChannel}; +use tonic::Streaming; + +use crate::dapr::dapr::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1}; +use crate::error::Error; #[derive(Clone)] -pub struct Client(T); +pub struct Client(pub(crate) T); impl Client { /// Connect to a Dapr enabled app. diff --git a/src/crypto.rs b/src/crypto.rs new file mode 100644 index 00000000..8ebc5c0f --- /dev/null +++ b/src/crypto.rs @@ -0,0 +1,78 @@ +use futures::StreamExt; +use tonic::{Request, Status}; +use tonic::codegen::tokio_stream; + +use crate::Client; +use crate::client::TonicClient; +use crate::dapr::dapr::proto::common::v1::StreamPayload; +use crate::dapr::dapr::proto::runtime::v1::{ + DecryptRequest, DecryptRequestOptions, EncryptRequest, EncryptRequestOptions, +}; + +impl Client { + pub async fn encrypt( + &mut self, + payload: &T, + request_options: EncryptRequestOptions, + ) -> Result, Status> + where + T: Into> + Clone, + { + let stream_payload = StreamPayload { + data: payload.clone().into(), + seq: 0, + }; + let request = EncryptRequest { + options: Some(request_options), + payload: Some(stream_payload), + }; + let request = Request::new(tokio_stream::iter([request])); + let stream = self.0.encrypt_alpha1(request).await?; + let mut stream = stream.into_inner(); + let mut return_data = vec![]; + while let Some(resp) = stream.next().await { + if let Ok(resp) = resp { + if let Some(data) = resp.payload { + return_data.push(data) + } + } + } + Ok(return_data) + } + + pub async fn decrypt( + &mut self, + encrypted: Vec, + options: DecryptRequestOptions, + ) -> Result, Status> { + let requested_items: Vec = encrypted + .iter() + .enumerate() + .map(|(i, item)| { + if i == 0 { + DecryptRequest { + options: Some(options.clone()), + payload: Some(item.clone()), + } + } else { + DecryptRequest { + options: None, + payload: Some(item.clone()), + } + } + }) + .collect(); + let request = Request::new(tokio_stream::iter(requested_items)); + let stream = self.0.decrypt_alpha1(request).await?; + let mut stream = stream.into_inner(); + let mut data = vec![]; + while let Some(resp) = stream.next().await { + if let Ok(resp) = resp { + if let Some(mut payload) = resp.payload { + data.append(payload.data.as_mut()) + } + } + } + Ok(data) + } +} diff --git a/src/lib.rs b/src/lib.rs index 06889748..08a64132 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,11 @@ +extern crate dapr_macros; + +pub use client::Client; +pub use dapr_macros::actor; + pub mod appcallback; pub mod client; +pub mod crypto; pub mod dapr; pub mod error; pub mod server; - -pub use client::Client; - -extern crate dapr_macros; -pub use dapr_macros::actor; From a0b154dac470689783c7bedd1c56b2b537e87768 Mon Sep 17 00:00:00 2001 From: Zachary Edgell Date: Wed, 20 Mar 2024 05:49:50 -0400 Subject: [PATCH 02/14] Added README.md Signed-off-by: Zachary Edgell --- examples/crypto/README.md | 40 ++++++++++++++++++++ examples/crypto/components/local-storage.yml | 2 +- examples/crypto/dapr.yaml | 10 +++++ examples/crypto/main.rs | 6 ++- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 examples/crypto/README.md create mode 100644 examples/crypto/dapr.yaml diff --git a/examples/crypto/README.md b/examples/crypto/README.md new file mode 100644 index 00000000..08507caa --- /dev/null +++ b/examples/crypto/README.md @@ -0,0 +1,40 @@ +# Crypto Example + +This is a simple example that demonstrates Dapr's Cryptography capabilities. + +> **Note:** Make sure to use latest version of proto bindings. + +## Running + +> Before you run the example make sure generate keys in examples/crypto/keys directory: +> ``` +> mkdir -p keys +> # Generate a private RSA key, 4096-bit keys +> openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out keys/rsa-private-key.pem +> # Generate a 256-bit key for AES +> openssl rand -out keys/symmetric-key-256 32 +> ``` + +To run this example: + +1. Run the multi-app run template: + + + +```bash +dapr run -f . +``` + + + +2. Stop with `ctrl + c` diff --git a/examples/crypto/components/local-storage.yml b/examples/crypto/components/local-storage.yml index 5a2d84e7..a678ef20 100644 --- a/examples/crypto/components/local-storage.yml +++ b/examples/crypto/components/local-storage.yml @@ -8,4 +8,4 @@ spec: metadata: - name: path # Path is relative to the folder where the example is located - value: ./examples/crypto/keys \ No newline at end of file + value: ./keys \ No newline at end of file diff --git a/examples/crypto/dapr.yaml b/examples/crypto/dapr.yaml new file mode 100644 index 00000000..91243ee5 --- /dev/null +++ b/examples/crypto/dapr.yaml @@ -0,0 +1,10 @@ +version: 1 +common: + daprdLogDestination: console +apps: + - appID: crypto-example + appDirPath: ./ + daprGRPCPort: 35002 + logLevel: debug + command: [ "cargo", "run", "--example", "crypto" ] + resourcesPath: ./components \ No newline at end of file diff --git a/examples/crypto/main.rs b/examples/crypto/main.rs index 68a8f19c..7f8879cf 100644 --- a/examples/crypto/main.rs +++ b/examples/crypto/main.rs @@ -40,7 +40,9 @@ async fn main() -> Result<(), Box> { assert_eq!(String::from_utf8(decrypted).unwrap().as_str(), "Test"); - let image = fs::read("./examples/crypto/image.png").unwrap(); + println!("Successfully Decrypted String"); + + let image = fs::read("./image.png").unwrap(); let encrypted = client .encrypt( @@ -70,5 +72,7 @@ async fn main() -> Result<(), Box> { assert_eq!(decrypted, image); + println!("Successfully Decrypted Image"); + Ok(()) } From 28f33f214dfe6b7ca998c6bca3b2167b86809048 Mon Sep 17 00:00:00 2001 From: Zachary Edgell Date: Wed, 20 Mar 2024 05:55:35 -0400 Subject: [PATCH 03/14] Code Formatting Signed-off-by: Zachary Edgell --- src/client.rs | 2 +- src/crypto.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client.rs b/src/client.rs index fa7fd711..014c23e0 100644 --- a/src/client.rs +++ b/src/client.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; use async_trait::async_trait; use prost_types::Any; use serde::{Deserialize, Serialize}; -use tonic::{Request, transport::Channel as TonicChannel}; use tonic::Streaming; +use tonic::{transport::Channel as TonicChannel, Request}; use crate::dapr::dapr::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1}; use crate::error::Error; diff --git a/src/crypto.rs b/src/crypto.rs index 8ebc5c0f..1b608714 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -1,13 +1,13 @@ use futures::StreamExt; -use tonic::{Request, Status}; use tonic::codegen::tokio_stream; +use tonic::{Request, Status}; -use crate::Client; use crate::client::TonicClient; use crate::dapr::dapr::proto::common::v1::StreamPayload; use crate::dapr::dapr::proto::runtime::v1::{ DecryptRequest, DecryptRequestOptions, EncryptRequest, EncryptRequestOptions, }; +use crate::Client; impl Client { pub async fn encrypt( From f4200a39ef6c21c56cb8fe533cdfaf47dc2430ab Mon Sep 17 00:00:00 2001 From: Zachary Edgell Date: Fri, 22 Mar 2024 00:19:33 -0400 Subject: [PATCH 04/14] Updated validate-examples.yml to test crypto examples Signed-off-by: Zachary Edgell --- .github/workflows/validate-examples.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate-examples.yml b/.github/workflows/validate-examples.yml index 0f796372..8a9932f4 100644 --- a/.github/workflows/validate-examples.yml +++ b/.github/workflows/validate-examples.yml @@ -22,7 +22,7 @@ on: required: false default: "" repository_dispatch: - types: [validate-examples] + types: [ validate-examples ] merge_group: jobs: setup: @@ -144,7 +144,7 @@ jobs: fail-fast: false matrix: examples: - ["actors", "client", "configuration", "invoke/grpc", "invoke/grpc-proxying", "pubsub", "secrets-bulk"] + [ "actors", "client", "configuration", "invoke/grpc", "invoke/grpc-proxying", "pubsub", "secrets-bulk", "crypto" ] steps: - name: Check out code uses: actions/checkout@v4 From 4dfb399e2558b95914054c163578c1ecdfcc7327 Mon Sep 17 00:00:00 2001 From: Zachary Edgell Date: Sat, 23 Mar 2024 00:06:08 -0400 Subject: [PATCH 05/14] Moved to client.rs and added docs. Signed-off-by: Zachary Edgell --- examples/crypto/README.md | 3 + src/client.rs | 122 +++++++++++++++++++++++++++++++++++++- src/crypto.rs | 78 ------------------------ src/lib.rs | 16 +++-- 4 files changed, 130 insertions(+), 89 deletions(-) delete mode 100644 src/crypto.rs diff --git a/examples/crypto/README.md b/examples/crypto/README.md index 08507caa..1072d409 100644 --- a/examples/crypto/README.md +++ b/examples/crypto/README.md @@ -32,6 +32,9 @@ timeout_seconds: 90 --> ```bash +mkdir -p keys +openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out keys/rsa-private-key.pem +openssl rand -out keys/symmetric-key-256 32 dapr run -f . ``` diff --git a/src/client.rs b/src/client.rs index 014c23e0..216bc254 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,12 +1,18 @@ use std::collections::HashMap; use async_trait::async_trait; +use futures::StreamExt; use prost_types::Any; use serde::{Deserialize, Serialize}; -use tonic::Streaming; -use tonic::{transport::Channel as TonicChannel, Request}; +use tonic::{Request, transport::Channel as TonicChannel}; +use tonic::{Status, Streaming}; +use tonic::codegen::tokio_stream; use crate::dapr::dapr::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1}; +use crate::dapr::dapr::proto::common::v1::StreamPayload; +use crate::dapr::dapr::proto::runtime::v1::{ + DecryptRequest, DecryptRequestOptions, EncryptRequest, EncryptRequestOptions, +}; use crate::error::Error; #[derive(Clone)] @@ -627,3 +633,115 @@ where } } } + +impl Client { + /// Encrypt binary data using Dapr. returns Vec to be used in decrypt method + /// + /// # Arguments + /// + /// * `payload` - A Reference to the data to encrypt, should impl Into> + /// * `request_option` - Encryption request options. + /// + /// # Example + /// ``` + /// let encrypted = client + /// .encrypt( + /// &"Test".to_string(), + /// EncryptRequestOptions { + /// component_name: "localstorage".to_string(), + /// key_name: "rsa-private-key.pem".to_string(), + /// key_wrap_algorithm: "RSA".to_string(), + /// data_encryption_cipher: "aes-gcm".to_string(), + /// omit_decryption_key_name: false, + /// decryption_key_name: "rsa-private-key.pem".to_string(), + /// }, + /// ) + /// .await + /// .unwrap(); + /// ``` + pub async fn encrypt( + &mut self, + payload: &T, + request_options: EncryptRequestOptions, + ) -> Result, Status> + where + T: Into> + Clone, + { + let stream_payload = StreamPayload { + data: payload.clone().into(), + seq: 0, + }; + let request = EncryptRequest { + options: Some(request_options), + payload: Some(stream_payload), + }; + let request = Request::new(tokio_stream::iter([request])); + let stream = self.0.encrypt_alpha1(request).await?; + let mut stream = stream.into_inner(); + let mut return_data = vec![]; + while let Some(resp) = stream.next().await { + if let Ok(resp) = resp { + if let Some(data) = resp.payload { + return_data.push(data) + } + } + } + Ok(return_data) + } + + /// Decrypt binary data using Dapr. returns Vec. + /// + /// # Arguments + /// + /// * `encrypted` - Encrypted data usually returned from encrypted, Vec + /// * `options` - Decryption request options. + /// + /// # Example + /// ``` + /// let decrypted = client + /// .decrypt( + /// encrypted, + /// DecryptRequestOptions { + /// component_name: "localstorage".to_string(), + /// key_name: "rsa-private-key.pem".to_string(), + /// }, + /// ) + /// .await + /// .unwrap(); + /// ``` + pub async fn decrypt( + &mut self, + encrypted: Vec, + options: DecryptRequestOptions, + ) -> Result, Status> { + let requested_items: Vec = encrypted + .iter() + .enumerate() + .map(|(i, item)| { + if i == 0 { + DecryptRequest { + options: Some(options.clone()), + payload: Some(item.clone()), + } + } else { + DecryptRequest { + options: None, + payload: Some(item.clone()), + } + } + }) + .collect(); + let request = Request::new(tokio_stream::iter(requested_items)); + let stream = self.0.decrypt_alpha1(request).await?; + let mut stream = stream.into_inner(); + let mut data = vec![]; + while let Some(resp) = stream.next().await { + if let Ok(resp) = resp { + if let Some(mut payload) = resp.payload { + data.append(payload.data.as_mut()) + } + } + } + Ok(data) + } +} diff --git a/src/crypto.rs b/src/crypto.rs deleted file mode 100644 index 1b608714..00000000 --- a/src/crypto.rs +++ /dev/null @@ -1,78 +0,0 @@ -use futures::StreamExt; -use tonic::codegen::tokio_stream; -use tonic::{Request, Status}; - -use crate::client::TonicClient; -use crate::dapr::dapr::proto::common::v1::StreamPayload; -use crate::dapr::dapr::proto::runtime::v1::{ - DecryptRequest, DecryptRequestOptions, EncryptRequest, EncryptRequestOptions, -}; -use crate::Client; - -impl Client { - pub async fn encrypt( - &mut self, - payload: &T, - request_options: EncryptRequestOptions, - ) -> Result, Status> - where - T: Into> + Clone, - { - let stream_payload = StreamPayload { - data: payload.clone().into(), - seq: 0, - }; - let request = EncryptRequest { - options: Some(request_options), - payload: Some(stream_payload), - }; - let request = Request::new(tokio_stream::iter([request])); - let stream = self.0.encrypt_alpha1(request).await?; - let mut stream = stream.into_inner(); - let mut return_data = vec![]; - while let Some(resp) = stream.next().await { - if let Ok(resp) = resp { - if let Some(data) = resp.payload { - return_data.push(data) - } - } - } - Ok(return_data) - } - - pub async fn decrypt( - &mut self, - encrypted: Vec, - options: DecryptRequestOptions, - ) -> Result, Status> { - let requested_items: Vec = encrypted - .iter() - .enumerate() - .map(|(i, item)| { - if i == 0 { - DecryptRequest { - options: Some(options.clone()), - payload: Some(item.clone()), - } - } else { - DecryptRequest { - options: None, - payload: Some(item.clone()), - } - } - }) - .collect(); - let request = Request::new(tokio_stream::iter(requested_items)); - let stream = self.0.decrypt_alpha1(request).await?; - let mut stream = stream.into_inner(); - let mut data = vec![]; - while let Some(resp) = stream.next().await { - if let Ok(resp) = resp { - if let Some(mut payload) = resp.payload { - data.append(payload.data.as_mut()) - } - } - } - Ok(data) - } -} diff --git a/src/lib.rs b/src/lib.rs index cdf87e01..72f881be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,15 +1,13 @@ -pub mod appcallback; -pub mod client; -pub mod crypto; -pub mod dapr; -pub mod error; -pub mod server; +extern crate dapr_macros; +pub use dapr_macros::actor; pub use serde; - pub use serde_json; pub use client::Client; -extern crate dapr_macros; -pub use dapr_macros::actor; +pub mod appcallback; +pub mod client; +pub mod dapr; +pub mod error; +pub mod server; From e3bbf921ac22d2c5374dd73e62710592a1745bc6 Mon Sep 17 00:00:00 2001 From: Mike Nguyen Date: Sun, 24 Mar 2024 12:01:44 +0000 Subject: [PATCH 06/14] fix: update crypto example Signed-off-by: Mike Nguyen --- examples/crypto/README.md | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/examples/crypto/README.md b/examples/crypto/README.md index 1072d409..7b00a5cd 100644 --- a/examples/crypto/README.md +++ b/examples/crypto/README.md @@ -6,21 +6,29 @@ This is a simple example that demonstrates Dapr's Cryptography capabilities. ## Running -> Before you run the example make sure generate keys in examples/crypto/keys directory: -> ``` -> mkdir -p keys -> # Generate a private RSA key, 4096-bit keys -> openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out keys/rsa-private-key.pem -> # Generate a 256-bit key for AES -> openssl rand -out keys/symmetric-key-256 32 -> ``` - To run this example: -1. Run the multi-app run template: +1. Generate keys in examples/crypto/keys directory: + +```bash +mkdir -p keys +# Generate a private RSA key, 4096-bit keys +openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out keys/rsa-private-key.pem +# Generate a 256-bit key for AES +openssl rand -out keys/symmetric-key-256 32 +``` + + + +2. Run the multi-app run template: ```bash -mkdir -p keys -openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out keys/rsa-private-key.pem -openssl rand -out keys/symmetric-key-256 32 dapr run -f . ``` From b9fe7649b814bd594252e7ebeb745b2d610d35c7 Mon Sep 17 00:00:00 2001 From: Mike Nguyen Date: Sun, 24 Mar 2024 12:02:28 +0000 Subject: [PATCH 07/14] chore: re-order examples Signed-off-by: Mike Nguyen --- .github/workflows/validate-examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-examples.yml b/.github/workflows/validate-examples.yml index 8a9932f4..e6e461ff 100644 --- a/.github/workflows/validate-examples.yml +++ b/.github/workflows/validate-examples.yml @@ -144,7 +144,7 @@ jobs: fail-fast: false matrix: examples: - [ "actors", "client", "configuration", "invoke/grpc", "invoke/grpc-proxying", "pubsub", "secrets-bulk", "crypto" ] + [ "actors", "client", "configuration", "crypto", "invoke/grpc", "invoke/grpc-proxying", "pubsub", "secrets-bulk" ] steps: - name: Check out code uses: actions/checkout@v4 From 52d853bddef26fa0cc7e4133f28b486059adeec9 Mon Sep 17 00:00:00 2001 From: Mike Nguyen Date: Sun, 24 Mar 2024 12:03:13 +0000 Subject: [PATCH 08/14] chore: re-order examples Signed-off-by: Mike Nguyen --- Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fd3c1812..56c287a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,13 +45,17 @@ path = "examples/actors/client.rs" name = "actor-server" path = "examples/actors/server.rs" +[[example]] +name = "client" +path = "examples/client/client.rs" + [[example]] name = "configuration" path = "examples/configuration/main.rs" [[example]] -name = "client" -path = "examples/client/client.rs" +name = "crypto" +path = "examples/crypto/main.rs" [[example]] name = "invoke-grpc-client" @@ -80,7 +84,3 @@ path = "examples/pubsub/subscriber.rs" [[example]] name = "secrets-bulk" path = "examples/secrets-bulk/app.rs" - -[[example]] -name = "crypto" -path = "examples/crypto/main.rs" From 7e98f9b63057e1054abe15adb99e2e4eeead44ef Mon Sep 17 00:00:00 2001 From: Zachary Edgell Date: Sun, 24 Mar 2024 21:17:43 -0400 Subject: [PATCH 09/14] Update to use tokio ReaderStream Signed-off-by: Zachary Edgell --- .github/workflows/validate-examples.yml | 2 +- Cargo.toml | 1 + examples/crypto/README.md | 22 +- examples/crypto/main.rs | 10 +- src/client.rs | 258 +++++++++++++----------- 5 files changed, 170 insertions(+), 123 deletions(-) diff --git a/.github/workflows/validate-examples.yml b/.github/workflows/validate-examples.yml index 8a9932f4..e6e461ff 100644 --- a/.github/workflows/validate-examples.yml +++ b/.github/workflows/validate-examples.yml @@ -144,7 +144,7 @@ jobs: fail-fast: false matrix: examples: - [ "actors", "client", "configuration", "invoke/grpc", "invoke/grpc-proxying", "pubsub", "secrets-bulk", "crypto" ] + [ "actors", "client", "configuration", "crypto", "invoke/grpc", "invoke/grpc-proxying", "pubsub", "secrets-bulk" ] steps: - name: Check out code uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index fd3c1812..cb00988d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" axum = "0.7.4" tokio = { version = "1.29", features = ["sync"] } +tokio-util = { version = "0.7.10", features = ["io"] } chrono = "0.4.24" [build-dependencies] diff --git a/examples/crypto/README.md b/examples/crypto/README.md index 1072d409..49030b2e 100644 --- a/examples/crypto/README.md +++ b/examples/crypto/README.md @@ -20,12 +20,9 @@ To run this example: 1. Run the multi-app run template: + + + +```bash dapr run -f . ``` diff --git a/examples/crypto/main.rs b/examples/crypto/main.rs index 7f8879cf..9f08e8d1 100644 --- a/examples/crypto/main.rs +++ b/examples/crypto/main.rs @@ -1,7 +1,9 @@ use std::fs; +use tokio::fs::File; use tokio::time::sleep; +use dapr::client::ReaderStream; use dapr::dapr::dapr::proto::runtime::v1::{DecryptRequestOptions, EncryptRequestOptions}; #[tokio::main] @@ -14,7 +16,7 @@ async fn main() -> Result<(), Box> { let encrypted = client .encrypt( - &"Test".to_string(), + ReaderStream::new("Test".as_bytes()), EncryptRequestOptions { component_name: "localstorage".to_string(), key_name: "rsa-private-key.pem".to_string(), @@ -42,11 +44,11 @@ async fn main() -> Result<(), Box> { println!("Successfully Decrypted String"); - let image = fs::read("./image.png").unwrap(); + let image = File::open("./image.png").await.unwrap(); let encrypted = client .encrypt( - &image, + ReaderStream::new(image), EncryptRequestOptions { component_name: "localstorage".to_string(), key_name: "rsa-private-key.pem".to_string(), @@ -70,6 +72,8 @@ async fn main() -> Result<(), Box> { .await .unwrap(); + let image = fs::read("./image.png").unwrap(); + assert_eq!(decrypted, image); println!("Successfully Decrypted Image"); diff --git a/src/client.rs b/src/client.rs index 216bc254..587ee67e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -4,19 +4,16 @@ use async_trait::async_trait; use futures::StreamExt; use prost_types::Any; use serde::{Deserialize, Serialize}; -use tonic::{Request, transport::Channel as TonicChannel}; -use tonic::{Status, Streaming}; +use tokio::io::AsyncRead; use tonic::codegen::tokio_stream; +use tonic::{transport::Channel as TonicChannel, Request}; +use tonic::{Status, Streaming}; use crate::dapr::dapr::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1}; -use crate::dapr::dapr::proto::common::v1::StreamPayload; -use crate::dapr::dapr::proto::runtime::v1::{ - DecryptRequest, DecryptRequestOptions, EncryptRequest, EncryptRequestOptions, -}; use crate::error::Error; #[derive(Clone)] -pub struct Client(pub(crate) T); +pub struct Client(T); impl Client { /// Connect to a Dapr enabled app. @@ -386,6 +383,78 @@ impl Client { }; self.0.unsubscribe_configuration(request).await } + + /// Encrypt binary data using Dapr. returns Vec to be used in decrypt method + /// + /// # Arguments + /// + /// * `payload` - ReaderStream to the data to encrypt + /// * `request_option` - Encryption request options. + pub async fn encrypt( + &mut self, + payload: ReaderStream, + request_options: EncryptRequestOptions, + ) -> Result, Status> + where + R: AsyncRead + Send, + { + // have to have it as a reference for the async move below + let request_options = &Some(request_options); + let requested_items: Vec = payload + .0 + .enumerate() + .fold(vec![], |mut init, (i, bytes)| async move { + let stream_payload = StreamPayload { + data: bytes.unwrap().to_vec(), + seq: 0, + }; + if i == 0 { + init.push(EncryptRequest { + options: request_options.clone(), + payload: Some(stream_payload), + }); + } else { + init.push(EncryptRequest { + options: None, + payload: Some(stream_payload), + }); + } + init + }) + .await; + self.0.encrypt(requested_items).await + } + + /// Decrypt binary data using Dapr. returns Vec. + /// + /// # Arguments + /// + /// * `encrypted` - Encrypted data usually returned from encrypted, Vec + /// * `options` - Decryption request options. + pub async fn decrypt( + &mut self, + encrypted: Vec, + options: DecryptRequestOptions, + ) -> Result, Status> { + let requested_items: Vec = encrypted + .iter() + .enumerate() + .map(|(i, item)| { + if i == 0 { + DecryptRequest { + options: Some(options.clone()), + payload: Some(item.clone()), + } + } else { + DecryptRequest { + options: None, + payload: Some(item.clone()), + } + } + }) + .collect(); + self.0.decrypt(requested_items).await + } } #[async_trait] @@ -427,6 +496,11 @@ pub trait DaprInterface: Sized { &mut self, request: UnsubscribeConfigurationRequest, ) -> Result; + + async fn encrypt(&mut self, payload: Vec) + -> Result, Status>; + + async fn decrypt(&mut self, payload: Vec) -> Result, Status>; } #[async_trait] @@ -542,6 +616,51 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient { .await? .into_inner()) } + + /// Encrypt binary data using Dapr. returns Vec to be used in decrypt method + /// + /// # Arguments + /// + /// * `payload` - ReaderStream to the data to encrypt + /// * `request_option` - Encryption request options. + async fn encrypt( + &mut self, + request: Vec, + ) -> Result, Status> { + let request = Request::new(tokio_stream::iter(request)); + let stream = self.encrypt_alpha1(request).await?; + let mut stream = stream.into_inner(); + let mut return_data = vec![]; + while let Some(resp) = stream.next().await { + if let Ok(resp) = resp { + if let Some(data) = resp.payload { + return_data.push(data) + } + } + } + Ok(return_data) + } + + /// Decrypt binary data using Dapr. returns Vec. + /// + /// # Arguments + /// + /// * `encrypted` - Encrypted data usually returned from encrypted, Vec + /// * `options` - Decryption request options. + async fn decrypt(&mut self, request: Vec) -> Result, Status> { + let request = Request::new(tokio_stream::iter(request)); + let stream = self.decrypt_alpha1(request).await?; + let mut stream = stream.into_inner(); + let mut data = vec![]; + while let Some(resp) = stream.next().await { + if let Ok(resp) = resp { + if let Some(mut payload) = resp.payload { + data.append(payload.data.as_mut()) + } + } + } + Ok(data) + } } /// A request from invoking a service @@ -621,6 +740,19 @@ pub type UnsubscribeConfigurationResponse = dapr_v1::UnsubscribeConfigurationRes /// A tonic based gRPC client pub type TonicClient = dapr_v1::dapr_client::DaprClient; +/// Encryption gRPC request +type EncryptRequest = crate::dapr::dapr::proto::runtime::v1::EncryptRequest; + +/// Decrypt gRPC request +type DecryptRequest = crate::dapr::dapr::proto::runtime::v1::DecryptRequest; + +/// Encryption request options +type EncryptRequestOptions = crate::dapr::dapr::proto::runtime::v1::EncryptRequestOptions; + +/// Decryption request options +type DecryptRequestOptions = crate::dapr::dapr::proto::runtime::v1::DecryptRequestOptions; + +type StreamPayload = crate::dapr::dapr::proto::common::v1::StreamPayload; impl From<(K, Vec)> for common_v1::StateItem where K: Into, @@ -634,114 +766,10 @@ where } } -impl Client { - /// Encrypt binary data using Dapr. returns Vec to be used in decrypt method - /// - /// # Arguments - /// - /// * `payload` - A Reference to the data to encrypt, should impl Into> - /// * `request_option` - Encryption request options. - /// - /// # Example - /// ``` - /// let encrypted = client - /// .encrypt( - /// &"Test".to_string(), - /// EncryptRequestOptions { - /// component_name: "localstorage".to_string(), - /// key_name: "rsa-private-key.pem".to_string(), - /// key_wrap_algorithm: "RSA".to_string(), - /// data_encryption_cipher: "aes-gcm".to_string(), - /// omit_decryption_key_name: false, - /// decryption_key_name: "rsa-private-key.pem".to_string(), - /// }, - /// ) - /// .await - /// .unwrap(); - /// ``` - pub async fn encrypt( - &mut self, - payload: &T, - request_options: EncryptRequestOptions, - ) -> Result, Status> - where - T: Into> + Clone, - { - let stream_payload = StreamPayload { - data: payload.clone().into(), - seq: 0, - }; - let request = EncryptRequest { - options: Some(request_options), - payload: Some(stream_payload), - }; - let request = Request::new(tokio_stream::iter([request])); - let stream = self.0.encrypt_alpha1(request).await?; - let mut stream = stream.into_inner(); - let mut return_data = vec![]; - while let Some(resp) = stream.next().await { - if let Ok(resp) = resp { - if let Some(data) = resp.payload { - return_data.push(data) - } - } - } - Ok(return_data) - } +pub struct ReaderStream(tokio_util::io::ReaderStream); - /// Decrypt binary data using Dapr. returns Vec. - /// - /// # Arguments - /// - /// * `encrypted` - Encrypted data usually returned from encrypted, Vec - /// * `options` - Decryption request options. - /// - /// # Example - /// ``` - /// let decrypted = client - /// .decrypt( - /// encrypted, - /// DecryptRequestOptions { - /// component_name: "localstorage".to_string(), - /// key_name: "rsa-private-key.pem".to_string(), - /// }, - /// ) - /// .await - /// .unwrap(); - /// ``` - pub async fn decrypt( - &mut self, - encrypted: Vec, - options: DecryptRequestOptions, - ) -> Result, Status> { - let requested_items: Vec = encrypted - .iter() - .enumerate() - .map(|(i, item)| { - if i == 0 { - DecryptRequest { - options: Some(options.clone()), - payload: Some(item.clone()), - } - } else { - DecryptRequest { - options: None, - payload: Some(item.clone()), - } - } - }) - .collect(); - let request = Request::new(tokio_stream::iter(requested_items)); - let stream = self.0.decrypt_alpha1(request).await?; - let mut stream = stream.into_inner(); - let mut data = vec![]; - while let Some(resp) = stream.next().await { - if let Ok(resp) = resp { - if let Some(mut payload) = resp.payload { - data.append(payload.data.as_mut()) - } - } - } - Ok(data) +impl ReaderStream { + pub fn new(data: T) -> Self { + ReaderStream(tokio_util::io::ReaderStream::new(data)) } } From 63c3f9442242dd0a242c68ccda37fa8e45ffcc28 Mon Sep 17 00:00:00 2001 From: Zachary K Edgell Date: Mon, 25 Mar 2024 11:48:29 -0400 Subject: [PATCH 10/14] Remove use dapr::dapr::dapr::proto::runtime::v1::{DecryptRequestOptions, EncryptRequestOptions}; Co-authored-by: Mike Nguyen Signed-off-by: Zachary K Edgell --- examples/crypto/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/crypto/main.rs b/examples/crypto/main.rs index 9f08e8d1..d79bf3a4 100644 --- a/examples/crypto/main.rs +++ b/examples/crypto/main.rs @@ -4,7 +4,6 @@ use tokio::fs::File; use tokio::time::sleep; use dapr::client::ReaderStream; -use dapr::dapr::dapr::proto::runtime::v1::{DecryptRequestOptions, EncryptRequestOptions}; #[tokio::main] async fn main() -> Result<(), Box> { From b731100560ea5e5739391c7a804bb117d29e034b Mon Sep 17 00:00:00 2001 From: Zachary K Edgell Date: Mon, 25 Mar 2024 11:48:49 -0400 Subject: [PATCH 11/14] Make types public Co-authored-by: Mike Nguyen Signed-off-by: Zachary K Edgell --- src/client.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client.rs b/src/client.rs index 587ee67e..712280e4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -741,16 +741,16 @@ pub type UnsubscribeConfigurationResponse = dapr_v1::UnsubscribeConfigurationRes pub type TonicClient = dapr_v1::dapr_client::DaprClient; /// Encryption gRPC request -type EncryptRequest = crate::dapr::dapr::proto::runtime::v1::EncryptRequest; +pub type EncryptRequest = crate::dapr::dapr::proto::runtime::v1::EncryptRequest; /// Decrypt gRPC request -type DecryptRequest = crate::dapr::dapr::proto::runtime::v1::DecryptRequest; +pub type DecryptRequest = crate::dapr::dapr::proto::runtime::v1::DecryptRequest; /// Encryption request options -type EncryptRequestOptions = crate::dapr::dapr::proto::runtime::v1::EncryptRequestOptions; +pub type EncryptRequestOptions = crate::dapr::dapr::proto::runtime::v1::EncryptRequestOptions; /// Decryption request options -type DecryptRequestOptions = crate::dapr::dapr::proto::runtime::v1::DecryptRequestOptions; +pub type DecryptRequestOptions = crate::dapr::dapr::proto::runtime::v1::DecryptRequestOptions; type StreamPayload = crate::dapr::dapr::proto::common::v1::StreamPayload; impl From<(K, Vec)> for common_v1::StateItem From fb1d6b3018108014d0df014017a605a6da755d32 Mon Sep 17 00:00:00 2001 From: Zachary K Edgell Date: Mon, 25 Mar 2024 11:49:02 -0400 Subject: [PATCH 12/14] Update examples/crypto/main.rs Co-authored-by: Mike Nguyen Signed-off-by: Zachary K Edgell --- examples/crypto/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/crypto/main.rs b/examples/crypto/main.rs index d79bf3a4..6ff9e0c9 100644 --- a/examples/crypto/main.rs +++ b/examples/crypto/main.rs @@ -16,7 +16,7 @@ async fn main() -> Result<(), Box> { let encrypted = client .encrypt( ReaderStream::new("Test".as_bytes()), - EncryptRequestOptions { + dapr::client::EncryptRequestOptions { component_name: "localstorage".to_string(), key_name: "rsa-private-key.pem".to_string(), key_wrap_algorithm: "RSA".to_string(), @@ -31,7 +31,7 @@ async fn main() -> Result<(), Box> { let decrypted = client .decrypt( encrypted, - DecryptRequestOptions { + dapr::client::DecryptRequestOptions { component_name: "localstorage".to_string(), key_name: "rsa-private-key.pem".to_string(), }, From 034da1d5cc624e83fe18fee311194d11d7565fac Mon Sep 17 00:00:00 2001 From: Zachary K Edgell Date: Mon, 25 Mar 2024 13:59:38 -0400 Subject: [PATCH 13/14] Update main.rs Co-authored-by: Mike Nguyen Signed-off-by: Zachary K Edgell --- examples/crypto/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/crypto/main.rs b/examples/crypto/main.rs index 6ff9e0c9..9b2d5fd1 100644 --- a/examples/crypto/main.rs +++ b/examples/crypto/main.rs @@ -48,7 +48,7 @@ async fn main() -> Result<(), Box> { let encrypted = client .encrypt( ReaderStream::new(image), - EncryptRequestOptions { + dapr::client::EncryptRequestOptions { component_name: "localstorage".to_string(), key_name: "rsa-private-key.pem".to_string(), key_wrap_algorithm: "RSA".to_string(), From 02dd85084bce1d31f503dc03b343a6509e3ba8ba Mon Sep 17 00:00:00 2001 From: Zachary K Edgell Date: Mon, 25 Mar 2024 13:59:42 -0400 Subject: [PATCH 14/14] Update main.rs Co-authored-by: Mike Nguyen Signed-off-by: Zachary K Edgell --- examples/crypto/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/crypto/main.rs b/examples/crypto/main.rs index 9b2d5fd1..8dab74cc 100644 --- a/examples/crypto/main.rs +++ b/examples/crypto/main.rs @@ -63,7 +63,7 @@ async fn main() -> Result<(), Box> { let decrypted = client .decrypt( encrypted, - DecryptRequestOptions { + dapr::client::DecryptRequestOptions { component_name: "localstorage".to_string(), key_name: "rsa-private-key.pem".to_string(), },