libmongocrypt-helper 1.7.4.0.1002 → 1.11.0.0.1001
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +40 -5
- data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +29 -24
- data/ext/libmongocrypt/libmongocrypt/CODEOWNERS +1 -4
- data/ext/libmongocrypt/libmongocrypt/Earthfile +522 -0
- data/ext/libmongocrypt/libmongocrypt/README.md +36 -40
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/CMakeLists.txt +1 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Driver.snk +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/AssemblyInfo.cs +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Binary.cs +16 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClientFactory.cs +8 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +35 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/LibraryLoader.cs +81 -44
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/MongoDB.Libmongocrypt.csproj +2 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/MongoDB.Libmongocrypt.Test.csproj +2 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test32/MongoDB.Libmongocrypt.Test32.csproj +2 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/README.md +3 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +22 -26
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.config +3 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.sh +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/build.gradle.kts +28 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/java/com/mongodb/crypt/benchmark/BenchmarkRunner.java +217 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/resources/keyDocument.json +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +22 -7
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.properties +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew +154 -108
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew.bat +7 -18
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/settings.gradle.kts +1 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPI.java +41 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPIHelper.java +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CipherCallback.java +27 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoCryptImpl.java +34 -19
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoExplicitEncryptOptions.java +6 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/jni-config.json +180 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/reflect-config.json +134 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +50 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/{python/test/data/fle2-find-range-explicit → java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2}/int32/rangeopts.json +3 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +4 -771
- data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +86 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +41 -20
- data/ext/libmongocrypt/libmongocrypt/bindings/python/RELEASE.rst +6 -24
- data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +4 -13
- data/ext/libmongocrypt/libmongocrypt/bindings/python/hatch_build.py +36 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/libmongocrypt-version.txt +1 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/__init__.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/auto_encrypter.py +61 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/credentials.py +156 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/explicit_encrypter.py +156 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/state_machine.py +149 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/auto_encrypter.py +2 -46
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binary.py +14 -17
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +232 -296
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +6 -31
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/credentials.py +2 -121
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/crypto.py +31 -20
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/errors.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +2 -233
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +168 -254
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/options.py +265 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/state_machine.py +2 -141
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/auto_encrypter.py +61 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/credentials.py +156 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/explicit_encrypter.py +156 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/state_machine.py +149 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pyproject.toml +118 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +97 -61
- data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements-test.txt +7 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements.txt +4 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/sbom.json +76 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/strip_header.py +6 -7
- data/ext/libmongocrypt/libmongocrypt/bindings/python/synchro.py +64 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +2 -10
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/collection-info.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/command.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/compact/success/encrypted-payload.json +21 -21
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-command-reply.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-field-config-map.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/rangeopts.json +14 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-azure.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-gcp.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-filter.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/list-collections-filter.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-command.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-reply.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/schema-map.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/keyDocument.json +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/perf_test.py +165 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_binding.py +8 -12
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_crypto.py +9 -11
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +991 -343
- data/ext/libmongocrypt/libmongocrypt/bindings/python/update-sbom.sh +14 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/FetchMongoC.cmake +19 -1
- data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +31 -6
- data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +20 -227
- data/ext/libmongocrypt/libmongocrypt/cmake/Patch.cmake +54 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
- data/ext/libmongocrypt/libmongocrypt/doc/img/cli-icon.png +0 -0
- data/ext/libmongocrypt/libmongocrypt/doc/img/reference-targets.png +0 -0
- data/ext/libmongocrypt/libmongocrypt/doc/releasing.md +153 -0
- data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
- data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version.py +61 -28
- data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version_selftest.sh +73 -0
- data/ext/libmongocrypt/libmongocrypt/etc/cyclonedx.sbom.json +108 -0
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
- data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
- data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
- data/ext/libmongocrypt/libmongocrypt/etc/libbson-remove-GCC-diagnostic-pragma.patch +27 -0
- data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-alpine-arm-fix.patch +17 -0
- data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
- data/ext/libmongocrypt/libmongocrypt/etc/packager.py +120 -91
- data/ext/libmongocrypt/libmongocrypt/etc/purls.txt +14 -0
- data/ext/libmongocrypt/libmongocrypt/etc/repo_config.yaml +56 -0
- data/ext/libmongocrypt/libmongocrypt/etc/silk-create-asset-group.sh +70 -0
- data/ext/libmongocrypt/libmongocrypt/etc/ssdlc_compliance_report.md +37 -0
- data/ext/libmongocrypt/libmongocrypt/etc/third_party_vulnerabilities.md +42 -0
- data/ext/libmongocrypt/libmongocrypt/integrating.md +18 -1
- data/ext/libmongocrypt/libmongocrypt/kms-message/CMakeLists.txt +11 -3
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_gcp_request.c +1 -1
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer.c +17 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer_private.h +6 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_request.c +211 -1
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_response.c +163 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_tag_type_private.h +2 -1
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_request.h +17 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_response.h +6 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_port.c +3 -2
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request.c +4 -2
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.c +2 -2
- data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kmip_reader_writer.c +23 -2
- data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
- data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
- data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +183 -248
- data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
- data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
- data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
- data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +21 -11
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +175 -99
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +69 -70
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +445 -439
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +103 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +28 -31
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +173 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +130 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +36 -44
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +382 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +454 -325
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +56 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +520 -580
- data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +47 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +67 -76
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +201 -190
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +55 -42
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +809 -558
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +177 -201
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +54 -53
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +188 -240
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +43 -35
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +484 -337
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +87 -65
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +153 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
- data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
- data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
- data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +461 -499
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +256 -334
- data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
- data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
- data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +1 -9
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +442 -565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +104 -132
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +16 -24
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +110 -93
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1145 -1567
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +510 -476
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2775 -2697
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +189 -184
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +990 -1139
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +23 -24
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +42 -44
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +292 -272
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +70 -110
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +1010 -1033
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +127 -120
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1692 -1611
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +31 -36
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1923 -1479
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +124 -107
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +925 -419
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +99 -122
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +98 -136
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +924 -1339
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +199 -313
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +83 -79
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +64 -73
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
- data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/bypassQueryAnalysis/payload.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd-to-mongocryptd.json +23 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd-to-mongocryptd.json +50 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/collinfo.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-field-map.json +24 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-payload-pattern.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/mongocryptd-reply.json +62 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd-to-mongocryptd.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd.json +17 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/mongocryptd-reply.json +39 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/payload.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/missing-key-id/collinfo.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/collinfo.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/encrypted-payload.json +4 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/cmd.json +1 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/collinfo.json +63 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-field-config-map.json +61 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload-range-v2.json +37 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/cmd.json +1 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/collinfo.json +64 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload-range-v2.json +105 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/cmd.json +1 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/collinfo.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-field-config-map.json +47 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-payload.json +23 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/collinfo.json +15 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-field-config-map.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload-range-v2.json +104 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/collinfo.json +4 -4
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +5 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/decrypt-response.txt +16 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/encrypt-response.txt +16 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/oauth-response.txt +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-field-map.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-payload.json +62 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/mongocryptd-reply.json +69 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-field-map.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-payload.json +40 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/mongocryptd-reply.json +47 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_decimal128.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_double.cstruct +8637 -7958
- data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int32.cstruct +5522 -1382
- data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int64.cstruct +5042 -1262
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128_precision.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double_precision.cstruct +2 -2
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int32.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int64.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-field-map.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-payload.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/mongocryptd-reply.json +58 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-field-map.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-payload.json +40 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/mongocryptd-reply.json +45 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/expected.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/to-encrypt.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/expected.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/to-encrypt.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-double/expected.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32/expected.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32-defaults/expected.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +25 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +25 -0
- data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
- data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +279 -323
- data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +60 -73
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +129 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +248 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +421 -388
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +974 -825
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +499 -481
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +312 -148
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +249 -213
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +632 -808
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +22 -2
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +118 -37
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cleanup.c +374 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +410 -445
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +798 -812
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +142 -135
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +70 -71
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +870 -1045
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +5183 -4717
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +1093 -1178
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +348 -420
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +705 -368
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +1073 -690
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-opts.c +42 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +381 -451
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +55 -67
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +7 -10
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +879 -918
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +119 -169
- data/ext/libmongocrypt/libmongocrypt/test/test-named-kms-providers.c +2381 -0
- data/ext/libmongocrypt/libmongocrypt/test/util/HELP.autogen +3 -1
- data/ext/libmongocrypt/libmongocrypt/test/util/README.md +1 -0
- data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +512 -559
- data/ext/libmongocrypt/libmongocrypt/test/util/make_includes.py +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/util/util.c +771 -882
- data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
- data/lib/libmongocrypt_helper/version.rb +2 -2
- metadata +245 -111
- checksums.yaml.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +0 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +0 -81
- data/ext/libmongocrypt/libmongocrypt/bindings/node/LICENSE +0 -201
- data/ext/libmongocrypt/libmongocrypt/bindings/node/binding.gyp +0 -79
- data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/README.hbs +0 -44
- data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +0 -39
- data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +0 -515
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +0 -420
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/buffer_pool.js +0 -123
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +0 -699
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +0 -100
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/cryptoCallbacks.js +0 -87
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +0 -42
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js +0 -66
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +0 -487
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +0 -16051
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +0 -81
- data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +0 -929
- data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.h +0 -114
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +0 -953
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/buffer_pool.test.js +0 -91
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +0 -701
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +0 -284
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/README.md +0 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/cmd.json +0 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/collection-info.json +0 -37
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document-nested.json +0 -8
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document.json +0 -11
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encryptedFields.json +0 -30
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key-document.json +0 -32
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key1-document.json +0 -30
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/mongocryptd-reply.json +0 -18
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +0 -48
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +0 -59
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +0 -29
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +0 -331
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/mongodb_reporter.js +0 -325
- data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +0 -84
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +0 -12
- data/ext/libmongocrypt/libmongocrypt/debian/build_snapshot.sh +0 -79
- data/ext/libmongocrypt/libmongocrypt/debian/changelog +0 -105
- data/ext/libmongocrypt/libmongocrypt/debian/compat +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/control +0 -41
- data/ext/libmongocrypt/libmongocrypt/debian/copyright +0 -129
- data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +0 -23
- data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.dirs +0 -2
- data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.install +0 -5
- data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.dirs +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.install +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/rules +0 -46
- data/ext/libmongocrypt/libmongocrypt/debian/source/format +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/source/lintian-overrides +0 -3
- data/ext/libmongocrypt/libmongocrypt/debian/source/options +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/watch +0 -3
- data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/mongocryptd-reply.json +0 -72
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/{java/mongocrypt/src/test/resources/fle2-find-range-explicit → python/test/data/fle2-find-rangePreview-explicit}/int32/rangeopts.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/{test/data/fle2-find-range-explicit/int32-nominmax → bindings/python/test/data/fle2-find-rangePreview-explicit/int32}/value-to-encrypt.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-decrypt-reply.txt → test/data/kms-aws/decrypt-response.txt} +0 -0
- /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-encrypt-reply.txt → test/data/kms-aws/encrypt-response.txt} +0 -0
- /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/decrypt-response.txt +0 -0
- /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/encrypt-response.txt +0 -0
- /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/oauth-response.txt +0 -0
@@ -14,14 +14,13 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
#include "mlib/thread.h"
|
18
|
-
#include "mlib/path.h"
|
19
17
|
#include "mlib/error.h"
|
18
|
+
#include "mlib/path.h"
|
19
|
+
#include "mlib/thread.h"
|
20
20
|
|
21
|
-
#include <kms_message/kms_message.h>
|
22
21
|
#include <bson/bson.h>
|
22
|
+
#include <kms_message/kms_message.h>
|
23
23
|
|
24
|
-
#include "mongocrypt-private.h"
|
25
24
|
#include "mongocrypt-binary-private.h"
|
26
25
|
#include "mongocrypt-cache-collinfo-private.h"
|
27
26
|
#include "mongocrypt-cache-key-private.h"
|
@@ -30,465 +29,404 @@
|
|
30
29
|
#include "mongocrypt-log-private.h"
|
31
30
|
#include "mongocrypt-mutex-private.h"
|
32
31
|
#include "mongocrypt-opts-private.h"
|
32
|
+
#include "mongocrypt-private.h"
|
33
33
|
#include "mongocrypt-status-private.h"
|
34
34
|
#include "mongocrypt-util-private.h"
|
35
35
|
|
36
36
|
/* Assert size for interop with wrapper purposes */
|
37
|
-
BSON_STATIC_ASSERT
|
37
|
+
BSON_STATIC_ASSERT(sizeof(mongocrypt_log_level_t) == 4);
|
38
38
|
|
39
|
+
const char *mongocrypt_version(uint32_t *len) {
|
40
|
+
if (len) {
|
41
|
+
*len = (uint32_t)strlen(MONGOCRYPT_VERSION);
|
42
|
+
}
|
43
|
+
return MONGOCRYPT_VERSION;
|
44
|
+
}
|
39
45
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
void _mongocrypt_set_error(mongocrypt_status_t *status,
|
47
|
+
mongocrypt_status_type_t type,
|
48
|
+
uint32_t code,
|
49
|
+
const char *format,
|
50
|
+
...) {
|
51
|
+
va_list args;
|
52
|
+
char *prepared_message;
|
53
|
+
|
54
|
+
if (status) {
|
55
|
+
va_start(args, format);
|
56
|
+
prepared_message = bson_strdupv_printf(format, args);
|
57
|
+
if (!prepared_message) {
|
58
|
+
mongocrypt_status_set(status, type, code, "Out of memory", -1);
|
59
|
+
} else {
|
60
|
+
mongocrypt_status_set(status, type, code, prepared_message, -1);
|
61
|
+
bson_free(prepared_message);
|
62
|
+
}
|
63
|
+
va_end(args);
|
64
|
+
}
|
47
65
|
}
|
48
66
|
|
67
|
+
const char *tmp_json(const bson_t *bson) {
|
68
|
+
static char storage[1024];
|
69
|
+
char *json;
|
70
|
+
|
71
|
+
BSON_ASSERT_PARAM(bson);
|
49
72
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
...)
|
56
|
-
{
|
57
|
-
va_list args;
|
58
|
-
char *prepared_message;
|
59
|
-
|
60
|
-
if (status) {
|
61
|
-
va_start (args, format);
|
62
|
-
prepared_message = bson_strdupv_printf (format, args);
|
63
|
-
if (!prepared_message) {
|
64
|
-
mongocrypt_status_set (status, type, code, "Out of memory", -1);
|
65
|
-
} else {
|
66
|
-
mongocrypt_status_set (status, type, code, prepared_message, -1);
|
67
|
-
bson_free (prepared_message);
|
68
|
-
}
|
69
|
-
va_end (args);
|
70
|
-
}
|
73
|
+
memset(storage, 0, 1024);
|
74
|
+
json = bson_as_canonical_extended_json(bson, NULL);
|
75
|
+
bson_snprintf(storage, sizeof(storage), "%s", json);
|
76
|
+
bson_free(json);
|
77
|
+
return (const char *)storage;
|
71
78
|
}
|
72
79
|
|
80
|
+
const char *tmp_buf(const _mongocrypt_buffer_t *buf) {
|
81
|
+
static char storage[1024];
|
82
|
+
size_t i, n;
|
73
83
|
|
74
|
-
|
75
|
-
tmp_json (const bson_t *bson)
|
76
|
-
{
|
77
|
-
static char storage[1024];
|
78
|
-
char *json;
|
84
|
+
BSON_ASSERT_PARAM(buf);
|
79
85
|
|
80
|
-
|
86
|
+
memset(storage, 0, 1024);
|
87
|
+
/* capped at two characters per byte, minus 1 for trailing \0 */
|
88
|
+
n = sizeof(storage) / 2 - 1;
|
89
|
+
if (buf->len < n) {
|
90
|
+
n = buf->len;
|
91
|
+
}
|
81
92
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
93
|
+
for (i = 0; i < n; i++) {
|
94
|
+
bson_snprintf(storage + (i * 2), 3, "%02x", buf->data[i]);
|
95
|
+
}
|
96
|
+
|
97
|
+
return (const char *)storage;
|
87
98
|
}
|
88
99
|
|
100
|
+
static void _mongocrypt_do_init(void) {
|
101
|
+
(void)kms_message_init();
|
102
|
+
_native_crypto_init();
|
103
|
+
}
|
89
104
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
105
|
+
mongocrypt_t *mongocrypt_new(void) {
|
106
|
+
mongocrypt_t *crypt;
|
107
|
+
|
108
|
+
crypt = bson_malloc0(sizeof(mongocrypt_t));
|
109
|
+
BSON_ASSERT(crypt);
|
110
|
+
crypt->crypto = bson_malloc0(sizeof(*crypt->crypto));
|
111
|
+
BSON_ASSERT(crypt->crypto);
|
112
|
+
|
113
|
+
_mongocrypt_mutex_init(&crypt->mutex);
|
114
|
+
_mongocrypt_cache_collinfo_init(&crypt->cache_collinfo);
|
115
|
+
_mongocrypt_cache_key_init(&crypt->cache_key);
|
116
|
+
crypt->status = mongocrypt_status_new();
|
117
|
+
_mongocrypt_opts_init(&crypt->opts);
|
118
|
+
_mongocrypt_log_init(&crypt->log);
|
119
|
+
// Default to using FLEv2 (aka QEv2)
|
120
|
+
crypt->opts.use_fle2_v2 = true;
|
121
|
+
crypt->ctx_counter = 1;
|
122
|
+
crypt->cache_oauth = mc_mapof_kmsid_to_token_new();
|
123
|
+
crypt->csfle = (_mongo_crypt_v1_vtable){.okay = false};
|
124
|
+
|
125
|
+
static mlib_once_flag init_flag = MLIB_ONCE_INITIALIZER;
|
126
|
+
|
127
|
+
if (!mlib_call_once(&init_flag, _mongocrypt_do_init) || !_native_crypto_initialized) {
|
128
|
+
mongocrypt_status_t *status = crypt->status;
|
129
|
+
|
130
|
+
CLIENT_ERR("failed to initialize");
|
131
|
+
/* Return crypt with failure status so caller can obtain error when
|
132
|
+
* calling mongocrypt_init */
|
133
|
+
}
|
134
|
+
|
135
|
+
return crypt;
|
136
|
+
}
|
95
137
|
|
96
|
-
|
138
|
+
#define ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt) \
|
139
|
+
{ \
|
140
|
+
const mongocrypt_t *_crypt = (crypt); \
|
141
|
+
BSON_ASSERT_PARAM(_crypt); \
|
142
|
+
if (_crypt->initialized) { \
|
143
|
+
mongocrypt_status_t *status = _crypt->status; \
|
144
|
+
CLIENT_ERR("options cannot be set after initialization"); \
|
145
|
+
return false; \
|
146
|
+
} \
|
147
|
+
}
|
148
|
+
|
149
|
+
bool mongocrypt_setopt_fle2v2(mongocrypt_t *crypt, bool enable) {
|
150
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
151
|
+
|
152
|
+
crypt->opts.use_fle2_v2 = enable;
|
153
|
+
return true;
|
154
|
+
}
|
97
155
|
|
98
|
-
|
99
|
-
|
100
|
-
n = sizeof (storage) / 2 - 1;
|
101
|
-
if (buf->len < n) {
|
102
|
-
n = buf->len;
|
103
|
-
}
|
156
|
+
bool mongocrypt_setopt_use_range_v2(mongocrypt_t *crypt) {
|
157
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
104
158
|
|
105
|
-
|
106
|
-
|
107
|
-
|
159
|
+
// Nothing to do. As of MONGOCRYPT-661, rangeV2 is the default.
|
160
|
+
return true;
|
161
|
+
}
|
108
162
|
|
109
|
-
|
163
|
+
bool mongocrypt_setopt_log_handler(mongocrypt_t *crypt, mongocrypt_log_fn_t log_fn, void *log_ctx) {
|
164
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
165
|
+
crypt->opts.log_fn = log_fn;
|
166
|
+
crypt->opts.log_ctx = log_ctx;
|
167
|
+
return true;
|
110
168
|
}
|
111
169
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
170
|
+
bool mongocrypt_setopt_kms_provider_aws(mongocrypt_t *crypt,
|
171
|
+
const char *aws_access_key_id,
|
172
|
+
int32_t aws_access_key_id_len,
|
173
|
+
const char *aws_secret_access_key,
|
174
|
+
int32_t aws_secret_access_key_len) {
|
175
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
176
|
+
|
177
|
+
mongocrypt_status_t *status = crypt->status;
|
178
|
+
_mongocrypt_opts_kms_providers_t *const kms_providers = &crypt->opts.kms_providers;
|
179
|
+
|
180
|
+
if (0 != (kms_providers->configured_providers & MONGOCRYPT_KMS_PROVIDER_AWS)) {
|
181
|
+
CLIENT_ERR("aws kms provider already set");
|
182
|
+
return false;
|
183
|
+
}
|
184
|
+
|
185
|
+
if (!_mongocrypt_validate_and_copy_string(aws_access_key_id,
|
186
|
+
aws_access_key_id_len,
|
187
|
+
&kms_providers->aws_mut.access_key_id)) {
|
188
|
+
CLIENT_ERR("invalid aws access key id");
|
189
|
+
return false;
|
190
|
+
}
|
191
|
+
|
192
|
+
if (!_mongocrypt_validate_and_copy_string(aws_secret_access_key,
|
193
|
+
aws_secret_access_key_len,
|
194
|
+
&kms_providers->aws_mut.secret_access_key)) {
|
195
|
+
CLIENT_ERR("invalid aws secret access key");
|
196
|
+
return false;
|
197
|
+
}
|
198
|
+
|
199
|
+
if (crypt->log.trace_enabled) {
|
200
|
+
_mongocrypt_log(&crypt->log,
|
201
|
+
MONGOCRYPT_LOG_LEVEL_TRACE,
|
202
|
+
"%s (%s=\"%s\", %s=%d, %s=\"%s\", %s=%d)",
|
203
|
+
BSON_FUNC,
|
204
|
+
"aws_access_key_id",
|
205
|
+
kms_providers->aws_mut.access_key_id,
|
206
|
+
"aws_access_key_id_len",
|
207
|
+
aws_access_key_id_len,
|
208
|
+
"aws_secret_access_key",
|
209
|
+
kms_providers->aws_mut.secret_access_key,
|
210
|
+
"aws_secret_access_key_len",
|
211
|
+
aws_secret_access_key_len);
|
212
|
+
}
|
213
|
+
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_AWS;
|
214
|
+
return true;
|
117
215
|
}
|
118
216
|
|
217
|
+
char *_mongocrypt_new_string_from_bytes(const void *in, int len) {
|
218
|
+
const int max_bytes = 100;
|
219
|
+
const int chars_per_byte = 2;
|
220
|
+
int out_size = max_bytes * chars_per_byte;
|
221
|
+
const unsigned char *src = in;
|
222
|
+
char *out;
|
223
|
+
char *ret;
|
119
224
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
mongocrypt_t *crypt;
|
225
|
+
out_size += len > max_bytes ? (int)sizeof("...") : 1 /* for null */;
|
226
|
+
out = bson_malloc0((size_t)out_size);
|
227
|
+
BSON_ASSERT(out);
|
124
228
|
|
125
|
-
|
126
|
-
BSON_ASSERT (crypt);
|
127
|
-
crypt->crypto = bson_malloc0 (sizeof (*crypt->crypto));
|
128
|
-
BSON_ASSERT (crypt->crypto);
|
229
|
+
ret = out;
|
129
230
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
crypt->status = mongocrypt_status_new ();
|
134
|
-
_mongocrypt_opts_init (&crypt->opts);
|
135
|
-
_mongocrypt_log_init (&crypt->log);
|
136
|
-
crypt->ctx_counter = 1;
|
137
|
-
crypt->cache_oauth_azure = _mongocrypt_cache_oauth_new ();
|
138
|
-
crypt->cache_oauth_gcp = _mongocrypt_cache_oauth_new ();
|
139
|
-
crypt->csfle = (_mongo_crypt_v1_vtable){.okay = false};
|
231
|
+
for (int i = 0; i < len && i < max_bytes; i++, out += chars_per_byte) {
|
232
|
+
sprintf(out, "%02X", src[i]);
|
233
|
+
}
|
140
234
|
|
141
|
-
|
235
|
+
sprintf(out, (len > max_bytes) ? "..." : "");
|
236
|
+
return ret;
|
237
|
+
}
|
142
238
|
|
143
|
-
|
144
|
-
|
145
|
-
|
239
|
+
char *_mongocrypt_new_json_string_from_binary(mongocrypt_binary_t *binary) {
|
240
|
+
bson_t bson;
|
241
|
+
uint32_t len;
|
146
242
|
|
147
|
-
|
148
|
-
/* Return crypt with failure status so caller can obtain error when
|
149
|
-
* calling mongocrypt_init */
|
150
|
-
}
|
243
|
+
BSON_ASSERT_PARAM(binary);
|
151
244
|
|
152
|
-
|
245
|
+
if (!_mongocrypt_binary_to_bson(binary, &bson) || !bson_validate(&bson, BSON_VALIDATE_NONE, NULL)) {
|
246
|
+
char *hex;
|
247
|
+
char *full_str;
|
248
|
+
|
249
|
+
BSON_ASSERT(binary->len <= (uint32_t)INT_MAX);
|
250
|
+
hex = _mongocrypt_new_string_from_bytes(binary->data, (int)binary->len);
|
251
|
+
full_str = bson_strdup_printf("(malformed) %s", hex);
|
252
|
+
bson_free(hex);
|
253
|
+
return full_str;
|
254
|
+
}
|
255
|
+
return bson_as_canonical_extended_json(&bson, (size_t *)&len);
|
153
256
|
}
|
154
257
|
|
258
|
+
bool mongocrypt_setopt_schema_map(mongocrypt_t *crypt, mongocrypt_binary_t *schema_map) {
|
259
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
155
260
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
void *log_ctx)
|
160
|
-
{
|
161
|
-
if (!crypt) {
|
162
|
-
return false;
|
163
|
-
}
|
164
|
-
|
165
|
-
if (crypt->initialized) {
|
166
|
-
mongocrypt_status_t *status = crypt->status;
|
167
|
-
CLIENT_ERR ("options cannot be set after initialization");
|
168
|
-
return false;
|
169
|
-
}
|
170
|
-
crypt->opts.log_fn = log_fn;
|
171
|
-
crypt->opts.log_ctx = log_ctx;
|
172
|
-
return true;
|
173
|
-
}
|
261
|
+
bson_t tmp;
|
262
|
+
bson_error_t bson_err;
|
263
|
+
mongocrypt_status_t *status = crypt->status;
|
174
264
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
const char *aws_secret_access_key,
|
180
|
-
int32_t aws_secret_access_key_len)
|
181
|
-
{
|
182
|
-
BSON_ASSERT_PARAM (crypt);
|
183
|
-
|
184
|
-
mongocrypt_status_t *status = crypt->status;
|
185
|
-
_mongocrypt_opts_kms_providers_t *const kms_providers =
|
186
|
-
&crypt->opts.kms_providers;
|
187
|
-
|
188
|
-
if (crypt->initialized) {
|
189
|
-
CLIENT_ERR ("options cannot be set after initialization");
|
190
|
-
return false;
|
191
|
-
}
|
192
|
-
|
193
|
-
if (0 !=
|
194
|
-
(kms_providers->configured_providers & MONGOCRYPT_KMS_PROVIDER_AWS)) {
|
195
|
-
CLIENT_ERR ("aws kms provider already set");
|
196
|
-
return false;
|
197
|
-
}
|
198
|
-
|
199
|
-
if (!_mongocrypt_validate_and_copy_string (
|
200
|
-
aws_access_key_id,
|
201
|
-
aws_access_key_id_len,
|
202
|
-
&kms_providers->aws.access_key_id)) {
|
203
|
-
CLIENT_ERR ("invalid aws access key id");
|
204
|
-
return false;
|
205
|
-
}
|
206
|
-
|
207
|
-
if (!_mongocrypt_validate_and_copy_string (
|
208
|
-
aws_secret_access_key,
|
209
|
-
aws_secret_access_key_len,
|
210
|
-
&kms_providers->aws.secret_access_key)) {
|
211
|
-
CLIENT_ERR ("invalid aws secret access key");
|
212
|
-
return false;
|
213
|
-
}
|
214
|
-
|
215
|
-
if (crypt->log.trace_enabled) {
|
216
|
-
_mongocrypt_log (&crypt->log,
|
217
|
-
MONGOCRYPT_LOG_LEVEL_TRACE,
|
218
|
-
"%s (%s=\"%s\", %s=%d, %s=\"%s\", %s=%d)",
|
219
|
-
BSON_FUNC,
|
220
|
-
"aws_access_key_id",
|
221
|
-
kms_providers->aws.access_key_id,
|
222
|
-
"aws_access_key_id_len",
|
223
|
-
aws_access_key_id_len,
|
224
|
-
"aws_secret_access_key",
|
225
|
-
kms_providers->aws.secret_access_key,
|
226
|
-
"aws_secret_access_key_len",
|
227
|
-
aws_secret_access_key_len);
|
228
|
-
}
|
229
|
-
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_AWS;
|
230
|
-
return true;
|
231
|
-
}
|
265
|
+
if (!schema_map || !mongocrypt_binary_data(schema_map)) {
|
266
|
+
CLIENT_ERR("passed null schema map");
|
267
|
+
return false;
|
268
|
+
}
|
232
269
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
const int chars_per_byte = 2;
|
238
|
-
int out_size = max_bytes * chars_per_byte;
|
239
|
-
const unsigned char *src = in;
|
240
|
-
char *out;
|
241
|
-
char *ret;
|
270
|
+
if (!_mongocrypt_buffer_empty(&crypt->opts.schema_map)) {
|
271
|
+
CLIENT_ERR("already set schema map");
|
272
|
+
return false;
|
273
|
+
}
|
242
274
|
|
243
|
-
|
244
|
-
out = bson_malloc0 ((size_t) out_size);
|
245
|
-
BSON_ASSERT (out);
|
275
|
+
_mongocrypt_buffer_copy_from_binary(&crypt->opts.schema_map, schema_map);
|
246
276
|
|
247
|
-
|
277
|
+
/* validate bson */
|
278
|
+
if (!_mongocrypt_buffer_to_bson(&crypt->opts.schema_map, &tmp)) {
|
279
|
+
CLIENT_ERR("invalid bson");
|
280
|
+
return false;
|
281
|
+
}
|
248
282
|
|
249
|
-
|
250
|
-
|
251
|
-
|
283
|
+
if (!bson_validate_with_error(&tmp, BSON_VALIDATE_NONE, &bson_err)) {
|
284
|
+
CLIENT_ERR("%s", bson_err.message);
|
285
|
+
return false;
|
286
|
+
}
|
252
287
|
|
253
|
-
|
254
|
-
return ret;
|
288
|
+
return true;
|
255
289
|
}
|
256
290
|
|
257
|
-
|
258
|
-
|
259
|
-
{
|
260
|
-
bson_t bson;
|
261
|
-
uint32_t len;
|
262
|
-
|
263
|
-
BSON_ASSERT_PARAM (binary);
|
264
|
-
|
265
|
-
if (!_mongocrypt_binary_to_bson (binary, &bson) ||
|
266
|
-
!bson_validate (&bson, BSON_VALIDATE_NONE, NULL)) {
|
267
|
-
char *hex;
|
268
|
-
char *full_str;
|
269
|
-
|
270
|
-
BSON_ASSERT (binary->len <= (uint32_t) INT_MAX);
|
271
|
-
hex = _mongocrypt_new_string_from_bytes (binary->data, (int) binary->len);
|
272
|
-
full_str = bson_strdup_printf ("(malformed) %s", hex);
|
273
|
-
bson_free (hex);
|
274
|
-
return full_str;
|
275
|
-
}
|
276
|
-
return bson_as_canonical_extended_json (&bson, (size_t *) &len);
|
277
|
-
}
|
291
|
+
bool mongocrypt_setopt_encrypted_field_config_map(mongocrypt_t *crypt, mongocrypt_binary_t *efc_map) {
|
292
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
278
293
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
if (!schema_map || !mongocrypt_binary_data (schema_map)) {
|
295
|
-
CLIENT_ERR ("passed null schema map");
|
296
|
-
return false;
|
297
|
-
}
|
298
|
-
|
299
|
-
if (!_mongocrypt_buffer_empty (&crypt->opts.schema_map)) {
|
300
|
-
CLIENT_ERR ("already set schema map");
|
301
|
-
return false;
|
302
|
-
}
|
303
|
-
|
304
|
-
_mongocrypt_buffer_copy_from_binary (&crypt->opts.schema_map, schema_map);
|
305
|
-
|
306
|
-
/* validate bson */
|
307
|
-
if (!_mongocrypt_buffer_to_bson (&crypt->opts.schema_map, &tmp)) {
|
308
|
-
CLIENT_ERR ("invalid bson");
|
309
|
-
return false;
|
310
|
-
}
|
311
|
-
|
312
|
-
if (!bson_validate_with_error (&tmp, BSON_VALIDATE_NONE, &bson_err)) {
|
313
|
-
CLIENT_ERR ("%s", bson_err.message);
|
314
|
-
return false;
|
315
|
-
}
|
316
|
-
|
317
|
-
return true;
|
318
|
-
}
|
294
|
+
mongocrypt_status_t *status = crypt->status;
|
295
|
+
bson_t as_bson;
|
296
|
+
bson_error_t bson_err;
|
297
|
+
|
298
|
+
if (!efc_map || !mongocrypt_binary_data(efc_map)) {
|
299
|
+
CLIENT_ERR("passed null encrypted_field_config_map");
|
300
|
+
return false;
|
301
|
+
}
|
302
|
+
|
303
|
+
if (!_mongocrypt_buffer_empty(&crypt->opts.encrypted_field_config_map)) {
|
304
|
+
CLIENT_ERR("already set encrypted_field_config_map");
|
305
|
+
return false;
|
306
|
+
}
|
307
|
+
|
308
|
+
_mongocrypt_buffer_copy_from_binary(&crypt->opts.encrypted_field_config_map, efc_map);
|
319
309
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
return false;
|
333
|
-
}
|
334
|
-
|
335
|
-
if (!efc_map || !mongocrypt_binary_data (efc_map)) {
|
336
|
-
CLIENT_ERR ("passed null encrypted_field_config_map");
|
337
|
-
return false;
|
338
|
-
}
|
339
|
-
|
340
|
-
if (!_mongocrypt_buffer_empty (&crypt->opts.encrypted_field_config_map)) {
|
341
|
-
CLIENT_ERR ("already set encrypted_field_config_map");
|
342
|
-
return false;
|
343
|
-
}
|
344
|
-
|
345
|
-
_mongocrypt_buffer_copy_from_binary (&crypt->opts.encrypted_field_config_map,
|
346
|
-
efc_map);
|
347
|
-
|
348
|
-
/* validate bson */
|
349
|
-
if (!_mongocrypt_buffer_to_bson (&crypt->opts.encrypted_field_config_map,
|
350
|
-
&as_bson)) {
|
351
|
-
CLIENT_ERR ("invalid bson");
|
352
|
-
return false;
|
353
|
-
}
|
354
|
-
|
355
|
-
if (!bson_validate_with_error (&as_bson, BSON_VALIDATE_NONE, &bson_err)) {
|
356
|
-
CLIENT_ERR ("%s", bson_err.message);
|
357
|
-
return false;
|
358
|
-
}
|
359
|
-
|
360
|
-
return true;
|
310
|
+
/* validate bson */
|
311
|
+
if (!_mongocrypt_buffer_to_bson(&crypt->opts.encrypted_field_config_map, &as_bson)) {
|
312
|
+
CLIENT_ERR("invalid bson");
|
313
|
+
return false;
|
314
|
+
}
|
315
|
+
|
316
|
+
if (!bson_validate_with_error(&as_bson, BSON_VALIDATE_NONE, &bson_err)) {
|
317
|
+
CLIENT_ERR("%s", bson_err.message);
|
318
|
+
return false;
|
319
|
+
}
|
320
|
+
|
321
|
+
return true;
|
361
322
|
}
|
362
323
|
|
363
|
-
bool
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
BSON_ASSERT (key->len <= (uint32_t) INT_MAX);
|
397
|
-
key_val = _mongocrypt_new_string_from_bytes (key->data, (int) key->len);
|
398
|
-
|
399
|
-
_mongocrypt_log (&crypt->log,
|
400
|
-
MONGOCRYPT_LOG_LEVEL_TRACE,
|
401
|
-
"%s (%s=\"%s\")",
|
402
|
-
BSON_FUNC,
|
403
|
-
"key",
|
404
|
-
key_val);
|
405
|
-
bson_free (key_val);
|
406
|
-
}
|
407
|
-
|
408
|
-
_mongocrypt_buffer_copy_from_binary (&kms_providers->local.key, key);
|
409
|
-
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_LOCAL;
|
410
|
-
return true;
|
324
|
+
bool mongocrypt_setopt_kms_provider_local(mongocrypt_t *crypt, mongocrypt_binary_t *key) {
|
325
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
326
|
+
|
327
|
+
mongocrypt_status_t *status = crypt->status;
|
328
|
+
_mongocrypt_opts_kms_providers_t *const kms_providers = &crypt->opts.kms_providers;
|
329
|
+
|
330
|
+
if (0 != (kms_providers->configured_providers & MONGOCRYPT_KMS_PROVIDER_LOCAL)) {
|
331
|
+
CLIENT_ERR("local kms provider already set");
|
332
|
+
return false;
|
333
|
+
}
|
334
|
+
|
335
|
+
if (!key) {
|
336
|
+
CLIENT_ERR("passed null key");
|
337
|
+
return false;
|
338
|
+
}
|
339
|
+
|
340
|
+
if (mongocrypt_binary_len(key) != MONGOCRYPT_KEY_LEN) {
|
341
|
+
CLIENT_ERR("local key must be %d bytes", MONGOCRYPT_KEY_LEN);
|
342
|
+
return false;
|
343
|
+
}
|
344
|
+
|
345
|
+
if (crypt->log.trace_enabled) {
|
346
|
+
char *key_val;
|
347
|
+
BSON_ASSERT(key->len <= (uint32_t)INT_MAX);
|
348
|
+
key_val = _mongocrypt_new_string_from_bytes(key->data, (int)key->len);
|
349
|
+
|
350
|
+
_mongocrypt_log(&crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "key", key_val);
|
351
|
+
bson_free(key_val);
|
352
|
+
}
|
353
|
+
|
354
|
+
_mongocrypt_buffer_copy_from_binary(&kms_providers->local_mut.key, key);
|
355
|
+
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_LOCAL;
|
356
|
+
return true;
|
411
357
|
}
|
412
358
|
|
413
359
|
typedef struct {
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
360
|
+
/// Whether the load is successful
|
361
|
+
bool okay;
|
362
|
+
/// The DLL handle to the opened library.
|
363
|
+
mcr_dll lib;
|
364
|
+
/// A vtable for the functions in the DLL
|
365
|
+
_mongo_crypt_v1_vtable vtable;
|
420
366
|
} _loaded_csfle;
|
421
367
|
|
422
368
|
/**
|
423
369
|
* @brief Attempt to open the CSFLE dynamic library and initialize a vtable for
|
424
370
|
* it.
|
371
|
+
*
|
372
|
+
* @param status is an optional status to set an error message if `mcr_dll_open` fails.
|
425
373
|
*/
|
426
|
-
static _loaded_csfle
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
/* Mark the vtable as broken, but keep trying to load more symbols to \
|
468
|
-
* produce error messages for all missing symbols */ \
|
469
|
-
vtable.okay = false; \
|
470
|
-
} \
|
471
|
-
}
|
472
|
-
MONGOC_CSFLE_FUNCTIONS_X
|
374
|
+
static _loaded_csfle _try_load_csfle(const char *filepath, mongocrypt_status_t *status, _mongocrypt_log_t *log) {
|
375
|
+
// Try to open the dynamic lib
|
376
|
+
mcr_dll lib = mcr_dll_open(filepath);
|
377
|
+
// Check for errors, which are represented by strings
|
378
|
+
if (lib.error_string.data) {
|
379
|
+
// Error opening candidate
|
380
|
+
_mongocrypt_log(log,
|
381
|
+
MONGOCRYPT_LOG_LEVEL_WARNING,
|
382
|
+
"Error while opening candidate for CSFLE dynamic library [%s]: %s",
|
383
|
+
filepath,
|
384
|
+
lib.error_string.data);
|
385
|
+
CLIENT_ERR("Error while opening candidate for CSFLE dynamic library [%s]: %s", filepath, lib.error_string.data);
|
386
|
+
// Free resources, which will include the error string
|
387
|
+
mcr_dll_close(lib);
|
388
|
+
// Bad:
|
389
|
+
return (_loaded_csfle){.okay = false};
|
390
|
+
}
|
391
|
+
|
392
|
+
// Successfully opened DLL
|
393
|
+
_mongocrypt_log(log, MONGOCRYPT_LOG_LEVEL_TRACE, "Loading CSFLE dynamic library [%s]", filepath);
|
394
|
+
|
395
|
+
// Construct the library vtable
|
396
|
+
_mongo_crypt_v1_vtable vtable = {.okay = true};
|
397
|
+
#define X_FUNC(Name, RetType, ...) \
|
398
|
+
{ \
|
399
|
+
/* Symbol names are qualified by the lib name and version: */ \
|
400
|
+
const char *symname = "mongo_crypt_v1_" #Name; \
|
401
|
+
vtable.Name = mcr_dll_sym(lib, symname); \
|
402
|
+
if (vtable.Name == NULL) { \
|
403
|
+
/* The requested symbol is not present */ \
|
404
|
+
_mongocrypt_log(log, \
|
405
|
+
MONGOCRYPT_LOG_LEVEL_ERROR, \
|
406
|
+
"Missing required symbol '%s' from CSFLE dynamic library [%s]", \
|
407
|
+
symname, \
|
408
|
+
filepath); \
|
409
|
+
/* Mark the vtable as broken, but keep trying to load more symbols to \
|
410
|
+
* produce error messages for all missing symbols */ \
|
411
|
+
vtable.okay = false; \
|
412
|
+
} \
|
413
|
+
}
|
414
|
+
MONGOC_CSFLE_FUNCTIONS_X
|
473
415
|
#undef X_FUNC
|
474
416
|
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
MONGOCRYPT_LOG_LEVEL_INFO,
|
489
|
-
"Opened CSFLE dynamic library [%s]",
|
490
|
-
filepath);
|
491
|
-
return (_loaded_csfle){.okay = true, .lib = lib, .vtable = vtable};
|
417
|
+
if (!vtable.okay) {
|
418
|
+
mcr_dll_close(lib);
|
419
|
+
_mongocrypt_log(log,
|
420
|
+
MONGOCRYPT_LOG_LEVEL_ERROR,
|
421
|
+
"One or more required symbols are missing from CSFLE dynamic library "
|
422
|
+
"[%s], so this dynamic library will not be used.",
|
423
|
+
filepath);
|
424
|
+
return (_loaded_csfle){.okay = false};
|
425
|
+
}
|
426
|
+
|
427
|
+
// Success!
|
428
|
+
_mongocrypt_log(log, MONGOCRYPT_LOG_LEVEL_INFO, "Opened CSFLE dynamic library [%s]", filepath);
|
429
|
+
return (_loaded_csfle){.okay = true, .lib = lib, .vtable = vtable};
|
492
430
|
}
|
493
431
|
|
494
432
|
/**
|
@@ -498,120 +436,108 @@ _try_load_csfle (const char *filepath, _mongocrypt_log_t *log)
|
|
498
436
|
* @return true If no error occurred and the path is valid
|
499
437
|
* @return false If there was an error and `filepath` cannot be processed
|
500
438
|
*/
|
501
|
-
static bool
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
mstr_free (self_exe_r.path);
|
535
|
-
return true;
|
439
|
+
static bool _try_replace_dollar_origin(mstr *filepath, _mongocrypt_log_t *log) {
|
440
|
+
const mstr_view dollar_origin = mstrv_lit("$ORIGIN");
|
441
|
+
|
442
|
+
BSON_ASSERT_PARAM(filepath);
|
443
|
+
|
444
|
+
if (!mstr_starts_with(filepath->view, dollar_origin)) {
|
445
|
+
// Nothing to replace
|
446
|
+
return true;
|
447
|
+
}
|
448
|
+
// Check that the next char is a path separator or end-of-string:
|
449
|
+
char peek = filepath->data[dollar_origin.len];
|
450
|
+
if (peek != 0 && !mpath_is_sep(peek, MPATH_NATIVE)) {
|
451
|
+
// Not a single path element
|
452
|
+
return true;
|
453
|
+
}
|
454
|
+
// Replace $ORIGIN with the directory of the current module
|
455
|
+
const current_module_result self_exe_r = current_module_path();
|
456
|
+
if (self_exe_r.error) {
|
457
|
+
// Failed to get the current module to load replace $ORIGIN
|
458
|
+
mstr error = merror_system_error_string(self_exe_r.error);
|
459
|
+
_mongocrypt_log(log,
|
460
|
+
MONGOCRYPT_LOG_LEVEL_WARNING,
|
461
|
+
"Error while loading the executable module path for "
|
462
|
+
"substitution of $ORIGIN in CSFLE search path [%s]: %s",
|
463
|
+
filepath->data,
|
464
|
+
error.data);
|
465
|
+
mstr_free(error);
|
466
|
+
return false;
|
467
|
+
}
|
468
|
+
const mstr_view self_dir = mpath_parent(self_exe_r.path.view, MPATH_NATIVE);
|
469
|
+
mstr_inplace_splice(filepath, 0, dollar_origin.len, self_dir);
|
470
|
+
mstr_free(self_exe_r.path);
|
471
|
+
return true;
|
536
472
|
}
|
537
473
|
|
538
|
-
static _loaded_csfle
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
mstr_assign (&csfle_cand_filepath,
|
573
|
-
mpath_join (cand_dir, csfle_filename, MPATH_NATIVE));
|
574
|
-
if (!_try_replace_dollar_origin (&csfle_cand_filepath,
|
575
|
-
&crypt->log)) {
|
576
|
-
// Error while substituting $ORIGIN
|
577
|
-
continue;
|
474
|
+
static _loaded_csfle _try_find_csfle(mongocrypt_t *crypt) {
|
475
|
+
_loaded_csfle candidate_csfle = {0};
|
476
|
+
mstr csfle_cand_filepath = MSTR_NULL;
|
477
|
+
|
478
|
+
BSON_ASSERT_PARAM(crypt);
|
479
|
+
|
480
|
+
if (crypt->opts.crypt_shared_lib_override_path.data) {
|
481
|
+
// If an override path was specified, skip the library searching behavior
|
482
|
+
csfle_cand_filepath = mstr_copy(crypt->opts.crypt_shared_lib_override_path.view);
|
483
|
+
if (_try_replace_dollar_origin(&csfle_cand_filepath, &crypt->log)) {
|
484
|
+
// Succesfully substituted $ORIGIN
|
485
|
+
// Do not allow a plain filename to go through, as that will cause the
|
486
|
+
// DLL load to search the system.
|
487
|
+
mstr_assign(&csfle_cand_filepath, mpath_absolute(csfle_cand_filepath.view, MPATH_NATIVE));
|
488
|
+
candidate_csfle = _try_load_csfle(csfle_cand_filepath.data, crypt->status, &crypt->log);
|
489
|
+
}
|
490
|
+
} else {
|
491
|
+
// No override path was specified, so try to find it on the provided
|
492
|
+
// search paths.
|
493
|
+
for (int i = 0; i < crypt->opts.n_crypt_shared_lib_search_paths; ++i) {
|
494
|
+
mstr_view cand_dir = crypt->opts.crypt_shared_lib_search_paths[i].view;
|
495
|
+
mstr_view csfle_filename = mstrv_lit("mongo_crypt_v1" MCR_DLL_SUFFIX);
|
496
|
+
if (mstr_eq(cand_dir, mstrv_lit("$SYSTEM"))) {
|
497
|
+
// Caller wants us to search for the library on the system's default
|
498
|
+
// library paths. Pass only the library's filename to cause dll_open
|
499
|
+
// to search on the library paths.
|
500
|
+
mstr_assign(&csfle_cand_filepath, mstr_copy(csfle_filename));
|
501
|
+
} else {
|
502
|
+
// Compose the candidate filepath:
|
503
|
+
mstr_assign(&csfle_cand_filepath, mpath_join(cand_dir, csfle_filename, MPATH_NATIVE));
|
504
|
+
if (!_try_replace_dollar_origin(&csfle_cand_filepath, &crypt->log)) {
|
505
|
+
// Error while substituting $ORIGIN
|
506
|
+
continue;
|
507
|
+
}
|
578
508
|
}
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
}
|
588
|
-
}
|
589
|
-
|
590
|
-
mstr_free (csfle_cand_filepath);
|
591
|
-
return candidate_csfle;
|
592
|
-
}
|
509
|
+
// Try to load the file:
|
510
|
+
candidate_csfle = _try_load_csfle(csfle_cand_filepath.data, NULL /* status */, &crypt->log);
|
511
|
+
if (candidate_csfle.okay) {
|
512
|
+
// Stop searching:
|
513
|
+
break;
|
514
|
+
}
|
515
|
+
}
|
516
|
+
}
|
593
517
|
|
518
|
+
mstr_free(csfle_cand_filepath);
|
519
|
+
return candidate_csfle;
|
520
|
+
}
|
594
521
|
|
595
522
|
/// Global state for the application's csfle library
|
596
523
|
typedef struct csfle_global_lib_state {
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
524
|
+
/// Synchronization around the reference count:
|
525
|
+
mongocrypt_mutex_t mtx;
|
526
|
+
int refcount;
|
527
|
+
/// The open library handle:
|
528
|
+
mcr_dll dll;
|
529
|
+
/// vtable for the APIs:
|
530
|
+
_mongo_crypt_v1_vtable vtable;
|
531
|
+
/// The global library state managed by the csfle library:
|
532
|
+
mongo_crypt_v1_lib *csfle_lib;
|
606
533
|
} csfle_global_lib_state;
|
607
534
|
|
608
535
|
csfle_global_lib_state g_csfle_state;
|
609
536
|
|
610
|
-
static void
|
611
|
-
|
612
|
-
{
|
613
|
-
_mongocrypt_mutex_init (&g_csfle_state.mtx);
|
537
|
+
static void init_csfle_state(void) {
|
538
|
+
_mongocrypt_mutex_init(&g_csfle_state.mtx);
|
614
539
|
}
|
540
|
+
|
615
541
|
mlib_once_flag g_csfle_init_flag = MLIB_ONCE_INITIALIZER;
|
616
542
|
|
617
543
|
/**
|
@@ -627,52 +553,56 @@ mlib_once_flag g_csfle_init_flag = MLIB_ONCE_INITIALIZER;
|
|
627
553
|
* @note This function assumes that the global csfle state is valid and will not
|
628
554
|
* be destroyed by any other thread. (One must hold the reference count >= 1)
|
629
555
|
*/
|
630
|
-
static bool
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
556
|
+
static bool _validate_csfle_singleton(mongocrypt_t *crypt, _loaded_csfle found) {
|
557
|
+
mongocrypt_status_t *status;
|
558
|
+
|
559
|
+
BSON_ASSERT_PARAM(crypt);
|
560
|
+
|
561
|
+
if (!mcr_dll_path_supported()) {
|
562
|
+
_mongocrypt_log(&crypt->log,
|
563
|
+
MONGOCRYPT_LOG_LEVEL_WARNING,
|
564
|
+
"Cannot get path of loaded library on this platform. Skipping validation to ensure "
|
565
|
+
"exactly one csfle library is loaded.");
|
566
|
+
return true;
|
567
|
+
}
|
568
|
+
|
569
|
+
status = crypt->status;
|
570
|
+
|
571
|
+
// Path to the existing loaded csfle:
|
572
|
+
mcr_dll_path_result existing_path_ = mcr_dll_path(g_csfle_state.dll);
|
573
|
+
assert(existing_path_.path.data && "Failed to get path to already-loaded csfle library");
|
574
|
+
mstr_view existing_path = existing_path_.path.view;
|
575
|
+
bool okay = true;
|
576
|
+
if (!found.okay) {
|
577
|
+
// There is one loaded, but we failed to find that same library. Error:
|
578
|
+
CLIENT_ERR("An existing CSFLE library is loaded by the application at "
|
579
|
+
"[%s], but the current call to mongocrypt_init() failed to "
|
580
|
+
"find that same library.",
|
581
|
+
existing_path.data);
|
582
|
+
okay = false;
|
583
|
+
} else {
|
584
|
+
// Get the path to what we found:
|
585
|
+
mcr_dll_path_result found_path = mcr_dll_path(found.lib);
|
586
|
+
assert(found_path.path.data
|
587
|
+
&& "Failed to get the dynamic library filepath of the library that "
|
588
|
+
"was loaded for csfle");
|
589
|
+
if (!mstr_eq(found_path.path.view, existing_path)) {
|
590
|
+
// Our find-result should only ever find the existing same library.
|
591
|
+
// Error:
|
592
|
+
CLIENT_ERR("An existing CSFLE library is loaded by the application at [%s], "
|
593
|
+
"but the current call to mongocrypt_init() attempted to load a "
|
594
|
+
"second CSFLE library from [%s]. This is not allowed.",
|
595
|
+
existing_path.data,
|
596
|
+
found_path.path.data);
|
597
|
+
okay = false;
|
598
|
+
}
|
599
|
+
mstr_free(found_path.path);
|
600
|
+
mstr_free(found_path.error_string);
|
601
|
+
}
|
602
|
+
|
603
|
+
mstr_free(existing_path_.path);
|
604
|
+
mstr_free(existing_path_.error_string);
|
605
|
+
return okay;
|
676
606
|
}
|
677
607
|
|
678
608
|
/**
|
@@ -681,44 +611,35 @@ _validate_csfle_singleton (mongocrypt_t *crypt, _loaded_csfle found)
|
|
681
611
|
* This should be called as part of mongocrypt_t destruction following a
|
682
612
|
* successful loading of csfle.
|
683
613
|
*/
|
684
|
-
static void
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
if (dropped_last_ref) {
|
702
|
-
mongo_crypt_v1_status *status = old_state.vtable.status_create ();
|
703
|
-
const int destroy_rc =
|
704
|
-
old_state.vtable.lib_destroy (old_state.csfle_lib, status);
|
705
|
-
if (destroy_rc != MONGO_CRYPT_V1_SUCCESS && status) {
|
706
|
-
fprintf (stderr,
|
707
|
-
"csfle lib_destroy() failed: %s [Error %d, code %d]\n",
|
708
|
-
old_state.vtable.status_get_explanation (status),
|
709
|
-
old_state.vtable.status_get_error (status),
|
710
|
-
old_state.vtable.status_get_code (status));
|
711
|
-
}
|
712
|
-
old_state.vtable.status_destroy (status);
|
713
|
-
|
614
|
+
static void _csfle_drop_global_ref(void) {
|
615
|
+
mlib_call_once(&g_csfle_init_flag, init_csfle_state);
|
616
|
+
|
617
|
+
MONGOCRYPT_WITH_MUTEX(g_csfle_state.mtx) {
|
618
|
+
assert(g_csfle_state.refcount > 0);
|
619
|
+
int new_rc = --g_csfle_state.refcount;
|
620
|
+
if (new_rc == 0) {
|
621
|
+
mongo_crypt_v1_status *status = g_csfle_state.vtable.status_create();
|
622
|
+
const int destroy_rc = g_csfle_state.vtable.lib_destroy(g_csfle_state.csfle_lib, status);
|
623
|
+
if (destroy_rc != MONGO_CRYPT_V1_SUCCESS && status) {
|
624
|
+
fprintf(stderr,
|
625
|
+
"csfle lib_destroy() failed: %s [Error %d, code %d]\n",
|
626
|
+
g_csfle_state.vtable.status_get_explanation(status),
|
627
|
+
g_csfle_state.vtable.status_get_error(status),
|
628
|
+
g_csfle_state.vtable.status_get_code(status));
|
629
|
+
}
|
630
|
+
g_csfle_state.vtable.status_destroy(status);
|
714
631
|
#ifndef __linux__
|
715
|
-
|
632
|
+
mcr_dll_close(g_csfle_state.dll);
|
633
|
+
#else
|
634
|
+
/// NOTE: On Linux, skip closing the CSFLE library itself, since a bug in
|
635
|
+
/// the way ld-linux and GCC interact causes static destructors to not run
|
636
|
+
/// during dlclose(). Still, free the error string:
|
637
|
+
///
|
638
|
+
/// Please see: https://jira.mongodb.org/browse/SERVER-63710
|
639
|
+
mstr_free(g_csfle_state.dll.error_string);
|
716
640
|
#endif
|
717
|
-
|
718
|
-
|
719
|
-
/// during dlclose(). Still, free the error string:
|
720
|
-
mstr_free (old_state.dll.error_string);
|
721
|
-
}
|
641
|
+
}
|
642
|
+
}
|
722
643
|
}
|
723
644
|
|
724
645
|
/**
|
@@ -755,132 +676,122 @@ _csfle_drop_global_ref (void)
|
|
755
676
|
* the library referenced by `found`. The caller should release `found->lib`
|
756
677
|
* regardless.
|
757
678
|
*/
|
758
|
-
static bool
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
have_csfle = false;
|
875
|
-
break;
|
876
|
-
case DID_NOTHING:
|
877
|
-
default:
|
878
|
-
have_csfle = false;
|
879
|
-
break;
|
880
|
-
}
|
881
|
-
|
882
|
-
mstr_free (message);
|
883
|
-
return have_csfle;
|
679
|
+
static bool _csfle_replace_or_take_validate_singleton(mongocrypt_t *crypt, _loaded_csfle *found) {
|
680
|
+
mlib_call_once(&g_csfle_init_flag, init_csfle_state);
|
681
|
+
|
682
|
+
// If we have a loaded library, create a csfle_status object to use with
|
683
|
+
// lib_create
|
684
|
+
mongo_crypt_v1_status *csfle_status = NULL;
|
685
|
+
|
686
|
+
BSON_ASSERT_PARAM(crypt);
|
687
|
+
BSON_ASSERT_PARAM(found);
|
688
|
+
|
689
|
+
if (found->okay) {
|
690
|
+
// Create the status. Note that this may fail, so do not assume
|
691
|
+
// csfle_status is non-null.
|
692
|
+
csfle_status = found->vtable.status_create();
|
693
|
+
}
|
694
|
+
|
695
|
+
/**
|
696
|
+
* Atomically:
|
697
|
+
*
|
698
|
+
* 1. If there is an existing global library, increment its reference count.
|
699
|
+
* 2. Otherwise, if we have successfully loaded a new csfle, replace the
|
700
|
+
* global library and set its reference count to 1.
|
701
|
+
* 3. Otherwise, do nothing.
|
702
|
+
*/
|
703
|
+
enum {
|
704
|
+
TOOK_REFERENCE,
|
705
|
+
DID_NOTHING,
|
706
|
+
REPLACED_GLOBAL,
|
707
|
+
LIB_CREATE_FAILED,
|
708
|
+
} action;
|
709
|
+
|
710
|
+
MONGOCRYPT_WITH_MUTEX(g_csfle_state.mtx) {
|
711
|
+
if (g_csfle_state.refcount) {
|
712
|
+
// Increment the refcount to prevent the global csfle library from
|
713
|
+
// disappearing
|
714
|
+
++g_csfle_state.refcount;
|
715
|
+
action = TOOK_REFERENCE;
|
716
|
+
} else if (found->okay) {
|
717
|
+
// We have found csfle, and no one else is holding one. Our result will
|
718
|
+
// now become the global result.
|
719
|
+
// Create the single csfle_lib object for the application:
|
720
|
+
mongo_crypt_v1_lib *csfle_lib = found->vtable.lib_create(csfle_status);
|
721
|
+
if (csfle_lib == NULL) {
|
722
|
+
// Creation failed:
|
723
|
+
action = LIB_CREATE_FAILED;
|
724
|
+
} else {
|
725
|
+
// Creation succeeded: Store the result:
|
726
|
+
g_csfle_state.dll = found->lib;
|
727
|
+
g_csfle_state.vtable = found->vtable;
|
728
|
+
g_csfle_state.csfle_lib = csfle_lib;
|
729
|
+
g_csfle_state.refcount = 1;
|
730
|
+
action = REPLACED_GLOBAL;
|
731
|
+
}
|
732
|
+
} else {
|
733
|
+
// We failed to load the library, and no one else has one either.
|
734
|
+
// Nothing to do.
|
735
|
+
action = DID_NOTHING;
|
736
|
+
}
|
737
|
+
}
|
738
|
+
|
739
|
+
// Get the possible failure status information.
|
740
|
+
mstr message = MSTR_NULL;
|
741
|
+
int err = 0;
|
742
|
+
int code = 0;
|
743
|
+
if (csfle_status) {
|
744
|
+
assert(found->okay);
|
745
|
+
message = mstr_copy_cstr(found->vtable.status_get_explanation(csfle_status));
|
746
|
+
err = found->vtable.status_get_error(csfle_status);
|
747
|
+
code = found->vtable.status_get_code(csfle_status);
|
748
|
+
found->vtable.status_destroy(csfle_status);
|
749
|
+
}
|
750
|
+
|
751
|
+
bool have_csfle = true;
|
752
|
+
switch (action) {
|
753
|
+
case TOOK_REFERENCE: {
|
754
|
+
const bool is_valid = _validate_csfle_singleton(crypt, *found);
|
755
|
+
if (!is_valid) {
|
756
|
+
// We've failed validation, so we're not going to continue to
|
757
|
+
// reference the global instance it. Drop it now:
|
758
|
+
_csfle_drop_global_ref();
|
759
|
+
}
|
760
|
+
have_csfle = is_valid;
|
761
|
+
break;
|
762
|
+
}
|
763
|
+
case REPLACED_GLOBAL:
|
764
|
+
// Reset the library in the caller so they can't unload the DLL. The DLL
|
765
|
+
// is now managed in the global variable.
|
766
|
+
found->lib = MCR_DLL_NULL;
|
767
|
+
_mongocrypt_log(&crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "Loading new csfle library for the application.");
|
768
|
+
have_csfle = true;
|
769
|
+
break;
|
770
|
+
case LIB_CREATE_FAILED:
|
771
|
+
if (!message.data) {
|
772
|
+
// We failed to obtain a message about the failure
|
773
|
+
_mongocrypt_set_error(crypt->status,
|
774
|
+
MONGOCRYPT_STATUS_ERROR_CRYPT_SHARED,
|
775
|
+
MONGOCRYPT_GENERIC_ERROR_CODE,
|
776
|
+
"csfle lib_create() failed");
|
777
|
+
} else {
|
778
|
+
// Record the message, error, and code from csfle about the failure
|
779
|
+
_mongocrypt_set_error(crypt->status,
|
780
|
+
MONGOCRYPT_STATUS_ERROR_CRYPT_SHARED,
|
781
|
+
MONGOCRYPT_GENERIC_ERROR_CODE,
|
782
|
+
"csfle lib_create() failed: %s [Error %d, code %d]",
|
783
|
+
message.data,
|
784
|
+
err,
|
785
|
+
code);
|
786
|
+
}
|
787
|
+
have_csfle = false;
|
788
|
+
break;
|
789
|
+
case DID_NOTHING:
|
790
|
+
default: have_csfle = false; break;
|
791
|
+
}
|
792
|
+
|
793
|
+
mstr_free(message);
|
794
|
+
return have_csfle;
|
884
795
|
}
|
885
796
|
|
886
797
|
/**
|
@@ -890,16 +801,13 @@ _csfle_replace_or_take_validate_singleton (mongocrypt_t *crypt,
|
|
890
801
|
* @note "Requesting csfle" means that it has set at least one search path OR
|
891
802
|
* has set the override path
|
892
803
|
*/
|
893
|
-
static bool
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
}
|
901
|
-
return c->opts.n_crypt_shared_lib_search_paths != 0 ||
|
902
|
-
c->opts.crypt_shared_lib_override_path.data != NULL;
|
804
|
+
static bool _wants_csfle(mongocrypt_t *c) {
|
805
|
+
BSON_ASSERT_PARAM(c);
|
806
|
+
|
807
|
+
if (c->opts.bypass_query_analysis) {
|
808
|
+
return false;
|
809
|
+
}
|
810
|
+
return c->opts.n_crypt_shared_lib_search_paths != 0 || c->opts.crypt_shared_lib_override_path.data != NULL;
|
903
811
|
}
|
904
812
|
|
905
813
|
/**
|
@@ -913,693 +821,370 @@ _wants_csfle (mongocrypt_t *c)
|
|
913
821
|
* requested paths. `false` is only for hard-errors, which includes failure to
|
914
822
|
* load from the override path.
|
915
823
|
*/
|
916
|
-
static bool
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
// In cast of failure, validate_singleton() will set a non-ok status.
|
949
|
-
return mongocrypt_status_type (status) == MONGOCRYPT_STATUS_OK;
|
824
|
+
static bool _try_enable_csfle(mongocrypt_t *crypt) {
|
825
|
+
mongocrypt_status_t *status;
|
826
|
+
_loaded_csfle found;
|
827
|
+
|
828
|
+
BSON_ASSERT_PARAM(crypt);
|
829
|
+
|
830
|
+
found = _try_find_csfle(crypt);
|
831
|
+
|
832
|
+
status = crypt->status;
|
833
|
+
|
834
|
+
// If a crypt_shared override path was specified, but we did not succeed in
|
835
|
+
// loading crypt_shared, that is a hard-error.
|
836
|
+
if (crypt->opts.crypt_shared_lib_override_path.data && !found.okay) {
|
837
|
+
// Wrap error with additional information.
|
838
|
+
CLIENT_ERR("A crypt_shared override path was specified [%s], but we failed to open a dynamic "
|
839
|
+
"library at that location. Load error: [%s]",
|
840
|
+
crypt->opts.crypt_shared_lib_override_path.data,
|
841
|
+
mongocrypt_status_message(crypt->status, NULL /* len */));
|
842
|
+
return false;
|
843
|
+
}
|
844
|
+
|
845
|
+
// Attempt to validate the try-find result against the global state:
|
846
|
+
const bool got_csfle = _csfle_replace_or_take_validate_singleton(crypt, &found);
|
847
|
+
// Close the lib we found (may have been stolen in validate_singleton())
|
848
|
+
mcr_dll_close(found.lib);
|
849
|
+
|
850
|
+
if (got_csfle) {
|
851
|
+
crypt->csfle = g_csfle_state.vtable;
|
852
|
+
crypt->csfle_lib = g_csfle_state.csfle_lib;
|
853
|
+
}
|
854
|
+
// In cast of failure, validate_singleton() will set a non-ok status.
|
855
|
+
return mongocrypt_status_type(status) == MONGOCRYPT_STATUS_OK;
|
950
856
|
}
|
951
857
|
|
952
|
-
bool
|
953
|
-
|
954
|
-
{
|
955
|
-
BSON_ASSERT_PARAM (crypt);
|
858
|
+
bool mongocrypt_init(mongocrypt_t *crypt) {
|
859
|
+
BSON_ASSERT_PARAM(crypt);
|
956
860
|
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
861
|
+
mongocrypt_status_t *status = crypt->status;
|
862
|
+
if (crypt->initialized) {
|
863
|
+
CLIENT_ERR("already initialized");
|
864
|
+
return false;
|
865
|
+
}
|
962
866
|
|
963
|
-
|
867
|
+
crypt->initialized = true;
|
964
868
|
|
965
|
-
|
966
|
-
|
967
|
-
|
869
|
+
if (!mongocrypt_status_ok(crypt->status)) {
|
870
|
+
return false;
|
871
|
+
}
|
968
872
|
|
969
|
-
|
970
|
-
|
971
|
-
|
873
|
+
if (!_mongocrypt_opts_validate(&crypt->opts, status)) {
|
874
|
+
return false;
|
875
|
+
}
|
972
876
|
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
}
|
877
|
+
if (crypt->opts.log_fn) {
|
878
|
+
_mongocrypt_log_set_fn(&crypt->log, crypt->opts.log_fn, crypt->opts.log_ctx);
|
879
|
+
}
|
977
880
|
|
978
|
-
|
881
|
+
if (!crypt->crypto) {
|
979
882
|
#ifndef MONGOCRYPT_ENABLE_CRYPTO
|
980
|
-
|
981
|
-
|
982
|
-
|
883
|
+
CLIENT_ERR("libmongocrypt built with native crypto disabled. crypto "
|
884
|
+
"hooks required");
|
885
|
+
return false;
|
983
886
|
#else
|
984
|
-
|
985
|
-
|
986
|
-
|
887
|
+
/* set default hooks. */
|
888
|
+
crypt->crypto = bson_malloc0(sizeof(*crypt->crypto));
|
889
|
+
BSON_ASSERT(crypt->crypto);
|
987
890
|
#endif
|
988
|
-
|
891
|
+
}
|
989
892
|
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
893
|
+
if (!_wants_csfle(crypt)) {
|
894
|
+
// User does not want csfle. Just succeed.
|
895
|
+
return true;
|
896
|
+
}
|
994
897
|
|
995
|
-
|
898
|
+
return _try_enable_csfle(crypt);
|
996
899
|
}
|
997
900
|
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
if (!out) {
|
1005
|
-
mongocrypt_status_t *status = crypt->status;
|
1006
|
-
CLIENT_ERR ("argument 'out' is required");
|
1007
|
-
return false;
|
1008
|
-
}
|
1009
|
-
|
1010
|
-
if (!mongocrypt_status_ok (crypt->status)) {
|
1011
|
-
_mongocrypt_status_copy_to (crypt->status, out);
|
1012
|
-
return false;
|
1013
|
-
}
|
1014
|
-
_mongocrypt_status_reset (out);
|
1015
|
-
return true;
|
901
|
+
bool mongocrypt_is_crypto_available(void) {
|
902
|
+
#ifdef MONGOCRYPT_ENABLE_CRYPTO
|
903
|
+
return true;
|
904
|
+
#else
|
905
|
+
return false;
|
906
|
+
#endif
|
1016
907
|
}
|
1017
908
|
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
{
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
_mongocrypt_cache_oauth_destroy (crypt->cache_oauth_gcp);
|
1034
|
-
|
1035
|
-
if (crypt->csfle.okay) {
|
1036
|
-
_csfle_drop_global_ref ();
|
1037
|
-
crypt->csfle.okay = false;
|
1038
|
-
}
|
1039
|
-
|
1040
|
-
|
1041
|
-
bson_free (crypt);
|
909
|
+
bool mongocrypt_status(mongocrypt_t *crypt, mongocrypt_status_t *out) {
|
910
|
+
BSON_ASSERT_PARAM(crypt);
|
911
|
+
|
912
|
+
if (!out) {
|
913
|
+
mongocrypt_status_t *status = crypt->status;
|
914
|
+
CLIENT_ERR("argument 'out' is required");
|
915
|
+
return false;
|
916
|
+
}
|
917
|
+
|
918
|
+
if (!mongocrypt_status_ok(crypt->status)) {
|
919
|
+
_mongocrypt_status_copy_to(crypt->status, out);
|
920
|
+
return false;
|
921
|
+
}
|
922
|
+
_mongocrypt_status_reset(out);
|
923
|
+
return true;
|
1042
924
|
}
|
1043
925
|
|
926
|
+
void mongocrypt_destroy(mongocrypt_t *crypt) {
|
927
|
+
if (!crypt) {
|
928
|
+
return;
|
929
|
+
}
|
930
|
+
_mongocrypt_opts_cleanup(&crypt->opts);
|
931
|
+
_mongocrypt_cache_cleanup(&crypt->cache_collinfo);
|
932
|
+
_mongocrypt_cache_cleanup(&crypt->cache_key);
|
933
|
+
_mongocrypt_mutex_cleanup(&crypt->mutex);
|
934
|
+
_mongocrypt_log_cleanup(&crypt->log);
|
935
|
+
mongocrypt_status_destroy(crypt->status);
|
936
|
+
bson_free(crypt->crypto);
|
937
|
+
mc_mapof_kmsid_to_token_destroy(crypt->cache_oauth);
|
938
|
+
|
939
|
+
if (crypt->csfle.okay) {
|
940
|
+
_csfle_drop_global_ref();
|
941
|
+
crypt->csfle.okay = false;
|
942
|
+
}
|
943
|
+
|
944
|
+
bson_free(crypt);
|
945
|
+
}
|
1044
946
|
|
1045
|
-
const char *
|
1046
|
-
|
1047
|
-
|
1048
|
-
{
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
*len = (uint32_t) (strlen (version));
|
1060
|
-
}
|
1061
|
-
return version;
|
947
|
+
const char *mongocrypt_crypt_shared_lib_version_string(const mongocrypt_t *crypt, uint32_t *len) {
|
948
|
+
BSON_ASSERT_PARAM(crypt);
|
949
|
+
|
950
|
+
if (!crypt->csfle.okay) {
|
951
|
+
if (len) {
|
952
|
+
*len = 0;
|
953
|
+
}
|
954
|
+
return NULL;
|
955
|
+
}
|
956
|
+
const char *version = crypt->csfle.get_version_str();
|
957
|
+
if (len) {
|
958
|
+
*len = (uint32_t)(strlen(version));
|
959
|
+
}
|
960
|
+
return version;
|
1062
961
|
}
|
1063
962
|
|
1064
|
-
uint64_t
|
1065
|
-
|
1066
|
-
{
|
1067
|
-
BSON_ASSERT_PARAM (crypt);
|
963
|
+
uint64_t mongocrypt_crypt_shared_lib_version(const mongocrypt_t *crypt) {
|
964
|
+
BSON_ASSERT_PARAM(crypt);
|
1068
965
|
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
966
|
+
if (!crypt->csfle.okay) {
|
967
|
+
return 0;
|
968
|
+
}
|
969
|
+
return crypt->csfle.get_version();
|
1073
970
|
}
|
1074
971
|
|
972
|
+
bool _mongocrypt_validate_and_copy_string(const char *in, int32_t in_len, char **out) {
|
973
|
+
BSON_ASSERT_PARAM(out);
|
1075
974
|
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
char **out)
|
1080
|
-
{
|
1081
|
-
BSON_ASSERT_PARAM (out);
|
975
|
+
if (!in || in_len < -1) {
|
976
|
+
return false;
|
977
|
+
}
|
1082
978
|
|
1083
|
-
|
1084
|
-
return false;
|
1085
|
-
}
|
979
|
+
const size_t len = in_len < 0 ? strlen(in) : (size_t)in_len;
|
1086
980
|
|
1087
|
-
|
981
|
+
if (!bson_utf8_validate(in, len, false)) {
|
982
|
+
return false;
|
983
|
+
}
|
984
|
+
*out = bson_strndup(in, len);
|
985
|
+
return true;
|
986
|
+
}
|
1088
987
|
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
988
|
+
bool mongocrypt_setopt_crypto_hooks(mongocrypt_t *crypt,
|
989
|
+
mongocrypt_crypto_fn aes_256_cbc_encrypt,
|
990
|
+
mongocrypt_crypto_fn aes_256_cbc_decrypt,
|
991
|
+
mongocrypt_random_fn random,
|
992
|
+
mongocrypt_hmac_fn hmac_sha_512,
|
993
|
+
mongocrypt_hmac_fn hmac_sha_256,
|
994
|
+
mongocrypt_hash_fn sha_256,
|
995
|
+
void *ctx) {
|
996
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
997
|
+
|
998
|
+
mongocrypt_status_t *status = crypt->status;
|
999
|
+
|
1000
|
+
if (!crypt->crypto) {
|
1001
|
+
crypt->crypto = bson_malloc0(sizeof(*crypt->crypto));
|
1002
|
+
BSON_ASSERT(crypt->crypto);
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
crypt->crypto->hooks_enabled = true;
|
1006
|
+
crypt->crypto->ctx = ctx;
|
1007
|
+
|
1008
|
+
if (!aes_256_cbc_encrypt) {
|
1009
|
+
CLIENT_ERR("aes_256_cbc_encrypt not set");
|
1010
|
+
return false;
|
1011
|
+
}
|
1012
|
+
crypt->crypto->aes_256_cbc_encrypt = aes_256_cbc_encrypt;
|
1013
|
+
|
1014
|
+
if (!aes_256_cbc_decrypt) {
|
1015
|
+
CLIENT_ERR("aes_256_cbc_decrypt not set");
|
1016
|
+
return false;
|
1017
|
+
}
|
1018
|
+
crypt->crypto->aes_256_cbc_decrypt = aes_256_cbc_decrypt;
|
1019
|
+
|
1020
|
+
if (!random) {
|
1021
|
+
CLIENT_ERR("random not set");
|
1022
|
+
return false;
|
1023
|
+
}
|
1024
|
+
crypt->crypto->random = random;
|
1025
|
+
|
1026
|
+
if (!hmac_sha_512) {
|
1027
|
+
CLIENT_ERR("hmac_sha_512 not set");
|
1028
|
+
return false;
|
1029
|
+
}
|
1030
|
+
crypt->crypto->hmac_sha_512 = hmac_sha_512;
|
1031
|
+
|
1032
|
+
if (!hmac_sha_256) {
|
1033
|
+
CLIENT_ERR("hmac_sha_256 not set");
|
1034
|
+
return false;
|
1035
|
+
}
|
1036
|
+
crypt->crypto->hmac_sha_256 = hmac_sha_256;
|
1037
|
+
|
1038
|
+
if (!sha_256) {
|
1039
|
+
CLIENT_ERR("sha_256 not set");
|
1040
|
+
return false;
|
1041
|
+
}
|
1042
|
+
crypt->crypto->sha_256 = sha_256;
|
1043
|
+
|
1044
|
+
return true;
|
1094
1045
|
}
|
1095
1046
|
|
1047
|
+
bool mongocrypt_setopt_crypto_hook_sign_rsaes_pkcs1_v1_5(mongocrypt_t *crypt,
|
1048
|
+
mongocrypt_hmac_fn sign_rsaes_pkcs1_v1_5,
|
1049
|
+
void *sign_ctx) {
|
1050
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
1096
1051
|
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
mongocrypt_hmac_fn hmac_sha_512,
|
1103
|
-
mongocrypt_hmac_fn hmac_sha_256,
|
1104
|
-
mongocrypt_hash_fn sha_256,
|
1105
|
-
void *ctx)
|
1106
|
-
{
|
1107
|
-
BSON_ASSERT_PARAM (crypt);
|
1108
|
-
|
1109
|
-
mongocrypt_status_t *status = crypt->status;
|
1110
|
-
|
1111
|
-
if (crypt->initialized) {
|
1112
|
-
CLIENT_ERR ("options cannot be set after initialization");
|
1113
|
-
return false;
|
1114
|
-
}
|
1115
|
-
|
1116
|
-
if (!crypt->crypto) {
|
1117
|
-
crypt->crypto = bson_malloc0 (sizeof (*crypt->crypto));
|
1118
|
-
BSON_ASSERT (crypt->crypto);
|
1119
|
-
}
|
1120
|
-
|
1121
|
-
crypt->crypto->hooks_enabled = true;
|
1122
|
-
crypt->crypto->ctx = ctx;
|
1123
|
-
|
1124
|
-
if (!aes_256_cbc_encrypt) {
|
1125
|
-
CLIENT_ERR ("aes_256_cbc_encrypt not set");
|
1126
|
-
return false;
|
1127
|
-
}
|
1128
|
-
crypt->crypto->aes_256_cbc_encrypt = aes_256_cbc_encrypt;
|
1129
|
-
|
1130
|
-
if (!aes_256_cbc_decrypt) {
|
1131
|
-
CLIENT_ERR ("aes_256_cbc_decrypt not set");
|
1132
|
-
return false;
|
1133
|
-
}
|
1134
|
-
crypt->crypto->aes_256_cbc_decrypt = aes_256_cbc_decrypt;
|
1135
|
-
|
1136
|
-
if (!random) {
|
1137
|
-
CLIENT_ERR ("random not set");
|
1138
|
-
return false;
|
1139
|
-
}
|
1140
|
-
crypt->crypto->random = random;
|
1141
|
-
|
1142
|
-
if (!hmac_sha_512) {
|
1143
|
-
CLIENT_ERR ("hmac_sha_512 not set");
|
1144
|
-
return false;
|
1145
|
-
}
|
1146
|
-
crypt->crypto->hmac_sha_512 = hmac_sha_512;
|
1147
|
-
|
1148
|
-
if (!hmac_sha_256) {
|
1149
|
-
CLIENT_ERR ("hmac_sha_256 not set");
|
1150
|
-
return false;
|
1151
|
-
}
|
1152
|
-
crypt->crypto->hmac_sha_256 = hmac_sha_256;
|
1153
|
-
|
1154
|
-
if (!sha_256) {
|
1155
|
-
CLIENT_ERR ("sha_256 not set");
|
1156
|
-
return false;
|
1157
|
-
}
|
1158
|
-
crypt->crypto->sha_256 = sha_256;
|
1159
|
-
|
1160
|
-
return true;
|
1161
|
-
}
|
1052
|
+
if (crypt->opts.sign_rsaes_pkcs1_v1_5) {
|
1053
|
+
mongocrypt_status_t *status = crypt->status;
|
1054
|
+
CLIENT_ERR("signature hook already set");
|
1055
|
+
return false;
|
1056
|
+
}
|
1162
1057
|
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
mongocrypt_hmac_fn sign_rsaes_pkcs1_v1_5,
|
1167
|
-
void *sign_ctx)
|
1168
|
-
{
|
1169
|
-
BSON_ASSERT_PARAM (crypt);
|
1170
|
-
|
1171
|
-
mongocrypt_status_t *status = crypt->status;
|
1172
|
-
|
1173
|
-
if (crypt->initialized) {
|
1174
|
-
CLIENT_ERR ("options cannot be set after initialization");
|
1175
|
-
return false;
|
1176
|
-
}
|
1177
|
-
|
1178
|
-
if (crypt->opts.sign_rsaes_pkcs1_v1_5) {
|
1179
|
-
CLIENT_ERR ("signature hook already set");
|
1180
|
-
return false;
|
1181
|
-
}
|
1182
|
-
|
1183
|
-
crypt->opts.sign_rsaes_pkcs1_v1_5 = sign_rsaes_pkcs1_v1_5;
|
1184
|
-
crypt->opts.sign_ctx = sign_ctx;
|
1185
|
-
return true;
|
1058
|
+
crypt->opts.sign_rsaes_pkcs1_v1_5 = sign_rsaes_pkcs1_v1_5;
|
1059
|
+
crypt->opts.sign_ctx = sign_ctx;
|
1060
|
+
return true;
|
1186
1061
|
}
|
1187
1062
|
|
1188
|
-
bool
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
{
|
1194
|
-
BSON_ASSERT_PARAM (crypt);
|
1195
|
-
|
1196
|
-
mongocrypt_status_t *status = crypt->status;
|
1063
|
+
bool mongocrypt_setopt_aes_256_ctr(mongocrypt_t *crypt,
|
1064
|
+
mongocrypt_crypto_fn aes_256_ctr_encrypt,
|
1065
|
+
mongocrypt_crypto_fn aes_256_ctr_decrypt,
|
1066
|
+
void *ctx) {
|
1067
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
1197
1068
|
|
1198
|
-
|
1199
|
-
crypt->crypto = bson_malloc0 (sizeof (*crypt->crypto));
|
1200
|
-
BSON_ASSERT (crypt->crypto);
|
1201
|
-
}
|
1069
|
+
mongocrypt_status_t *status = crypt->status;
|
1202
1070
|
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1071
|
+
if (!crypt->crypto) {
|
1072
|
+
crypt->crypto = bson_malloc0(sizeof(*crypt->crypto));
|
1073
|
+
BSON_ASSERT(crypt->crypto);
|
1074
|
+
}
|
1207
1075
|
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1076
|
+
if (!aes_256_ctr_encrypt) {
|
1077
|
+
CLIENT_ERR("aes_256_ctr_encrypt not set");
|
1078
|
+
return false;
|
1079
|
+
}
|
1212
1080
|
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1081
|
+
if (!aes_256_ctr_decrypt) {
|
1082
|
+
CLIENT_ERR("aes_256_ctr_decrypt not set");
|
1083
|
+
return false;
|
1084
|
+
}
|
1217
1085
|
|
1218
|
-
|
1219
|
-
|
1086
|
+
crypt->crypto->aes_256_ctr_encrypt = aes_256_ctr_encrypt;
|
1087
|
+
crypt->crypto->aes_256_ctr_decrypt = aes_256_ctr_decrypt;
|
1220
1088
|
|
1221
|
-
|
1089
|
+
return true;
|
1222
1090
|
}
|
1223
1091
|
|
1224
|
-
bool
|
1225
|
-
|
1226
|
-
mongocrypt_crypto_fn aes_256_ecb_encrypt,
|
1227
|
-
void *ctx)
|
1228
|
-
{
|
1229
|
-
BSON_ASSERT_PARAM (crypt);
|
1230
|
-
|
1231
|
-
mongocrypt_status_t *status = crypt->status;
|
1232
|
-
|
1233
|
-
if (!crypt->crypto) {
|
1234
|
-
crypt->crypto = bson_malloc0 (sizeof (*crypt->crypto));
|
1235
|
-
BSON_ASSERT (crypt->crypto);
|
1236
|
-
}
|
1092
|
+
bool mongocrypt_setopt_aes_256_ecb(mongocrypt_t *crypt, mongocrypt_crypto_fn aes_256_ecb_encrypt, void *ctx) {
|
1093
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
1237
1094
|
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1095
|
+
if (!crypt->crypto) {
|
1096
|
+
crypt->crypto = bson_malloc0(sizeof(*crypt->crypto));
|
1097
|
+
BSON_ASSERT(crypt->crypto);
|
1098
|
+
}
|
1242
1099
|
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1100
|
+
if (!aes_256_ecb_encrypt) {
|
1101
|
+
mongocrypt_status_t *status = crypt->status;
|
1102
|
+
CLIENT_ERR("aes_256_ecb_encrypt not set");
|
1103
|
+
return false;
|
1104
|
+
}
|
1247
1105
|
|
1248
|
-
|
1106
|
+
crypt->crypto->aes_256_ecb_encrypt = aes_256_ecb_encrypt;
|
1249
1107
|
|
1250
|
-
|
1108
|
+
return true;
|
1251
1109
|
}
|
1252
1110
|
|
1253
|
-
bool
|
1254
|
-
|
1255
|
-
|
1256
|
-
{
|
1257
|
-
BSON_ASSERT_PARAM (crypt);
|
1258
|
-
BSON_ASSERT_PARAM (kms_providers_definition);
|
1111
|
+
bool mongocrypt_setopt_kms_providers(mongocrypt_t *crypt, mongocrypt_binary_t *kms_providers_definition) {
|
1112
|
+
ASSERT_MONGOCRYPT_PARAM_UNINIT(crypt);
|
1113
|
+
BSON_ASSERT_PARAM(kms_providers_definition);
|
1259
1114
|
|
1260
|
-
|
1261
|
-
|
1262
|
-
if (crypt->initialized) {
|
1263
|
-
CLIENT_ERR ("options cannot be set after initialization");
|
1264
|
-
return false;
|
1265
|
-
}
|
1266
|
-
|
1267
|
-
return _mongocrypt_parse_kms_providers (kms_providers_definition,
|
1115
|
+
return _mongocrypt_parse_kms_providers(kms_providers_definition,
|
1268
1116
|
&crypt->opts.kms_providers,
|
1269
1117
|
crypt->status,
|
1270
1118
|
&crypt->log);
|
1271
1119
|
}
|
1272
1120
|
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
while (bson_iter_next (&iter)) {
|
1292
|
-
const char *field_name;
|
1293
|
-
bson_t field_bson;
|
1294
|
-
|
1295
|
-
field_name = bson_iter_key (&iter);
|
1296
|
-
if (!mc_iter_document_as_bson (&iter, &field_bson, status)) {
|
1297
|
-
return false;
|
1298
|
-
}
|
1299
|
-
|
1300
|
-
if (0 == strcmp (field_name, "azure") && bson_empty (&field_bson)) {
|
1301
|
-
kms_providers->need_credentials |= MONGOCRYPT_KMS_PROVIDER_AZURE;
|
1302
|
-
} else if (0 == strcmp (field_name, "azure")) {
|
1303
|
-
if (0 != (kms_providers->configured_providers &
|
1304
|
-
MONGOCRYPT_KMS_PROVIDER_AZURE)) {
|
1305
|
-
CLIENT_ERR ("azure KMS provider already set");
|
1306
|
-
return false;
|
1307
|
-
}
|
1308
|
-
|
1309
|
-
if (!_mongocrypt_parse_optional_utf8 (
|
1310
|
-
&as_bson,
|
1311
|
-
"azure.accessToken",
|
1312
|
-
&kms_providers->azure.access_token,
|
1313
|
-
status)) {
|
1314
|
-
return false;
|
1315
|
-
}
|
1316
|
-
|
1317
|
-
if (kms_providers->azure.access_token) {
|
1318
|
-
// Caller provides an accessToken directly
|
1319
|
-
if (!_mongocrypt_check_allowed_fields (
|
1320
|
-
&as_bson, "azure", status, "accessToken")) {
|
1321
|
-
return false;
|
1322
|
-
}
|
1323
|
-
kms_providers->configured_providers |=
|
1324
|
-
MONGOCRYPT_KMS_PROVIDER_AZURE;
|
1325
|
-
continue;
|
1326
|
-
}
|
1327
|
-
|
1328
|
-
// No accessToken given, so we'll need to look one up on our own later
|
1329
|
-
// using the Azure API
|
1330
|
-
|
1331
|
-
if (!_mongocrypt_parse_required_utf8 (&as_bson,
|
1332
|
-
"azure.tenantId",
|
1333
|
-
&kms_providers->azure.tenant_id,
|
1334
|
-
status)) {
|
1335
|
-
return false;
|
1336
|
-
}
|
1337
|
-
|
1338
|
-
if (!_mongocrypt_parse_required_utf8 (&as_bson,
|
1339
|
-
"azure.clientId",
|
1340
|
-
&kms_providers->azure.client_id,
|
1341
|
-
status)) {
|
1342
|
-
return false;
|
1343
|
-
}
|
1344
|
-
|
1345
|
-
if (!_mongocrypt_parse_required_utf8 (
|
1346
|
-
&as_bson,
|
1347
|
-
"azure.clientSecret",
|
1348
|
-
&kms_providers->azure.client_secret,
|
1349
|
-
status)) {
|
1350
|
-
return false;
|
1351
|
-
}
|
1352
|
-
|
1353
|
-
if (!_mongocrypt_parse_optional_endpoint (
|
1354
|
-
&as_bson,
|
1355
|
-
"azure.identityPlatformEndpoint",
|
1356
|
-
&kms_providers->azure.identity_platform_endpoint,
|
1357
|
-
NULL /* opts */,
|
1358
|
-
status)) {
|
1359
|
-
return false;
|
1360
|
-
}
|
1361
|
-
|
1362
|
-
if (!_mongocrypt_check_allowed_fields (&as_bson,
|
1363
|
-
"azure",
|
1364
|
-
status,
|
1365
|
-
"tenantId",
|
1366
|
-
"clientId",
|
1367
|
-
"clientSecret",
|
1368
|
-
"identityPlatformEndpoint")) {
|
1369
|
-
return false;
|
1370
|
-
}
|
1371
|
-
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_AZURE;
|
1372
|
-
} else if (0 == strcmp (field_name, "gcp") && bson_empty (&field_bson)) {
|
1373
|
-
kms_providers->need_credentials |= MONGOCRYPT_KMS_PROVIDER_GCP;
|
1374
|
-
} else if (0 == strcmp (field_name, "gcp")) {
|
1375
|
-
if (0 != (kms_providers->configured_providers &
|
1376
|
-
MONGOCRYPT_KMS_PROVIDER_GCP)) {
|
1377
|
-
CLIENT_ERR ("gcp KMS provider already set");
|
1378
|
-
return false;
|
1379
|
-
}
|
1380
|
-
|
1381
|
-
if (!_mongocrypt_parse_optional_utf8 (&as_bson,
|
1382
|
-
"gcp.accessToken",
|
1383
|
-
&kms_providers->gcp.access_token,
|
1384
|
-
status)) {
|
1385
|
-
return false;
|
1386
|
-
}
|
1387
|
-
|
1388
|
-
if (NULL != kms_providers->gcp.access_token) {
|
1389
|
-
/* "gcp" document has form:
|
1390
|
-
* {
|
1391
|
-
* "accessToken": <required UTF-8>
|
1392
|
-
* }
|
1393
|
-
*/
|
1394
|
-
if (!_mongocrypt_check_allowed_fields (
|
1395
|
-
&as_bson, "gcp", status, "accessToken")) {
|
1396
|
-
return false;
|
1397
|
-
}
|
1398
|
-
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_GCP;
|
1399
|
-
continue;
|
1400
|
-
}
|
1401
|
-
|
1402
|
-
/* "gcp" document has form:
|
1403
|
-
* {
|
1404
|
-
* "email": <required UTF-8>
|
1405
|
-
* "privateKey": <required UTF-8 or Binary>
|
1406
|
-
* }
|
1407
|
-
*/
|
1408
|
-
if (!_mongocrypt_parse_required_utf8 (
|
1409
|
-
&as_bson, "gcp.email", &kms_providers->gcp.email, status)) {
|
1410
|
-
return false;
|
1411
|
-
}
|
1412
|
-
|
1413
|
-
if (!_mongocrypt_parse_required_binary (
|
1414
|
-
&as_bson,
|
1415
|
-
"gcp.privateKey",
|
1416
|
-
&kms_providers->gcp.private_key,
|
1417
|
-
status)) {
|
1418
|
-
return false;
|
1419
|
-
}
|
1420
|
-
|
1421
|
-
if (!_mongocrypt_parse_optional_endpoint (&as_bson,
|
1422
|
-
"gcp.endpoint",
|
1423
|
-
&kms_providers->gcp.endpoint,
|
1424
|
-
NULL /* opts */,
|
1425
|
-
status)) {
|
1426
|
-
return false;
|
1427
|
-
}
|
1428
|
-
|
1429
|
-
if (!_mongocrypt_check_allowed_fields (
|
1430
|
-
&as_bson, "gcp", status, "email", "privateKey", "endpoint")) {
|
1431
|
-
return false;
|
1432
|
-
}
|
1433
|
-
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_GCP;
|
1434
|
-
} else if (0 == strcmp (field_name, "local") &&
|
1435
|
-
bson_empty (&field_bson)) {
|
1436
|
-
kms_providers->need_credentials |= MONGOCRYPT_KMS_PROVIDER_LOCAL;
|
1437
|
-
} else if (0 == strcmp (field_name, "local")) {
|
1438
|
-
if (!_mongocrypt_parse_required_binary (
|
1439
|
-
&as_bson, "local.key", &kms_providers->local.key, status)) {
|
1440
|
-
return false;
|
1441
|
-
}
|
1442
|
-
|
1443
|
-
if (kms_providers->local.key.len != MONGOCRYPT_KEY_LEN) {
|
1444
|
-
CLIENT_ERR ("local key must be %d bytes", MONGOCRYPT_KEY_LEN);
|
1445
|
-
return false;
|
1446
|
-
}
|
1447
|
-
|
1448
|
-
if (!_mongocrypt_check_allowed_fields (
|
1449
|
-
&as_bson, "local", status, "key")) {
|
1450
|
-
return false;
|
1451
|
-
}
|
1452
|
-
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_LOCAL;
|
1453
|
-
} else if (0 == strcmp (field_name, "aws") && bson_empty (&field_bson)) {
|
1454
|
-
kms_providers->need_credentials |= MONGOCRYPT_KMS_PROVIDER_AWS;
|
1455
|
-
} else if (0 == strcmp (field_name, "aws")) {
|
1456
|
-
if (!_mongocrypt_parse_required_utf8 (
|
1457
|
-
&as_bson,
|
1458
|
-
"aws.accessKeyId",
|
1459
|
-
&kms_providers->aws.access_key_id,
|
1460
|
-
status)) {
|
1461
|
-
return false;
|
1462
|
-
}
|
1463
|
-
if (!_mongocrypt_parse_required_utf8 (
|
1464
|
-
&as_bson,
|
1465
|
-
"aws.secretAccessKey",
|
1466
|
-
&kms_providers->aws.secret_access_key,
|
1467
|
-
status)) {
|
1468
|
-
return false;
|
1469
|
-
}
|
1470
|
-
|
1471
|
-
if (!_mongocrypt_parse_optional_utf8 (
|
1472
|
-
&as_bson,
|
1473
|
-
"aws.sessionToken",
|
1474
|
-
&kms_providers->aws.session_token,
|
1475
|
-
status)) {
|
1476
|
-
return false;
|
1477
|
-
}
|
1478
|
-
|
1479
|
-
if (!_mongocrypt_check_allowed_fields (&as_bson,
|
1480
|
-
"aws",
|
1481
|
-
status,
|
1482
|
-
"accessKeyId",
|
1483
|
-
"secretAccessKey",
|
1484
|
-
"sessionToken")) {
|
1485
|
-
return false;
|
1486
|
-
}
|
1487
|
-
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_AWS;
|
1488
|
-
} else if (0 == strcmp (field_name, "kmip") && bson_empty (&field_bson)) {
|
1489
|
-
kms_providers->need_credentials |= MONGOCRYPT_KMS_PROVIDER_KMIP;
|
1490
|
-
} else if (0 == strcmp (field_name, "kmip")) {
|
1491
|
-
_mongocrypt_endpoint_parse_opts_t opts = {0};
|
1492
|
-
|
1493
|
-
opts.allow_empty_subdomain = true;
|
1494
|
-
if (!_mongocrypt_parse_required_endpoint (
|
1495
|
-
&as_bson,
|
1496
|
-
"kmip.endpoint",
|
1497
|
-
&kms_providers->kmip.endpoint,
|
1498
|
-
&opts,
|
1499
|
-
status)) {
|
1500
|
-
return false;
|
1501
|
-
}
|
1502
|
-
|
1503
|
-
if (!_mongocrypt_check_allowed_fields (
|
1504
|
-
&as_bson, "kmip", status, "endpoint")) {
|
1505
|
-
return false;
|
1506
|
-
}
|
1507
|
-
kms_providers->configured_providers |= MONGOCRYPT_KMS_PROVIDER_KMIP;
|
1508
|
-
} else {
|
1509
|
-
CLIENT_ERR ("unsupported KMS provider: %s", field_name);
|
1510
|
-
return false;
|
1511
|
-
}
|
1512
|
-
}
|
1513
|
-
|
1514
|
-
if (log && log->trace_enabled) {
|
1515
|
-
char *as_str = bson_as_json (&as_bson, NULL);
|
1516
|
-
_mongocrypt_log (log,
|
1517
|
-
MONGOCRYPT_LOG_LEVEL_TRACE,
|
1518
|
-
"%s (%s=\"%s\")",
|
1519
|
-
BSON_FUNC,
|
1520
|
-
"kms_providers",
|
1521
|
-
as_str);
|
1522
|
-
bson_free (as_str);
|
1523
|
-
}
|
1524
|
-
|
1525
|
-
return true;
|
1121
|
+
void mongocrypt_setopt_append_crypt_shared_lib_search_path(mongocrypt_t *crypt, const char *path) {
|
1122
|
+
BSON_ASSERT_PARAM(crypt);
|
1123
|
+
BSON_ASSERT_PARAM(path);
|
1124
|
+
|
1125
|
+
// Dup the path string for us to manage
|
1126
|
+
mstr pathdup = mstr_copy_cstr(path);
|
1127
|
+
// Increase array len
|
1128
|
+
BSON_ASSERT(crypt->opts.n_crypt_shared_lib_search_paths < INT_MAX);
|
1129
|
+
const int new_len = crypt->opts.n_crypt_shared_lib_search_paths + 1;
|
1130
|
+
BSON_ASSERT(new_len > 0 && sizeof(mstr) <= SIZE_MAX / (size_t)new_len);
|
1131
|
+
mstr *const new_array = bson_realloc(crypt->opts.crypt_shared_lib_search_paths, sizeof(mstr) * (size_t)new_len);
|
1132
|
+
|
1133
|
+
// Store the path
|
1134
|
+
new_array[new_len - 1] = pathdup;
|
1135
|
+
// Write back opts
|
1136
|
+
crypt->opts.crypt_shared_lib_search_paths = new_array;
|
1137
|
+
crypt->opts.n_crypt_shared_lib_search_paths = new_len;
|
1526
1138
|
}
|
1527
1139
|
|
1140
|
+
void mongocrypt_setopt_use_need_kms_credentials_state(mongocrypt_t *crypt) {
|
1141
|
+
BSON_ASSERT_PARAM(crypt);
|
1528
1142
|
|
1529
|
-
|
1530
|
-
mongocrypt_setopt_append_crypt_shared_lib_search_path (mongocrypt_t *crypt,
|
1531
|
-
const char *path)
|
1532
|
-
{
|
1533
|
-
BSON_ASSERT_PARAM (crypt);
|
1534
|
-
BSON_ASSERT_PARAM (path);
|
1535
|
-
|
1536
|
-
// Dup the path string for us to manage
|
1537
|
-
mstr pathdup = mstr_copy_cstr (path);
|
1538
|
-
// Increase array len
|
1539
|
-
BSON_ASSERT (crypt->opts.n_crypt_shared_lib_search_paths < INT_MAX);
|
1540
|
-
const int new_len = crypt->opts.n_crypt_shared_lib_search_paths + 1;
|
1541
|
-
BSON_ASSERT (new_len > 0 && sizeof (mstr) <= SIZE_MAX / (size_t) new_len);
|
1542
|
-
mstr *const new_array =
|
1543
|
-
bson_realloc (crypt->opts.crypt_shared_lib_search_paths,
|
1544
|
-
sizeof (mstr) * (size_t) new_len);
|
1545
|
-
|
1546
|
-
// Store the path
|
1547
|
-
new_array[new_len - 1] = pathdup;
|
1548
|
-
// Write back opts
|
1549
|
-
crypt->opts.crypt_shared_lib_search_paths = new_array;
|
1550
|
-
crypt->opts.n_crypt_shared_lib_search_paths = new_len;
|
1143
|
+
crypt->opts.use_need_kms_credentials_state = true;
|
1551
1144
|
}
|
1552
1145
|
|
1146
|
+
void mongocrypt_setopt_use_need_mongo_collinfo_with_db_state(mongocrypt_t *crypt) {
|
1147
|
+
BSON_ASSERT_PARAM(crypt);
|
1553
1148
|
|
1554
|
-
|
1555
|
-
mongocrypt_setopt_use_need_kms_credentials_state (mongocrypt_t *crypt)
|
1556
|
-
{
|
1557
|
-
BSON_ASSERT_PARAM (crypt);
|
1558
|
-
|
1559
|
-
crypt->opts.use_need_kms_credentials_state = true;
|
1149
|
+
crypt->opts.use_need_mongo_collinfo_with_db_state = true;
|
1560
1150
|
}
|
1561
1151
|
|
1152
|
+
void mongocrypt_setopt_set_crypt_shared_lib_path_override(mongocrypt_t *crypt, const char *path) {
|
1153
|
+
BSON_ASSERT_PARAM(crypt);
|
1154
|
+
BSON_ASSERT_PARAM(path);
|
1562
1155
|
|
1563
|
-
|
1564
|
-
mongocrypt_setopt_set_crypt_shared_lib_path_override (mongocrypt_t *crypt,
|
1565
|
-
const char *path)
|
1566
|
-
{
|
1567
|
-
BSON_ASSERT_PARAM (crypt);
|
1568
|
-
BSON_ASSERT_PARAM (path);
|
1569
|
-
|
1570
|
-
mstr_assign (&crypt->opts.crypt_shared_lib_override_path,
|
1571
|
-
mstr_copy_cstr (path));
|
1156
|
+
mstr_assign(&crypt->opts.crypt_shared_lib_override_path, mstr_copy_cstr(path));
|
1572
1157
|
}
|
1573
1158
|
|
1574
|
-
bool
|
1575
|
-
|
1576
|
-
{
|
1577
|
-
BSON_ASSERT_PARAM (crypt);
|
1159
|
+
bool _mongocrypt_needs_credentials(mongocrypt_t *crypt) {
|
1160
|
+
BSON_ASSERT_PARAM(crypt);
|
1578
1161
|
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1162
|
+
if (!crypt->opts.use_need_kms_credentials_state) {
|
1163
|
+
return false;
|
1164
|
+
}
|
1582
1165
|
|
1583
|
-
|
1166
|
+
return crypt->opts.kms_providers.need_credentials != 0;
|
1584
1167
|
}
|
1585
1168
|
|
1586
|
-
bool
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1169
|
+
bool _mongocrypt_needs_credentials_for_provider(mongocrypt_t *crypt,
|
1170
|
+
_mongocrypt_kms_provider_t provider,
|
1171
|
+
const char *name) {
|
1172
|
+
BSON_ASSERT_PARAM(crypt);
|
1173
|
+
|
1174
|
+
if (name != NULL) {
|
1175
|
+
// Named KMS providers do not support on-demand credentials.
|
1176
|
+
return false;
|
1177
|
+
}
|
1591
1178
|
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1179
|
+
if (!crypt->opts.use_need_kms_credentials_state) {
|
1180
|
+
return false;
|
1181
|
+
}
|
1595
1182
|
|
1596
|
-
|
1183
|
+
return (crypt->opts.kms_providers.need_credentials & (int)provider) != 0;
|
1597
1184
|
}
|
1598
1185
|
|
1599
|
-
void
|
1600
|
-
|
1601
|
-
{
|
1602
|
-
BSON_ASSERT_PARAM (crypt);
|
1186
|
+
void mongocrypt_setopt_bypass_query_analysis(mongocrypt_t *crypt) {
|
1187
|
+
BSON_ASSERT_PARAM(crypt);
|
1603
1188
|
|
1604
|
-
|
1189
|
+
crypt->opts.bypass_query_analysis = true;
|
1605
1190
|
}
|