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.
Files changed (396) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
  4. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
  6. data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
  7. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
  14. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
  15. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
  16. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
  19. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
  20. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
  21. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
  22. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
  23. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
  24. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
  25. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
  26. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
  27. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
  28. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
  31. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
  32. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
  33. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
  34. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
  35. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
  36. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
  37. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
  38. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
  39. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
  41. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
  44. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
  45. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
  46. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
  61. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
  62. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
  63. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  64. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  65. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
  66. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  67. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  68. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  69. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  70. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  71. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  72. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  73. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  74. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  75. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  76. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  77. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
  78. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  79. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  80. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  81. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  82. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  83. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  84. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  85. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
  86. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
  87. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  88. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
  89. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
  90. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  91. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  92. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  93. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  94. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
  95. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
  96. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
  97. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  98. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
  99. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
  100. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
  101. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  102. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  103. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  104. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  105. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
  106. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  107. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  108. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  109. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  110. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  111. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  112. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  113. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
  114. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
  115. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
  116. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
  117. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
  118. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
  119. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
  120. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
  121. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
  122. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
  123. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
  124. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
  125. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  126. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  127. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
  128. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
  129. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  130. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  131. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  132. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  133. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  134. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
  135. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
  136. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  137. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  138. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  139. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  140. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  141. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  142. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  143. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
  144. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  145. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  146. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
  147. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  148. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  149. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  150. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
  151. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
  152. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
  153. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  154. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  155. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  156. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  157. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  158. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  159. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
  160. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
  161. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  162. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
  163. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
  164. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  165. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
  166. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
  194. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
  195. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  196. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
  197. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  198. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  199. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  200. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
  202. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  203. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  231. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  243. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  244. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  245. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  246. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  247. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  248. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  249. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  250. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  251. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  252. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  253. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  261. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  262. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  263. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  271. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  272. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  276. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  277. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  281. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  282. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  283. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  284. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  285. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  286. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  288. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  303. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  314. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
  315. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  316. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  317. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  318. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
  319. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  320. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  323. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
  324. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  325. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  326. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  327. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  328. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
  329. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
  330. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
  331. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
  332. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  333. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
  334. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  335. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
  336. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
  337. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  338. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  339. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
  340. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  341. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  342. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
  343. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
  344. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
  345. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
  346. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  347. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  348. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
  349. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
  350. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  351. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
  352. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
  353. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  354. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  355. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  356. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  357. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  358. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  359. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
  360. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  361. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  362. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  363. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
  364. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  365. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
  366. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
  367. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
  368. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
  369. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
  370. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
  371. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
  372. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  373. data/lib/libmongocrypt_helper/version.rb +2 -2
  374. data.tar.gz.sig +0 -0
  375. metadata +154 -26
  376. metadata.gz.sig +0 -0
  377. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  378. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  379. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  380. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  381. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  382. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  383. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  384. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  392. /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
  393. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  394. /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
  395. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  396. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -16,474 +16,397 @@
16
16
 
17
17
  #include <mongocrypt.h>
18
18
 
19
+ #include "mongocrypt-crypto-private.h"
19
20
  #include "mongocrypt-private.h"
20
21
  #include "test-mongocrypt.h"
21
- #include "mongocrypt-crypto-private.h"
22
22
 
