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
@@ -19,1265 +19,1116 @@
|
|
19
19
|
#include "mongocrypt-ctx-private.h"
|
20
20
|
#include "mongocrypt-key-broker-private.h"
|
21
21
|
|
22
|
-
bool
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
_mongocrypt_set_error (ctx->status,
|
29
|
-
MONGOCRYPT_STATUS_ERROR_CLIENT,
|
30
|
-
MONGOCRYPT_GENERIC_ERROR_CODE,
|
31
|
-
"%s",
|
32
|
-
msg);
|
33
|
-
return _mongocrypt_ctx_fail (ctx);
|
22
|
+
bool _mongocrypt_ctx_fail_w_msg(mongocrypt_ctx_t *ctx, const char *msg) {
|
23
|
+
BSON_ASSERT_PARAM(ctx);
|
24
|
+
BSON_ASSERT_PARAM(msg);
|
25
|
+
|
26
|
+
_mongocrypt_set_error(ctx->status, MONGOCRYPT_STATUS_ERROR_CLIENT, MONGOCRYPT_GENERIC_ERROR_CODE, "%s", msg);
|
27
|
+
return _mongocrypt_ctx_fail(ctx);
|
34
28
|
}
|
35
29
|
|
36
30
|
/* A failure status has already been set. */
|
37
|
-
bool
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
}
|
46
|
-
ctx->state = MONGOCRYPT_CTX_ERROR;
|
47
|
-
return false;
|
31
|
+
bool _mongocrypt_ctx_fail(mongocrypt_ctx_t *ctx) {
|
32
|
+
BSON_ASSERT_PARAM(ctx);
|
33
|
+
|
34
|
+
if (mongocrypt_status_ok(ctx->status)) {
|
35
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "unexpected, failing but no error status set");
|
36
|
+
}
|
37
|
+
ctx->state = MONGOCRYPT_CTX_ERROR;
|
38
|
+
return false;
|
48
39
|
}
|
49
40
|
|
50
|
-
|
51
41
|
static bool
|
52
|
-
_set_binary_opt
|
53
|
-
|
54
|
-
_mongocrypt_buffer_t *buf,
|
55
|
-
bson_subtype_t subtype)
|
56
|
-
{
|
57
|
-
BSON_ASSERT_PARAM (ctx);
|
42
|
+
_set_binary_opt(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *binary, _mongocrypt_buffer_t *buf, bson_subtype_t subtype) {
|
43
|
+
BSON_ASSERT_PARAM(ctx);
|
58
44
|
|
59
|
-
|
60
|
-
|
61
|
-
|
45
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
46
|
+
return false;
|
47
|
+
}
|
62
48
|
|
63
|
-
|
64
|
-
|
65
|
-
|
49
|
+
if (!binary || !binary->data) {
|
50
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "option must be non-NULL");
|
51
|
+
}
|
66
52
|
|
67
|
-
|
68
|
-
|
69
|
-
|
53
|
+
if (!_mongocrypt_buffer_empty(buf)) {
|
54
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "option already set");
|
55
|
+
}
|
70
56
|
|
71
|
-
|
72
|
-
|
73
|
-
|
57
|
+
if (ctx->initialized) {
|
58
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot set options after init");
|
59
|
+
}
|
74
60
|
|
75
|
-
|
76
|
-
|
77
|
-
|
61
|
+
if (subtype == BSON_SUBTYPE_UUID && binary->len != 16) {
|
62
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "expected 16 byte UUID");
|
63
|
+
}
|
78
64
|
|
79
|
-
|
80
|
-
|
65
|
+
_mongocrypt_buffer_copy_from_binary(buf, binary);
|
66
|
+
buf->subtype = subtype;
|
81
67
|
|
82
|
-
|
68
|
+
return true;
|
83
69
|
}
|
84
70
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
key_id_val);
|
106
|
-
bson_free (key_id_val);
|
107
|
-
}
|
108
|
-
|
109
|
-
return _set_binary_opt (ctx, key_id, &ctx->opts.key_id, BSON_SUBTYPE_UUID);
|
71
|
+
bool mongocrypt_ctx_setopt_key_id(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *key_id) {
|
72
|
+
if (!ctx) {
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (ctx->crypt->log.trace_enabled && key_id && key_id->data) {
|
77
|
+
char *key_id_val;
|
78
|
+
/* this should never happen, so assert rather than return false */
|
79
|
+
BSON_ASSERT(key_id->len <= INT_MAX);
|
80
|
+
key_id_val = _mongocrypt_new_string_from_bytes(key_id->data, (int)key_id->len);
|
81
|
+
_mongocrypt_log(&ctx->crypt->log,
|
82
|
+
MONGOCRYPT_LOG_LEVEL_TRACE,
|
83
|
+
"%s (%s=\"%s\")",
|
84
|
+
BSON_FUNC,
|
85
|
+
"key_id",
|
86
|
+
key_id_val);
|
87
|
+
bson_free(key_id_val);
|
88
|
+
}
|
89
|
+
|
90
|
+
return _set_binary_opt(ctx, key_id, &ctx->opts.key_id, BSON_SUBTYPE_UUID);
|
110
91
|
}
|
111
92
|
|
93
|
+
bool mongocrypt_ctx_setopt_key_alt_name(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *key_alt_name) {
|
94
|
+
bson_t as_bson;
|
95
|
+
bson_iter_t iter;
|
96
|
+
_mongocrypt_key_alt_name_t *new_key_alt_name;
|
97
|
+
const char *key;
|
112
98
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
{
|
117
|
-
bson_t as_bson;
|
118
|
-
bson_iter_t iter;
|
119
|
-
_mongocrypt_key_alt_name_t *new_key_alt_name;
|
120
|
-
const char *key;
|
121
|
-
|
122
|
-
if (!ctx) {
|
123
|
-
return false;
|
124
|
-
}
|
125
|
-
|
126
|
-
if (ctx->initialized) {
|
127
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "cannot set options after init");
|
128
|
-
}
|
129
|
-
|
130
|
-
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
131
|
-
return false;
|
132
|
-
}
|
133
|
-
|
134
|
-
if (!key_alt_name || !key_alt_name->data) {
|
135
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "option must be non-NULL");
|
136
|
-
}
|
137
|
-
|
138
|
-
if (!_mongocrypt_binary_to_bson (key_alt_name, &as_bson)) {
|
139
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "invalid keyAltName bson object");
|
140
|
-
}
|
141
|
-
|
142
|
-
if (!bson_iter_init (&iter, &as_bson) || !bson_iter_next (&iter)) {
|
143
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "invalid bson");
|
144
|
-
}
|
145
|
-
|
146
|
-
key = bson_iter_key (&iter);
|
147
|
-
BSON_ASSERT (key);
|
148
|
-
if (0 != strcmp (key, "keyAltName")) {
|
149
|
-
return _mongocrypt_ctx_fail_w_msg (
|
150
|
-
ctx, "keyAltName must have field 'keyAltName'");
|
151
|
-
}
|
152
|
-
|
153
|
-
if (!BSON_ITER_HOLDS_UTF8 (&iter)) {
|
154
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "keyAltName expected to be UTF8");
|
155
|
-
}
|
156
|
-
|
157
|
-
new_key_alt_name = _mongocrypt_key_alt_name_new (bson_iter_value (&iter));
|
158
|
-
|
159
|
-
if (ctx->opts.key_alt_names &&
|
160
|
-
_mongocrypt_key_alt_name_intersects (ctx->opts.key_alt_names,
|
161
|
-
new_key_alt_name)) {
|
162
|
-
_mongocrypt_key_alt_name_destroy_all (new_key_alt_name);
|
163
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "duplicate keyAltNames found");
|
164
|
-
}
|
165
|
-
new_key_alt_name->next = ctx->opts.key_alt_names;
|
166
|
-
ctx->opts.key_alt_names = new_key_alt_name;
|
167
|
-
|
168
|
-
if (bson_iter_next (&iter)) {
|
169
|
-
return _mongocrypt_ctx_fail_w_msg (
|
170
|
-
ctx, "unrecognized field, only keyAltName expected");
|
171
|
-
}
|
172
|
-
|
173
|
-
return true;
|
174
|
-
}
|
99
|
+
if (!ctx) {
|
100
|
+
return false;
|
101
|
+
}
|
175
102
|
|
103
|
+
if (ctx->initialized) {
|
104
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot set options after init");
|
105
|
+
}
|
176
106
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
{
|
181
|
-
bson_t as_bson;
|
182
|
-
bson_iter_t iter;
|
183
|
-
const char *key;
|
184
|
-
_mongocrypt_buffer_t buffer;
|
185
|
-
|
186
|
-
if (!ctx) {
|
187
|
-
return false;
|
188
|
-
}
|
189
|
-
|
190
|
-
if (ctx->initialized) {
|
191
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "cannot set options after init");
|
192
|
-
}
|
193
|
-
|
194
|
-
if (ctx->opts.key_material.owned) {
|
195
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "keyMaterial already set");
|
196
|
-
}
|
197
|
-
|
198
|
-
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
199
|
-
return false;
|
200
|
-
}
|
201
|
-
|
202
|
-
if (!key_material || !key_material->data) {
|
203
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "option must be non-NULL");
|
204
|
-
}
|
205
|
-
|
206
|
-
if (!_mongocrypt_binary_to_bson (key_material, &as_bson)) {
|
207
|
-
return _mongocrypt_ctx_fail_w_msg (ctx,
|
208
|
-
"invalid keyMaterial bson object");
|
209
|
-
}
|
210
|
-
|
211
|
-
/* TODO: use _mongocrypt_parse_required_binary once MONGOCRYPT-380 is
|
212
|
-
* resolved.*/
|
213
|
-
if (!bson_iter_init (&iter, &as_bson) || !bson_iter_next (&iter)) {
|
214
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "invalid bson");
|
215
|
-
}
|
216
|
-
|
217
|
-
key = bson_iter_key (&iter);
|
218
|
-
BSON_ASSERT (key);
|
219
|
-
if (0 != strcmp (key, "keyMaterial")) {
|
220
|
-
return _mongocrypt_ctx_fail_w_msg (
|
221
|
-
ctx, "keyMaterial must have field 'keyMaterial'");
|
222
|
-
}
|
223
|
-
|
224
|
-
if (!_mongocrypt_buffer_from_binary_iter (&buffer, &iter)) {
|
225
|
-
return _mongocrypt_ctx_fail_w_msg (ctx,
|
226
|
-
"keyMaterial must be binary data");
|
227
|
-
}
|
228
|
-
|
229
|
-
if (buffer.len != MONGOCRYPT_KEY_LEN) {
|
230
|
-
_mongocrypt_set_error (
|
231
|
-
ctx->status,
|
232
|
-
MONGOCRYPT_STATUS_ERROR_CLIENT,
|
233
|
-
MONGOCRYPT_GENERIC_ERROR_CODE,
|
234
|
-
"keyMaterial should have length %d, but has length %" PRIu32,
|
235
|
-
MONGOCRYPT_KEY_LEN,
|
236
|
-
buffer.len);
|
237
|
-
return _mongocrypt_ctx_fail (ctx);
|
238
|
-
}
|
239
|
-
|
240
|
-
_mongocrypt_buffer_steal (&ctx->opts.key_material, &buffer);
|
241
|
-
|
242
|
-
if (bson_iter_next (&iter)) {
|
243
|
-
return _mongocrypt_ctx_fail_w_msg (
|
244
|
-
ctx, "unrecognized field, only keyMaterial expected");
|
245
|
-
}
|
246
|
-
|
247
|
-
return true;
|
248
|
-
}
|
107
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
108
|
+
return false;
|
109
|
+
}
|
249
110
|
|
111
|
+
if (!key_alt_name || !key_alt_name->data) {
|
112
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "option must be non-NULL");
|
113
|
+
}
|
250
114
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
int len)
|
255
|
-
{
|
256
|
-
if (!ctx) {
|
257
|
-
return false;
|
258
|
-
}
|
259
|
-
|
260
|
-
if (ctx->initialized) {
|
261
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "cannot set options after init");
|
262
|
-
}
|
263
|
-
|
264
|
-
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
265
|
-
return false;
|
266
|
-
}
|
267
|
-
|
268
|
-
if (ctx->opts.algorithm != MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE ||
|
269
|
-
ctx->opts.index_type.set) {
|
270
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "already set algorithm");
|
271
|
-
}
|
272
|
-
|
273
|
-
if (len < -1) {
|
274
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "invalid algorithm length");
|
275
|
-
}
|
276
|
-
|
277
|
-
if (!algorithm) {
|
278
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "passed null algorithm");
|
279
|
-
}
|
280
|
-
|
281
|
-
const size_t calculated_len = len == -1 ? strlen (algorithm) : (size_t) len;
|
282
|
-
if (ctx->crypt->log.trace_enabled) {
|
283
|
-
_mongocrypt_log (&ctx->crypt->log,
|
284
|
-
MONGOCRYPT_LOG_LEVEL_TRACE,
|
285
|
-
"%s (%s=\"%.*s\")",
|
286
|
-
BSON_FUNC,
|
287
|
-
"algorithm",
|
288
|
-
calculated_len <= (size_t) INT_MAX ? (int) calculated_len
|
289
|
-
: INT_MAX,
|
290
|
-
algorithm);
|
291
|
-
}
|
292
|
-
|
293
|
-
mstr_view algo_str = mstrv_view_data (algorithm, calculated_len);
|
294
|
-
if (mstr_eq_ignore_case (
|
295
|
-
algo_str, mstrv_lit (MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR))) {
|
296
|
-
ctx->opts.algorithm = MONGOCRYPT_ENCRYPTION_ALGORITHM_DETERMINISTIC;
|
297
|
-
} else if (mstr_eq_ignore_case (
|
298
|
-
algo_str, mstrv_lit (MONGOCRYPT_ALGORITHM_RANDOM_STR))) {
|
299
|
-
ctx->opts.algorithm = MONGOCRYPT_ENCRYPTION_ALGORITHM_RANDOM;
|
300
|
-
} else if (mstr_eq_ignore_case (
|
301
|
-
algo_str, mstrv_lit (MONGOCRYPT_ALGORITHM_INDEXED_STR))) {
|
302
|
-
ctx->opts.index_type.value = MONGOCRYPT_INDEX_TYPE_EQUALITY;
|
303
|
-
ctx->opts.index_type.set = true;
|
304
|
-
} else if (mstr_eq_ignore_case (
|
305
|
-
algo_str, mstrv_lit (MONGOCRYPT_ALGORITHM_UNINDEXED_STR))) {
|
306
|
-
ctx->opts.index_type.value = MONGOCRYPT_INDEX_TYPE_NONE;
|
307
|
-
ctx->opts.index_type.set = true;
|
308
|
-
} else if (mstr_eq_ignore_case (
|
309
|
-
algo_str, mstrv_lit (MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR))) {
|
310
|
-
ctx->opts.index_type.value = MONGOCRYPT_INDEX_TYPE_RANGEPREVIEW;
|
311
|
-
ctx->opts.index_type.set = true;
|
312
|
-
} else {
|
313
|
-
char *error = bson_strdup_printf (
|
314
|
-
"unsupported algorithm string \"%.*s\"",
|
315
|
-
algo_str.len <= (size_t) INT_MAX ? (int) algo_str.len : INT_MAX,
|
316
|
-
algo_str.data);
|
317
|
-
_mongocrypt_ctx_fail_w_msg (ctx, error);
|
318
|
-
bson_free (error);
|
319
|
-
return false;
|
320
|
-
}
|
321
|
-
|
322
|
-
return true;
|
323
|
-
}
|
115
|
+
if (!_mongocrypt_binary_to_bson(key_alt_name, &as_bson)) {
|
116
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid keyAltName bson object");
|
117
|
+
}
|
324
118
|
|
119
|
+
if (!bson_iter_init(&iter, &as_bson) || !bson_iter_next(&iter)) {
|
120
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid bson");
|
121
|
+
}
|
325
122
|
|
326
|
-
|
327
|
-
|
328
|
-
{
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
if (!crypt) {
|
333
|
-
return NULL;
|
334
|
-
}
|
335
|
-
if (!crypt->initialized) {
|
336
|
-
mongocrypt_status_t *status;
|
337
|
-
|
338
|
-
status = crypt->status;
|
339
|
-
CLIENT_ERR ("cannot create context from uninitialized crypt");
|
340
|
-
return NULL;
|
341
|
-
}
|
342
|
-
ctx_size = sizeof (_mongocrypt_ctx_encrypt_t);
|
343
|
-
if (sizeof (_mongocrypt_ctx_decrypt_t) > ctx_size) {
|
344
|
-
ctx_size = sizeof (_mongocrypt_ctx_decrypt_t);
|
345
|
-
}
|
346
|
-
if (sizeof (_mongocrypt_ctx_datakey_t) > ctx_size) {
|
347
|
-
ctx_size = sizeof (_mongocrypt_ctx_datakey_t);
|
348
|
-
}
|
349
|
-
ctx = bson_malloc0 (ctx_size);
|
350
|
-
BSON_ASSERT (ctx);
|
351
|
-
|
352
|
-
ctx->crypt = crypt;
|
353
|
-
ctx->status = mongocrypt_status_new ();
|
354
|
-
ctx->opts.algorithm = MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE;
|
355
|
-
ctx->state = MONGOCRYPT_CTX_DONE;
|
356
|
-
return ctx;
|
357
|
-
}
|
123
|
+
key = bson_iter_key(&iter);
|
124
|
+
BSON_ASSERT(key);
|
125
|
+
if (0 != strcmp(key, "keyAltName")) {
|
126
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "keyAltName must have field 'keyAltName'");
|
127
|
+
}
|
358
128
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "not applicable to context"); \
|
363
|
-
} \
|
364
|
-
return ctx->vtable.fn (__VA_ARGS__); \
|
365
|
-
} while (0)
|
129
|
+
if (!BSON_ITER_HOLDS_UTF8(&iter)) {
|
130
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "keyAltName expected to be UTF8");
|
131
|
+
}
|
366
132
|
|
367
|
-
|
368
|
-
static bool
|
369
|
-
_mongo_op_keys (mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out)
|
370
|
-
{
|
371
|
-
BSON_ASSERT_PARAM (ctx);
|
372
|
-
BSON_ASSERT_PARAM (out);
|
373
|
-
|
374
|
-
/* Construct the find filter to fetch keys. */
|
375
|
-
if (!_mongocrypt_key_broker_filter (&ctx->kb, out)) {
|
376
|
-
BSON_ASSERT (!_mongocrypt_key_broker_status (&ctx->kb, ctx->status));
|
377
|
-
return _mongocrypt_ctx_fail (ctx);
|
378
|
-
}
|
379
|
-
return true;
|
380
|
-
}
|
133
|
+
new_key_alt_name = _mongocrypt_key_alt_name_new(bson_iter_value(&iter));
|
381
134
|
|
135
|
+
if (ctx->opts.key_alt_names && _mongocrypt_key_alt_name_intersects(ctx->opts.key_alt_names, new_key_alt_name)) {
|
136
|
+
_mongocrypt_key_alt_name_destroy_all(new_key_alt_name);
|
137
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "duplicate keyAltNames found");
|
138
|
+
}
|
139
|
+
new_key_alt_name->next = ctx->opts.key_alt_names;
|
140
|
+
ctx->opts.key_alt_names = new_key_alt_name;
|
382
141
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
BSON_ASSERT_PARAM (ctx);
|
389
|
-
BSON_ASSERT_PARAM (in);
|
390
|
-
|
391
|
-
_mongocrypt_buffer_from_binary (&buf, in);
|
392
|
-
if (!_mongocrypt_key_broker_add_doc (
|
393
|
-
&ctx->kb, _mongocrypt_ctx_kms_providers (ctx), &buf)) {
|
394
|
-
BSON_ASSERT (!_mongocrypt_key_broker_status (&ctx->kb, ctx->status));
|
395
|
-
return _mongocrypt_ctx_fail (ctx);
|
396
|
-
}
|
397
|
-
return true;
|
142
|
+
if (bson_iter_next(&iter)) {
|
143
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "unrecognized field, only keyAltName expected");
|
144
|
+
}
|
145
|
+
|
146
|
+
return true;
|
398
147
|
}
|
399
148
|
|
149
|
+
bool mongocrypt_ctx_setopt_key_material(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *key_material) {
|
150
|
+
bson_t as_bson;
|
151
|
+
bson_iter_t iter;
|
152
|
+
const char *key;
|
153
|
+
_mongocrypt_buffer_t buffer;
|
154
|
+
|
155
|
+
if (!ctx) {
|
156
|
+
return false;
|
157
|
+
}
|
158
|
+
|
159
|
+
if (ctx->initialized) {
|
160
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot set options after init");
|
161
|
+
}
|
162
|
+
|
163
|
+
if (ctx->opts.key_material.owned) {
|
164
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "keyMaterial already set");
|
165
|
+
}
|
166
|
+
|
167
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
168
|
+
return false;
|
169
|
+
}
|
170
|
+
|
171
|
+
if (!key_material || !key_material->data) {
|
172
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "option must be non-NULL");
|
173
|
+
}
|
174
|
+
|
175
|
+
if (!_mongocrypt_binary_to_bson(key_material, &as_bson)) {
|
176
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid keyMaterial bson object");
|
177
|
+
}
|
178
|
+
|
179
|
+
/* TODO: use _mongocrypt_parse_required_binary once MONGOCRYPT-380 is
|
180
|
+
* resolved.*/
|
181
|
+
if (!bson_iter_init(&iter, &as_bson) || !bson_iter_next(&iter)) {
|
182
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid bson");
|
183
|
+
}
|
184
|
+
|
185
|
+
key = bson_iter_key(&iter);
|
186
|
+
BSON_ASSERT(key);
|
187
|
+
if (0 != strcmp(key, "keyMaterial")) {
|
188
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "keyMaterial must have field 'keyMaterial'");
|
189
|
+
}
|
190
|
+
|
191
|
+
if (!_mongocrypt_buffer_from_binary_iter(&buffer, &iter)) {
|
192
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "keyMaterial must be binary data");
|
193
|
+
}
|
194
|
+
|
195
|
+
if (buffer.len != MONGOCRYPT_KEY_LEN) {
|
196
|
+
_mongocrypt_set_error(ctx->status,
|
197
|
+
MONGOCRYPT_STATUS_ERROR_CLIENT,
|
198
|
+
MONGOCRYPT_GENERIC_ERROR_CODE,
|
199
|
+
"keyMaterial should have length %d, but has length %" PRIu32,
|
200
|
+
MONGOCRYPT_KEY_LEN,
|
201
|
+
buffer.len);
|
202
|
+
return _mongocrypt_ctx_fail(ctx);
|
203
|
+
}
|
204
|
+
|
205
|
+
_mongocrypt_buffer_steal(&ctx->opts.key_material, &buffer);
|
206
|
+
|
207
|
+
if (bson_iter_next(&iter)) {
|
208
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "unrecognized field, only keyMaterial expected");
|
209
|
+
}
|
210
|
+
|
211
|
+
return true;
|
212
|
+
}
|
400
213
|
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
214
|
+
bool mongocrypt_ctx_setopt_algorithm(mongocrypt_ctx_t *ctx, const char *algorithm, int len) {
|
215
|
+
if (!ctx) {
|
216
|
+
return false;
|
217
|
+
}
|
218
|
+
|
219
|
+
if (ctx->initialized) {
|
220
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot set options after init");
|
221
|
+
}
|
222
|
+
|
223
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
224
|
+
return false;
|
225
|
+
}
|
226
|
+
|
227
|
+
if (ctx->opts.algorithm != MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE || ctx->opts.index_type.set) {
|
228
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "already set algorithm");
|
229
|
+
}
|
230
|
+
|
231
|
+
if (len < -1) {
|
232
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid algorithm length");
|
233
|
+
}
|
234
|
+
|
235
|
+
if (!algorithm) {
|
236
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "passed null algorithm");
|
237
|
+
}
|
238
|
+
|
239
|
+
const size_t calculated_len = len == -1 ? strlen(algorithm) : (size_t)len;
|
240
|
+
if (ctx->crypt->log.trace_enabled) {
|
241
|
+
_mongocrypt_log(&ctx->crypt->log,
|
242
|
+
MONGOCRYPT_LOG_LEVEL_TRACE,
|
243
|
+
"%s (%s=\"%.*s\")",
|
244
|
+
BSON_FUNC,
|
245
|
+
"algorithm",
|
246
|
+
calculated_len <= (size_t)INT_MAX ? (int)calculated_len : INT_MAX,
|
247
|
+
algorithm);
|
248
|
+
}
|
249
|
+
|
250
|
+
mstr_view algo_str = mstrv_view_data(algorithm, calculated_len);
|
251
|
+
if (mstr_eq_ignore_case(algo_str, mstrv_lit(MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR))) {
|
252
|
+
ctx->opts.algorithm = MONGOCRYPT_ENCRYPTION_ALGORITHM_DETERMINISTIC;
|
253
|
+
} else if (mstr_eq_ignore_case(algo_str, mstrv_lit(MONGOCRYPT_ALGORITHM_RANDOM_STR))) {
|
254
|
+
ctx->opts.algorithm = MONGOCRYPT_ENCRYPTION_ALGORITHM_RANDOM;
|
255
|
+
} else if (mstr_eq_ignore_case(algo_str, mstrv_lit(MONGOCRYPT_ALGORITHM_INDEXED_STR))) {
|
256
|
+
ctx->opts.index_type.value = MONGOCRYPT_INDEX_TYPE_EQUALITY;
|
257
|
+
ctx->opts.index_type.set = true;
|
258
|
+
} else if (mstr_eq_ignore_case(algo_str, mstrv_lit(MONGOCRYPT_ALGORITHM_UNINDEXED_STR))) {
|
259
|
+
ctx->opts.index_type.value = MONGOCRYPT_INDEX_TYPE_NONE;
|
260
|
+
ctx->opts.index_type.set = true;
|
261
|
+
} else if (mstr_eq_ignore_case(algo_str, mstrv_lit(MONGOCRYPT_ALGORITHM_RANGE_STR))) {
|
262
|
+
ctx->opts.index_type.value = MONGOCRYPT_INDEX_TYPE_RANGE;
|
263
|
+
ctx->opts.index_type.set = true;
|
264
|
+
} else if (mstr_eq_ignore_case(algo_str, mstrv_lit(MONGOCRYPT_ALGORITHM_RANGEPREVIEW_DEPRECATED_STR))) {
|
265
|
+
if (ctx->crypt->opts.use_range_v2) {
|
266
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "Algorithm 'rangePreview' is deprecated, please use 'range'");
|
267
|
+
return false;
|
268
|
+
}
|
269
|
+
ctx->opts.index_type.value = MONGOCRYPT_INDEX_TYPE_RANGEPREVIEW_DEPRECATED;
|
270
|
+
ctx->opts.index_type.set = true;
|
271
|
+
} else {
|
272
|
+
char *error = bson_strdup_printf("unsupported algorithm string \"%.*s\"",
|
273
|
+
algo_str.len <= (size_t)INT_MAX ? (int)algo_str.len : INT_MAX,
|
274
|
+
algo_str.data);
|
275
|
+
_mongocrypt_ctx_fail_w_msg(ctx, error);
|
276
|
+
bson_free(error);
|
277
|
+
return false;
|
278
|
+
}
|
279
|
+
|
280
|
+
return true;
|
281
|
+
}
|
405
282
|
|
406
|
-
|
407
|
-
|
283
|
+
mongocrypt_ctx_t *mongocrypt_ctx_new(mongocrypt_t *crypt) {
|
284
|
+
mongocrypt_ctx_t *ctx;
|
285
|
+
size_t ctx_size;
|
286
|
+
|
287
|
+
if (!crypt) {
|
288
|
+
return NULL;
|
289
|
+
}
|
290
|
+
if (!crypt->initialized) {
|
291
|
+
mongocrypt_status_t *status;
|
292
|
+
|
293
|
+
status = crypt->status;
|
294
|
+
CLIENT_ERR("cannot create context from uninitialized crypt");
|
295
|
+
return NULL;
|
296
|
+
}
|
297
|
+
ctx_size = sizeof(_mongocrypt_ctx_encrypt_t);
|
298
|
+
if (sizeof(_mongocrypt_ctx_decrypt_t) > ctx_size) {
|
299
|
+
ctx_size = sizeof(_mongocrypt_ctx_decrypt_t);
|
300
|
+
}
|
301
|
+
if (sizeof(_mongocrypt_ctx_datakey_t) > ctx_size) {
|
302
|
+
ctx_size = sizeof(_mongocrypt_ctx_datakey_t);
|
303
|
+
}
|
304
|
+
ctx = bson_malloc0(ctx_size);
|
305
|
+
BSON_ASSERT(ctx);
|
306
|
+
|
307
|
+
ctx->crypt = crypt;
|
308
|
+
ctx->status = mongocrypt_status_new();
|
309
|
+
ctx->opts.algorithm = MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE;
|
310
|
+
ctx->state = MONGOCRYPT_CTX_DONE;
|
311
|
+
return ctx;
|
408
312
|
}
|
409
313
|
|
410
|
-
|
411
|
-
|
412
|
-
{
|
413
|
-
|
314
|
+
#define CHECK_AND_CALL(fn, ...) \
|
315
|
+
do { \
|
316
|
+
if (!ctx->vtable.fn) { \
|
317
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "not applicable to context"); \
|
318
|
+
} \
|
319
|
+
return ctx->vtable.fn(__VA_ARGS__); \
|
320
|
+
} while (0)
|
414
321
|
|
415
|
-
|
322
|
+
/* Common to both encrypt and decrypt context. */
|
323
|
+
static bool _mongo_op_keys(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out) {
|
324
|
+
BSON_ASSERT_PARAM(ctx);
|
325
|
+
BSON_ASSERT_PARAM(out);
|
326
|
+
|
327
|
+
/* Construct the find filter to fetch keys. */
|
328
|
+
if (!_mongocrypt_key_broker_filter(&ctx->kb, out)) {
|
329
|
+
BSON_ASSERT(!_mongocrypt_key_broker_status(&ctx->kb, ctx->status));
|
330
|
+
return _mongocrypt_ctx_fail(ctx);
|
331
|
+
}
|
332
|
+
return true;
|
416
333
|
}
|
417
334
|
|
335
|
+
static bool _mongo_feed_keys(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *in) {
|
336
|
+
_mongocrypt_buffer_t buf;
|
418
337
|
|
419
|
-
|
420
|
-
|
421
|
-
{
|
422
|
-
_mongocrypt_opts_kms_providers_t *kms_providers;
|
338
|
+
BSON_ASSERT_PARAM(ctx);
|
339
|
+
BSON_ASSERT_PARAM(in);
|
423
340
|
|
424
|
-
|
341
|
+
_mongocrypt_buffer_from_binary(&buf, in);
|
342
|
+
if (!_mongocrypt_key_broker_add_doc(&ctx->kb, _mongocrypt_ctx_kms_providers(ctx), &buf)) {
|
343
|
+
BSON_ASSERT(!_mongocrypt_key_broker_status(&ctx->kb, ctx->status));
|
344
|
+
return _mongocrypt_ctx_fail(ctx);
|
345
|
+
}
|
346
|
+
return true;
|
347
|
+
}
|
425
348
|
|
426
|
-
|
349
|
+
static bool _mongo_done_keys(mongocrypt_ctx_t *ctx) {
|
350
|
+
BSON_ASSERT_PARAM(ctx);
|
427
351
|
|
428
|
-
|
429
|
-
|
430
|
-
return _mongocrypt_ctx_fail (ctx);
|
431
|
-
}
|
432
|
-
return _mongocrypt_ctx_state_from_key_broker (ctx);
|
352
|
+
(void)_mongocrypt_key_broker_docs_done(&ctx->kb);
|
353
|
+
return _mongocrypt_ctx_state_from_key_broker(ctx);
|
433
354
|
}
|
434
355
|
|
356
|
+
static mongocrypt_kms_ctx_t *_next_kms_ctx(mongocrypt_ctx_t *ctx) {
|
357
|
+
BSON_ASSERT_PARAM(ctx);
|
435
358
|
|
436
|
-
|
437
|
-
mongocrypt_ctx_mongo_op (mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out)
|
438
|
-
{
|
439
|
-
if (!ctx) {
|
440
|
-
return false;
|
441
|
-
}
|
442
|
-
if (!ctx->initialized) {
|
443
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "ctx NULL or uninitialized");
|
444
|
-
}
|
445
|
-
|
446
|
-
if (!out) {
|
447
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "invalid NULL output");
|
448
|
-
}
|
449
|
-
|
450
|
-
switch (ctx->state) {
|
451
|
-
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
|
452
|
-
CHECK_AND_CALL (mongo_op_collinfo, ctx, out);
|
453
|
-
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
|
454
|
-
CHECK_AND_CALL (mongo_op_markings, ctx, out);
|
455
|
-
case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
|
456
|
-
CHECK_AND_CALL (mongo_op_keys, ctx, out);
|
457
|
-
case MONGOCRYPT_CTX_ERROR:
|
458
|
-
return false;
|
459
|
-
case MONGOCRYPT_CTX_DONE:
|
460
|
-
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
461
|
-
case MONGOCRYPT_CTX_NEED_KMS:
|
462
|
-
case MONGOCRYPT_CTX_READY:
|
463
|
-
default:
|
464
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "wrong state");
|
465
|
-
}
|
359
|
+
return _mongocrypt_key_broker_next_kms(&ctx->kb);
|
466
360
|
}
|
467
361
|
|
362
|
+
static bool _kms_done(mongocrypt_ctx_t *ctx) {
|
363
|
+
_mongocrypt_opts_kms_providers_t *kms_providers;
|
468
364
|
|
469
|
-
|
470
|
-
mongocrypt_ctx_mongo_feed (mongocrypt_ctx_t *ctx, mongocrypt_binary_t *in)
|
471
|
-
{
|
472
|
-
if (!ctx) {
|
473
|
-
return false;
|
474
|
-
}
|
475
|
-
if (!ctx->initialized) {
|
476
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "ctx NULL or uninitialized");
|
477
|
-
}
|
478
|
-
|
479
|
-
if (!in) {
|
480
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "invalid NULL input");
|
481
|
-
}
|
482
|
-
|
483
|
-
if (ctx->crypt->log.trace_enabled) {
|
484
|
-
char *in_val;
|
485
|
-
|
486
|
-
in_val = _mongocrypt_new_json_string_from_binary (in);
|
487
|
-
_mongocrypt_log (&ctx->crypt->log,
|
488
|
-
MONGOCRYPT_LOG_LEVEL_TRACE,
|
489
|
-
"%s (%s=\"%s\")",
|
490
|
-
BSON_FUNC,
|
491
|
-
"in",
|
492
|
-
in_val);
|
493
|
-
bson_free (in_val);
|
494
|
-
}
|
495
|
-
|
496
|
-
switch (ctx->state) {
|
497
|
-
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
|
498
|
-
CHECK_AND_CALL (mongo_feed_collinfo, ctx, in);
|
499
|
-
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
|
500
|
-
CHECK_AND_CALL (mongo_feed_markings, ctx, in);
|
501
|
-
case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
|
502
|
-
CHECK_AND_CALL (mongo_feed_keys, ctx, in);
|
503
|
-
case MONGOCRYPT_CTX_ERROR:
|
504
|
-
return false;
|
505
|
-
case MONGOCRYPT_CTX_DONE:
|
506
|
-
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
507
|
-
case MONGOCRYPT_CTX_NEED_KMS:
|
508
|
-
case MONGOCRYPT_CTX_READY:
|
509
|
-
default:
|
510
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "wrong state");
|
511
|
-
}
|
512
|
-
}
|
365
|
+
BSON_ASSERT_PARAM(ctx);
|
513
366
|
|
367
|
+
kms_providers = _mongocrypt_ctx_kms_providers(ctx);
|
368
|
+
|
369
|
+
if (!_mongocrypt_key_broker_kms_done(&ctx->kb, kms_providers)) {
|
370
|
+
BSON_ASSERT(!_mongocrypt_key_broker_status(&ctx->kb, ctx->status));
|
371
|
+
return _mongocrypt_ctx_fail(ctx);
|
372
|
+
}
|
373
|
+
return _mongocrypt_ctx_state_from_key_broker(ctx);
|
374
|
+
}
|
514
375
|
|
515
|
-
bool
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "wrong state");
|
540
|
-
}
|
376
|
+
bool mongocrypt_ctx_mongo_op(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out) {
|
377
|
+
if (!ctx) {
|
378
|
+
return false;
|
379
|
+
}
|
380
|
+
if (!ctx->initialized) {
|
381
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "ctx NULL or uninitialized");
|
382
|
+
}
|
383
|
+
|
384
|
+
if (!out) {
|
385
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid NULL output");
|
386
|
+
}
|
387
|
+
|
388
|
+
switch (ctx->state) {
|
389
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB:
|
390
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO: CHECK_AND_CALL(mongo_op_collinfo, ctx, out);
|
391
|
+
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS: CHECK_AND_CALL(mongo_op_markings, ctx, out);
|
392
|
+
case MONGOCRYPT_CTX_NEED_MONGO_KEYS: CHECK_AND_CALL(mongo_op_keys, ctx, out);
|
393
|
+
case MONGOCRYPT_CTX_ERROR: return false;
|
394
|
+
case MONGOCRYPT_CTX_DONE:
|
395
|
+
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
396
|
+
case MONGOCRYPT_CTX_NEED_KMS:
|
397
|
+
case MONGOCRYPT_CTX_READY:
|
398
|
+
default: return _mongocrypt_ctx_fail_w_msg(ctx, "wrong state");
|
399
|
+
}
|
541
400
|
}
|
542
401
|
|
402
|
+
const char *mongocrypt_ctx_mongo_db(mongocrypt_ctx_t *ctx) {
|
403
|
+
if (!ctx) {
|
404
|
+
return NULL;
|
405
|
+
}
|
406
|
+
if (!ctx->initialized) {
|
407
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "ctx NULL or uninitialized");
|
408
|
+
return NULL;
|
409
|
+
}
|
410
|
+
|
411
|
+
switch (ctx->state) {
|
412
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB: {
|
413
|
+
if (!ctx->vtable.mongo_db_collinfo) {
|
414
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "not applicable to context");
|
415
|
+
return NULL;
|
416
|
+
}
|
417
|
+
return ctx->vtable.mongo_db_collinfo(ctx);
|
418
|
+
}
|
419
|
+
case MONGOCRYPT_CTX_ERROR: return false;
|
420
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
|
421
|
+
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
|
422
|
+
case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
|
423
|
+
case MONGOCRYPT_CTX_DONE:
|
424
|
+
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
425
|
+
case MONGOCRYPT_CTX_NEED_KMS:
|
426
|
+
case MONGOCRYPT_CTX_READY:
|
427
|
+
default: {
|
428
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "wrong state");
|
429
|
+
return NULL;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
}
|
543
433
|
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
434
|
+
bool mongocrypt_ctx_mongo_feed(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *in) {
|
435
|
+
if (!ctx) {
|
436
|
+
return false;
|
437
|
+
}
|
438
|
+
if (!ctx->initialized) {
|
439
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "ctx NULL or uninitialized");
|
440
|
+
}
|
441
|
+
|
442
|
+
if (!in) {
|
443
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid NULL input");
|
444
|
+
}
|
445
|
+
|
446
|
+
if (ctx->crypt->log.trace_enabled) {
|
447
|
+
char *in_val;
|
448
|
+
|
449
|
+
in_val = _mongocrypt_new_json_string_from_binary(in);
|
450
|
+
_mongocrypt_log(&ctx->crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "in", in_val);
|
451
|
+
bson_free(in_val);
|
452
|
+
}
|
453
|
+
|
454
|
+
switch (ctx->state) {
|
455
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB:
|
456
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO: CHECK_AND_CALL(mongo_feed_collinfo, ctx, in);
|
457
|
+
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS: CHECK_AND_CALL(mongo_feed_markings, ctx, in);
|
458
|
+
case MONGOCRYPT_CTX_NEED_MONGO_KEYS: CHECK_AND_CALL(mongo_feed_keys, ctx, in);
|
459
|
+
case MONGOCRYPT_CTX_ERROR: return false;
|
460
|
+
case MONGOCRYPT_CTX_DONE:
|
461
|
+
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
462
|
+
case MONGOCRYPT_CTX_NEED_KMS:
|
463
|
+
case MONGOCRYPT_CTX_READY:
|
464
|
+
default: return _mongocrypt_ctx_fail_w_msg(ctx, "wrong state");
|
465
|
+
}
|
466
|
+
}
|
554
467
|
|
555
|
-
|
468
|
+
bool mongocrypt_ctx_mongo_done(mongocrypt_ctx_t *ctx) {
|
469
|
+
if (!ctx) {
|
470
|
+
return false;
|
471
|
+
}
|
472
|
+
if (!ctx->initialized) {
|
473
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "ctx NULL or uninitialized");
|
474
|
+
}
|
475
|
+
|
476
|
+
switch (ctx->state) {
|
477
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB:
|
478
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO: CHECK_AND_CALL(mongo_done_collinfo, ctx);
|
479
|
+
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS: CHECK_AND_CALL(mongo_done_markings, ctx);
|
480
|
+
case MONGOCRYPT_CTX_NEED_MONGO_KEYS: CHECK_AND_CALL(mongo_done_keys, ctx);
|
481
|
+
case MONGOCRYPT_CTX_ERROR: return false;
|
482
|
+
case MONGOCRYPT_CTX_DONE:
|
483
|
+
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
484
|
+
case MONGOCRYPT_CTX_NEED_KMS:
|
485
|
+
case MONGOCRYPT_CTX_READY:
|
486
|
+
default: return _mongocrypt_ctx_fail_w_msg(ctx, "wrong state");
|
487
|
+
}
|
556
488
|
}
|
557
489
|
|
490
|
+
mongocrypt_ctx_state_t mongocrypt_ctx_state(mongocrypt_ctx_t *ctx) {
|
491
|
+
if (!ctx) {
|
492
|
+
return MONGOCRYPT_CTX_ERROR;
|
493
|
+
}
|
494
|
+
if (!ctx->initialized) {
|
495
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "ctx NULL or uninitialized");
|
496
|
+
return MONGOCRYPT_CTX_ERROR;
|
497
|
+
}
|
498
|
+
|
499
|
+
return ctx->state;
|
500
|
+
}
|
558
501
|
|
559
|
-
mongocrypt_kms_ctx_t *
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
case MONGOCRYPT_CTX_READY:
|
586
|
-
default:
|
587
|
-
_mongocrypt_ctx_fail_w_msg (ctx, "wrong state");
|
588
|
-
return NULL;
|
589
|
-
}
|
502
|
+
mongocrypt_kms_ctx_t *mongocrypt_ctx_next_kms_ctx(mongocrypt_ctx_t *ctx) {
|
503
|
+
if (!ctx) {
|
504
|
+
return NULL;
|
505
|
+
}
|
506
|
+
if (!ctx->initialized) {
|
507
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "ctx NULL or uninitialized");
|
508
|
+
return NULL;
|
509
|
+
}
|
510
|
+
|
511
|
+
if (!ctx->vtable.next_kms_ctx) {
|
512
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "not applicable to context");
|
513
|
+
return NULL;
|
514
|
+
}
|
515
|
+
|
516
|
+
switch (ctx->state) {
|
517
|
+
case MONGOCRYPT_CTX_NEED_KMS: return ctx->vtable.next_kms_ctx(ctx);
|
518
|
+
case MONGOCRYPT_CTX_ERROR: return NULL;
|
519
|
+
case MONGOCRYPT_CTX_DONE:
|
520
|
+
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
521
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB:
|
522
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
|
523
|
+
case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
|
524
|
+
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
|
525
|
+
case MONGOCRYPT_CTX_READY:
|
526
|
+
default: _mongocrypt_ctx_fail_w_msg(ctx, "wrong state"); return NULL;
|
527
|
+
}
|
590
528
|
}
|
591
529
|
|
530
|
+
bool mongocrypt_ctx_provide_kms_providers(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *kms_providers_definition) {
|
531
|
+
if (!ctx) {
|
532
|
+
return false;
|
533
|
+
}
|
592
534
|
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
if (!ctx) {
|
598
|
-
return false;
|
599
|
-
}
|
535
|
+
if (!ctx->initialized) {
|
536
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "ctx NULL or uninitialized");
|
537
|
+
return false;
|
538
|
+
}
|
600
539
|
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
540
|
+
if (ctx->state != MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS) {
|
541
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "wrong state");
|
542
|
+
return false;
|
543
|
+
}
|
605
544
|
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
545
|
+
if (!kms_providers_definition) {
|
546
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "KMS provider credential mapping not provided");
|
547
|
+
return false;
|
548
|
+
}
|
610
549
|
|
611
|
-
|
612
|
-
_mongocrypt_ctx_fail_w_msg (
|
613
|
-
ctx, "KMS provider credential mapping not provided");
|
614
|
-
return false;
|
615
|
-
}
|
550
|
+
_mongocrypt_opts_kms_providers_init(&ctx->per_ctx_kms_providers);
|
616
551
|
|
617
|
-
|
552
|
+
if (!_mongocrypt_parse_kms_providers(kms_providers_definition,
|
618
553
|
&ctx->per_ctx_kms_providers,
|
619
554
|
ctx->status,
|
620
555
|
&ctx->crypt->log)) {
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
ctx->state = ctx->kb.state == KB_ADDING_DOCS ? MONGOCRYPT_CTX_NEED_MONGO_KEYS
|
640
|
-
: MONGOCRYPT_CTX_NEED_KMS;
|
641
|
-
if (ctx->vtable.after_kms_credentials_provided) {
|
642
|
-
return ctx->vtable.after_kms_credentials_provided (ctx);
|
643
|
-
}
|
644
|
-
return true;
|
556
|
+
return _mongocrypt_ctx_fail(ctx);
|
557
|
+
}
|
558
|
+
|
559
|
+
if (!_mongocrypt_opts_kms_providers_validate(&ctx->crypt->opts, &ctx->per_ctx_kms_providers, ctx->status)) {
|
560
|
+
/* Remove the parsed KMS providers if they are invalid */
|
561
|
+
_mongocrypt_opts_kms_providers_cleanup(&ctx->per_ctx_kms_providers);
|
562
|
+
memset(&ctx->per_ctx_kms_providers, 0, sizeof(ctx->per_ctx_kms_providers));
|
563
|
+
return _mongocrypt_ctx_fail(ctx);
|
564
|
+
}
|
565
|
+
|
566
|
+
memcpy(&ctx->kms_providers, &ctx->crypt->opts.kms_providers, sizeof(_mongocrypt_opts_kms_providers_t));
|
567
|
+
_mongocrypt_opts_merge_kms_providers(&ctx->kms_providers, &ctx->per_ctx_kms_providers);
|
568
|
+
|
569
|
+
ctx->state = ctx->kb.state == KB_ADDING_DOCS ? MONGOCRYPT_CTX_NEED_MONGO_KEYS : MONGOCRYPT_CTX_NEED_KMS;
|
570
|
+
if (ctx->vtable.after_kms_credentials_provided) {
|
571
|
+
return ctx->vtable.after_kms_credentials_provided(ctx);
|
572
|
+
}
|
573
|
+
return true;
|
645
574
|
}
|
646
575
|
|
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
|
-
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
|
672
|
-
case MONGOCRYPT_CTX_READY:
|
673
|
-
default:
|
674
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "wrong state");
|
675
|
-
}
|
576
|
+
bool mongocrypt_ctx_kms_done(mongocrypt_ctx_t *ctx) {
|
577
|
+
if (!ctx) {
|
578
|
+
return false;
|
579
|
+
}
|
580
|
+
if (!ctx->initialized) {
|
581
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "ctx NULL or uninitialized");
|
582
|
+
}
|
583
|
+
|
584
|
+
if (!ctx->vtable.kms_done) {
|
585
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "not applicable to context");
|
586
|
+
}
|
587
|
+
|
588
|
+
switch (ctx->state) {
|
589
|
+
case MONGOCRYPT_CTX_NEED_KMS: return ctx->vtable.kms_done(ctx);
|
590
|
+
case MONGOCRYPT_CTX_ERROR: return false;
|
591
|
+
case MONGOCRYPT_CTX_DONE:
|
592
|
+
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
593
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB:
|
594
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
|
595
|
+
case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
|
596
|
+
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
|
597
|
+
case MONGOCRYPT_CTX_READY:
|
598
|
+
default: return _mongocrypt_ctx_fail_w_msg(ctx, "wrong state");
|
599
|
+
}
|
676
600
|
}
|
677
601
|
|
602
|
+
bool mongocrypt_ctx_finalize(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out) {
|
603
|
+
if (!ctx) {
|
604
|
+
return false;
|
605
|
+
}
|
606
|
+
if (!ctx->initialized) {
|
607
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "ctx NULL or uninitialized");
|
608
|
+
}
|
609
|
+
|
610
|
+
if (!out) {
|
611
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid NULL output");
|
612
|
+
}
|
613
|
+
|
614
|
+
if (!ctx->vtable.finalize) {
|
615
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "not applicable to context");
|
616
|
+
}
|
617
|
+
|
618
|
+
switch (ctx->state) {
|
619
|
+
case MONGOCRYPT_CTX_READY: return ctx->vtable.finalize(ctx, out);
|
620
|
+
case MONGOCRYPT_CTX_ERROR: return false;
|
621
|
+
case MONGOCRYPT_CTX_DONE:
|
622
|
+
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
623
|
+
case MONGOCRYPT_CTX_NEED_KMS:
|
624
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB:
|
625
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
|
626
|
+
case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
|
627
|
+
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
|
628
|
+
default: return _mongocrypt_ctx_fail_w_msg(ctx, "wrong state");
|
629
|
+
}
|
630
|
+
}
|
678
631
|
|
679
|
-
bool
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "not applicable to context");
|
695
|
-
}
|
696
|
-
|
697
|
-
switch (ctx->state) {
|
698
|
-
case MONGOCRYPT_CTX_READY:
|
699
|
-
return ctx->vtable.finalize (ctx, out);
|
700
|
-
case MONGOCRYPT_CTX_ERROR:
|
701
|
-
return false;
|
702
|
-
case MONGOCRYPT_CTX_DONE:
|
703
|
-
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
|
704
|
-
case MONGOCRYPT_CTX_NEED_KMS:
|
705
|
-
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
|
706
|
-
case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
|
707
|
-
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
|
708
|
-
default:
|
709
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "wrong state");
|
710
|
-
}
|
632
|
+
bool mongocrypt_ctx_status(mongocrypt_ctx_t *ctx, mongocrypt_status_t *out) {
|
633
|
+
if (!ctx) {
|
634
|
+
return false;
|
635
|
+
}
|
636
|
+
|
637
|
+
if (!out) {
|
638
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid NULL output");
|
639
|
+
}
|
640
|
+
|
641
|
+
if (!mongocrypt_status_ok(ctx->status)) {
|
642
|
+
_mongocrypt_status_copy_to(ctx->status, out);
|
643
|
+
return false;
|
644
|
+
}
|
645
|
+
_mongocrypt_status_reset(out);
|
646
|
+
return true;
|
711
647
|
}
|
712
648
|
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
649
|
+
void mongocrypt_ctx_destroy(mongocrypt_ctx_t *ctx) {
|
650
|
+
if (!ctx) {
|
651
|
+
return;
|
652
|
+
}
|
653
|
+
|
654
|
+
if (ctx->vtable.cleanup) {
|
655
|
+
ctx->vtable.cleanup(ctx);
|
656
|
+
}
|
657
|
+
|
658
|
+
mc_RangeOpts_cleanup(&ctx->opts.rangeopts.value);
|
659
|
+
_mongocrypt_opts_kms_providers_cleanup(&ctx->per_ctx_kms_providers);
|
660
|
+
_mongocrypt_kek_cleanup(&ctx->opts.kek);
|
661
|
+
mongocrypt_status_destroy(ctx->status);
|
662
|
+
_mongocrypt_key_broker_cleanup(&ctx->kb);
|
663
|
+
_mongocrypt_buffer_cleanup(&ctx->opts.key_material);
|
664
|
+
_mongocrypt_key_alt_name_destroy_all(ctx->opts.key_alt_names);
|
665
|
+
_mongocrypt_buffer_cleanup(&ctx->opts.key_id);
|
666
|
+
_mongocrypt_buffer_cleanup(&ctx->opts.index_key_id);
|
667
|
+
bson_free(ctx);
|
668
|
+
return;
|
730
669
|
}
|
731
670
|
|
671
|
+
bool mongocrypt_ctx_setopt_masterkey_aws(mongocrypt_ctx_t *ctx,
|
672
|
+
const char *region,
|
673
|
+
int32_t region_len,
|
674
|
+
const char *cmk,
|
675
|
+
int32_t cmk_len) {
|
676
|
+
mongocrypt_binary_t *bin;
|
677
|
+
bson_t as_bson;
|
678
|
+
bool ret;
|
679
|
+
char *temp = NULL;
|
680
|
+
|
681
|
+
if (!ctx) {
|
682
|
+
return false;
|
683
|
+
}
|
684
|
+
if (ctx->initialized) {
|
685
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot set options after init");
|
686
|
+
}
|
687
|
+
|
688
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
689
|
+
return false;
|
690
|
+
}
|
691
|
+
|
692
|
+
if (ctx->opts.kek.kms_provider != MONGOCRYPT_KMS_PROVIDER_AWS
|
693
|
+
&& ctx->opts.kek.kms_provider != MONGOCRYPT_KMS_PROVIDER_NONE) {
|
694
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "master key already set");
|
695
|
+
}
|
696
|
+
|
697
|
+
if (ctx->opts.kek.kms_provider == MONGOCRYPT_KMS_PROVIDER_AWS && ctx->opts.kek.provider.aws.region) {
|
698
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "master key already set");
|
699
|
+
}
|
700
|
+
|
701
|
+
if (!_mongocrypt_validate_and_copy_string(region, region_len, &temp) || region_len == 0) {
|
702
|
+
bson_free(temp);
|
703
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid region");
|
704
|
+
}
|
705
|
+
bson_free(temp);
|
706
|
+
|
707
|
+
temp = NULL;
|
708
|
+
if (!_mongocrypt_validate_and_copy_string(cmk, cmk_len, &temp) || cmk_len == 0) {
|
709
|
+
bson_free(temp);
|
710
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid cmk");
|
711
|
+
}
|
712
|
+
bson_free(temp);
|
713
|
+
|
714
|
+
bson_init(&as_bson);
|
715
|
+
bson_append_utf8(&as_bson, MONGOCRYPT_STR_AND_LEN("provider"), MONGOCRYPT_STR_AND_LEN("aws"));
|
716
|
+
BSON_ASSERT(region_len <= INT_MAX);
|
717
|
+
bson_append_utf8(&as_bson, MONGOCRYPT_STR_AND_LEN("region"), region, region_len);
|
718
|
+
BSON_ASSERT(cmk_len <= INT_MAX);
|
719
|
+
bson_append_utf8(&as_bson, MONGOCRYPT_STR_AND_LEN("key"), cmk, cmk_len);
|
720
|
+
bin = mongocrypt_binary_new_from_data((uint8_t *)bson_get_data(&as_bson), as_bson.len);
|
721
|
+
|
722
|
+
ret = mongocrypt_ctx_setopt_key_encryption_key(ctx, bin);
|
723
|
+
mongocrypt_binary_destroy(bin);
|
724
|
+
bson_destroy(&as_bson);
|
725
|
+
|
726
|
+
if (ctx->crypt->log.trace_enabled) {
|
727
|
+
_mongocrypt_log(&ctx->crypt->log,
|
728
|
+
MONGOCRYPT_LOG_LEVEL_TRACE,
|
729
|
+
"%s (%s=\"%s\", %s=%d, %s=\"%s\", %s=%d)",
|
730
|
+
BSON_FUNC,
|
731
|
+
"region",
|
732
|
+
ctx->opts.kek.provider.aws.region,
|
733
|
+
"region_len",
|
734
|
+
region_len,
|
735
|
+
"cmk",
|
736
|
+
ctx->opts.kek.provider.aws.cmk,
|
737
|
+
"cmk_len",
|
738
|
+
cmk_len);
|
739
|
+
}
|
740
|
+
|
741
|
+
return ret;
|
742
|
+
}
|
732
743
|
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
_mongocrypt_buffer_cleanup (&ctx->opts.index_key_id);
|
753
|
-
bson_free (ctx);
|
754
|
-
return;
|
744
|
+
bool mongocrypt_ctx_setopt_masterkey_local(mongocrypt_ctx_t *ctx) {
|
745
|
+
if (!ctx) {
|
746
|
+
return false;
|
747
|
+
}
|
748
|
+
if (ctx->initialized) {
|
749
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot set options after init");
|
750
|
+
}
|
751
|
+
|
752
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
753
|
+
return false;
|
754
|
+
}
|
755
|
+
|
756
|
+
if (ctx->opts.kek.kms_provider) {
|
757
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "master key already set");
|
758
|
+
}
|
759
|
+
|
760
|
+
ctx->opts.kek.kms_provider = MONGOCRYPT_KMS_PROVIDER_LOCAL;
|
761
|
+
ctx->opts.kek.kmsid = bson_strdup("local");
|
762
|
+
return true;
|
755
763
|
}
|
756
764
|
|
765
|
+
bool _mongocrypt_ctx_init(mongocrypt_ctx_t *ctx, _mongocrypt_ctx_opts_spec_t *opts_spec) {
|
766
|
+
bool has_id = false, has_alt_name = false, has_multiple_alt_names = false;
|
767
|
+
|
768
|
+
BSON_ASSERT_PARAM(ctx);
|
769
|
+
BSON_ASSERT_PARAM(opts_spec);
|
770
|
+
|
771
|
+
// This condition is guarded in setopt_algorithm:
|
772
|
+
BSON_ASSERT(!(ctx->opts.index_type.set && ctx->opts.algorithm != MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE)
|
773
|
+
&& "Both an encryption algorithm and an index_type were set.");
|
774
|
+
|
775
|
+
if (ctx->initialized) {
|
776
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot double initialize");
|
777
|
+
}
|
778
|
+
ctx->initialized = true;
|
779
|
+
|
780
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
781
|
+
return false;
|
782
|
+
}
|
783
|
+
/* Set some default functions */
|
784
|
+
ctx->vtable.mongo_op_keys = _mongo_op_keys;
|
785
|
+
ctx->vtable.mongo_feed_keys = _mongo_feed_keys;
|
786
|
+
ctx->vtable.mongo_done_keys = _mongo_done_keys;
|
787
|
+
ctx->vtable.next_kms_ctx = _next_kms_ctx;
|
788
|
+
ctx->vtable.kms_done = _kms_done;
|
789
|
+
|
790
|
+
/* Check that required options are included and prohibited options are
|
791
|
+
* not.
|
792
|
+
*/
|
793
|
+
|
794
|
+
if (opts_spec->kek == OPT_REQUIRED) {
|
795
|
+
if (!ctx->opts.kek.kms_provider) {
|
796
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "master key required");
|
797
|
+
}
|
798
|
+
mc_kms_creds_t unused;
|
799
|
+
bool is_configured =
|
800
|
+
_mongocrypt_opts_kms_providers_lookup(_mongocrypt_ctx_kms_providers(ctx), ctx->opts.kek.kmsid, &unused);
|
801
|
+
if (!ctx->crypt->opts.use_need_kms_credentials_state && !is_configured) {
|
802
|
+
mongocrypt_status_t *status = ctx->status;
|
803
|
+
CLIENT_ERR("requested kms provider not configured: `%s`", ctx->opts.kek.kmsid);
|
804
|
+
return _mongocrypt_ctx_fail(ctx);
|
805
|
+
}
|
806
|
+
}
|
807
|
+
|
808
|
+
if (opts_spec->kek == OPT_PROHIBITED && ctx->opts.kek.kms_provider) {
|
809
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "master key prohibited");
|
810
|
+
}
|
811
|
+
|
812
|
+
/* Check that the kms provider required by the datakey is configured. */
|
813
|
+
if (ctx->opts.kek.kms_provider) {
|
814
|
+
mc_kms_creds_t unused;
|
815
|
+
bool is_configured =
|
816
|
+
_mongocrypt_opts_kms_providers_lookup(_mongocrypt_ctx_kms_providers(ctx), ctx->opts.kek.kmsid, &unused);
|
817
|
+
bool needs = _mongocrypt_needs_credentials_for_provider(ctx->crypt,
|
818
|
+
ctx->opts.kek.kms_provider,
|
819
|
+
ctx->opts.kek.kmsid_name);
|
820
|
+
if (!is_configured && !needs) {
|
821
|
+
mongocrypt_status_t *status = ctx->status;
|
822
|
+
CLIENT_ERR("requested kms provider required by datakey is not configured: `%s`", ctx->opts.kek.kmsid);
|
823
|
+
return _mongocrypt_ctx_fail(ctx);
|
824
|
+
}
|
825
|
+
}
|
826
|
+
|
827
|
+
/* Special case. key_descriptor applies to explicit encryption. It must be
|
828
|
+
* either a key id or *one* key alt name, but not both.
|
829
|
+
* key_alt_names applies to creating a data key. It may be one or multiple
|
830
|
+
* key alt names.
|
831
|
+
*/
|
832
|
+
has_id = !_mongocrypt_buffer_empty(&ctx->opts.key_id);
|
833
|
+
has_alt_name = !!(ctx->opts.key_alt_names);
|
834
|
+
has_multiple_alt_names = has_alt_name && !!(ctx->opts.key_alt_names->next);
|
835
|
+
|
836
|
+
if (opts_spec->key_descriptor == OPT_REQUIRED) {
|
837
|
+
if (!has_id && !has_alt_name) {
|
838
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "either key id or key alt name required");
|
839
|
+
}
|
840
|
+
|
841
|
+
if (has_id && has_alt_name) {
|
842
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot have both key id and key alt name");
|
843
|
+
}
|
844
|
+
|
845
|
+
if (has_multiple_alt_names) {
|
846
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "must not specify multiple key alt names");
|
847
|
+
}
|
848
|
+
}
|
849
|
+
|
850
|
+
if (opts_spec->key_descriptor == OPT_PROHIBITED) {
|
851
|
+
/* still okay if key_alt_names are allowed and only alt names were
|
852
|
+
* specified. */
|
853
|
+
if ((opts_spec->key_alt_names == OPT_PROHIBITED && has_alt_name) || has_id) {
|
854
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "key id and alt name prohibited");
|
855
|
+
}
|
856
|
+
}
|
857
|
+
|
858
|
+
if (opts_spec->key_material == OPT_PROHIBITED && ctx->opts.key_material.owned) {
|
859
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "key material prohibited");
|
860
|
+
}
|
861
|
+
|
862
|
+
if (opts_spec->algorithm == OPT_REQUIRED && ctx->opts.algorithm == MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE) {
|
863
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "algorithm required");
|
864
|
+
}
|
865
|
+
|
866
|
+
if (opts_spec->algorithm == OPT_PROHIBITED && ctx->opts.algorithm != MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE) {
|
867
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "algorithm prohibited");
|
868
|
+
}
|
869
|
+
|
870
|
+
if (opts_spec->rangeopts == OPT_PROHIBITED && ctx->opts.rangeopts.set) {
|
871
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "range opts are prohibited on this context");
|
872
|
+
}
|
873
|
+
|
874
|
+
_mongocrypt_key_broker_init(&ctx->kb, ctx->crypt);
|
875
|
+
return true;
|
876
|
+
}
|
757
877
|
|
758
|
-
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
|
-
_mongocrypt_log (&ctx->crypt->log,
|
824
|
-
MONGOCRYPT_LOG_LEVEL_TRACE,
|
825
|
-
"%s (%s=\"%s\", %s=%d, %s=\"%s\", %s=%d)",
|
826
|
-
BSON_FUNC,
|
827
|
-
"region",
|
828
|
-
ctx->opts.kek.provider.aws.region,
|
829
|
-
"region_len",
|
830
|
-
region_len,
|
831
|
-
"cmk",
|
832
|
-
ctx->opts.kek.provider.aws.cmk,
|
833
|
-
"cmk_len",
|
834
|
-
cmk_len);
|
835
|
-
}
|
836
|
-
|
837
|
-
return ret;
|
878
|
+
bool _mongocrypt_ctx_state_from_key_broker(mongocrypt_ctx_t *ctx) {
|
879
|
+
_mongocrypt_key_broker_t *kb;
|
880
|
+
mongocrypt_status_t *status;
|
881
|
+
mongocrypt_ctx_state_t new_state = MONGOCRYPT_CTX_ERROR;
|
882
|
+
bool ret = false;
|
883
|
+
|
884
|
+
BSON_ASSERT_PARAM(ctx);
|
885
|
+
|
886
|
+
status = ctx->status;
|
887
|
+
kb = &ctx->kb;
|
888
|
+
|
889
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
890
|
+
return false;
|
891
|
+
}
|
892
|
+
|
893
|
+
switch (kb->state) {
|
894
|
+
case KB_ERROR:
|
895
|
+
_mongocrypt_status_copy_to(kb->status, status);
|
896
|
+
new_state = MONGOCRYPT_CTX_ERROR;
|
897
|
+
ret = false;
|
898
|
+
break;
|
899
|
+
case KB_ADDING_DOCS:
|
900
|
+
/* Encrypted keys need KMS, which need to be provided before
|
901
|
+
* adding docs. */
|
902
|
+
if (_mongocrypt_needs_credentials(ctx->crypt)) {
|
903
|
+
new_state = MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS;
|
904
|
+
} else {
|
905
|
+
/* Require key documents from driver. */
|
906
|
+
new_state = MONGOCRYPT_CTX_NEED_MONGO_KEYS;
|
907
|
+
}
|
908
|
+
ret = true;
|
909
|
+
break;
|
910
|
+
case KB_ADDING_DOCS_ANY:
|
911
|
+
/* Assume KMS credentials have been provided. */
|
912
|
+
new_state = MONGOCRYPT_CTX_NEED_MONGO_KEYS;
|
913
|
+
ret = true;
|
914
|
+
break;
|
915
|
+
case KB_AUTHENTICATING:
|
916
|
+
case KB_DECRYPTING_KEY_MATERIAL:
|
917
|
+
new_state = MONGOCRYPT_CTX_NEED_KMS;
|
918
|
+
ret = true;
|
919
|
+
break;
|
920
|
+
case KB_DONE:
|
921
|
+
new_state = MONGOCRYPT_CTX_READY;
|
922
|
+
if (kb->key_requests == NULL) {
|
923
|
+
/* No key requests were ever added. */
|
924
|
+
ctx->nothing_to_do = true; /* nothing to encrypt/decrypt */
|
925
|
+
}
|
926
|
+
ret = true;
|
927
|
+
break;
|
928
|
+
/* As currently implemented, we do not expect to ever be in KB_REQUESTING
|
929
|
+
* or KB_REQUESTING_ANY state when calling this function. */
|
930
|
+
case KB_REQUESTING:
|
931
|
+
default:
|
932
|
+
CLIENT_ERR("key broker in unexpected state");
|
933
|
+
new_state = MONGOCRYPT_CTX_ERROR;
|
934
|
+
ret = false;
|
935
|
+
break;
|
936
|
+
}
|
937
|
+
|
938
|
+
if (new_state != ctx->state) {
|
939
|
+
ctx->state = new_state;
|
940
|
+
}
|
941
|
+
|
942
|
+
return ret;
|
838
943
|
}
|
839
944
|
|
945
|
+
bool mongocrypt_ctx_setopt_masterkey_aws_endpoint(mongocrypt_ctx_t *ctx, const char *endpoint, int32_t endpoint_len) {
|
946
|
+
if (!ctx) {
|
947
|
+
return false;
|
948
|
+
}
|
840
949
|
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
if (!ctx) {
|
845
|
-
return false;
|
846
|
-
}
|
847
|
-
if (ctx->initialized) {
|
848
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "cannot set options after init");
|
849
|
-
}
|
950
|
+
if (ctx->initialized) {
|
951
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot set options after init");
|
952
|
+
}
|
850
953
|
|
851
|
-
|
852
|
-
|
853
|
-
|
954
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
955
|
+
return false;
|
956
|
+
}
|
854
957
|
|
855
|
-
|
856
|
-
|
857
|
-
|
958
|
+
if (ctx->opts.kek.kms_provider != MONGOCRYPT_KMS_PROVIDER_AWS
|
959
|
+
&& ctx->opts.kek.kms_provider != MONGOCRYPT_KMS_PROVIDER_NONE) {
|
960
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "endpoint prohibited");
|
961
|
+
}
|
858
962
|
|
859
|
-
|
860
|
-
return true;
|
861
|
-
}
|
963
|
+
ctx->opts.kek.kms_provider = MONGOCRYPT_KMS_PROVIDER_AWS;
|
862
964
|
|
965
|
+
if (ctx->opts.kek.provider.aws.endpoint) {
|
966
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "already set masterkey endpoint");
|
967
|
+
}
|
863
968
|
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
BSON_ASSERT_PARAM (ctx);
|
871
|
-
BSON_ASSERT_PARAM (opts_spec);
|
872
|
-
|
873
|
-
// This condition is guarded in setopt_algorithm:
|
874
|
-
BSON_ASSERT (
|
875
|
-
!(ctx->opts.index_type.set &&
|
876
|
-
ctx->opts.algorithm != MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE) &&
|
877
|
-
"Both an encryption algorithm and an index_type were set.");
|
878
|
-
|
879
|
-
if (ctx->initialized) {
|
880
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "cannot double initialize");
|
881
|
-
}
|
882
|
-
ctx->initialized = true;
|
883
|
-
|
884
|
-
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
885
|
-
return false;
|
886
|
-
}
|
887
|
-
/* Set some default functions */
|
888
|
-
ctx->vtable.mongo_op_keys = _mongo_op_keys;
|
889
|
-
ctx->vtable.mongo_feed_keys = _mongo_feed_keys;
|
890
|
-
ctx->vtable.mongo_done_keys = _mongo_done_keys;
|
891
|
-
ctx->vtable.next_kms_ctx = _next_kms_ctx;
|
892
|
-
ctx->vtable.kms_done = _kms_done;
|
893
|
-
|
894
|
-
/* Check that required options are included and prohibited options are
|
895
|
-
* not.
|
896
|
-
*/
|
897
|
-
|
898
|
-
if (opts_spec->kek == OPT_REQUIRED) {
|
899
|
-
if (!ctx->opts.kek.kms_provider) {
|
900
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "master key required");
|
901
|
-
}
|
902
|
-
if (!ctx->crypt->opts.use_need_kms_credentials_state &&
|
903
|
-
!((int) ctx->opts.kek.kms_provider &
|
904
|
-
_mongocrypt_ctx_kms_providers (ctx)->configured_providers)) {
|
905
|
-
return _mongocrypt_ctx_fail_w_msg (
|
906
|
-
ctx, "requested kms provider not configured");
|
907
|
-
}
|
908
|
-
}
|
909
|
-
|
910
|
-
if (opts_spec->kek == OPT_PROHIBITED && ctx->opts.kek.kms_provider) {
|
911
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "master key prohibited");
|
912
|
-
}
|
913
|
-
|
914
|
-
/* Check that the kms provider required by the datakey is configured. */
|
915
|
-
if (ctx->opts.kek.kms_provider) {
|
916
|
-
if (!((ctx->crypt->opts.kms_providers.need_credentials |
|
917
|
-
ctx->crypt->opts.kms_providers.configured_providers) &
|
918
|
-
(int) ctx->opts.kek.kms_provider)) {
|
919
|
-
return _mongocrypt_ctx_fail_w_msg (
|
920
|
-
ctx, "kms provider required by datakey is not configured");
|
921
|
-
}
|
922
|
-
}
|
923
|
-
|
924
|
-
/* Special case. key_descriptor applies to explicit encryption. It must be
|
925
|
-
* either a key id or *one* key alt name, but not both.
|
926
|
-
* key_alt_names applies to creating a data key. It may be one or multiple
|
927
|
-
* key alt names.
|
928
|
-
*/
|
929
|
-
has_id = !_mongocrypt_buffer_empty (&ctx->opts.key_id);
|
930
|
-
has_alt_name = !!(ctx->opts.key_alt_names);
|
931
|
-
has_multiple_alt_names = has_alt_name && !!(ctx->opts.key_alt_names->next);
|
932
|
-
|
933
|
-
if (opts_spec->key_descriptor == OPT_REQUIRED) {
|
934
|
-
if (!has_id && !has_alt_name) {
|
935
|
-
return _mongocrypt_ctx_fail_w_msg (
|
936
|
-
ctx, "either key id or key alt name required");
|
937
|
-
}
|
938
|
-
|
939
|
-
if (has_id && has_alt_name) {
|
940
|
-
return _mongocrypt_ctx_fail_w_msg (
|
941
|
-
ctx, "cannot have both key id and key alt name");
|
942
|
-
}
|
943
|
-
|
944
|
-
if (has_multiple_alt_names) {
|
945
|
-
return _mongocrypt_ctx_fail_w_msg (
|
946
|
-
ctx, "must not specify multiple key alt names");
|
947
|
-
}
|
948
|
-
}
|
949
|
-
|
950
|
-
if (opts_spec->key_descriptor == OPT_PROHIBITED) {
|
951
|
-
/* still okay if key_alt_names are allowed and only alt names were
|
952
|
-
* specified. */
|
953
|
-
if ((opts_spec->key_alt_names == OPT_PROHIBITED && has_alt_name) ||
|
954
|
-
has_id) {
|
955
|
-
return _mongocrypt_ctx_fail_w_msg (ctx,
|
956
|
-
"key id and alt name prohibited");
|
957
|
-
}
|
958
|
-
}
|
959
|
-
|
960
|
-
if (opts_spec->key_material == OPT_PROHIBITED &&
|
961
|
-
ctx->opts.key_material.owned) {
|
962
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "key material prohibited");
|
963
|
-
}
|
964
|
-
|
965
|
-
if (opts_spec->algorithm == OPT_REQUIRED &&
|
966
|
-
ctx->opts.algorithm == MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE) {
|
967
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "algorithm required");
|
968
|
-
}
|
969
|
-
|
970
|
-
if (opts_spec->algorithm == OPT_PROHIBITED &&
|
971
|
-
ctx->opts.algorithm != MONGOCRYPT_ENCRYPTION_ALGORITHM_NONE) {
|
972
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "algorithm prohibited");
|
973
|
-
}
|
974
|
-
|
975
|
-
if (opts_spec->rangeopts == OPT_PROHIBITED && ctx->opts.rangeopts.set) {
|
976
|
-
return _mongocrypt_ctx_fail_w_msg (
|
977
|
-
ctx, "range opts are prohibited on this context");
|
978
|
-
}
|
979
|
-
|
980
|
-
_mongocrypt_key_broker_init (&ctx->kb, ctx->crypt);
|
981
|
-
return true;
|
982
|
-
}
|
969
|
+
ctx->opts.kek.provider.aws.endpoint =
|
970
|
+
_mongocrypt_endpoint_new(endpoint, endpoint_len, NULL /* opts */, ctx->status);
|
971
|
+
if (!ctx->opts.kek.provider.aws.endpoint) {
|
972
|
+
return _mongocrypt_ctx_fail(ctx);
|
973
|
+
}
|
983
974
|
|
984
|
-
|
985
|
-
_mongocrypt_ctx_state_from_key_broker (mongocrypt_ctx_t *ctx)
|
986
|
-
{
|
987
|
-
_mongocrypt_key_broker_t *kb;
|
988
|
-
mongocrypt_status_t *status;
|
989
|
-
mongocrypt_ctx_state_t new_state = MONGOCRYPT_CTX_ERROR;
|
990
|
-
bool ret = false;
|
991
|
-
|
992
|
-
BSON_ASSERT_PARAM (ctx);
|
993
|
-
|
994
|
-
status = ctx->status;
|
995
|
-
kb = &ctx->kb;
|
996
|
-
|
997
|
-
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
998
|
-
return false;
|
999
|
-
}
|
1000
|
-
|
1001
|
-
|
1002
|
-
switch (kb->state) {
|
1003
|
-
case KB_ERROR:
|
1004
|
-
_mongocrypt_status_copy_to (kb->status, status);
|
1005
|
-
new_state = MONGOCRYPT_CTX_ERROR;
|
1006
|
-
ret = false;
|
1007
|
-
break;
|
1008
|
-
case KB_ADDING_DOCS:
|
1009
|
-
/* Encrypted keys need KMS, which need to be provided before
|
1010
|
-
* adding docs. */
|
1011
|
-
if (_mongocrypt_needs_credentials (ctx->crypt)) {
|
1012
|
-
new_state = MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS;
|
1013
|
-
} else {
|
1014
|
-
/* Require key documents from driver. */
|
1015
|
-
new_state = MONGOCRYPT_CTX_NEED_MONGO_KEYS;
|
1016
|
-
}
|
1017
|
-
ret = true;
|
1018
|
-
break;
|
1019
|
-
case KB_ADDING_DOCS_ANY:
|
1020
|
-
/* Assume KMS credentials have been provided. */
|
1021
|
-
new_state = MONGOCRYPT_CTX_NEED_MONGO_KEYS;
|
1022
|
-
ret = true;
|
1023
|
-
break;
|
1024
|
-
case KB_AUTHENTICATING:
|
1025
|
-
case KB_DECRYPTING_KEY_MATERIAL:
|
1026
|
-
new_state = MONGOCRYPT_CTX_NEED_KMS;
|
1027
|
-
ret = true;
|
1028
|
-
break;
|
1029
|
-
case KB_DONE:
|
1030
|
-
new_state = MONGOCRYPT_CTX_READY;
|
1031
|
-
if (kb->key_requests == NULL) {
|
1032
|
-
/* No key requests were ever added. */
|
1033
|
-
ctx->nothing_to_do = true; /* nothing to encrypt/decrypt */
|
1034
|
-
}
|
1035
|
-
ret = true;
|
1036
|
-
break;
|
1037
|
-
/* As currently implemented, we do not expect to ever be in KB_REQUESTING
|
1038
|
-
* or KB_REQUESTING_ANY state when calling this function. */
|
1039
|
-
case KB_REQUESTING:
|
1040
|
-
default:
|
1041
|
-
CLIENT_ERR ("key broker in unexpected state");
|
1042
|
-
new_state = MONGOCRYPT_CTX_ERROR;
|
1043
|
-
ret = false;
|
1044
|
-
break;
|
1045
|
-
}
|
1046
|
-
|
1047
|
-
if (new_state != ctx->state) {
|
1048
|
-
ctx->state = new_state;
|
1049
|
-
}
|
1050
|
-
|
1051
|
-
return ret;
|
975
|
+
return true;
|
1052
976
|
}
|
1053
977
|
|
978
|
+
bool mongocrypt_ctx_setopt_key_encryption_key(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *bin) {
|
979
|
+
bson_t as_bson;
|
1054
980
|
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
int32_t endpoint_len)
|
1059
|
-
{
|
1060
|
-
if (!ctx) {
|
1061
|
-
return false;
|
1062
|
-
}
|
981
|
+
if (!ctx) {
|
982
|
+
return false;
|
983
|
+
}
|
1063
984
|
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
985
|
+
if (ctx->initialized) {
|
986
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot set options after init");
|
987
|
+
}
|
1067
988
|
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
989
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
990
|
+
return false;
|
991
|
+
}
|
1071
992
|
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
}
|
993
|
+
if (ctx->opts.kek.kms_provider) {
|
994
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "key encryption key already set");
|
995
|
+
}
|
1076
996
|
|
1077
|
-
|
997
|
+
if (!bin) {
|
998
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid NULL key encryption key document");
|
999
|
+
}
|
1078
1000
|
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1001
|
+
if (!_mongocrypt_binary_to_bson(bin, &as_bson)) {
|
1002
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid BSON");
|
1003
|
+
}
|
1082
1004
|
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
return _mongocrypt_ctx_fail (ctx);
|
1087
|
-
}
|
1005
|
+
if (!_mongocrypt_kek_parse_owned(&as_bson, &ctx->opts.kek, ctx->status)) {
|
1006
|
+
return _mongocrypt_ctx_fail(ctx);
|
1007
|
+
}
|
1088
1008
|
|
1089
|
-
|
1090
|
-
|
1009
|
+
if (ctx->crypt->log.trace_enabled) {
|
1010
|
+
char *bin_str = bson_as_canonical_extended_json(&as_bson, NULL);
|
1011
|
+
_mongocrypt_log(&ctx->crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "bin", bin_str);
|
1012
|
+
bson_free(bin_str);
|
1013
|
+
}
|
1091
1014
|
|
1092
|
-
|
1093
|
-
mongocrypt_ctx_setopt_key_encryption_key (mongocrypt_ctx_t *ctx,
|
1094
|
-
mongocrypt_binary_t *bin)
|
1095
|
-
{
|
1096
|
-
bson_t as_bson;
|
1097
|
-
|
1098
|
-
if (!ctx) {
|
1099
|
-
return false;
|
1100
|
-
}
|
1101
|
-
|
1102
|
-
if (ctx->initialized) {
|
1103
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "cannot set options after init");
|
1104
|
-
}
|
1105
|
-
|
1106
|
-
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
1107
|
-
return false;
|
1108
|
-
}
|
1109
|
-
|
1110
|
-
if (ctx->opts.kek.kms_provider) {
|
1111
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "key encryption key already set");
|
1112
|
-
}
|
1113
|
-
|
1114
|
-
if (!bin) {
|
1115
|
-
return _mongocrypt_ctx_fail_w_msg (
|
1116
|
-
ctx, "invalid NULL key encryption key document");
|
1117
|
-
}
|
1118
|
-
|
1119
|
-
if (!_mongocrypt_binary_to_bson (bin, &as_bson)) {
|
1120
|
-
return _mongocrypt_ctx_fail_w_msg (ctx, "invalid BSON");
|
1121
|
-
}
|
1122
|
-
|
1123
|
-
if (!_mongocrypt_kek_parse_owned (&as_bson, &ctx->opts.kek, ctx->status)) {
|
1124
|
-
return _mongocrypt_ctx_fail (ctx);
|
1125
|
-
}
|
1126
|
-
|
1127
|
-
if (ctx->crypt->log.trace_enabled) {
|
1128
|
-
char *bin_str = bson_as_canonical_extended_json (&as_bson, NULL);
|
1129
|
-
_mongocrypt_log (&ctx->crypt->log,
|
1130
|
-
MONGOCRYPT_LOG_LEVEL_TRACE,
|
1131
|
-
"%s (%s=\"%s\")",
|
1132
|
-
BSON_FUNC,
|
1133
|
-
"bin",
|
1134
|
-
bin_str);
|
1135
|
-
bson_free (bin_str);
|
1136
|
-
}
|
1137
|
-
|
1138
|
-
return true;
|
1015
|
+
return true;
|
1139
1016
|
}
|
1140
1017
|
|
1141
|
-
_mongocrypt_opts_kms_providers_t *
|
1142
|
-
|
1143
|
-
{
|
1144
|
-
BSON_ASSERT_PARAM (ctx);
|
1018
|
+
_mongocrypt_opts_kms_providers_t *_mongocrypt_ctx_kms_providers(mongocrypt_ctx_t *ctx) {
|
1019
|
+
BSON_ASSERT_PARAM(ctx);
|
1145
1020
|
|
1146
|
-
|
1147
|
-
? &ctx->kms_providers
|
1148
|
-
: &ctx->crypt->opts.kms_providers;
|
1021
|
+
return ctx->kms_providers.configured_providers ? &ctx->kms_providers : &ctx->crypt->opts.kms_providers;
|
1149
1022
|
}
|
1150
1023
|
|
1151
|
-
bool
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
ctx->opts.contention_factor.value = contention_factor;
|
1159
|
-
ctx->opts.contention_factor.set = true;
|
1160
|
-
return true;
|
1024
|
+
bool mongocrypt_ctx_setopt_contention_factor(mongocrypt_ctx_t *ctx, int64_t contention_factor) {
|
1025
|
+
if (!ctx) {
|
1026
|
+
return false;
|
1027
|
+
}
|
1028
|
+
ctx->opts.contention_factor.value = contention_factor;
|
1029
|
+
ctx->opts.contention_factor.set = true;
|
1030
|
+
return true;
|
1161
1031
|
}
|
1162
1032
|
|
1163
|
-
bool
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
if (!ctx) {
|
1168
|
-
return false;
|
1169
|
-
}
|
1033
|
+
bool mongocrypt_ctx_setopt_index_key_id(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *key_id) {
|
1034
|
+
if (!ctx) {
|
1035
|
+
return false;
|
1036
|
+
}
|
1170
1037
|
|
1171
|
-
|
1172
|
-
ctx, key_id, &ctx->opts.index_key_id, BSON_SUBTYPE_UUID);
|
1038
|
+
return _set_binary_opt(ctx, key_id, &ctx->opts.index_key_id, BSON_SUBTYPE_UUID);
|
1173
1039
|
}
|
1174
1040
|
|
1175
|
-
bool
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
return true;
|
1041
|
+
bool mongocrypt_ctx_setopt_query_type(mongocrypt_ctx_t *ctx, const char *query_type, int len) {
|
1042
|
+
if (!ctx) {
|
1043
|
+
return false;
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
if (ctx->initialized) {
|
1047
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "Cannot set options after init");
|
1048
|
+
}
|
1049
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
1050
|
+
return false;
|
1051
|
+
}
|
1052
|
+
if (len < -1) {
|
1053
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "Invalid query_type string length");
|
1054
|
+
}
|
1055
|
+
if (!query_type) {
|
1056
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "Invalid null query_type string");
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
const size_t calc_len = len == -1 ? strlen(query_type) : (size_t)len;
|
1060
|
+
mstr_view qt_str = mstrv_view_data(query_type, calc_len);
|
1061
|
+
if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR))) {
|
1062
|
+
ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_EQUALITY;
|
1063
|
+
ctx->opts.query_type.set = true;
|
1064
|
+
} else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_RANGE_STR))) {
|
1065
|
+
ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_RANGE;
|
1066
|
+
ctx->opts.query_type.set = true;
|
1067
|
+
} else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_DEPRECATED_STR))) {
|
1068
|
+
if (ctx->crypt->opts.use_range_v2) {
|
1069
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "Query type 'rangePreview' is deprecated, please use 'range'");
|
1070
|
+
return false;
|
1071
|
+
}
|
1072
|
+
ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_DEPRECATED;
|
1073
|
+
ctx->opts.query_type.set = true;
|
1074
|
+
} else {
|
1075
|
+
/* don't check if qt_str.len fits in int; we want the diagnostic output */
|
1076
|
+
char *error = bson_strdup_printf("Unsupported query_type \"%.*s\"",
|
1077
|
+
qt_str.len <= (size_t)INT_MAX ? (int)qt_str.len : INT_MAX,
|
1078
|
+
qt_str.data);
|
1079
|
+
_mongocrypt_ctx_fail_w_msg(ctx, error);
|
1080
|
+
bson_free(error);
|
1081
|
+
return false;
|
1082
|
+
}
|
1083
|
+
return true;
|
1219
1084
|
}
|
1220
1085
|
|
1221
|
-
const char *
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
case MONGOCRYPT_INDEX_TYPE_RANGEPREVIEW:
|
1230
|
-
return "RangePreview";
|
1231
|
-
default:
|
1232
|
-
return "Unknown";
|
1233
|
-
}
|
1086
|
+
const char *_mongocrypt_index_type_to_string(mongocrypt_index_type_t val) {
|
1087
|
+
switch (val) {
|
1088
|
+
case MONGOCRYPT_INDEX_TYPE_NONE: return "None";
|
1089
|
+
case MONGOCRYPT_INDEX_TYPE_EQUALITY: return "Equality";
|
1090
|
+
case MONGOCRYPT_INDEX_TYPE_RANGE: return "Range";
|
1091
|
+
case MONGOCRYPT_INDEX_TYPE_RANGEPREVIEW_DEPRECATED: return "RangePreview";
|
1092
|
+
default: return "Unknown";
|
1093
|
+
}
|
1234
1094
|
}
|
1235
1095
|
|
1236
|
-
const char *
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
return "RangePreview";
|
1244
|
-
default:
|
1245
|
-
return "Unknown";
|
1246
|
-
}
|
1096
|
+
const char *_mongocrypt_query_type_to_string(mongocrypt_query_type_t val) {
|
1097
|
+
switch (val) {
|
1098
|
+
case MONGOCRYPT_QUERY_TYPE_EQUALITY: return "Equality";
|
1099
|
+
case MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_DEPRECATED: return "RangePreview";
|
1100
|
+
case MONGOCRYPT_QUERY_TYPE_RANGE: return "Range";
|
1101
|
+
default: return "Unknown";
|
1102
|
+
}
|
1247
1103
|
}
|
1248
1104
|
|
1249
|
-
bool
|
1250
|
-
|
1251
|
-
mongocrypt_binary_t *opts)
|
1252
|
-
{
|
1253
|
-
bson_t as_bson;
|
1254
|
-
|
1255
|
-
if (!ctx) {
|
1256
|
-
return false;
|
1257
|
-
}
|
1105
|
+
bool mongocrypt_ctx_setopt_algorithm_range(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *opts) {
|
1106
|
+
bson_t as_bson;
|
1258
1107
|
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1108
|
+
if (!ctx) {
|
1109
|
+
return false;
|
1110
|
+
}
|
1262
1111
|
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1112
|
+
if (ctx->initialized) {
|
1113
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "cannot set options after init");
|
1114
|
+
}
|
1266
1115
|
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1116
|
+
if (ctx->state == MONGOCRYPT_CTX_ERROR) {
|
1117
|
+
return false;
|
1118
|
+
}
|
1270
1119
|
|
1120
|
+
if (ctx->opts.rangeopts.set) {
|
1121
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "RangeOpts already set");
|
1122
|
+
}
|
1271
1123
|
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1124
|
+
if (!_mongocrypt_binary_to_bson(opts, &as_bson)) {
|
1125
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid BSON");
|
1126
|
+
}
|
1275
1127
|
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
}
|
1128
|
+
if (!mc_RangeOpts_parse(&ctx->opts.rangeopts.value, &as_bson, ctx->crypt->opts.use_range_v2, ctx->status)) {
|
1129
|
+
return _mongocrypt_ctx_fail(ctx);
|
1130
|
+
}
|
1280
1131
|
|
1281
|
-
|
1282
|
-
|
1132
|
+
ctx->opts.rangeopts.set = true;
|
1133
|
+
return true;
|
1283
1134
|
}
|