You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update the public API to remove footguns, and document it.
This is a significant refactor of the public API of the crate, simplifying
the API surface and removing some of the footgun potential noted by Martin
in his review at mozilla/application-services#1068.
In particular:
* The public `encrypt` functions no longer take a `salt` parameter. The
right thing to do is to generate a new random `salt` for each encryption
so we just do that for you automatically.
* Many internal implementation details are now `pub(crate)` rather than `pub`,
to avoid potential confusion from consumers.
* We refuse to encrypt or decrypt across multiple records, because our only
consumer in practice is webpush, and webpush restricts consumers to using
only a single record.
We still have the code lying around to encrypt/decrypt across record
boundaries, but we don't have high confidence that it works correctly
and intend to remove it in a future commit. So, may as well adjust the
interface to reflect that while we're in here making breaking changes.
To go along with the revised interface, this commit also significantly
expands to docs in order to help set consumer expectations and context.
[ece](https://crates.io/crates/ece) is a Rust implementation of the HTTP Encrypted Content-Encoding standard (RFC 8188). It is a port of the [ecec](https://github.com/web-push-libs/ecec) C library.
11
-
This crate is destined to be used by higher-level Web Push libraries, both on the server and the client side.
11
+
The [ece](https://crates.io/crates/ece) crate is a Rust implementation of Message Encryption for Web Push
12
+
([RFC8291](https://tools.ietf.org/html/rfc8291)) and the HTTP Encrypted Content-Encoding scheme
13
+
([RFC8188](https://tools.ietf.org/html/rfc8188)) on which it is based.
12
14
13
-
[Documentation](https://docs.rs/ece/)
15
+
It provides low-level cryptographic "plumbing" and is destined to be used by higher-level Web Push libraries, both on
16
+
the server and the client side. It is a port of the [ecec](https://github.com/web-push-libs/ecec) C library.
14
17
15
-
## Cryptographic backends
16
-
17
-
This crate is designed to be used with different crypto backends. At the moment only [openssl](https://github.com/sfackler/rust-openssl) is supported.
18
+
[Full Documentation](https://docs.rs/ece/)
18
19
19
20
## Implemented schemes
20
21
21
-
Currently, two HTTP ece schemes are available to consumers of the crate:
22
-
- The newer [RFC8188](https://tools.ietf.org/html/rfc8188)`aes128gcm` standard.
23
-
- The legacy [draft-03](https://tools.ietf.org/html/draft-ietf-httpbis-encryption-encoding-03)`aesgcm` scheme.
22
+
This crate implements both the published Web Push Encryption scheme, and a legacy scheme from earlier drafts
23
+
that is still widely used in the wild:
24
+
25
+
*`aes128gcm`: the scheme described in [RFC8291](https://tools.ietf.org/html/rfc8291) and
26
+
[RFC8188](https://tools.ietf.org/html/rfc8188)
27
+
*`aesgcm`: the draft scheme described in
28
+
[draft-ietf-webpush-encryption-04](https://tools.ietf.org/html/draft-ietf-webpush-encryption-04) and
/// Web Push encryption structure for the AES128GCM encoding scheme ([RFC8591](https://tools.ietf.org/html/rfc8291))
30
30
///
31
31
/// This structure is meant for advanced use. For simple encryption/decryption, use the top-level [`encrypt`](crate::encrypt) and [`decrypt`](crate::decrypt) functions.
32
-
pubstructAes128GcmEceWebPush;
32
+
pub(crate)structAes128GcmEceWebPush;
33
33
implAes128GcmEceWebPush{
34
-
/// Encrypts a Web Push message using the "aes128gcm" scheme. This function
35
-
/// automatically generates an ephemeral ECDH key pair.
36
-
pubfnencrypt(
37
-
remote_pub_key:&dynRemotePublicKey,
38
-
auth_secret:&[u8],
39
-
plaintext:&[u8],
40
-
params:WebPushParams,
41
-
) -> Result<Vec<u8>>{
42
-
let cryptographer = crypto::holder::get_cryptographer();
43
-
let local_prv_key = cryptographer.generate_ephemeral_keypair()?;
44
-
Self::encrypt_with_keys(
45
-
&*local_prv_key,
46
-
remote_pub_key,
47
-
auth_secret,
48
-
plaintext,
49
-
params,
50
-
)
51
-
}
52
-
53
34
/// Encrypts a Web Push message using the "aes128gcm" scheme, with an explicit
/// This structure is meant for advanced use. For simple encryption/decryption, use the top-level [`encrypt_aesgcm`](crate::legacy::encrypt_aesgcm) and [`decrypt_aesgcm`](crate::legacy::decrypt_aesgcm) functions.
98
-
pubstructAesGcmEceWebPush;
99
-
implAesGcmEceWebPush{
100
-
/// Encrypts a Web Push message using the "aesgcm" scheme. This function
101
-
/// automatically generates an ephemeral ECDH key pair.
102
-
pubfnencrypt(
103
-
remote_pub_key:&dynRemotePublicKey,
104
-
auth_secret:&[u8],
105
-
plaintext:&[u8],
106
-
params:WebPushParams,
107
-
) -> Result<AesGcmEncryptedBlock>{
108
-
let cryptographer = crypto::holder::get_cryptographer();
109
-
let local_prv_key = cryptographer.generate_ephemeral_keypair()?;
110
-
Self::encrypt_with_keys(
111
-
&*local_prv_key,
112
-
remote_pub_key,
113
-
auth_secret,
114
-
plaintext,
115
-
params,
116
-
)
117
-
}
97
+
/// This structure is meant for advanced use. For simple encryption/decryption, use the top-level
98
+
/// [`encrypt_aesgcm`](crate::legacy::encrypt_aesgcm) and [`decrypt_aesgcm`](crate::legacy::decrypt_aesgcm)
99
+
/// functions.
100
+
pub(crate)structAesGcmEceWebPush;
118
101
102
+
implAesGcmEceWebPush{
119
103
/// Encrypts a Web Push message using the "aesgcm" scheme, with an explicit
120
104
/// sender key. The sender key can be reused.
121
105
pubfnencrypt_with_keys(
@@ -201,7 +185,7 @@ impl EceWebPush for AesGcmEceWebPush {
201
185
Ok(&block[(2 + padding_size)..])
202
186
}
203
187
204
-
/// Derives the "aesgcm" decryption keyn and nonce given the receiver private
188
+
/// Derives the "aesgcm" decryption key and nonce given the receiver private
205
189
/// key, sender public key, authentication secret, and sender salt.
0 commit comments