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,31 +14,28 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
|
18
|
-
#include "mongocrypt-private.h"
|
19
17
|
#include "mongocrypt-binary-private.h"
|
20
18
|
#include "mongocrypt-buffer-private.h"
|
21
19
|
#include "mongocrypt-ctx-private.h"
|
22
20
|
#include "mongocrypt-kms-ctx-private.h"
|
23
21
|
#include "mongocrypt-opts-private.h"
|
22
|
+
#include "mongocrypt-private.h"
|
24
23
|
#include "mongocrypt-status-private.h"
|
25
24
|
#include "mongocrypt-util-private.h"
|
26
|
-
#include
|
25
|
+
#include "mongocrypt.h"
|
27
26
|
#include <kms_message/kms_azure_request.h>
|
27
|
+
#include <kms_message/kms_b64.h>
|
28
28
|
#include <kms_message/kms_gcp_request.h>
|
29
|
-
#include "mongocrypt.h"
|
30
29
|
|
31
30
|
/* Sadly, Windows does not define SSIZE_MAX. It is defined in bson-compat.h,
|
32
31
|
* but only since 1.22.x, so copy this from bson-compat.h for now. */
|
33
32
|
#ifndef SSIZE_MAX
|
34
|
-
#define SSIZE_MAX
|
35
|
-
(ssize_t) ( \
|
36
|
-
(((size_t) 0x01u) << (sizeof (ssize_t) * (size_t) CHAR_BIT - 1u)) - 1u)
|
33
|
+
#define SSIZE_MAX (ssize_t)((((size_t)0x01u) << (sizeof(ssize_t) * (size_t)CHAR_BIT - 1u)) - 1u)
|
37
34
|
#endif
|
38
35
|
|
39
36
|
typedef struct {
|
40
|
-
|
41
|
-
|
37
|
+
mongocrypt_status_t *status;
|
38
|
+
void *ctx;
|
42
39
|
} ctx_with_status_t;
|
43
40
|
|
44
41
|
/* Before we've read the Content-Length header in an HTTP response,
|
@@ -50,1544 +47,1358 @@ typedef struct {
|
|
50
47
|
#define DEFAULT_HTTPS_PORT "443"
|
51
48
|
#define DEFAULT_KMIP_PORT "5696"
|
52
49
|
|
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
|
-
mongocrypt_binary_destroy (plaintext);
|
78
|
-
mongocrypt_binary_destroy (out);
|
79
|
-
return ret;
|
50
|
+
static bool _sha256(void *ctx, const char *input, size_t len, unsigned char *hash_out) {
|
51
|
+
BSON_ASSERT_PARAM(ctx);
|
52
|
+
BSON_ASSERT_PARAM(input);
|
53
|
+
BSON_ASSERT_PARAM(hash_out);
|
54
|
+
|
55
|
+
bool ret;
|
56
|
+
ctx_with_status_t *ctx_with_status = (ctx_with_status_t *)ctx;
|
57
|
+
_mongocrypt_crypto_t *crypto;
|
58
|
+
mongocrypt_binary_t *plaintext, *out;
|
59
|
+
|
60
|
+
crypto = (_mongocrypt_crypto_t *)ctx_with_status->ctx;
|
61
|
+
BSON_ASSERT(crypto);
|
62
|
+
BSON_ASSERT(len <= UINT32_MAX);
|
63
|
+
plaintext = mongocrypt_binary_new_from_data((uint8_t *)input, (uint32_t)len);
|
64
|
+
out = mongocrypt_binary_new();
|
65
|
+
|
66
|
+
out->data = hash_out;
|
67
|
+
out->len = SHA256_LEN;
|
68
|
+
|
69
|
+
ret = crypto->sha_256(crypto->ctx, plaintext, out, ctx_with_status->status);
|
70
|
+
|
71
|
+
mongocrypt_binary_destroy(plaintext);
|
72
|
+
mongocrypt_binary_destroy(out);
|
73
|
+
return ret;
|
80
74
|
}
|
81
75
|
|
82
76
|
static bool
|
83
|
-
_sha256_hmac
|
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
|
-
out->len = SHA256_LEN;
|
113
|
-
|
114
|
-
ret = crypto->hmac_sha_256 (
|
115
|
-
crypto->ctx, key, plaintext, out, ctx_with_status->status);
|
116
|
-
|
117
|
-
mongocrypt_binary_destroy (key);
|
118
|
-
mongocrypt_binary_destroy (plaintext);
|
119
|
-
mongocrypt_binary_destroy (out);
|
120
|
-
return ret;
|
77
|
+
_sha256_hmac(void *ctx, const char *key_input, size_t key_len, const char *input, size_t len, unsigned char *hash_out) {
|
78
|
+
BSON_ASSERT_PARAM(ctx);
|
79
|
+
BSON_ASSERT_PARAM(key_input);
|
80
|
+
BSON_ASSERT_PARAM(input);
|
81
|
+
BSON_ASSERT_PARAM(hash_out);
|
82
|
+
|
83
|
+
ctx_with_status_t *ctx_with_status = (ctx_with_status_t *)ctx;
|
84
|
+
_mongocrypt_crypto_t *crypto;
|
85
|
+
mongocrypt_binary_t *key, *plaintext, *out;
|
86
|
+
bool ret;
|
87
|
+
|
88
|
+
crypto = (_mongocrypt_crypto_t *)ctx_with_status->ctx;
|
89
|
+
BSON_ASSERT(crypto);
|
90
|
+
|
91
|
+
BSON_ASSERT(key_len <= UINT32_MAX);
|
92
|
+
key = mongocrypt_binary_new_from_data((uint8_t *)key_input, (uint32_t)key_len);
|
93
|
+
BSON_ASSERT(len <= UINT32_MAX);
|
94
|
+
plaintext = mongocrypt_binary_new_from_data((uint8_t *)input, (uint32_t)len);
|
95
|
+
out = mongocrypt_binary_new();
|
96
|
+
|
97
|
+
out->data = hash_out;
|
98
|
+
out->len = SHA256_LEN;
|
99
|
+
|
100
|
+
ret = crypto->hmac_sha_256(crypto->ctx, key, plaintext, out, ctx_with_status->status);
|
101
|
+
|
102
|
+
mongocrypt_binary_destroy(key);
|
103
|
+
mongocrypt_binary_destroy(plaintext);
|
104
|
+
mongocrypt_binary_destroy(out);
|
105
|
+
return ret;
|
121
106
|
}
|
122
107
|
|
123
108
|
static void
|
124
|
-
_set_kms_crypto_hooks
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
if (crypto->hooks_enabled) {
|
133
|
-
kms_request_opt_set_crypto_hooks (
|
134
|
-
opts, _sha256, _sha256_hmac, ctx_with_status);
|
135
|
-
}
|
109
|
+
_set_kms_crypto_hooks(_mongocrypt_crypto_t *crypto, ctx_with_status_t *ctx_with_status, kms_request_opt_t *opts) {
|
110
|
+
BSON_ASSERT_PARAM(crypto);
|
111
|
+
BSON_ASSERT_PARAM(ctx_with_status);
|
112
|
+
BSON_ASSERT_PARAM(opts);
|
113
|
+
|
114
|
+
if (crypto->hooks_enabled) {
|
115
|
+
kms_request_opt_set_crypto_hooks(opts, _sha256, _sha256_hmac, ctx_with_status);
|
116
|
+
}
|
136
117
|
}
|
137
118
|
|
138
|
-
static bool
|
139
|
-
|
140
|
-
|
141
|
-
return kms_type == MONGOCRYPT_KMS_KMIP_REGISTER ||
|
142
|
-
kms_type == MONGOCRYPT_KMS_KMIP_ACTIVATE ||
|
143
|
-
kms_type == MONGOCRYPT_KMS_KMIP_GET;
|
119
|
+
static bool is_kms(_kms_request_type_t kms_type) {
|
120
|
+
return kms_type == MONGOCRYPT_KMS_KMIP_REGISTER || kms_type == MONGOCRYPT_KMS_KMIP_ACTIVATE
|
121
|
+
|| kms_type == MONGOCRYPT_KMS_KMIP_GET;
|
144
122
|
}
|
145
123
|
|
146
|
-
static void
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
kms->log = log;
|
159
|
-
kms->status = mongocrypt_status_new ();
|
160
|
-
kms->req_type = kms_type;
|
161
|
-
_mongocrypt_buffer_init (&kms->result);
|
124
|
+
static void _init_common(mongocrypt_kms_ctx_t *kms, _mongocrypt_log_t *log, _kms_request_type_t kms_type) {
|
125
|
+
BSON_ASSERT_PARAM(kms);
|
126
|
+
|
127
|
+
if (is_kms(kms_type)) {
|
128
|
+
kms->parser = kms_kmip_response_parser_new(NULL /* reserved */);
|
129
|
+
} else {
|
130
|
+
kms->parser = kms_response_parser_new();
|
131
|
+
}
|
132
|
+
kms->log = log;
|
133
|
+
kms->status = mongocrypt_status_new();
|
134
|
+
kms->req_type = kms_type;
|
135
|
+
_mongocrypt_buffer_init(&kms->result);
|
162
136
|
}
|
163
137
|
|
164
|
-
bool
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
CLIENT_ERR ("failed to create KMS message: %s",
|
290
|
-
kms_request_get_error (kms->req));
|
291
|
-
_mongocrypt_status_append (status, ctx_with_status.status);
|
292
|
-
goto done;
|
293
|
-
}
|
294
|
-
kms->msg.len = (uint32_t) strlen ((char *) kms->msg.data);
|
295
|
-
kms->msg.owned = true;
|
296
|
-
|
297
|
-
if (key->kek.provider.aws.endpoint) {
|
298
|
-
kms->endpoint =
|
299
|
-
bson_strdup (key->kek.provider.aws.endpoint->host_and_port);
|
300
|
-
} else {
|
301
|
-
/* construct the endpoint from AWS region. */
|
302
|
-
kms->endpoint = bson_strdup_printf ("kms.%s.amazonaws.com",
|
303
|
-
key->kek.provider.aws.region);
|
304
|
-
}
|
305
|
-
_mongocrypt_apply_default_port (&kms->endpoint, DEFAULT_HTTPS_PORT);
|
306
|
-
|
307
|
-
ret = true;
|
138
|
+
bool _mongocrypt_kms_ctx_init_aws_decrypt(mongocrypt_kms_ctx_t *kms,
|
139
|
+
_mongocrypt_opts_kms_providers_t *kms_providers,
|
140
|
+
_mongocrypt_key_doc_t *key,
|
141
|
+
_mongocrypt_log_t *log,
|
142
|
+
_mongocrypt_crypto_t *crypto) {
|
143
|
+
BSON_ASSERT_PARAM(kms);
|
144
|
+
BSON_ASSERT_PARAM(key);
|
145
|
+
BSON_ASSERT_PARAM(kms_providers);
|
146
|
+
BSON_ASSERT_PARAM(crypto);
|
147
|
+
|
148
|
+
kms_request_opt_t *opt;
|
149
|
+
mongocrypt_status_t *status;
|
150
|
+
ctx_with_status_t ctx_with_status;
|
151
|
+
bool ret = false;
|
152
|
+
|
153
|
+
_init_common(kms, log, MONGOCRYPT_KMS_AWS_DECRYPT);
|
154
|
+
status = kms->status;
|
155
|
+
ctx_with_status.ctx = crypto;
|
156
|
+
ctx_with_status.status = mongocrypt_status_new();
|
157
|
+
|
158
|
+
if (!key->kek.kms_provider) {
|
159
|
+
CLIENT_ERR("no kms provider specified on key");
|
160
|
+
goto done;
|
161
|
+
}
|
162
|
+
|
163
|
+
if (MONGOCRYPT_KMS_PROVIDER_AWS != key->kek.kms_provider) {
|
164
|
+
CLIENT_ERR("expected aws kms provider");
|
165
|
+
goto done;
|
166
|
+
}
|
167
|
+
|
168
|
+
if (!key->kek.provider.aws.region) {
|
169
|
+
CLIENT_ERR("no key region provided");
|
170
|
+
goto done;
|
171
|
+
}
|
172
|
+
|
173
|
+
if (0 == (kms_providers->configured_providers & MONGOCRYPT_KMS_PROVIDER_AWS)) {
|
174
|
+
CLIENT_ERR("aws kms not configured");
|
175
|
+
goto done;
|
176
|
+
}
|
177
|
+
|
178
|
+
if (!kms_providers->aws.access_key_id) {
|
179
|
+
CLIENT_ERR("aws access key id not provided");
|
180
|
+
goto done;
|
181
|
+
}
|
182
|
+
|
183
|
+
if (!kms_providers->aws.secret_access_key) {
|
184
|
+
CLIENT_ERR("aws secret access key not provided");
|
185
|
+
goto done;
|
186
|
+
}
|
187
|
+
|
188
|
+
/* create the KMS request. */
|
189
|
+
opt = kms_request_opt_new();
|
190
|
+
BSON_ASSERT(opt);
|
191
|
+
|
192
|
+
_set_kms_crypto_hooks(crypto, &ctx_with_status, opt);
|
193
|
+
kms_request_opt_set_connection_close(opt, true);
|
194
|
+
|
195
|
+
kms->req = kms_decrypt_request_new(key->key_material.data, key->key_material.len, opt);
|
196
|
+
|
197
|
+
kms_request_opt_destroy(opt);
|
198
|
+
if (!kms_request_set_service(kms->req, "kms")) {
|
199
|
+
CLIENT_ERR("failed to set service: %s", kms_request_get_error(kms->req));
|
200
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
201
|
+
goto done;
|
202
|
+
}
|
203
|
+
|
204
|
+
if (kms_providers->aws.session_token) {
|
205
|
+
if (!kms_request_add_header_field(kms->req, "X-Amz-Security-Token", kms_providers->aws.session_token)) {
|
206
|
+
CLIENT_ERR("failed to set session token: %s", kms_request_get_error(kms->req));
|
207
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
208
|
+
goto done;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
if (kms_request_get_error(kms->req)) {
|
213
|
+
CLIENT_ERR("error constructing KMS message: %s", kms_request_get_error(kms->req));
|
214
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
215
|
+
goto done;
|
216
|
+
}
|
217
|
+
|
218
|
+
/* If an endpoint was set, override the default Host header. */
|
219
|
+
if (key->kek.provider.aws.endpoint) {
|
220
|
+
if (!kms_request_add_header_field(kms->req, "Host", key->kek.provider.aws.endpoint->host_and_port)) {
|
221
|
+
CLIENT_ERR("error constructing KMS message: %s", kms_request_get_error(kms->req));
|
222
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
223
|
+
goto done;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
if (!kms_request_set_region(kms->req, key->kek.provider.aws.region)) {
|
228
|
+
CLIENT_ERR("failed to set region: %s", kms_request_get_error(kms->req));
|
229
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
230
|
+
goto done;
|
231
|
+
}
|
232
|
+
|
233
|
+
if (!kms_request_set_access_key_id(kms->req, kms_providers->aws.access_key_id)) {
|
234
|
+
CLIENT_ERR("failed to set aws access key id: %s", kms_request_get_error(kms->req));
|
235
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
236
|
+
goto done;
|
237
|
+
}
|
238
|
+
if (!kms_request_set_secret_key(kms->req, kms_providers->aws.secret_access_key)) {
|
239
|
+
CLIENT_ERR("failed to set aws secret access key: %s", kms_request_get_error(kms->req));
|
240
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
241
|
+
goto done;
|
242
|
+
}
|
243
|
+
|
244
|
+
_mongocrypt_buffer_init(&kms->msg);
|
245
|
+
kms->msg.data = (uint8_t *)kms_request_get_signed(kms->req);
|
246
|
+
if (!kms->msg.data) {
|
247
|
+
CLIENT_ERR("failed to create KMS message: %s", kms_request_get_error(kms->req));
|
248
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
249
|
+
goto done;
|
250
|
+
}
|
251
|
+
kms->msg.len = (uint32_t)strlen((char *)kms->msg.data);
|
252
|
+
kms->msg.owned = true;
|
253
|
+
|
254
|
+
if (key->kek.provider.aws.endpoint) {
|
255
|
+
kms->endpoint = bson_strdup(key->kek.provider.aws.endpoint->host_and_port);
|
256
|
+
} else {
|
257
|
+
/* construct the endpoint from AWS region. */
|
258
|
+
kms->endpoint = bson_strdup_printf("kms.%s.amazonaws.com", key->kek.provider.aws.region);
|
259
|
+
}
|
260
|
+
_mongocrypt_apply_default_port(&kms->endpoint, DEFAULT_HTTPS_PORT);
|
261
|
+
|
262
|
+
ret = true;
|
308
263
|
done:
|
309
|
-
|
264
|
+
mongocrypt_status_destroy(ctx_with_status.status);
|
310
265
|
|
311
|
-
|
266
|
+
return ret;
|
312
267
|
}
|
313
268
|
|
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
|
-
_set_kms_crypto_hooks (crypto, &ctx_with_status, opt);
|
376
|
-
kms_request_opt_set_connection_close (opt, true);
|
377
|
-
|
378
|
-
kms->req = kms_encrypt_request_new (plaintext_key_material->data,
|
269
|
+
bool _mongocrypt_kms_ctx_init_aws_encrypt(mongocrypt_kms_ctx_t *kms,
|
270
|
+
_mongocrypt_opts_kms_providers_t *kms_providers,
|
271
|
+
_mongocrypt_ctx_opts_t *ctx_opts,
|
272
|
+
_mongocrypt_buffer_t *plaintext_key_material,
|
273
|
+
_mongocrypt_log_t *log,
|
274
|
+
_mongocrypt_crypto_t *crypto) {
|
275
|
+
BSON_ASSERT_PARAM(kms);
|
276
|
+
BSON_ASSERT_PARAM(ctx_opts);
|
277
|
+
BSON_ASSERT_PARAM(kms_providers);
|
278
|
+
BSON_ASSERT_PARAM(crypto);
|
279
|
+
BSON_ASSERT_PARAM(plaintext_key_material);
|
280
|
+
|
281
|
+
kms_request_opt_t *opt;
|
282
|
+
mongocrypt_status_t *status;
|
283
|
+
ctx_with_status_t ctx_with_status;
|
284
|
+
bool ret = false;
|
285
|
+
|
286
|
+
_init_common(kms, log, MONGOCRYPT_KMS_AWS_ENCRYPT);
|
287
|
+
status = kms->status;
|
288
|
+
ctx_with_status.ctx = crypto;
|
289
|
+
ctx_with_status.status = mongocrypt_status_new();
|
290
|
+
|
291
|
+
if (MONGOCRYPT_KMS_PROVIDER_AWS != ctx_opts->kek.kms_provider) {
|
292
|
+
CLIENT_ERR("expected aws kms provider");
|
293
|
+
goto done;
|
294
|
+
}
|
295
|
+
|
296
|
+
if (!ctx_opts->kek.provider.aws.region) {
|
297
|
+
CLIENT_ERR("no key region provided");
|
298
|
+
goto done;
|
299
|
+
}
|
300
|
+
|
301
|
+
if (!ctx_opts->kek.provider.aws.cmk) {
|
302
|
+
CLIENT_ERR("no aws cmk provided");
|
303
|
+
goto done;
|
304
|
+
}
|
305
|
+
|
306
|
+
if (0 == (kms_providers->configured_providers & MONGOCRYPT_KMS_PROVIDER_AWS)) {
|
307
|
+
CLIENT_ERR("aws kms not configured");
|
308
|
+
goto done;
|
309
|
+
}
|
310
|
+
|
311
|
+
if (!kms_providers->aws.access_key_id) {
|
312
|
+
CLIENT_ERR("aws access key id not provided");
|
313
|
+
goto done;
|
314
|
+
}
|
315
|
+
|
316
|
+
if (!kms_providers->aws.secret_access_key) {
|
317
|
+
CLIENT_ERR("aws secret access key not provided");
|
318
|
+
goto done;
|
319
|
+
}
|
320
|
+
|
321
|
+
/* create the KMS request. */
|
322
|
+
opt = kms_request_opt_new();
|
323
|
+
BSON_ASSERT(opt);
|
324
|
+
|
325
|
+
_set_kms_crypto_hooks(crypto, &ctx_with_status, opt);
|
326
|
+
kms_request_opt_set_connection_close(opt, true);
|
327
|
+
|
328
|
+
kms->req = kms_encrypt_request_new(plaintext_key_material->data,
|
379
329
|
plaintext_key_material->len,
|
380
330
|
ctx_opts->kek.provider.aws.cmk,
|
381
331
|
opt);
|
382
332
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
kms->msg.len = (uint32_t) strlen ((char *) kms->msg.data);
|
450
|
-
kms->msg.owned = true;
|
451
|
-
|
452
|
-
/* construct the endpoint */
|
453
|
-
if (ctx_opts->kek.provider.aws.endpoint) {
|
454
|
-
kms->endpoint =
|
455
|
-
bson_strdup (ctx_opts->kek.provider.aws.endpoint->host_and_port);
|
456
|
-
} else {
|
457
|
-
kms->endpoint = bson_strdup_printf ("kms.%s.amazonaws.com",
|
458
|
-
ctx_opts->kek.provider.aws.region);
|
459
|
-
}
|
460
|
-
_mongocrypt_apply_default_port (&kms->endpoint, DEFAULT_HTTPS_PORT);
|
461
|
-
|
462
|
-
ret = true;
|
333
|
+
kms_request_opt_destroy(opt);
|
334
|
+
if (!kms_request_set_service(kms->req, "kms")) {
|
335
|
+
CLIENT_ERR("failed to set service: %s", kms_request_get_error(kms->req));
|
336
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
337
|
+
goto done;
|
338
|
+
}
|
339
|
+
|
340
|
+
if (kms_providers->aws.session_token) {
|
341
|
+
if (!kms_request_add_header_field(kms->req, "X-Amz-Security-Token", kms_providers->aws.session_token)) {
|
342
|
+
CLIENT_ERR("failed to set session token: %s", kms_request_get_error(kms->req));
|
343
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
344
|
+
goto done;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
|
348
|
+
if (kms_request_get_error(kms->req)) {
|
349
|
+
CLIENT_ERR("error constructing KMS message: %s", kms_request_get_error(kms->req));
|
350
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
351
|
+
goto done;
|
352
|
+
}
|
353
|
+
|
354
|
+
/* If an endpoint was set, override the default Host header. */
|
355
|
+
if (ctx_opts->kek.provider.aws.endpoint) {
|
356
|
+
if (!kms_request_add_header_field(kms->req, "Host", ctx_opts->kek.provider.aws.endpoint->host)) {
|
357
|
+
CLIENT_ERR("error constructing KMS message: %s", kms_request_get_error(kms->req));
|
358
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
359
|
+
goto done;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
|
363
|
+
if (!kms_request_set_region(kms->req, ctx_opts->kek.provider.aws.region)) {
|
364
|
+
CLIENT_ERR("failed to set region: %s", kms_request_get_error(kms->req));
|
365
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
366
|
+
goto done;
|
367
|
+
}
|
368
|
+
|
369
|
+
if (!kms_request_set_access_key_id(kms->req, kms_providers->aws.access_key_id)) {
|
370
|
+
CLIENT_ERR("failed to set aws access key id: %s", kms_request_get_error(kms->req));
|
371
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
372
|
+
goto done;
|
373
|
+
}
|
374
|
+
if (!kms_request_set_secret_key(kms->req, kms_providers->aws.secret_access_key)) {
|
375
|
+
CLIENT_ERR("failed to set aws secret access key: %s", kms_request_get_error(kms->req));
|
376
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
377
|
+
goto done;
|
378
|
+
}
|
379
|
+
|
380
|
+
_mongocrypt_buffer_init(&kms->msg);
|
381
|
+
kms->msg.data = (uint8_t *)kms_request_get_signed(kms->req);
|
382
|
+
if (!kms->msg.data) {
|
383
|
+
CLIENT_ERR("failed to create KMS message: %s", kms_request_get_error(kms->req));
|
384
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
385
|
+
goto done;
|
386
|
+
}
|
387
|
+
kms->msg.len = (uint32_t)strlen((char *)kms->msg.data);
|
388
|
+
kms->msg.owned = true;
|
389
|
+
|
390
|
+
/* construct the endpoint */
|
391
|
+
if (ctx_opts->kek.provider.aws.endpoint) {
|
392
|
+
kms->endpoint = bson_strdup(ctx_opts->kek.provider.aws.endpoint->host_and_port);
|
393
|
+
} else {
|
394
|
+
kms->endpoint = bson_strdup_printf("kms.%s.amazonaws.com", ctx_opts->kek.provider.aws.region);
|
395
|
+
}
|
396
|
+
_mongocrypt_apply_default_port(&kms->endpoint, DEFAULT_HTTPS_PORT);
|
397
|
+
|
398
|
+
ret = true;
|
463
399
|
done:
|
464
|
-
|
465
|
-
|
400
|
+
mongocrypt_status_destroy(ctx_with_status.status);
|
401
|
+
return ret;
|
466
402
|
}
|
467
403
|
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
{
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
}
|
483
|
-
want_bytes = kms_response_parser_wants_bytes (kms->parser,
|
484
|
-
DEFAULT_MAX_KMS_BYTE_REQUEST);
|
485
|
-
BSON_ASSERT (want_bytes >= 0);
|
486
|
-
return (uint32_t) want_bytes;
|
404
|
+
uint32_t mongocrypt_kms_ctx_bytes_needed(mongocrypt_kms_ctx_t *kms) {
|
405
|
+
int want_bytes;
|
406
|
+
|
407
|
+
if (!kms) {
|
408
|
+
return 0;
|
409
|
+
}
|
410
|
+
/* TODO: an oddity of kms-message. After retrieving the result, it
|
411
|
+
* resets the parser. */
|
412
|
+
if (!mongocrypt_status_ok(kms->status) || !_mongocrypt_buffer_empty(&kms->result)) {
|
413
|
+
return 0;
|
414
|
+
}
|
415
|
+
want_bytes = kms_response_parser_wants_bytes(kms->parser, DEFAULT_MAX_KMS_BYTE_REQUEST);
|
416
|
+
BSON_ASSERT(want_bytes >= 0);
|
417
|
+
return (uint32_t)want_bytes;
|
487
418
|
}
|
488
419
|
|
489
420
|
static void
|
490
|
-
_handle_non200_http_status
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
http_status);
|
511
|
-
return;
|
512
|
-
}
|
513
|
-
|
514
|
-
CLIENT_ERR ("Error in KMS response. HTTP status=%d. Response body=\n%s",
|
515
|
-
http_status,
|
516
|
-
body);
|
421
|
+
_handle_non200_http_status(int http_status, const char *body, size_t body_len, mongocrypt_status_t *status) {
|
422
|
+
BSON_ASSERT_PARAM(body);
|
423
|
+
|
424
|
+
/* 1xx, 2xx, and 3xx HTTP status codes are not errors, but we only
|
425
|
+
* support handling 200 response. */
|
426
|
+
if (http_status < 400) {
|
427
|
+
CLIENT_ERR("Unsupported HTTP code in KMS response. HTTP status=%d. "
|
428
|
+
"Response body=\n%s",
|
429
|
+
http_status,
|
430
|
+
body);
|
431
|
+
return;
|
432
|
+
}
|
433
|
+
|
434
|
+
/* Either empty body or body containing JSON with error message. */
|
435
|
+
if (body_len == 0) {
|
436
|
+
CLIENT_ERR("Error in KMS response. HTTP status=%d. Empty body.", http_status);
|
437
|
+
return;
|
438
|
+
}
|
439
|
+
|
440
|
+
CLIENT_ERR("Error in KMS response. HTTP status=%d. Response body=\n%s", http_status, body);
|
517
441
|
}
|
518
442
|
|
519
443
|
/* An AWS KMS context has received full response. Parse out the result or error.
|
520
444
|
*/
|
521
|
-
static bool
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
body);
|
595
|
-
bson_free (result_data);
|
596
|
-
goto fail;
|
597
|
-
}
|
598
|
-
kms->result.data = result_data;
|
599
|
-
kms->result.len = (uint32_t) result_len;
|
600
|
-
kms->result.owned = true;
|
601
|
-
ret = true;
|
445
|
+
static bool _ctx_done_aws(mongocrypt_kms_ctx_t *kms, const char *json_field) {
|
446
|
+
BSON_ASSERT_PARAM(kms);
|
447
|
+
BSON_ASSERT_PARAM(json_field);
|
448
|
+
|
449
|
+
kms_response_t *response = NULL;
|
450
|
+
const char *body;
|
451
|
+
bson_t body_bson = BSON_INITIALIZER;
|
452
|
+
bool ret;
|
453
|
+
bson_error_t bson_error;
|
454
|
+
bson_iter_t iter;
|
455
|
+
uint32_t b64_strlen;
|
456
|
+
char *b64_str;
|
457
|
+
int http_status;
|
458
|
+
size_t body_len;
|
459
|
+
int result_len;
|
460
|
+
mongocrypt_status_t *status;
|
461
|
+
|
462
|
+
status = kms->status;
|
463
|
+
ret = false;
|
464
|
+
/* Parse out the {en|de}crypted result. */
|
465
|
+
http_status = kms_response_parser_status(kms->parser);
|
466
|
+
response = kms_response_parser_get_response(kms->parser);
|
467
|
+
body = kms_response_get_body(response, &body_len);
|
468
|
+
|
469
|
+
if (http_status != 200) {
|
470
|
+
_handle_non200_http_status(http_status, body, body_len, status);
|
471
|
+
goto fail;
|
472
|
+
}
|
473
|
+
|
474
|
+
/* If HTTP response succeeded (status 200) then body should contain JSON.
|
475
|
+
*/
|
476
|
+
bson_destroy(&body_bson);
|
477
|
+
if (body_len > (size_t)SSIZE_MAX) {
|
478
|
+
CLIENT_ERR("Error parsing JSON in KMS response '%s'. "
|
479
|
+
"Response body exceeds maximum supported length",
|
480
|
+
bson_error.message);
|
481
|
+
bson_init(&body_bson);
|
482
|
+
goto fail;
|
483
|
+
}
|
484
|
+
if (!bson_init_from_json(&body_bson, body, (ssize_t)body_len, &bson_error)) {
|
485
|
+
CLIENT_ERR("Error parsing JSON in KMS response '%s'. "
|
486
|
+
"HTTP status=%d. Response body=\n%s",
|
487
|
+
bson_error.message,
|
488
|
+
http_status,
|
489
|
+
body);
|
490
|
+
bson_init(&body_bson);
|
491
|
+
goto fail;
|
492
|
+
}
|
493
|
+
|
494
|
+
if (!bson_iter_init_find(&iter, &body_bson, json_field) || !BSON_ITER_HOLDS_UTF8(&iter)) {
|
495
|
+
CLIENT_ERR("KMS JSON response does not include field '%s'. HTTP status=%d. "
|
496
|
+
"Response body=\n%s",
|
497
|
+
json_field,
|
498
|
+
http_status,
|
499
|
+
body);
|
500
|
+
goto fail;
|
501
|
+
}
|
502
|
+
|
503
|
+
b64_str = (char *)bson_iter_utf8(&iter, &b64_strlen);
|
504
|
+
BSON_ASSERT(b64_str);
|
505
|
+
uint8_t *result_data = bson_malloc((size_t)b64_strlen + 1u);
|
506
|
+
BSON_ASSERT(result_data);
|
507
|
+
|
508
|
+
result_len = kms_message_b64_pton(b64_str, result_data, b64_strlen);
|
509
|
+
if (result_len < 0) {
|
510
|
+
CLIENT_ERR("Failed to base64 decode response. HTTP status=%d. Response body=\n%s", http_status, body);
|
511
|
+
bson_free(result_data);
|
512
|
+
goto fail;
|
513
|
+
}
|
514
|
+
kms->result.data = result_data;
|
515
|
+
kms->result.len = (uint32_t)result_len;
|
516
|
+
kms->result.owned = true;
|
517
|
+
ret = true;
|
602
518
|
fail:
|
603
|
-
|
604
|
-
|
605
|
-
|
519
|
+
bson_destroy(&body_bson);
|
520
|
+
kms_response_destroy(response);
|
521
|
+
return ret;
|
606
522
|
}
|
607
523
|
|
608
524
|
/* A Azure/GCP oauth KMS context has received full response. Parse out the
|
609
525
|
* bearer token or error. */
|
610
|
-
static bool
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
_mongocrypt_buffer_steal_from_bson (&kms->result, bson_body);
|
671
|
-
bson_body = NULL;
|
672
|
-
|
673
|
-
ret = true;
|
526
|
+
static bool _ctx_done_oauth(mongocrypt_kms_ctx_t *kms) {
|
527
|
+
BSON_ASSERT_PARAM(kms);
|
528
|
+
|
529
|
+
kms_response_t *response = NULL;
|
530
|
+
const char *body;
|
531
|
+
bson_t *bson_body = NULL;
|
532
|
+
bool ret;
|
533
|
+
bson_error_t bson_error;
|
534
|
+
bson_iter_t iter;
|
535
|
+
int http_status;
|
536
|
+
size_t body_len;
|
537
|
+
mongocrypt_status_t *status;
|
538
|
+
|
539
|
+
status = kms->status;
|
540
|
+
ret = false;
|
541
|
+
/* Parse out the oauth token result (or error). */
|
542
|
+
http_status = kms_response_parser_status(kms->parser);
|
543
|
+
response = kms_response_parser_get_response(kms->parser);
|
544
|
+
body = kms_response_get_body(response, &body_len);
|
545
|
+
|
546
|
+
if (body_len == 0) {
|
547
|
+
CLIENT_ERR("Empty KMS response. HTTP status=%d", http_status);
|
548
|
+
goto fail;
|
549
|
+
}
|
550
|
+
|
551
|
+
if (body_len > (size_t)SSIZE_MAX) {
|
552
|
+
CLIENT_ERR("Error parsing JSON in KMS response '%s'. "
|
553
|
+
"Response body exceeds maximum supported length",
|
554
|
+
bson_error.message);
|
555
|
+
goto fail;
|
556
|
+
}
|
557
|
+
bson_body = bson_new_from_json((const uint8_t *)body, (ssize_t)body_len, &bson_error);
|
558
|
+
if (!bson_body) {
|
559
|
+
CLIENT_ERR("Error parsing JSON in KMS response '%s'. "
|
560
|
+
"HTTP status=%d. Response body=\n%s",
|
561
|
+
bson_error.message,
|
562
|
+
http_status,
|
563
|
+
body);
|
564
|
+
goto fail;
|
565
|
+
}
|
566
|
+
|
567
|
+
if (http_status != 200) {
|
568
|
+
_handle_non200_http_status(http_status, body, body_len, status);
|
569
|
+
goto fail;
|
570
|
+
}
|
571
|
+
|
572
|
+
if (!bson_iter_init_find(&iter, bson_body, "access_token") || !BSON_ITER_HOLDS_UTF8(&iter)) {
|
573
|
+
CLIENT_ERR("Invalid KMS response. KMS JSON response does not include "
|
574
|
+
"field 'access_token'. "
|
575
|
+
"HTTP status=%d. Response body=\n%s",
|
576
|
+
http_status,
|
577
|
+
body);
|
578
|
+
goto fail;
|
579
|
+
}
|
580
|
+
|
581
|
+
/* Store the full response, to include the expiration time. */
|
582
|
+
_mongocrypt_buffer_steal_from_bson(&kms->result, bson_body);
|
583
|
+
bson_body = NULL;
|
584
|
+
|
585
|
+
ret = true;
|
674
586
|
fail:
|
675
|
-
|
676
|
-
|
677
|
-
|
587
|
+
bson_destroy(bson_body);
|
588
|
+
kms_response_destroy(response);
|
589
|
+
return ret;
|
678
590
|
}
|
679
591
|
|
680
592
|
/* An Azure oauth KMS context has received full response. Parse out the bearer
|
681
593
|
* token or error. */
|
682
|
-
static bool
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
bson_free (result_data);
|
766
|
-
goto fail;
|
767
|
-
}
|
768
|
-
|
769
|
-
kms->result.data = result_data;
|
770
|
-
kms->result.len = (uint32_t) result_len;
|
771
|
-
kms->result.owned = true;
|
772
|
-
|
773
|
-
ret = true;
|
594
|
+
static bool _ctx_done_azure_wrapkey_unwrapkey(mongocrypt_kms_ctx_t *kms) {
|
595
|
+
BSON_ASSERT_PARAM(kms);
|
596
|
+
|
597
|
+
kms_response_t *response = NULL;
|
598
|
+
const char *body;
|
599
|
+
bson_t *bson_body = NULL;
|
600
|
+
bool ret;
|
601
|
+
bson_error_t bson_error;
|
602
|
+
bson_iter_t iter;
|
603
|
+
int http_status;
|
604
|
+
size_t body_len;
|
605
|
+
mongocrypt_status_t *status;
|
606
|
+
const char *b64url_data = NULL;
|
607
|
+
uint32_t b64url_len;
|
608
|
+
char *b64_data = NULL;
|
609
|
+
uint32_t b64_len;
|
610
|
+
int result_len;
|
611
|
+
|
612
|
+
status = kms->status;
|
613
|
+
ret = false;
|
614
|
+
/* Parse out the oauth token result (or error). */
|
615
|
+
http_status = kms_response_parser_status(kms->parser);
|
616
|
+
response = kms_response_parser_get_response(kms->parser);
|
617
|
+
body = kms_response_get_body(response, &body_len);
|
618
|
+
|
619
|
+
if (body_len == 0) {
|
620
|
+
CLIENT_ERR("Empty KMS response. HTTP status=%d", http_status);
|
621
|
+
goto fail;
|
622
|
+
}
|
623
|
+
|
624
|
+
if (body_len > (size_t)SSIZE_MAX) {
|
625
|
+
CLIENT_ERR("Error parsing JSON in KMS response '%s'. "
|
626
|
+
"Response body exceeds maximum supported length",
|
627
|
+
bson_error.message);
|
628
|
+
goto fail;
|
629
|
+
}
|
630
|
+
bson_body = bson_new_from_json((const uint8_t *)body, (ssize_t)body_len, &bson_error);
|
631
|
+
if (!bson_body) {
|
632
|
+
CLIENT_ERR("Error parsing JSON in KMS response '%s'. "
|
633
|
+
"HTTP status=%d. Response body=\n%s",
|
634
|
+
bson_error.message,
|
635
|
+
http_status,
|
636
|
+
body);
|
637
|
+
goto fail;
|
638
|
+
}
|
639
|
+
|
640
|
+
if (http_status != 200) {
|
641
|
+
_handle_non200_http_status(http_status, body, body_len, status);
|
642
|
+
goto fail;
|
643
|
+
}
|
644
|
+
|
645
|
+
if (!bson_iter_init_find(&iter, bson_body, "value") || !BSON_ITER_HOLDS_UTF8(&iter)) {
|
646
|
+
CLIENT_ERR("KMS JSON response does not include field 'value'. HTTP status=%d. "
|
647
|
+
"Response body=\n%s",
|
648
|
+
http_status,
|
649
|
+
body);
|
650
|
+
goto fail;
|
651
|
+
}
|
652
|
+
|
653
|
+
b64url_data = bson_iter_utf8(&iter, &b64url_len);
|
654
|
+
BSON_ASSERT(b64url_len <= UINT32_MAX - 4u);
|
655
|
+
/* add four for padding. */
|
656
|
+
b64_len = b64url_len + 4;
|
657
|
+
b64_data = bson_malloc0(b64_len);
|
658
|
+
if (kms_message_b64url_to_b64(b64url_data, b64url_len, b64_data, b64_len) == -1) {
|
659
|
+
CLIENT_ERR("Error converting base64url to base64");
|
660
|
+
goto fail;
|
661
|
+
}
|
662
|
+
|
663
|
+
uint8_t *result_data = bson_malloc(b64_len);
|
664
|
+
BSON_ASSERT(result_data);
|
665
|
+
result_len = kms_message_b64_pton(b64_data, result_data, b64_len);
|
666
|
+
if (result_len < 0) {
|
667
|
+
CLIENT_ERR("Failed to base64 decode response. HTTP status=%d. Response body=\n%s", http_status, body);
|
668
|
+
bson_free(result_data);
|
669
|
+
goto fail;
|
670
|
+
}
|
671
|
+
|
672
|
+
kms->result.data = result_data;
|
673
|
+
kms->result.len = (uint32_t)result_len;
|
674
|
+
kms->result.owned = true;
|
675
|
+
|
676
|
+
ret = true;
|
774
677
|
fail:
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
678
|
+
bson_destroy(bson_body);
|
679
|
+
kms_response_destroy(response);
|
680
|
+
bson_free(b64_data);
|
681
|
+
return ret;
|
779
682
|
}
|
780
683
|
|
781
684
|
/* A GCP KMS context has received full response. Parse out the result or error.
|
782
685
|
*/
|
783
|
-
static bool
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
BSON_ASSERT (b64_str);
|
848
|
-
kms->result.data = kms_message_b64_to_raw (b64_str, &outlen);
|
849
|
-
BSON_ASSERT (outlen <= UINT32_MAX);
|
850
|
-
kms->result.len = (uint32_t) outlen;
|
851
|
-
kms->result.owned = true;
|
852
|
-
ret = true;
|
686
|
+
static bool _ctx_done_gcp(mongocrypt_kms_ctx_t *kms, const char *json_field) {
|
687
|
+
BSON_ASSERT_PARAM(kms);
|
688
|
+
BSON_ASSERT_PARAM(json_field);
|
689
|
+
|
690
|
+
kms_response_t *response = NULL;
|
691
|
+
const char *body;
|
692
|
+
bson_t body_bson = BSON_INITIALIZER;
|
693
|
+
bool ret;
|
694
|
+
bson_error_t bson_error;
|
695
|
+
bson_iter_t iter;
|
696
|
+
size_t outlen;
|
697
|
+
char *b64_str;
|
698
|
+
int http_status;
|
699
|
+
size_t body_len;
|
700
|
+
mongocrypt_status_t *status;
|
701
|
+
|
702
|
+
status = kms->status;
|
703
|
+
ret = false;
|
704
|
+
/* Parse out the {en|de}crypted result. */
|
705
|
+
http_status = kms_response_parser_status(kms->parser);
|
706
|
+
response = kms_response_parser_get_response(kms->parser);
|
707
|
+
body = kms_response_get_body(response, &body_len);
|
708
|
+
|
709
|
+
if (http_status != 200) {
|
710
|
+
_handle_non200_http_status(http_status, body, body_len, status);
|
711
|
+
goto fail;
|
712
|
+
}
|
713
|
+
|
714
|
+
/* If HTTP response succeeded (status 200) then body should contain JSON.
|
715
|
+
*/
|
716
|
+
bson_destroy(&body_bson);
|
717
|
+
if (body_len > (size_t)SSIZE_MAX) {
|
718
|
+
CLIENT_ERR("Error parsing JSON in KMS response '%s'. "
|
719
|
+
"Response body exceeds maximum supported length",
|
720
|
+
bson_error.message);
|
721
|
+
bson_init(&body_bson);
|
722
|
+
goto fail;
|
723
|
+
}
|
724
|
+
if (!bson_init_from_json(&body_bson, body, (ssize_t)body_len, &bson_error)) {
|
725
|
+
CLIENT_ERR("Error parsing JSON in KMS response '%s'. "
|
726
|
+
"HTTP status=%d. Response body=\n%s",
|
727
|
+
bson_error.message,
|
728
|
+
http_status,
|
729
|
+
body);
|
730
|
+
bson_init(&body_bson);
|
731
|
+
goto fail;
|
732
|
+
}
|
733
|
+
|
734
|
+
if (!bson_iter_init_find(&iter, &body_bson, json_field) || !BSON_ITER_HOLDS_UTF8(&iter)) {
|
735
|
+
CLIENT_ERR("KMS JSON response does not include field '%s'. HTTP status=%d. "
|
736
|
+
"Response body=\n%s",
|
737
|
+
json_field,
|
738
|
+
http_status,
|
739
|
+
body);
|
740
|
+
goto fail;
|
741
|
+
}
|
742
|
+
|
743
|
+
b64_str = (char *)bson_iter_utf8(&iter, NULL);
|
744
|
+
BSON_ASSERT(b64_str);
|
745
|
+
kms->result.data = kms_message_b64_to_raw(b64_str, &outlen);
|
746
|
+
BSON_ASSERT(outlen <= UINT32_MAX);
|
747
|
+
kms->result.len = (uint32_t)outlen;
|
748
|
+
kms->result.owned = true;
|
749
|
+
ret = true;
|
853
750
|
fail:
|
854
|
-
|
855
|
-
|
856
|
-
|
751
|
+
bson_destroy(&body_bson);
|
752
|
+
kms_response_destroy(response);
|
753
|
+
return ret;
|
857
754
|
}
|
858
755
|
|
859
|
-
static bool
|
860
|
-
|
861
|
-
{
|
862
|
-
BSON_ASSERT_PARAM (kms_ctx);
|
863
|
-
|
864
|
-
kms_response_t *res = NULL;
|
865
|
-
|
866
|
-
mongocrypt_status_t *status = kms_ctx->status;
|
867
|
-
bool ret = false;
|
868
|
-
char *uid;
|
869
|
-
|
870
|
-
res = kms_response_parser_get_response (kms_ctx->parser);
|
871
|
-
if (!res) {
|
872
|
-
CLIENT_ERR ("Error getting KMIP response: %s",
|
873
|
-
kms_response_parser_error (kms_ctx->parser));
|
874
|
-
goto done;
|
875
|
-
}
|
876
|
-
|
877
|
-
uid = kms_kmip_response_get_unique_identifier (res);
|
878
|
-
if (!uid) {
|
879
|
-
CLIENT_ERR (
|
880
|
-
"Error getting UniqueIdentifer from KMIP Register response: %s",
|
881
|
-
kms_response_get_error (res));
|
882
|
-
goto done;
|
883
|
-
}
|
884
|
-
|
885
|
-
if (!_mongocrypt_buffer_steal_from_string (&kms_ctx->result, uid)) {
|
886
|
-
CLIENT_ERR ("Error storing KMS UniqueIdentifer result");
|
887
|
-
bson_free (uid);
|
888
|
-
goto done;
|
889
|
-
}
|
890
|
-
ret = true;
|
756
|
+
static bool _ctx_done_kmip_register(mongocrypt_kms_ctx_t *kms_ctx) {
|
757
|
+
BSON_ASSERT_PARAM(kms_ctx);
|
891
758
|
|
892
|
-
|
893
|
-
kms_response_destroy (res);
|
894
|
-
return ret;
|
895
|
-
}
|
759
|
+
kms_response_t *res = NULL;
|
896
760
|
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
BSON_ASSERT_PARAM (kms_ctx);
|
901
|
-
return _ctx_done_kmip_register (kms_ctx);
|
902
|
-
}
|
761
|
+
mongocrypt_status_t *status = kms_ctx->status;
|
762
|
+
bool ret = false;
|
763
|
+
char *uid;
|
903
764
|
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
secretdata = kms_kmip_response_get_secretdata (res, &secretdata_len);
|
924
|
-
if (!secretdata) {
|
925
|
-
CLIENT_ERR ("Error getting SecretData from KMIP Get response: %s",
|
926
|
-
kms_response_get_error (res));
|
927
|
-
goto done;
|
928
|
-
}
|
929
|
-
|
930
|
-
if (!_mongocrypt_buffer_steal_from_data_and_size (
|
931
|
-
&kms_ctx->result, secretdata, secretdata_len)) {
|
932
|
-
CLIENT_ERR ("Error storing KMS SecretData result");
|
933
|
-
bson_free (secretdata);
|
934
|
-
goto done;
|
935
|
-
}
|
936
|
-
|
937
|
-
ret = true;
|
765
|
+
res = kms_response_parser_get_response(kms_ctx->parser);
|
766
|
+
if (!res) {
|
767
|
+
CLIENT_ERR("Error getting KMIP response: %s", kms_response_parser_error(kms_ctx->parser));
|
768
|
+
goto done;
|
769
|
+
}
|
770
|
+
|
771
|
+
uid = kms_kmip_response_get_unique_identifier(res);
|
772
|
+
if (!uid) {
|
773
|
+
CLIENT_ERR("Error getting UniqueIdentifer from KMIP Register response: %s", kms_response_get_error(res));
|
774
|
+
goto done;
|
775
|
+
}
|
776
|
+
|
777
|
+
if (!_mongocrypt_buffer_steal_from_string(&kms_ctx->result, uid)) {
|
778
|
+
CLIENT_ERR("Error storing KMS UniqueIdentifer result");
|
779
|
+
bson_free(uid);
|
780
|
+
goto done;
|
781
|
+
}
|
782
|
+
ret = true;
|
938
783
|
|
939
784
|
done:
|
940
|
-
|
941
|
-
|
785
|
+
kms_response_destroy(res);
|
786
|
+
return ret;
|
942
787
|
}
|
943
788
|
|
944
|
-
bool
|
945
|
-
|
946
|
-
|
947
|
-
if (!kms) {
|
948
|
-
return false;
|
949
|
-
}
|
950
|
-
|
951
|
-
mongocrypt_status_t *status = kms->status;
|
952
|
-
if (!mongocrypt_status_ok (status)) {
|
953
|
-
return false;
|
954
|
-
}
|
955
|
-
|
956
|
-
if (!bytes) {
|
957
|
-
CLIENT_ERR ("argument 'bytes' is required");
|
958
|
-
return false;
|
959
|
-
}
|
960
|
-
|
961
|
-
if (0 == bytes->len) {
|
962
|
-
CLIENT_ERR ("argument 'bytes' cannot be empty");
|
963
|
-
return false;
|
964
|
-
}
|
965
|
-
|
966
|
-
if (bytes->len > mongocrypt_kms_ctx_bytes_needed (kms)) {
|
967
|
-
CLIENT_ERR ("KMS response fed too much data");
|
968
|
-
return false;
|
969
|
-
}
|
970
|
-
|
971
|
-
if (kms->log && kms->log->trace_enabled) {
|
972
|
-
_mongocrypt_log (kms->log,
|
973
|
-
MONGOCRYPT_LOG_LEVEL_TRACE,
|
974
|
-
"%s (%s=\"%.*s\")",
|
975
|
-
BSON_FUNC,
|
976
|
-
"bytes",
|
977
|
-
mongocrypt_binary_len (bytes),
|
978
|
-
mongocrypt_binary_data (bytes));
|
979
|
-
}
|
980
|
-
|
981
|
-
if (!kms_response_parser_feed (kms->parser, bytes->data, bytes->len)) {
|
982
|
-
if (is_kms (kms->req_type)) {
|
983
|
-
/* The KMIP response parser does not suport kms_response_parser_status.
|
984
|
-
* Only report the error string. */
|
985
|
-
CLIENT_ERR ("KMS response parser error with error: '%s'",
|
986
|
-
kms_response_parser_error (kms->parser));
|
987
|
-
} else {
|
988
|
-
CLIENT_ERR ("KMS response parser error with status %d, error: '%s'",
|
989
|
-
kms_response_parser_status (kms->parser),
|
990
|
-
kms_response_parser_error (kms->parser));
|
991
|
-
}
|
992
|
-
|
993
|
-
return false;
|
994
|
-
}
|
995
|
-
|
996
|
-
if (0 == mongocrypt_kms_ctx_bytes_needed (kms)) {
|
997
|
-
switch (kms->req_type) {
|
998
|
-
default:
|
999
|
-
CLIENT_ERR ("Unknown request type");
|
1000
|
-
return false;
|
1001
|
-
case MONGOCRYPT_KMS_AWS_ENCRYPT:
|
1002
|
-
return _ctx_done_aws (kms, "CiphertextBlob");
|
1003
|
-
case MONGOCRYPT_KMS_AWS_DECRYPT:
|
1004
|
-
return _ctx_done_aws (kms, "Plaintext");
|
1005
|
-
case MONGOCRYPT_KMS_AZURE_OAUTH:
|
1006
|
-
return _ctx_done_oauth (kms);
|
1007
|
-
case MONGOCRYPT_KMS_AZURE_WRAPKEY:
|
1008
|
-
return _ctx_done_azure_wrapkey_unwrapkey (kms);
|
1009
|
-
case MONGOCRYPT_KMS_AZURE_UNWRAPKEY:
|
1010
|
-
return _ctx_done_azure_wrapkey_unwrapkey (kms);
|
1011
|
-
case MONGOCRYPT_KMS_GCP_OAUTH:
|
1012
|
-
return _ctx_done_oauth (kms);
|
1013
|
-
case MONGOCRYPT_KMS_GCP_ENCRYPT:
|
1014
|
-
return _ctx_done_gcp (kms, "ciphertext");
|
1015
|
-
case MONGOCRYPT_KMS_GCP_DECRYPT:
|
1016
|
-
return _ctx_done_gcp (kms, "plaintext");
|
1017
|
-
case MONGOCRYPT_KMS_KMIP_REGISTER:
|
1018
|
-
return _ctx_done_kmip_register (kms);
|
1019
|
-
case MONGOCRYPT_KMS_KMIP_ACTIVATE:
|
1020
|
-
return _ctx_done_kmip_activate (kms);
|
1021
|
-
case MONGOCRYPT_KMS_KMIP_GET:
|
1022
|
-
return _ctx_done_kmip_get (kms);
|
1023
|
-
}
|
1024
|
-
}
|
1025
|
-
return true;
|
789
|
+
static bool _ctx_done_kmip_activate(mongocrypt_kms_ctx_t *kms_ctx) {
|
790
|
+
BSON_ASSERT_PARAM(kms_ctx);
|
791
|
+
return _ctx_done_kmip_register(kms_ctx);
|
1026
792
|
}
|
1027
793
|
|
794
|
+
static bool _ctx_done_kmip_get(mongocrypt_kms_ctx_t *kms_ctx) {
|
795
|
+
BSON_ASSERT_PARAM(kms_ctx);
|
1028
796
|
|
1029
|
-
|
1030
|
-
_mongocrypt_kms_ctx_result (mongocrypt_kms_ctx_t *kms,
|
1031
|
-
_mongocrypt_buffer_t *out)
|
1032
|
-
{
|
1033
|
-
BSON_ASSERT_PARAM (kms);
|
1034
|
-
BSON_ASSERT_PARAM (out);
|
797
|
+
kms_response_t *res = NULL;
|
1035
798
|
|
1036
|
-
|
799
|
+
mongocrypt_status_t *status = kms_ctx->status;
|
800
|
+
bool ret = false;
|
801
|
+
uint8_t *secretdata;
|
802
|
+
size_t secretdata_len;
|
1037
803
|
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
804
|
+
res = kms_response_parser_get_response(kms_ctx->parser);
|
805
|
+
if (!res) {
|
806
|
+
CLIENT_ERR("Error getting KMIP response: %s", kms_response_parser_error(kms_ctx->parser));
|
807
|
+
goto done;
|
808
|
+
}
|
1042
809
|
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
810
|
+
secretdata = kms_kmip_response_get_secretdata(res, &secretdata_len);
|
811
|
+
if (!secretdata) {
|
812
|
+
CLIENT_ERR("Error getting SecretData from KMIP Get response: %s", kms_response_get_error(res));
|
813
|
+
goto done;
|
814
|
+
}
|
1046
815
|
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
816
|
+
if (!_mongocrypt_buffer_steal_from_data_and_size(&kms_ctx->result, secretdata, secretdata_len)) {
|
817
|
+
CLIENT_ERR("Error storing KMS SecretData result");
|
818
|
+
bson_free(secretdata);
|
819
|
+
goto done;
|
820
|
+
}
|
1051
821
|
|
1052
|
-
|
1053
|
-
out->data = kms->result.data;
|
1054
|
-
out->len = kms->result.len;
|
1055
|
-
return true;
|
1056
|
-
}
|
822
|
+
ret = true;
|
1057
823
|
|
824
|
+
done:
|
825
|
+
kms_response_destroy(res);
|
826
|
+
return ret;
|
827
|
+
}
|
1058
828
|
|
1059
|
-
bool
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
829
|
+
bool mongocrypt_kms_ctx_feed(mongocrypt_kms_ctx_t *kms, mongocrypt_binary_t *bytes) {
|
830
|
+
if (!kms) {
|
831
|
+
return false;
|
832
|
+
}
|
833
|
+
|
834
|
+
mongocrypt_status_t *status = kms->status;
|
835
|
+
if (!mongocrypt_status_ok(status)) {
|
836
|
+
return false;
|
837
|
+
}
|
838
|
+
|
839
|
+
if (!bytes) {
|
840
|
+
CLIENT_ERR("argument 'bytes' is required");
|
841
|
+
return false;
|
842
|
+
}
|
843
|
+
|
844
|
+
if (0 == bytes->len) {
|
845
|
+
CLIENT_ERR("argument 'bytes' cannot be empty");
|
846
|
+
return false;
|
847
|
+
}
|
848
|
+
|
849
|
+
if (bytes->len > mongocrypt_kms_ctx_bytes_needed(kms)) {
|
850
|
+
CLIENT_ERR("KMS response fed too much data");
|
851
|
+
return false;
|
852
|
+
}
|
853
|
+
|
854
|
+
if (kms->log && kms->log->trace_enabled) {
|
855
|
+
_mongocrypt_log(kms->log,
|
856
|
+
MONGOCRYPT_LOG_LEVEL_TRACE,
|
857
|
+
"%s (%s=\"%.*s\")",
|
858
|
+
BSON_FUNC,
|
859
|
+
"bytes",
|
860
|
+
mongocrypt_binary_len(bytes),
|
861
|
+
mongocrypt_binary_data(bytes));
|
862
|
+
}
|
863
|
+
|
864
|
+
if (!kms_response_parser_feed(kms->parser, bytes->data, bytes->len)) {
|
865
|
+
if (is_kms(kms->req_type)) {
|
866
|
+
/* The KMIP response parser does not suport kms_response_parser_status.
|
867
|
+
* Only report the error string. */
|
868
|
+
CLIENT_ERR("KMS response parser error with error: '%s'", kms_response_parser_error(kms->parser));
|
869
|
+
} else {
|
870
|
+
CLIENT_ERR("KMS response parser error with status %d, error: '%s'",
|
871
|
+
kms_response_parser_status(kms->parser),
|
872
|
+
kms_response_parser_error(kms->parser));
|
873
|
+
}
|
874
|
+
|
875
|
+
return false;
|
876
|
+
}
|
877
|
+
|
878
|
+
if (0 == mongocrypt_kms_ctx_bytes_needed(kms)) {
|
879
|
+
switch (kms->req_type) {
|
880
|
+
default: CLIENT_ERR("Unknown request type"); return false;
|
881
|
+
case MONGOCRYPT_KMS_AWS_ENCRYPT: return _ctx_done_aws(kms, "CiphertextBlob");
|
882
|
+
case MONGOCRYPT_KMS_AWS_DECRYPT: return _ctx_done_aws(kms, "Plaintext");
|
883
|
+
case MONGOCRYPT_KMS_AZURE_OAUTH: return _ctx_done_oauth(kms);
|
884
|
+
case MONGOCRYPT_KMS_AZURE_WRAPKEY: return _ctx_done_azure_wrapkey_unwrapkey(kms);
|
885
|
+
case MONGOCRYPT_KMS_AZURE_UNWRAPKEY: return _ctx_done_azure_wrapkey_unwrapkey(kms);
|
886
|
+
case MONGOCRYPT_KMS_GCP_OAUTH: return _ctx_done_oauth(kms);
|
887
|
+
case MONGOCRYPT_KMS_GCP_ENCRYPT: return _ctx_done_gcp(kms, "ciphertext");
|
888
|
+
case MONGOCRYPT_KMS_GCP_DECRYPT: return _ctx_done_gcp(kms, "plaintext");
|
889
|
+
case MONGOCRYPT_KMS_KMIP_REGISTER: return _ctx_done_kmip_register(kms);
|
890
|
+
case MONGOCRYPT_KMS_KMIP_ACTIVATE: return _ctx_done_kmip_activate(kms);
|
891
|
+
case MONGOCRYPT_KMS_KMIP_GET: return _ctx_done_kmip_get(kms);
|
892
|
+
}
|
893
|
+
}
|
894
|
+
return true;
|
1074
895
|
}
|
1075
896
|
|
897
|
+
bool _mongocrypt_kms_ctx_result(mongocrypt_kms_ctx_t *kms, _mongocrypt_buffer_t *out) {
|
898
|
+
BSON_ASSERT_PARAM(kms);
|
899
|
+
BSON_ASSERT_PARAM(out);
|
900
|
+
|
901
|
+
mongocrypt_status_t *status = kms->status;
|
1076
902
|
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
903
|
+
/* If we have no status, we were never initialized */
|
904
|
+
if (!status) {
|
905
|
+
return false;
|
906
|
+
}
|
907
|
+
|
908
|
+
if (!mongocrypt_status_ok(status)) {
|
909
|
+
return false;
|
910
|
+
}
|
911
|
+
|
912
|
+
if (mongocrypt_kms_ctx_bytes_needed(kms) > 0) {
|
913
|
+
CLIENT_ERR("KMS response unfinished");
|
914
|
+
return false;
|
915
|
+
}
|
916
|
+
|
917
|
+
_mongocrypt_buffer_init(out);
|
918
|
+
out->data = kms->result.data;
|
919
|
+
out->len = kms->result.len;
|
920
|
+
return true;
|
1093
921
|
}
|
1094
922
|
|
923
|
+
bool mongocrypt_kms_ctx_status(mongocrypt_kms_ctx_t *kms, mongocrypt_status_t *status_out) {
|
924
|
+
if (!kms) {
|
925
|
+
return false;
|
926
|
+
}
|
927
|
+
|
928
|
+
if (!status_out) {
|
929
|
+
mongocrypt_status_t *status = kms->status;
|
930
|
+
CLIENT_ERR("argument 'status' is required");
|
931
|
+
return false;
|
932
|
+
}
|
933
|
+
_mongocrypt_status_copy_to(kms->status, status_out);
|
934
|
+
return mongocrypt_status_ok(status_out);
|
935
|
+
}
|
1095
936
|
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
return true;
|
937
|
+
void _mongocrypt_kms_ctx_cleanup(mongocrypt_kms_ctx_t *kms) {
|
938
|
+
if (!kms) {
|
939
|
+
return;
|
940
|
+
}
|
941
|
+
if (kms->req) {
|
942
|
+
kms_request_destroy(kms->req);
|
943
|
+
}
|
944
|
+
if (kms->parser) {
|
945
|
+
kms_response_parser_destroy(kms->parser);
|
946
|
+
}
|
947
|
+
mongocrypt_status_destroy(kms->status);
|
948
|
+
_mongocrypt_buffer_cleanup(&kms->msg);
|
949
|
+
_mongocrypt_buffer_cleanup(&kms->result);
|
950
|
+
bson_free(kms->endpoint);
|
1111
951
|
}
|
1112
952
|
|
953
|
+
bool mongocrypt_kms_ctx_message(mongocrypt_kms_ctx_t *kms, mongocrypt_binary_t *msg) {
|
954
|
+
if (!kms) {
|
955
|
+
return false;
|
956
|
+
}
|
957
|
+
|
958
|
+
if (!msg) {
|
959
|
+
mongocrypt_status_t *status = kms->status;
|
960
|
+
CLIENT_ERR("argument 'msg' is required");
|
961
|
+
return false;
|
962
|
+
}
|
963
|
+
msg->data = kms->msg.data;
|
964
|
+
msg->len = kms->msg.len;
|
965
|
+
return true;
|
966
|
+
}
|
1113
967
|
|
1114
|
-
bool
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
*endpoint = kms->endpoint;
|
1126
|
-
return true;
|
968
|
+
bool mongocrypt_kms_ctx_endpoint(mongocrypt_kms_ctx_t *kms, const char **endpoint) {
|
969
|
+
if (!kms) {
|
970
|
+
return false;
|
971
|
+
}
|
972
|
+
if (!endpoint) {
|
973
|
+
mongocrypt_status_t *status = kms->status;
|
974
|
+
CLIENT_ERR("argument 'endpoint' is required");
|
975
|
+
return false;
|
976
|
+
}
|
977
|
+
*endpoint = kms->endpoint;
|
978
|
+
return true;
|
1127
979
|
}
|
1128
980
|
|
1129
|
-
bool
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
BSON_ASSERT (opt);
|
1173
|
-
kms_request_opt_set_connection_close (opt, true);
|
1174
|
-
kms_request_opt_set_provider (opt, KMS_REQUEST_PROVIDER_AZURE);
|
1175
|
-
kms->req = kms_azure_request_oauth_new (hostname,
|
981
|
+
bool _mongocrypt_kms_ctx_init_azure_auth(mongocrypt_kms_ctx_t *kms,
|
982
|
+
_mongocrypt_log_t *log,
|
983
|
+
_mongocrypt_opts_kms_providers_t *kms_providers,
|
984
|
+
_mongocrypt_endpoint_t *key_vault_endpoint) {
|
985
|
+
BSON_ASSERT_PARAM(kms);
|
986
|
+
BSON_ASSERT_PARAM(kms_providers);
|
987
|
+
|
988
|
+
kms_request_opt_t *opt = NULL;
|
989
|
+
mongocrypt_status_t *status;
|
990
|
+
_mongocrypt_endpoint_t *identity_platform_endpoint;
|
991
|
+
char *scope = NULL;
|
992
|
+
const char *hostname;
|
993
|
+
char *request_string;
|
994
|
+
bool ret = false;
|
995
|
+
|
996
|
+
_init_common(kms, log, MONGOCRYPT_KMS_AZURE_OAUTH);
|
997
|
+
status = kms->status;
|
998
|
+
|
999
|
+
identity_platform_endpoint = kms_providers->azure.identity_platform_endpoint;
|
1000
|
+
|
1001
|
+
if (identity_platform_endpoint) {
|
1002
|
+
kms->endpoint = bson_strdup(identity_platform_endpoint->host_and_port);
|
1003
|
+
hostname = identity_platform_endpoint->host;
|
1004
|
+
} else {
|
1005
|
+
kms->endpoint = bson_strdup("login.microsoftonline.com");
|
1006
|
+
hostname = "login.microsoftonline.com";
|
1007
|
+
}
|
1008
|
+
_mongocrypt_apply_default_port(&kms->endpoint, DEFAULT_HTTPS_PORT);
|
1009
|
+
|
1010
|
+
if (key_vault_endpoint) {
|
1011
|
+
/* Request a custom scope. It is URL encoded, like
|
1012
|
+
* https%3A%2F%2Fvault.azure.net%2F.default */
|
1013
|
+
scope = bson_strdup_printf("%s%s%s", "https%3A%2F%2F", key_vault_endpoint->domain, "%2F.default");
|
1014
|
+
} else {
|
1015
|
+
/* Default to commercial Azure endpoint. */
|
1016
|
+
scope = bson_strdup("https%3A%2F%2Fvault.azure.net%2F.default");
|
1017
|
+
}
|
1018
|
+
|
1019
|
+
opt = kms_request_opt_new();
|
1020
|
+
BSON_ASSERT(opt);
|
1021
|
+
kms_request_opt_set_connection_close(opt, true);
|
1022
|
+
kms_request_opt_set_provider(opt, KMS_REQUEST_PROVIDER_AZURE);
|
1023
|
+
kms->req = kms_azure_request_oauth_new(hostname,
|
1176
1024
|
scope,
|
1177
1025
|
kms_providers->azure.tenant_id,
|
1178
1026
|
kms_providers->azure.client_id,
|
1179
1027
|
kms_providers->azure.client_secret,
|
1180
1028
|
opt);
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
ret = true;
|
1029
|
+
if (kms_request_get_error(kms->req)) {
|
1030
|
+
CLIENT_ERR("error constructing KMS message: %s", kms_request_get_error(kms->req));
|
1031
|
+
goto fail;
|
1032
|
+
}
|
1033
|
+
|
1034
|
+
request_string = kms_request_to_string(kms->req);
|
1035
|
+
if (!request_string) {
|
1036
|
+
CLIENT_ERR("error getting Azure OAuth KMS message: %s", kms_request_get_error(kms->req));
|
1037
|
+
goto fail;
|
1038
|
+
}
|
1039
|
+
_mongocrypt_buffer_init(&kms->msg);
|
1040
|
+
kms->msg.data = (uint8_t *)request_string;
|
1041
|
+
kms->msg.len = (uint32_t)strlen(request_string);
|
1042
|
+
kms->msg.owned = true;
|
1043
|
+
|
1044
|
+
ret = true;
|
1199
1045
|
fail:
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1046
|
+
bson_free(scope);
|
1047
|
+
kms_request_opt_destroy(opt);
|
1048
|
+
return ret;
|
1203
1049
|
}
|
1204
1050
|
|
1205
|
-
bool
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
}
|
1261
|
-
_mongocrypt_buffer_init (&kms->msg);
|
1262
|
-
kms->msg.data = (uint8_t *) request_string;
|
1263
|
-
kms->msg.len = (uint32_t) strlen (request_string);
|
1264
|
-
kms->msg.owned = true;
|
1265
|
-
|
1266
|
-
ret = true;
|
1051
|
+
bool _mongocrypt_kms_ctx_init_azure_wrapkey(mongocrypt_kms_ctx_t *kms,
|
1052
|
+
_mongocrypt_log_t *log,
|
1053
|
+
_mongocrypt_opts_kms_providers_t *kms_providers,
|
1054
|
+
struct __mongocrypt_ctx_opts_t *ctx_opts,
|
1055
|
+
const char *access_token,
|
1056
|
+
_mongocrypt_buffer_t *plaintext_key_material) {
|
1057
|
+
BSON_ASSERT_PARAM(kms);
|
1058
|
+
BSON_ASSERT_PARAM(ctx_opts);
|
1059
|
+
BSON_ASSERT_PARAM(plaintext_key_material);
|
1060
|
+
|
1061
|
+
kms_request_opt_t *opt = NULL;
|
1062
|
+
mongocrypt_status_t *status;
|
1063
|
+
char *path_and_query = NULL;
|
1064
|
+
char *payload = NULL;
|
1065
|
+
const char *host;
|
1066
|
+
char *request_string;
|
1067
|
+
bool ret = false;
|
1068
|
+
|
1069
|
+
_init_common(kms, log, MONGOCRYPT_KMS_AZURE_WRAPKEY);
|
1070
|
+
status = kms->status;
|
1071
|
+
|
1072
|
+
BSON_ASSERT(ctx_opts->kek.provider.azure.key_vault_endpoint);
|
1073
|
+
|
1074
|
+
kms->endpoint = bson_strdup(ctx_opts->kek.provider.azure.key_vault_endpoint->host_and_port);
|
1075
|
+
_mongocrypt_apply_default_port(&kms->endpoint, DEFAULT_HTTPS_PORT);
|
1076
|
+
host = ctx_opts->kek.provider.azure.key_vault_endpoint->host;
|
1077
|
+
|
1078
|
+
opt = kms_request_opt_new();
|
1079
|
+
BSON_ASSERT(opt);
|
1080
|
+
kms_request_opt_set_connection_close(opt, true);
|
1081
|
+
kms_request_opt_set_provider(opt, KMS_REQUEST_PROVIDER_AZURE);
|
1082
|
+
kms->req = kms_azure_request_wrapkey_new(host,
|
1083
|
+
access_token,
|
1084
|
+
ctx_opts->kek.provider.azure.key_name,
|
1085
|
+
ctx_opts->kek.provider.azure.key_version,
|
1086
|
+
plaintext_key_material->data,
|
1087
|
+
plaintext_key_material->len,
|
1088
|
+
opt);
|
1089
|
+
|
1090
|
+
if (kms_request_get_error(kms->req)) {
|
1091
|
+
CLIENT_ERR("error constructing KMS wrapkey message: %s", kms_request_get_error(kms->req));
|
1092
|
+
goto fail;
|
1093
|
+
}
|
1094
|
+
|
1095
|
+
request_string = kms_request_to_string(kms->req);
|
1096
|
+
if (!request_string) {
|
1097
|
+
CLIENT_ERR("error getting Azure wrapkey KMS message: %s", kms_request_get_error(kms->req));
|
1098
|
+
goto fail;
|
1099
|
+
}
|
1100
|
+
_mongocrypt_buffer_init(&kms->msg);
|
1101
|
+
kms->msg.data = (uint8_t *)request_string;
|
1102
|
+
kms->msg.len = (uint32_t)strlen(request_string);
|
1103
|
+
kms->msg.owned = true;
|
1104
|
+
|
1105
|
+
ret = true;
|
1267
1106
|
fail:
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1107
|
+
kms_request_opt_destroy(opt);
|
1108
|
+
bson_free(path_and_query);
|
1109
|
+
bson_free(payload);
|
1110
|
+
return ret;
|
1272
1111
|
}
|
1273
1112
|
|
1274
|
-
bool
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
}
|
1328
|
-
_mongocrypt_buffer_init (&kms->msg);
|
1329
|
-
kms->msg.data = (uint8_t *) request_string;
|
1330
|
-
kms->msg.len = (uint32_t) strlen (request_string);
|
1331
|
-
kms->msg.owned = true;
|
1332
|
-
|
1333
|
-
ret = true;
|
1113
|
+
bool _mongocrypt_kms_ctx_init_azure_unwrapkey(mongocrypt_kms_ctx_t *kms,
|
1114
|
+
_mongocrypt_opts_kms_providers_t *kms_providers,
|
1115
|
+
const char *access_token,
|
1116
|
+
_mongocrypt_key_doc_t *key,
|
1117
|
+
_mongocrypt_log_t *log) {
|
1118
|
+
BSON_ASSERT_PARAM(kms);
|
1119
|
+
BSON_ASSERT_PARAM(key);
|
1120
|
+
|
1121
|
+
kms_request_opt_t *opt = NULL;
|
1122
|
+
mongocrypt_status_t *status;
|
1123
|
+
char *path_and_query = NULL;
|
1124
|
+
char *payload = NULL;
|
1125
|
+
const char *host;
|
1126
|
+
char *request_string;
|
1127
|
+
bool ret = false;
|
1128
|
+
|
1129
|
+
_init_common(kms, log, MONGOCRYPT_KMS_AZURE_UNWRAPKEY);
|
1130
|
+
status = kms->status;
|
1131
|
+
|
1132
|
+
BSON_ASSERT(key->kek.provider.azure.key_vault_endpoint);
|
1133
|
+
|
1134
|
+
kms->endpoint = bson_strdup(key->kek.provider.azure.key_vault_endpoint->host_and_port);
|
1135
|
+
_mongocrypt_apply_default_port(&kms->endpoint, DEFAULT_HTTPS_PORT);
|
1136
|
+
host = key->kek.provider.azure.key_vault_endpoint->host;
|
1137
|
+
|
1138
|
+
opt = kms_request_opt_new();
|
1139
|
+
BSON_ASSERT(opt);
|
1140
|
+
kms_request_opt_set_connection_close(opt, true);
|
1141
|
+
kms_request_opt_set_provider(opt, KMS_REQUEST_PROVIDER_AZURE);
|
1142
|
+
kms->req = kms_azure_request_unwrapkey_new(host,
|
1143
|
+
access_token,
|
1144
|
+
key->kek.provider.azure.key_name,
|
1145
|
+
key->kek.provider.azure.key_version,
|
1146
|
+
key->key_material.data,
|
1147
|
+
key->key_material.len,
|
1148
|
+
opt);
|
1149
|
+
|
1150
|
+
if (kms_request_get_error(kms->req)) {
|
1151
|
+
CLIENT_ERR("error constructing KMS unwrapkey message: %s", kms_request_get_error(kms->req));
|
1152
|
+
goto fail;
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
request_string = kms_request_to_string(kms->req);
|
1156
|
+
if (!request_string) {
|
1157
|
+
CLIENT_ERR("error getting Azure unwrapkey KMS message: %s", kms_request_get_error(kms->req));
|
1158
|
+
goto fail;
|
1159
|
+
}
|
1160
|
+
_mongocrypt_buffer_init(&kms->msg);
|
1161
|
+
kms->msg.data = (uint8_t *)request_string;
|
1162
|
+
kms->msg.len = (uint32_t)strlen(request_string);
|
1163
|
+
kms->msg.owned = true;
|
1164
|
+
|
1165
|
+
ret = true;
|
1334
1166
|
fail:
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1167
|
+
kms_request_opt_destroy(opt);
|
1168
|
+
bson_free(path_and_query);
|
1169
|
+
bson_free(payload);
|
1170
|
+
return ret;
|
1339
1171
|
}
|
1340
1172
|
|
1341
1173
|
#define RSAES_PKCS1_V1_5_SIGNATURE_LEN 256
|
1342
1174
|
|
1343
1175
|
/* This is the form of the callback that KMS message calls. */
|
1344
|
-
static bool
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
ret = crypt_opts->sign_rsaes_pkcs1_v1_5 (crypt_opts->sign_ctx,
|
1176
|
+
static bool _sign_rsaes_pkcs1_v1_5_trampoline(void *ctx,
|
1177
|
+
const char *private_key,
|
1178
|
+
size_t private_key_len,
|
1179
|
+
const char *input,
|
1180
|
+
size_t input_len,
|
1181
|
+
unsigned char *signature_out) {
|
1182
|
+
ctx_with_status_t *ctx_with_status;
|
1183
|
+
_mongocrypt_opts_t *crypt_opts;
|
1184
|
+
mongocrypt_binary_t private_key_bin;
|
1185
|
+
mongocrypt_binary_t input_bin;
|
1186
|
+
mongocrypt_binary_t output_bin;
|
1187
|
+
bool ret;
|
1188
|
+
|
1189
|
+
BSON_ASSERT_PARAM(ctx);
|
1190
|
+
BSON_ASSERT_PARAM(input);
|
1191
|
+
BSON_ASSERT_PARAM(private_key);
|
1192
|
+
BSON_ASSERT_PARAM(signature_out);
|
1193
|
+
|
1194
|
+
ctx_with_status = (ctx_with_status_t *)ctx;
|
1195
|
+
crypt_opts = (_mongocrypt_opts_t *)ctx_with_status->ctx;
|
1196
|
+
BSON_ASSERT(crypt_opts);
|
1197
|
+
private_key_bin.data = (uint8_t *)private_key;
|
1198
|
+
BSON_ASSERT(private_key_len <= UINT32_MAX);
|
1199
|
+
private_key_bin.len = (uint32_t)private_key_len;
|
1200
|
+
input_bin.data = (uint8_t *)input;
|
1201
|
+
BSON_ASSERT(input_len <= UINT32_MAX);
|
1202
|
+
input_bin.len = (uint32_t)input_len;
|
1203
|
+
output_bin.data = (uint8_t *)signature_out;
|
1204
|
+
output_bin.len = RSAES_PKCS1_V1_5_SIGNATURE_LEN;
|
1205
|
+
|
1206
|
+
ret = crypt_opts->sign_rsaes_pkcs1_v1_5(crypt_opts->sign_ctx,
|
1377
1207
|
&private_key_bin,
|
1378
1208
|
&input_bin,
|
1379
1209
|
&output_bin,
|
1380
1210
|
ctx_with_status->status);
|
1381
|
-
|
1211
|
+
return ret;
|
1382
1212
|
}
|
1383
1213
|
|
1384
|
-
bool
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
goto fail;
|
1460
|
-
}
|
1461
|
-
_mongocrypt_buffer_init (&kms->msg);
|
1462
|
-
kms->msg.data = (uint8_t *) request_string;
|
1463
|
-
kms->msg.len = (uint32_t) strlen (request_string);
|
1464
|
-
kms->msg.owned = true;
|
1465
|
-
|
1466
|
-
ret = true;
|
1214
|
+
bool _mongocrypt_kms_ctx_init_gcp_auth(mongocrypt_kms_ctx_t *kms,
|
1215
|
+
_mongocrypt_log_t *log,
|
1216
|
+
_mongocrypt_opts_t *crypt_opts,
|
1217
|
+
_mongocrypt_opts_kms_providers_t *kms_providers,
|
1218
|
+
_mongocrypt_endpoint_t *kms_endpoint) {
|
1219
|
+
BSON_ASSERT_PARAM(kms);
|
1220
|
+
BSON_ASSERT_PARAM(kms_providers);
|
1221
|
+
BSON_ASSERT_PARAM(crypt_opts);
|
1222
|
+
|
1223
|
+
kms_request_opt_t *opt = NULL;
|
1224
|
+
mongocrypt_status_t *status;
|
1225
|
+
_mongocrypt_endpoint_t *auth_endpoint;
|
1226
|
+
char *scope = NULL;
|
1227
|
+
char *audience = NULL;
|
1228
|
+
const char *hostname;
|
1229
|
+
char *request_string;
|
1230
|
+
bool ret = false;
|
1231
|
+
ctx_with_status_t ctx_with_status;
|
1232
|
+
|
1233
|
+
_init_common(kms, log, MONGOCRYPT_KMS_GCP_OAUTH);
|
1234
|
+
status = kms->status;
|
1235
|
+
ctx_with_status.ctx = crypt_opts;
|
1236
|
+
ctx_with_status.status = mongocrypt_status_new();
|
1237
|
+
|
1238
|
+
auth_endpoint = kms_providers->gcp.endpoint;
|
1239
|
+
if (auth_endpoint) {
|
1240
|
+
kms->endpoint = bson_strdup(auth_endpoint->host_and_port);
|
1241
|
+
hostname = auth_endpoint->host;
|
1242
|
+
audience = bson_strdup_printf("https://%s/token", auth_endpoint->host);
|
1243
|
+
} else {
|
1244
|
+
kms->endpoint = bson_strdup("oauth2.googleapis.com");
|
1245
|
+
hostname = "oauth2.googleapis.com";
|
1246
|
+
audience = bson_strdup_printf("https://oauth2.googleapis.com/token");
|
1247
|
+
}
|
1248
|
+
_mongocrypt_apply_default_port(&kms->endpoint, DEFAULT_HTTPS_PORT);
|
1249
|
+
|
1250
|
+
if (kms_endpoint) {
|
1251
|
+
/* Request a custom scope. */
|
1252
|
+
scope = bson_strdup_printf("https://www.%s/auth/cloudkms", kms_endpoint->domain);
|
1253
|
+
} else {
|
1254
|
+
scope = bson_strdup("https://www.googleapis.com/auth/cloudkms");
|
1255
|
+
}
|
1256
|
+
|
1257
|
+
opt = kms_request_opt_new();
|
1258
|
+
BSON_ASSERT(opt);
|
1259
|
+
kms_request_opt_set_connection_close(opt, true);
|
1260
|
+
kms_request_opt_set_provider(opt, KMS_REQUEST_PROVIDER_GCP);
|
1261
|
+
if (crypt_opts->sign_rsaes_pkcs1_v1_5) {
|
1262
|
+
kms_request_opt_set_crypto_hook_sign_rsaes_pkcs1_v1_5(opt, _sign_rsaes_pkcs1_v1_5_trampoline, &ctx_with_status);
|
1263
|
+
}
|
1264
|
+
kms->req = kms_gcp_request_oauth_new(hostname,
|
1265
|
+
kms_providers->gcp.email,
|
1266
|
+
audience,
|
1267
|
+
scope,
|
1268
|
+
(const char *)kms_providers->gcp.private_key.data,
|
1269
|
+
kms_providers->gcp.private_key.len,
|
1270
|
+
opt);
|
1271
|
+
if (kms_request_get_error(kms->req)) {
|
1272
|
+
CLIENT_ERR("error constructing KMS message: %s", kms_request_get_error(kms->req));
|
1273
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
1274
|
+
goto fail;
|
1275
|
+
}
|
1276
|
+
|
1277
|
+
request_string = kms_request_to_string(kms->req);
|
1278
|
+
if (!request_string) {
|
1279
|
+
CLIENT_ERR("error getting GCP OAuth KMS message: %s", kms_request_get_error(kms->req));
|
1280
|
+
_mongocrypt_status_append(status, ctx_with_status.status);
|
1281
|
+
goto fail;
|
1282
|
+
}
|
1283
|
+
_mongocrypt_buffer_init(&kms->msg);
|
1284
|
+
kms->msg.data = (uint8_t *)request_string;
|
1285
|
+
kms->msg.len = (uint32_t)strlen(request_string);
|
1286
|
+
kms->msg.owned = true;
|
1287
|
+
|
1288
|
+
ret = true;
|
1467
1289
|
fail:
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1290
|
+
bson_free(scope);
|
1291
|
+
bson_free(audience);
|
1292
|
+
kms_request_opt_destroy(opt);
|
1293
|
+
mongocrypt_status_destroy(ctx_with_status.status);
|
1294
|
+
return ret;
|
1473
1295
|
}
|
1474
1296
|
|
1475
|
-
bool
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
}
|
1539
|
-
_mongocrypt_buffer_init (&kms->msg);
|
1540
|
-
kms->msg.data = (uint8_t *) request_string;
|
1541
|
-
kms->msg.len = (uint32_t) strlen (request_string);
|
1542
|
-
kms->msg.owned = true;
|
1543
|
-
|
1544
|
-
ret = true;
|
1297
|
+
bool _mongocrypt_kms_ctx_init_gcp_encrypt(mongocrypt_kms_ctx_t *kms,
|
1298
|
+
_mongocrypt_log_t *log,
|
1299
|
+
_mongocrypt_opts_kms_providers_t *kms_providers,
|
1300
|
+
struct __mongocrypt_ctx_opts_t *ctx_opts,
|
1301
|
+
const char *access_token,
|
1302
|
+
_mongocrypt_buffer_t *plaintext_key_material) {
|
1303
|
+
BSON_ASSERT_PARAM(kms);
|
1304
|
+
BSON_ASSERT_PARAM(ctx_opts);
|
1305
|
+
BSON_ASSERT_PARAM(kms_providers);
|
1306
|
+
BSON_ASSERT_PARAM(access_token);
|
1307
|
+
BSON_ASSERT_PARAM(plaintext_key_material);
|
1308
|
+
|
1309
|
+
kms_request_opt_t *opt = NULL;
|
1310
|
+
mongocrypt_status_t *status;
|
1311
|
+
char *path_and_query = NULL;
|
1312
|
+
char *payload = NULL;
|
1313
|
+
const char *hostname;
|
1314
|
+
char *request_string;
|
1315
|
+
bool ret = false;
|
1316
|
+
|
1317
|
+
_init_common(kms, log, MONGOCRYPT_KMS_GCP_ENCRYPT);
|
1318
|
+
status = kms->status;
|
1319
|
+
|
1320
|
+
if (ctx_opts->kek.provider.gcp.endpoint) {
|
1321
|
+
kms->endpoint = bson_strdup(ctx_opts->kek.provider.gcp.endpoint->host_and_port);
|
1322
|
+
hostname = ctx_opts->kek.provider.gcp.endpoint->host;
|
1323
|
+
} else {
|
1324
|
+
kms->endpoint = bson_strdup("cloudkms.googleapis.com");
|
1325
|
+
hostname = "cloudkms.googleapis.com";
|
1326
|
+
}
|
1327
|
+
_mongocrypt_apply_default_port(&kms->endpoint, DEFAULT_HTTPS_PORT);
|
1328
|
+
|
1329
|
+
opt = kms_request_opt_new();
|
1330
|
+
BSON_ASSERT(opt);
|
1331
|
+
kms_request_opt_set_connection_close(opt, true);
|
1332
|
+
kms_request_opt_set_provider(opt, KMS_REQUEST_PROVIDER_GCP);
|
1333
|
+
kms->req = kms_gcp_request_encrypt_new(hostname,
|
1334
|
+
access_token,
|
1335
|
+
ctx_opts->kek.provider.gcp.project_id,
|
1336
|
+
ctx_opts->kek.provider.gcp.location,
|
1337
|
+
ctx_opts->kek.provider.gcp.key_ring,
|
1338
|
+
ctx_opts->kek.provider.gcp.key_name,
|
1339
|
+
ctx_opts->kek.provider.gcp.key_version,
|
1340
|
+
plaintext_key_material->data,
|
1341
|
+
plaintext_key_material->len,
|
1342
|
+
opt);
|
1343
|
+
|
1344
|
+
if (kms_request_get_error(kms->req)) {
|
1345
|
+
CLIENT_ERR("error constructing GCP KMS encrypt message: %s", kms_request_get_error(kms->req));
|
1346
|
+
goto fail;
|
1347
|
+
}
|
1348
|
+
|
1349
|
+
request_string = kms_request_to_string(kms->req);
|
1350
|
+
if (!request_string) {
|
1351
|
+
CLIENT_ERR("error getting GCP KMS encrypt KMS message: %s", kms_request_get_error(kms->req));
|
1352
|
+
goto fail;
|
1353
|
+
}
|
1354
|
+
_mongocrypt_buffer_init(&kms->msg);
|
1355
|
+
kms->msg.data = (uint8_t *)request_string;
|
1356
|
+
kms->msg.len = (uint32_t)strlen(request_string);
|
1357
|
+
kms->msg.owned = true;
|
1358
|
+
|
1359
|
+
ret = true;
|
1545
1360
|
fail:
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1361
|
+
kms_request_opt_destroy(opt);
|
1362
|
+
bson_free(path_and_query);
|
1363
|
+
bson_free(payload);
|
1364
|
+
return ret;
|
1550
1365
|
}
|
1551
1366
|
|
1552
|
-
bool
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
BSON_ASSERT (opt);
|
1588
|
-
kms_request_opt_set_connection_close (opt, true);
|
1589
|
-
kms_request_opt_set_provider (opt, KMS_REQUEST_PROVIDER_GCP);
|
1590
|
-
kms->req = kms_gcp_request_decrypt_new (hostname,
|
1367
|
+
bool _mongocrypt_kms_ctx_init_gcp_decrypt(mongocrypt_kms_ctx_t *kms,
|
1368
|
+
_mongocrypt_opts_kms_providers_t *kms_providers,
|
1369
|
+
const char *access_token,
|
1370
|
+
_mongocrypt_key_doc_t *key,
|
1371
|
+
_mongocrypt_log_t *log) {
|
1372
|
+
BSON_ASSERT_PARAM(kms);
|
1373
|
+
BSON_ASSERT_PARAM(kms_providers);
|
1374
|
+
BSON_ASSERT_PARAM(access_token);
|
1375
|
+
BSON_ASSERT_PARAM(key);
|
1376
|
+
|
1377
|
+
kms_request_opt_t *opt = NULL;
|
1378
|
+
mongocrypt_status_t *status;
|
1379
|
+
char *path_and_query = NULL;
|
1380
|
+
char *payload = NULL;
|
1381
|
+
const char *hostname;
|
1382
|
+
char *request_string;
|
1383
|
+
bool ret = false;
|
1384
|
+
|
1385
|
+
_init_common(kms, log, MONGOCRYPT_KMS_GCP_DECRYPT);
|
1386
|
+
status = kms->status;
|
1387
|
+
|
1388
|
+
if (key->kek.provider.gcp.endpoint) {
|
1389
|
+
kms->endpoint = bson_strdup(key->kek.provider.gcp.endpoint->host_and_port);
|
1390
|
+
hostname = key->kek.provider.gcp.endpoint->host;
|
1391
|
+
} else {
|
1392
|
+
kms->endpoint = bson_strdup("cloudkms.googleapis.com");
|
1393
|
+
hostname = "cloudkms.googleapis.com";
|
1394
|
+
}
|
1395
|
+
_mongocrypt_apply_default_port(&kms->endpoint, DEFAULT_HTTPS_PORT);
|
1396
|
+
|
1397
|
+
opt = kms_request_opt_new();
|
1398
|
+
BSON_ASSERT(opt);
|
1399
|
+
kms_request_opt_set_connection_close(opt, true);
|
1400
|
+
kms_request_opt_set_provider(opt, KMS_REQUEST_PROVIDER_GCP);
|
1401
|
+
kms->req = kms_gcp_request_decrypt_new(hostname,
|
1591
1402
|
access_token,
|
1592
1403
|
key->kek.provider.gcp.project_id,
|
1593
1404
|
key->kek.provider.gcp.location,
|
@@ -1597,189 +1408,163 @@ _mongocrypt_kms_ctx_init_gcp_decrypt (
|
|
1597
1408
|
key->key_material.len,
|
1598
1409
|
opt);
|
1599
1410
|
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
ret = true;
|
1411
|
+
if (kms_request_get_error(kms->req)) {
|
1412
|
+
CLIENT_ERR("error constructing GCP KMS decrypt message: %s", kms_request_get_error(kms->req));
|
1413
|
+
goto fail;
|
1414
|
+
}
|
1415
|
+
|
1416
|
+
request_string = kms_request_to_string(kms->req);
|
1417
|
+
if (!request_string) {
|
1418
|
+
CLIENT_ERR("error getting GCP KMS decrypt KMS message: %s", kms_request_get_error(kms->req));
|
1419
|
+
goto fail;
|
1420
|
+
}
|
1421
|
+
_mongocrypt_buffer_init(&kms->msg);
|
1422
|
+
kms->msg.data = (uint8_t *)request_string;
|
1423
|
+
kms->msg.len = (uint32_t)strlen(request_string);
|
1424
|
+
kms->msg.owned = true;
|
1425
|
+
|
1426
|
+
ret = true;
|
1618
1427
|
fail:
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1428
|
+
kms_request_opt_destroy(opt);
|
1429
|
+
bson_free(path_and_query);
|
1430
|
+
bson_free(payload);
|
1431
|
+
return ret;
|
1623
1432
|
}
|
1624
1433
|
|
1625
|
-
bool
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
CLIENT_ERR ("Error storing KMS request payload");
|
1659
|
-
goto done;
|
1660
|
-
}
|
1661
|
-
|
1662
|
-
ret = true;
|
1434
|
+
bool _mongocrypt_kms_ctx_init_kmip_register(mongocrypt_kms_ctx_t *kms_ctx,
|
1435
|
+
const _mongocrypt_endpoint_t *endpoint,
|
1436
|
+
const uint8_t *secretdata,
|
1437
|
+
uint32_t secretdata_len,
|
1438
|
+
_mongocrypt_log_t *log) {
|
1439
|
+
BSON_ASSERT_PARAM(kms_ctx);
|
1440
|
+
BSON_ASSERT_PARAM(endpoint);
|
1441
|
+
BSON_ASSERT_PARAM(secretdata);
|
1442
|
+
|
1443
|
+
mongocrypt_status_t *status;
|
1444
|
+
bool ret = false;
|
1445
|
+
const uint8_t *reqdata;
|
1446
|
+
size_t reqlen;
|
1447
|
+
|
1448
|
+
_init_common(kms_ctx, log, MONGOCRYPT_KMS_KMIP_REGISTER);
|
1449
|
+
status = kms_ctx->status;
|
1450
|
+
|
1451
|
+
kms_ctx->endpoint = bson_strdup(endpoint->host_and_port);
|
1452
|
+
_mongocrypt_apply_default_port(&kms_ctx->endpoint, DEFAULT_KMIP_PORT);
|
1453
|
+
kms_ctx->req = kms_kmip_request_register_secretdata_new(NULL /* reserved */, secretdata, secretdata_len);
|
1454
|
+
|
1455
|
+
if (kms_request_get_error(kms_ctx->req)) {
|
1456
|
+
CLIENT_ERR("Error creating KMIP register request: %s", kms_request_get_error(kms_ctx->req));
|
1457
|
+
goto done;
|
1458
|
+
}
|
1459
|
+
|
1460
|
+
reqdata = kms_request_to_bytes(kms_ctx->req, &reqlen);
|
1461
|
+
if (!_mongocrypt_buffer_copy_from_data_and_size(&kms_ctx->msg, reqdata, reqlen)) {
|
1462
|
+
CLIENT_ERR("Error storing KMS request payload");
|
1463
|
+
goto done;
|
1464
|
+
}
|
1465
|
+
|
1466
|
+
ret = true;
|
1663
1467
|
done:
|
1664
|
-
|
1468
|
+
return ret;
|
1665
1469
|
}
|
1666
1470
|
|
1667
|
-
bool
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
CLIENT_ERR ("Error storing KMS request payload");
|
1700
|
-
goto done;
|
1701
|
-
}
|
1702
|
-
|
1703
|
-
ret = true;
|
1471
|
+
bool _mongocrypt_kms_ctx_init_kmip_activate(mongocrypt_kms_ctx_t *kms_ctx,
|
1472
|
+
const _mongocrypt_endpoint_t *endpoint,
|
1473
|
+
const char *unique_identifier,
|
1474
|
+
_mongocrypt_log_t *log) {
|
1475
|
+
BSON_ASSERT_PARAM(kms_ctx);
|
1476
|
+
BSON_ASSERT_PARAM(endpoint);
|
1477
|
+
BSON_ASSERT_PARAM(unique_identifier);
|
1478
|
+
|
1479
|
+
mongocrypt_status_t *status;
|
1480
|
+
bool ret = false;
|
1481
|
+
size_t reqlen;
|
1482
|
+
const uint8_t *reqdata;
|
1483
|
+
|
1484
|
+
_init_common(kms_ctx, log, MONGOCRYPT_KMS_KMIP_ACTIVATE);
|
1485
|
+
status = kms_ctx->status;
|
1486
|
+
|
1487
|
+
kms_ctx->endpoint = bson_strdup(endpoint->host_and_port);
|
1488
|
+
_mongocrypt_apply_default_port(&kms_ctx->endpoint, DEFAULT_KMIP_PORT);
|
1489
|
+
kms_ctx->req = kms_kmip_request_activate_new(NULL /* reserved */, unique_identifier);
|
1490
|
+
|
1491
|
+
if (kms_request_get_error(kms_ctx->req)) {
|
1492
|
+
CLIENT_ERR("Error creating KMIP activate request: %s", kms_request_get_error(kms_ctx->req));
|
1493
|
+
goto done;
|
1494
|
+
}
|
1495
|
+
|
1496
|
+
reqdata = kms_request_to_bytes(kms_ctx->req, &reqlen);
|
1497
|
+
if (!_mongocrypt_buffer_copy_from_data_and_size(&kms_ctx->msg, reqdata, reqlen)) {
|
1498
|
+
CLIENT_ERR("Error storing KMS request payload");
|
1499
|
+
goto done;
|
1500
|
+
}
|
1501
|
+
|
1502
|
+
ret = true;
|
1704
1503
|
done:
|
1705
|
-
|
1504
|
+
return ret;
|
1706
1505
|
}
|
1707
1506
|
|
1708
|
-
bool
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
CLIENT_ERR ("Error storing KMS request payload");
|
1741
|
-
goto done;
|
1742
|
-
}
|
1743
|
-
|
1744
|
-
ret = true;
|
1507
|
+
bool _mongocrypt_kms_ctx_init_kmip_get(mongocrypt_kms_ctx_t *kms_ctx,
|
1508
|
+
const _mongocrypt_endpoint_t *endpoint,
|
1509
|
+
const char *unique_identifier,
|
1510
|
+
_mongocrypt_log_t *log) {
|
1511
|
+
BSON_ASSERT_PARAM(kms_ctx);
|
1512
|
+
BSON_ASSERT_PARAM(endpoint);
|
1513
|
+
BSON_ASSERT_PARAM(unique_identifier);
|
1514
|
+
|
1515
|
+
mongocrypt_status_t *status;
|
1516
|
+
bool ret = false;
|
1517
|
+
size_t reqlen;
|
1518
|
+
const uint8_t *reqdata;
|
1519
|
+
|
1520
|
+
_init_common(kms_ctx, log, MONGOCRYPT_KMS_KMIP_GET);
|
1521
|
+
status = kms_ctx->status;
|
1522
|
+
|
1523
|
+
kms_ctx->endpoint = bson_strdup(endpoint->host_and_port);
|
1524
|
+
_mongocrypt_apply_default_port(&kms_ctx->endpoint, DEFAULT_KMIP_PORT);
|
1525
|
+
kms_ctx->req = kms_kmip_request_get_new(NULL /* reserved */, unique_identifier);
|
1526
|
+
|
1527
|
+
if (kms_request_get_error(kms_ctx->req)) {
|
1528
|
+
CLIENT_ERR("Error creating KMIP get request: %s", kms_request_get_error(kms_ctx->req));
|
1529
|
+
goto done;
|
1530
|
+
}
|
1531
|
+
|
1532
|
+
reqdata = kms_request_to_bytes(kms_ctx->req, &reqlen);
|
1533
|
+
if (!_mongocrypt_buffer_copy_from_data_and_size(&kms_ctx->msg, reqdata, reqlen)) {
|
1534
|
+
CLIENT_ERR("Error storing KMS request payload");
|
1535
|
+
goto done;
|
1536
|
+
}
|
1537
|
+
|
1538
|
+
ret = true;
|
1745
1539
|
done:
|
1746
|
-
|
1540
|
+
return ret;
|
1747
1541
|
}
|
1748
1542
|
|
1749
|
-
static const char *
|
1750
|
-
|
1751
|
-
{
|
1752
|
-
BSON_ASSERT_PARAM (what);
|
1543
|
+
static const char *set_and_ret(const char *what, uint32_t *len) {
|
1544
|
+
BSON_ASSERT_PARAM(what);
|
1753
1545
|
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1546
|
+
if (len) {
|
1547
|
+
BSON_ASSERT(size_to_uint32(strlen(what), len));
|
1548
|
+
}
|
1549
|
+
return what;
|
1758
1550
|
}
|
1759
1551
|
|
1760
|
-
const char *
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
case MONGOCRYPT_KMS_GCP_DECRYPT:
|
1779
|
-
return set_and_ret ("gcp", len);
|
1780
|
-
case MONGOCRYPT_KMS_KMIP_REGISTER:
|
1781
|
-
case MONGOCRYPT_KMS_KMIP_ACTIVATE:
|
1782
|
-
case MONGOCRYPT_KMS_KMIP_GET:
|
1783
|
-
return set_and_ret ("kmip", len);
|
1784
|
-
}
|
1552
|
+
const char *mongocrypt_kms_ctx_get_kms_provider(mongocrypt_kms_ctx_t *kms, uint32_t *len) {
|
1553
|
+
BSON_ASSERT_PARAM(kms);
|
1554
|
+
/* len is checked in set_and_ret () before it is used */
|
1555
|
+
|
1556
|
+
switch (kms->req_type) {
|
1557
|
+
default: BSON_ASSERT(false && "unknown KMS request type");
|
1558
|
+
case MONGOCRYPT_KMS_AWS_ENCRYPT:
|
1559
|
+
case MONGOCRYPT_KMS_AWS_DECRYPT: return set_and_ret("aws", len);
|
1560
|
+
case MONGOCRYPT_KMS_AZURE_OAUTH:
|
1561
|
+
case MONGOCRYPT_KMS_AZURE_WRAPKEY:
|
1562
|
+
case MONGOCRYPT_KMS_AZURE_UNWRAPKEY: return set_and_ret("azure", len);
|
1563
|
+
case MONGOCRYPT_KMS_GCP_OAUTH:
|
1564
|
+
case MONGOCRYPT_KMS_GCP_ENCRYPT:
|
1565
|
+
case MONGOCRYPT_KMS_GCP_DECRYPT: return set_and_ret("gcp", len);
|
1566
|
+
case MONGOCRYPT_KMS_KMIP_REGISTER:
|
1567
|
+
case MONGOCRYPT_KMS_KMIP_ACTIVATE:
|
1568
|
+
case MONGOCRYPT_KMS_KMIP_GET: return set_and_ret("kmip", len);
|
1569
|
+
}
|
1785
1570
|
}
|