23
- static void
24
- _init_buffer_with_count (_mongocrypt_buffer_t *out, uint32_t count)
25
- {
26
- out->len = count;
27
- out->data = bson_malloc0 (out->len);
28
- BSON_ASSERT (out->data);
23
+ static void _init_buffer_with_count(_mongocrypt_buffer_t *out, uint32_t count) {
24
+ out->len = count;
25
+ out->data = bson_malloc0(out->len);
26
+ BSON_ASSERT(out->data);
29
27
 
30
- out->owned = true;
28
+ out->owned = true;
31
29
  }
32
30
 
33
- static void
34
- _test_random_generator (_mongocrypt_tester_t *tester)
35
- {
36
- mongocrypt_t *crypt;
37
- _mongocrypt_buffer_t out;
38
- mongocrypt_status_t *status;
31
+ static void _test_random_generator(_mongocrypt_tester_t *tester) {
32
+ mongocrypt_t *crypt;
33
+ _mongocrypt_buffer_t out;
34
+ mongocrypt_status_t *status;
39
35
  #define TEST_COUNT 32
40
- int mid = TEST_COUNT / 2;
41
- char zero[TEST_COUNT];
42
-
43
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
36
+ int mid = TEST_COUNT / 2;
37
+ char zero[TEST_COUNT];
44
38
 
45
- /* _mongocrypt_random handles the case where the count size is greater
46
- * than the buffer by throwing an error. Because of that, no additional tests
47
- * for this case is needed here. */
39
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
48
40
 
49
- memset (zero, 0, TEST_COUNT);
50
- status = mongocrypt_status_new ();
51
- _init_buffer_with_count (&out, TEST_COUNT);
41
+ /* _mongocrypt_random handles the case where the count size is greater
42
+ * than the buffer by throwing an error. Because of that, no additional tests
43
+ * for this case is needed here. */
52
44
 
53
- BSON_ASSERT (_mongocrypt_random (crypt->crypto, &out, TEST_COUNT, status));
54
- BSON_ASSERT (0 != memcmp (zero, out.data, TEST_COUNT)); /* initialized */
45
+ memset(zero, 0, TEST_COUNT);
46
+ status = mongocrypt_status_new();
47
+ _init_buffer_with_count(&out, TEST_COUNT);
55
48
 
56
- mongocrypt_status_destroy (status);
57
- _mongocrypt_buffer_cleanup (&out);
49
+ BSON_ASSERT(_mongocrypt_random(crypt->crypto, &out, TEST_COUNT, status));
50
+ BSON_ASSERT(0 != memcmp(zero, out.data, TEST_COUNT)); /* initialized */
58
51
 
59
- status = mongocrypt_status_new ();
60
- _init_buffer_with_count (&out, TEST_COUNT);
52
+ mongocrypt_status_destroy(status);
53
+ _mongocrypt_buffer_cleanup(&out);
61
54
 
62
- ASSERT_FAILS_STATUS (_mongocrypt_random (crypt->crypto, &out, mid, status),
63
- status,
64
- "out should have length 16");
55
+ status = mongocrypt_status_new();
56
+ _init_buffer_with_count(&out, TEST_COUNT);
65
57
 
58
+ ASSERT_FAILS_STATUS(_mongocrypt_random(crypt->crypto, &out, mid, status), status, "out should have length 16");
66
59
 
67
- mongocrypt_status_destroy (status);
68
- _mongocrypt_buffer_cleanup (&out);
69
- mongocrypt_destroy (crypt);
60
+ mongocrypt_status_destroy(status);
61
+ _mongocrypt_buffer_cleanup(&out);
62
+ mongocrypt_destroy(crypt);
70
63
  }
71
64
 
72
-
73
- static void
74
- _test_create_data_key_with_provider (_mongocrypt_tester_t *tester,
75
- _mongocrypt_kms_provider_t provider,
76
- bool with_alt_name)
77
- {
78
- mongocrypt_t *crypt;
79
- mongocrypt_ctx_t *ctx;
80
- mongocrypt_kms_ctx_t *kms;
81
- mongocrypt_binary_t *bin;
82
- bson_t as_bson;
83
- bson_iter_t iter;
84
- _mongocrypt_buffer_t buf;
85
- int64_t created_date;
86
- const int64_t current_epoch_time_ms =
87
- 1565097975532ll; /* the time this code was written */
88
- const int64_t one_hundred_years_ms =
89
- (int64_t) 1000ll * 60ll * 60ll * 24ll * 365ll * 100ll;
90
-
91
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
92
- ctx = mongocrypt_ctx_new (crypt);
93
- if (provider == MONGOCRYPT_KMS_PROVIDER_AWS) {
94
- ASSERT_OK (
95
- mongocrypt_ctx_setopt_masterkey_aws (ctx, "region", -1, "cmk", -1),
96
- ctx);
97
- } else {
98
- ASSERT_OK (mongocrypt_ctx_setopt_masterkey_local (ctx), ctx);
99
- }
100
-
101
- if (with_alt_name) {
102
- ASSERT_OK (mongocrypt_ctx_setopt_key_alt_name (
103
- ctx, TEST_BSON ("{'keyAltName': 'b'}")),
104
- ctx);
105
- ASSERT_OK (mongocrypt_ctx_setopt_key_alt_name (
106
- ctx, TEST_BSON ("{'keyAltName': 'a'}")),
107
- ctx);
108
- }
109
-
110
- ASSERT_OK (mongocrypt_ctx_datakey_init (ctx), ctx);
111
- if (provider == MONGOCRYPT_KMS_PROVIDER_AWS) {
112
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_NEED_KMS);
113
- kms = mongocrypt_ctx_next_kms_ctx (ctx);
114
- BSON_ASSERT (kms);
115
- ASSERT_OK (mongocrypt_kms_ctx_feed (
116
- kms, TEST_FILE ("./test/data/kms-encrypt-reply.txt")),
117
- kms);
118
- BSON_ASSERT (0 == mongocrypt_kms_ctx_bytes_needed (kms));
119
- ASSERT_OK (mongocrypt_ctx_kms_done (ctx), ctx);
120
- }
121
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_READY);
122
- bin = mongocrypt_binary_new ();
123
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, bin), ctx);
124
- /* Check the BSON document created. */
125
- BSON_ASSERT (_mongocrypt_binary_to_bson (bin, &as_bson));
126
- CRYPT_TRACEF (&crypt->log, "created data key: %s\n", tmp_json (&as_bson));
127
- /* _id is a UUID */
128
- BSON_ASSERT (bson_iter_init_find (&iter, &as_bson, "_id"));
129
- BSON_ASSERT (_mongocrypt_buffer_from_binary_iter (&buf, &iter));
130
- BSON_ASSERT (buf.subtype == BSON_SUBTYPE_UUID);
131
- /* keyMaterial is a binary blob of >= KEYMATERIAL_LEN bytes. */
132
- BSON_ASSERT (bson_iter_init_find (&iter, &as_bson, "keyMaterial"));
133
- BSON_ASSERT (_mongocrypt_buffer_from_binary_iter (&buf, &iter));
134
- BSON_ASSERT (buf.subtype == BSON_SUBTYPE_BINARY);
135
- BSON_ASSERT (buf.len >= MONGOCRYPT_KEY_LEN);
136
- /* creationDate and updatedDate exist and have the same value. */
137
- BSON_ASSERT (bson_iter_init_find (&iter, &as_bson, "creationDate"));
138
- BSON_ASSERT (BSON_ITER_HOLDS_DATE_TIME (&iter));
139
- created_date = bson_iter_date_time (&iter);
140
- BSON_ASSERT (created_date > current_epoch_time_ms &&
141
- created_date < current_epoch_time_ms + one_hundred_years_ms);
142
- BSON_ASSERT (bson_iter_init_find (&iter, &as_bson, "updateDate"));
143
- BSON_ASSERT (BSON_ITER_HOLDS_DATE_TIME (&iter));
144
- BSON_ASSERT (created_date == bson_iter_date_time (&iter));
145
- if (with_alt_name) {
146
- BSON_ASSERT (bson_iter_init (&iter, &as_bson));
147
- BSON_ASSERT (bson_iter_find_descendant (&iter, "keyAltNames.0", &iter));
148
- BSON_ASSERT (BSON_ITER_HOLDS_UTF8 (&iter));
149
- BSON_ASSERT (0 == strcmp (bson_iter_utf8 (&iter, NULL), "a"));
150
- BSON_ASSERT (bson_iter_init (&iter, &as_bson));
151
- BSON_ASSERT (bson_iter_find_descendant (&iter, "keyAltNames.1", &iter));
152
- BSON_ASSERT (BSON_ITER_HOLDS_UTF8 (&iter));
153
- BSON_ASSERT (0 == strcmp (bson_iter_utf8 (&iter, NULL), "b"));
154
- BSON_ASSERT (BSON_ITER_HOLDS_UTF8 (&iter));
155
- } else {
156
- BSON_ASSERT (!bson_iter_init_find (&iter, &as_bson, "keyAltNames"));
157
- }
158
-
159
- /* masterKey matches set options. */
160
- BSON_ASSERT (bson_iter_init (&iter, &as_bson));
161
- BSON_ASSERT (bson_iter_find_descendant (&iter, "masterKey.provider", &iter));
162
- BSON_ASSERT (BSON_ITER_HOLDS_UTF8 (&iter));
163
- if (provider == MONGOCRYPT_KMS_PROVIDER_AWS) {
164
- BSON_ASSERT (0 == strcmp ("aws", bson_iter_utf8 (&iter, NULL)));
165
- BSON_ASSERT (bson_iter_init (&iter, &as_bson));
166
- BSON_ASSERT (
167
- bson_iter_find_descendant (&iter, "masterKey.region", &iter));
168
- BSON_ASSERT (BSON_ITER_HOLDS_UTF8 (&iter));
169
- BSON_ASSERT (0 == strcmp ("region", bson_iter_utf8 (&iter, NULL)));
170
- BSON_ASSERT (bson_iter_init (&iter, &as_bson));
171
- BSON_ASSERT (bson_iter_find_descendant (&iter, "masterKey.key", &iter));
172
- BSON_ASSERT (BSON_ITER_HOLDS_UTF8 (&iter));
173
- BSON_ASSERT (0 == strcmp ("cmk", bson_iter_utf8 (&iter, NULL)));
174
- } else {
175
- BSON_ASSERT (0 == strcmp ("local", bson_iter_utf8 (&iter, NULL)));
176
- }
177
- mongocrypt_binary_destroy (bin);
178
- mongocrypt_ctx_destroy (ctx);
179
- mongocrypt_destroy (crypt);
65
+ static void _test_create_data_key_with_provider(_mongocrypt_tester_t *tester,
66
+ _mongocrypt_kms_provider_t provider,
67
+ bool with_alt_name) {
68
+ mongocrypt_t *crypt;
69
+ mongocrypt_ctx_t *ctx;
70
+ mongocrypt_kms_ctx_t *kms;
71
+ mongocrypt_binary_t *bin;
72
+ bson_t as_bson;
73
+ bson_iter_t iter;
74
+ _mongocrypt_buffer_t buf;
75
+ int64_t created_date;
76
+ const int64_t current_epoch_time_ms = 1565097975532ll; /* the time this code was written */
77
+ const int64_t one_hundred_years_ms = (int64_t)1000ll * 60ll * 60ll * 24ll * 365ll * 100ll;
78
+
79
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
80
+ ctx = mongocrypt_ctx_new(crypt);
81
+ if (provider == MONGOCRYPT_KMS_PROVIDER_AWS) {
82
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, "region", -1, "cmk", -1), ctx);
83
+ } else {
84
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_local(ctx), ctx);
85
+ }
86
+
87
+ if (with_alt_name) {
88
+ ASSERT_OK(mongocrypt_ctx_setopt_key_alt_name(ctx, TEST_BSON("{'keyAltName': 'b'}")), ctx);
89
+ ASSERT_OK(mongocrypt_ctx_setopt_key_alt_name(ctx, TEST_BSON("{'keyAltName': 'a'}")), ctx);
90
+ }
91
+
92
+ ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
93
+ if (provider == MONGOCRYPT_KMS_PROVIDER_AWS) {
94
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_KMS);
95
+ kms = mongocrypt_ctx_next_kms_ctx(ctx);
96
+ BSON_ASSERT(kms);
97
+ ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/kms-encrypt-reply.txt")), kms);
98
+ BSON_ASSERT(0 == mongocrypt_kms_ctx_bytes_needed(kms));
99
+ ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
100
+ }
101
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_READY);
102
+ bin = mongocrypt_binary_new();
103
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, bin), ctx);
104
+ /* Check the BSON document created. */
105
+ BSON_ASSERT(_mongocrypt_binary_to_bson(bin, &as_bson));
106
+ CRYPT_TRACEF(&crypt->log, "created data key: %s\n", tmp_json(&as_bson));
107
+ /* _id is a UUID */
108
+ BSON_ASSERT(bson_iter_init_find(&iter, &as_bson, "_id"));
109
+ BSON_ASSERT(_mongocrypt_buffer_from_binary_iter(&buf, &iter));
110
+ BSON_ASSERT(buf.subtype == BSON_SUBTYPE_UUID);
111
+ /* keyMaterial is a binary blob of >= KEYMATERIAL_LEN bytes. */
112
+ BSON_ASSERT(bson_iter_init_find(&iter, &as_bson, "keyMaterial"));
113
+ BSON_ASSERT(_mongocrypt_buffer_from_binary_iter(&buf, &iter));
114
+ BSON_ASSERT(buf.subtype == BSON_SUBTYPE_BINARY);
115
+ BSON_ASSERT(buf.len >= MONGOCRYPT_KEY_LEN);
116
+ /* creationDate and updatedDate exist and have the same value. */
117
+ BSON_ASSERT(bson_iter_init_find(&iter, &as_bson, "creationDate"));
118
+ BSON_ASSERT(BSON_ITER_HOLDS_DATE_TIME(&iter));
119
+ created_date = bson_iter_date_time(&iter);
120
+ BSON_ASSERT(created_date > current_epoch_time_ms && created_date < current_epoch_time_ms + one_hundred_years_ms);
121
+ BSON_ASSERT(bson_iter_init_find(&iter, &as_bson, "updateDate"));
122
+ BSON_ASSERT(BSON_ITER_HOLDS_DATE_TIME(&iter));
123
+ BSON_ASSERT(created_date == bson_iter_date_time(&iter));
124
+ if (with_alt_name) {
125
+ BSON_ASSERT(bson_iter_init(&iter, &as_bson));
126
+ BSON_ASSERT(bson_iter_find_descendant(&iter, "keyAltNames.0", &iter));
127
+ BSON_ASSERT(BSON_ITER_HOLDS_UTF8(&iter));
128
+ BSON_ASSERT(0 == strcmp(bson_iter_utf8(&iter, NULL), "a"));
129
+ BSON_ASSERT(bson_iter_init(&iter, &as_bson));
130
+ BSON_ASSERT(bson_iter_find_descendant(&iter, "keyAltNames.1", &iter));
131
+ BSON_ASSERT(BSON_ITER_HOLDS_UTF8(&iter));
132
+ BSON_ASSERT(0 == strcmp(bson_iter_utf8(&iter, NULL), "b"));
133
+ BSON_ASSERT(BSON_ITER_HOLDS_UTF8(&iter));
134
+ } else {
135
+ BSON_ASSERT(!bson_iter_init_find(&iter, &as_bson, "keyAltNames"));
136
+ }
137
+
138
+ /* masterKey matches set options. */
139
+ BSON_ASSERT(bson_iter_init(&iter, &as_bson));
140
+ BSON_ASSERT(bson_iter_find_descendant(&iter, "masterKey.provider", &iter));
141
+ BSON_ASSERT(BSON_ITER_HOLDS_UTF8(&iter));
142
+ if (provider == MONGOCRYPT_KMS_PROVIDER_AWS) {
143
+ BSON_ASSERT(0 == strcmp("aws", bson_iter_utf8(&iter, NULL)));
144
+ BSON_ASSERT(bson_iter_init(&iter, &as_bson));
145
+ BSON_ASSERT(bson_iter_find_descendant(&iter, "masterKey.region", &iter));
146
+ BSON_ASSERT(BSON_ITER_HOLDS_UTF8(&iter));
147
+ BSON_ASSERT(0 == strcmp("region", bson_iter_utf8(&iter, NULL)));
148
+ BSON_ASSERT(bson_iter_init(&iter, &as_bson));
149
+ BSON_ASSERT(bson_iter_find_descendant(&iter, "masterKey.key", &iter));
150
+ BSON_ASSERT(BSON_ITER_HOLDS_UTF8(&iter));
151
+ BSON_ASSERT(0 == strcmp("cmk", bson_iter_utf8(&iter, NULL)));
152
+ } else {
153
+ BSON_ASSERT(0 == strcmp("local", bson_iter_utf8(&iter, NULL)));
154
+ }
155
+ mongocrypt_binary_destroy(bin);
156
+ mongocrypt_ctx_destroy(ctx);
157
+ mongocrypt_destroy(crypt);
180
158
  }
