Skip to content

DOCSP-42150: CSFLE standardization #102

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

Merged
merged 11 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/redirects
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ raw: /docs/languages/cxx -> /docs/languages/cpp

(v3.10-master]: ${prefix}/${version}/installation/ -> ${base}/${version}/get-started/
(v3.10-master]: ${prefix}/${version}/configuration/ -> ${base}/${version}/security/
(v3.10-master]: ${prefix}/${version}/client-side-encryption/ -> ${base}/${version}/security/client-side-encryption/
(v3.10-master]: ${prefix}/${version}/client-side-encryption/ -> ${base}/${version}/security/in-use-encryption/
(v3.10-master]: ${prefix}/${version}/tutorial/ -> ${base}/${version}/
(v3.10-master]: ${prefix}/${version}/connection-pools/ -> ${base}/${version}/connect/connection-pools/
(v3.10-master]: ${prefix}/${version}/working-with-bson/ -> ${base}/${version}/data-formats/working-with-bson/
Expand Down
8 changes: 4 additions & 4 deletions source/include-link.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The examples on this page reference {+driver-short+} library targets. Examples i
The availability of targets depends on the particular installation method.

.. _cpp-include-cmake:

CMake
-----

Expand Down Expand Up @@ -83,8 +84,7 @@ After installing the {+driver-short+}, you can use CMake's ``find_package`` comm
To use the ``find_package`` command, create a ``CMakeLists.txt`` file in your project directory. The following example creates a ``CMakeLists.txt`` file in the ``/home/user/project1`` project directory that uses ``find_package``:

.. literalinclude:: /includes/cmake_with_driver_installation.txt
:caption: /home/user/project1/CMakeLists.txt
:start-after: -- sphinx-include-start --
:caption: /home/user/project1/CMakeLists.txt

Then, run the following commands to build your project:

Expand Down Expand Up @@ -140,8 +140,7 @@ Alternatively, you can use CMake's ``add_subdirectory`` command without installi
To use the ``add_subdirectory`` command, create a ``CMakeLists.txt`` file in your project directory. The following example creates a ``CMakeLists.txt`` file in the ``/home/user/project2`` project directory that uses ``add_subdirectory``:

.. literalinclude:: /includes/cmake_without_driver_installation.txt
:caption: /home/user/project2/CMakeLists.txt
:start-after: -- sphinx-include-start --
:caption: /home/user/project2/CMakeLists.txt

.. note::

Expand Down Expand Up @@ -190,6 +189,7 @@ The output resembles the following:
members

.. _cpp-include-pkg-config:

pkg-config
----------

Expand Down
52 changes: 52 additions & 0 deletions source/includes/csfle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// start-auto-encrypt
auto mongocryptd_options = make_document(kvp("mongocryptdBypassSpawn", true));

options::auto_encryption auto_encrypt_opts{};
auto_encrypt_opts.extra_options({mongocryptd_options.view()});

options::client client_opts;
client_opts.auto_encryption_opts(std::move(auto_encrypt_opts));

// Create and use your client here
// end-auto-encrypt

// start-json-schema
auto data_key_id = client_encryption.create_data_key("local");
auto json_schema = document{} << "properties" << open_document << "encryptedFieldName" << open_document << "encrypt"
<< open_document << "keyId" << open_array << data_key_id << close_array << "bsonType"
<< "string"
<< "algorithm"
<< "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" << close_document << close_document
<< close_document << "bsonType"
<< "object" << finalize;
// end-json-schema

// start-explicit-encrypt
// Configure your MongoDB client's encryption options here

class client_encryption client_encryption(std::move(client_encryption_opts));

auto data_key_id = client_encryption.create_data_key("local");
options::encrypt encrypt_opts{};
encrypt_opts.key_id(data_key_id.view());
encrypt_opts.algorithm(options::encrypt::encryption_algorithm::k_deterministic);

// Explicitly encrypts a BSON value
auto to_encrypt = bsoncxx::types::bson_value::make_value("secret message");
auto encrypted_message = client_encryption.encrypt(to_encrypt, encrypt_opts);

// Explicitly decrypts a BSON value
auto decrypted_message = client_encryption.decrypt(encrypted_message);

// Inserts the encrypted value into the database
coll.insert_one(make_document(kvp("encryptedField", encrypted_message)));
// end-explicit-encrypt

// start-auto-decrypt
options::auto_encryption auto_encrypt_opts{};
auto_encrypt_opts.bypass_auto_encryption(true);

options::client client_opts{};
client_opts.auto_encryption_opts(std::move(auto_encrypt_opts));
class client client_encrypted {uri{}, std::move(client_opts)};
// end-auto-decrypt
1 change: 0 additions & 1 deletion source/security.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Secure Your Data
Authentication </security/authentication>
Enterprise Authentication </security/enterprise-authentication>
In-Use Encryption </security/in-use-encryption>
Client-Side Encryption </security/client-side-encryption>

Overview
--------
Expand Down
162 changes: 0 additions & 162 deletions source/security/client-side-encryption.txt

This file was deleted.

Loading
Loading