Skip to content

Commit 28e3dc3

Browse files
authored
Added HTTP APIs for high-level crypto
1 parent c8f3987 commit 28e3dc3

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

0002-RCBS-Crypto-building-block.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The new building block will feature 7 low-level APIs:
5454

5555
The high-level APIs at launch will only include support for **encrypting** and **decrypting** messages (of arbitrary length), using the [Dapr encryption scheme](#dapr-encryption-scheme-daprioencv1).
5656

57-
These APIs will only be available over gRPC, because they will work over a stream of data from the client. An HTTP implementation would require keeping the entire message in-memory, which is not acceptable (messages could be multiple GBs in size).
57+
Although these APIs will be available over both gRPC and HTTP, the gRPC implementation is **strongly** preferred, since it allows encrypting/decrypting data as a stream. The HTTP implementation requires keeping the entire message in memory, both as plaintext and ciphertext (a limitation in the HTTP protocol itself we cannot work around), which is not desirable unless users are encrypting very small files.
5858

5959
### Components
6060

@@ -658,9 +658,11 @@ The `Encrypt` and `Decrypt` methods are stream-based. Dapr will read from the cl
658658

659659
## HTTP APIs
660660

661-
The HTTP APIs are developed in a way that is the exact "port" of the gRPC "subtle" APIs, and the contents of the request and response bodies match exactly the fields in the gRPC APIs (except for the component name).
661+
### Low-level
662662

663-
Methods are:
663+
The low-level HTTP APIs are developed in a way that is the exact "port" of the gRPC "subtle" APIs, and the contents of the request and response bodies match exactly the fields in the gRPC APIs (except for the component name in the URL).
664+
665+
List of HTTP endpoints and the corresponding gRPC method:
664666

665667
- `POST /v1.0/subtlecrypto/[component]/getkey` -> SubtleGetKey
666668
- `POST /v1.0/subtlecrypto/[component]/encrypt` -> SubtleEncrypt
@@ -672,4 +674,28 @@ Methods are:
672674

673675
> Note: URL will begin with `/v1.0-alpha1` while in preview
674676
675-
**Currently, higher-level APIs are not offered via HTTP**. This is because it's not possible, using HTTP, to have a stream where Dapr sends back data to the client before the client's request is complete. Without that, we'd have to buffer the entire data in-memory in the runtime, which would be not practical when encrypting very large files.
677+
> These APIs are implemented as "Universal" APIs in Dapr, where the business logic is implemented in gRPC only, and the APIs are then exposed as HTTP using the Universal API wrapper.
678+
679+
### High-level
680+
681+
For high-level APIs, we cannot use Universal APIs because we cannot perform bi-directional streaming with HTTP.
682+
683+
As mentioned earlier, using HTTP for the high-level APIs is **highly inefficient** and users will be strongly advised against doing that outside of development or testing scenarios. In fact, while the Dapr encryption scheme is designed for streaming, that is not possible when using HTTP: first, the Dapr sidecar needs to receive the entire message (e.g. plaintext while encrypting), and only after that can begin responding to the caller; this means the Dapr sidecar needs to keep the entire message in-memory.
684+
685+
List of high-level HTTP endpoints:
686+
687+
- `PUT /v1.0/crypto/[component]/encrypt`
688+
- Query-string arguments:
689+
- `key` (required): name–or name/version (URL-encoded)–of the key
690+
- `algorithm` (optional): `aes-gcm` (default) or `chacha20-poly1305`
691+
- Body: the plain-text message to encrypt (in "raw format", e.g. not using multipart/form-data)
692+
- Response: the ciphertext (in "raw format")
693+
- `PUT /v1.0/crypto/[component]/decrypt`
694+
- Query-string arguments:
695+
- `key` (required): name–or name/version (URL-encoded)–of the key
696+
- Body: the ciphertext to decrypt (in "raw format", e.g. not using multipart/form-data)
697+
- Response: the plain-text message (in "raw format")
698+
699+
> Note: URL will begin with `/v1.0-alpha1` while in preview
700+
701+
> Note: the body is limited by Dapr's ["http-max-request-size" option](https://docs.dapr.io/operations/configuration/increase-request-size/).

0 commit comments

Comments
 (0)