181
159
 
182
- static void
183
- _test_datakey_custom_endpoint (_mongocrypt_tester_t *tester)
184
- {
185
- mongocrypt_t *crypt;
186
- mongocrypt_ctx_t *ctx;
187
- mongocrypt_kms_ctx_t *kms_ctx;
188
- mongocrypt_binary_t *bin;
189
- const char *endpoint;
190
- bson_t key_bson;
191
- bson_iter_t iter;
192
-
193
- /* Success. */
194
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
195
- ctx = mongocrypt_ctx_new (crypt);
196
- ASSERT_OK (
197
- mongocrypt_ctx_setopt_masterkey_aws (ctx, "region", -1, "cmk", -1), ctx);
198
- ASSERT_OK (
199
- mongocrypt_ctx_setopt_masterkey_aws_endpoint (ctx, "example.com", -1),
200
- ctx);
201
- ASSERT_OK (mongocrypt_ctx_datakey_init (ctx), ctx);
202
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_NEED_KMS);
203
- kms_ctx = mongocrypt_ctx_next_kms_ctx (ctx);
204
- BSON_ASSERT (kms_ctx);
205
- ASSERT_OK (mongocrypt_kms_ctx_endpoint (kms_ctx, &endpoint), ctx);
206
- BSON_ASSERT (0 == strcmp ("example.com:443", endpoint));
207
- bin = mongocrypt_binary_new ();
208
- ASSERT_OK (mongocrypt_kms_ctx_message (kms_ctx, bin), ctx);
209
- BSON_ASSERT (NULL != strstr ((char *) bin->data, "Host:example.com"));
210
- ASSERT_OK (mongocrypt_kms_ctx_feed (
211
- kms_ctx, TEST_FILE ("./test/data/kms-encrypt-reply.txt")),
212
- kms_ctx);
213
- BSON_ASSERT (0 == mongocrypt_kms_ctx_bytes_needed (kms_ctx));
214
- ASSERT_OK (mongocrypt_ctx_kms_done (ctx), ctx);
215
-
216
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_READY);
217
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, bin), ctx);
218
- /* Check the BSON document created. */
219
- BSON_ASSERT (_mongocrypt_binary_to_bson (bin, &key_bson));
220
- BSON_ASSERT (bson_iter_init (&iter, &key_bson));
221
- BSON_ASSERT (bson_iter_find_descendant (&iter, "masterKey.endpoint", &iter));
222
- BSON_ASSERT (0 == strcmp (bson_iter_utf8 (&iter, NULL), "example.com"));
223
-
224
- mongocrypt_binary_destroy (bin);
225
- mongocrypt_ctx_destroy (ctx);
226
- mongocrypt_destroy (crypt);
160
+ static void _test_datakey_custom_endpoint(_mongocrypt_tester_t *tester) {
161
+ mongocrypt_t *crypt;
162
+ mongocrypt_ctx_t *ctx;
163
+ mongocrypt_kms_ctx_t *kms_ctx;
164
+ mongocrypt_binary_t *bin;
165
+ const char *endpoint;
166
+ bson_t key_bson;
167
+ bson_iter_t iter;
168
+
169
+ /* Success. */
170
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
171
+ ctx = mongocrypt_ctx_new(crypt);
172
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, "region", -1, "cmk", -1), ctx);
173
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws_endpoint(ctx, "example.com", -1), ctx);
174
+ ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
175
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_KMS);
176
+ kms_ctx = mongocrypt_ctx_next_kms_ctx(ctx);
177
+ BSON_ASSERT(kms_ctx);
178
+ ASSERT_OK(mongocrypt_kms_ctx_endpoint(kms_ctx, &endpoint), ctx);
179
+ BSON_ASSERT(0 == strcmp("example.com:443", endpoint));
180
+ bin = mongocrypt_binary_new();
181
+ ASSERT_OK(mongocrypt_kms_ctx_message(kms_ctx, bin), ctx);
182
+ BSON_ASSERT(NULL != strstr((char *)bin->data, "Host:example.com"));
183
+ ASSERT_OK(mongocrypt_kms_ctx_feed(kms_ctx, TEST_FILE("./test/data/kms-encrypt-reply.txt")), kms_ctx);
184
+ BSON_ASSERT(0 == mongocrypt_kms_ctx_bytes_needed(kms_ctx));
185
+ ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
186
+
187
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_READY);
188
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, bin), ctx);
189
+ /* Check the BSON document created. */
190
+ BSON_ASSERT(_mongocrypt_binary_to_bson(bin, &key_bson));
191
+ BSON_ASSERT(bson_iter_init(&iter, &key_bson));
192
+ BSON_ASSERT(bson_iter_find_descendant(&iter, "masterKey.endpoint", &iter));
193
+ BSON_ASSERT(0 == strcmp(bson_iter_utf8(&iter, NULL), "example.com"));
194
+
195
+ mongocrypt_binary_destroy(bin);
196
+ mongocrypt_ctx_destroy(ctx);
197
+ mongocrypt_destroy(crypt);
227
198
  }
