Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Crypto] Implement support for high-level crypto APIs #387

Merged
merged 10 commits into from May 26, 2023

Conversation

ItalyPaleAle
Copy link
Contributor

@ItalyPaleAle ItalyPaleAle commented Apr 5, 2023

This implements support for the high-level crypto APIs implemented here: dapr/dapr#6197

These allow encrypting and decrypting files of arbitrary length (up to 256TB :) ), while working on a stream of data.

The gRPC APIs are quite complex as they require data to be chunked, but the SDK takes care of all that complexity and offers a simple API with Encrypt and Decrypt. Both accept a readable stream as input (io.Reader) and return a readable stream (io.Reader) that receives the processed data.

Example usage. This reads a file and encrypts it, storing the result in another file:

// Input file, clear-text
rf, err := os.Open("input")
if err != nil {
	panic(err)
}
defer rf.Close()

// Output file, encrypted
wf, err := os.Create("output.enc")
if err != nil {
	panic(err)
}
defer wf.Close()

// Encrypt the data using Dapr
out, err := sdkClient.Encrypt(context.Background(), rf, dapr.EncryptOptions{
	// These are the 3 required parameters
	ComponentName: "mycryptocomponent",
	KeyName:        "mykey",
	Algorithm:     "RSA",
})
if err != nil {
	panic(err)
}

// Read the stream and copy it to the out file
n, err := io.Copy(wf, out)
if err != nil {
	panic(err)
}
fmt.Println("Written", n, "bytes")

Decrypting works very similarly:

out, err := sdkClient.Decrypt(context.Background(), rf, dapr.EncryptOptions{
	// Only required option is the component name
	ComponentName: "mycryptocomponent",
})

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Apr 5, 2023

Codecov Report

Merging #387 (54d4130) into main (b14253b) will increase coverage by 0.88%.
The diff coverage is 83.75%.

@@            Coverage Diff             @@
##             main     #387      +/-   ##
==========================================
+ Coverage   69.08%   69.97%   +0.88%     
==========================================
  Files          31       33       +2     
  Lines        2491     2651     +160     
==========================================
+ Hits         1721     1855     +134     
- Misses        676      695      +19     
- Partials       94      101       +7     
Impacted Files Coverage Δ
client/client.go 69.74% <ø> (ø)
client/crypto.go 83.11% <83.11%> (ø)
client/bufpool.go 100.00% <100.00%> (ø)

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Makefile Show resolved Hide resolved
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@yaron2
Copy link
Member

yaron2 commented May 25, 2023

@daixiang0 can you please review this?

client/bufpool.go Outdated Show resolved Hide resolved
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@yaron2 yaron2 merged commit 92c23df into dapr:main May 26, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants