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
@@ -15,903 +15,759 @@
|
|
15
15
|
*/
|
16
16
|
|
17
17
|
#include "mongocrypt-config.h"
|
18
|
-
#include "mongocrypt-private.h"
|
19
18
|
#include "mongocrypt-crypto-private.h"
|
19
|
+
#include "mongocrypt-private.h"
|
20
20
|
|
21
21
|
#include "test-mongocrypt.h"
|
22
22
|
|
23
23
|
#define IV_HEX "1F572A1B84EC8F99B7915AA2A2AEA2F4"
|
24
|
-
#define HMAC_HEX
|
25
|
-
|
26
|
-
|
24
|
+
#define HMAC_HEX \
|
25
|
+
"60676DE9FD305FD2C0815763C422687270DA2416D94A917B276E9DCBB13F412F" \
|
26
|
+
"92FA403AA8AE172BD2E4729ED352793795EE588A2977C9C1F218D2AAD779C997"
|
27
27
|
/* only the first 32 bytes are appended. */
|
28
|
-
#define HMAC_HEX_TAG
|
29
|
-
|
30
|
-
|
31
|
-
#define
|
32
|
-
|
33
|
-
#define ENCRYPTION_KEY_HEX \
|
34
|
-
"E1D1727BAF970E01181C0868CB9D3E574B47AC09771FF30FE2D093B0950C7DAF"
|
35
|
-
#define IV_KEY_HEX \
|
36
|
-
"0A9328FCB6405ABDF5B4BFEC243FE9CF503CD4F24360872B75F08A2A3961802B"
|
28
|
+
#define HMAC_HEX_TAG "60676DE9FD305FD2C0815763C422687270DA2416D94A917B276E9DCBB13F412F"
|
29
|
+
|
30
|
+
#define HMAC_KEY_HEX "CCD3836C8F24AC5FAAFAAA630C5C6C5D210FD03934EA1440CD67E0DCDE3F8EA6"
|
31
|
+
#define ENCRYPTION_KEY_HEX "E1D1727BAF970E01181C0868CB9D3E574B47AC09771FF30FE2D093B0950C7DAF"
|
32
|
+
#define IV_KEY_HEX "0A9328FCB6405ABDF5B4BFEC243FE9CF503CD4F24360872B75F08A2A3961802B"
|
37
33
|
/* full 96 byte key consists of three "sub" keys */
|
38
34
|
#define KEY_HEX HMAC_KEY_HEX ENCRYPTION_KEY_HEX IV_KEY_HEX
|
39
|
-
#define HASH_HEX
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
"CC0B95D217493205A038C50F537F452C59EFF6541D0026"
|
35
|
+
#define HASH_HEX "489EC3238378DC624C74B8CC4598ACED2B7EA5DE5C5F7602D8761BAE92FD8ABE"
|
36
|
+
#define RANDOM_HEX \
|
37
|
+
"670ACBB44D4E04A279CC0B95D217493205A038C50F537F452C59EFF6541D0026670ACBB44" \
|
38
|
+
"D4E04A279CC0B95D217493205A038C50F537F452C59EFF6541D0026670ACBB44D4E04A279" \
|
39
|
+
"CC0B95D217493205A038C50F537F452C59EFF6541D0026"
|
45
40
|
|
46
41
|
/* a document containing the history of calls */
|
47
42
|
static bson_string_t *call_history;
|
48
43
|
|
49
|
-
static void
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
bson_free (hex);
|
59
|
-
_mongocrypt_buffer_cleanup (&tmp);
|
44
|
+
static void _append_bin(const char *name, mongocrypt_binary_t *bin) {
|
45
|
+
_mongocrypt_buffer_t tmp;
|
46
|
+
char *hex;
|
47
|
+
|
48
|
+
_mongocrypt_buffer_from_binary(&tmp, bin);
|
49
|
+
hex = _mongocrypt_buffer_to_hex(&tmp);
|
50
|
+
bson_string_append_printf(call_history, "%s:%s\n", name, hex);
|
51
|
+
bson_free(hex);
|
52
|
+
_mongocrypt_buffer_cleanup(&tmp);
|
60
53
|
}
|
61
54
|
|
62
|
-
static bool
|
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
|
-
return false;
|
88
|
-
}
|
89
|
-
return true;
|
55
|
+
static bool _mock_aes_256_xxx_encrypt(void *ctx,
|
56
|
+
mongocrypt_binary_t *key,
|
57
|
+
mongocrypt_binary_t *iv,
|
58
|
+
mongocrypt_binary_t *in,
|
59
|
+
mongocrypt_binary_t *out,
|
60
|
+
uint32_t *bytes_written,
|
61
|
+
mongocrypt_status_t *status) {
|
62
|
+
BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
|
63
|
+
bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
|
64
|
+
_append_bin("key", key);
|
65
|
+
if (NULL != iv) {
|
66
|
+
_append_bin("iv", iv);
|
67
|
+
}
|
68
|
+
_append_bin("in", in);
|
69
|
+
/* append it directly, don't encrypt. */
|
70
|
+
memcpy(out->data + *bytes_written, in->data, in->len);
|
71
|
+
*bytes_written += in->len;
|
72
|
+
bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
|
73
|
+
if (0 == strcmp((char *)ctx, "error_on:aes_256_cbc_encrypt")
|
74
|
+
|| 0 == strcmp((char *)ctx, "error_on:aes_256_ctr_encrypt")
|
75
|
+
|| 0 == strcmp((char *)ctx, "error_on:aes_256_ecb_encrypt")) {
|
76
|
+
mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
|
77
|
+
return false;
|
78
|
+
}
|
79
|
+
return true;
|
90
80
|
}
|
91
81
|
|
92
|
-
static bool
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
return false;
|
115
|
-
}
|
116
|
-
return true;
|
82
|
+
static bool _mock_aes_256_xxx_decrypt(void *ctx,
|
83
|
+
mongocrypt_binary_t *key,
|
84
|
+
mongocrypt_binary_t *iv,
|
85
|
+
mongocrypt_binary_t *in,
|
86
|
+
mongocrypt_binary_t *out,
|
87
|
+
uint32_t *bytes_written,
|
88
|
+
mongocrypt_status_t *status) {
|
89
|
+
BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
|
90
|
+
bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
|
91
|
+
_append_bin("key", key);
|
92
|
+
_append_bin("iv", iv);
|
93
|
+
_append_bin("in", in);
|
94
|
+
/* append it directly, don't decrypt. */
|
95
|
+
memcpy(out->data + *bytes_written, in->data, in->len);
|
96
|
+
*bytes_written += in->len;
|
97
|
+
bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
|
98
|
+
if (0 == strcmp((char *)ctx, "error_on:aes_256_cbc_decrypt")
|
99
|
+
|| 0 == strcmp((char *)ctx, "error_on:aes_256_ctr_decrypt")) {
|
100
|
+
mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
return true;
|
117
104
|
}
|
118
105
|
|
119
|
-
bool
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
return false;
|
142
|
-
}
|
143
|
-
return true;
|
106
|
+
bool _hmac_sha_512(void *ctx,
|
107
|
+
mongocrypt_binary_t *key,
|
108
|
+
mongocrypt_binary_t *in,
|
109
|
+
mongocrypt_binary_t *out,
|
110
|
+
mongocrypt_status_t *status) {
|
111
|
+
_mongocrypt_buffer_t tmp;
|
112
|
+
|
113
|
+
BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
|
114
|
+
bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
|
115
|
+
_append_bin("key", key);
|
116
|
+
_append_bin("in", in);
|
117
|
+
|
118
|
+
bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
|
119
|
+
|
120
|
+
_mongocrypt_buffer_copy_from_hex(&tmp, HMAC_HEX);
|
121
|
+
memcpy(out->data, tmp.data, tmp.len);
|
122
|
+
_mongocrypt_buffer_cleanup(&tmp);
|
123
|
+
if (0 == strcmp((char *)ctx, "error_on:hmac_sha512")) {
|
124
|
+
mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
|
125
|
+
return false;
|
126
|
+
}
|
127
|
+
return true;
|
144
128
|
}
|
145
129
|
|
146
|
-
bool
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
return false;
|
169
|
-
}
|
170
|
-
return true;
|
130
|
+
bool _hmac_sha_256(void *ctx,
|
131
|
+
mongocrypt_binary_t *key,
|
132
|
+
mongocrypt_binary_t *in,
|
133
|
+
mongocrypt_binary_t *out,
|
134
|
+
mongocrypt_status_t *status) {
|
135
|
+
_mongocrypt_buffer_t tmp;
|
136
|
+
|
137
|
+
BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
|
138
|
+
bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
|
139
|
+
_append_bin("key", key);
|
140
|
+
_append_bin("in", in);
|
141
|
+
|
142
|
+
bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
|
143
|
+
|
144
|
+
_mongocrypt_buffer_copy_from_hex(&tmp, HASH_HEX);
|
145
|
+
memcpy(out->data, tmp.data, tmp.len);
|
146
|
+
_mongocrypt_buffer_cleanup(&tmp);
|
147
|
+
if (0 == strcmp((char *)ctx, "error_on:hmac_sha256")) {
|
148
|
+
mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
|
149
|
+
return false;
|
150
|
+
}
|
151
|
+
return true;
|
171
152
|
}
|
172
153
|
|
173
|
-
bool
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
if (0 == strcmp ((char *) ctx, "error_on:sha256")) {
|
191
|
-
mongocrypt_status_set (
|
192
|
-
status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *) ctx, -1);
|
193
|
-
return false;
|
194
|
-
}
|
195
|
-
return true;
|
154
|
+
bool _sha_256(void *ctx, mongocrypt_binary_t *in, mongocrypt_binary_t *out, mongocrypt_status_t *status) {
|
155
|
+
_mongocrypt_buffer_t tmp;
|
156
|
+
|
157
|
+
BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
|
158
|
+
bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
|
159
|
+
_append_bin("in", in);
|
160
|
+
|
161
|
+
bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
|
162
|
+
|
163
|
+
_mongocrypt_buffer_copy_from_hex(&tmp, HASH_HEX);
|
164
|
+
memcpy(out->data, tmp.data, tmp.len);
|
165
|
+
_mongocrypt_buffer_cleanup(&tmp);
|
166
|
+
if (0 == strcmp((char *)ctx, "error_on:sha256")) {
|
167
|
+
mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
|
168
|
+
return false;
|
169
|
+
}
|
170
|
+
return true;
|
196
171
|
}
|
197
172
|
|
198
|
-
bool
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
if (0 == strcmp ((char *) ctx, "error_on:random")) {
|
217
|
-
mongocrypt_status_set (
|
218
|
-
status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *) ctx, -1);
|
219
|
-
return false;
|
220
|
-
}
|
221
|
-
return true;
|
173
|
+
bool _random(void *ctx, mongocrypt_binary_t *out, uint32_t count, mongocrypt_status_t *status) {
|
174
|
+
/* only have 32 bytes of random test data. */
|
175
|
+
BSON_ASSERT(count <= 96);
|
176
|
+
|
177
|
+
BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
|
178
|
+
bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
|
179
|
+
bson_string_append_printf(call_history, "count:%d\n", (int)count);
|
180
|
+
bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
|
181
|
+
|
182
|
+
_mongocrypt_buffer_t tmp;
|
183
|
+
_mongocrypt_buffer_copy_from_hex(&tmp, RANDOM_HEX);
|
184
|
+
memcpy(out->data, tmp.data, count);
|
185
|
+
_mongocrypt_buffer_cleanup(&tmp);
|
186
|
+
if (0 == strcmp((char *)ctx, "error_on:random")) {
|
187
|
+
mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
|
188
|
+
return false;
|
189
|
+
}
|
190
|
+
return true;
|
222
191
|
}
|
223
192
|
|
224
|
-
bool
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
return false;
|
248
|
-
}
|
249
|
-
return true;
|
193
|
+
bool _sign_rsaes_pkcs1_v1_5(void *ctx,
|
194
|
+
mongocrypt_binary_t *key,
|
195
|
+
mongocrypt_binary_t *in,
|
196
|
+
mongocrypt_binary_t *out,
|
197
|
+
mongocrypt_status_t *status) {
|
198
|
+
_mongocrypt_buffer_t tmp;
|
199
|
+
|
200
|
+
BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
|
201
|
+
bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
|
202
|
+
_append_bin("key", key);
|
203
|
+
_append_bin("in", in);
|
204
|
+
|
205
|
+
bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
|
206
|
+
memset(out->data, 0, out->len);
|
207
|
+
|
208
|
+
_mongocrypt_buffer_copy_from_hex(&tmp, HASH_HEX);
|
209
|
+
memcpy(out->data, tmp.data, tmp.len);
|
210
|
+
_mongocrypt_buffer_cleanup(&tmp);
|
211
|
+
if (0 == strcmp((char *)ctx, "error_on:sign_rsaes_pkcs1_v1_5")) {
|
212
|
+
mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
|
213
|
+
return false;
|
214
|
+
}
|
215
|
+
return true;
|
250
216
|
}
|
251
217
|
|
252
218
|
static mongocrypt_t *
|
253
|
-
_create_mongocrypt_and_hooks
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
ASSERT_OK (
|
262
|
-
mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, "example", -1),
|
263
|
-
crypt);
|
264
|
-
ASSERT_OK (
|
265
|
-
mongocrypt_setopt_kms_providers (
|
266
|
-
crypt,
|
267
|
-
TEST_BSON ("{'gcp': { 'email': 'test', 'privateKey': 'AAAA'}}")),
|
268
|
-
crypt);
|
269
|
-
ret = mongocrypt_setopt_crypto_hooks (crypt,
|
219
|
+
_create_mongocrypt_and_hooks(_mongocrypt_tester_t *tester, const char *error_on, bool ctr_hook, bool ecb_hook) {
|
220
|
+
bool ret;
|
221
|
+
|
222
|
+
mongocrypt_t *crypt = mongocrypt_new();
|
223
|
+
ASSERT_OK(mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, "example", -1), crypt);
|
224
|
+
ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'gcp': { 'email': 'test', 'privateKey': 'AAAA'}}")),
|
225
|
+
crypt);
|
226
|
+
ret = mongocrypt_setopt_crypto_hooks(crypt,
|
270
227
|
_mock_aes_256_xxx_encrypt,
|
271
228
|
_mock_aes_256_xxx_decrypt,
|
272
229
|
_random,
|
273
230
|
_hmac_sha_512,
|
274
231
|
_hmac_sha_256,
|
275
232
|
_sha_256,
|
276
|
-
(void *)
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
ASSERT_OK (mongocrypt_init (crypt), crypt);
|
294
|
-
return crypt;
|
233
|
+
(void *)error_on);
|
234
|
+
ASSERT_OK(ret, crypt);
|
235
|
+
ret = mongocrypt_setopt_crypto_hook_sign_rsaes_pkcs1_v1_5(crypt, _sign_rsaes_pkcs1_v1_5, (void *)error_on);
|
236
|
+
ASSERT_OK(ret, crypt);
|
237
|
+
if (ctr_hook) {
|
238
|
+
ret = mongocrypt_setopt_aes_256_ctr(crypt,
|
239
|
+
_mock_aes_256_xxx_encrypt,
|
240
|
+
_mock_aes_256_xxx_decrypt,
|
241
|
+
(void *)error_on);
|
242
|
+
ASSERT_OK(ret, crypt);
|
243
|
+
}
|
244
|
+
if (ecb_hook) {
|
245
|
+
ret = mongocrypt_setopt_aes_256_ecb(crypt, _mock_aes_256_xxx_encrypt, (void *)error_on);
|
246
|
+
ASSERT_OK(ret, crypt);
|
247
|
+
}
|
248
|
+
ASSERT_OK(mongocrypt_init(crypt), crypt);
|
249
|
+
return crypt;
|
295
250
|
}
|
296
251
|
|
297
|
-
static mongocrypt_t *
|
298
|
-
|
299
|
-
{
|
300
|
-
return _create_mongocrypt_and_hooks (tester, error_on, false, false);
|
252
|
+
static mongocrypt_t *_create_mongocrypt(_mongocrypt_tester_t *tester, const char *error_on) {
|
253
|
+
return _create_mongocrypt_and_hooks(tester, error_on, false, false);
|
301
254
|
}
|
302
255
|
|
303
256
|
static void
|
304
|
-
_test_crypto_hooks_encryption_helper
|
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
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
} else {
|
380
|
-
ASSERT_FAILS_STATUS (ret, status, error_on);
|
381
|
-
}
|
382
|
-
|
383
|
-
|
384
|
-
_mongocrypt_buffer_cleanup (&key);
|
385
|
-
_mongocrypt_buffer_cleanup (&iv);
|
386
|
-
_mongocrypt_buffer_cleanup (&associated_data);
|
387
|
-
_mongocrypt_buffer_cleanup (&plaintext);
|
388
|
-
_mongocrypt_buffer_cleanup (&ciphertext);
|
389
|
-
mongocrypt_status_destroy (status);
|
390
|
-
mongocrypt_destroy (crypt);
|
391
|
-
bson_string_free (call_history, true);
|
257
|
+
_test_crypto_hooks_encryption_helper(_mongocrypt_tester_t *tester, const char *error_on, bool ctr_hook, bool ecb_hook) {
|
258
|
+
mongocrypt_t *crypt;
|
259
|
+
bool ret;
|
260
|
+
uint32_t bytes_written;
|
261
|
+
mongocrypt_status_t *status;
|
262
|
+
_mongocrypt_buffer_t iv, associated_data, key, plaintext, ciphertext;
|
263
|
+
const char *expected_call_history = "call:_mock_aes_256_xxx_encrypt\n"
|
264
|
+
"key:" ENCRYPTION_KEY_HEX "\n"
|
265
|
+
"iv:" IV_HEX "\n"
|
266
|
+
"in:BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E\n"
|
267
|
+
"ret:_mock_aes_256_xxx_encrypt\n"
|
268
|
+
"call:_hmac_sha_512\n"
|
269
|
+
"key:CCD3836C8F24AC5FAAFAAA630C5C6C5D210FD03934EA1440CD67E0DCDE3F8EA6\n"
|
270
|
+
"in:AAAA" IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E0000000000000010\n"
|
271
|
+
"ret:_hmac_sha_512\n";
|
272
|
+
|
273
|
+
status = mongocrypt_status_new();
|
274
|
+
crypt = _create_mongocrypt_and_hooks(tester, error_on, ctr_hook, ecb_hook);
|
275
|
+
|
276
|
+
_mongocrypt_buffer_copy_from_hex(&iv, IV_HEX);
|
277
|
+
_mongocrypt_buffer_copy_from_hex(&associated_data, "AAAA");
|
278
|
+
_mongocrypt_buffer_copy_from_hex(&plaintext, "BBBB");
|
279
|
+
|
280
|
+
call_history = bson_string_new(NULL);
|
281
|
+
|
282
|
+
if (ctr_hook || ecb_hook) {
|
283
|
+
const _mongocrypt_value_encryption_algorithm_t *fle2alg = _mcFLE2Algorithm();
|
284
|
+
_mongocrypt_buffer_copy_from_hex(&key, ENCRYPTION_KEY_HEX);
|
285
|
+
_mongocrypt_buffer_init(&ciphertext);
|
286
|
+
_mongocrypt_buffer_resize(&ciphertext, fle2alg->get_ciphertext_len(plaintext.len, status));
|
287
|
+
ret =
|
288
|
+
fle2alg
|
289
|
+
->do_encrypt(crypt->crypto, &iv, NULL /* aad */, &key, &plaintext, &ciphertext, &bytes_written, status);
|
290
|
+
} else {
|
291
|
+
const _mongocrypt_value_encryption_algorithm_t *fle1alg = _mcFLE1Algorithm();
|
292
|
+
_mongocrypt_buffer_copy_from_hex(&key, KEY_HEX);
|
293
|
+
_mongocrypt_buffer_init(&ciphertext);
|
294
|
+
_mongocrypt_buffer_resize(&ciphertext, fle1alg->get_ciphertext_len(plaintext.len, status));
|
295
|
+
ret = fle1alg->do_encrypt(crypt->crypto,
|
296
|
+
&iv,
|
297
|
+
&associated_data,
|
298
|
+
&key,
|
299
|
+
&plaintext,
|
300
|
+
&ciphertext,
|
301
|
+
&bytes_written,
|
302
|
+
status);
|
303
|
+
}
|
304
|
+
|
305
|
+
if (0 == strcmp(error_on, "error_on:none")) {
|
306
|
+
ASSERT_OK_STATUS(ret, status);
|
307
|
+
ciphertext.len = bytes_written;
|
308
|
+
|
309
|
+
/* Check the full trace. */
|
310
|
+
ASSERT_STREQUAL(call_history->str, expected_call_history);
|
311
|
+
|
312
|
+
/* Check the structure of the ciphertext */
|
313
|
+
BSON_ASSERT(0
|
314
|
+
== _mongocrypt_buffer_cmp_hex(&ciphertext,
|
315
|
+
IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E" /* the "encrypted"
|
316
|
+
block which is
|
317
|
+
really plaintext.
|
318
|
+
BBBB + padding. */
|
319
|
+
HMAC_HEX_TAG));
|
320
|
+
} else {
|
321
|
+
ASSERT_FAILS_STATUS(ret, status, error_on);
|
322
|
+
}
|
323
|
+
|
324
|
+
_mongocrypt_buffer_cleanup(&key);
|
325
|
+
_mongocrypt_buffer_cleanup(&iv);
|
326
|
+
_mongocrypt_buffer_cleanup(&associated_data);
|
327
|
+
_mongocrypt_buffer_cleanup(&plaintext);
|
328
|
+
_mongocrypt_buffer_cleanup(&ciphertext);
|
329
|
+
mongocrypt_status_destroy(status);
|
330
|
+
mongocrypt_destroy(crypt);
|
331
|
+
bson_string_free(call_history, true);
|
392
332
|
}
|
393
333
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
tester, "error_on:aes_256_cbc_encrypt", false, false);
|
401
|
-
_test_crypto_hooks_encryption_helper (
|
402
|
-
tester, "error_on:aes_256_ctr_encrypt", true, false);
|
403
|
-
_test_crypto_hooks_encryption_helper (
|
404
|
-
tester, "error_on:aes_256_ecb_encrypt", false, true);
|
405
|
-
_test_crypto_hooks_encryption_helper (
|
406
|
-
tester, "error_on:hmac_sha512", false, false);
|
334
|
+
static void _test_crypto_hooks_encryption(_mongocrypt_tester_t *tester) {
|
335
|
+
_test_crypto_hooks_encryption_helper(tester, "error_on:none", false, false);
|
336
|
+
_test_crypto_hooks_encryption_helper(tester, "error_on:aes_256_cbc_encrypt", false, false);
|
337
|
+
_test_crypto_hooks_encryption_helper(tester, "error_on:aes_256_ctr_encrypt", true, false);
|
338
|
+
_test_crypto_hooks_encryption_helper(tester, "error_on:aes_256_ecb_encrypt", false, true);
|
339
|
+
_test_crypto_hooks_encryption_helper(tester, "error_on:hmac_sha512", false, false);
|
407
340
|
}
|
408
341
|
|
409
|
-
|
410
342
|
static void
|
411
|
-
_test_crypto_hooks_decryption_helper
|
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
|
-
|
472
|
-
|
473
|
-
/* Check the resulting plaintext */
|
474
|
-
BSON_ASSERT (0 == _mongocrypt_buffer_cmp_hex (&plaintext, "BBBB"));
|
475
|
-
} else {
|
476
|
-
ASSERT_FAILS_STATUS (ret, status, error_on);
|
477
|
-
}
|
478
|
-
|
479
|
-
_mongocrypt_buffer_cleanup (&key);
|
480
|
-
_mongocrypt_buffer_cleanup (&associated_data);
|
481
|
-
_mongocrypt_buffer_cleanup (&plaintext);
|
482
|
-
_mongocrypt_buffer_cleanup (&ciphertext);
|
483
|
-
mongocrypt_status_destroy (status);
|
484
|
-
mongocrypt_destroy (crypt);
|
485
|
-
bson_string_free (call_history, true);
|
343
|
+
_test_crypto_hooks_decryption_helper(_mongocrypt_tester_t *tester, const char *error_on, bool ctr_hook, bool ecb_hook) {
|
344
|
+
mongocrypt_t *crypt;
|
345
|
+
bool ret;
|
346
|
+
uint32_t bytes_written;
|
347
|
+
mongocrypt_status_t *status;
|
348
|
+
_mongocrypt_buffer_t associated_data, key, plaintext, ciphertext;
|
349
|
+
const char *expected_call_history = "call:_hmac_sha_512\n"
|
350
|
+
"key:" HMAC_KEY_HEX "\n"
|
351
|
+
"in:AAAA" IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E0000000000000010\n"
|
352
|
+
"ret:_hmac_sha_512\n"
|
353
|
+
"call:_mock_aes_256_xxx_decrypt\n"
|
354
|
+
"key:" ENCRYPTION_KEY_HEX "\n"
|
355
|
+
"iv:" IV_HEX "\n"
|
356
|
+
"in:BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E\n"
|
357
|
+
"ret:_mock_aes_256_xxx_decrypt\n";
|
358
|
+
|
359
|
+
status = mongocrypt_status_new();
|
360
|
+
crypt = _create_mongocrypt_and_hooks(tester, error_on, ctr_hook, ecb_hook);
|
361
|
+
|
362
|
+
_mongocrypt_buffer_copy_from_hex(&associated_data, "AAAA");
|
363
|
+
_mongocrypt_buffer_copy_from_hex(&ciphertext, IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E" HMAC_HEX_TAG);
|
364
|
+
|
365
|
+
call_history = bson_string_new(NULL);
|
366
|
+
|
367
|
+
if (ctr_hook || ecb_hook) {
|
368
|
+
const _mongocrypt_value_encryption_algorithm_t *fle2alg = _mcFLE2Algorithm();
|
369
|
+
_mongocrypt_buffer_copy_from_hex(&key, ENCRYPTION_KEY_HEX);
|
370
|
+
_mongocrypt_buffer_init(&plaintext);
|
371
|
+
_mongocrypt_buffer_resize(&plaintext, fle2alg->get_plaintext_len(ciphertext.len, status));
|
372
|
+
|
373
|
+
ret = fle2alg->do_decrypt(crypt->crypto, NULL /* aad */, &key, &ciphertext, &plaintext, &bytes_written, status);
|
374
|
+
} else {
|
375
|
+
const _mongocrypt_value_encryption_algorithm_t *fle1alg = _mcFLE1Algorithm();
|
376
|
+
_mongocrypt_buffer_copy_from_hex(&key, KEY_HEX);
|
377
|
+
_mongocrypt_buffer_init(&plaintext);
|
378
|
+
_mongocrypt_buffer_resize(&plaintext, fle1alg->get_plaintext_len(ciphertext.len, status));
|
379
|
+
|
380
|
+
ret =
|
381
|
+
fle1alg->do_decrypt(crypt->crypto, &associated_data, &key, &ciphertext, &plaintext, &bytes_written, status);
|
382
|
+
}
|
383
|
+
|
384
|
+
if (0 == strcmp(error_on, "error_on:none")) {
|
385
|
+
ASSERT_OK_STATUS(ret, status);
|
386
|
+
plaintext.len = bytes_written;
|
387
|
+
|
388
|
+
/* Check the full trace. */
|
389
|
+
ASSERT_STREQUAL(call_history->str, expected_call_history);
|
390
|
+
|
391
|
+
/* Check the resulting plaintext */
|
392
|
+
BSON_ASSERT(0 == _mongocrypt_buffer_cmp_hex(&plaintext, "BBBB"));
|
393
|
+
} else {
|
394
|
+
ASSERT_FAILS_STATUS(ret, status, error_on);
|
395
|
+
}
|
396
|
+
|
397
|
+
_mongocrypt_buffer_cleanup(&key);
|
398
|
+
_mongocrypt_buffer_cleanup(&associated_data);
|
399
|
+
_mongocrypt_buffer_cleanup(&plaintext);
|
400
|
+
_mongocrypt_buffer_cleanup(&ciphertext);
|
401
|
+
mongocrypt_status_destroy(status);
|
402
|
+
mongocrypt_destroy(crypt);
|
403
|
+
bson_string_free(call_history, true);
|
486
404
|
}
|
487
405
|
|
488
|
-
static void
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
_test_crypto_hooks_decryption_helper (
|
495
|
-
tester, "error_on:aes_256_ctr_decrypt", true, false);
|
496
|
-
_test_crypto_hooks_decryption_helper (
|
497
|
-
tester, "error_on:aes_256_ecb_encrypt", false, true);
|
498
|
-
_test_crypto_hooks_decryption_helper (
|
499
|
-
tester, "error_on:hmac_sha512", false, false);
|
406
|
+
static void _test_crypto_hooks_decryption(_mongocrypt_tester_t *tester) {
|
407
|
+
_test_crypto_hooks_decryption_helper(tester, "error_on:none", false, false);
|
408
|
+
_test_crypto_hooks_decryption_helper(tester, "error_on:aes_256_cbc_decrypt", false, false);
|
409
|
+
_test_crypto_hooks_decryption_helper(tester, "error_on:aes_256_ctr_decrypt", true, false);
|
410
|
+
_test_crypto_hooks_decryption_helper(tester, "error_on:aes_256_ecb_encrypt", false, true);
|
411
|
+
_test_crypto_hooks_decryption_helper(tester, "error_on:hmac_sha512", false, false);
|
500
412
|
}
|
501
413
|
|
502
|
-
static void
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
_mongocrypt_buffer_cleanup (&iv);
|
548
|
-
mongocrypt_status_destroy (status);
|
549
|
-
mongocrypt_destroy (crypt);
|
550
|
-
bson_string_free (call_history, true);
|
414
|
+
static void _test_crypto_hooks_iv_gen_helper(_mongocrypt_tester_t *tester, char *error_on) {
|
415
|
+
mongocrypt_t *crypt;
|
416
|
+
bool ret;
|
417
|
+
mongocrypt_status_t *status;
|
418
|
+
_mongocrypt_buffer_t associated_data, key, plaintext, iv;
|
419
|
+
char *expected_iv = bson_strndup(HMAC_HEX_TAG, 16 * 2); /* only the first 16 bytes are used for IV. */
|
420
|
+
const char *expected_call_history = "call:_hmac_sha_512\n"
|
421
|
+
"key:" IV_KEY_HEX "\n"
|
422
|
+
"in:AAAA0000000000000010BBBB\n"
|
423
|
+
"ret:_hmac_sha_512\n";
|
424
|
+
|
425
|
+
status = mongocrypt_status_new();
|
426
|
+
crypt = _create_mongocrypt(tester, error_on);
|
427
|
+
|
428
|
+
_mongocrypt_buffer_copy_from_hex(&associated_data, "AAAA");
|
429
|
+
_mongocrypt_buffer_copy_from_hex(&key, KEY_HEX);
|
430
|
+
_mongocrypt_buffer_copy_from_hex(&plaintext, "BBBB");
|
431
|
+
|
432
|
+
_mongocrypt_buffer_init(&iv);
|
433
|
+
_mongocrypt_buffer_resize(&iv, MONGOCRYPT_IV_LEN);
|
434
|
+
|
435
|
+
call_history = bson_string_new(NULL);
|
436
|
+
|
437
|
+
ret = _mongocrypt_calculate_deterministic_iv(crypt->crypto, &key, &plaintext, &associated_data, &iv, status);
|
438
|
+
|
439
|
+
if (0 == strcmp(error_on, "error_on:none")) {
|
440
|
+
ASSERT_OK_STATUS(ret, status);
|
441
|
+
|
442
|
+
/* Check the full trace. */
|
443
|
+
ASSERT_STREQUAL(call_history->str, expected_call_history);
|
444
|
+
|
445
|
+
/* Check the resulting iv */
|
446
|
+
BSON_ASSERT(0 == _mongocrypt_buffer_cmp_hex(&iv, expected_iv));
|
447
|
+
} else {
|
448
|
+
ASSERT_FAILS_STATUS(ret, status, error_on);
|
449
|
+
}
|
450
|
+
|
451
|
+
bson_free(expected_iv);
|
452
|
+
_mongocrypt_buffer_cleanup(&key);
|
453
|
+
_mongocrypt_buffer_cleanup(&associated_data);
|
454
|
+
_mongocrypt_buffer_cleanup(&plaintext);
|
455
|
+
_mongocrypt_buffer_cleanup(&iv);
|
456
|
+
mongocrypt_status_destroy(status);
|
457
|
+
mongocrypt_destroy(crypt);
|
458
|
+
bson_string_free(call_history, true);
|
551
459
|
}
|
552
460
|
|
553
|
-
static void
|
554
|
-
|
555
|
-
|
556
|
-
_test_crypto_hooks_iv_gen_helper (tester, "error_on:none");
|
557
|
-
_test_crypto_hooks_iv_gen_helper (tester, "error_on:hmac_sha512");
|
461
|
+
static void _test_crypto_hooks_iv_gen(_mongocrypt_tester_t *tester) {
|
462
|
+
_test_crypto_hooks_iv_gen_helper(tester, "error_on:none");
|
463
|
+
_test_crypto_hooks_iv_gen_helper(tester, "error_on:hmac_sha512");
|
558
464
|
}
|
559
465
|
|
466
|
+
static void _test_crypto_hooks_random_helper(_mongocrypt_tester_t *tester, const char *error_on) {
|
467
|
+
mongocrypt_t *crypt;
|
468
|
+
bool ret;
|
469
|
+
mongocrypt_status_t *status;
|
470
|
+
_mongocrypt_buffer_t random;
|
471
|
+
const char *expected_call_history = "call:_random\n"
|
472
|
+
"count:96\n"
|
473
|
+
"ret:_random\n";
|
560
474
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
ASSERT_STREQUAL (call_history->str, expected_call_history);
|
588
|
-
|
589
|
-
/* Check the resulting iv */
|
590
|
-
BSON_ASSERT (0 == _mongocrypt_buffer_cmp_hex (&random, RANDOM_HEX));
|
591
|
-
} else {
|
592
|
-
ASSERT_FAILS_STATUS (ret, status, error_on);
|
593
|
-
}
|
594
|
-
|
595
|
-
_mongocrypt_buffer_cleanup (&random);
|
596
|
-
mongocrypt_status_destroy (status);
|
597
|
-
mongocrypt_destroy (crypt);
|
598
|
-
bson_string_free (call_history, true);
|
475
|
+
status = mongocrypt_status_new();
|
476
|
+
crypt = _create_mongocrypt(tester, error_on);
|
477
|
+
|
478
|
+
_mongocrypt_buffer_init(&random);
|
479
|
+
_mongocrypt_buffer_resize(&random, 96);
|
480
|
+
|
481
|
+
call_history = bson_string_new(NULL);
|
482
|
+
|
483
|
+
ret = _mongocrypt_random(crypt->crypto, &random, random.len, status);
|
484
|
+
|
485
|
+
if (0 == strcmp(error_on, "error_on:none")) {
|
486
|
+
ASSERT_OK_STATUS(ret, status);
|
487
|
+
|
488
|
+
/* Check the full trace. */
|
489
|
+
ASSERT_STREQUAL(call_history->str, expected_call_history);
|
490
|
+
|
491
|
+
/* Check the resulting iv */
|
492
|
+
BSON_ASSERT(0 == _mongocrypt_buffer_cmp_hex(&random, RANDOM_HEX));
|
493
|
+
} else {
|
494
|
+
ASSERT_FAILS_STATUS(ret, status, error_on);
|
495
|
+
}
|
496
|
+
|
497
|
+
_mongocrypt_buffer_cleanup(&random);
|
498
|
+
mongocrypt_status_destroy(status);
|
499
|
+
mongocrypt_destroy(crypt);
|
500
|
+
bson_string_free(call_history, true);
|
599
501
|
}
|
600
502
|
|
601
|
-
static void
|
602
|
-
|
603
|
-
|
604
|
-
_test_crypto_hooks_random_helper (tester, "error_on:none");
|
605
|
-
_test_crypto_hooks_random_helper (tester, "error_on:random");
|
503
|
+
static void _test_crypto_hooks_random(_mongocrypt_tester_t *tester) {
|
504
|
+
_test_crypto_hooks_random_helper(tester, "error_on:none");
|
505
|
+
_test_crypto_hooks_random_helper(tester, "error_on:random");
|
606
506
|
}
|
607
507
|
|
608
|
-
static void
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
mongocrypt_ctx_destroy (ctx);
|
641
|
-
mongocrypt_status_destroy (status);
|
642
|
-
mongocrypt_destroy (crypt);
|
643
|
-
bson_string_free (call_history, true);
|
508
|
+
static void _test_kms_request_helper(_mongocrypt_tester_t *tester, const char *error_on) {
|
509
|
+
mongocrypt_t *crypt;
|
510
|
+
mongocrypt_status_t *status;
|
511
|
+
mongocrypt_ctx_t *ctx;
|
512
|
+
bool ret;
|
513
|
+
|
514
|
+
status = mongocrypt_status_new();
|
515
|
+
crypt = _create_mongocrypt(tester, error_on);
|
516
|
+
ctx = mongocrypt_ctx_new(crypt);
|
517
|
+
|
518
|
+
call_history = bson_string_new(NULL);
|
519
|
+
|
520
|
+
ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, "us-east-1", -1, "cmk", -1), ctx);
|
521
|
+
|
522
|
+
mongocrypt_ctx_datakey_init(ctx);
|
523
|
+
ret = mongocrypt_ctx_status(ctx, status);
|
524
|
+
|
525
|
+
if (0 == strcmp(error_on, "error_on:none")) {
|
526
|
+
ASSERT_OK_STATUS(ret, status);
|
527
|
+
|
528
|
+
/* The call history includes some random data, just assert we've called
|
529
|
+
* our hooks. */
|
530
|
+
BSON_ASSERT(strstr(call_history->str, "call:_hmac_sha_256"));
|
531
|
+
BSON_ASSERT(strstr(call_history->str, "call:_sha_256"));
|
532
|
+
} else {
|
533
|
+
ASSERT_FAILS_STATUS(ret, status, error_on);
|
534
|
+
}
|
535
|
+
|
536
|
+
mongocrypt_ctx_destroy(ctx);
|
537
|
+
mongocrypt_status_destroy(status);
|
538
|
+
mongocrypt_destroy(crypt);
|
539
|
+
bson_string_free(call_history, true);
|
644
540
|
}
|
645
541
|
|
646
|
-
static void
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
_test_kms_request_helper (tester, "error_on:hmac_sha256");
|
651
|
-
_test_kms_request_helper (tester, "error_on:sha256");
|
542
|
+
static void _test_kms_request(_mongocrypt_tester_t *tester) {
|
543
|
+
_test_kms_request_helper(tester, "error_on:none");
|
544
|
+
_test_kms_request_helper(tester, "error_on:hmac_sha256");
|
545
|
+
_test_kms_request_helper(tester, "error_on:sha256");
|
652
546
|
}
|
653
547
|
|
548
|
+
static void _test_crypto_hooks_unset(_mongocrypt_tester_t *tester) {
|
549
|
+
mongocrypt_t *crypt;
|
654
550
|
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
crypt = mongocrypt_new ();
|
661
|
-
mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, "example", -1);
|
662
|
-
ASSERT_OK (mongocrypt_init (crypt), crypt);
|
663
|
-
mongocrypt_destroy (crypt);
|
551
|
+
crypt = mongocrypt_new();
|
552
|
+
mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, "example", -1);
|
553
|
+
ASSERT_OK(mongocrypt_init(crypt), crypt);
|
554
|
+
mongocrypt_destroy(crypt);
|
664
555
|
}
|
665
556
|
|
666
|
-
|
667
557
|
/* test a bug fix, that an error on explicit encryption in the crypto hooks sets
|
668
558
|
* the context state */
|
669
|
-
static void
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
BSON_ASSERT (MONGOCRYPT_CTX_ERROR == mongocrypt_ctx_state (ctx));
|
697
|
-
mongocrypt_binary_destroy (bin);
|
698
|
-
mongocrypt_binary_destroy (key_id);
|
699
|
-
mongocrypt_ctx_destroy (ctx);
|
700
|
-
mongocrypt_destroy (crypt);
|
701
|
-
bson_string_free (call_history, true);
|
559
|
+
static void _test_crypto_hooks_explicit_err(_mongocrypt_tester_t *tester) {
|
560
|
+
mongocrypt_t *crypt;
|
561
|
+
mongocrypt_ctx_t *ctx;
|
562
|
+
mongocrypt_binary_t *bin, *key_id;
|
563
|
+
const char *deterministic = MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR;
|
564
|
+
|
565
|
+
call_history = bson_string_new(NULL);
|
566
|
+
|
567
|
+
/* error on something during encryption. */
|
568
|
+
crypt = _create_mongocrypt(tester, "error_on:hmac_sha512");
|
569
|
+
|
570
|
+
ctx = mongocrypt_ctx_new(crypt);
|
571
|
+
key_id = mongocrypt_binary_new_from_data(MONGOCRYPT_DATA_AND_LEN("aaaaaaaaaaaaaaaa"));
|
572
|
+
|
573
|
+
ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, deterministic, -1), ctx);
|
574
|
+
ASSERT_OK(mongocrypt_ctx_setopt_key_id(ctx, key_id), ctx);
|
575
|
+
ASSERT_OK(mongocrypt_ctx_explicit_encrypt_init(ctx, TEST_BSON("{'v': 123}")), ctx);
|
576
|
+
|
577
|
+
_mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
|
578
|
+
bin = mongocrypt_binary_new();
|
579
|
+
ASSERT_FAILS(mongocrypt_ctx_finalize(ctx, bin), ctx, "error_on:hmac_sha512");
|
580
|
+
BSON_ASSERT(MONGOCRYPT_CTX_ERROR == mongocrypt_ctx_state(ctx));
|
581
|
+
mongocrypt_binary_destroy(bin);
|
582
|
+
mongocrypt_binary_destroy(key_id);
|
583
|
+
mongocrypt_ctx_destroy(ctx);
|
584
|
+
mongocrypt_destroy(crypt);
|
585
|
+
bson_string_free(call_history, true);
|
702
586
|
}
|
703
587
|
|
704
588
|
/* validate that sha256 errors are handled correctly */
|
705
|
-
static void
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
mongocrypt_ctx_destroy (ctx);
|
725
|
-
mongocrypt_status_destroy (status);
|
726
|
-
mongocrypt_destroy (crypt);
|
727
|
-
bson_string_free (call_history, true);
|
589
|
+
static void _test_crypto_hooks_explicit_sha256_err(_mongocrypt_tester_t *tester) {
|
590
|
+
mongocrypt_t *crypt;
|
591
|
+
mongocrypt_status_t *status;
|
592
|
+
mongocrypt_ctx_t *ctx;
|
593
|
+
|
594
|
+
status = mongocrypt_status_new();
|
595
|
+
crypt = _create_mongocrypt(tester, "error_on:sha256");
|
596
|
+
ctx = mongocrypt_ctx_new(crypt);
|
597
|
+
|
598
|
+
call_history = bson_string_new(NULL);
|
599
|
+
|
600
|
+
ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, "us-east-1", -1, "cmk", -1), ctx);
|
601
|
+
ASSERT_FAILS(mongocrypt_ctx_datakey_init(ctx), ctx, "failed to create KMS message");
|
602
|
+
|
603
|
+
mongocrypt_ctx_destroy(ctx);
|
604
|
+
mongocrypt_status_destroy(status);
|
605
|
+
mongocrypt_destroy(crypt);
|
606
|
+
bson_string_free(call_history, true);
|
728
607
|
}
|
729
608
|
|
730
|
-
static void
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
call_history = bson_string_new (NULL);
|
773
|
-
|
774
|
-
ASSERT_OK (mongocrypt_ctx_encrypt_init (
|
775
|
-
ctx, "test", -1, TEST_FILE ("./test/example/cmd.json")),
|
776
|
-
ctx);
|
777
|
-
_mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
778
|
-
ASSERT_FAILS (mongocrypt_ctx_mongo_feed (
|
779
|
-
ctx, TEST_FILE ("./test/data/key-document-gcp.json")),
|
609
|
+
static void _test_crypto_hook_sign_rsaes_pkcs1_v1_5(_mongocrypt_tester_t *tester) {
|
610
|
+
mongocrypt_t *crypt;
|
611
|
+
mongocrypt_ctx_t *ctx;
|
612
|
+
|
613
|
+
crypt = _create_mongocrypt(tester, "error_on:none");
|
614
|
+
call_history = bson_string_new(NULL);
|
615
|
+
|
616
|
+
ctx = mongocrypt_ctx_new(crypt);
|
617
|
+
mongocrypt_ctx_setopt_key_encryption_key(ctx,
|
618
|
+
TEST_BSON("{'provider': 'gcp', 'projectId': 'test', 'location': "
|
619
|
+
"'global', 'keyRing': 'ring', 'keyName': 'key'}"));
|
620
|
+
ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
|
621
|
+
|
622
|
+
BSON_ASSERT(strstr(call_history->str, "call:_sign_rsaes_pkcs1_v1_5"));
|
623
|
+
BSON_ASSERT(strstr(call_history->str, "key:000000"));
|
624
|
+
|
625
|
+
mongocrypt_ctx_destroy(ctx);
|
626
|
+
mongocrypt_destroy(crypt);
|
627
|
+
bson_string_free(call_history, true);
|
628
|
+
|
629
|
+
/* Test error when creating a data key. */
|
630
|
+
crypt = _create_mongocrypt(tester, "error_on:sign_rsaes_pkcs1_v1_5");
|
631
|
+
ctx = mongocrypt_ctx_new(crypt);
|
632
|
+
call_history = bson_string_new(NULL);
|
633
|
+
|
634
|
+
mongocrypt_ctx_setopt_key_encryption_key(ctx,
|
635
|
+
TEST_BSON("{'provider': 'gcp', 'projectId': 'test', 'location': "
|
636
|
+
"'global', 'keyRing': 'ring', 'keyName': 'key'}"));
|
637
|
+
ASSERT_FAILS(mongocrypt_ctx_datakey_init(ctx), ctx, "error_on:sign_rsaes_pkcs1_v1_5");
|
638
|
+
|
639
|
+
mongocrypt_ctx_destroy(ctx);
|
640
|
+
mongocrypt_destroy(crypt);
|
641
|
+
bson_string_free(call_history, true);
|
642
|
+
|
643
|
+
/* Test error when encrypting. */
|
644
|
+
crypt = _create_mongocrypt(tester, "error_on:sign_rsaes_pkcs1_v1_5");
|
645
|
+
ctx = mongocrypt_ctx_new(crypt);
|
646
|
+
call_history = bson_string_new(NULL);
|
647
|
+
|
648
|
+
ASSERT_OK(mongocrypt_ctx_encrypt_init(ctx, "test", -1, TEST_FILE("./test/example/cmd.json")), ctx);
|
649
|
+
_mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
|
650
|
+
ASSERT_FAILS(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-gcp.json")),
|
780
651
|
ctx,
|
781
652
|
"error_on:sign_rsaes_pkcs1_v1_5");
|
782
653
|
|
783
|
-
|
784
|
-
|
785
|
-
|
654
|
+
mongocrypt_ctx_destroy(ctx);
|
655
|
+
mongocrypt_destroy(crypt);
|
656
|
+
bson_string_free(call_history, true);
|
786
657
|
}
|
787
658
|
|
788
659
|
#ifdef MONGOCRYPT_ENABLE_CRYPTO_LIBCRYPTO
|
789
|
-
bool
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
{
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
aes_256_args_t args = {
|
813
|
-
&key_buf, NULL, &in_buf, &out_buf, bytes_written, status};
|
814
|
-
|
815
|
-
return _native_crypto_aes_256_ecb_encrypt (args);
|
660
|
+
bool _native_crypto_aes_256_ecb_encrypt(aes_256_args_t args);
|
661
|
+
|
662
|
+
static bool _aes_256_ecb_encrypt(void *ctx,
|
663
|
+
mongocrypt_binary_t *key,
|
664
|
+
mongocrypt_binary_t *iv,
|
665
|
+
mongocrypt_binary_t *in,
|
666
|
+
mongocrypt_binary_t *out,
|
667
|
+
uint32_t *bytes_written,
|
668
|
+
mongocrypt_status_t *status) {
|
669
|
+
_mongocrypt_buffer_t key_buf;
|
670
|
+
_mongocrypt_buffer_from_binary(&key_buf, key);
|
671
|
+
if (iv) {
|
672
|
+
CLIENT_ERR("IV expected to be NULL in this mode");
|
673
|
+
return false;
|
674
|
+
}
|
675
|
+
_mongocrypt_buffer_t in_buf;
|
676
|
+
_mongocrypt_buffer_from_binary(&in_buf, in);
|
677
|
+
_mongocrypt_buffer_t out_buf;
|
678
|
+
_mongocrypt_buffer_from_binary(&out_buf, out);
|
679
|
+
|
680
|
+
aes_256_args_t args = {&key_buf, NULL, &in_buf, &out_buf, bytes_written, status};
|
681
|
+
|
682
|
+
return _native_crypto_aes_256_ecb_encrypt(args);
|
816
683
|
}
|
817
684
|
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
_mongocrypt_buffer_cleanup (&plaintext);
|
891
|
-
_mongocrypt_buffer_cleanup (&ciphertext_reg);
|
892
|
-
_mongocrypt_buffer_cleanup (&ciphertext_ecb);
|
893
|
-
_mongocrypt_buffer_cleanup (&plaintext_ecb);
|
894
|
-
mongocrypt_destroy (crypt_reg);
|
895
|
-
mongocrypt_destroy (crypt_ecb);
|
896
|
-
mongocrypt_status_destroy (status);
|
685
|
+
void _test_fle2_crypto_via_ecb_hook(_mongocrypt_tester_t *tester) {
|
686
|
+
const _mongocrypt_value_encryption_algorithm_t *fle2alg = _mcFLE2Algorithm();
|
687
|
+
bool ret;
|
688
|
+
_mongocrypt_buffer_t key;
|
689
|
+
_mongocrypt_buffer_t iv;
|
690
|
+
_mongocrypt_buffer_t plaintext;
|
691
|
+
_mongocrypt_buffer_t ciphertext_reg;
|
692
|
+
_mongocrypt_buffer_t ciphertext_ecb;
|
693
|
+
_mongocrypt_buffer_t plaintext_ecb;
|
694
|
+
uint32_t bytes_written;
|
695
|
+
mongocrypt_status_t *status = mongocrypt_status_new();
|
696
|
+
|
697
|
+
_mongocrypt_buffer_copy_from_hex(&iv, IV_HEX);
|
698
|
+
_mongocrypt_buffer_copy_from_hex(&plaintext, "4f6c64204d63446f6e616c64206861642061206661726d2e20456965696f0a");
|
699
|
+
_mongocrypt_buffer_copy_from_hex(&key, ENCRYPTION_KEY_HEX);
|
700
|
+
|
701
|
+
/* Encrypt data using native CTR and ECB-hook and compare */
|
702
|
+
|
703
|
+
mongocrypt_t *crypt_reg = mongocrypt_new();
|
704
|
+
_mongocrypt_buffer_init(&ciphertext_reg);
|
705
|
+
_mongocrypt_buffer_resize(&ciphertext_reg, fle2alg->get_ciphertext_len(plaintext.len, status));
|
706
|
+
ret = fle2alg->do_encrypt(crypt_reg->crypto,
|
707
|
+
&iv,
|
708
|
+
NULL /* aad */,
|
709
|
+
&key,
|
710
|
+
&plaintext,
|
711
|
+
&ciphertext_reg,
|
712
|
+
&bytes_written,
|
713
|
+
status);
|
714
|
+
ASSERT_OK(ret, crypt_reg);
|
715
|
+
|
716
|
+
mongocrypt_t *crypt_ecb = mongocrypt_new();
|
717
|
+
ret = mongocrypt_setopt_aes_256_ecb(crypt_ecb, _aes_256_ecb_encrypt, NULL);
|
718
|
+
ASSERT_OK(ret, crypt_ecb);
|
719
|
+
_mongocrypt_buffer_init(&ciphertext_ecb);
|
720
|
+
_mongocrypt_buffer_resize(&ciphertext_ecb, fle2alg->get_ciphertext_len(plaintext.len, status));
|
721
|
+
ret = fle2alg->do_encrypt(crypt_ecb->crypto,
|
722
|
+
&iv,
|
723
|
+
NULL /* aad */,
|
724
|
+
&key,
|
725
|
+
&plaintext,
|
726
|
+
&ciphertext_ecb,
|
727
|
+
&bytes_written,
|
728
|
+
status);
|
729
|
+
ASSERT_OK(ret, crypt_ecb);
|
730
|
+
|
731
|
+
ASSERT(0 == _mongocrypt_buffer_cmp(&ciphertext_reg, &ciphertext_ecb));
|
732
|
+
|
733
|
+
/* Decrypt data using ECB-hook and compare to original */
|
734
|
+
|
735
|
+
_mongocrypt_buffer_init(&plaintext_ecb);
|
736
|
+
_mongocrypt_buffer_resize(&plaintext_ecb, fle2alg->get_plaintext_len(ciphertext_ecb.len, status));
|
737
|
+
ret = fle2alg->do_decrypt(crypt_ecb->crypto,
|
738
|
+
NULL /* aad */,
|
739
|
+
&key,
|
740
|
+
&ciphertext_ecb,
|
741
|
+
&plaintext_ecb,
|
742
|
+
&bytes_written,
|
743
|
+
status);
|
744
|
+
ASSERT_OK(ret, crypt_ecb);
|
745
|
+
|
746
|
+
ASSERT(0 == _mongocrypt_buffer_cmp(&plaintext, &plaintext_ecb));
|
747
|
+
|
748
|
+
_mongocrypt_buffer_cleanup(&key);
|
749
|
+
_mongocrypt_buffer_cleanup(&iv);
|
750
|
+
_mongocrypt_buffer_cleanup(&plaintext);
|
751
|
+
_mongocrypt_buffer_cleanup(&ciphertext_reg);
|
752
|
+
_mongocrypt_buffer_cleanup(&ciphertext_ecb);
|
753
|
+
_mongocrypt_buffer_cleanup(&plaintext_ecb);
|
754
|
+
mongocrypt_destroy(crypt_reg);
|
755
|
+
mongocrypt_destroy(crypt_ecb);
|
756
|
+
mongocrypt_status_destroy(status);
|
897
757
|
}
|
898
758
|
#endif
|
899
759
|
|
900
|
-
void
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
INSTALL_TEST_CRYPTO (_test_crypto_hooks_explicit_sha256_err,
|
911
|
-
CRYPTO_OPTIONAL);
|
912
|
-
INSTALL_TEST_CRYPTO (_test_crypto_hook_sign_rsaes_pkcs1_v1_5,
|
913
|
-
CRYPTO_OPTIONAL);
|
760
|
+
void _mongocrypt_tester_install_crypto_hooks(_mongocrypt_tester_t *tester) {
|
761
|
+
INSTALL_TEST_CRYPTO(_test_crypto_hooks_encryption, CRYPTO_OPTIONAL);
|
762
|
+
INSTALL_TEST_CRYPTO(_test_crypto_hooks_decryption, CRYPTO_OPTIONAL);
|
763
|
+
INSTALL_TEST_CRYPTO(_test_crypto_hooks_iv_gen, CRYPTO_OPTIONAL);
|
764
|
+
INSTALL_TEST_CRYPTO(_test_crypto_hooks_random, CRYPTO_OPTIONAL);
|
765
|
+
INSTALL_TEST_CRYPTO(_test_kms_request, CRYPTO_OPTIONAL);
|
766
|
+
INSTALL_TEST_CRYPTO(_test_crypto_hooks_unset, CRYPTO_PROHIBITED);
|
767
|
+
INSTALL_TEST_CRYPTO(_test_crypto_hooks_explicit_err, CRYPTO_OPTIONAL);
|
768
|
+
INSTALL_TEST_CRYPTO(_test_crypto_hooks_explicit_sha256_err, CRYPTO_OPTIONAL);
|
769
|
+
INSTALL_TEST_CRYPTO(_test_crypto_hook_sign_rsaes_pkcs1_v1_5, CRYPTO_OPTIONAL);
|
914
770
|
#ifdef MONGOCRYPT_ENABLE_CRYPTO_LIBCRYPTO
|
915
|
-
|
771
|
+
INSTALL_TEST(_test_fle2_crypto_via_ecb_hook);
|
916
772
|
#endif
|
917
773
|
}
|