Skip to content

Commit 958b871

Browse files
authored
CDRIVER-4317 Add support for rewrapManyDataKey and keyMaterial (#991)
* Move existing CSE tests into legacy subdirectory * Add client_side_encryption/unified to unified test suite * Add ClientEncryption.createKey() * Add unified test support for ClientEncryption.createKey() * Add const to parameters of result_from_*() functions * Refactor and export result_from_bulk_write() helper in result.c * Implement mongoc_client_encryption_rewrap_many_datakey() * Add unified tests support for rewrapManyDataKey tests * Add support for custom key material in dataKeyOpts * Add test runner support for custom key material * Add unified tests for createKey() * Update skip-tests.txt with new paths to legacy subdirectory * Add prose test for custom key material * Number CSE prose tests * Add documentation for mongoc_client_encryption_create_key * Add documentation for mongoc_client_encryption_datakey_opts_set_keymaterial * Add documentation for mongoc_client_encryption_rewrap_many_datakey
1 parent dddadc1 commit 958b871

File tree

72 files changed

+3047
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3047
-83
lines changed

.evergreen/skip-tests.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
/transactions/legacy/mongos-recovery-token/"commitTransaction retry fails on new mongos" # fails with server selection timeout (CDRIVER-4268)
7777
/crud/unified/aggregate-out-readConcern/"readConcern available with out stage" # server error on sharded: "PlanExecutor error" (CDRIVER-4161)
78-
/client_side_encryption/azureKMS/"Insert a document with auto encryption using Azure KMS provider" # failing on RHEL 7.0 / RHEL 7.1 (CDRIVER-3814)
78+
/client_side_encryption/legacy/azureKMS/"Insert a document with auto encryption using Azure KMS provider" # failing on RHEL 7.0 / RHEL 7.1 (CDRIVER-3814)
7979
/transactions/legacy/pin-mongos/"unpin after transient error within a transaction and commit" # (CDRIVER-4351) server selection timeout (on ASAN Tests Ubuntu 18.04 build variant)
8080
/Samples # (CDRIVER-4352) strange "heartbeat failed" error
8181
/server_discovery_and_monitoring/monitoring/heartbeat/pooled/dns # (CDRIVER-4353) this initially seemed like a zSeries w/ RHEL8 issue, but it also appeared on arm64 w/ Ubuntu 18.04
@@ -86,5 +86,5 @@
8686
/sessions/unified/snapshot-sessions/"countDocuments operation with snapshot" # (CDRIVER-4355) error: checking expectResult: { "$numberInt" : "2" }
8787
/load_balancers/non-lb-connection-establishment/"operations against non-load balanced clusters fail if URI contains loadBalanced=true" # (CDRIVER-4356) error: expected error to contain "Driver attempted to initialize in load balancing mode, but the server does not support this mode", but got: "BSON field 'hello.loadBalanced' is an unknown field."
8888

89-
/client_side_encryption/explain # Failure with diverging behavior between csfle and mongocryptd
89+
/client_side_encryption/legacy/explain # Failure with diverging behavior between csfle and mongocryptd
9090
/client_side_encryption/bypass_spawning_mongocryptd/mongocryptdBypassSpawn # Fails if csfle is visible

src/libmongoc/doc/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ API Reference
1515
mongoc_change_stream_t
1616
mongoc_client_encryption_t
1717
mongoc_client_encryption_datakey_opts_t
18+
mongoc_client_encryption_rewrap_many_datakey_result_t
1819
mongoc_client_encryption_encrypt_opts_t
1920
mongoc_client_encryption_opts_t
2021
mongoc_client_pool_t

src/libmongoc/doc/mongoc_client_encryption_create_datakey.rst

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,8 @@ Synopsis
1616
bson_value_t *keyid,
1717
bson_error_t *error);
1818
19-
Creates a new key document in the key vault collection and sets ``keyid`` to the UUID of the
20-
newly created key if ``keyid`` is not NULL. The new key can be used to configure automatic encryption (see :symbol:`mongoc_client_enable_auto_encryption()` and :symbol:`mongoc_client_pool_enable_auto_encryption()`) or for explicit encryption (see :symbol:`mongoc_client_encryption_encrypt()`).
21-
22-
The created key document is inserted into the key vault collection (identified via :symbol:`mongoc_client_encryption_opts_set_keyvault_namespace()`) with majority write concern.
23-
24-
``keyid`` is always initialized (even on error). Caller must call :symbol:`bson_value_destroy()` on ``keyid`` to free.
25-
26-
Parameters
27-
----------
28-
29-
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
30-
* ``kms_provider``: A string identifying the Key Management Service (KMS) provider used to encrypt the datakey (e.g. "aws" or "local").
31-
* ``opts``: A :symbol:`mongoc_client_encryption_datakey_opts_t`
32-
* ``keyid``: The resulting UUID key ID of the newly created key.
33-
* ``error``: A :symbol:`bson_error_t`
34-
35-
Returns
36-
-------
37-
38-
Returns ``true`` if successful. Returns ``false`` and sets ``error`` otherwise.
19+
Alias function equivalent to :symbol:`mongoc_client_encryption_create_key`.
3920