228
199
 
229
- static void
230
- _test_datakey_kms_per_ctx_credentials (_mongocrypt_tester_t *tester)
231
- {
232
- mongocrypt_t *crypt;
233
- mongocrypt_ctx_t *ctx;
234
- mongocrypt_kms_ctx_t *kms_ctx;
235
- mongocrypt_binary_t *bin;
236
- const char *endpoint;
237
- bson_t key_bson;
238
- bson_iter_t iter;
239
-
240
- /* Success. */
241
- crypt = mongocrypt_new ();
242
- mongocrypt_setopt_use_need_kms_credentials_state (crypt);
243
- ASSERT_OK (
244
- mongocrypt_setopt_kms_providers (crypt, TEST_BSON ("{'aws': {}}")),
245
- crypt);
246
- ASSERT_OK (mongocrypt_init (crypt), crypt);
247
- ctx = mongocrypt_ctx_new (crypt);
248
- ASSERT_OK (
249
- mongocrypt_ctx_setopt_masterkey_aws (ctx, "region", -1, "cmk", -1), ctx);
250
- ASSERT_OK (
251
- mongocrypt_ctx_setopt_masterkey_aws_endpoint (ctx, "example.com", -1),
252
- ctx);
253
- ASSERT_OK (mongocrypt_ctx_datakey_init (ctx), ctx);
254
- BSON_ASSERT (
255
- mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
256
- ASSERT_OK (
257
- mongocrypt_ctx_provide_kms_providers (ctx,
258
- TEST_BSON ("{'aws':{'accessKeyId': 'example',"
259
- "'secretAccessKey': 'example'}}")), ctx);
260
- BSON_ASSERT (
261
- mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_NEED_KMS);
262
- kms_ctx = mongocrypt_ctx_next_kms_ctx (ctx);
263
- BSON_ASSERT (kms_ctx);
264
- ASSERT_OK (mongocrypt_kms_ctx_endpoint (kms_ctx, &endpoint), ctx);
265
- BSON_ASSERT (0 == strcmp ("example.com:443", endpoint));
266
- bin = mongocrypt_binary_new ();
267
- ASSERT_OK (mongocrypt_kms_ctx_message (kms_ctx, bin), ctx);
268
- BSON_ASSERT (NULL != strstr ((char *) bin->data, "Host:example.com"));
269
- ASSERT_OK (mongocrypt_kms_ctx_feed (
270
- kms_ctx, TEST_FILE ("./test/data/kms-encrypt-reply.txt")),
271
- kms_ctx);
272
- BSON_ASSERT (0 == mongocrypt_kms_ctx_bytes_needed (kms_ctx));
273
- ASSERT_OK (mongocrypt_ctx_kms_done (ctx), ctx);
274
-
275
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_READY);
276
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, bin), ctx);
277
- /* Check the BSON document created. */
278
- BSON_ASSERT (_mongocrypt_binary_to_bson (bin, &key_bson));
279
- BSON_ASSERT (bson_iter_init (&iter, &key_bson));
280
- BSON_ASSERT (bson_iter_find_descendant (&iter, "masterKey.endpoint", &iter));
281
- BSON_ASSERT (0 == strcmp (bson_iter_utf8 (&iter, NULL), "example.com"));
282
-
283
- mongocrypt_binary_destroy (bin);
284
- mongocrypt_ctx_destroy (ctx);
285
- mongocrypt_destroy (crypt);
200
+ static void _test_datakey_kms_per_ctx_credentials(_mongocrypt_tester_t *tester) {
201
+ mongocrypt_t *crypt;
202
+ mongocrypt_ctx_t *ctx;
203
+ mongocrypt_kms_ctx_t *kms_ctx;
204
+ mongocrypt_binary_t *bin;
205
+ const char *endpoint;
206
+ bson_t key_bson;
207
+ bson_iter_t iter;
208
+
209
+ /* Success. */
210
+ crypt = mongocrypt_new();
211
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
212
+ ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'aws': {}}")), crypt);
213
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
214
+ ctx = mongocrypt_ctx_new(crypt);
215
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, "region", -1, "cmk", -1), ctx);
216
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws_endpoint(ctx, "example.com", -1), ctx);
217
+ ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
218
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
219
+ ASSERT_OK(mongocrypt_ctx_provide_kms_providers(ctx,
220
+ TEST_BSON("{'aws':{'accessKeyId': 'example',"
221
+ "'secretAccessKey': 'example'}}")),
222
+ ctx);
223
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_KMS);
224
+ kms_ctx = mongocrypt_ctx_next_kms_ctx(ctx);
225
+ BSON_ASSERT(kms_ctx);
226
+ ASSERT_OK(mongocrypt_kms_ctx_endpoint(kms_ctx, &endpoint), ctx);
227
+ BSON_ASSERT(0 == strcmp("example.com:443", endpoint));
228
+ bin = mongocrypt_binary_new();
229
+ ASSERT_OK(mongocrypt_kms_ctx_message(kms_ctx, bin), ctx);
230
+ BSON_ASSERT(NULL != strstr((char *)bin->data, "Host:example.com"));
231
+ ASSERT_OK(mongocrypt_kms_ctx_feed(kms_ctx, TEST_FILE("./test/data/kms-encrypt-reply.txt")), kms_ctx);
232
+ BSON_ASSERT(0 == mongocrypt_kms_ctx_bytes_needed(kms_ctx));
233
+ ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
234
+
235
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_READY);
236
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, bin), ctx);
237
+ /* Check the BSON document created. */
238
+ BSON_ASSERT(_mongocrypt_binary_to_bson(bin, &key_bson));
239
+ BSON_ASSERT(bson_iter_init(&iter, &key_bson));
240
+ BSON_ASSERT(bson_iter_find_descendant(&iter, "masterKey.endpoint", &iter));
241
+ BSON_ASSERT(0 == strcmp(bson_iter_utf8(&iter, NULL), "example.com"));
242
+
243
+ mongocrypt_binary_destroy(bin);
244
+ mongocrypt_ctx_destroy(ctx);
245
+ mongocrypt_destroy(crypt);
286
246
  }
