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
@@ -14,521 +14,474 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
#include "mongocrypt.h"
|
18
|
-
#include "mongocrypt-private.h"
|
19
|
-
#include "mongocrypt-ctx-private.h"
|
20
17
|
#include "mongocrypt-crypto-private.h"
|
18
|
+
#include "mongocrypt-ctx-private.h"
|
19
|
+
#include "mongocrypt-private.h"
|
20
|
+
#include "mongocrypt.h"
|
21
21
|
|
22
|
-
static void
|
23
|
-
|
24
|
-
{
|
25
|
-
_mongocrypt_ctx_datakey_t *dkctx;
|
22
|
+
static void _cleanup(mongocrypt_ctx_t *ctx) {
|
23
|
+
_mongocrypt_ctx_datakey_t *dkctx;
|
26
24
|
|
27
|
-
|
25
|
+
BSON_ASSERT_PARAM(ctx);
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
dkctx = (_mongocrypt_ctx_datakey_t *)ctx;
|
28
|
+
_mongocrypt_buffer_cleanup(&dkctx->key_doc);
|
29
|
+
_mongocrypt_kms_ctx_cleanup(&dkctx->kms);
|
30
|
+
_mongocrypt_buffer_cleanup(&dkctx->encrypted_key_material);
|
31
|
+
_mongocrypt_buffer_cleanup(&dkctx->plaintext_key_material);
|
32
|
+
_mongocrypt_buffer_cleanup(&dkctx->kmip_secretdata);
|
33
|
+
bson_free((void *)dkctx->kmip_unique_identifier);
|
36
34
|
}
|
37
35
|
|
38
|
-
static mongocrypt_kms_ctx_t *
|
39
|
-
|
40
|
-
{
|
41
|
-
_mongocrypt_ctx_datakey_t *dkctx;
|
36
|
+
static mongocrypt_kms_ctx_t *_next_kms_ctx(mongocrypt_ctx_t *ctx) {
|
37
|
+
_mongocrypt_ctx_datakey_t *dkctx;
|
42
38
|
|
43
|
-
|
39
|
+
BSON_ASSERT_PARAM(ctx);
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
dkctx = (_mongocrypt_ctx_datakey_t *)ctx;
|
42
|
+
if (dkctx->kms_returned) {
|
43
|
+
return NULL;
|
44
|
+
}
|
45
|
+
dkctx->kms_returned = true;
|
46
|
+
return &dkctx->kms;
|
51
47
|
}
|
52
48
|
|
53
|
-
static bool
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
ctx->state = MONGOCRYPT_CTX_NEED_KMS;
|
150
|
-
goto success;
|
151
|
-
}
|
152
|
-
|
153
|
-
/* Step 4. Use the 96 byte SecretData to encrypt a new DEK. */
|
154
|
-
if (!_mongocrypt_wrap_key (ctx->crypt->crypto,
|
49
|
+
static bool _kms_kmip_start(mongocrypt_ctx_t *ctx) {
|
50
|
+
bool ret = false;
|
51
|
+
_mongocrypt_ctx_datakey_t *dkctx = (_mongocrypt_ctx_datakey_t *)ctx;
|
52
|
+
char *user_supplied_keyid = NULL;
|
53
|
+
_mongocrypt_endpoint_t *endpoint = NULL;
|
54
|
+
mongocrypt_status_t *status = ctx->status;
|
55
|
+
_mongocrypt_buffer_t secretdata = {0};
|
56
|
+
|
57
|
+
BSON_ASSERT_PARAM(ctx);
|
58
|
+
|
59
|
+
if (ctx->opts.kek.kms_provider != MONGOCRYPT_KMS_PROVIDER_KMIP) {
|
60
|
+
CLIENT_ERR("KMS provider is not KMIP");
|
61
|
+
goto fail;
|
62
|
+
}
|
63
|
+
|
64
|
+
user_supplied_keyid = ctx->opts.kek.provider.kmip.key_id;
|
65
|
+
|
66
|
+
if (ctx->opts.kek.provider.kmip.endpoint) {
|
67
|
+
endpoint = ctx->opts.kek.provider.kmip.endpoint;
|
68
|
+
} else if (_mongocrypt_ctx_kms_providers(ctx)->kmip.endpoint) {
|
69
|
+
endpoint = _mongocrypt_ctx_kms_providers(ctx)->kmip.endpoint;
|
70
|
+
} else {
|
71
|
+
CLIENT_ERR("endpoint not set for KMIP request");
|
72
|
+
goto fail;
|
73
|
+
}
|
74
|
+
|
75
|
+
/* The KMIP createDataKey flow is the following:
|
76
|
+
*
|
77
|
+
* 1. Send a KMIP Register request with a new 96 byte key as a SecretData
|
78
|
+
* managed object. This returns a Unique Identifier.
|
79
|
+
* 2. Send a KMIP Activate request with the Unique Identifier.
|
80
|
+
* This returns the same Unique Identifier.
|
81
|
+
* 3. Send a KMIP Get request with the Unique Identifier.
|
82
|
+
* This returns the 96 byte SecretData.
|
83
|
+
* 4. Use the 96 byte SecretData to encrypt a new DEK.
|
84
|
+
*
|
85
|
+
* If the user set a 'keyId' to use, the flow begins at step 3.
|
86
|
+
*/
|
87
|
+
|
88
|
+
if (user_supplied_keyid && !dkctx->kmip_unique_identifier) {
|
89
|
+
/* User set a 'keyId'. */
|
90
|
+
dkctx->kmip_unique_identifier = bson_strdup(user_supplied_keyid);
|
91
|
+
dkctx->kmip_activated = true;
|
92
|
+
/* Fall through to Step 3. */
|
93
|
+
}
|
94
|
+
|
95
|
+
if (!dkctx->kmip_unique_identifier) {
|
96
|
+
/* User did not set a 'keyId'. */
|
97
|
+
/* Step 1. Send a KMIP Register request with a new 96 byte SecretData. */
|
98
|
+
_mongocrypt_buffer_init(&secretdata);
|
99
|
+
_mongocrypt_buffer_resize(&secretdata, MONGOCRYPT_KEY_LEN);
|
100
|
+
if (!_mongocrypt_random(ctx->crypt->crypto, &secretdata, MONGOCRYPT_KEY_LEN, ctx->status)) {
|
101
|
+
goto fail;
|
102
|
+
}
|
103
|
+
|
104
|
+
if (!_mongocrypt_kms_ctx_init_kmip_register(&dkctx->kms,
|
105
|
+
endpoint,
|
106
|
+
secretdata.data,
|
107
|
+
secretdata.len,
|
108
|
+
&ctx->crypt->log)) {
|
109
|
+
mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status);
|
110
|
+
goto fail;
|
111
|
+
}
|
112
|
+
ctx->state = MONGOCRYPT_CTX_NEED_KMS;
|
113
|
+
|
114
|
+
goto success;
|
115
|
+
}
|
116
|
+
|
117
|
+
if (!dkctx->kmip_activated) {
|
118
|
+
/* Step 2. Send a KMIP Activate request. */
|
119
|
+
if (!_mongocrypt_kms_ctx_init_kmip_activate(&dkctx->kms,
|
120
|
+
endpoint,
|
121
|
+
dkctx->kmip_unique_identifier,
|
122
|
+
&ctx->crypt->log)) {
|
123
|
+
mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status);
|
124
|
+
goto fail;
|
125
|
+
}
|
126
|
+
ctx->state = MONGOCRYPT_CTX_NEED_KMS;
|
127
|
+
goto success;
|
128
|
+
}
|
129
|
+
|
130
|
+
if (!dkctx->kmip_secretdata.data) {
|
131
|
+
/* Step 3. Send a KMIP Get request with the Unique Identifier. */
|
132
|
+
if (!_mongocrypt_kms_ctx_init_kmip_get(&dkctx->kms,
|
133
|
+
endpoint,
|
134
|
+
dkctx->kmip_unique_identifier,
|
135
|
+
&ctx->crypt->log)) {
|
136
|
+
mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status);
|
137
|
+
goto fail;
|
138
|
+
}
|
139
|
+
ctx->state = MONGOCRYPT_CTX_NEED_KMS;
|
140
|
+
goto success;
|
141
|
+
}
|
142
|
+
|
143
|
+
/* Step 4. Use the 96 byte SecretData to encrypt a new DEK. */
|
144
|
+
if (!_mongocrypt_wrap_key(ctx->crypt->crypto,
|
155
145
|
&dkctx->kmip_secretdata,
|
156
146
|
&dkctx->plaintext_key_material,
|
157
147
|
&dkctx->encrypted_key_material,
|
158
148
|
ctx->status)) {
|
159
|
-
|
160
|
-
|
149
|
+
goto fail;
|
150
|
+
}
|
161
151
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
ctx->state = MONGOCRYPT_CTX_READY;
|
152
|
+
if (!ctx->opts.kek.provider.kmip.key_id) {
|
153
|
+
/* If there was no user supplied key_id, set it from the
|
154
|
+
* UniqueIdentifer of the newly registered SecretData. */
|
155
|
+
ctx->opts.kek.provider.kmip.key_id = bson_strdup(dkctx->kmip_unique_identifier);
|
156
|
+
}
|
157
|
+
ctx->state = MONGOCRYPT_CTX_READY;
|
169
158
|
|
170
159
|
success:
|
171
|
-
|
160
|
+
ret = true;
|
172
161
|
fail:
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
162
|
+
if (!ret) {
|
163
|
+
_mongocrypt_ctx_fail(ctx);
|
164
|
+
}
|
165
|
+
_mongocrypt_buffer_cleanup(&secretdata);
|
166
|
+
return ret;
|
178
167
|
}
|
179
168
|
|
180
169
|
/* For local, immediately encrypt.
|
181
170
|
* For AWS, create the KMS request to encrypt.
|
182
171
|
* For Azure/GCP, auth first if needed, otherwise encrypt.
|
183
172
|
*/
|
184
|
-
static bool
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
&dkctx->encrypted_key_material,
|
207
|
-
ctx->status)) {
|
208
|
-
_mongocrypt_ctx_fail (ctx);
|
209
|
-
goto done;
|
210
|
-
}
|
211
|
-
ctx->state = MONGOCRYPT_CTX_READY;
|
212
|
-
} else if (ctx->opts.kek.kms_provider == MONGOCRYPT_KMS_PROVIDER_AWS) {
|
213
|
-
/* For AWS provider, AWS credentials are supplied in
|
214
|
-
* mongocrypt_setopt_kms_provider_aws. Data keys are encrypted with an
|
215
|
-
* "encrypt" HTTP message to KMS. */
|
216
|
-
if (!_mongocrypt_kms_ctx_init_aws_encrypt (&dkctx->kms,
|
217
|
-
kms_providers,
|
218
|
-
&ctx->opts,
|
219
|
-
&dkctx->plaintext_key_material,
|
220
|
-
&ctx->crypt->log,
|
221
|
-
ctx->crypt->crypto)) {
|
222
|
-
mongocrypt_kms_ctx_status (&dkctx->kms, ctx->status);
|
223
|
-
_mongocrypt_ctx_fail (ctx);
|
224
|
-
goto done;
|
225
|
-
}
|
226
|
-
|
227
|
-
ctx->state = MONGOCRYPT_CTX_NEED_KMS;
|
228
|
-
} else if (ctx->opts.kek.kms_provider == MONGOCRYPT_KMS_PROVIDER_AZURE) {
|
229
|
-
if (ctx->kms_providers.azure.access_token) {
|
230
|
-
access_token = bson_strdup (ctx->kms_providers.azure.access_token);
|
231
|
-
} else {
|
232
|
-
access_token =
|
233
|
-
_mongocrypt_cache_oauth_get (ctx->crypt->cache_oauth_azure);
|
234
|
-
}
|
235
|
-
if (access_token) {
|
236
|
-
if (!_mongocrypt_kms_ctx_init_azure_wrapkey (
|
237
|
-
&dkctx->kms,
|
238
|
-
&ctx->crypt->log,
|
239
|
-
kms_providers,
|
240
|
-
&ctx->opts,
|
241
|
-
access_token,
|
242
|
-
&dkctx->plaintext_key_material)) {
|
243
|
-
mongocrypt_kms_ctx_status (&dkctx->kms, ctx->status);
|
244
|
-
_mongocrypt_ctx_fail (ctx);
|
173
|
+
static bool _kms_start(mongocrypt_ctx_t *ctx) {
|
174
|
+
BSON_ASSERT_PARAM(ctx);
|
175
|
+
|
176
|
+
bool ret = false;
|
177
|
+
_mongocrypt_ctx_datakey_t *dkctx;
|
178
|
+
char *access_token = NULL;
|
179
|
+
_mongocrypt_opts_kms_providers_t *const kms_providers = _mongocrypt_ctx_kms_providers(ctx);
|
180
|
+
|
181
|
+
dkctx = (_mongocrypt_ctx_datakey_t *)ctx;
|
182
|
+
|
183
|
+
/* Clear out any pre-existing initialized KMS context, and zero it (so it is
|
184
|
+
* safe to call cleanup again). */
|
185
|
+
_mongocrypt_kms_ctx_cleanup(&dkctx->kms);
|
186
|
+
memset(&dkctx->kms, 0, sizeof(dkctx->kms));
|
187
|
+
dkctx->kms_returned = false;
|
188
|
+
if (ctx->opts.kek.kms_provider == MONGOCRYPT_KMS_PROVIDER_LOCAL) {
|
189
|
+
if (!_mongocrypt_wrap_key(ctx->crypt->crypto,
|
190
|
+
&kms_providers->local.key,
|
191
|
+
&dkctx->plaintext_key_material,
|
192
|
+
&dkctx->encrypted_key_material,
|
193
|
+
ctx->status)) {
|
194
|
+
_mongocrypt_ctx_fail(ctx);
|
245
195
|
goto done;
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
196
|
+
}
|
197
|
+
ctx->state = MONGOCRYPT_CTX_READY;
|
198
|
+
} else if (ctx->opts.kek.kms_provider == MONGOCRYPT_KMS_PROVIDER_AWS) {
|
199
|
+
/* For AWS provider, AWS credentials are supplied in
|
200
|
+
* mongocrypt_setopt_kms_provider_aws. Data keys are encrypted with an
|
201
|
+
* "encrypt" HTTP message to KMS. */
|
202
|
+
if (!_mongocrypt_kms_ctx_init_aws_encrypt(&dkctx->kms,
|
203
|
+
kms_providers,
|
204
|
+
&ctx->opts,
|
205
|
+
&dkctx->plaintext_key_material,
|
206
|
+
&ctx->crypt->log,
|
207
|
+
ctx->crypt->crypto)) {
|
208
|
+
mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status);
|
209
|
+
_mongocrypt_ctx_fail(ctx);
|
255
210
|
goto done;
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
&ctx->
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
211
|
+
}
|
212
|
+
|
213
|
+
ctx->state = MONGOCRYPT_CTX_NEED_KMS;
|
214
|
+
} else if (ctx->opts.kek.kms_provider == MONGOCRYPT_KMS_PROVIDER_AZURE) {
|
215
|
+
if (ctx->kms_providers.azure.access_token) {
|
216
|
+
access_token = bson_strdup(ctx->kms_providers.azure.access_token);
|
217
|
+
} else {
|
218
|
+
access_token = _mongocrypt_cache_oauth_get(ctx->crypt->cache_oauth_azure);
|
219
|
+
}
|
220
|
+
if (access_token) {
|
221
|
+
if (!_mongocrypt_kms_ctx_init_azure_wrapkey(&dkctx->kms,
|
222
|
+
&ctx->crypt->log,
|
223
|
+
kms_providers,
|
224
|
+
&ctx->opts,
|
225
|
+
access_token,
|
226
|
+
&dkctx->plaintext_key_material)) {
|
227
|
+
mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status);
|
228
|
+
_mongocrypt_ctx_fail(ctx);
|
229
|
+
goto done;
|
230
|
+
}
|
231
|
+
} else {
|
232
|
+
if (!_mongocrypt_kms_ctx_init_azure_auth(&dkctx->kms,
|
233
|
+
&ctx->crypt->log,
|
234
|
+
kms_providers,
|
235
|
+
ctx->opts.kek.provider.azure.key_vault_endpoint)) {
|
236
|
+
mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status);
|
237
|
+
_mongocrypt_ctx_fail(ctx);
|
238
|
+
goto done;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
ctx->state = MONGOCRYPT_CTX_NEED_KMS;
|
242
|
+
} else if (ctx->opts.kek.kms_provider == MONGOCRYPT_KMS_PROVIDER_GCP) {
|
243
|
+
if (NULL != ctx->kms_providers.gcp.access_token) {
|
244
|
+
access_token = bson_strdup((const char *)ctx->kms_providers.gcp.access_token);
|
245
|
+
} else {
|
246
|
+
access_token = _mongocrypt_cache_oauth_get(ctx->crypt->cache_oauth_gcp);
|
247
|
+
}
|
248
|
+
if (access_token) {
|
249
|
+
if (!_mongocrypt_kms_ctx_init_gcp_encrypt(&dkctx->kms,
|
250
|
+
&ctx->crypt->log,
|
251
|
+
kms_providers,
|
252
|
+
&ctx->opts,
|
253
|
+
access_token,
|
254
|
+
&dkctx->plaintext_key_material)) {
|
255
|
+
mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status);
|
256
|
+
_mongocrypt_ctx_fail(ctx);
|
257
|
+
goto done;
|
258
|
+
}
|
259
|
+
} else {
|
260
|
+
if (!_mongocrypt_kms_ctx_init_gcp_auth(&dkctx->kms,
|
261
|
+
&ctx->crypt->log,
|
262
|
+
&ctx->crypt->opts,
|
263
|
+
kms_providers,
|
264
|
+
ctx->opts.kek.provider.gcp.endpoint)) {
|
265
|
+
mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status);
|
266
|
+
_mongocrypt_ctx_fail(ctx);
|
267
|
+
goto done;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
ctx->state = MONGOCRYPT_CTX_NEED_KMS;
|
271
|
+
} else if (ctx->opts.kek.kms_provider == MONGOCRYPT_KMS_PROVIDER_KMIP) {
|
272
|
+
if (!_kms_kmip_start(ctx)) {
|
277
273
|
goto done;
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
ctx->opts.kek.provider.gcp.endpoint)) {
|
286
|
-
mongocrypt_kms_ctx_status (&dkctx->kms, ctx->status);
|
287
|
-
_mongocrypt_ctx_fail (ctx);
|
288
|
-
goto done;
|
289
|
-
}
|
290
|
-
}
|
291
|
-
ctx->state = MONGOCRYPT_CTX_NEED_KMS;
|
292
|
-
} else if (ctx->opts.kek.kms_provider == MONGOCRYPT_KMS_PROVIDER_KMIP) {
|
293
|
-
if (!_kms_kmip_start (ctx)) {
|
294
|
-
goto done;
|
295
|
-
}
|
296
|
-
} else {
|
297
|
-
_mongocrypt_ctx_fail_w_msg (ctx, "unsupported KMS provider");
|
298
|
-
goto done;
|
299
|
-
}
|
300
|
-
|
301
|
-
ret = true;
|
274
|
+
}
|
275
|
+
} else {
|
276
|
+
_mongocrypt_ctx_fail_w_msg(ctx, "unsupported KMS provider");
|
277
|
+
goto done;
|
278
|
+
}
|
279
|
+
|
280
|
+
ret = true;
|
302
281
|
done:
|
303
|
-
|
304
|
-
|
282
|
+
bson_free(access_token);
|
283
|
+
return ret;
|
305
284
|
}
|
306
285
|
|
307
|
-
static bool
|
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
|
-
/* The encrypted key material must be at least as large as the plaintext. */
|
367
|
-
if (dkctx->encrypted_key_material.len < MONGOCRYPT_KEY_LEN) {
|
368
|
-
return _mongocrypt_ctx_fail_w_msg (ctx,
|
369
|
-
"key material not expected length");
|
370
|
-
}
|
371
|
-
|
372
|
-
ctx->state = MONGOCRYPT_CTX_READY;
|
373
|
-
return true;
|
286
|
+
static bool _kms_done(mongocrypt_ctx_t *ctx) {
|
287
|
+
_mongocrypt_ctx_datakey_t *dkctx;
|
288
|
+
mongocrypt_status_t *status;
|
289
|
+
|
290
|
+
BSON_ASSERT_PARAM(ctx);
|
291
|
+
|
292
|
+
dkctx = (_mongocrypt_ctx_datakey_t *)ctx;
|
293
|
+
status = ctx->status;
|
294
|
+
if (!mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status)) {
|
295
|
+
return _mongocrypt_ctx_fail(ctx);
|
296
|
+
}
|
297
|
+
|
298
|
+
if (mongocrypt_kms_ctx_bytes_needed(&dkctx->kms) != 0) {
|
299
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "KMS response unfinished");
|
300
|
+
}
|
301
|
+
|
302
|
+
/* If this was an oauth request, store the response and proceed to encrypt.
|
303
|
+
*/
|
304
|
+
if (dkctx->kms.req_type == MONGOCRYPT_KMS_AZURE_OAUTH) {
|
305
|
+
bson_t oauth_response;
|
306
|
+
|
307
|
+
BSON_ASSERT(_mongocrypt_buffer_to_bson(&dkctx->kms.result, &oauth_response));
|
308
|
+
if (!_mongocrypt_cache_oauth_add(ctx->crypt->cache_oauth_azure, &oauth_response, status)) {
|
309
|
+
return _mongocrypt_ctx_fail(ctx);
|
310
|
+
}
|
311
|
+
return _kms_start(ctx);
|
312
|
+
} else if (dkctx->kms.req_type == MONGOCRYPT_KMS_GCP_OAUTH) {
|
313
|
+
bson_t oauth_response;
|
314
|
+
|
315
|
+
BSON_ASSERT(_mongocrypt_buffer_to_bson(&dkctx->kms.result, &oauth_response));
|
316
|
+
if (!_mongocrypt_cache_oauth_add(ctx->crypt->cache_oauth_gcp, &oauth_response, status)) {
|
317
|
+
return _mongocrypt_ctx_fail(ctx);
|
318
|
+
}
|
319
|
+
return _kms_start(ctx);
|
320
|
+
} else if (dkctx->kms.req_type == MONGOCRYPT_KMS_KMIP_REGISTER) {
|
321
|
+
dkctx->kmip_unique_identifier = bson_strdup((const char *)dkctx->kms.result.data);
|
322
|
+
return _kms_start(ctx);
|
323
|
+
} else if (dkctx->kms.req_type == MONGOCRYPT_KMS_KMIP_ACTIVATE) {
|
324
|
+
dkctx->kmip_activated = true;
|
325
|
+
return _kms_start(ctx);
|
326
|
+
} else if (dkctx->kms.req_type == MONGOCRYPT_KMS_KMIP_GET) {
|
327
|
+
_mongocrypt_buffer_copy_to(&dkctx->kms.result, &dkctx->kmip_secretdata);
|
328
|
+
return _kms_start(ctx);
|
329
|
+
}
|
330
|
+
|
331
|
+
/* Store the result. */
|
332
|
+
if (!_mongocrypt_kms_ctx_result(&dkctx->kms, &dkctx->encrypted_key_material)) {
|
333
|
+
BSON_ASSERT(!mongocrypt_kms_ctx_status(&dkctx->kms, ctx->status));
|
334
|
+
return _mongocrypt_ctx_fail(ctx);
|
335
|
+
}
|
336
|
+
|
337
|
+
/* The encrypted key material must be at least as large as the plaintext. */
|
338
|
+
if (dkctx->encrypted_key_material.len < MONGOCRYPT_KEY_LEN) {
|
339
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "key material not expected length");
|
340
|
+
}
|
341
|
+
|
342
|
+
ctx->state = MONGOCRYPT_CTX_READY;
|
343
|
+
return true;
|
374
344
|
}
|
375
345
|
|
376
346
|
/* Append a UUID _id. Confer with libmongoc's `_mongoc_server_session_uuid`. */
|
377
|
-
static bool
|
378
|
-
|
379
|
-
{
|
380
|
-
_mongocrypt_buffer_t uuid;
|
347
|
+
static bool _append_id(mongocrypt_t *crypt, bson_t *bson, mongocrypt_status_t *status) {
|
348
|
+
_mongocrypt_buffer_t uuid;
|
381
349
|
|
382
|
-
|
383
|
-
|
350
|
+
BSON_ASSERT_PARAM(crypt);
|
351
|
+
BSON_ASSERT_PARAM(bson);
|
384
352
|
|
385
|
-
|
386
|
-
|
387
|
-
|
353
|
+
_mongocrypt_buffer_init(&uuid);
|
354
|
+
uuid.data = bson_malloc(UUID_LEN);
|
355
|
+
BSON_ASSERT(uuid.data);
|
388
356
|
|
389
|
-
|
390
|
-
|
391
|
-
|
357
|
+
uuid.len = UUID_LEN;
|
358
|
+
uuid.subtype = BSON_SUBTYPE_UUID;
|
359
|
+
uuid.owned = true;
|
392
360
|
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
361
|
+
if (!_mongocrypt_random(crypt->crypto, &uuid, UUID_LEN, status)) {
|
362
|
+
_mongocrypt_buffer_cleanup(&uuid);
|
363
|
+
return false;
|
364
|
+
}
|
397
365
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
366
|
+
uuid.data[6] = (uint8_t)(0x40 | (uuid.data[6] & 0xf));
|
367
|
+
uuid.data[8] = (uint8_t)(0x80 | (uuid.data[8] & 0x3f));
|
368
|
+
if (!_mongocrypt_buffer_append(&uuid, bson, "_id", 3)) {
|
369
|
+
_mongocrypt_buffer_cleanup(&uuid);
|
370
|
+
return false;
|
371
|
+
}
|
404
372
|
|
405
|
-
|
373
|
+
_mongocrypt_buffer_cleanup(&uuid);
|
406
374
|
|
407
|
-
|
375
|
+
return true;
|
408
376
|
}
|
409
377
|
|
410
|
-
static bool
|
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
|
-
bson_destroy (&key_doc);
|
463
|
-
return _mongocrypt_ctx_fail (ctx);
|
464
|
-
}
|
465
|
-
BSON_CHECK (bson_append_document_end (&key_doc, &child));
|
466
|
-
_mongocrypt_buffer_steal_from_bson (&dkctx->key_doc, &key_doc);
|
467
|
-
_mongocrypt_buffer_to_binary (&dkctx->key_doc, out);
|
468
|
-
ctx->state = MONGOCRYPT_CTX_DONE;
|
469
|
-
return true;
|
378
|
+
static bool _finalize(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out) {
|
379
|
+
_mongocrypt_ctx_datakey_t *dkctx;
|
380
|
+
bson_t key_doc, child;
|
381
|
+
struct timeval tp;
|
382
|
+
|
383
|
+
BSON_ASSERT_PARAM(ctx);
|
384
|
+
BSON_ASSERT_PARAM(out);
|
385
|
+
|
386
|
+
#define BSON_CHECK(_stmt) \
|
387
|
+
if (!(_stmt)) { \
|
388
|
+
bson_destroy(&key_doc); \
|
389
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "unable to construct BSON doc"); \
|
390
|
+
}
|
391
|
+
|
392
|
+
dkctx = (_mongocrypt_ctx_datakey_t *)ctx;
|
393
|
+
|
394
|
+
bson_init(&key_doc);
|
395
|
+
if (!_append_id(ctx->crypt, &key_doc, ctx->status)) {
|
396
|
+
return _mongocrypt_ctx_fail(ctx);
|
397
|
+
}
|
398
|
+
|
399
|
+
if (ctx->opts.key_alt_names) {
|
400
|
+
_mongocrypt_key_alt_name_t *alt_name = ctx->opts.key_alt_names;
|
401
|
+
int i;
|
402
|
+
|
403
|
+
bson_append_array_begin(&key_doc, "keyAltNames", -1, &child);
|
404
|
+
for (i = 0; alt_name; i++) {
|
405
|
+
char *key = bson_strdup_printf("%d", i);
|
406
|
+
bson_append_value(&child, key, -1, &alt_name->value);
|
407
|
+
bson_free(key);
|
408
|
+
alt_name = alt_name->next;
|
409
|
+
}
|
410
|
+
bson_append_array_end(&key_doc, &child);
|
411
|
+
}
|
412
|
+
if (!_mongocrypt_buffer_append(&dkctx->encrypted_key_material, &key_doc, MONGOCRYPT_STR_AND_LEN("keyMaterial"))) {
|
413
|
+
bson_destroy(&key_doc);
|
414
|
+
return _mongocrypt_ctx_fail_w_msg(ctx, "could not append keyMaterial");
|
415
|
+
}
|
416
|
+
bson_gettimeofday(&tp);
|
417
|
+
BSON_CHECK(bson_append_timeval(&key_doc, MONGOCRYPT_STR_AND_LEN("creationDate"), &tp));
|
418
|
+
BSON_CHECK(bson_append_timeval(&key_doc, MONGOCRYPT_STR_AND_LEN("updateDate"), &tp));
|
419
|
+
BSON_CHECK(bson_append_int32(&key_doc, MONGOCRYPT_STR_AND_LEN("status"), 0)); /* 0 = enabled. */
|
420
|
+
BSON_CHECK(bson_append_document_begin(&key_doc, MONGOCRYPT_STR_AND_LEN("masterKey"), &child));
|
421
|
+
if (!_mongocrypt_kek_append(&ctx->opts.kek, &child, ctx->status)) {
|
422
|
+
bson_destroy(&key_doc);
|
423
|
+
return _mongocrypt_ctx_fail(ctx);
|
424
|
+
}
|
425
|
+
BSON_CHECK(bson_append_document_end(&key_doc, &child));
|
426
|
+
_mongocrypt_buffer_steal_from_bson(&dkctx->key_doc, &key_doc);
|
427
|
+
_mongocrypt_buffer_to_binary(&dkctx->key_doc, out);
|
428
|
+
ctx->state = MONGOCRYPT_CTX_DONE;
|
429
|
+
return true;
|
470
430
|
}
|
471
431
|
|
472
|
-
bool
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
ctx->crypt, ctx->opts.kek.kms_provider)) {
|
526
|
-
ctx->state = MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS;
|
527
|
-
} else if (!_kms_start (ctx)) {
|
528
|
-
goto done;
|
529
|
-
}
|
530
|
-
|
531
|
-
ret = true;
|
432
|
+
bool mongocrypt_ctx_datakey_init(mongocrypt_ctx_t *ctx) {
|
433
|
+
_mongocrypt_ctx_datakey_t *dkctx;
|
434
|
+
_mongocrypt_ctx_opts_spec_t opts_spec;
|
435
|
+
bool ret;
|
436
|
+
|
437
|
+
if (!ctx) {
|
438
|
+
return false;
|
439
|
+
}
|
440
|
+
ret = false;
|
441
|
+
memset(&opts_spec, 0, sizeof(opts_spec));
|
442
|
+
opts_spec.kek = OPT_REQUIRED;
|
443
|
+
opts_spec.key_alt_names = OPT_OPTIONAL;
|
444
|
+
opts_spec.key_material = OPT_OPTIONAL;
|
445
|
+
|
446
|
+
if (!_mongocrypt_ctx_init(ctx, &opts_spec)) {
|
447
|
+
return false;
|
448
|
+
}
|
449
|
+
|
450
|
+
dkctx = (_mongocrypt_ctx_datakey_t *)ctx;
|
451
|
+
ctx->type = _MONGOCRYPT_TYPE_CREATE_DATA_KEY;
|
452
|
+
ctx->vtable.mongo_op_keys = NULL;
|
453
|
+
ctx->vtable.mongo_feed_keys = NULL;
|
454
|
+
ctx->vtable.mongo_done_keys = NULL;
|
455
|
+
ctx->vtable.next_kms_ctx = _next_kms_ctx;
|
456
|
+
ctx->vtable.after_kms_credentials_provided = _kms_start;
|
457
|
+
ctx->vtable.kms_done = _kms_done;
|
458
|
+
ctx->vtable.finalize = _finalize;
|
459
|
+
ctx->vtable.cleanup = _cleanup;
|
460
|
+
|
461
|
+
_mongocrypt_buffer_init(&dkctx->plaintext_key_material);
|
462
|
+
|
463
|
+
if (ctx->opts.key_material.owned) {
|
464
|
+
/* Use keyMaterial provided by user via DataKeyOpts. */
|
465
|
+
_mongocrypt_buffer_steal(&dkctx->plaintext_key_material, &ctx->opts.key_material);
|
466
|
+
} else {
|
467
|
+
/* Generate keyMaterial instead. */
|
468
|
+
dkctx->plaintext_key_material.data = bson_malloc(MONGOCRYPT_KEY_LEN);
|
469
|
+
BSON_ASSERT(dkctx->plaintext_key_material.data);
|
470
|
+
dkctx->plaintext_key_material.len = MONGOCRYPT_KEY_LEN;
|
471
|
+
dkctx->plaintext_key_material.owned = true;
|
472
|
+
if (!_mongocrypt_random(ctx->crypt->crypto, &dkctx->plaintext_key_material, MONGOCRYPT_KEY_LEN, ctx->status)) {
|
473
|
+
_mongocrypt_ctx_fail(ctx);
|
474
|
+
goto done;
|
475
|
+
}
|
476
|
+
}
|
477
|
+
|
478
|
+
if (_mongocrypt_needs_credentials_for_provider(ctx->crypt, ctx->opts.kek.kms_provider)) {
|
479
|
+
ctx->state = MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS;
|
480
|
+
} else if (!_kms_start(ctx)) {
|
481
|
+
goto done;
|
482
|
+
}
|
483
|
+
|
484
|
+
ret = true;
|
532
485
|
done:
|
533
|
-
|
486
|
+
return ret;
|
534
487
|
}
|