4021
.. seealso::
4122

4223
| :symbol:`mongoc_client_encryption_datakey_opts_t`
43-
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
:man_page: mongoc_client_encryption_create_key
2+
3+
mongoc_client_encryption_create_key()
4+
=====================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_client_encryption_create_key (
13+
mongoc_client_encryption_t *client_encryption,
14+
const char *kms_provider,
15+
mongoc_client_encryption_datakey_opts_t *opts,
16+
bson_value_t *keyid,
17+
bson_error_t *error);
18+
19+
Creates a new key document in the key vault collection and sets ``keyid`` to the UUID of the
20+
newly created key if ``keyid`` is not NULL. The new key can be used to configure automatic encryption (see :symbol:`mongoc_client_enable_auto_encryption()` and :symbol:`mongoc_client_pool_enable_auto_encryption()`) or for explicit encryption (see :symbol:`mongoc_client_encryption_encrypt()`).
21+
22+
The created key document is inserted into the key vault collection (identified via :symbol:`mongoc_client_encryption_opts_set_keyvault_namespace()`) with majority write concern.
23+
24+
``keyid`` is always initialized (even on error). Caller must call :symbol:`bson_value_destroy()` on ``keyid`` to free.
25+
26+
Parameters
27+
----------
28+
29+
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
30+
* ``kms_provider``: A string identifying the Key Management Service (KMS) provider used to encrypt the datakey (e.g. "aws" or "local").
31+
* ``opts``: A :symbol:`mongoc_client_encryption_datakey_opts_t`
32+
* ``keyid``: The resulting UUID key ID of the newly created key.
33+
* ``error``: A :symbol:`bson_error_t`
34+
35+
Returns
36+
-------
37+
38+
Returns ``true`` if successful. Returns ``false`` and sets ``error`` otherwise.
39+
40+
.. seealso::
41+
42+
| :symbol:`mongoc_client_encryption_datakey_opts_t`
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
:man_page: mongoc_client_encryption_datakey_opts_set_keymaterial
2+
3+
mongoc_client_encryption_datakey_opts_set_keymaterial()
4+
=======================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void
12+
mongoc_client_encryption_datakey_opts_set_keymaterial (
13+
mongoc_client_encryption_datakey_opts_t *opts,
14+
const uint8_t *data,
15+
uint32_t len);
16+
17+
Sets the custom key material to be used by the data key for encryption and decryption.
18+
19+
Parameters
20+
----------
21+
22+
* ``opts``: A :symbol:`mongoc_client_encryption_datakey_opts_t`
23+
* ``data``: A pointer to the bytes constituting the custom key material.
24+
* ``len``: The length of the bytes constituting the custom key material.
25+
26+
Description
27+
-----------
28+
29+
Key material is used to encrypt and decrypt data. If custom key material is not provided, the key material for the new data key is generated from a cryptographically secure random device.

src/libmongoc/doc/mongoc_client_encryption_datakey_opts_t.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ Used to set options for :symbol:`mongoc_client_encryption_create_datakey()`.
2525
mongoc_client_encryption_datakey_opts_destroy
2626
mongoc_client_encryption_datakey_opts_set_masterkey
2727
mongoc_client_encryption_datakey_opts_set_keyaltnames
28+
mongoc_client_encryption_datakey_opts_set_keymaterial
2829

2930
.. seealso::
3031