287
247
 
288
248
  /* Test creating a data key with "azure" when only "aws" credentials are needed.
289
249
  * Expect the context not to enter the MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS
290
250
  * state. */
291
- static void
292
- _test_datakey_kms_per_ctx_credentials_not_requested (
293
- _mongocrypt_tester_t *tester)
294
- {
295
- mongocrypt_t *crypt;
296
- mongocrypt_ctx_t *ctx;
297
-
298
- crypt = mongocrypt_new ();
299
- mongocrypt_setopt_use_need_kms_credentials_state (crypt);
300
- ASSERT_OK (mongocrypt_setopt_kms_providers (
301
- crypt,
302
- TEST_BSON ("{'aws': {}, 'azure': {'tenantId': '', 'clientId': "
303
- "'', 'clientSecret': '' }}")),
251
+ static void _test_datakey_kms_per_ctx_credentials_not_requested(_mongocrypt_tester_t *tester) {
252
+ mongocrypt_t *crypt;
253
+ mongocrypt_ctx_t *ctx;
254
+
255
+ crypt = mongocrypt_new();
256
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
257
+ ASSERT_OK(mongocrypt_setopt_kms_providers(crypt,
258
+ TEST_BSON("{'aws': {}, 'azure': {'tenantId': '', 'clientId': "
259
+ "'', 'clientSecret': '' }}")),
304
260
  crypt);
305
- ASSERT_OK (mongocrypt_init (crypt), crypt);
306
- ctx = mongocrypt_ctx_new (crypt);
307
- ASSERT_OK (mongocrypt_ctx_setopt_key_encryption_key (
308
- ctx,
309
- TEST_BSON ("{'provider': 'azure', 'keyVaultEndpoint': "
310
- "'example.vault.azure.net', 'keyName': 'test'}")),
261
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
262
+ ctx = mongocrypt_ctx_new(crypt);
263
+ ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx,
264
+ TEST_BSON("{'provider': 'azure', 'keyVaultEndpoint': "
265
+ "'example.vault.azure.net', 'keyName': 'test'}")),
311
266
  ctx);
312
- ASSERT_OK (mongocrypt_ctx_datakey_init (ctx), ctx);
313
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
267
+ ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
268
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
314
269
 
315
- mongocrypt_ctx_destroy (ctx);
316
- mongocrypt_destroy (crypt);
270
+ mongocrypt_ctx_destroy(ctx);
271
+ mongocrypt_destroy(crypt);
317
272
  }
318
273
 
319
274
  /* Test creating a data key with "local" when "local" credentials are required.
320
275
  * Expect the context to enter the MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS
321
276
  * state. */
322
- static void
323
- _test_datakey_kms_per_ctx_credentials_local (_mongocrypt_tester_t *tester)
324
- {
325
- mongocrypt_t *crypt;
326
- mongocrypt_ctx_t *ctx;
327
- mongocrypt_binary_t *bin;
328
- bson_t key_bson;
329
- bson_iter_t iter;
330
- const char *local_kek =
331
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
332
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
333
-
334
- crypt = mongocrypt_new ();
335
- mongocrypt_setopt_use_need_kms_credentials_state (crypt);
336
- ASSERT_OK (
337
- mongocrypt_setopt_kms_providers (crypt, TEST_BSON ("{'local': {}}")),
338
- crypt);
339
- ASSERT_OK (mongocrypt_init (crypt), crypt);
340
- ctx = mongocrypt_ctx_new (crypt);
341
- ASSERT_OK (mongocrypt_ctx_setopt_key_encryption_key (
342
- ctx, TEST_BSON ("{'provider': 'local' }")),
343
- ctx);
344
- ASSERT_OK (mongocrypt_ctx_datakey_init (ctx), ctx);
345
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
346
- MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
347
-
348
- ASSERT_OK (mongocrypt_ctx_provide_kms_providers (
349
- ctx,
350
- TEST_BSON ("{'local':{'key': { '$binary': {'base64': '%s', "
351
- "'subType': '00'}}}}",
352
- local_kek)),
277
+ static void _test_datakey_kms_per_ctx_credentials_local(_mongocrypt_tester_t *tester) {
278
+ mongocrypt_t *crypt;
279
+ mongocrypt_ctx_t *ctx;
280
+ mongocrypt_binary_t *bin;
281
+ bson_t key_bson;
282
+ bson_iter_t iter;
283
+ const char *local_kek = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
284
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
285
+
286
+ crypt = mongocrypt_new();
287
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
288
+ ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'local': {}}")), crypt);
289
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
290
+ ctx = mongocrypt_ctx_new(crypt);
291
+ ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx, TEST_BSON("{'provider': 'local' }")), ctx);
292
+ ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
293
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
294
+
295
+ ASSERT_OK(mongocrypt_ctx_provide_kms_providers(ctx,
296
+ TEST_BSON("{'local':{'key': { '$binary': {'base64': '%s', "
297
+ "'subType': '00'}}}}",
298
+ local_kek)),
353
299
  ctx);
354
300
 
355
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
356
- bin = mongocrypt_binary_new ();
357
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, bin), ctx);
358
- /* Check the BSON document created. */
359
- BSON_ASSERT (_mongocrypt_binary_to_bson (bin, &key_bson));
360
- BSON_ASSERT (bson_iter_init (&iter, &key_bson));
361
- BSON_ASSERT (bson_iter_find_descendant (&iter, "masterKey.provider", &iter));
362
- BSON_ASSERT (0 == strcmp (bson_iter_utf8 (&iter, NULL), "local"));
363
-
364
- mongocrypt_binary_destroy (bin);
365
- mongocrypt_ctx_destroy (ctx);
366
- mongocrypt_destroy (crypt);
301
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
302
+ bin = mongocrypt_binary_new();
303
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, bin), ctx);
304
+ /* Check the BSON document created. */
305
+ BSON_ASSERT(_mongocrypt_binary_to_bson(bin, &key_bson));
306
+ BSON_ASSERT(bson_iter_init(&iter, &key_bson));
307
+ BSON_ASSERT(bson_iter_find_descendant(&iter, "masterKey.provider", &iter));
308
+ BSON_ASSERT(0 == strcmp(bson_iter_utf8(&iter, NULL), "local"));
309
+
310
+ mongocrypt_binary_destroy(bin);
311
+ mongocrypt_ctx_destroy(ctx);
312
+ mongocrypt_destroy(crypt);
367
313
  }
