libmongocrypt-helper 1.7.4.0.1002 → 1.8.0.0.1001
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
- data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
- data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
- data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
- data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
- 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/Scripts/build.cake +3 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
- 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/node/CHANGELOG.md +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
- data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
- 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/test_mongocrypt.py +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
- data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
- data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
- data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
- data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
- data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -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/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
- 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 +180 -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 +7 -11
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -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 +88 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -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 +117 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -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 +476 -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 +55 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
- data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
- 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 +55 -49
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -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 +444 -499
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -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 +3 -6
- 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 +444 -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 +103 -132
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
- 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 +1137 -1565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -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 +37 -43
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
- 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 +92 -120
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
- 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 +30 -36
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
- 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 +96 -135
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -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/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/encrypted-payload.json +2 -2
- 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/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 +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
- data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -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 +58 -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 +89 -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 +172 -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 +346 -388
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -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 +34 -36
- 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-compact.c +331 -445
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -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 +867 -1045
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
- 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 +286 -370
- 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 +656 -692
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
- data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
- data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
- data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
- data/lib/libmongocrypt_helper/version.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +154 -26
- metadata.gz.sig +0 -0
- 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/lib/credentialsProvider.js +0 -33
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
- 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-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
- 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/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/rangeopts.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/rangeopts.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
@@ -18,1284 +18,1097 @@
|
|
18
18
|
|
19
19
|
#include <stdarg.h>
|
20
20
|
|
21
|
-
#include "test-mongocrypt.h"
|
22
21
|
#include "mongocrypt-binary-private.h"
|
22
|
+
#include "test-mongocrypt.h"
|
23
23
|
|
24
24
|
/* An orphaned UTF-8 continuation byte (10xxxxxx) is malformed UTF-8. */
|
25
|
-
static char invalid_utf8[] = {(char)
|
25
|
+
static char invalid_utf8[] = {(char)0x80, (char)0x00};
|
26
26
|
|
27
27
|
/* Convenience macros for setting options */
|
28
|
-
#define ASSERT_MASTERKEY_AWS_OK(region, region_len, cmk, cmk_len)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
#define
|
41
|
-
|
42
|
-
|
43
|
-
#define
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
#define
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#define
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#define
|
60
|
-
|
61
|
-
#define
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#define
|
66
|
-
|
67
|
-
#define
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
#define
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
#define
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
#define
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
#define ASSERT_ENCRYPT_INIT_OK(db, db_len, cmd) \
|
92
|
-
ASSERT_OK (mongocrypt_ctx_encrypt_init (ctx, db, db_len, cmd), ctx);
|
93
|
-
#define ENCRYPT_INIT_FAILS(db, db_len, cmd, msg) \
|
94
|
-
ASSERT_FAILS (mongocrypt_ctx_encrypt_init (ctx, db, db_len, cmd), ctx, msg);
|
95
|
-
|
96
|
-
#define ASSERT_EX_ENCRYPT_INIT_OK(bin) \
|
97
|
-
ASSERT_OK (mongocrypt_ctx_explicit_encrypt_init (ctx, bin), ctx);
|
98
|
-
#define ASSERT_EX_ENCRYPT_INIT_FAILS(bin, msg) \
|
99
|
-
ASSERT_FAILS (mongocrypt_ctx_explicit_encrypt_init (ctx, bin), ctx, msg);
|
100
|
-
|
101
|
-
#define ASSERT_EX_ENCRYPT_EXPRESSION_INIT_OK(bin) \
|
102
|
-
ASSERT_OK (mongocrypt_ctx_explicit_encrypt_expression_init (ctx, bin), ctx);
|
103
|
-
#define ASSERT_EX_ENCRYPT_EXPRESSION_INIT_FAILS(bin, msg) \
|
104
|
-
ASSERT_FAILS ( \
|
105
|
-
mongocrypt_ctx_explicit_encrypt_expression_init (ctx, bin), ctx, msg);
|
106
|
-
|
107
|
-
#define ASSERT_DECRYPT_INIT_OK(bin) \
|
108
|
-
ASSERT_OK (mongocrypt_ctx_decrypt_init (ctx, bin), ctx);
|
109
|
-
#define ASSERT_DECRYPT_INIT_FAILS(bin, msg) \
|
110
|
-
ASSERT_FAILS (mongocrypt_ctx_decrypt_init (ctx, bin), ctx, msg);
|
111
|
-
|
112
|
-
#define ASSERT_EX_DECRYPT_INIT_OK(bin) \
|
113
|
-
ASSERT_OK (mongocrypt_ctx_explicit_decrypt_init (ctx, bin), ctx);
|
114
|
-
#define ASSERT_EX_DECRYPT_INIT_FAILS(bin, msg) \
|
115
|
-
ASSERT_FAILS (mongocrypt_ctx_explicit_decrypt_init (ctx, bin), ctx, msg);
|
116
|
-
|
117
|
-
#define REFRESH \
|
118
|
-
do { \
|
119
|
-
mongocrypt_ctx_destroy (ctx); \
|
120
|
-
ctx = mongocrypt_ctx_new (crypt); \
|
121
|
-
} while (0)
|
28
|
+
#define ASSERT_MASTERKEY_AWS_OK(region, region_len, cmk, cmk_len) \
|
29
|
+
ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, region, region_len, cmk, cmk_len), ctx);
|
30
|
+
#define ASSERT_MASTERKEY_AWS_FAILS(region, region_len, cmk, cmk_len, msg) \
|
31
|
+
ASSERT_FAILS(mongocrypt_ctx_setopt_masterkey_aws(ctx, region, region_len, cmk, cmk_len), ctx, msg);
|
32
|
+
|
33
|
+
#define ASSERT_MASTERKEY_LOCAL_OK ASSERT_OK(mongocrypt_ctx_setopt_masterkey_local(ctx), ctx);
|
34
|
+
#define ASSERT_MASTERKEY_LOCAL_FAILS(msg) ASSERT_FAILS(mongocrypt_ctx_setopt_masterkey_local(ctx), ctx, msg);
|
35
|
+
|
36
|
+
#define ASSERT_KEY_ENCRYPTION_KEY_OK(bin) ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx, bin), ctx);
|
37
|
+
#define ASSERT_KEY_ENCRYPTION_KEY_FAILS(bin, msg) \
|
38
|
+
ASSERT_FAILS(mongocrypt_ctx_setopt_key_encryption_key(ctx, bin), ctx, msg);
|
39
|
+
|
40
|
+
#define ASSERT_KEY_ID_OK(key_id) ASSERT_OK(mongocrypt_ctx_setopt_key_id(ctx, key_id), ctx);
|
41
|
+
#define ASSERT_KEY_ID_FAILS(key_id, msg) ASSERT_FAILS(mongocrypt_ctx_setopt_key_id(ctx, key_id), ctx, msg);
|
42
|
+
|
43
|
+
#define ASSERT_KEY_ALT_NAME_OK(key_alt_name) ASSERT_OK(mongocrypt_ctx_setopt_key_alt_name(ctx, key_alt_name), ctx);
|
44
|
+
#define ASSERT_KEY_ALT_NAME_FAILS(key_alt_name, msg) \
|
45
|
+
ASSERT_FAILS(mongocrypt_ctx_setopt_key_alt_name(ctx, key_alt_name), ctx, msg);
|
46
|
+
|
47
|
+
#define ASSERT_KEY_MATERIAL_OK(key_material) ASSERT_OK(mongocrypt_ctx_setopt_key_material(ctx, key_material), ctx);
|
48
|
+
#define ASSERT_KEY_MATERIAL_FAILS(key_material, msg) \
|
49
|
+
ASSERT_FAILS(mongocrypt_ctx_setopt_key_material(ctx, key_material), ctx, msg);
|
50
|
+
|
51
|
+
#define ASSERT_ALGORITHM_OK(algo, algo_len) ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, algo, algo_len), ctx);
|
52
|
+
#define ASSERT_ALGORITHM_FAILS(algo, algo_len, msg) \
|
53
|
+
ASSERT_FAILS(mongocrypt_ctx_setopt_algorithm(ctx, algo, algo_len), ctx, msg);
|
54
|
+
|
55
|
+
#define ASSERT_QUERY_TYPE_OK(qt, qt_len) ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, qt, qt_len), ctx);
|
56
|
+
#define ASSERT_QUERY_TYPE_FAILS(qt, qt_len, msg) \
|
57
|
+
ASSERT_FAILS(mongocrypt_ctx_setopt_query_type(ctx, qt, qt_len), ctx, msg);
|
58
|
+
|
59
|
+
#define ASSERT_ENDPOINT_OK(endpoint, endpoint_len) \
|
60
|
+
ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws_endpoint(ctx, endpoint, endpoint_len), ctx);
|
61
|
+
#define ASSERT_ENDPOINT_FAILS(endpoint, endpoint_len, msg) \
|
62
|
+
ASSERT_FAILS(mongocrypt_ctx_setopt_masterkey_aws_endpoint(ctx, endpoint, endpoint_len), ctx, msg);
|
63
|
+
|
64
|
+
#define ASSERT_DATAKEY_INIT_OK ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
|
65
|
+
#define ASSERT_DATAKEY_INIT_FAILS(msg) ASSERT_FAILS(mongocrypt_ctx_datakey_init(ctx), ctx, msg);
|
66
|
+
|
67
|
+
#define ASSERT_ENCRYPT_INIT_OK(db, db_len, cmd) ASSERT_OK(mongocrypt_ctx_encrypt_init(ctx, db, db_len, cmd), ctx);
|
68
|
+
#define ENCRYPT_INIT_FAILS(db, db_len, cmd, msg) \
|
69
|
+
ASSERT_FAILS(mongocrypt_ctx_encrypt_init(ctx, db, db_len, cmd), ctx, msg);
|
70
|
+
|
71
|
+
#define ASSERT_EX_ENCRYPT_INIT_OK(bin) ASSERT_OK(mongocrypt_ctx_explicit_encrypt_init(ctx, bin), ctx);
|
72
|
+
#define ASSERT_EX_ENCRYPT_INIT_FAILS(bin, msg) ASSERT_FAILS(mongocrypt_ctx_explicit_encrypt_init(ctx, bin), ctx, msg);
|
73
|
+
|
74
|
+
#define ASSERT_EX_ENCRYPT_EXPRESSION_INIT_OK(bin) \
|
75
|
+
ASSERT_OK(mongocrypt_ctx_explicit_encrypt_expression_init(ctx, bin), ctx);
|
76
|
+
#define ASSERT_EX_ENCRYPT_EXPRESSION_INIT_FAILS(bin, msg) \
|
77
|
+
ASSERT_FAILS(mongocrypt_ctx_explicit_encrypt_expression_init(ctx, bin), ctx, msg);
|
78
|
+
|
79
|
+
#define ASSERT_DECRYPT_INIT_OK(bin) ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, bin), ctx);
|
80
|
+
#define ASSERT_DECRYPT_INIT_FAILS(bin, msg) ASSERT_FAILS(mongocrypt_ctx_decrypt_init(ctx, bin), ctx, msg);
|
81
|
+
|
82
|
+
#define ASSERT_EX_DECRYPT_INIT_OK(bin) ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(ctx, bin), ctx);
|
83
|
+
#define ASSERT_EX_DECRYPT_INIT_FAILS(bin, msg) ASSERT_FAILS(mongocrypt_ctx_explicit_decrypt_init(ctx, bin), ctx, msg);
|
84
|
+
|
85
|
+
#define REFRESH \
|
86
|
+
do { \
|
87
|
+
mongocrypt_ctx_destroy(ctx); \
|
88
|
+
ctx = mongocrypt_ctx_new(crypt); \
|
89
|
+
} while (0)
|
122
90
|
|
123
91
|
#define DET MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR
|
124
92
|
#define RAND MONGOCRYPT_ALGORITHM_RANDOM_STR
|
125
93
|
|
126
94
|
/* Test valid and invalid options */
|
127
|
-
static void
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
mongocrypt_ctx_destroy (ctx);
|
169
|
-
mongocrypt_destroy (crypt);
|
95
|
+
static void _test_setopt_masterkey_aws(_mongocrypt_tester_t *tester) {
|
96
|
+
mongocrypt_t *crypt;
|
97
|
+
mongocrypt_ctx_t *ctx = NULL;
|
98
|
+
|
99
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
100
|
+
|
101
|
+
REFRESH;
|
102
|
+
ASSERT_MASTERKEY_AWS_FAILS(NULL, 0, "cmk", 3, "invalid region");
|
103
|
+
REFRESH;
|
104
|
+
ASSERT_MASTERKEY_AWS_FAILS("region", 6, NULL, 0, "invalid cmk");
|
105
|
+
REFRESH;
|
106
|
+
ASSERT_MASTERKEY_AWS_FAILS("region", 0, "cmk", 0, "invalid region");
|
107
|
+
REFRESH;
|
108
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
109
|
+
REFRESH;
|
110
|
+
ASSERT_MASTERKEY_AWS_FAILS("region", -2, "cmk", -1, "invalid region");
|
111
|
+
REFRESH;
|
112
|
+
ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -2, "invalid cmk");
|
113
|
+
|
114
|
+
/* Test invalid UTF 8 */
|
115
|
+
REFRESH;
|
116
|
+
ASSERT_MASTERKEY_AWS_FAILS(invalid_utf8, -1, "cmk", -2, "invalid region");
|
117
|
+
|
118
|
+
/* Test double setting. */
|
119
|
+
REFRESH;
|
120
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
121
|
+
ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -1, "master key already set");
|
122
|
+
|
123
|
+
/* Cannot be set with local masterkey. */
|
124
|
+
REFRESH;
|
125
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
126
|
+
ASSERT_MASTERKEY_LOCAL_FAILS("master key already set");
|
127
|
+
|
128
|
+
/* Cannot be set after entering error state. */
|
129
|
+
REFRESH;
|
130
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "test");
|
131
|
+
ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -1, "test");
|
132
|
+
|
133
|
+
mongocrypt_ctx_destroy(ctx);
|
134
|
+
mongocrypt_destroy(crypt);
|
170
135
|
}
|
171
136
|
|
137
|
+
static void _test_setopt_masterkey_local(_mongocrypt_tester_t *tester) {
|
138
|
+
mongocrypt_t *crypt;
|
139
|
+
mongocrypt_ctx_t *ctx = NULL;
|
172
140
|
|
173
|
-
|
174
|
-
_test_setopt_masterkey_local (_mongocrypt_tester_t *tester)
|
175
|
-
{
|
176
|
-
mongocrypt_t *crypt;
|
177
|
-
mongocrypt_ctx_t *ctx = NULL;
|
141
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
178
142
|
|
179
|
-
|
143
|
+
/* Test double setting. */
|
144
|
+
REFRESH;
|
145
|
+
ASSERT_MASTERKEY_LOCAL_OK;
|
146
|
+
ASSERT_MASTERKEY_LOCAL_FAILS("master key already set");
|
180
147
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
148
|
+
/* Cannot be set with aws masterkey. */
|
149
|
+
REFRESH;
|
150
|
+
ASSERT_MASTERKEY_LOCAL_OK;
|
151
|
+
ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -1, "master key already set");
|
185
152
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
ASSERT_MASTERKEY_AWS_FAILS (
|
190
|
-
"region", -1, "cmk", -1, "master key already set");
|
153
|
+
REFRESH;
|
154
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "test");
|
155
|
+
ASSERT_MASTERKEY_LOCAL_FAILS("test");
|
191
156
|
|
192
|
-
|
193
|
-
|
194
|
-
ASSERT_MASTERKEY_LOCAL_FAILS ("test");
|
195
|
-
|
196
|
-
mongocrypt_ctx_destroy (ctx);
|
197
|
-
mongocrypt_destroy (crypt);
|
157
|
+
mongocrypt_ctx_destroy(ctx);
|
158
|
+
mongocrypt_destroy(crypt);
|
198
159
|
}
|
199
160
|
|
200
|
-
static void
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
TEST_BSON ("{'provider': 'azure', 'keyName': '', "
|
230
|
-
"'keyVaultEndpoint': 'example.com' }"),
|
231
|
-
"test");
|
232
|
-
|
233
|
-
mongocrypt_ctx_destroy (ctx);
|
234
|
-
mongocrypt_destroy (crypt);
|
161
|
+
static void _test_setopt_key_encryption_key_azure(_mongocrypt_tester_t *tester) {
|
162
|
+
mongocrypt_t *crypt;
|
163
|
+
mongocrypt_ctx_t *ctx = NULL;
|
164
|
+
|
165
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
166
|
+
|
167
|
+
/* Test double setting. */
|
168
|
+
REFRESH;
|
169
|
+
ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
|
170
|
+
"'keyVaultEndpoint': 'example.com' }"));
|
171
|
+
ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'azure', 'keyName': '', "
|
172
|
+
"'keyVaultEndpoint': 'example.com' }"),
|
173
|
+
"key encryption key already set");
|
174
|
+
|
175
|
+
/* Cannot be set when another masterkey is set. */
|
176
|
+
REFRESH;
|
177
|
+
ASSERT_MASTERKEY_LOCAL_OK;
|
178
|
+
ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'azure', 'keyName': '', "
|
179
|
+
"'keyVaultEndpoint': 'example.com' }"),
|
180
|
+
"key encryption key already set");
|
181
|
+
|
182
|
+
REFRESH;
|
183
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "test");
|
184
|
+
ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'azure', 'keyName': '', "
|
185
|
+
"'keyVaultEndpoint': 'example.com' }"),
|
186
|
+
"test");
|
187
|
+
|
188
|
+
mongocrypt_ctx_destroy(ctx);
|
189
|
+
mongocrypt_destroy(crypt);
|
235
190
|
}
|
236
191
|
|
237
|
-
static void
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
TEST_BSON ("{'provider': 'gcp', 'projectId': 'proj', 'location': "
|
267
|
-
"'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
|
268
|
-
"test");
|
269
|
-
|
270
|
-
mongocrypt_ctx_destroy (ctx);
|
271
|
-
mongocrypt_destroy (crypt);
|
192
|
+
static void _test_setopt_key_encryption_key_gcp(_mongocrypt_tester_t *tester) {
|
193
|
+
mongocrypt_t *crypt;
|
194
|
+
mongocrypt_ctx_t *ctx = NULL;
|
195
|
+
|
196
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
197
|
+
|
198
|
+
/* Test double setting. */
|
199
|
+
REFRESH;
|
200
|
+
ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'gcp', 'projectId': 'proj', 'location': "
|
201
|
+
"'google.com', 'keyRing': 'ring', 'keyName': 'key' }"));
|
202
|
+
ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'gcp', 'projectId': 'proj', 'location': "
|
203
|
+
"'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
|
204
|
+
"key encryption key already set");
|
205
|
+
|
206
|
+
/* Cannot be set when another masterkey is set. */
|
207
|
+
REFRESH;
|
208
|
+
ASSERT_MASTERKEY_LOCAL_OK;
|
209
|
+
ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'gcp', 'projectId': 'proj', 'location': "
|
210
|
+
"'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
|
211
|
+
"key encryption key already set");
|
212
|
+
|
213
|
+
REFRESH;
|
214
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "test");
|
215
|
+
ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'gcp', 'projectId': 'proj', 'location': "
|
216
|
+
"'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
|
217
|
+
"test");
|
218
|
+
|
219
|
+
mongocrypt_ctx_destroy(ctx);
|
220
|
+
mongocrypt_destroy(crypt);
|
272
221
|
}
|
273
222
|
|
223
|
+
static void _test_setopt_key_id(_mongocrypt_tester_t *tester) {
|
224
|
+
mongocrypt_t *crypt;
|
225
|
+
mongocrypt_ctx_t *ctx = NULL;
|
274
226
|
|
275
|
-
|
276
|
-
_test_setopt_key_id (_mongocrypt_tester_t *tester)
|
277
|
-
{
|
278
|
-
mongocrypt_t *crypt;
|
279
|
-
mongocrypt_ctx_t *ctx = NULL;
|
280
|
-
|
281
|
-
crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
|
227
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
282
228
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
229
|
+
/* Test double setting. */
|
230
|
+
REFRESH;
|
231
|
+
ASSERT_KEY_ID_OK(TEST_BIN(16));
|
232
|
+
ASSERT_KEY_ID_FAILS(TEST_BIN(16), "option already set");
|
287
233
|
|
288
|
-
|
289
|
-
|
290
|
-
|
234
|
+
/* Test NULL/empty input */
|
235
|
+
REFRESH;
|
236
|
+
ASSERT_KEY_ID_FAILS(NULL, "option must be non-NULL");
|
291
237
|
|
292
|
-
|
293
|
-
|
238
|
+
REFRESH;
|
239
|
+
ASSERT_KEY_ID_FAILS(TEST_BIN(0), "option must be non-NULL");
|
294
240
|
|
295
|
-
|
296
|
-
|
297
|
-
|
241
|
+
/* Test wrong length */
|
242
|
+
REFRESH;
|
243
|
+
ASSERT_KEY_ID_FAILS(TEST_BIN(5), "expected 16 byte UUID");
|
298
244
|
|
299
|
-
|
300
|
-
|
301
|
-
|
245
|
+
REFRESH;
|
246
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "test");
|
247
|
+
ASSERT_KEY_ID_FAILS(TEST_BIN(16), "test");
|
302
248
|
|
303
|
-
|
304
|
-
|
249
|
+
mongocrypt_ctx_destroy(ctx);
|
250
|
+
mongocrypt_destroy(crypt);
|
305
251
|
}
|
306
252
|
|
253
|
+
static void _test_setopt_key_alt_name(_mongocrypt_tester_t *tester) {
|
254
|
+
mongocrypt_t *crypt;
|
255
|
+
mongocrypt_ctx_t *ctx = NULL;
|
307
256
|
|
308
|
-
|
309
|
-
_test_setopt_key_alt_name (_mongocrypt_tester_t *tester)
|
310
|
-
{
|
311
|
-
mongocrypt_t *crypt;
|
312
|
-
mongocrypt_ctx_t *ctx = NULL;
|
257
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
313
258
|
|
314
|
-
|
259
|
+
/* Test double setting - actually succeeds since multiple key alt names
|
260
|
+
* allowed for data keys. */
|
261
|
+
REFRESH;
|
262
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
263
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'def'}"));
|
315
264
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
|
320
|
-
ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'def'}"));
|
265
|
+
/* Test NULL/empty input */
|
266
|
+
REFRESH;
|
267
|
+
ASSERT_KEY_ALT_NAME_FAILS(NULL, "option must be non-NULL");
|
321
268
|
|
322
|
-
|
323
|
-
|
324
|
-
ASSERT_KEY_ALT_NAME_FAILS (NULL, "option must be non-NULL");
|
269
|
+
REFRESH;
|
270
|
+
ASSERT_KEY_ALT_NAME_FAILS(TEST_BIN(0), "option must be non-NULL");
|
325
271
|
|
326
|
-
|
327
|
-
|
272
|
+
/* Test wrong type */
|
273
|
+
REFRESH;
|
274
|
+
REFRESH;
|
275
|
+
ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'keyAltName': 1}"), "keyAltName expected to be UTF8");
|
328
276
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
ASSERT_KEY_ALT_NAME_FAILS (TEST_BSON ("{'keyAltName': 1}"),
|
333
|
-
"keyAltName expected to be UTF8");
|
277
|
+
/* Test missing key */
|
278
|
+
REFRESH;
|
279
|
+
ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'keyAltNames': 'abc'}"), "keyAltName must have field 'keyAltName'");
|
334
280
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
"keyAltName must have field 'keyAltName'");
|
281
|
+
/* Test extra key */
|
282
|
+
REFRESH;
|
283
|
+
ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'keyAltName': 'abc', 'extra': 1}"), "unrecognized field");
|
339
284
|
|
340
|
-
|
341
|
-
|
342
|
-
ASSERT_KEY_ALT_NAME_FAILS (TEST_BSON ("{'keyAltName': 'abc', 'extra': 1}"),
|
343
|
-
"unrecognized field");
|
344
|
-
|
345
|
-
mongocrypt_ctx_destroy (ctx);
|
346
|
-
mongocrypt_destroy (crypt);
|
285
|
+
mongocrypt_ctx_destroy(ctx);
|
286
|
+
mongocrypt_destroy(crypt);
|
347
287
|
}
|
348
288
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
ASSERT_KEY_MATERIAL_FAILS (TEST_BSON ("{}"), "invalid bson");
|
407
|
-
|
408
|
-
REFRESH;
|
409
|
-
ASSERT_KEY_MATERIAL_FAILS (TEST_BSON ("{'a': 1}"),
|
410
|
-
"keyMaterial must have field 'keyMaterial'");
|
411
|
-
|
412
|
-
REFRESH;
|
413
|
-
ASSERT_KEY_MATERIAL_FAILS (TEST_BSON ("{'keyMaterial': 1}"),
|
414
|
-
"keyMaterial must be binary data");
|
415
|
-
|
416
|
-
/* Test extra key. */
|
417
|
-
REFRESH;
|
418
|
-
ASSERT_KEY_MATERIAL_FAILS (TEST_BSON (pattern, material, ", 'a': 1"),
|
289
|
+
static void _test_setopt_key_material(_mongocrypt_tester_t *tester) {
|
290
|
+
/* "0123456789abcef", repeated 6 times. */
|
291
|
+
const char *const material = "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyMzQ1"
|
292
|
+
"Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVm";
|
293
|
+
const char *const pattern = "{'keyMaterial': {'$binary': {'base64': '%s', 'subType': '00'}}%s}";
|
294
|
+
mongocrypt_binary_t *const valid = TEST_BSON(pattern, material, "");
|
295
|
+
|
296
|
+
mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
297
|
+
mongocrypt_ctx_t *ctx = NULL;
|
298
|
+
|
299
|
+
/* Test double setting. */
|
300
|
+
REFRESH;
|
301
|
+
ASSERT_KEY_MATERIAL_OK(valid);
|
302
|
+
ASSERT_KEY_MATERIAL_FAILS(valid, "keyMaterial already set");
|
303
|
+
|
304
|
+
/* Test NULL input. */
|
305
|
+
REFRESH;
|
306
|
+
ASSERT_KEY_MATERIAL_FAILS(NULL, "option must be non-NULL");
|
307
|
+
|
308
|
+
/* Test empty input. */
|
309
|
+
REFRESH;
|
310
|
+
ASSERT_KEY_MATERIAL_FAILS(TEST_BIN(0), "option must be non-NULL");
|
311
|
+
|
312
|
+
/* Test empty key material. */
|
313
|
+
REFRESH;
|
314
|
+
ASSERT_KEY_MATERIAL_FAILS(TEST_BSON(pattern, "", ""), "keyMaterial should have length 96, but has length 0");
|
315
|
+
|
316
|
+
/* Test too short key material. */
|
317
|
+
REFRESH;
|
318
|
+
ASSERT_KEY_MATERIAL_FAILS(TEST_BSON(pattern,
|
319
|
+
"dG9vc2hvcnQ=", /* "tooshort" */
|
320
|
+
""),
|
321
|
+
"keyMaterial should have length 96, but has length 8");
|
322
|
+
|
323
|
+
/* Test too long key material. */
|
324
|
+
REFRESH;
|
325
|
+
ASSERT_KEY_MATERIAL_FAILS(TEST_BSON(pattern,
|
326
|
+
/* "0123456789abcdef", repeated 6 times, followed by "toolong". */
|
327
|
+
"MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyM"
|
328
|
+
"zQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmdG9vbG9uZw"
|
329
|
+
"==",
|
330
|
+
""),
|
331
|
+
"keyMaterial should have length 96, but has length 103");
|
332
|
+
|
333
|
+
/* Test invalid keyMaterial options. */
|
334
|
+
REFRESH;
|
335
|
+
ASSERT_KEY_MATERIAL_FAILS(TEST_BSON("{}"), "invalid bson");
|
336
|
+
|
337
|
+
REFRESH;
|
338
|
+
ASSERT_KEY_MATERIAL_FAILS(TEST_BSON("{'a': 1}"), "keyMaterial must have field 'keyMaterial'");
|
339
|
+
|
340
|
+
REFRESH;
|
341
|
+
ASSERT_KEY_MATERIAL_FAILS(TEST_BSON("{'keyMaterial': 1}"), "keyMaterial must be binary data");
|
342
|
+
|
343
|
+
/* Test extra key. */
|
344
|
+
REFRESH;
|
345
|
+
ASSERT_KEY_MATERIAL_FAILS(TEST_BSON(pattern, material, ", 'a': 1"),
|
419
346
|
"unrecognized field, only keyMaterial expected");
|
420
347
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
348
|
+
/* Test error propagation. */
|
349
|
+
REFRESH;
|
350
|
+
ASSERT(!_mongocrypt_ctx_fail_w_msg(ctx, "test"));
|
351
|
+
ASSERT_KEY_MATERIAL_FAILS(valid, "test");
|
425
352
|
|
426
|
-
|
427
|
-
|
353
|
+
mongocrypt_ctx_destroy(ctx);
|
354
|
+
mongocrypt_destroy(crypt);
|
428
355
|
}
|
429
356
|
|
357
|
+
static void _test_setopt_algorithm(_mongocrypt_tester_t *tester) {
|
358
|
+
mongocrypt_t *crypt;
|
359
|
+
mongocrypt_ctx_t *ctx = NULL;
|
430
360
|
|
431
|
-
|
432
|
-
_test_setopt_algorithm (_mongocrypt_tester_t *tester)
|
433
|
-
{
|
434
|
-
mongocrypt_t *crypt;
|
435
|
-
mongocrypt_ctx_t *ctx = NULL;
|
361
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
436
362
|
|
437
|
-
|
363
|
+
REFRESH;
|
364
|
+
ASSERT_ALGORITHM_FAILS(DET, -2, "invalid algorithm length");
|
438
365
|
|
439
|
-
|
440
|
-
|
366
|
+
REFRESH;
|
367
|
+
ASSERT_ALGORITHM_OK(DET, 43);
|
441
368
|
|
442
|
-
|
443
|
-
|
369
|
+
REFRESH;
|
370
|
+
ASSERT_ALGORITHM_FAILS(DET, 42, "unsupported algorithm");
|
444
371
|
|
445
|
-
|
446
|
-
|
372
|
+
/* Check for prior bug. It's "Random", not "Randomized" */
|
373
|
+
REFRESH;
|
374
|
+
ASSERT_ALGORITHM_FAILS(RAND "ized", -1, "unsupported algorithm");
|
447
375
|
|
448
|
-
|
449
|
-
|
450
|
-
|
376
|
+
/* Test double setting. */
|
377
|
+
REFRESH;
|
378
|
+
ASSERT_ALGORITHM_OK(DET, -1);
|
379
|
+
ASSERT_ALGORITHM_FAILS(DET, -1, "already set algorithm");
|
451
380
|
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
ASSERT_ALGORITHM_FAILS (DET, -1, "already set algorithm");
|
381
|
+
/* Test NULL input */
|
382
|
+
REFRESH;
|
383
|
+
ASSERT_ALGORITHM_FAILS(NULL, 0, "passed null algorithm");
|
456
384
|
|
457
|
-
|
458
|
-
|
459
|
-
|
385
|
+
REFRESH;
|
386
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "test");
|
387
|
+
ASSERT_ALGORITHM_FAILS(RAND, -1, "test")
|
460
388
|
|
461
|
-
|
462
|
-
|
463
|
-
|
389
|
+
/* Test case insensitive. */
|
390
|
+
REFRESH;
|
391
|
+
ASSERT_ALGORITHM_OK("aEAD_AES_256_CBC_HMAC_SHA_512-Deterministic", -1);
|
392
|
+
REFRESH;
|
393
|
+
ASSERT_ALGORITHM_OK("aEAD_AES_256_CBC_HMAC_SHA_512-Random", -1);
|
394
|
+
REFRESH;
|
395
|
+
ASSERT_ALGORITHM_OK("indexed", -1);
|
396
|
+
REFRESH;
|
397
|
+
ASSERT_ALGORITHM_OK("unindexed", -1);
|
464
398
|
|
465
|
-
|
466
|
-
|
467
|
-
ASSERT_ALGORITHM_OK ("aEAD_AES_256_CBC_HMAC_SHA_512-Deterministic", -1);
|
468
|
-
REFRESH;
|
469
|
-
ASSERT_ALGORITHM_OK ("aEAD_AES_256_CBC_HMAC_SHA_512-Random", -1);
|
470
|
-
REFRESH;
|
471
|
-
ASSERT_ALGORITHM_OK ("indexed", -1);
|
472
|
-
REFRESH;
|
473
|
-
ASSERT_ALGORITHM_OK ("unindexed", -1);
|
474
|
-
|
475
|
-
mongocrypt_ctx_destroy (ctx);
|
476
|
-
mongocrypt_destroy (crypt);
|
399
|
+
mongocrypt_ctx_destroy(ctx);
|
400
|
+
mongocrypt_destroy(crypt);
|
477
401
|
}
|
478
402
|
|
479
|
-
static void
|
480
|
-
|
481
|
-
|
482
|
-
mongocrypt_t *crypt;
|
483
|
-
mongocrypt_ctx_t *ctx = NULL;
|
403
|
+
static void _test_setopt_query_type(_mongocrypt_tester_t *tester) {
|
404
|
+
mongocrypt_t *crypt;
|
405
|
+
mongocrypt_ctx_t *ctx = NULL;
|
484
406
|
|
485
|
-
|
407
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
486
408
|
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
(int) strlen (MONGOCRYPT_QUERY_TYPE_EQUALITY_STR));
|
409
|
+
/* Test valid input. */
|
410
|
+
REFRESH;
|
411
|
+
ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, (int)strlen(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR));
|
491
412
|
|
492
|
-
|
493
|
-
|
494
|
-
|
413
|
+
/* Test invalid length. */
|
414
|
+
REFRESH;
|
415
|
+
ASSERT_QUERY_TYPE_FAILS("foo", -2, "Invalid query_type string length");
|
495
416
|
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
417
|
+
/* Test double setting. */
|
418
|
+
REFRESH;
|
419
|
+
ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1);
|
420
|
+
ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1);
|
500
421
|
|
501
|
-
|
502
|
-
|
503
|
-
|
422
|
+
/* Test NULL input */
|
423
|
+
REFRESH;
|
424
|
+
ASSERT_QUERY_TYPE_FAILS(NULL, 0, "Invalid null query_type string");
|
504
425
|
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
426
|
+
/* Test with failed context. */
|
427
|
+
REFRESH;
|
428
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "test");
|
429
|
+
ASSERT_QUERY_TYPE_FAILS(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1, "test")
|
509
430
|
|
510
|
-
|
511
|
-
|
512
|
-
|
431
|
+
/* Test case insensitive. */
|
432
|
+
REFRESH;
|
433
|
+
ASSERT_QUERY_TYPE_OK("Equality", -1);
|
513
434
|
|
514
|
-
|
515
|
-
|
435
|
+
mongocrypt_ctx_destroy(ctx);
|
436
|
+
mongocrypt_destroy(crypt);
|
516
437
|
}
|
517
438
|
|
518
|
-
|
519
439
|
/* Test required and prohibited options on a datakey context. */
|
520
|
-
static void
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
REFRESH;
|
598
|
-
ASSERT_MASTERKEY_LOCAL_OK;
|
599
|
-
ASSERT_ENDPOINT_FAILS ("example.com:80", -1, "endpoint prohibited");
|
600
|
-
|
601
|
-
mongocrypt_ctx_destroy (ctx);
|
602
|
-
mongocrypt_destroy (crypt);
|
440
|
+
static void _test_setopt_for_datakey(_mongocrypt_tester_t *tester) {
|
441
|
+
mongocrypt_t *crypt;
|
442
|
+
mongocrypt_ctx_t *ctx = NULL;
|
443
|
+
mongocrypt_binary_t *uuid;
|
444
|
+
|
445
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
446
|
+
uuid = TEST_BIN(16);
|
447
|
+
|
448
|
+
/* Test required and prohibited options. */
|
449
|
+
REFRESH;
|
450
|
+
ASSERT_DATAKEY_INIT_FAILS("master key required");
|
451
|
+
|
452
|
+
REFRESH;
|
453
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
454
|
+
ASSERT_DATAKEY_INIT_OK;
|
455
|
+
|
456
|
+
REFRESH;
|
457
|
+
ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
|
458
|
+
"'keyVaultEndpoint': 'example.com' }"));
|
459
|
+
ASSERT_DATAKEY_INIT_OK;
|
460
|
+
|
461
|
+
/* Test optional key alt names. */
|
462
|
+
REFRESH;
|
463
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
464
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
465
|
+
ASSERT_DATAKEY_INIT_OK;
|
466
|
+
|
467
|
+
/* Multiple key alt names are okay. */
|
468
|
+
REFRESH;
|
469
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
470
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
471
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'def'}"));
|
472
|
+
ASSERT_DATAKEY_INIT_OK;
|
473
|
+
|
474
|
+
/* But duplicates are not. */
|
475
|
+
REFRESH;
|
476
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
477
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
478
|
+
ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'keyAltName': 'abc'}"), "duplicate keyAltNames found");
|
479
|
+
|
480
|
+
/* Key Material is okay. */
|
481
|
+
REFRESH;
|
482
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
483
|
+
ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
|
484
|
+
"'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
|
485
|
+
"ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
|
486
|
+
"WJjZGVm', 'subType': '00'}}}"));
|
487
|
+
ASSERT_DATAKEY_INIT_OK;
|
488
|
+
|
489
|
+
/* Test each prohibited option. */
|
490
|
+
REFRESH;
|
491
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
492
|
+
ASSERT_KEY_ID_OK(uuid);
|
493
|
+
ASSERT_DATAKEY_INIT_FAILS("key id and alt name prohibited");
|
494
|
+
|
495
|
+
REFRESH;
|
496
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
497
|
+
ASSERT_ALGORITHM_OK(MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
|
498
|
+
ASSERT_DATAKEY_INIT_FAILS("algorithm prohibited");
|
499
|
+
|
500
|
+
/* Test setting options after init. */
|
501
|
+
REFRESH;
|
502
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
503
|
+
ASSERT_DATAKEY_INIT_OK;
|
504
|
+
ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -1, "cannot set options after init");
|
505
|
+
|
506
|
+
REFRESH;
|
507
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
508
|
+
ASSERT_ENDPOINT_OK("example.com:80", -1);
|
509
|
+
ASSERT_DATAKEY_INIT_OK;
|
510
|
+
|
511
|
+
REFRESH;
|
512
|
+
ASSERT_MASTERKEY_LOCAL_OK;
|
513
|
+
ASSERT_ENDPOINT_FAILS("example.com:80", -1, "endpoint prohibited");
|
514
|
+
|
515
|
+
mongocrypt_ctx_destroy(ctx);
|
516
|
+
mongocrypt_destroy(crypt);
|
603
517
|
}
|
604
518
|
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
ASSERT_ENCRYPT_INIT_OK ("a", -1, cmd);
|
661
|
-
ASSERT_MASTERKEY_LOCAL_FAILS ("cannot set options after init");
|
662
|
-
|
663
|
-
mongocrypt_ctx_destroy (ctx);
|
664
|
-
mongocrypt_destroy (crypt);
|
519
|
+
static void _test_setopt_for_encrypt(_mongocrypt_tester_t *tester) {
|
520
|
+
mongocrypt_t *crypt;
|
521
|
+
mongocrypt_ctx_t *ctx = NULL;
|
522
|
+
mongocrypt_binary_t *uuid, *cmd;
|
523
|
+
|
524
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
525
|
+
cmd = TEST_FILE("./test/example/cmd.json");
|
526
|
+
uuid = TEST_BIN(16);
|
527
|
+
|
528
|
+
/* Test required and prohibited options. */
|
529
|
+
REFRESH;
|
530
|
+
ASSERT_ENCRYPT_INIT_OK("a", -1, cmd);
|
531
|
+
|
532
|
+
REFRESH;
|
533
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
534
|
+
ENCRYPT_INIT_FAILS("a", -1, cmd, "master key prohibited");
|
535
|
+
|
536
|
+
REFRESH;
|
537
|
+
ASSERT_MASTERKEY_LOCAL_OK;
|
538
|
+
ENCRYPT_INIT_FAILS("a", -1, cmd, "master key prohibited");
|
539
|
+
|
540
|
+
REFRESH;
|
541
|
+
ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
|
542
|
+
"'keyVaultEndpoint': 'example.com' }"));
|
543
|
+
ENCRYPT_INIT_FAILS("a", -1, cmd, "master key prohibited");
|
544
|
+
|
545
|
+
REFRESH;
|
546
|
+
ASSERT_KEY_ID_OK(uuid);
|
547
|
+
ENCRYPT_INIT_FAILS("a", -1, cmd, "key id and alt name prohibited");
|
548
|
+
|
549
|
+
REFRESH;
|
550
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
551
|
+
ENCRYPT_INIT_FAILS("a", -1, cmd, "key id and alt name prohibited");
|
552
|
+
|
553
|
+
REFRESH;
|
554
|
+
ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
|
555
|
+
"'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
|
556
|
+
"ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
|
557
|
+
"WJjZGVm', 'subType': '00'}}}"));
|
558
|
+
ENCRYPT_INIT_FAILS("a", -1, cmd, "key material prohibited");
|
559
|
+
|
560
|
+
REFRESH;
|
561
|
+
ASSERT_ALGORITHM_OK(DET, -1);
|
562
|
+
ENCRYPT_INIT_FAILS("a", -1, cmd, "algorithm prohibited");
|
563
|
+
|
564
|
+
REFRESH;
|
565
|
+
ENCRYPT_INIT_FAILS("a", -1, NULL, "invalid command");
|
566
|
+
|
567
|
+
/* Test setting options after init. */
|
568
|
+
REFRESH;
|
569
|
+
ASSERT_ENCRYPT_INIT_OK("a", -1, cmd);
|
570
|
+
ASSERT_MASTERKEY_LOCAL_FAILS("cannot set options after init");
|
571
|
+
|
572
|
+
mongocrypt_ctx_destroy(ctx);
|
573
|
+
mongocrypt_destroy(crypt);
|
665
574
|
}
|
666
575
|
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
|
981
|
-
ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1),
|
982
|
-
ctx);
|
983
|
-
ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "sparsity must be non-negative");
|
984
|
-
}
|
985
|
-
|
986
|
-
/* Error if query_type == "rangePreview" and algorithm != "rangePreview". */
|
987
|
-
{
|
988
|
-
REFRESH;
|
989
|
-
ASSERT_KEY_ID_OK (uuid);
|
990
|
-
ASSERT_ALGORITHM_OK (MONGOCRYPT_ALGORITHM_INDEXED_STR, -1);
|
991
|
-
ASSERT_QUERY_TYPE_OK (MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_STR, -1);
|
992
|
-
ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 0), ctx);
|
993
|
-
ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "must match index_type");
|
994
|
-
}
|
995
|
-
|
996
|
-
/* Error if query_type == "rangePreview" for
|
997
|
-
* mongocrypt_ctx_explicit_encrypt_init. */
|
998
|
-
{
|
999
|
-
REFRESH;
|
1000
|
-
ASSERT_KEY_ID_OK (uuid);
|
1001
|
-
ASSERT_ALGORITHM_OK (MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1);
|
1002
|
-
ASSERT_QUERY_TYPE_OK (MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_STR, -1);
|
1003
|
-
ASSERT_OK (
|
1004
|
-
mongocrypt_ctx_setopt_algorithm_range (
|
1005
|
-
ctx,
|
1006
|
-
TEST_BSON (
|
1007
|
-
"{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
|
1008
|
-
ctx);
|
1009
|
-
ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 0), ctx);
|
1010
|
-
ASSERT_EX_ENCRYPT_INIT_FAILS (
|
1011
|
-
bson,
|
1012
|
-
"Encrypt may not be used for range queries. Use EncryptExpression.");
|
1013
|
-
}
|
1014
|
-
|
1015
|
-
/* Error if query_type is unset for
|
1016
|
-
* mongocrypt_ctx_explicit_encrypt_expression_init. */
|
1017
|
-
{
|
1018
|
-
REFRESH;
|
1019
|
-
ASSERT_KEY_ID_OK (uuid);
|
1020
|
-
ASSERT_ALGORITHM_OK (MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1);
|
1021
|
-
ASSERT_OK (
|
1022
|
-
mongocrypt_ctx_setopt_algorithm_range (
|
1023
|
-
ctx,
|
1024
|
-
TEST_BSON (
|
1025
|
-
"{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
|
1026
|
-
ctx);
|
1027
|
-
ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 0), ctx);
|
1028
|
-
ASSERT_EX_ENCRYPT_EXPRESSION_INIT_FAILS (
|
1029
|
-
bson, "EncryptExpression may only be used for range queries.");
|
1030
|
-
}
|
1031
|
-
|
1032
|
-
mongocrypt_ctx_destroy (ctx);
|
1033
|
-
mongocrypt_destroy (crypt);
|
576
|
+
static void _test_setopt_for_explicit_encrypt(_mongocrypt_tester_t *tester) {
|
577
|
+
mongocrypt_t *crypt;
|
578
|
+
mongocrypt_ctx_t *ctx = NULL;
|
579
|
+
mongocrypt_binary_t *bson, *uuid, *rangeopts;
|
580
|
+
|
581
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
582
|
+
uuid = TEST_BIN(16);
|
583
|
+
bson = TEST_BSON("{'v': 'hello'}");
|
584
|
+
rangeopts = TEST_BSON("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}");
|
585
|
+
|
586
|
+
/* Test required and prohibited options. */
|
587
|
+
REFRESH;
|
588
|
+
ASSERT_KEY_ID_OK(uuid);
|
589
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
590
|
+
ASSERT_EX_ENCRYPT_INIT_OK(bson);
|
591
|
+
|
592
|
+
/* Just keyAltName is ok */
|
593
|
+
REFRESH;
|
594
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
595
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
596
|
+
ASSERT_EX_ENCRYPT_INIT_OK(bson);
|
597
|
+
|
598
|
+
/* Two keyAltNames is invalid */
|
599
|
+
REFRESH;
|
600
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
601
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'def'}"));
|
602
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
603
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "must not specify multiple key alt names");
|
604
|
+
|
605
|
+
/* Both keyAltName and keyId is invalid */
|
606
|
+
REFRESH;
|
607
|
+
ASSERT_KEY_ID_OK(uuid);
|
608
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
609
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
610
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot have both key id and key alt name");
|
611
|
+
|
612
|
+
REFRESH;
|
613
|
+
ASSERT_KEY_ID_OK(uuid);
|
614
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
615
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
616
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "master key prohibited");
|
617
|
+
|
618
|
+
REFRESH;
|
619
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
620
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
621
|
+
ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
|
622
|
+
"'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
|
623
|
+
"ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
|
624
|
+
"WJjZGVm', 'subType': '00'}}}"));
|
625
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "key material prohibited");
|
626
|
+
|
627
|
+
REFRESH;
|
628
|
+
ASSERT_KEY_ID_OK(uuid);
|
629
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
630
|
+
ASSERT_MASTERKEY_LOCAL_OK;
|
631
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "master key prohibited");
|
632
|
+
|
633
|
+
REFRESH;
|
634
|
+
ASSERT_KEY_ID_OK(uuid);
|
635
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
636
|
+
ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
|
637
|
+
"'keyVaultEndpoint': 'example.com' }"));
|
638
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "master key prohibited");
|
639
|
+
|
640
|
+
REFRESH;
|
641
|
+
ASSERT_KEY_ID_OK(uuid);
|
642
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "algorithm or index type required");
|
643
|
+
|
644
|
+
REFRESH;
|
645
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
646
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "key id or key alt name required")
|
647
|
+
|
648
|
+
REFRESH;
|
649
|
+
ASSERT_KEY_ID_OK(uuid);
|
650
|
+
ASSERT_ALGORITHM_OK(DET, -1);
|
651
|
+
ASSERT_EX_ENCRYPT_INIT_OK(bson);
|
652
|
+
|
653
|
+
/* Just key alt name is ok */
|
654
|
+
REFRESH;
|
655
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
656
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
657
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
658
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "master key prohibited");
|
659
|
+
|
660
|
+
REFRESH;
|
661
|
+
ASSERT_KEY_ID_OK(uuid);
|
662
|
+
ASSERT_ALGORITHM_OK(DET, -1);
|
663
|
+
ASSERT_EX_ENCRYPT_INIT_OK(bson);
|
664
|
+
|
665
|
+
/* Test setting options after init. */
|
666
|
+
REFRESH;
|
667
|
+
ASSERT_KEY_ID_OK(uuid);
|
668
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
669
|
+
ASSERT_EX_ENCRYPT_INIT_OK(bson);
|
670
|
+
ASSERT_ALGORITHM_FAILS(RAND, -1, "cannot set options after init");
|
671
|
+
|
672
|
+
/* Test that an option failure validated at the time of 'setopt' persists
|
673
|
+
* upon init. */
|
674
|
+
REFRESH;
|
675
|
+
ASSERT_KEY_ID_OK(uuid);
|
676
|
+
ASSERT_ALGORITHM_FAILS("bad-algo", -1, "unsupported algorithm");
|
677
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "unsupported algorithm");
|
678
|
+
|
679
|
+
/* It is an error to set the FLE 1 keyAltName option with any of the FLE 2
|
680
|
+
* options (index_type, index_key_id, contention_factor, query_type, or
|
681
|
+
* range opts). */
|
682
|
+
{
|
683
|
+
REFRESH;
|
684
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
685
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1), ctx);
|
686
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and index type");
|
687
|
+
|
688
|
+
REFRESH;
|
689
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
690
|
+
ASSERT_OK(mongocrypt_ctx_setopt_index_key_id(ctx, uuid), ctx);
|
691
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and index key id");
|
692
|
+
|
693
|
+
REFRESH;
|
694
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
695
|
+
ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 123), ctx);
|
696
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and contention factor");
|
697
|
+
|
698
|
+
REFRESH;
|
699
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
700
|
+
ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1), ctx);
|
701
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and query type");
|
702
|
+
|
703
|
+
REFRESH;
|
704
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
705
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
|
706
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and range opts");
|
707
|
+
}
|
708
|
+
|
709
|
+
/* It is an error to set the FLE 1 algorithm option with any of the FLE 2
|
710
|
+
* options (index_type, index_key_id, contention_factor, query_type, or
|
711
|
+
* range opts). */
|
712
|
+
{
|
713
|
+
REFRESH;
|
714
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
715
|
+
* error */
|
716
|
+
ASSERT_KEY_ID_OK(uuid);
|
717
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
718
|
+
ASSERT_OK(mongocrypt_ctx_setopt_index_key_id(ctx, uuid), ctx);
|
719
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both algorithm and index key id");
|
720
|
+
|
721
|
+
REFRESH;
|
722
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
723
|
+
* error */
|
724
|
+
ASSERT_KEY_ID_OK(uuid);
|
725
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
726
|
+
ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 123), ctx);
|
727
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both algorithm and contention factor");
|
728
|
+
REFRESH;
|
729
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
730
|
+
* error */
|
731
|
+
ASSERT_KEY_ID_OK(uuid);
|
732
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
733
|
+
ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1), ctx);
|
734
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both algorithm and query type");
|
735
|
+
REFRESH;
|
736
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
737
|
+
* error */
|
738
|
+
ASSERT_KEY_ID_OK(uuid);
|
739
|
+
ASSERT_ALGORITHM_OK(RAND, -1);
|
740
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
|
741
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both algorithm and range opts");
|
742
|
+
}
|
743
|
+
|
744
|
+
/* Require either index_type or algorithm */
|
745
|
+
{
|
746
|
+
REFRESH;
|
747
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
748
|
+
* error */
|
749
|
+
ASSERT_KEY_ID_OK(uuid);
|
750
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "algorithm or index type required");
|
751
|
+
}
|
752
|
+
|
753
|
+
/* It is an error to set contention_factor with index_type ==
|
754
|
+
* MONGOCRYPT_INDEX_TYPE_NONE */
|
755
|
+
{
|
756
|
+
REFRESH;
|
757
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
758
|
+
* error */
|
759
|
+
ASSERT_KEY_ID_OK(uuid);
|
760
|
+
ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
|
761
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1), ctx);
|
762
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set contention factor with no index type");
|
763
|
+
}
|
764
|
+
|
765
|
+
/* It is an error to set range opts with index_type ==
|
766
|
+
* MONGOCRYPT_INDEX_TYPE_NONE */
|
767
|
+
{
|
768
|
+
REFRESH;
|
769
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
770
|
+
* error */
|
771
|
+
ASSERT_KEY_ID_OK(uuid);
|
772
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
|
773
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1), ctx);
|
774
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set range opts with no index type");
|
775
|
+
}
|
776
|
+
|
777
|
+
/* It is an error to set range opts with index_type ==
|
778
|
+
* MONGOCRYPT_INDEX_TYPE_EQUALITY */
|
779
|
+
{
|
780
|
+
REFRESH;
|
781
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
782
|
+
* error */
|
783
|
+
ASSERT_KEY_ID_OK(uuid);
|
784
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
|
785
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_INDEXED_STR, -1), ctx);
|
786
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set range opts with equality index type");
|
787
|
+
}
|
788
|
+
|
789
|
+
/* It is an error to set query_type with index_type ==
|
790
|
+
* MONGOCRYPT_INDEX_TYPE_NONE */
|
791
|
+
{
|
792
|
+
REFRESH;
|
793
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
794
|
+
* error */
|
795
|
+
ASSERT_KEY_ID_OK(uuid);
|
796
|
+
ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1), ctx);
|
797
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1), ctx);
|
798
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set query type with no index type");
|
799
|
+
}
|
800
|
+
|
801
|
+
/* Contention factor is required for "Indexed" algorithm. */
|
802
|
+
{
|
803
|
+
REFRESH;
|
804
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
805
|
+
* error */
|
806
|
+
ASSERT_KEY_ID_OK(uuid);
|
807
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_INDEXED_STR, -1), ctx);
|
808
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "contention factor is required");
|
809
|
+
}
|
810
|
+
|
811
|
+
/* Contention factor is required for "rangePreview" algorithm. */
|
812
|
+
{
|
813
|
+
REFRESH;
|
814
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
815
|
+
* error */
|
816
|
+
ASSERT_KEY_ID_OK(uuid);
|
817
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
|
818
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1), ctx);
|
819
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "contention factor is required");
|
820
|
+
}
|
821
|
+
|
822
|
+
/* Range opts is required for "rangePreview" algorithm. */
|
823
|
+
{
|
824
|
+
REFRESH;
|
825
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
826
|
+
* error */
|
827
|
+
ASSERT_KEY_ID_OK(uuid);
|
828
|
+
ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
|
829
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1), ctx);
|
830
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "range opts are required");
|
831
|
+
}
|
832
|
+
|
833
|
+
/* Negative sparsity is prohibited. */
|
834
|
+
{
|
835
|
+
REFRESH;
|
836
|
+
/* Set key ID to get past the 'either key id or key alt name required'
|
837
|
+
* error */
|
838
|
+
ASSERT_KEY_ID_OK(uuid);
|
839
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(
|
840
|
+
ctx,
|
841
|
+
TEST_BSON("{'min': 0, 'max': 1, 'sparsity': { '$numberLong': '-1'}}")),
|
842
|
+
ctx);
|
843
|
+
ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
|
844
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1), ctx);
|
845
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "sparsity must be non-negative");
|
846
|
+
}
|
847
|
+
|
848
|
+
/* Error if query_type == "rangePreview" and algorithm != "rangePreview". */
|
849
|
+
{
|
850
|
+
REFRESH;
|
851
|
+
ASSERT_KEY_ID_OK(uuid);
|
852
|
+
ASSERT_ALGORITHM_OK(MONGOCRYPT_ALGORITHM_INDEXED_STR, -1);
|
853
|
+
ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_STR, -1);
|
854
|
+
ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
|
855
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "must match index_type");
|
856
|
+
}
|
857
|
+
|
858
|
+
/* Error if query_type == "rangePreview" for
|
859
|
+
* mongocrypt_ctx_explicit_encrypt_init. */
|
860
|
+
{
|
861
|
+
REFRESH;
|
862
|
+
ASSERT_KEY_ID_OK(uuid);
|
863
|
+
ASSERT_ALGORITHM_OK(MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1);
|
864
|
+
ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_STR, -1);
|
865
|
+
ASSERT_OK(
|
866
|
+
mongocrypt_ctx_setopt_algorithm_range(ctx,
|
867
|
+
TEST_BSON("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
|
868
|
+
ctx);
|
869
|
+
ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
|
870
|
+
ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "Encrypt may not be used for range queries. Use EncryptExpression.");
|
871
|
+
}
|
872
|
+
|
873
|
+
/* Error if query_type is unset for
|
874
|
+
* mongocrypt_ctx_explicit_encrypt_expression_init. */
|
875
|
+
{
|
876
|
+
REFRESH;
|
877
|
+
ASSERT_KEY_ID_OK(uuid);
|
878
|
+
ASSERT_ALGORITHM_OK(MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1);
|
879
|
+
ASSERT_OK(
|
880
|
+
mongocrypt_ctx_setopt_algorithm_range(ctx,
|
881
|
+
TEST_BSON("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
|
882
|
+
ctx);
|
883
|
+
ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
|
884
|
+
ASSERT_EX_ENCRYPT_EXPRESSION_INIT_FAILS(bson, "EncryptExpression may only be used for range queries.");
|
885
|
+
}
|
886
|
+
|
887
|
+
mongocrypt_ctx_destroy(ctx);
|
888
|
+
mongocrypt_destroy(crypt);
|
1034
889
|
}
|
1035
890
|
|
891
|
+
static void _test_setopt_for_decrypt(_mongocrypt_tester_t *tester) {
|
892
|
+
mongocrypt_t *crypt;
|
893
|
+
mongocrypt_ctx_t *ctx = NULL;
|
894
|
+
mongocrypt_binary_t *bson, *uuid;
|
895
|
+
|
896
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
897
|
+
uuid = TEST_BIN(16);
|
898
|
+
bson = TEST_BSON("{'a': 1}");
|
899
|
+
|
900
|
+
/* Test required and prohibited options. */
|
901
|
+
REFRESH;
|
902
|
+
ASSERT_DECRYPT_INIT_OK(bson);
|
903
|
+
|
904
|
+
REFRESH;
|
905
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
906
|
+
ASSERT_DECRYPT_INIT_FAILS(bson, "master key prohibited");
|
907
|
+
|
908
|
+
REFRESH;
|
909
|
+
ASSERT_MASTERKEY_LOCAL_OK;
|
910
|
+
ASSERT_DECRYPT_INIT_FAILS(bson, "master key prohibited");
|
911
|
+
|
912
|
+
REFRESH;
|
913
|
+
ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
|
914
|
+
"'keyVaultEndpoint': 'example.com' }"));
|
915
|
+
ASSERT_DECRYPT_INIT_FAILS(bson, "master key prohibited");
|
916
|
+
|
917
|
+
REFRESH;
|
918
|
+
ASSERT_KEY_ID_OK(uuid);
|
919
|
+
ASSERT_DECRYPT_INIT_FAILS(bson, "key id and alt name prohibited");
|
920
|
+
|
921
|
+
REFRESH;
|
922
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
923
|
+
ASSERT_DECRYPT_INIT_FAILS(bson, "key id and alt name prohibited");
|
924
|
+
|
925
|
+
REFRESH;
|
926
|
+
ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
|
927
|
+
"'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
|
928
|
+
"ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
|
929
|
+
"WJjZGVm', 'subType': '00'}}}"));
|
930
|
+
ASSERT_DECRYPT_INIT_FAILS(bson, "key material prohibited");
|
931
|
+
|
932
|
+
REFRESH;
|
933
|
+
ASSERT_ALGORITHM_OK(DET, -1);
|
934
|
+
ASSERT_DECRYPT_INIT_FAILS(bson, "algorithm prohibited");
|
935
|
+
|
936
|
+
/* Test setting options after init. */
|
937
|
+
REFRESH;
|
938
|
+
ASSERT_DECRYPT_INIT_OK(bson);
|
939
|
+
ASSERT_MASTERKEY_LOCAL_FAILS("cannot set options after init");
|
940
|
+
|
941
|
+
mongocrypt_ctx_destroy(ctx);
|
942
|
+
mongocrypt_destroy(crypt);
|
943
|
+
}
|
1036
944
|
|
1037
|
-
static void
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
mongocrypt_ctx_destroy (ctx);
|
1092
|
-
mongocrypt_destroy (crypt);
|
945
|
+
static void _test_setopt_for_explicit_decrypt(_mongocrypt_tester_t *tester) {
|
946
|
+
mongocrypt_t *crypt;
|
947
|
+
mongocrypt_ctx_t *ctx = NULL;
|
948
|
+
mongocrypt_binary_t *bson, *uuid;
|
949
|
+
|
950
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
951
|
+
uuid = TEST_BIN(16);
|
952
|
+
bson = TEST_FILE("./test/data/explicit-decryption-input.json");
|
953
|
+
|
954
|
+
/* Test required and prohibited options. */
|
955
|
+
REFRESH;
|
956
|
+
ASSERT_EX_DECRYPT_INIT_OK(bson);
|
957
|
+
|
958
|
+
REFRESH;
|
959
|
+
ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
|
960
|
+
ASSERT_EX_DECRYPT_INIT_FAILS(bson, "master key prohibited");
|
961
|
+
|
962
|
+
REFRESH;
|
963
|
+
ASSERT_MASTERKEY_LOCAL_OK;
|
964
|
+
ASSERT_EX_DECRYPT_INIT_FAILS(bson, "master key prohibited");
|
965
|
+
|
966
|
+
REFRESH;
|
967
|
+
ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
|
968
|
+
"'keyVaultEndpoint': 'example.com' }"));
|
969
|
+
ASSERT_EX_DECRYPT_INIT_FAILS(bson, "master key prohibited");
|
970
|
+
|
971
|
+
REFRESH;
|
972
|
+
ASSERT_KEY_ID_OK(uuid);
|
973
|
+
ASSERT_EX_DECRYPT_INIT_FAILS(bson, "key id and alt name prohibited");
|
974
|
+
|
975
|
+
REFRESH;
|
976
|
+
ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
|
977
|
+
ASSERT_DECRYPT_INIT_FAILS(bson, "key id and alt name prohibited");
|
978
|
+
|
979
|
+
REFRESH;
|
980
|
+
ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
|
981
|
+
"'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
|
982
|
+
"ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
|
983
|
+
"WJjZGVm', 'subType': '00'}}}"));
|
984
|
+
ASSERT_DECRYPT_INIT_FAILS(bson, "key material prohibited");
|
985
|
+
|
986
|
+
REFRESH;
|
987
|
+
ASSERT_ALGORITHM_OK(DET, -1);
|
988
|
+
ASSERT_EX_DECRYPT_INIT_FAILS(bson, "algorithm prohibited");
|
989
|
+
|
990
|
+
// Range opts are prohibited.
|
991
|
+
REFRESH;
|
992
|
+
ASSERT_OK(
|
993
|
+
mongocrypt_ctx_setopt_algorithm_range(ctx, TEST_BSON("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
|
994
|
+
ctx);
|
995
|
+
ASSERT_EX_DECRYPT_INIT_FAILS(bson, "range opts are prohibited");
|
996
|
+
|
997
|
+
mongocrypt_ctx_destroy(ctx);
|
998
|
+
mongocrypt_destroy(crypt);
|
1093
999
|
}
|
1094
1000
|
|
1001
|
+
static void _test_setopt_failure_uninitialized(_mongocrypt_tester_t *tester) {
|
1002
|
+
mongocrypt_t *crypt;
|
1003
|
+
mongocrypt_ctx_t *ctx = NULL;
|
1004
|
+
mongocrypt_status_t *status;
|
1095
1005
|
|
1096
|
-
|
1097
|
-
|
1098
|
-
{
|
1099
|
-
mongocrypt_t *crypt;
|
1100
|
-
mongocrypt_ctx_t *ctx = NULL;
|
1101
|
-
mongocrypt_binary_t *bson, *uuid;
|
1102
|
-
|
1103
|
-
crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
|
1104
|
-
uuid = TEST_BIN (16);
|
1105
|
-
bson = TEST_FILE ("./test/data/explicit-decryption-input.json");
|
1106
|
-
|
1107
|
-
/* Test required and prohibited options. */
|
1108
|
-
REFRESH;
|
1109
|
-
ASSERT_EX_DECRYPT_INIT_OK (bson);
|
1110
|
-
|
1111
|
-
REFRESH;
|
1112
|
-
ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
|
1113
|
-
ASSERT_EX_DECRYPT_INIT_FAILS (bson, "master key prohibited");
|
1114
|
-
|
1115
|
-
REFRESH;
|
1116
|
-
ASSERT_MASTERKEY_LOCAL_OK;
|
1117
|
-
ASSERT_EX_DECRYPT_INIT_FAILS (bson, "master key prohibited");
|
1118
|
-
|
1119
|
-
REFRESH;
|
1120
|
-
ASSERT_KEY_ENCRYPTION_KEY_OK (
|
1121
|
-
TEST_BSON ("{'provider': 'azure', 'keyName': '', "
|
1122
|
-
"'keyVaultEndpoint': 'example.com' }"));
|
1123
|
-
ASSERT_EX_DECRYPT_INIT_FAILS (bson, "master key prohibited");
|
1124
|
-
|
1125
|
-
REFRESH;
|
1126
|
-
ASSERT_KEY_ID_OK (uuid);
|
1127
|
-
ASSERT_EX_DECRYPT_INIT_FAILS (bson, "key id and alt name prohibited");
|
1128
|
-
|
1129
|
-
REFRESH;
|
1130
|
-
ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
|
1131
|
-
ASSERT_DECRYPT_INIT_FAILS (bson, "key id and alt name prohibited");
|
1132
|
-
|
1133
|
-
REFRESH;
|
1134
|
-
ASSERT_KEY_MATERIAL_OK (
|
1135
|
-
TEST_BSON ("{'keyMaterial': {'$binary': {'base64': "
|
1136
|
-
"'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
|
1137
|
-
"ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
|
1138
|
-
"WJjZGVm', 'subType': '00'}}}"));
|
1139
|
-
ASSERT_DECRYPT_INIT_FAILS (bson, "key material prohibited");
|
1140
|
-
|
1141
|
-
REFRESH;
|
1142
|
-
ASSERT_ALGORITHM_OK (DET, -1);
|
1143
|
-
ASSERT_EX_DECRYPT_INIT_FAILS (bson, "algorithm prohibited");
|
1144
|
-
|
1145
|
-
// Range opts are prohibited.
|
1146
|
-
REFRESH;
|
1147
|
-
ASSERT_OK (
|
1148
|
-
mongocrypt_ctx_setopt_algorithm_range (
|
1149
|
-
ctx,
|
1150
|
-
TEST_BSON ("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
|
1151
|
-
ctx);
|
1152
|
-
ASSERT_EX_DECRYPT_INIT_FAILS (bson, "range opts are prohibited");
|
1153
|
-
|
1154
|
-
mongocrypt_ctx_destroy (ctx);
|
1155
|
-
mongocrypt_destroy (crypt);
|
1156
|
-
}
|
1006
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
1007
|
+
status = mongocrypt_status_new();
|
1157
1008
|
|
1009
|
+
REFRESH;
|
1010
|
+
ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'fake': 'abc'}"), "keyAltName must have field 'keyAltName'");
|
1011
|
+
/* Though mongocrypt_ctx_t is uninitialized, we should still get failure
|
1012
|
+
* status. */
|
1013
|
+
ASSERT_FAILS_STATUS(mongocrypt_ctx_status(ctx, status), status, "keyAltName must have field 'keyAltName'");
|
1158
1014
|
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
mongocrypt_t *crypt;
|
1163
|
-
mongocrypt_ctx_t *ctx = NULL;
|
1164
|
-
mongocrypt_status_t *status;
|
1165
|
-
|
1166
|
-
crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
|
1167
|
-
status = mongocrypt_status_new ();
|
1168
|
-
|
1169
|
-
REFRESH;
|
1170
|
-
ASSERT_KEY_ALT_NAME_FAILS (TEST_BSON ("{'fake': 'abc'}"),
|
1171
|
-
"keyAltName must have field 'keyAltName'");
|
1172
|
-
/* Though mongocrypt_ctx_t is uninitialized, we should still get failure
|
1173
|
-
* status. */
|
1174
|
-
ASSERT_FAILS_STATUS (mongocrypt_ctx_status (ctx, status),
|
1175
|
-
status,
|
1176
|
-
"keyAltName must have field 'keyAltName'");
|
1177
|
-
|
1178
|
-
mongocrypt_ctx_destroy (ctx);
|
1179
|
-
mongocrypt_destroy (crypt);
|
1180
|
-
mongocrypt_status_destroy (status);
|
1015
|
+
mongocrypt_ctx_destroy(ctx);
|
1016
|
+
mongocrypt_destroy(crypt);
|
1017
|
+
mongocrypt_status_destroy(status);
|
1181
1018
|
}
|
1182
1019
|
|
1020
|
+
static void _test_setopt_endpoint(_mongocrypt_tester_t *tester) {
|
1021
|
+
mongocrypt_t *crypt;
|
1022
|
+
mongocrypt_ctx_t *ctx = NULL;
|
1183
1023
|
|
1184
|
-
|
1185
|
-
_test_setopt_endpoint (_mongocrypt_tester_t *tester)
|
1186
|
-
{
|
1187
|
-
mongocrypt_t *crypt;
|
1188
|
-
mongocrypt_ctx_t *ctx = NULL;
|
1024
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
1189
1025
|
|
1190
|
-
|
1026
|
+
REFRESH;
|
1027
|
+
ASSERT_ENDPOINT_FAILS("example.com", -2, "Invalid endpoint");
|
1191
1028
|
|
1192
|
-
|
1193
|
-
|
1029
|
+
REFRESH;
|
1030
|
+
ASSERT_ENDPOINT_OK("example.com", -1);
|
1031
|
+
BSON_ASSERT(0 == strcmp(ctx->opts.kek.provider.aws.endpoint->host_and_port, "example.com"));
|
1194
1032
|
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1033
|
+
/* Including a port is ok. */
|
1034
|
+
REFRESH;
|
1035
|
+
ASSERT_ENDPOINT_OK("example.com:80", -1);
|
1036
|
+
BSON_ASSERT(0 == strcmp(ctx->opts.kek.provider.aws.endpoint->host_and_port, "example.com:80"));
|
1199
1037
|
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
"example.com:80"));
|
1038
|
+
/* Test double setting. */
|
1039
|
+
REFRESH;
|
1040
|
+
ASSERT_ENDPOINT_OK("example.com", -1);
|
1041
|
+
ASSERT_ENDPOINT_FAILS("example.com", -1, "already set masterkey endpoint");
|
1205
1042
|
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
ASSERT_ENDPOINT_FAILS ("example.com", -1, "already set masterkey endpoint");
|
1043
|
+
/* Test NULL input */
|
1044
|
+
REFRESH;
|
1045
|
+
ASSERT_ENDPOINT_FAILS(NULL, 0, "Invalid endpoint");
|
1210
1046
|
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1047
|
+
REFRESH;
|
1048
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "test");
|
1049
|
+
ASSERT_ENDPOINT_FAILS(RAND, -1, "test")
|
1214
1050
|
|
1215
|
-
|
1216
|
-
|
1217
|
-
ASSERT_ENDPOINT_FAILS (RAND, -1, "test")
|
1218
|
-
|
1219
|
-
mongocrypt_ctx_destroy (ctx);
|
1220
|
-
mongocrypt_destroy (crypt);
|
1051
|
+
mongocrypt_ctx_destroy(ctx);
|
1052
|
+
mongocrypt_destroy(crypt);
|
1221
1053
|
}
|
1222
1054
|
|
1223
|
-
static void
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
ctx,
|
1244
|
-
"kms provider required by datakey is not configured");
|
1245
|
-
|
1246
|
-
mongocrypt_ctx_destroy (ctx);
|
1247
|
-
mongocrypt_destroy (crypt);
|
1055
|
+
static void _test_createdatakey_with_wrong_kms_provider_helper(_mongocrypt_tester_t *tester,
|
1056
|
+
mongocrypt_binary_t *kms_provider) {
|
1057
|
+
mongocrypt_t *crypt;
|
1058
|
+
mongocrypt_ctx_t *ctx;
|
1059
|
+
const char *const kek = "{"
|
1060
|
+
"'provider': 'azure',"
|
1061
|
+
"'keyName': 'foo',"
|
1062
|
+
"'keyVaultEndpoint': 'example.com'"
|
1063
|
+
"}";
|
1064
|
+
|
1065
|
+
crypt = mongocrypt_new();
|
1066
|
+
ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, kms_provider), crypt);
|
1067
|
+
mongocrypt_setopt_use_need_kms_credentials_state(crypt);
|
1068
|
+
ASSERT_OK(mongocrypt_init(crypt), crypt);
|
1069
|
+
ctx = mongocrypt_ctx_new(crypt);
|
1070
|
+
ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx, TEST_BSON(kek)), ctx);
|
1071
|
+
ASSERT_FAILS(mongocrypt_ctx_datakey_init(ctx), ctx, "kms provider required by datakey is not configured");
|
1072
|
+
|
1073
|
+
mongocrypt_ctx_destroy(ctx);
|
1074
|
+
mongocrypt_destroy(crypt);
|
1248
1075
|
}
|
1249
1076
|
|
1250
|
-
static void
|
1251
|
-
|
1252
|
-
_mongocrypt_tester_t *tester)
|
1253
|
-
{
|
1254
|
-
_test_createdatakey_with_wrong_kms_provider_helper (
|
1255
|
-
tester, TEST_BSON ("{'gcp': { 'accessToken': '1234' } }"));
|
1077
|
+
static void _test_setopt_createdatakey_wrong_kms_provider_configured(_mongocrypt_tester_t *tester) {
|
1078
|
+
_test_createdatakey_with_wrong_kms_provider_helper(tester, TEST_BSON("{'gcp': { 'accessToken': '1234' } }"));
|
1256
1079
|
}
|
1257
1080
|
|
1258
|
-
static void
|
1259
|
-
|
1260
|
-
_mongocrypt_tester_t *tester)
|
1261
|
-
{
|
1262
|
-
_test_createdatakey_with_wrong_kms_provider_helper (
|
1263
|
-
tester, TEST_BSON ("{'gcp': {}}"));
|
1081
|
+
static void _test_setopt_createdatakey_wrong_kms_provider_empty(_mongocrypt_tester_t *tester) {
|
1082
|
+
_test_createdatakey_with_wrong_kms_provider_helper(tester, TEST_BSON("{'gcp': {}}"));
|
1264
1083
|
}
|
1265
1084
|
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
/* Test that failure to set an option on an uninitialized context is returned
|
1292
|
-
* through mongocrypt_ctx_status */
|
1293
|
-
_test_setopt_failure_uninitialized (tester);
|
1085
|
+
static void _test_options(_mongocrypt_tester_t *tester) {
|
1086
|
+
/* Test individual options */
|
1087
|
+
_test_setopt_masterkey_aws(tester);
|
1088
|
+
_test_setopt_masterkey_local(tester);
|
1089
|
+
_test_setopt_key_id(tester);
|
1090
|
+
_test_setopt_algorithm(tester);
|
1091
|
+
_test_setopt_key_alt_name(tester);
|
1092
|
+
_test_setopt_key_material(tester);
|
1093
|
+
_test_setopt_endpoint(tester);
|
1094
|
+
_test_setopt_key_encryption_key_azure(tester);
|
1095
|
+
_test_setopt_key_encryption_key_gcp(tester);
|
1096
|
+
_test_setopt_query_type(tester);
|
1097
|
+
_test_setopt_createdatakey_wrong_kms_provider_empty(tester);
|
1098
|
+
_test_setopt_createdatakey_wrong_kms_provider_configured(tester);
|
1099
|
+
|
1100
|
+
/* Test options on different contexts */
|
1101
|
+
_test_setopt_for_datakey(tester);
|
1102
|
+
_test_setopt_for_encrypt(tester);
|
1103
|
+
_test_setopt_for_explicit_encrypt(tester);
|
1104
|
+
_test_setopt_for_decrypt(tester);
|
1105
|
+
_test_setopt_for_explicit_decrypt(tester);
|
1106
|
+
|
1107
|
+
/* Test that failure to set an option on an uninitialized context is returned
|
1108
|
+
* through mongocrypt_ctx_status */
|
1109
|
+
_test_setopt_failure_uninitialized(tester);
|
1294
1110
|
}
|
1295
1111
|
|
1296
|
-
|
1297
|
-
|
1298
|
-
_mongocrypt_tester_install_ctx_setopt (_mongocrypt_tester_t *tester)
|
1299
|
-
{
|
1300
|
-
INSTALL_TEST (_test_options);
|
1112
|
+
void _mongocrypt_tester_install_ctx_setopt(_mongocrypt_tester_t *tester) {
|
1113
|
+
INSTALL_TEST(_test_options);
|
1301
1114
|
}
|