Skip to content

Commit 1de613a

Browse files
committed
CDRIVER-2875 auto encryption and decryption
1 parent ce14000 commit 1de613a

File tree

71 files changed

+11362
-144
lines changed

Some content is hidden

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

71 files changed

+11362
-144
lines changed

.lsan-suppressions

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
leak:ccrng_cryptographic_init_once
22
leak:ccrng_cryptographic_generate
33
leak:res_9_ninit
4+
leak:SSLCreateContext

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ option (ENABLE_RDTSCP
5555
option (ENABLE_APPLE_FRAMEWORK "Build libraries as frameworks on darwin platforms" OFF)
5656
set (ENABLE_ICU AUTO CACHE STRING "Enable ICU support, necessary to use non-ASCII usernames or passwords, default AUTO.")
5757
option (ENABLE_UNINSTALL "Enable creation of uninstall script and associated uninstall build target." ON)
58+
set (ENABLE_CLIENT_SIDE_ENCRYPTION AUTO CACHE STRING "Enable Client-Side Field Level Encryption support. Requires libmongocrypt. Set to ON/AUTO/OFF, default AUTO.")
5859

5960
project (mongo-c-driver C)
6061

CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ The mock server timeout threshold for future functions can be set with:
223223

224224
This is useful for debugging, so future calls don't timeout when stepping through code.
225225

226+
Tests of Client-Side Field Level Encryption require credentials to an AWS user which has list and read permissions to AWS KMS.
227+
228+
* `MONGOC_TEST_AWS_SECRET_ACCESS_KEY=<string>`
229+
* `MONGOC_TEST_AWS_ACCESS_KEY_ID=<string>`
230+
226231
All tests should pass before submitting a patch.
227232

228233
## Configuring the test runner

src/libmongoc/CMakeLists.txt

+34-2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,35 @@ if (NOT ENABLE_ICU STREQUAL OFF)
396396
endif()
397397
endif()
398398

399+
# Configure client side encryption.
400+
set (MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION 0)
401+
if (NOT ENABLE_CLIENT_SIDE_ENCRYPTION MATCHES "AUTO|ON|OFF")
402+
message (FATAL_ERROR, "ENABLE_CLIENT_SIDE_ENCRYPTION option must be AUTO, ON, or OFF")
403+
endif ()
404+
405+
if (NOT MONGOC_ENABLE_SSL)
406+
if (ENABLE_CLIENT_SIDE_ENCRYPTION STREQUAL ON)
407+
message (FATAL_ERROR "SSL disabled, but is required for Client-Side Field Level Encryption support.")
408+
elseif (ENABLE_CLIENT_SIDE_ENCRYPTION STREQUAL AUTO)
409+
message (STATUS "SSL disabled. Configuring without Client-Side Field Level Encryption support.")
410+
endif ()
411+
elseif (NOT ENABLE_CLIENT_SIDE_ENCRYPTION STREQUAL OFF)
412+
message ("Searching for libmongocrypt")
413+
find_package (mongocrypt)
414+
if (mongocrypt_FOUND)
415+
set (CLIENT_SIDE_ENCRYPTION_LIBRARIES mongo::mongocrypt)
416+
get_target_property (LIBMONGOCRYPT_LOCATION mongo::mongocrypt LOCATION)
417+
get_target_property (LIBMONGOCRYPT_INCLUDE_DIRECTORIES mongo::mongocrypt INTERFACE_INCLUDE_DIRECTORIES)
418+
message ("-- libmongocrypt found at ${LIBMONGOCRYPT_LOCATION}")
419+
message ("-- libmongocrypt include path ${LIBMONGOCRYPT_INCLUDE_DIRECTORIES}")
420+
set (MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION 1)
421+
elseif (ENABLE_CLIENT_SIDE_ENCRYPTION STREQUAL ON)
422+
message (FATAL_ERROR "Required library (libmongocrypt) not found.")
423+
else ()
424+
message (STATUS "libmongocrypt not found. Configuring without Client-Side Field Level Encryption support.")
425+
endif ()
426+
endif ()
427+
399428
configure_file (
400429
"${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-config.h.in"
401430
"${PROJECT_BINARY_DIR}/src/mongoc/mongoc-config.h"
@@ -428,6 +457,7 @@ set (SOURCES ${SOURCES}
428457
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-change-stream.c
429458
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-client.c
430459
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-client-pool.c
460+
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-client-side-encryption.c
431461
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cluster.c
432462
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cluster-sasl.c
433463
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-collection.c
@@ -507,6 +537,7 @@ set (HEADERS
507537
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-change-stream.h
508538
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-client.h
509539
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-client-pool.h
540+
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-client-side-encryption.h
510541
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-collection.h
511542
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor.h
512543
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-database.h
@@ -633,11 +664,11 @@ endif ()
633664

634665
set (LIBRARIES
635666
${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES} ${RESOLV_LIBRARIES}
636-
${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} Threads::Threads ${ICU_LIBRARIES}
667+
${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} Threads::Threads ${ICU_LIBRARIES} ${CLIENT_SIDE_ENCRYPTION_LIBRARIES}
637668
)
638669
set (STATIC_LIBRARIES
639670
${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES} ${RESOLV_LIBRARIES}
640-
${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ICU_LIBRARIES}
671+
${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ICU_LIBRARIES} ${CLIENT_SIDE_ENCRYPTION_LIBRARIES}
641672
)
642673

643674
if (WIN32)
@@ -772,6 +803,7 @@ set (test-libmongoc-sources
772803
${PROJECT_SOURCE_DIR}/tests/test-mongoc-change-stream.c
773804
${PROJECT_SOURCE_DIR}/tests/test-mongoc-client.c
774805
${PROJECT_SOURCE_DIR}/tests/test-mongoc-client-pool.c
806+
${PROJECT_SOURCE_DIR}/tests/test-mongoc-client-side-encryption.c
775807
${PROJECT_SOURCE_DIR}/tests/test-mongoc-cluster.c
776808
${PROJECT_SOURCE_DIR}/tests/test-mongoc-collection.c
777809
${PROJECT_SOURCE_DIR}/tests/test-mongoc-collection-find.c

src/libmongoc/doc/api.rst

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ API Reference
1010
errors
1111
lifecycle
1212
gridfs
13+
mongoc_auto_encryption_opts_t
1314
mongoc_bulk_operation_t
1415
mongoc_change_stream_t
1516
mongoc_client_pool_t

0 commit comments

Comments
 (0)