368
314
 
315
+ static void _test_datakey_custom_key_material(_mongocrypt_tester_t *tester) {
316
+ const uint8_t expected_dek[MONGOCRYPT_KEY_LEN] = "0123456789abcdef"
317
+ "0123456789abcdef"
318
+ "0123456789abcdef"
319
+ "0123456789abcdef"
320
+ "0123456789abcdef"
321
+ "0123456789abcdef";
322
+
323
+ mongocrypt_t *const crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
324
+
325
+ _mongocrypt_buffer_t encrypted_dek_buf;
326
+
327
+ {
328
+ mongocrypt_ctx_t *ctx = mongocrypt_ctx_new(crypt);
329
+
330
+ /* Generate encrypted DEK using custom key material. */
331
+ {
332
+ mongocrypt_binary_t *const kek = TEST_BSON("{'provider': 'local'}");
333
+
334
+ bson_t bson;
335
+ _mongocrypt_buffer_t key_material_buf;
336
+ mongocrypt_binary_t key_material;
337
+
338
+ bson_init(&bson);
339
+ ASSERT(BSON_APPEND_BINARY(&bson, "keyMaterial", BSON_SUBTYPE_BINARY, expected_dek, MONGOCRYPT_KEY_LEN));
340
+ _mongocrypt_buffer_from_bson(&key_material_buf, &bson);
341
+ _mongocrypt_buffer_to_binary(&key_material_buf, &key_material);
369
342
 
370
- static void
371
- _test_datakey_custom_key_material (_mongocrypt_tester_t *tester)
372
- {
373
- const uint8_t expected_dek[MONGOCRYPT_KEY_LEN] = "0123456789abcdef"
374
- "0123456789abcdef"
375
- "0123456789abcdef"
376
- "0123456789abcdef"
377
- "0123456789abcdef"
378
- "0123456789abcdef";
379
-
380
- mongocrypt_t *const crypt =
381
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
382
-
383
- _mongocrypt_buffer_t encrypted_dek_buf;
384
-
385
- {
386
- mongocrypt_ctx_t *ctx = mongocrypt_ctx_new (crypt);
387
-
388
- /* Generate encrypted DEK using custom key material. */
389
- {
390
- mongocrypt_binary_t *const kek = TEST_BSON ("{'provider': 'local'}");
391
-
392
- bson_t bson;
393
- _mongocrypt_buffer_t key_material_buf;
394
- mongocrypt_binary_t key_material;
395
-
396
- bson_init (&bson);
397
- ASSERT (BSON_APPEND_BINARY (&bson,
398
- "keyMaterial",
399
- BSON_SUBTYPE_BINARY,
400
- expected_dek,
401
- MONGOCRYPT_KEY_LEN));
402
- _mongocrypt_buffer_from_bson (&key_material_buf, &bson);
403
- _mongocrypt_buffer_to_binary (&key_material_buf, &key_material);
404
-
405
- ASSERT_OK (mongocrypt_ctx_setopt_key_encryption_key (ctx, kek), ctx);
406
- ASSERT_OK (mongocrypt_ctx_setopt_key_material (ctx, &key_material),
407
- ctx);
408
- ASSERT_OK (mongocrypt_ctx_datakey_init (ctx), ctx);
409
-
410
- bson_destroy (&bson);
411
- }
412
-
413
- /* Extract encrypted DEK from datakey. */
414
- {
415
- mongocrypt_binary_t *const datakey = mongocrypt_binary_new ();
416
-
417
- bson_t bson;
418
- bson_iter_t iter;
419
- const uint8_t *binary;
420
- uint32_t len;
421
- bson_subtype_t subtype;
422
-
423
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
424
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, datakey), ctx);
425
- ASSERT (_mongocrypt_binary_to_bson (datakey, &bson));
426
-
427
- ASSERT (bson_iter_init_find (&iter, &bson, "keyMaterial"));
428
- ASSERT (BSON_ITER_HOLDS_BINARY (&iter));
429
- bson_iter_binary (&iter, &subtype, &len, &binary);
430
- ASSERT (_mongocrypt_buffer_copy_from_data_and_size (
431
- &encrypted_dek_buf, binary, len));
432
-
433
- mongocrypt_binary_destroy (datakey);
434
- }
435
-
436
- mongocrypt_ctx_destroy (ctx);
437
- }
438
-
439
- /* Decrypt key material and confirm it matches original DEK. */
440
- {
441
- _mongocrypt_buffer_t decrypted_dek_buf;
442
- mongocrypt_binary_t decrypted_dek;
443
-
444
- ASSERT (_mongocrypt_unwrap_key (crypt->crypto,
343
+ ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx, kek), ctx);
344
+ ASSERT_OK(mongocrypt_ctx_setopt_key_material(ctx, &key_material), ctx);
345
+ ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
346
+
347
+ bson_destroy(&bson);
348
+ }
349
+
350
+ /* Extract encrypted DEK from datakey. */
351
+ {
352
+ mongocrypt_binary_t *const datakey = mongocrypt_binary_new();
353
+
354
+ bson_t bson;
355
+ bson_iter_t iter;
356
+ const uint8_t *binary;
357
+ uint32_t len;
358
+ bson_subtype_t subtype;
359
+
360
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
361
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, datakey), ctx);
362
+ ASSERT(_mongocrypt_binary_to_bson(datakey, &bson));
363
+
364
+ ASSERT(bson_iter_init_find(&iter, &bson, "keyMaterial"));
365
+ ASSERT(BSON_ITER_HOLDS_BINARY(&iter));
366
+ bson_iter_binary(&iter, &subtype, &len, &binary);
367
+ ASSERT(_mongocrypt_buffer_copy_from_data_and_size(&encrypted_dek_buf, binary, len));
368
+
369
+ mongocrypt_binary_destroy(datakey);
370
+ }
371
+
372
+ mongocrypt_ctx_destroy(ctx);
373
+ }
374
+
375
+ /* Decrypt key material and confirm it matches original DEK. */
376
+ {
377
+ _mongocrypt_buffer_t decrypted_dek_buf;
378
+ mongocrypt_binary_t decrypted_dek;
379
+
380
+ ASSERT(_mongocrypt_unwrap_key(crypt->crypto,
445
381
  &crypt->opts.kms_providers.local.key,
446
382
  &encrypted_dek_buf,
447
383
  &decrypted_dek_buf,
448
384
  crypt->status));
449
385
 
450
- _mongocrypt_buffer_to_binary (&decrypted_dek_buf, &decrypted_dek);
386
+ _mongocrypt_buffer_to_binary(&decrypted_dek_buf, &decrypted_dek);
451
387
 
452
- ASSERT_CMPBYTES (expected_dek,
453
- MONGOCRYPT_KEY_LEN,
454
- decrypted_dek.data,
455
- decrypted_dek.len);
388
+ ASSERT_CMPBYTES(expected_dek, MONGOCRYPT_KEY_LEN, decrypted_dek.data, decrypted_dek.len);
456
389
 
457
- _mongocrypt_buffer_cleanup (&decrypted_dek_buf);
458
- }
390
+ _mongocrypt_buffer_cleanup(&decrypted_dek_buf);
391
+ }
459
392
 