32+
| :symbol:`mongoc_client_encryption_create_key()`
3133
| :symbol:`mongoc_client_encryption_create_datakey()`
32-
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
:man_page: mongoc_client_encryption_rewrap_many_datakey
2+
3+
mongoc_client_encryption_rewrap_many_datakey()
4+
==============================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_client_encryption_rewrap_many_datakey (
13+
mongoc_client_encryption_t *client_encryption,
14+
const bson_t *filter,
15+
const char *provider,
16+
const bson_t *master_key,
17+
mongoc_client_encryption_rewrap_many_datakey_result_t *result,
18+
bson_error_t *error);
19+
20+
Rewraps zero or more data keys in the key vault collection that match the
21+
provided ``filter``.
22+
23+
A ``NULL`` argument for ``filter`` is equivalent to being given an empty
24+
document (match all).
25+
26+
If ``provider`` is ``NULL``, rewraps matching data keys with their current KMS
27+
provider.
28+
29+
If ``provider`` is not ``NULL``, rewraps matching data keys with the new KMS
30+
provider as described by ``master_key``. The ``master_key`` document must
31+
conform to the `Client Side Encryption specification
32+
<https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#masterkey>`_.
33+
34+
Parameters
35+
----------
36+
37+
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
38+
* ``filter``: The filter to use when finding data keys to rewrap in the key vault collection.
39+
* ``provider``: The new KMS provider to use to encrypt the data keys, or ``NULL`` to use the current KMS provider(s).
40+
* ``master_key``: The master key fields corresponding to the new KMS provider when ``provider`` is not ``NULL``.
41+
* ``result``: An optional :symbol:`mongoc_client_encryption_rewrap_many_datakey_result_t`.
42+
* ``error``: A :symbol:`bson_error_t` set on failure.
43+
44+
Returns
45+
-------
46+
47+
Returns ``true`` if successful. Returns ``false`` and sets ``error`` otherwise.
48+
49+
.. seealso::
50+
51+
| :symbol:`mongoc_client_encryption_rewrap_many_datakey_result_t`
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
:man_page: mongoc_client_encryption_rewrap_many_datakey_result_destroy
2+
3+
mongoc_client_encryption_rewrap_many_datakey_result_destroy()
4+
=============================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void
12+
mongoc_client_encryption_rewrap_many_datakey_result_destroy (
13+
mongoc_client_encryption_rewrap_many_datakey_result_t *result);
14+
15+
Frees resources of a :symbol:`mongoc_client_encryption_rewrap_many_datakey_result_t` created with :symbol:`mongoc_client_encryption_rewrap_many_datakey_result_new()`. Does nothing if ``NULL`` is passed.
16+
17+
Parameters
18+
----------
19+
20+
* ``result``: A :symbol:`mongoc_client_encryption_rewrap_many_datakey_result_t`.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
:man_page: mongoc_client_encryption_rewrap_many_datakey_result_get_bulk_write_result
2+
3+
mongoc_client_encryption_rewrap_many_datakey_result_get_bulk_write_result()
4+
===========================================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
const bson_t *
12+
mongoc_client_encryption_rewrap_many_datakey_result_get_bulk_write_result (
13+
mongoc_client_encryption_rewrap_many_datakey_result_t *result)
14+
BSON_GNUC_WARN_UNUSED_RESULT;
15+
16+
Get the bulk write result set by a successful call to :symbol:`mongoc_client_encryption_rewrap_many_datakey()`.
17+
18+
Parameters
19+
----------
20+
21+
* ``result``: A :symbol:`mongoc_client_encryption_rewrap_many_datakey_result_t`.
22+
23+
Returns
24+
-------
25+
26+
A :symbol:`bson_t` that must not be modified or freed if ``result`` is not ``NULL``. Otherwise, returns ``NULL``.
27+
28+
.. seealso::
29+
30+
| :symbol:`mongoc_client_encryption_rewrap_many_datakey()`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
:man_page: mongoc_client_encryption_rewrap_many_datakey_result_new
2+
3+
mongoc_client_encryption_rewrap_many_datakey_result_new()
4+
=========================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
mongoc_client_encryption_rewrap_many_datakey_result_t *
12+
mongoc_client_encryption_rewrap_many_datakey_result_new (void)
13+
BSON_GNUC_WARN_UNUSED_RESULT;
14+
15+
Returns
16+
-------
17+
18+
A new :symbol:`mongoc_client_encryption_rewrap_many_datakey_result_t` that must be freed with :symbol:`mongoc_client_encryption_rewrap_many_datakey_result_destroy()`.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
:man_page: mongoc_client_encryption_rewrap_many_datakey_result_t
2+
3+
mongoc_client_encryption_rewrap_many_datakey_result_t
4+
=====================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
typedef struct _mongoc_client_encryption_rewrap_many_datakey_result_t
12+
mongoc_client_encryption_rewrap_many_datakey_result_t;
13+
14+
15+
Used to access the result of :symbol:`mongoc_client_encryption_rewrap_many_datakey()`.
16+
17+
.. only:: html
18+
19+
Functions
20+
---------
21+
22+
.. toctree::
23+
:titlesonly:
24+
:maxdepth: 1
25+
26+
mongoc_client_encryption_rewrap_many_datakey_result_new
27+
mongoc_client_encryption_rewrap_many_datakey_result_destroy
28+
mongoc_client_encryption_rewrap_many_datakey_result_get_bulk_write_result
29+
30+
.. seealso::
31+
32+
| :symbol:`mongoc_client_encryption_rewrap_many_datakey()`

src/libmongoc/doc/mongoc_client_encryption_t.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ The key vault client, configured via :symbol:`mongoc_client_encryption_opts_set_
3434

3535
mongoc_client_encryption_new
3636
mongoc_client_encryption_destroy
37+
mongoc_client_encryption_create_key
3738
mongoc_client_encryption_create_datakey
39+
mongoc_client_encryption_rewrap_many_datakey
3840
mongoc_client_encryption_encrypt
3941
mongoc_client_encryption_decrypt
4042

@@ -47,4 +49,3 @@ The key vault client, configured via :symbol:`mongoc_client_encryption_opts_set_
4749
| The guide for :doc:`Using Client-Side Field Level Encryption <using_client_side_encryption>` for libmongoc
4850
4951
| The MongoDB Manual for `Client-Side Field Level Encryption <https://docs.mongodb.com/manual/core/security-client-side-encryption/>`_
50-

0 commit comments

Comments
 (0)