Skip to content

Commit 584eaca

Browse files
authored
CDRIVER-4317 Add remaining Key Management API functions (#1008)
* Fix validation of opts field for rewrapManyDataKey operation * Update unified spec tests * Set default read and write concern on keyvault collection * Add key management API functions * Add prose test for keyAltname unique index * Add unified test runner support for key management API
1 parent c55b224 commit 584eaca

26 files changed

+5405
-827
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
:man_page: mongoc_client_encryption_add_key_alt_name
2+
3+
mongoc_client_encryption_add_key_alt_name()
4+
===========================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_client_encryption_add_key_alt_name (
13+
mongoc_client_encryption_t *client_encryption,
14+
const bson_value_t *keyid,
15+
const char *keyaltname,
16+
bson_t *key_doc,
17+
bson_error_t *error);
18+
19+
Add ``keyaltname`` to the set of alternate names in the key document with UUID ``keyid``.
20+
21+
Parameters
22+
----------
23+
24+
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
25+
* ``keyid``: A UUID (BSON binary subtype 0x04) key ID of the key to add the key alternate name to.
26+
* ``keyaltname``: The key alternate name to add.
27+
* ``key_doc``: Optional. An uninitialized :symbol:`bson_t` set to the value of the key document before addition of the alternate name, or an empty document if the key does not exist. Must be freed by :symbol:`bson_destroy`.
28+
* ``error``: Optional. :symbol:`bson_error_t`.
29+
30+
Returns
31+
-------
32+
33+
Returns ``true`` if successful. Returns ``false`` and sets ``error`` otherwise.
34+
35+
.. seealso::
36+
37+
| :symbol:`mongoc_client_encryption_t`

src/libmongoc/doc/mongoc_client_encryption_create_key.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ 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()`).
19+
Creates a new key document in the key vault collection and sets ``keyid`` to the UUID of the 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()`).
2120

2221
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.
2322