460
- _mongocrypt_buffer_cleanup (&encrypted_dek_buf);
461
- mongocrypt_destroy (crypt);
393
+ _mongocrypt_buffer_cleanup(&encrypted_dek_buf);
394
+ mongocrypt_destroy(crypt);
462
395
  }
463
396
 
464
-
465
- static void
466
- _test_create_data_key (_mongocrypt_tester_t *tester)
467
- {
468
- _test_create_data_key_with_provider (
469
- tester, MONGOCRYPT_KMS_PROVIDER_AWS, false /* with_alt_name */);
470
- _test_create_data_key_with_provider (
471
- tester, MONGOCRYPT_KMS_PROVIDER_LOCAL, false /* with_alt_name */);
472
- _test_create_data_key_with_provider (
473
- tester, MONGOCRYPT_KMS_PROVIDER_AWS, true /* with_alt_name */);
474
- _test_create_data_key_with_provider (
475
- tester, MONGOCRYPT_KMS_PROVIDER_LOCAL, true /* with_alt_name */);
397
+ static void _test_create_data_key(_mongocrypt_tester_t *tester) {
398
+ _test_create_data_key_with_provider(tester, MONGOCRYPT_KMS_PROVIDER_AWS, false /* with_alt_name */);
399
+ _test_create_data_key_with_provider(tester, MONGOCRYPT_KMS_PROVIDER_LOCAL, false /* with_alt_name */);
400
+ _test_create_data_key_with_provider(tester, MONGOCRYPT_KMS_PROVIDER_AWS, true /* with_alt_name */);
401
+ _test_create_data_key_with_provider(tester, MONGOCRYPT_KMS_PROVIDER_LOCAL, true /* with_alt_name */);
476
402
  }
477
403
 
478
-
479
- void
480
- _mongocrypt_tester_install_data_key (_mongocrypt_tester_t *tester)
481
- {
482
- INSTALL_TEST (_test_random_generator);
483
- INSTALL_TEST (_test_create_data_key);
484
- INSTALL_TEST (_test_datakey_custom_endpoint);
485
- INSTALL_TEST (_test_datakey_custom_key_material);
486
- INSTALL_TEST (_test_datakey_kms_per_ctx_credentials);
487
- INSTALL_TEST (_test_datakey_kms_per_ctx_credentials_not_requested);
488
- INSTALL_TEST (_test_datakey_kms_per_ctx_credentials_local);
404
+ void _mongocrypt_tester_install_data_key(_mongocrypt_tester_t *tester) {
405
+ INSTALL_TEST(_test_random_generator);
406
+ INSTALL_TEST(_test_create_data_key);
407
+ INSTALL_TEST(_test_datakey_custom_endpoint);
408
+ INSTALL_TEST(_test_datakey_custom_key_material);
409
+ INSTALL_TEST(_test_datakey_kms_per_ctx_credentials);
410
+ INSTALL_TEST(_test_datakey_kms_per_ctx_credentials_not_requested);
411
+ INSTALL_TEST(_test_datakey_kms_per_ctx_credentials_local);
489
412
  }