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
@@ -16,1046 +16,832 @@
|
|
16
16
|
|
17
17
|
#include "test-mongocrypt.h"
|
18
18
|
|
19
|
+
#define TEST_REWRAP_MASTER_KEY_ID_OLD \
|
20
|
+
"arn:aws:kms:us-east-1:579766882180:key/" \
|
21
|
+
"89fcc2c4-08b0-4bd9-9f25-e30687b580d0"
|
19
22
|
|
20
|
-
#define
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
#define TEST_REWRAP_MASTER_KEY_ID_NEW \
|
25
|
-
"arn:aws:kms:us-east-1:579766882180:key/" \
|
26
|
-
"061334ae-07a8-4ceb-a813-8135540e837d"
|
27
|
-
|
23
|
+
#define TEST_REWRAP_MASTER_KEY_ID_NEW \
|
24
|
+
"arn:aws:kms:us-east-1:579766882180:key/" \
|
25
|
+
"061334ae-07a8-4ceb-a813-8135540e837d"
|
28
26
|
|
29
27
|
typedef struct {
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
_mongocrypt_buffer_t id;
|
29
|
+
const char *kek_id;
|
30
|
+
_mongocrypt_buffer_t key_material;
|
31
|
+
int64_t creation_date;
|
32
|
+
int64_t update_date;
|
33
|
+
_mongocrypt_key_alt_name_t *key_alt_names;
|
36
34
|
} _test_datakey_fields_t;
|
37
35
|
|
38
|
-
static _test_datakey_fields_t *
|
39
|
-
|
40
|
-
{
|
41
|
-
return bson_malloc0 (sizeof (_test_datakey_fields_t));
|
36
|
+
static _test_datakey_fields_t *_test_datakey_fields_new(void) {
|
37
|
+
return bson_malloc0(sizeof(_test_datakey_fields_t));
|
42
38
|
}
|
43
39
|
|
44
|
-
static void
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
return;
|
49
|
-
}
|
40
|
+
static void _test_datakey_fields_destroy(_test_datakey_fields_t *fields) {
|
41
|
+
if (!fields) {
|
42
|
+
return;
|
43
|
+
}
|
50
44
|
|
51
|
-
|
45
|
+
_mongocrypt_key_alt_name_destroy_all(fields->key_alt_names);
|
52
46
|
|
53
|
-
|
47
|
+
bson_free(fields);
|
54
48
|
}
|
55
49
|
|
56
|
-
static _mongocrypt_buffer_t
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
bson_iter_t iter;
|
61
|
-
_mongocrypt_buffer_t buf;
|
50
|
+
static _mongocrypt_buffer_t _find_key_id(mongocrypt_binary_t *key) {
|
51
|
+
bson_t bson;
|
52
|
+
bson_iter_t iter;
|
53
|
+
_mongocrypt_buffer_t buf;
|
62
54
|
|
63
|
-
|
55
|
+
BSON_ASSERT_PARAM(key);
|
64
56
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
57
|
+
ASSERT(_mongocrypt_binary_to_bson(key, &bson));
|
58
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
59
|
+
ASSERT(bson_iter_find_descendant(&iter, "_id", &iter));
|
60
|
+
ASSERT(BSON_ITER_HOLDS_BINARY(&iter));
|
61
|
+
ASSERT(_mongocrypt_buffer_from_binary_iter(&buf, &iter));
|
62
|
+
ASSERT(buf.subtype == BSON_SUBTYPE_UUID);
|
63
|
+
ASSERT(buf.len > 0u);
|
72
64
|
|
73
|
-
|
65
|
+
return buf;
|
74
66
|
}
|
75
67
|
|
76
|
-
static _mongocrypt_buffer_t
|
77
|
-
|
78
|
-
{
|
79
|
-
_mongocrypt_buffer_t buf;
|
68
|
+
static _mongocrypt_buffer_t _find_key_id_from_iter(bson_iter_t *iter) {
|
69
|
+
_mongocrypt_buffer_t buf;
|
80
70
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
71
|
+
ASSERT(BSON_ITER_HOLDS_BINARY(iter));
|
72
|
+
ASSERT(_mongocrypt_buffer_from_binary_iter(&buf, iter));
|
73
|
+
ASSERT(buf.subtype == BSON_SUBTYPE_UUID);
|
74
|
+
ASSERT(buf.len > 0u);
|
85
75
|
|
86
|
-
|
76
|
+
return buf;
|
87
77
|
}
|
88
78
|
|
89
|
-
static const char *
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
bson_iter_t iter;
|
94
|
-
const char *res;
|
79
|
+
static const char *_find_masterkey_id(mongocrypt_binary_t *key) {
|
80
|
+
bson_t bson;
|
81
|
+
bson_iter_t iter;
|
82
|
+
const char *res;
|
95
83
|
|
96
|
-
|
84
|
+
BSON_ASSERT_PARAM(key);
|
97
85
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
86
|
+
ASSERT(_mongocrypt_binary_to_bson(key, &bson));
|
87
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
88
|
+
ASSERT(bson_iter_find_descendant(&iter, "masterKey.key", &iter));
|
89
|
+
ASSERT((res = bson_iter_utf8(&iter, NULL)));
|
102
90
|
|
103
|
-
|
91
|
+
return res;
|
104
92
|
}
|
105
93
|
|
106
|
-
static _mongocrypt_buffer_t
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
bson_iter_t iter;
|
111
|
-
_mongocrypt_buffer_t buf;
|
94
|
+
static _mongocrypt_buffer_t _find_key_material(mongocrypt_binary_t *key) {
|
95
|
+
bson_t bson;
|
96
|
+
bson_iter_t iter;
|
97
|
+
_mongocrypt_buffer_t buf;
|
112
98
|
|
113
|
-
|
99
|
+
BSON_ASSERT_PARAM(key);
|
114
100
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
101
|
+
ASSERT(_mongocrypt_binary_to_bson(key, &bson));
|
102
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
103
|
+
ASSERT(bson_iter_find_descendant(&iter, "keyMaterial", &iter));
|
104
|
+
ASSERT(BSON_ITER_HOLDS_BINARY(&iter));
|
105
|
+
ASSERT(_mongocrypt_buffer_from_binary_iter(&buf, &iter));
|
106
|
+
ASSERT(buf.subtype == BSON_SUBTYPE_BINARY);
|
107
|
+
ASSERT(buf.len > 0u);
|
122
108
|
|
123
|
-
|
109
|
+
return buf;
|
124
110
|
}
|
125
111
|
|
126
|
-
static _mongocrypt_buffer_t
|
127
|
-
|
128
|
-
{
|
129
|
-
_mongocrypt_buffer_t buf;
|
112
|
+
static _mongocrypt_buffer_t _key_material_from_iter(bson_iter_t *iter) {
|
113
|
+
_mongocrypt_buffer_t buf;
|
130
114
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
115
|
+
ASSERT(BSON_ITER_HOLDS_BINARY(iter));
|
116
|
+
ASSERT(_mongocrypt_buffer_from_binary_iter(&buf, iter));
|
117
|
+
ASSERT(buf.subtype == BSON_SUBTYPE_BINARY);
|
118
|
+
ASSERT(buf.len > 0u);
|
135
119
|
|
136
|
-
|
120
|
+
return buf;
|
137
121
|
}
|
138
122
|
|
139
|
-
static bool
|
140
|
-
|
141
|
-
|
142
|
-
{
|
143
|
-
BSON_ASSERT_PARAM (lhs);
|
144
|
-
BSON_ASSERT_PARAM (rhs);
|
123
|
+
static bool _buffer_cmp_equal(const _mongocrypt_buffer_t *lhs, const _mongocrypt_buffer_t *rhs) {
|
124
|
+
BSON_ASSERT_PARAM(lhs);
|
125
|
+
BSON_ASSERT_PARAM(rhs);
|
145
126
|
|
146
|
-
|
127
|
+
return lhs->len == rhs->len && memcmp(lhs->data, rhs->data, lhs->len) == 0;
|
147
128
|
}
|
148
129
|
|
149
|
-
static int64_t
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
bson_iter_t iter;
|
154
|
-
int64_t res;
|
130
|
+
static int64_t _find_date_field(mongocrypt_binary_t *key, const char *dotkey) {
|
131
|
+
bson_t bson;
|
132
|
+
bson_iter_t iter;
|
133
|
+
int64_t res;
|
155
134
|
|
156
|
-
|
135
|
+
BSON_ASSERT_PARAM(key);
|
157
136
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
137
|
+
ASSERT(_mongocrypt_binary_to_bson(key, &bson));
|
138
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
139
|
+
ASSERT(bson_iter_find_descendant(&iter, dotkey, &iter));
|
140
|
+
ASSERT(BSON_ITER_HOLDS_DATE_TIME(&iter));
|
141
|
+
ASSERT((res = bson_iter_date_time(&iter)) != 0)
|
163
142
|
|
164
|
-
|
143
|
+
return res;
|
165
144
|
}
|
166
145
|
|
167
|
-
static int64_t
|
168
|
-
|
169
|
-
{
|
170
|
-
return _find_date_field (key, "creationDate");
|
146
|
+
static int64_t _find_creation_date(mongocrypt_binary_t *key) {
|
147
|
+
return _find_date_field(key, "creationDate");
|
171
148
|
}
|
172
149
|
|
173
|
-
static int64_t
|
174
|
-
|
175
|
-
{
|
176
|
-
return _find_date_field (key, "updateDate");
|
150
|
+
static int64_t _find_update_date(mongocrypt_binary_t *key) {
|
151
|
+
return _find_date_field(key, "updateDate");
|
177
152
|
}
|
178
153
|
|
179
|
-
static _mongocrypt_key_alt_name_t *
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
bson_iter_t iter;
|
184
|
-
_mongocrypt_key_alt_name_t *res;
|
154
|
+
static _mongocrypt_key_alt_name_t *_find_key_alt_names(mongocrypt_binary_t *key) {
|
155
|
+
bson_t bson;
|
156
|
+
bson_iter_t iter;
|
157
|
+
_mongocrypt_key_alt_name_t *res;
|
185
158
|
|
186
|
-
|
159
|
+
BSON_ASSERT_PARAM(key);
|
187
160
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
161
|
+
ASSERT(_mongocrypt_binary_to_bson(key, &bson));
|
162
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
163
|
+
ASSERT(bson_iter_find_descendant(&iter, "keyAltNames", &iter));
|
164
|
+
ASSERT(_mongocrypt_key_alt_name_from_iter(&iter, &res, NULL));
|
165
|
+
ASSERT(res);
|
193
166
|
|
194
|
-
|
167
|
+
return res;
|
195
168
|
}
|
196
169
|
|
197
|
-
static _test_datakey_fields_t *
|
198
|
-
|
199
|
-
{
|
200
|
-
_test_datakey_fields_t *res = _test_datakey_fields_new ();
|
170
|
+
static _test_datakey_fields_t *_find_datakey_fields(mongocrypt_binary_t *key) {
|
171
|
+
_test_datakey_fields_t *res = _test_datakey_fields_new();
|
201
172
|
|
202
|
-
|
173
|
+
BSON_ASSERT_PARAM(key);
|
203
174
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
175
|
+
res->id = _find_key_id(key);
|
176
|
+
res->kek_id = _find_masterkey_id(key);
|
177
|
+
res->creation_date = _find_creation_date(key);
|
178
|
+
res->update_date = _find_update_date(key);
|
179
|
+
res->key_material = _find_key_material(key);
|
180
|
+
res->key_alt_names = _find_key_alt_names(key);
|
210
181
|
|
211
|
-
|
182
|
+
return res;
|
212
183
|
}
|
213
184
|
|
214
|
-
static void
|
215
|
-
|
216
|
-
{
|
217
|
-
BSON_ASSERT_PARAM (kms);
|
185
|
+
static void _assert_aws_kms_request(mongocrypt_kms_ctx_t *kms) {
|
186
|
+
BSON_ASSERT_PARAM(kms);
|
218
187
|
|
219
|
-
|
188
|
+
ASSERT_STREQUAL(mongocrypt_kms_ctx_get_kms_provider(kms, NULL), "aws");
|
220
189
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
190
|
+
{
|
191
|
+
mongocrypt_binary_t bin;
|
192
|
+
ASSERT(mongocrypt_kms_ctx_message(kms, &bin));
|
193
|
+
ASSERT(bin.len > 0);
|
194
|
+
}
|
226
195
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
196
|
+
{
|
197
|
+
const char *endpoint;
|
198
|
+
ASSERT(mongocrypt_kms_ctx_endpoint(kms, &endpoint));
|
199
|
+
ASSERT(endpoint);
|
200
|
+
}
|
232
201
|
|
233
|
-
|
202
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) > 0);
|
234
203
|
}
|
235
204
|
|
236
|
-
static void
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
ASSERT ((mongocrypt_kms_ctx_endpoint (kms, &endpoint)));
|
241
|
-
ASSERT_STREQUAL (expected, endpoint);
|
205
|
+
static void _assert_aws_kms_endpoint(mongocrypt_kms_ctx_t *kms, const char *expected) {
|
206
|
+
const char *endpoint = NULL;
|
207
|
+
ASSERT((mongocrypt_kms_ctx_endpoint(kms, &endpoint)));
|
208
|
+
ASSERT_STREQUAL(expected, endpoint);
|
242
209
|
}
|
243
210
|
|
211
|
+
static void _test_rewrap_many_datakey_init(_mongocrypt_tester_t *tester) {
|
212
|
+
mongocrypt_t *const crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
213
|
+
mongocrypt_ctx_t *ctx = NULL;
|
214
|
+
|
215
|
+
/* No context, nothing to init. */
|
216
|
+
ASSERT(!mongocrypt_ctx_rewrap_many_datakey_init(NULL, NULL));
|
217
|
+
|
218
|
+
/* Filter argument required. */
|
219
|
+
ctx = mongocrypt_ctx_new(crypt);
|
220
|
+
ASSERT_FAILS(mongocrypt_ctx_rewrap_many_datakey_init(ctx, NULL), ctx, "filter must not be null");
|
221
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_ERROR);
|
222
|
+
mongocrypt_ctx_destroy(ctx);
|
223
|
+
|
224
|
+
/* Irrelevant options should trigger initialization error. */
|
225
|
+
ctx = mongocrypt_ctx_new(crypt);
|
226
|
+
ASSERT_OK(mongocrypt_ctx_setopt_key_alt_name(ctx, TEST_BSON("{'keyAltName': 'test'}")), ctx);
|
227
|
+
ASSERT_FAILS(mongocrypt_ctx_rewrap_many_datakey_init(ctx, TEST_BSON("{}")), ctx, "key id and alt name prohibited");
|
228
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_ERROR);
|
229
|
+
mongocrypt_ctx_destroy(ctx);
|
230
|
+
|
231
|
+
/* rewrapManyDataKeyOpts.newProvider and rewrapManyDataKeyOpts.newMasterKey
|
232
|
+
* should be provided via mongocrypt_ctx_setopt_key_encryption_key. */
|
233
|
+
ctx = mongocrypt_ctx_new(crypt);
|
234
|
+
ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx,
|
235
|
+
TEST_BSON("{'provider': 'aws',"
|
236
|
+
" 'region': 'us-east-1',"
|
237
|
+
" 'key': '" TEST_REWRAP_MASTER_KEY_ID_NEW "'}")),
|
238
|
+
ctx);
|
239
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, TEST_BSON("{}")), ctx);
|
240
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
241
|
+
mongocrypt_ctx_destroy(ctx);
|
242
|
+
|
243
|
+
/* Not providing rewrapManyDataKeyOpts is OK. */
|
244
|
+
ctx = mongocrypt_ctx_new(crypt);
|
245
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, TEST_BSON("{}")), ctx);
|
246
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
247
|
+
mongocrypt_ctx_destroy(ctx);
|
248
|
+
|
249
|
+
mongocrypt_destroy(crypt);
|
250
|
+
}
|
244
251
|
|
245
|
-
static void
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
252
|
+
static void _test_rewrap_many_datakey_need_mongo_keys(_mongocrypt_tester_t *tester) {
|
253
|
+
mongocrypt_binary_t *const filter = TEST_BSON("{'keyAltName': {'$in': ['keyDocumentA', 'keyDocumentB']}}");
|
254
|
+
|
255
|
+
mongocrypt_t *const crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
256
|
+
mongocrypt_ctx_t *ctx = NULL;
|
257
|
+
|
258
|
+
/* Filter should be the same as what was provided in call to init. */
|
259
|
+
ctx = mongocrypt_ctx_new(crypt);
|
260
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
261
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
262
|
+
{
|
263
|
+
mongocrypt_binary_t *const op = mongocrypt_binary_new();
|
264
|
+
ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, op), ctx);
|
265
|
+
ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(filter, op);
|
266
|
+
mongocrypt_binary_destroy(op);
|
267
|
+
}
|
268
|
+
mongocrypt_ctx_destroy(ctx);
|
269
|
+
|
270
|
+
/* No key documents is OK, no work to be done. */
|
271
|
+
ctx = mongocrypt_ctx_new(crypt);
|
272
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
273
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
274
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
275
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_DONE);
|
276
|
+
mongocrypt_ctx_destroy(ctx);
|
277
|
+
|
278
|
+
/* Any number of key documents can be given. */
|
279
|
+
ctx = mongocrypt_ctx_new(crypt);
|
280
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
281
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
282
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
283
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
284
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
285
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
286
|
+
mongocrypt_ctx_destroy(ctx);
|
287
|
+
|
288
|
+
/* Key documents must not have duplicate key ID or alt names. */
|
289
|
+
ctx = mongocrypt_ctx_new(crypt);
|
290
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
291
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
292
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-with-alt-name.json")), ctx);
|
293
|
+
ASSERT_FAILS(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-with-alt-name-duplicate-id.json")),
|
279
294
|
ctx,
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
ctx);
|
284
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, TEST_BSON ("{}")),
|
285
|
-
ctx);
|
286
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
287
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
288
|
-
mongocrypt_ctx_destroy (ctx);
|
289
|
-
|
290
|
-
/* Not providing rewrapManyDataKeyOpts is OK. */
|
291
|
-
ctx = mongocrypt_ctx_new (crypt);
|
292
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, TEST_BSON ("{}")),
|
293
|
-
ctx);
|
294
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
295
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
296
|
-
mongocrypt_ctx_destroy (ctx);
|
295
|
+
"keys returned have duplicate keyAltNames or _id");
|
296
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_ERROR);
|
297
|
+
mongocrypt_ctx_destroy(ctx);
|
297
298
|
|
298
|
-
|
299
|
+
mongocrypt_destroy(crypt);
|
299
300
|
}
|
300
301
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
302
|
+
static void _test_rewrap_many_datakey_need_kms_decrypt(_mongocrypt_tester_t *tester) {
|
303
|
+
mongocrypt_binary_t *const filter = TEST_BSON("{'keyAltName': {'$in': ['keyDocumentA', 'keyDocumentB']}}");
|
304
|
+
|
305
|
+
mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
306
|
+
mongocrypt_ctx_t *ctx = NULL;
|
307
|
+
mongocrypt_kms_ctx_t *kms = NULL;
|
308
|
+
|
309
|
+
/* AWS */
|
310
|
+
ctx = mongocrypt_ctx_new(crypt);
|
311
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
312
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
313
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-full.json")), ctx);
|
314
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
315
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
316
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
317
|
+
ASSERT_STREQUAL("aws", mongocrypt_kms_ctx_get_kms_provider(kms, NULL));
|
318
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
319
|
+
mongocrypt_ctx_destroy(ctx);
|
320
|
+
|
321
|
+
/* Clear key cache. */
|
322
|
+
mongocrypt_destroy(crypt);
|
323
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
324
|
+
|
325
|
+
/* Azure */
|
326
|
+
ctx = mongocrypt_ctx_new(crypt);
|
327
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
328
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
329
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-azure.json")), ctx);
|
330
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
331
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
332
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
333
|
+
ASSERT_STREQUAL("azure", mongocrypt_kms_ctx_get_kms_provider(kms, NULL));
|
334
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
335
|
+
mongocrypt_ctx_destroy(ctx);
|
336
|
+
|
337
|
+
/* Clear key cache. */
|
338
|
+
mongocrypt_destroy(crypt);
|
339
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
340
|
+
|
341
|
+
/* GCP */
|
342
|
+
ctx = mongocrypt_ctx_new(crypt);
|
343
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
344
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
345
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-gcp.json")), ctx);
|
346
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
347
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
348
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
349
|
+
ASSERT_STREQUAL("gcp", mongocrypt_kms_ctx_get_kms_provider(kms, NULL));
|
350
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
351
|
+
mongocrypt_ctx_destroy(ctx);
|
352
|
+
|
353
|
+
/* Clear key cache. */
|
354
|
+
mongocrypt_destroy(crypt);
|
355
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
356
|
+
|
357
|
+
/* KMIP */
|
358
|
+
ctx = mongocrypt_ctx_new(crypt);
|
359
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
360
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
361
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-kmip.json")), ctx);
|
362
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
363
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
364
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
365
|
+
ASSERT_STREQUAL("kmip", mongocrypt_kms_ctx_get_kms_provider(kms, NULL));
|
366
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
367
|
+
mongocrypt_ctx_destroy(ctx);
|
368
|
+
|
369
|
+
/* Clear key cache. */
|
370
|
+
mongocrypt_destroy(crypt);
|
371
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
372
|
+
|
373
|
+
/* Local: no KMS required. */
|
374
|
+
ctx = mongocrypt_ctx_new(crypt);
|
375
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
376
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
377
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-local.json")), ctx);
|
378
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
379
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
|
380
|
+
mongocrypt_ctx_destroy(ctx);
|
381
|
+
|
382
|
+
/* Clear key cache. */
|
383
|
+
mongocrypt_destroy(crypt);
|
384
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
385
|
+
|
386
|
+
/* Number of KMS requests should match number of keys that require it. */
|
387
|
+
ctx = mongocrypt_ctx_new(crypt);
|
388
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
389
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
390
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
391
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
392
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
393
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
394
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
395
|
+
ASSERT_STREQUAL("aws", mongocrypt_kms_ctx_get_kms_provider(kms, NULL));
|
396
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
397
|
+
ASSERT_STREQUAL("aws", mongocrypt_kms_ctx_get_kms_provider(kms, NULL));
|
398
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
399
|
+
mongocrypt_ctx_destroy(ctx);
|
400
|
+
|
401
|
+
/* Ensure keys that don't require KMS do not request it. */
|
402
|
+
ctx = mongocrypt_ctx_new(crypt);
|
403
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
404
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
405
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
406
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
407
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-local.json")), ctx);
|
408
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
409
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
410
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
411
|
+
ASSERT_STREQUAL("aws", mongocrypt_kms_ctx_get_kms_provider(kms, NULL));
|
412
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
413
|
+
ASSERT_STREQUAL("aws", mongocrypt_kms_ctx_get_kms_provider(kms, NULL));
|
414
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
415
|
+
mongocrypt_ctx_destroy(ctx);
|
416
|
+
|
417
|
+
/* Clear key cache. */
|
418
|
+
mongocrypt_destroy(crypt);
|
419
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
420
|
+
|
421
|
+
/* Ensure number of KMS requests matches number of keys that require it. */
|
422
|
+
ctx = mongocrypt_ctx_new(crypt);
|
423
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
424
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
425
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
426
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
427
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
428
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
429
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
430
|
+
/* Implementation detail: decryption KMS requests are issued in reverse order
|
431
|
+
* of provided key documents. */
|
432
|
+
_assert_aws_kms_endpoint(kms, "example.com:443");
|
433
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-b.txt")), kms);
|
434
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
435
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
436
|
+
_assert_aws_kms_endpoint(kms, "kms.us-east-1.amazonaws.com:443");
|
437
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-a.txt")), kms);
|
438
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
439
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
440
|
+
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
|
441
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
442
|
+
mongocrypt_ctx_destroy(ctx);
|
443
|
+
|
444
|
+
/* Clear key cache. */
|
445
|
+
mongocrypt_destroy(crypt);
|
446
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
447
|
+
|
448
|
+
/* Ensure all KMS requests have a corresponding KMS response. */
|
449
|
+
ctx = mongocrypt_ctx_new(crypt);
|
450
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
451
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
452
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
453
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
454
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
455
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
456
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
457
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-b.txt")), kms);
|
458
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
459
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
460
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) > 0); /* "Oops." */
|
461
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
462
|
+
ASSERT_FAILS(mongocrypt_ctx_kms_done(ctx), ctx, "KMS response unfinished");
|
463
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_ERROR);
|
464
|
+
mongocrypt_ctx_destroy(ctx);
|
465
|
+
|
466
|
+
/* Clear key cache. */
|
467
|
+
mongocrypt_destroy(crypt);
|
468
|
+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
469
|
+
|
470
|
+
/* Skip KMS for keys with cached decrypted key material. */
|
471
|
+
ctx = mongocrypt_ctx_new(crypt);
|
472
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
473
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
474
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
475
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
476
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
477
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
478
|
+
/* Cache decrypted key material for datakey B. */
|
479
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-b.txt")), kms);
|
480
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
481
|
+
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
|
482
|
+
mongocrypt_ctx_destroy(ctx);
|
483
|
+
ctx = mongocrypt_ctx_new(crypt);
|
484
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
485
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
486
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
487
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
488
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
489
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
490
|
+
/* Only datakey A should make a KMS request. */
|
491
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
492
|
+
_assert_aws_kms_endpoint(kms, "kms.us-east-1.amazonaws.com:443");
|
493
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
494
|
+
mongocrypt_ctx_destroy(ctx);
|
495
|
+
|
496
|
+
mongocrypt_destroy(crypt);
|
369
497
|
}
|
370
498
|
|
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
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
/* Clear key cache. */
|
472
|
-
mongocrypt_destroy (crypt);
|
473
|
-
crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
|
474
|
-
|
475
|
-
/* Number of KMS requests should match number of keys that require it. */
|
476
|
-
ctx = mongocrypt_ctx_new (crypt);
|
477
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
478
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
479
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
480
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
481
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-a.json")),
|
482
|
-
ctx);
|
483
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
484
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
485
|
-
ctx);
|
486
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
487
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
488
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
489
|
-
ASSERT_STREQUAL ("aws", mongocrypt_kms_ctx_get_kms_provider (kms, NULL));
|
490
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
491
|
-
ASSERT_STREQUAL ("aws", mongocrypt_kms_ctx_get_kms_provider (kms, NULL));
|
492
|
-
ASSERT_OK (!mongocrypt_ctx_next_kms_ctx (ctx), ctx);
|
493
|
-
mongocrypt_ctx_destroy (ctx);
|
494
|
-
|
495
|
-
/* Ensure keys that don't require KMS do not request it. */
|
496
|
-
ctx = mongocrypt_ctx_new (crypt);
|
497
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
498
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
499
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
500
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
501
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-a.json")),
|
502
|
-
ctx);
|
503
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
504
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
505
|
-
ctx);
|
506
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
507
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-local.json")),
|
508
|
-
ctx);
|
509
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
510
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
511
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
512
|
-
ASSERT_STREQUAL ("aws", mongocrypt_kms_ctx_get_kms_provider (kms, NULL));
|
513
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
514
|
-
ASSERT_STREQUAL ("aws", mongocrypt_kms_ctx_get_kms_provider (kms, NULL));
|
515
|
-
ASSERT_OK (!mongocrypt_ctx_next_kms_ctx (ctx), ctx);
|
516
|
-
mongocrypt_ctx_destroy (ctx);
|
517
|
-
|
518
|
-
/* Clear key cache. */
|
519
|
-
mongocrypt_destroy (crypt);
|
520
|
-
crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
|
521
|
-
|
522
|
-
/* Ensure number of KMS requests matches number of keys that require it. */
|
523
|
-
ctx = mongocrypt_ctx_new (crypt);
|
524
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
525
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
526
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
527
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
528
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-a.json")),
|
529
|
-
ctx);
|
530
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
531
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
532
|
-
ctx);
|
533
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
534
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
535
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
536
|
-
/* Implementation detail: decryption KMS requests are issued in reverse order
|
537
|
-
* of provided key documents. */
|
538
|
-
_assert_aws_kms_endpoint (kms, "example.com:443");
|
539
|
-
ASSERT_OK (mongocrypt_kms_ctx_feed (
|
540
|
-
kms, TEST_FILE ("./test/data/rmd/kms-decrypt-reply-b.txt")),
|
541
|
-
kms);
|
542
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) == 0);
|
543
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
544
|
-
_assert_aws_kms_endpoint (kms, "kms.us-east-1.amazonaws.com:443");
|
545
|
-
ASSERT_OK (mongocrypt_kms_ctx_feed (
|
546
|
-
kms, TEST_FILE ("./test/data/rmd/kms-decrypt-reply-a.txt")),
|
547
|
-
kms);
|
548
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) == 0);
|
549
|
-
ASSERT_OK (!mongocrypt_ctx_next_kms_ctx (ctx), ctx);
|
550
|
-
ASSERT_OK (mongocrypt_ctx_kms_done (ctx), ctx);
|
551
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
552
|
-
mongocrypt_ctx_destroy (ctx);
|
553
|
-
|
554
|
-
/* Clear key cache. */
|
555
|
-
mongocrypt_destroy (crypt);
|
556
|
-
crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
|
557
|
-
|
558
|
-
/* Ensure all KMS requests have a corresponding KMS response. */
|
559
|
-
ctx = mongocrypt_ctx_new (crypt);
|
560
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
561
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
562
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
563
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
564
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-a.json")),
|
565
|
-
ctx);
|
566
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
567
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
568
|
-
ctx);
|
569
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
570
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
571
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
572
|
-
ASSERT_OK (mongocrypt_kms_ctx_feed (
|
573
|
-
kms, TEST_FILE ("./test/data/rmd/kms-decrypt-reply-b.txt")),
|
574
|
-
kms);
|
575
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) == 0);
|
576
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
577
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) > 0); /* "Oops." */
|
578
|
-
ASSERT_OK (!mongocrypt_ctx_next_kms_ctx (ctx), ctx);
|
579
|
-
ASSERT_FAILS (mongocrypt_ctx_kms_done (ctx), ctx, "KMS response unfinished");
|
580
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_ERROR);
|
581
|
-
mongocrypt_ctx_destroy (ctx);
|
582
|
-
|
583
|
-
/* Clear key cache. */
|
584
|
-
mongocrypt_destroy (crypt);
|
585
|
-
crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
|
586
|
-
|
587
|
-
/* Skip KMS for keys with cached decrypted key material. */
|
588
|
-
ctx = mongocrypt_ctx_new (crypt);
|
589
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
590
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
591
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
592
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
593
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
594
|
-
ctx);
|
595
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
596
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
597
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
598
|
-
/* Cache decrypted key material for datakey B. */
|
599
|
-
ASSERT_OK (mongocrypt_kms_ctx_feed (
|
600
|
-
kms, TEST_FILE ("./test/data/rmd/kms-decrypt-reply-b.txt")),
|
601
|
-
kms);
|
602
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) == 0);
|
603
|
-
ASSERT_OK (mongocrypt_ctx_kms_done (ctx), ctx);
|
604
|
-
mongocrypt_ctx_destroy (ctx);
|
605
|
-
ctx = mongocrypt_ctx_new (crypt);
|
606
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
607
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
608
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
609
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
610
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-a.json")),
|
611
|
-
ctx);
|
612
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
613
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
614
|
-
ctx);
|
615
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
616
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
617
|
-
/* Only datakey A should make a KMS request. */
|
618
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
619
|
-
_assert_aws_kms_endpoint (kms, "kms.us-east-1.amazonaws.com:443");
|
620
|
-
ASSERT_OK (!mongocrypt_ctx_next_kms_ctx (ctx), ctx);
|
621
|
-
mongocrypt_ctx_destroy (ctx);
|
622
|
-
|
623
|
-
mongocrypt_destroy (crypt);
|
624
|
-
}
|
625
|
-
|
626
|
-
|
627
|
-
static void
|
628
|
-
_test_rewrap_many_datakey_need_kms_encrypt (_mongocrypt_tester_t *tester)
|
629
|
-
{
|
630
|
-
mongocrypt_binary_t *const filter =
|
631
|
-
TEST_BSON ("{'keyAltName': {'$in': ['keyDocumentA', 'keyDocumentB']}}");
|
632
|
-
|
633
|
-
mongocrypt_t *const crypt =
|
634
|
-
_mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
|
635
|
-
mongocrypt_ctx_t *ctx = NULL;
|
636
|
-
mongocrypt_kms_ctx_t *kms = NULL;
|
637
|
-
|
638
|
-
/* If no new provider is given, encryption should reuse current KMS provider
|
639
|
-
* for each key. */
|
640
|
-
ctx = mongocrypt_ctx_new (crypt);
|
641
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
642
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
643
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
644
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
645
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-a.json")),
|
646
|
-
ctx);
|
647
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
648
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
649
|
-
ctx);
|
650
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
651
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
652
|
-
/* These decrypt replies should cache key material used by later blocks. */
|
653
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
654
|
-
ASSERT_OK (mongocrypt_kms_ctx_feed (
|
655
|
-
kms, TEST_FILE ("./test/data/rmd/kms-decrypt-reply-b.txt")),
|
656
|
-
kms);
|
657
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) == 0);
|
658
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
659
|
-
ASSERT_OK (mongocrypt_kms_ctx_feed (
|
660
|
-
kms, TEST_FILE ("./test/data/rmd/kms-decrypt-reply-a.txt")),
|
661
|
-
kms);
|
662
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) == 0);
|
663
|
-
ASSERT_OK (!mongocrypt_ctx_next_kms_ctx (ctx), ctx);
|
664
|
-
ASSERT_OK (mongocrypt_ctx_kms_done (ctx), ctx);
|
665
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
666
|
-
/* Implementation detail: encryption KMS requests are issued in same order as
|
667
|
-
* provided key documents. */
|
668
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
669
|
-
_assert_aws_kms_endpoint (kms, "kms.us-east-1.amazonaws.com:443");
|
670
|
-
ASSERT_OK (mongocrypt_kms_ctx_feed (
|
671
|
-
kms, TEST_FILE ("./test/data/rmd/kms-encrypt-reply-a.txt")),
|
672
|
-
kms);
|
673
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) == 0);
|
674
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
675
|
-
_assert_aws_kms_endpoint (kms, "example.com:443");
|
676
|
-
ASSERT_OK (mongocrypt_kms_ctx_feed (
|
677
|
-
kms, TEST_FILE ("./test/data/rmd/kms-encrypt-reply-b.txt")),
|
678
|
-
kms);
|
679
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) == 0);
|
680
|
-
ASSERT_OK (!mongocrypt_ctx_next_kms_ctx (ctx), ctx);
|
681
|
-
ASSERT_OK (mongocrypt_ctx_kms_done (ctx), ctx);
|
682
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
|
683
|
-
mongocrypt_ctx_destroy (ctx);
|
684
|
-
|
685
|
-
/* If new provider is given, encryption should use new KMS provider for all
|
686
|
-
* keys. */
|
687
|
-
ctx = mongocrypt_ctx_new (crypt);
|
688
|
-
ASSERT_OK (mongocrypt_ctx_setopt_key_encryption_key (
|
689
|
-
ctx,
|
690
|
-
TEST_BSON ("{'provider': 'aws',"
|
691
|
-
" 'region': 'us-east-2',"
|
692
|
-
" 'key': '" TEST_REWRAP_MASTER_KEY_ID_NEW "'}")),
|
693
|
-
ctx);
|
694
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
695
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
696
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
697
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
698
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-a.json")),
|
699
|
-
ctx);
|
700
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
701
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
702
|
-
ctx);
|
703
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
704
|
-
/* Skip decryption, key material should have been cached. */
|
705
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
706
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
707
|
-
_assert_aws_kms_endpoint (kms, "kms.us-east-2.amazonaws.com:443");
|
708
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
709
|
-
_assert_aws_kms_endpoint (kms, "kms.us-east-2.amazonaws.com:443");
|
710
|
-
ASSERT_OK (!mongocrypt_ctx_next_kms_ctx (ctx), ctx);
|
711
|
-
mongocrypt_ctx_destroy (ctx);
|
712
|
-
|
713
|
-
/* If no encryption KMS required, should skip straight to READY state. */
|
714
|
-
ctx = mongocrypt_ctx_new (crypt);
|
715
|
-
ASSERT_OK (mongocrypt_ctx_setopt_key_encryption_key (
|
716
|
-
ctx, TEST_BSON ("{'provider': 'local'}")),
|
717
|
-
ctx);
|
718
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
719
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
720
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
721
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
722
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-a.json")),
|
723
|
-
ctx);
|
724
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
725
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
726
|
-
ctx);
|
727
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
728
|
-
/* Skip decryption, key material should have been cached. */
|
729
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
|
730
|
-
mongocrypt_ctx_destroy (ctx);
|
731
|
-
|
732
|
-
/* Ensure all KMS requests have a corresponding KMS response. */
|
733
|
-
ctx = mongocrypt_ctx_new (crypt);
|
734
|
-
ASSERT_OK (mongocrypt_ctx_setopt_key_encryption_key (
|
735
|
-
ctx,
|
736
|
-
TEST_BSON ("{'provider': 'aws',"
|
737
|
-
" 'region': 'us-east-1',"
|
738
|
-
" 'key': '" TEST_REWRAP_MASTER_KEY_ID_NEW "'}")),
|
739
|
-
ctx);
|
740
|
-
ASSERT_OK (mongocrypt_ctx_rewrap_many_datakey_init (ctx, filter), ctx);
|
741
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
|
742
|
-
MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
743
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
744
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-a.json")),
|
745
|
-
ctx);
|
746
|
-
ASSERT_OK (mongocrypt_ctx_mongo_feed (
|
747
|
-
ctx, TEST_FILE ("./test/data/rmd/key-document-b.json")),
|
748
|
-
ctx);
|
749
|
-
ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
|
750
|
-
/* Skip decryption, key material should have been cached. */
|
751
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
|
752
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
753
|
-
ASSERT_OK (mongocrypt_kms_ctx_feed (
|
754
|
-
kms, TEST_FILE ("./test/data/rmd/kms-encrypt-reply-a.txt")),
|
755
|
-
kms);
|
756
|
-
ASSERT ((kms = mongocrypt_ctx_next_kms_ctx (ctx)));
|
757
|
-
ASSERT (mongocrypt_kms_ctx_bytes_needed (kms) > 0); /* "Oops." */
|
758
|
-
ASSERT_OK (!mongocrypt_ctx_next_kms_ctx (ctx), ctx);
|
759
|
-
ASSERT_FAILS (mongocrypt_ctx_kms_done (ctx), ctx, "KMS response unfinished");
|
760
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_ERROR);
|
761
|
-
mongocrypt_ctx_destroy (ctx);
|
762
|
-
|
763
|
-
mongocrypt_destroy (crypt);
|
499
|
+
static void _test_rewrap_many_datakey_need_kms_encrypt(_mongocrypt_tester_t *tester) {
|
500
|
+
mongocrypt_binary_t *const filter = TEST_BSON("{'keyAltName': {'$in': ['keyDocumentA', 'keyDocumentB']}}");
|
501
|
+
|
502
|
+
mongocrypt_t *const crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
503
|
+
mongocrypt_ctx_t *ctx = NULL;
|
504
|
+
mongocrypt_kms_ctx_t *kms = NULL;
|
505
|
+
|
506
|
+
/* If no new provider is given, encryption should reuse current KMS provider
|
507
|
+
* for each key. */
|
508
|
+
ctx = mongocrypt_ctx_new(crypt);
|
509
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
510
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
511
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
512
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
513
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
514
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
515
|
+
/* These decrypt replies should cache key material used by later blocks. */
|
516
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
517
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-b.txt")), kms);
|
518
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
519
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
520
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-a.txt")), kms);
|
521
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
522
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
523
|
+
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
|
524
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
525
|
+
/* Implementation detail: encryption KMS requests are issued in same order as
|
526
|
+
* provided key documents. */
|
527
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
528
|
+
_assert_aws_kms_endpoint(kms, "kms.us-east-1.amazonaws.com:443");
|
529
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-encrypt-reply-a.txt")), kms);
|
530
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
531
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
532
|
+
_assert_aws_kms_endpoint(kms, "example.com:443");
|
533
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-encrypt-reply-b.txt")), kms);
|
534
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
535
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
536
|
+
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
|
537
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
|
538
|
+
mongocrypt_ctx_destroy(ctx);
|
539
|
+
|
540
|
+
/* If new provider is given, encryption should use new KMS provider for all
|
541
|
+
* keys. */
|
542
|
+
ctx = mongocrypt_ctx_new(crypt);
|
543
|
+
ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx,
|
544
|
+
TEST_BSON("{'provider': 'aws',"
|
545
|
+
" 'region': 'us-east-2',"
|
546
|
+
" 'key': '" TEST_REWRAP_MASTER_KEY_ID_NEW "'}")),
|
547
|
+
ctx);
|
548
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
549
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
550
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
551
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
552
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
553
|
+
/* Skip decryption, key material should have been cached. */
|
554
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
555
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
556
|
+
_assert_aws_kms_endpoint(kms, "kms.us-east-2.amazonaws.com:443");
|
557
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
558
|
+
_assert_aws_kms_endpoint(kms, "kms.us-east-2.amazonaws.com:443");
|
559
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
560
|
+
mongocrypt_ctx_destroy(ctx);
|
561
|
+
|
562
|
+
/* If no encryption KMS required, should skip straight to READY state. */
|
563
|
+
ctx = mongocrypt_ctx_new(crypt);
|
564
|
+
ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx, TEST_BSON("{'provider': 'local'}")), ctx);
|
565
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
566
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
567
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
568
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
569
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
570
|
+
/* Skip decryption, key material should have been cached. */
|
571
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
|
572
|
+
mongocrypt_ctx_destroy(ctx);
|
573
|
+
|
574
|
+
/* Ensure all KMS requests have a corresponding KMS response. */
|
575
|
+
ctx = mongocrypt_ctx_new(crypt);
|
576
|
+
ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx,
|
577
|
+
TEST_BSON("{'provider': 'aws',"
|
578
|
+
" 'region': 'us-east-1',"
|
579
|
+
" 'key': '" TEST_REWRAP_MASTER_KEY_ID_NEW "'}")),
|
580
|
+
ctx);
|
581
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
582
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
583
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
584
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
585
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
586
|
+
/* Skip decryption, key material should have been cached. */
|
587
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
588
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
589
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-encrypt-reply-a.txt")), kms);
|
590
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
591
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) > 0); /* "Oops." */
|
592
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
593
|
+
ASSERT_FAILS(mongocrypt_ctx_kms_done(ctx), ctx, "KMS response unfinished");
|
594
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_ERROR);
|
595
|
+
mongocrypt_ctx_destroy(ctx);
|
596
|
+
|
597
|
+
mongocrypt_destroy(crypt);
|
764
598
|
}
|
765
599
|
|
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
|
-
ASSERT
|
870
|
-
|
871
|
-
ASSERT
|
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
|
-
ASSERT (bson_iter_find_descendant (&iter, "keyMaterial", &iter));
|
912
|
-
key_material_a = _key_material_from_iter (&iter);
|
913
|
-
ASSERT (!_buffer_cmp_equal (&fields_a->key_material, &key_material_a));
|
914
|
-
|
915
|
-
iter = b_iter;
|
916
|
-
ASSERT (bson_iter_find_descendant (&iter, "keyMaterial", &iter));
|
917
|
-
key_material_b = _key_material_from_iter (&iter);
|
918
|
-
ASSERT (!_buffer_cmp_equal (&fields_b->key_material, &key_material_b));
|
919
|
-
|
920
|
-
/* Key materials should differ. */
|
921
|
-
ASSERT (!_buffer_cmp_equal (&key_material_a, &key_material_b));
|
922
|
-
}
|
923
|
-
|
924
|
-
bson_destroy (&bson);
|
925
|
-
}
|
926
|
-
|
927
|
-
/* No more work to be done for RewrapManyDatakey. */
|
928
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_DONE);
|
929
|
-
|
930
|
-
_test_datakey_fields_destroy (fields_b);
|
931
|
-
_test_datakey_fields_destroy (fields_a);
|
932
|
-
mongocrypt_ctx_destroy (ctx);
|
933
|
-
mongocrypt_destroy (crypt);
|
600
|
+
static void _test_rewrap_many_datakey_finalize(_mongocrypt_tester_t *tester) {
|
601
|
+
mongocrypt_t *const crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
|
602
|
+
mongocrypt_ctx_t *const ctx = mongocrypt_ctx_new(crypt);
|
603
|
+
|
604
|
+
mongocrypt_binary_t *const filter = TEST_BSON("{'keyAltName': {'$in': ['keyDocumentA', 'keyDocumentB']}}");
|
605
|
+
|
606
|
+
mongocrypt_binary_t *const key_doc_a = TEST_FILE("./test/data/rmd/key-document-a.json");
|
607
|
+
mongocrypt_binary_t *const key_doc_b = TEST_FILE("./test/data/rmd/key-document-b.json");
|
608
|
+
|
609
|
+
/* Save current key fields for comparison with rewrapped keys. */
|
610
|
+
_test_datakey_fields_t *const fields_a = _find_datakey_fields(key_doc_a);
|
611
|
+
_test_datakey_fields_t *const fields_b = _find_datakey_fields(key_doc_b);
|
612
|
+
|
613
|
+
mongocrypt_kms_ctx_t *kms = NULL;
|
614
|
+
|
615
|
+
ASSERT_OK(ctx, crypt);
|
616
|
+
ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx,
|
617
|
+
TEST_BSON("{'provider': 'aws',"
|
618
|
+
" 'region': 'us-east-1',"
|
619
|
+
" 'key': '" TEST_REWRAP_MASTER_KEY_ID_NEW "'}")),
|
620
|
+
ctx);
|
621
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
|
622
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
623
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
624
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-b.json")), ctx);
|
625
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
626
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
627
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
628
|
+
_assert_aws_kms_request(kms);
|
629
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-b.txt")), kms);
|
630
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
631
|
+
|
632
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
633
|
+
_assert_aws_kms_request(kms);
|
634
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-a.txt")), kms);
|
635
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
636
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
637
|
+
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
|
638
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
639
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
640
|
+
_assert_aws_kms_request(kms);
|
641
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-encrypt-reply-a.txt")), kms);
|
642
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
643
|
+
|
644
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
645
|
+
_assert_aws_kms_request(kms);
|
646
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-encrypt-reply-b.txt")), kms);
|
647
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
648
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
649
|
+
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
|
650
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
|
651
|
+
|
652
|
+
{
|
653
|
+
mongocrypt_binary_t res;
|
654
|
+
bson_t bson;
|
655
|
+
bson_iter_t iter;
|
656
|
+
bson_iter_t a_iter;
|
657
|
+
bson_iter_t b_iter;
|
658
|
+
|
659
|
+
ASSERT_OK(mongocrypt_ctx_finalize(ctx, &res), ctx);
|
660
|
+
ASSERT(_mongocrypt_binary_to_bson(&res, &bson));
|
661
|
+
|
662
|
+
/* There should be exactly 2 documents. */
|
663
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
664
|
+
ASSERT(bson_iter_find_descendant(&iter, "v.1", &iter));
|
665
|
+
ASSERT(!bson_iter_find_descendant(&iter, "v.2", &iter));
|
666
|
+
|
667
|
+
/* Both keys should have the same ID as prior to rewrap, but may be
|
668
|
+
* returned in a different order from order they were fed. */
|
669
|
+
{
|
670
|
+
_mongocrypt_buffer_t id;
|
671
|
+
|
672
|
+
ASSERT(bson_iter_init(&a_iter, &bson));
|
673
|
+
ASSERT(bson_iter_init(&b_iter, &bson));
|
674
|
+
|
675
|
+
/* Find first keyDocument. */
|
676
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
677
|
+
ASSERT(bson_iter_find_descendant(&iter, "v.0._id", &iter));
|
678
|
+
id = _find_key_id_from_iter(&iter);
|
679
|
+
if (_buffer_cmp_equal(&fields_a->id, &id)) {
|
680
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
681
|
+
ASSERT(bson_iter_find_descendant(&iter, "v.0", &iter));
|
682
|
+
ASSERT(bson_iter_recurse(&iter, &a_iter));
|
683
|
+
} else if (_buffer_cmp_equal(&fields_b->id, &id)) {
|
684
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
685
|
+
ASSERT(bson_iter_find_descendant(&iter, "v.0", &iter));
|
686
|
+
ASSERT(bson_iter_recurse(&iter, &b_iter));
|
687
|
+
}
|
688
|
+
|
689
|
+
/* Find second keyDocument. */
|
690
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
691
|
+
ASSERT(bson_iter_find_descendant(&iter, "v.1._id", &iter));
|
692
|
+
id = _find_key_id_from_iter(&iter);
|
693
|
+
if (_buffer_cmp_equal(&fields_a->id, &id)) {
|
694
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
695
|
+
ASSERT(bson_iter_find_descendant(&iter, "v.1", &iter));
|
696
|
+
ASSERT(bson_iter_recurse(&iter, &a_iter));
|
697
|
+
} else if (_buffer_cmp_equal(&fields_b->id, &id)) {
|
698
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
699
|
+
ASSERT(bson_iter_find_descendant(&iter, "v.1", &iter));
|
700
|
+
ASSERT(bson_iter_recurse(&iter, &b_iter));
|
701
|
+
}
|
702
|
+
|
703
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
704
|
+
ASSERT(iter.raw != a_iter.raw || iter.off != a_iter.off);
|
705
|
+
ASSERT(iter.raw != b_iter.raw || iter.off != b_iter.off);
|
706
|
+
}
|
707
|
+
|
708
|
+
/* Both keys should be rewrapped with new masterKey. */
|
709
|
+
iter = a_iter;
|
710
|
+
ASSERT(bson_iter_find_descendant(&iter, "masterKey.key", &iter));
|
711
|
+
ASSERT_STREQUAL(TEST_REWRAP_MASTER_KEY_ID_NEW, bson_iter_utf8(&iter, NULL));
|
712
|
+
iter = b_iter;
|
713
|
+
ASSERT(bson_iter_find_descendant(&iter, "masterKey.key", &iter));
|
714
|
+
ASSERT_STREQUAL(TEST_REWRAP_MASTER_KEY_ID_NEW, bson_iter_utf8(&iter, NULL));
|
715
|
+
|
716
|
+
/* Both keys should have new key material. */
|
717
|
+
{
|
718
|
+
_mongocrypt_buffer_t key_material_a;
|
719
|
+
_mongocrypt_buffer_t key_material_b;
|
720
|
+
|
721
|
+
iter = a_iter;
|
722
|
+
ASSERT(bson_iter_find_descendant(&iter, "keyMaterial", &iter));
|
723
|
+
key_material_a = _key_material_from_iter(&iter);
|
724
|
+
ASSERT(!_buffer_cmp_equal(&fields_a->key_material, &key_material_a));
|
725
|
+
|
726
|
+
iter = b_iter;
|
727
|
+
ASSERT(bson_iter_find_descendant(&iter, "keyMaterial", &iter));
|
728
|
+
key_material_b = _key_material_from_iter(&iter);
|
729
|
+
ASSERT(!_buffer_cmp_equal(&fields_b->key_material, &key_material_b));
|
730
|
+
|
731
|
+
/* Key materials should differ. */
|
732
|
+
ASSERT(!_buffer_cmp_equal(&key_material_a, &key_material_b));
|
733
|
+
}
|
734
|
+
|
735
|
+
bson_destroy(&bson);
|
736
|
+
}
|
737
|
+
|
738
|
+
/* No more work to be done for RewrapManyDatakey. */
|
739
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_DONE);
|
740
|
+
|
741
|
+
_test_datakey_fields_destroy(fields_b);
|
742
|
+
_test_datakey_fields_destroy(fields_a);
|
743
|
+
mongocrypt_ctx_destroy(ctx);
|
744
|
+
mongocrypt_destroy(crypt);
|
934
745
|
}
|
935
746
|
|
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
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
kms);
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
ASSERT_STREQUAL (TEST_REWRAP_MASTER_KEY_ID_OLD,
|
1020
|
-
bson_iter_utf8 (&iter, NULL));
|
1021
|
-
}
|
1022
|
-
|
1023
|
-
ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_DONE);
|
1024
|
-
|
1025
|
-
mongocrypt_ctx_destroy (ctx);
|
1026
|
-
mongocrypt_destroy (crypt);
|
1027
|
-
}
|
1028
|
-
|
1029
|
-
/* Should not enter NEED_KMS_CREDENTIALS state if credentials already
|
1030
|
-
* provided. */
|
1031
|
-
crypt = mongocrypt_new ();
|
1032
|
-
mongocrypt_setopt_use_need_kms_credentials_state (crypt);
|
1033
|
-
ASSERT_OK (mongocrypt_setopt_kms_providers (
|
1034
|
-
crypt,
|
1035
|
-
TEST_BSON ("{'aws': {"
|
1036
|
-
" 'accessKeyId': 'example',"
|
1037
|
-
" 'secretAccessKey': 'example'}}")),
|
747
|
+
static void _test_rewrap_many_datakey_kms_credentials(_mongocrypt_tester_t *tester) {
|
748
|
+
mongocrypt_t *crypt = NULL;
|
749
|
+
mongocrypt_ctx_t *ctx = NULL;
|
750
|
+
|
751
|
+
/* Ensure rewrapManyDataKey correctly handles need KMS credentials option. */
|
752
|
+
{
|
753
|
+
crypt = mongocrypt_new();
|
754
|
+
mongocrypt_setopt_use_need_kms_credentials_state(crypt);
|
755
|
+
ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'aws': {}}")), crypt);
|
756
|
+
ASSERT_OK(mongocrypt_init(crypt), crypt);
|
757
|
+
ctx = mongocrypt_ctx_new(crypt);
|
758
|
+
|
759
|
+
ASSERT_OK(ctx, crypt);
|
760
|
+
|
761
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, TEST_BSON("{}")), ctx);
|
762
|
+
|
763
|
+
/* NEED_KMS_CREDENTIALS comes before NEED_MONGO_KEYS. */
|
764
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
|
765
|
+
ASSERT_OK(mongocrypt_ctx_provide_kms_providers(ctx,
|
766
|
+
TEST_BSON("{'aws': {"
|
767
|
+
" 'accessKeyId': 'example',"
|
768
|
+
" 'secretAccessKey': 'example'}}")),
|
769
|
+
ctx);
|
770
|
+
|
771
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
772
|
+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
|
773
|
+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
|
774
|
+
|
775
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
776
|
+
{
|
777
|
+
mongocrypt_kms_ctx_t *kms = NULL;
|
778
|
+
|
779
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
780
|
+
_assert_aws_kms_request(kms);
|
781
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-a.txt")), kms);
|
782
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
783
|
+
|
784
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
785
|
+
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
|
786
|
+
}
|
787
|
+
|
788
|
+
/* KMS credentials provided before decryption should be reused here. */
|
789
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
|
790
|
+
{
|
791
|
+
mongocrypt_kms_ctx_t *kms = NULL;
|
792
|
+
|
793
|
+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
|
794
|
+
_assert_aws_kms_request(kms);
|
795
|
+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-encrypt-reply-a.txt")), kms);
|
796
|
+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
|
797
|
+
|
798
|
+
ASSERT_OK(!mongocrypt_ctx_next_kms_ctx(ctx), ctx);
|
799
|
+
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
|
800
|
+
}
|
801
|
+
|
802
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
|
803
|
+
|
804
|
+
{
|
805
|
+
mongocrypt_binary_t res;
|
806
|
+
bson_t bson;
|
807
|
+
bson_iter_t iter;
|
808
|
+
|
809
|
+
ASSERT_OK(mongocrypt_ctx_finalize(ctx, &res), ctx);
|
810
|
+
ASSERT(_mongocrypt_binary_to_bson(&res, &bson));
|
811
|
+
ASSERT(bson_iter_init(&iter, &bson));
|
812
|
+
ASSERT(bson_iter_find_descendant(&iter, "v.0.masterKey.key", &iter));
|
813
|
+
ASSERT_STREQUAL(TEST_REWRAP_MASTER_KEY_ID_OLD, bson_iter_utf8(&iter, NULL));
|
814
|
+
}
|
815
|
+
|
816
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_DONE);
|
817
|
+
|
818
|
+
mongocrypt_ctx_destroy(ctx);
|
819
|
+
mongocrypt_destroy(crypt);
|
820
|
+
}
|
821
|
+
|
822
|
+
/* Should not enter NEED_KMS_CREDENTIALS state if credentials already
|
823
|
+
* provided. */
|
824
|
+
crypt = mongocrypt_new();
|
825
|
+
mongocrypt_setopt_use_need_kms_credentials_state(crypt);
|
826
|
+
ASSERT_OK(mongocrypt_setopt_kms_providers(crypt,
|
827
|
+
TEST_BSON("{'aws': {"
|
828
|
+
" 'accessKeyId': 'example',"
|
829
|
+
" 'secretAccessKey': 'example'}}")),
|
1038
830
|
crypt);
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
mongocrypt_ctx_destroy (ctx);
|
1047
|
-
mongocrypt_destroy (crypt);
|
831
|
+
ASSERT_OK(mongocrypt_init(crypt), crypt);
|
832
|
+
ctx = mongocrypt_ctx_new(crypt);
|
833
|
+
ASSERT_OK(ctx, crypt);
|
834
|
+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, TEST_BSON("{}")), ctx);
|
835
|
+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
836
|
+
mongocrypt_ctx_destroy(ctx);
|
837
|
+
mongocrypt_destroy(crypt);
|
1048
838
|
}
|
1049
839
|
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
INSTALL_TEST (_test_rewrap_many_datakey_need_kms_decrypt);
|
1058
|
-
INSTALL_TEST (_test_rewrap_many_datakey_need_kms_encrypt);
|
1059
|
-
INSTALL_TEST (_test_rewrap_many_datakey_finalize);
|
1060
|
-
INSTALL_TEST (_test_rewrap_many_datakey_kms_credentials);
|
840
|
+
void _mongocrypt_tester_install_ctx_rewrap_many_datakey(_mongocrypt_tester_t *tester) {
|
841
|
+
INSTALL_TEST(_test_rewrap_many_datakey_init);
|
842
|
+
INSTALL_TEST(_test_rewrap_many_datakey_need_mongo_keys);
|
843
|
+
INSTALL_TEST(_test_rewrap_many_datakey_need_kms_decrypt);
|
844
|
+
INSTALL_TEST(_test_rewrap_many_datakey_need_kms_encrypt);
|
845
|
+
INSTALL_TEST(_test_rewrap_many_datakey_finalize);
|
846
|
+
INSTALL_TEST(_test_rewrap_many_datakey_kms_credentials);
|
1061
847
|
}
|