@@ -29,8 +28,8 @@ Parameters
2928
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
3029
* ``kms_provider``: A string identifying the Key Management Service (KMS) provider used to encrypt the datakey (e.g. "aws" or "local").
3130
* ``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`
31+
* ``keyid``: Optional. An uninitialized :symbol:`bson_value_t` set to the UUID (BSON binary subtype 0x04) of the newly created key. Must be freed by :symbol:`bson_value_destroy`.
32+
* ``error``: Optional. A :symbol:`bson_error_t`.
3433

3534
Returns
3635
-------
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
:man_page: mongoc_client_encryption_delete_key
2+
3+
mongoc_client_encryption_delete_key()
4+
=====================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_client_encryption_delete_key (
13+
mongoc_client_encryption_t *client_encryption,
14+
const bson_value_t *keyid,
15+
bson_t *reply,
16+
bson_error_t *error);
17+
18+
Delete a key document in the key vault collection that has the given ``keyid``.
19+
20+
Parameters
21+
----------
22+
23+
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
24+
* ``keyid``: The UUID (BSON binary subtype 0x04) of the key to delete.
25+
* ``reply``: Optional. An uninitalized :symbol:`bson:bson_t` set to the delete result. Must be freed by :symbol:`bson_destroy`.
26+
* ``error``: Optional. :symbol:`bson_error_t`.
27+
28+
Returns
29+
-------
30+
31+
Returns ``true`` if successful. Returns ``false`` and sets ``error`` otherwise.
32+
33+
.. seealso::
34+
35+
| :symbol:`mongoc_client_encryption_t`
36+
| :symbol:`mongoc_client_encryption_create_key`

src/libmongoc/doc/mongoc_client_encryption_encrypt_opts_set_contention_factor.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Synopsis
88

99
.. code-block:: c
1010
11-
MONGOC_EXPORT (void)
11+
void
1212
mongoc_client_encryption_encrypt_opts_set_contention_factor (
1313
mongoc_client_encryption_encrypt_opts_t *opts, int64_t contention_factor);
1414

src/libmongoc/doc/mongoc_client_encryption_encrypt_opts_set_keyid.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ Parameters
1818
----------
1919

2020
* ``opts``: A :symbol:`mongoc_client_encryption_encrypt_opts_t`
21-
* ``keyid``: A UUID (BSON binary with subtype 4) corresponding to the ``_id`` of the data key.
21+
* ``keyid``: The UUID (BSON binary subtype 0x04) corresponding to the ``_id`` of the data key.
2222

2323
.. seealso::
2424

2525
| :symbol:`mongoc_client_encryption_encrypt_opts_set_keyaltname`
26-
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
:man_page: mongoc_client_encryption_get_key
2+
3+
mongoc_client_encryption_get_key()
4+
==================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_client_encryption_get_key (mongoc_client_encryption_t *client_encryption,
13+
const bson_value_t *keyid,
14+
bson_t *key_doc,
15+
bson_error_t *error);
16+
17+
Get a key document in the key vault collection that has the given ``keyid``.
18+
19+
Parameters
20+
----------
21+
22+
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
23+
* ``keyid``: The UUID (BSON binary subtype 0x04) of the key to get.
24+
* ``key_doc``: Optional. An uninitialized :symbol:`bson_t` set to the resulting key document, or an empty document value if the key does not exist. Must be freed by :symbol:`bson_destroy`.
25+
* ``error``: Optional. :symbol:`bson_error_t`.
26+
27+
Returns
28+
-------
29+
30+
Returns ``true`` if successful. Returns ``false`` and sets ``error`` otherwise.
31+
32+
.. seealso::
33+
34+
| :symbol:`mongoc_client_encryption_t`
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
:man_page: mongoc_client_encryption_get_key_by_alt_name
2+
3+
mongoc_client_encryption_get_key_by_alt_name()
4+
==============================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_client_encryption_get_key_by_alt_name (
13+
mongoc_client_encryption_t *client_encryption,
14+
const char *keyaltname,
15+
bson_value_t *key_doc,
16+
bson_error_t *error);
17+
18+
Get a key document in the key vault collection that has the given ``keyaltname``.
19+
20+
Parameters
21+
----------
22+
23+
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
24+
* ``keyaltname``: The key alternate name of the key to get.
25+
* ``key_doc``: Optional. An uninitialized :symbol:`bson_t` set to the resulting key document, or an empty document if the key does not exist. Must be freed by :symbol:`bson_value_destroy`.
26+
* ``error``: Optional. :symbol:`bson_error_t`.
27+
28+
Returns
29+
-------
30+
31+
Returns ``true`` if successful. Returns ``false`` and sets ``error`` otherwise.
32+
33+
.. seealso::
34+
35+
| :symbol:`mongoc_client_encryption_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_get_keys
2+
3+
mongoc_client_encryption_get_keys()
4+
===================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
mongoc_cursor_t *
12+
mongoc_client_encryption_get_keys (mongoc_client_encryption_t *client_encryption,
13+
bson_error_t *error);
14+
15+
Get all the key documents in the key vault collection.
16+
17+
Parameters
18+
----------
19+
20+
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
21+
* ``error``: Optional. :symbol:`bson_error_t`.
22+
23+
Returns
24+
-------
25+
26+
Returns the result of the internal find command if successful. Returns ``NULL`` and sets ``error`` otherwise.
27+
28+
.. seealso::
29+
30+
| :symbol:`mongoc_client_encryption_t`
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
:man_page: mongoc_client_encryption_remove_key_alt_name
2+
3+
mongoc_client_encryption_remove_key_alt_name()
4+
==============================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_client_encryption_remove_key_alt_name (
13+
mongoc_client_encryption_t *client_encryption,
14+
const bson_value_t *keyid,
15+
const char *keyaltname,
16+
bson_t *key_doc,
17+
bson_error_t *error);
18+
19+
Remove ``keyaltname`` from the set of keyAltNames in the key document with UUID ``keyid``.
20+
21+
Also removes the ``keyAltNames`` field from the key document if it would otherwise be empty.
22+
23+
Parameters
24+
----------
25+
26+
* ``client_encryption``: A :symbol:`mongoc_client_encryption_t`.
27+
* ``keyid``: The UUID (BSON binary subtype 0x04) of the key to remove the key alternate name from.
28+
* ``keyaltname``: The key alternate name to remove.
29+
* ``key_doc``: Optional. An uninitialized :symbol:`bson_t` set to the value of the key document before removal of the key alternate name, or an empty document the key does not exist. Must be freed by :symbol:`bson_value_destroy`.
30+
* ``error``: Optional. :symbol:`bson_error_t`.
31+
32+
Returns
33+
-------
34+
35+
Returns ``true`` if successful. Returns ``false`` and sets ``error`` otherwise.
36+
37+
.. seealso::
38+
39+
| :symbol:`mongoc_client_encryption_t`

src/libmongoc/doc/mongoc_client_encryption_t.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ The key vault client, configured via :symbol:`mongoc_client_encryption_opts_set_
3737
mongoc_client_encryption_create_key
3838
mongoc_client_encryption_create_datakey
3939
mongoc_client_encryption_rewrap_many_datakey
40+
mongoc_client_encryption_delete_key
41+
mongoc_client_encryption_get_key
42+
mongoc_client_encryption_get_keys
43+
mongoc_client_encryption_add_key_alt_name
44+
mongoc_client_encryption_remove_key_alt_name
45+
mongoc_client_encryption_get_key_by_alt_name
4046
mongoc_client_encryption_encrypt
4147
mongoc_client_encryption_decrypt
4248

0 commit comments

Comments
 (0)