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
@@ -19,10 +19,10 @@
19
19
 
20
20
  #include <bson/bson.h>
21
21
 
22
- #include "mongocrypt.h"
23
22
  #include "mongocrypt-config.h"
24
23
  #include "mongocrypt-crypto-private.h"
25
24
  #include "mongocrypt-marking-private.h"
25
+ #include "mongocrypt.h"
26
26
  #include "test-mongocrypt.h"
27
27
 
28
28
  #ifdef MONGOCRYPT_ENABLE_CRYPTO_COMMON_CRYPTO
@@ -30,496 +30,439 @@
30
30
  #endif
31
31
 
32
32
  /* Return a repeated character with no null terminator. */
33
- char *
34
- _mongocrypt_repeat_char (char c, uint32_t times)
35
- {
36
- char *result;
37
- uint32_t i;
33
+ char *_mongocrypt_repeat_char(char c, uint32_t times) {
34
+ char *result;
35
+ uint32_t i;
38
36
 
39
- result = bson_malloc (times);
40
- BSON_ASSERT (result);
37
+ result = bson_malloc(times);
38
+ BSON_ASSERT(result);
41
39
 
42
- for (i = 0; i < times; i++) {
43
- result[i] = c;
44
- }
40
+ for (i = 0; i < times; i++) {
41
+ result[i] = c;
42
+ }
45
43
 
46
- return result;
44
+ return result;
47
45
  }
48
46
 
49
- void
50
- _load_json_as_bson (const char *path, bson_t *out)
51
- {
52
- bson_error_t error;
53
- bson_json_reader_t *reader;
54
- bool ret;
55
-
56
- reader = bson_json_reader_new_from_file (path, &error);
57
- if (!reader) {
58
- fprintf (stderr, "error reading: %s\n", path);
59
- }
60
- ASSERT_OR_PRINT_BSON (reader, error);
61
- bson_init (out);
62
- ret = bson_json_reader_read (reader, out, &error);
63
- ASSERT_OR_PRINT_BSON (ret, error);
64
-
65
- bson_json_reader_destroy (reader);
47
+ void _load_json_as_bson(const char *path, bson_t *out) {
48
+ bson_error_t error;
49
+ bson_json_reader_t *reader;
50
+ bool ret;
51
+
52
+ reader = bson_json_reader_new_from_file(path, &error);
53
+ if (!reader) {
54
+ fprintf(stderr, "error reading: %s\n", path);
55
+ }
56
+ ASSERT_OR_PRINT_BSON(reader, error);
57
+ bson_init(out);
58
+ ret = bson_json_reader_read(reader, out, &error);
59
+ ASSERT_OR_PRINT_BSON(ret, error);
60
+
61
+ bson_json_reader_destroy(reader);
66
62
  }
67
63
 
68
- #define TEST_DATA_COUNT_INC(var) \
69
- (var)++; \
70
- if ((var) >= TEST_DATA_COUNT) { \
71
- TEST_ERROR ( \
72
- "TEST_DATA_COUNT exceeded for %s. Increment TEST_DATA_COUNT.", #var); \
73
- }
74
-
75
- static void
76
- _load_json (_mongocrypt_tester_t *tester, const char *path)
77
- {
78
- bson_t as_bson;
79
- _mongocrypt_buffer_t *buf;
80
-
81
- _load_json_as_bson (path, &as_bson);
82
-
83
- buf = &tester->file_bufs[tester->file_count];
84
- _mongocrypt_buffer_steal_from_bson (buf, &as_bson);
85
- tester->file_paths[tester->file_count] = bson_strdup (path);
86
- TEST_DATA_COUNT_INC (tester->file_count);
87
- }
64
+ #define TEST_DATA_COUNT_INC(var) \
65
+ (var)++; \
66
+ if ((var) >= TEST_DATA_COUNT) { \
67
+ TEST_ERROR("TEST_DATA_COUNT exceeded for %s. Increment TEST_DATA_COUNT.", #var); \
68
+ }
69
+
70
+ static void _load_json(_mongocrypt_tester_t *tester, const char *path) {
71
+ bson_t as_bson;
72
+ _mongocrypt_buffer_t *buf;
88
73
 
74
+ _load_json_as_bson(path, &as_bson);
89
75
 
90
- static void
91
- _load_http (_mongocrypt_tester_t *tester, const char *path)
92
- {
93
- int fd;
94
- char *contents;
95
- int n_read;
96
- int filesize;
97
- char storage[512];
98
- int i;
99
- _mongocrypt_buffer_t *buf;
100
-
101
- filesize = 0;
102
- contents = NULL;
103
- fd = open (path, O_RDONLY);
104
- while ((n_read = read (fd, storage, sizeof (storage))) > 0) {
105
- filesize += n_read;
106
- /* Append storage. Performance does not matter. */
107
- contents = bson_realloc (contents, filesize);
108
- memcpy (contents + (filesize - n_read), storage, n_read);
109
- }
110
-
111
- if (n_read < 0) {
112
- fprintf (stderr, "failed to read %s\n", path);
113
- abort ();
114
- }
115
-
116
- close (fd);
117
-
118
- buf = &tester->file_bufs[tester->file_count];
119
- /* copy and fix newlines */
120
- _mongocrypt_buffer_init (buf);
121
- /* allocate twice the size since \n may become \r\n */
122
- buf->data = bson_malloc0 (filesize * 2);
123
- BSON_ASSERT (buf->data);
124
-
125
- buf->len = 0;
126
- buf->owned = true;
127
- for (i = 0; i < filesize; i++) {
128
- if (contents[i] == '\n' && contents[i - 1] != '\r') {
129
- buf->data[buf->len++] = '\r';
130
- }
131
- buf->data[buf->len++] = contents[i];
132
- }
133
-
134
- bson_free (contents);
135
- tester->file_paths[tester->file_count] = bson_strdup (path);
136
- TEST_DATA_COUNT_INC (tester->file_count);
76
+ buf = &tester->file_bufs[tester->file_count];
77
+ _mongocrypt_buffer_steal_from_bson(buf, &as_bson);
78
+ tester->file_paths[tester->file_count] = bson_strdup(path);
79
+ TEST_DATA_COUNT_INC(tester->file_count);
137
80
  }
138
81
 
82
+ static void _load_http(_mongocrypt_tester_t *tester, const char *path) {
83
+ int fd;
84
+ char *contents;
85
+ int n_read;
86
+ int filesize;
87
+ char storage[512];
88
+ int i;
89
+ _mongocrypt_buffer_t *buf;
90
+
91
+ filesize = 0;
92
+ contents = NULL;
93
+ fd = open(path, O_RDONLY);
94
+ while ((n_read = read(fd, storage, sizeof(storage))) > 0) {
95
+ filesize += n_read;
96
+ /* Append storage. Performance does not matter. */
97
+ contents = bson_realloc(contents, filesize);
98
+ memcpy(contents + (filesize - n_read), storage, n_read);
99
+ }
100
+
101
+ if (n_read < 0) {
102
+ fprintf(stderr, "failed to read %s\n", path);
103
+ abort();
104
+ }
105
+
106
+ close(fd);
107
+
108
+ buf = &tester->file_bufs[tester->file_count];
109
+ /* copy and fix newlines */
110
+ _mongocrypt_buffer_init(buf);
111
+ /* allocate twice the size since \n may become \r\n */
112
+ buf->data = bson_malloc0(filesize * 2);
113
+ BSON_ASSERT(buf->data);
114
+
115
+ buf->len = 0;
116
+ buf->owned = true;
117
+ for (i = 0; i < filesize; i++) {
118
+ if (contents[i] == '\n' && contents[i - 1] != '\r') {
119
+ buf->data[buf->len++] = '\r';
120
+ }
121
+ buf->data[buf->len++] = contents[i];
122
+ }
123
+
124
+ bson_free(contents);
125
+ tester->file_paths[tester->file_count] = bson_strdup(path);
126
+ TEST_DATA_COUNT_INC(tester->file_count);
127
+ }
139
128
 
140
- void
141
- _mongocrypt_tester_install (_mongocrypt_tester_t *tester,
142
- char *name,
143
- _mongocrypt_test_fn fn,
144
- _mongocrypt_tester_crypto_spec_t crypto_spec)
145
- {
146
- bool crypto_enabled;
129
+ void _mongocrypt_tester_install(_mongocrypt_tester_t *tester,
130
+ char *name,
131
+ _mongocrypt_test_fn fn,
132
+ _mongocrypt_tester_crypto_spec_t crypto_spec) {
133
+ bool crypto_enabled;
147
134
 
148
135
  #ifdef MONGOCRYPT_ENABLE_CRYPTO
149
- crypto_enabled = true;
136
+ crypto_enabled = true;
150
137
  #else
151
- crypto_enabled = false;
138
+ crypto_enabled = false;
152
139
  #endif
153
140
 
154
- if (crypto_spec == CRYPTO_REQUIRED && !crypto_enabled) {
155
- printf ("Skipping test: %s – requires crypto to be enabled\n", name);
156
- return;
157
- }
141
+ if (crypto_spec == CRYPTO_REQUIRED && !crypto_enabled) {
142
+ printf("Skipping test: %s – requires crypto to be enabled\n", name);
143
+ return;
144
+ }
158
145
 
159
- if (crypto_spec == CRYPTO_PROHIBITED && crypto_enabled) {
160
- printf ("Skipping test: %s – requires crypto to be disabled\n", name);
161
- return;
162
- }
146
+ if (crypto_spec == CRYPTO_PROHIBITED && crypto_enabled) {
147
+ printf("Skipping test: %s – requires crypto to be disabled\n", name);
148
+ return;
149
+ }
163
150
 
164
- tester->test_fns[tester->test_count] = fn;
165
- tester->test_names[tester->test_count] = bson_strdup (name);
166
- TEST_DATA_COUNT_INC (tester->test_count);
151
+ tester->test_fns[tester->test_count] = fn;
152
+ tester->test_names[tester->test_count] = bson_strdup(name);
153
+ TEST_DATA_COUNT_INC(tester->test_count);
167
154
  }
168
155
 
169
-
170
- mongocrypt_binary_t *
171
- _mongocrypt_tester_file (_mongocrypt_tester_t *tester, const char *path)
172
- {
173
- int i;
174
- mongocrypt_binary_t *to_return;
175
-
176
- to_return = mongocrypt_binary_new ();
177
- tester->test_bin[tester->bin_count] = to_return;
178
- TEST_DATA_COUNT_INC (tester->bin_count);
179
-
180
- for (i = 0; i < tester->file_count; i++) {
181
- if (0 == strcmp (tester->file_paths[i], path)) {
182
- _mongocrypt_buffer_to_binary (&tester->file_bufs[i], to_return);
183
- return to_return;
184
- }
185
- }
186
-
187
- /* File not found, load it. */
188
- if (strstr (path, ".json")) {
189
- _load_json (tester, path);
190
- } else if (strstr (path, ".txt")) {
191
- _load_http (tester, path);
192
- }
193
-
194
- _mongocrypt_buffer_to_binary (&tester->file_bufs[tester->file_count - 1],
195
- to_return);
196
- return to_return;
156
+ mongocrypt_binary_t *_mongocrypt_tester_file(_mongocrypt_tester_t *tester, const char *path) {
157
+ int i;
158
+ mongocrypt_binary_t *to_return;
159
+
160
+ to_return = mongocrypt_binary_new();
161
+ tester->test_bin[tester->bin_count] = to_return;
162
+ TEST_DATA_COUNT_INC(tester->bin_count);
163
+
164
+ for (i = 0; i < tester->file_count; i++) {
165
+ if (0 == strcmp(tester->file_paths[i], path)) {
166
+ _mongocrypt_buffer_to_binary(&tester->file_bufs[i], to_return);
167
+ return to_return;
168
+ }
169
+ }
170
+
171
+ /* File not found, load it. */
172
+ if (strstr(path, ".json")) {
173
+ _load_json(tester, path);
174
+ } else if (strstr(path, ".txt")) {
175
+ _load_http(tester, path);
176
+ }
177
+
178
+ _mongocrypt_buffer_to_binary(&tester->file_bufs[tester->file_count - 1], to_return);
179
+ return to_return;
197
180
  }
198
181
 
199
-
200
- bson_t *
201
- _mongocrypt_tester_bson_from_json (_mongocrypt_tester_t *tester,
202
- const char *json,
203
- ...)
204
- {
205
- va_list ap;
206
- char *full_json;
207
- bson_t *bson;
208
- bson_error_t error;
209
- char *c;
210
-
211
- va_start (ap, json);
212
- full_json = bson_strdupv_printf (json, ap);
213
- /* Replace ' with " */
214
- for (c = full_json; *c; c++) {
215
- if (*c == '\'') {
216
- *c = '"';
217
- }
218
- }
219
-
220
- va_end (ap);
221
- bson = &tester->test_bson[tester->bson_count];
222
- TEST_DATA_COUNT_INC (tester->bson_count);
223
- if (!bson_init_from_json (bson, full_json, strlen (full_json), &error)) {
224
- fprintf (stderr, "%s", error.message);
225
- abort ();
226
- }
227
- bson_free (full_json);
228
- return bson;
182
+ bson_t *_mongocrypt_tester_bson_from_json(_mongocrypt_tester_t *tester, const char *json, ...) {
183
+ va_list ap;
184
+ char *full_json;
185
+ bson_t *bson;
186
+ bson_error_t error;
187
+ char *c;
188
+
189
+ va_start(ap, json);
190
+ full_json = bson_strdupv_printf(json, ap);
191
+ /* Replace ' with " */
192
+ for (c = full_json; *c; c++) {
193
+ if (*c == '\'') {
194
+ *c = '"';
195
+ }
196
+ }
197
+
198
+ va_end(ap);
199
+ bson = &tester->test_bson[tester->bson_count];
200
+ TEST_DATA_COUNT_INC(tester->bson_count);
201
+ if (!bson_init_from_json(bson, full_json, strlen(full_json), &error)) {
202
+ fprintf(stderr, "%s", error.message);
203
+ abort();
204
+ }
205
+ bson_free(full_json);
206
+ return bson;
229
207
  }
230
208
 
231
-
232
- mongocrypt_binary_t *
233
- _mongocrypt_tester_bin_from_json (_mongocrypt_tester_t *tester,
234
- const char *json,
235
- ...)
236
- {
237
- va_list ap;
238
- char *full_json;
239
- bson_t *bson;
240
- mongocrypt_binary_t *bin;
241
- bson_error_t error;
242
- char *c;
243
-
244
- va_start (ap, json);
245
- full_json = bson_strdupv_printf (json, ap);
246
- /* Replace ' with " */
247
- for (c = full_json; *c; c++) {
248
- if (*c == '\'') {
249
- *c = '"';
250
- }
251
- }
252
-
253
- va_end (ap);
254
- bson = &tester->test_bson[tester->bson_count];
255
- TEST_DATA_COUNT_INC (tester->bson_count);
256
- if (!bson_init_from_json (bson, full_json, strlen (full_json), &error)) {
257
- fprintf (stderr, "failed to parse JSON %s: %s", error.message, json);
258
- abort ();
259
- }
260
- bin = mongocrypt_binary_new ();
261
- tester->test_bin[tester->bin_count] = bin;
262
- TEST_DATA_COUNT_INC (tester->bin_count);
263
- bin->data = (uint8_t *) bson_get_data (bson);
264
- bin->len = bson->len;
265
- bson_free (full_json);
266
- return bin;
209
+ mongocrypt_binary_t *_mongocrypt_tester_bin_from_json(_mongocrypt_tester_t *tester, const char *json, ...) {
210
+ va_list ap;
211
+ char *full_json;
212
+ bson_t *bson;
213
+ mongocrypt_binary_t *bin;
214
+ bson_error_t error;
215
+ char *c;
216
+
217
+ va_start(ap, json);
218
+ full_json = bson_strdupv_printf(json, ap);
219
+ /* Replace ' with " */
220
+ for (c = full_json; *c; c++) {
221
+ if (*c == '\'') {
222
+ *c = '"';
223
+ }
224
+ }
225
+
226
+ va_end(ap);
227
+ bson = &tester->test_bson[tester->bson_count];
228
+ TEST_DATA_COUNT_INC(tester->bson_count);
229
+ if (!bson_init_from_json(bson, full_json, strlen(full_json), &error)) {
230
+ fprintf(stderr, "failed to parse JSON %s: %s", error.message, json);
231
+ abort();
232
+ }
233
+ bin = mongocrypt_binary_new();
234
+ tester->test_bin[tester->bin_count] = bin;
235
+ TEST_DATA_COUNT_INC(tester->bin_count);
236
+ bin->data = (uint8_t *)bson_get_data(bson);
237
+ bin->len = bson->len;
238
+ bson_free(full_json);
239
+ return bin;
267
240
  }
268
241
 
242
+ mongocrypt_binary_t *_mongocrypt_tester_bin(_mongocrypt_tester_t *tester, int size) {
243
+ mongocrypt_binary_t *bin;
244
+ uint8_t *blob;
245
+ int i;
269
246
 
270
- mongocrypt_binary_t *
271
- _mongocrypt_tester_bin (_mongocrypt_tester_t *tester, int size)
272
- {
273
- mongocrypt_binary_t *bin;
274
- uint8_t *blob;
275
- int i;
247
+ if (size == 0) {
248
+ return NULL;
249
+ }
250
+ blob = bson_malloc(size);
251
+ BSON_ASSERT(blob);
276
252
 
277
- if (size == 0) {
278
- return NULL;
279
- }
280
- blob = bson_malloc (size);
281
- BSON_ASSERT (blob);
253
+ for (i = 0; i < size; i++) {
254
+ blob[i] = (i % 3) + 1; /* 1, 2, 3, 1, 2, 3, ... */
255
+ }
282
256
 
283
- for (i = 0; i < size; i++) {
284
- blob[i] = (i % 3) + 1; /* 1, 2, 3, 1, 2, 3, ... */
285
- }
257
+ bin = mongocrypt_binary_new_from_data(blob, size);
286
258
 
287
- bin = mongocrypt_binary_new_from_data (blob, size);
288
-
289
- tester->test_blob[tester->blob_count] = blob;
290
- TEST_DATA_COUNT_INC (tester->blob_count);
291
- tester->test_bin[tester->bin_count] = bin;
292
- TEST_DATA_COUNT_INC (tester->bin_count);
293
- return bin;
259
+ tester->test_blob[tester->blob_count] = blob;
260
+ TEST_DATA_COUNT_INC(tester->blob_count);
261
+ tester->test_bin[tester->bin_count] = bin;
262
+ TEST_DATA_COUNT_INC(tester->bin_count);
263
+ return bin;
294
264
  }
295
265
 
296
- void
297
- _mongocrypt_tester_satisfy_kms (_mongocrypt_tester_t *tester,
298
- mongocrypt_kms_ctx_t *kms)
299
- {
300
- const char *endpoint;
301
-
302
- BSON_ASSERT (mongocrypt_kms_ctx_endpoint (kms, &endpoint));
303
- BSON_ASSERT (endpoint == strstr (endpoint, "kms.") &&
304
- strstr (endpoint, ".amazonaws.com"));
305
- mongocrypt_kms_ctx_feed (kms,
306
- TEST_FILE ("./test/example/kms-decrypt-reply.txt"));
307
- BSON_ASSERT (0 == mongocrypt_kms_ctx_bytes_needed (kms));
308
- }
266
+ void _mongocrypt_tester_satisfy_kms(_mongocrypt_tester_t *tester, mongocrypt_kms_ctx_t *kms) {
267
+ const char *endpoint;
309
268
 
269
+ BSON_ASSERT(mongocrypt_kms_ctx_endpoint(kms, &endpoint));
270
+ BSON_ASSERT(endpoint == strstr(endpoint, "kms.") && strstr(endpoint, ".amazonaws.com"));
271
+ mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/example/kms-decrypt-reply.txt"));
272
+ BSON_ASSERT(0 == mongocrypt_kms_ctx_bytes_needed(kms));
273
+ }
310
274
 
311
275
  /* Run the state machine on example data until hitting stop_state or a
312
276
  * terminal state. */
313
- void
314
- _mongocrypt_tester_run_ctx_to (_mongocrypt_tester_t *tester,
315
- mongocrypt_ctx_t *ctx,
316
- mongocrypt_ctx_state_t stop_state)
317
- {
318
- mongocrypt_ctx_state_t state;
319
- mongocrypt_kms_ctx_t *kms;
320
- mongocrypt_status_t *status;
321
- mongocrypt_binary_t *bin;
322
- bool res;
323
-
324
- status = mongocrypt_status_new ();
325
- state = mongocrypt_ctx_state (ctx);
326
- while (state != stop_state) {
327
- switch (state) {
328
- case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
329
- if (tester->paths.collection_info) {
330
- bin = TEST_FILE (tester->paths.collection_info);
331
- } else {
332
- bin = TEST_FILE ("./test/example/collection-info.json");
333
- }
334
- BSON_ASSERT (ctx->type == _MONGOCRYPT_TYPE_ENCRYPT);
335
- BSON_ASSERT (mongocrypt_ctx_mongo_feed (ctx, bin));
336
- BSON_ASSERT (mongocrypt_ctx_mongo_done (ctx));
337
- break;
338
- case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
339
- if (tester->paths.mongocryptd_reply) {
340
- bin = TEST_FILE (tester->paths.mongocryptd_reply);
341
- } else {
342
- bin = TEST_FILE ("./test/example/mongocryptd-reply.json");
343
- }
344
- BSON_ASSERT (ctx->type == _MONGOCRYPT_TYPE_ENCRYPT);
345
- res = mongocrypt_ctx_mongo_feed (ctx, bin);
346
- mongocrypt_ctx_status (ctx, status);
347
- ASSERT_OR_PRINT (res, status);
348
- BSON_ASSERT (mongocrypt_ctx_mongo_done (ctx));
349
- break;
350
- case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
351
- if (tester->paths.key_file) {
352
- bin = TEST_FILE (tester->paths.key_file);
353
- } else {
354
- bin = TEST_FILE ("./test/example/key-document.json");
355
- }
356
- res = mongocrypt_ctx_mongo_feed (ctx, bin);
357
- mongocrypt_ctx_status (ctx, status);
358
- ASSERT_OR_PRINT (res, status);
359
- BSON_ASSERT (mongocrypt_ctx_mongo_done (ctx));
360
- break;
361
- case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
362
- bin = TEST_BSON ("{}");
363
- mongocrypt_ctx_provide_kms_providers (ctx, bin);
364
- break;
365
- case MONGOCRYPT_CTX_NEED_KMS:
366
- kms = mongocrypt_ctx_next_kms_ctx (ctx);
367
- while (kms) {
368
- _mongocrypt_tester_satisfy_kms (tester, kms);
369
- kms = mongocrypt_ctx_next_kms_ctx (ctx);
370
- }
371
- res = mongocrypt_ctx_kms_done (ctx);
372
- mongocrypt_ctx_status (ctx, status);
373
- ASSERT_OR_PRINT (res, status);
374
- break;
375
- case MONGOCRYPT_CTX_READY:
376
- bin = mongocrypt_binary_new ();
377
- res = mongocrypt_ctx_finalize (ctx, bin);
378
- mongocrypt_ctx_status (ctx, status);
379
- ASSERT_OR_PRINT (res, status);
380
- mongocrypt_binary_destroy (bin);
381
- break;
382
- case MONGOCRYPT_CTX_ERROR:
383
- mongocrypt_ctx_status (ctx, status);
384
- fprintf (stderr,
385
- "Got error: %s\n",
386
- mongocrypt_status_message (status, NULL));
387
- ASSERT_STATE_EQUAL (state, stop_state);
388
- mongocrypt_status_destroy (status);
389
- return;
390
- case MONGOCRYPT_CTX_DONE:
391
- ASSERT_STATE_EQUAL (state, stop_state);
392
- mongocrypt_status_destroy (status);
393
- return;
394
- default:
395
- BSON_ASSERT (false && "Invalid state");
396
- }
397
- state = mongocrypt_ctx_state (ctx);
398
- }
399
- ASSERT_STATE_EQUAL (state, stop_state);
400
- mongocrypt_status_destroy (status);
277
+ void _mongocrypt_tester_run_ctx_to(_mongocrypt_tester_t *tester,
278
+ mongocrypt_ctx_t *ctx,
279
+ mongocrypt_ctx_state_t stop_state) {
280
+ mongocrypt_ctx_state_t state;
281
+ mongocrypt_kms_ctx_t *kms;
282
+ mongocrypt_status_t *status;
283
+ mongocrypt_binary_t *bin;
284
+ bool res;
285
+
286
+ status = mongocrypt_status_new();
287
+ state = mongocrypt_ctx_state(ctx);
288
+ while (state != stop_state) {
289
+ switch (state) {
290
+ case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
291
+ if (tester->paths.collection_info) {
292
+ bin = TEST_FILE(tester->paths.collection_info);
293
+ } else {
294
+ bin = TEST_FILE("./test/example/collection-info.json");
295
+ }
296
+ BSON_ASSERT(ctx->type == _MONGOCRYPT_TYPE_ENCRYPT);
297
+ BSON_ASSERT(mongocrypt_ctx_mongo_feed(ctx, bin));
298
+ BSON_ASSERT(mongocrypt_ctx_mongo_done(ctx));
299
+ break;
300
+ case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
301
+ if (tester->paths.mongocryptd_reply) {
302
+ bin = TEST_FILE(tester->paths.mongocryptd_reply);
303
+ } else {
304
+ bin = TEST_FILE("./test/example/mongocryptd-reply.json");
305
+ }
306
+ BSON_ASSERT(ctx->type == _MONGOCRYPT_TYPE_ENCRYPT);
307
+ res = mongocrypt_ctx_mongo_feed(ctx, bin);
308
+ mongocrypt_ctx_status(ctx, status);
309
+ ASSERT_OR_PRINT(res, status);
310
+ BSON_ASSERT(mongocrypt_ctx_mongo_done(ctx));
311
+ break;
312
+ case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
313
+ if (tester->paths.key_file) {
314
+ bin = TEST_FILE(tester->paths.key_file);
315
+ } else {
316
+ bin = TEST_FILE("./test/example/key-document.json");
317
+ }
318
+ res = mongocrypt_ctx_mongo_feed(ctx, bin);
319
+ mongocrypt_ctx_status(ctx, status);
320
+ ASSERT_OR_PRINT(res, status);
321
+ BSON_ASSERT(mongocrypt_ctx_mongo_done(ctx));
322
+ break;
323
+ case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
324
+ bin = TEST_BSON("{}");
325
+ mongocrypt_ctx_provide_kms_providers(ctx, bin);
326
+ break;
327
+ case MONGOCRYPT_CTX_NEED_KMS:
328
+ kms = mongocrypt_ctx_next_kms_ctx(ctx);
329
+ while (kms) {
330
+ _mongocrypt_tester_satisfy_kms(tester, kms);
331
+ kms = mongocrypt_ctx_next_kms_ctx(ctx);
332
+ }
333
+ res = mongocrypt_ctx_kms_done(ctx);
334
+ mongocrypt_ctx_status(ctx, status);
335
+ ASSERT_OR_PRINT(res, status);
336
+ break;
337
+ case MONGOCRYPT_CTX_READY:
338
+ bin = mongocrypt_binary_new();
339
+ res = mongocrypt_ctx_finalize(ctx, bin);
340
+ mongocrypt_ctx_status(ctx, status);
341
+ ASSERT_OR_PRINT(res, status);
342
+ mongocrypt_binary_destroy(bin);
343
+ break;
344
+ case MONGOCRYPT_CTX_ERROR:
345
+ mongocrypt_ctx_status(ctx, status);
346
+ fprintf(stderr, "Got error: %s\n", mongocrypt_status_message(status, NULL));
347
+ ASSERT_STATE_EQUAL(state, stop_state);
348
+ mongocrypt_status_destroy(status);
349
+ return;
350
+ case MONGOCRYPT_CTX_DONE:
351
+ ASSERT_STATE_EQUAL(state, stop_state);
352
+ mongocrypt_status_destroy(status);
353
+ return;
354
+ default: BSON_ASSERT(false && "Invalid state");
355
+ }
356
+ state = mongocrypt_ctx_state(ctx);
357
+ }
358
+ ASSERT_STATE_EQUAL(state, stop_state);
359
+ mongocrypt_status_destroy(status);
401
360
  }
402
361
 
403
-
404
362
  /* Get the plaintext associated with the encrypted doc for assertions. */
405
- const char *
406
- _mongocrypt_tester_plaintext (_mongocrypt_tester_t *tester)
407
- {
408
- bson_t as_bson;
409
- bson_iter_t iter;
410
- _mongocrypt_marking_t marking;
411
- _mongocrypt_buffer_t buf;
412
- mongocrypt_status_t *status;
413
-
414
- BSON_ASSERT (_mongocrypt_binary_to_bson (
415
- TEST_FILE ("./test/example/mongocryptd-reply.json"), &as_bson));
416
- /* Underlying binary data lives on in tester */
417
- BSON_ASSERT (bson_iter_init (&iter, &as_bson));
418
- BSON_ASSERT (bson_iter_find_descendant (&iter, "result.filter.ssn", &iter));
419
- BSON_ASSERT (_mongocrypt_buffer_from_binary_iter (&buf, &iter));
420
- status = mongocrypt_status_new ();
421
- ASSERT_OR_PRINT (_mongocrypt_marking_parse_unowned (&buf, &marking, status),
422
- status);
423
- mongocrypt_status_destroy (status);
424
- BSON_ASSERT (BSON_ITER_HOLDS_UTF8 (&marking.v_iter));
425
- return bson_iter_utf8 (&marking.v_iter, NULL);
363
+ const char *_mongocrypt_tester_plaintext(_mongocrypt_tester_t *tester) {
364
+ bson_t as_bson;
365
+ bson_iter_t iter;
366
+ _mongocrypt_marking_t marking;
367
+ _mongocrypt_buffer_t buf;
368
+ mongocrypt_status_t *status;
369
+
370
+ BSON_ASSERT(_mongocrypt_binary_to_bson(TEST_FILE("./test/example/mongocryptd-reply.json"), &as_bson));
371
+ /* Underlying binary data lives on in tester */
372
+ BSON_ASSERT(bson_iter_init(&iter, &as_bson));
373
+ BSON_ASSERT(bson_iter_find_descendant(&iter, "result.filter.ssn", &iter));
374
+ BSON_ASSERT(_mongocrypt_buffer_from_binary_iter(&buf, &iter));
375
+ status = mongocrypt_status_new();
376
+ ASSERT_OR_PRINT(_mongocrypt_marking_parse_unowned(&buf, &marking, status), status);
377
+ mongocrypt_status_destroy(status);
378
+ BSON_ASSERT(BSON_ITER_HOLDS_UTF8(&marking.v_iter));
379
+ return bson_iter_utf8(&marking.v_iter, NULL);
426
380
  }
427
381
 
428
-
429
- mongocrypt_binary_t *
430
- _mongocrypt_tester_encrypted_doc (_mongocrypt_tester_t *tester)
431
- {
432
- mongocrypt_t *crypt;
433
- mongocrypt_ctx_t *ctx;
434
- mongocrypt_binary_t *bin;
435
-
436
- bin = mongocrypt_binary_new ();
437
- if (!_mongocrypt_buffer_empty (&tester->encrypted_doc)) {
438
- _mongocrypt_buffer_to_binary (&tester->encrypted_doc, bin);
439
- return bin;
440
- }
441
-
442
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
443
-
444
- ctx = mongocrypt_ctx_new (crypt);
445
- ASSERT_OK (mongocrypt_ctx_encrypt_init (
446
- ctx, "test", -1, TEST_FILE ("./test/example/cmd.json")),
447
- ctx);
448
-
449
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
450
- mongocrypt_ctx_finalize (ctx, bin);
451
- _mongocrypt_buffer_copy_from_binary (&tester->encrypted_doc, bin);
452
- mongocrypt_ctx_destroy (ctx);
453
- mongocrypt_destroy (crypt);
454
- _mongocrypt_buffer_to_binary (&tester->encrypted_doc, bin);
455
- return bin;
382
+ mongocrypt_binary_t *_mongocrypt_tester_encrypted_doc(_mongocrypt_tester_t *tester) {
383
+ mongocrypt_t *crypt;
384
+ mongocrypt_ctx_t *ctx;
385
+ mongocrypt_binary_t *bin;
386
+
387
+ bin = mongocrypt_binary_new();
388
+ if (!_mongocrypt_buffer_empty(&tester->encrypted_doc)) {
389
+ _mongocrypt_buffer_to_binary(&tester->encrypted_doc, bin);
390
+ return bin;
391
+ }
392
+
393
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
394
+
395
+ ctx = mongocrypt_ctx_new(crypt);
396
+ ASSERT_OK(mongocrypt_ctx_encrypt_init(ctx, "test", -1, TEST_FILE("./test/example/cmd.json")), ctx);
397
+
398
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
399
+ mongocrypt_ctx_finalize(ctx, bin);
400
+ _mongocrypt_buffer_copy_from_binary(&tester->encrypted_doc, bin);
401
+ mongocrypt_ctx_destroy(ctx);
402
+ mongocrypt_destroy(crypt);
403
+ _mongocrypt_buffer_to_binary(&tester->encrypted_doc, bin);
404
+ return bin;
456
405
  }
457
406
 
407
+ void _mongocrypt_tester_fill_buffer(_mongocrypt_buffer_t *buf, int n) {
408
+ uint8_t i;
458
409
 
459
- void
460
- _mongocrypt_tester_fill_buffer (_mongocrypt_buffer_t *buf, int n)
461
- {
462
- uint8_t i;
463
-
464
- memset (buf, 0, sizeof (*buf));
465
- buf->data = bson_malloc (n);
466
- BSON_ASSERT (buf->data);
410
+ memset(buf, 0, sizeof(*buf));
411
+ buf->data = bson_malloc(n);
412
+ BSON_ASSERT(buf->data);
467
413
 
468
- for (i = 0; i < n; i++) {
469
- buf->data[i] = i;
470
- }
471
- buf->len = n;
472
- buf->owned = true;
414
+ for (i = 0; i < n; i++) {
415
+ buf->data[i] = i;
416
+ }
417
+ buf->len = n;
418
+ buf->owned = true;
473
419
  }
474
420
 
475
- #define PRIVATE_KEY_FOR_TESTING \
476
- "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4JOyv5z05cL18ztpknRC7C" \
477
- "FY2gYol4DAKerdVUoDJxCTmFMf39dVUEqD0WDiw/qcRtSO1/" \
478
- "FRut08PlSPmvbyKetsLoxlpS8lukSzEFpFK7+L+R4miFOl6HvECyg7lbC1H/" \
479
- "WGAhIz9yZRlXhRo9qmO/" \
480
- "fB6PV9IeYtU+" \
481
- "1xYuXicjCDPp36uuxBAnCz7JfvxJ3mdVc0vpSkbSb141nWuKNYR1mgyvvL6KzxO6mYsCo4hRA" \
482
- "dhuizD9C4jDHk0V2gDCFBk0h8SLEdzStX8L0jG90/Og4y7J1b/cPo/" \
483
- "kbYokkYisxe8cPlsvGBf+rZex7XPxc1yWaP080qeABJb+S88O//" \
484
- "LAgMBAAECggEBAKVxP1m3FzHBUe2NZ3fYCc0Qa2zjK7xl1KPFp2u4CU+" \
485
- "9sy0oZJUqQHUdm5CMprqWwIHPTftWboFenmCwrSXFOFzujljBO7Z3yc1WD3NJl1ZNepLcsRJ3" \
486
- "WWFH5V+NLJ8Bdxlj1DMEZCwr7PC5+vpnCuYWzvT0qOPTl9RNVaW9VVjHouJ9Fg+" \
487
- "s2DrShXDegFabl1iZEDdI4xScHoYBob06A5lw0WOCTayzw0Naf37lM8Y4psRAmI46XLiF/" \
488
- "Vbuorna4hcChxDePlNLEfMipICcuxTcei1RBSlBa2t1tcnvoTy6cuYDqqImRYjp1KnMKlKQBn" \
489
- "Q1NjS2TsRGm+F0FbreVCECgYEA4IDJlm8q/hVyNcPe4OzIcL1rsdYN3bNm2Y2O/" \
490
- "YtRPIkQ446ItyxD06d9VuXsQpFp9jNACAPfCMSyHpPApqlxdc8z/" \
491
- "xATlgHkcGezEOd1r4E7NdTpGg8y6Rj9b8kVlED6v4grbRhKcU6moyKUQT3+" \
492
- "1B6ENZTOKyxuyDEgTwZHtFECgYEA0fqdv9h9s77d6eWmIioP7FSymq93pC4umxf6TVicpjpME" \
493
- "rdD2ZfJGulN37dq8FOsOFnSmFYJdICj/PbJm6p1i8O21lsFCltEqVoVabJ7/" \
494
- "0alPfdG2U76OeBqI8ZubL4BMnWXAB/" \
495
- "VVEYbyWCNpQSDTjHQYs54qa2I0dJB7OgJt1sCgYEArctFQ02/" \
496
- "7H5Rscl1yo3DBXO94SeiCFSPdC8f2Kt3MfOxvVdkAtkjkMACSbkoUsgbTVqTYSEOEc2jTgR3i" \
497
- "Q13JgpHaFbbsq64V0QP3TAxbLIQUjYGVgQaF1UfLOBv8hrzgj45z/ST/" \
498
- "G80lOl595+0nCUbmBcgG1AEWrmdF0/" \
499
- "3RmECgYAKvIzKXXB3+19vcT2ga5Qq2l3TiPtOGsppRb2XrNs9qKdxIYvHmXo/" \
500
- "9QP1V3SRW0XoD7ez8FpFabp42cmPOxUNk3FK3paQZABLxH5pzCWI9PzIAVfPDrm+" \
501
- "sdnbgG7vAnwfL2IMMJSA3aDYGCbF9EgefG+" \
502
- "STcpfqq7fQ6f5TBgLFwKBgCd7gn1xYL696SaKVSm7VngpXlczHVEpz3kStWR5gfzriPBxXgMV" \
503
- "cWmcbajRser7ARpCEfbxM1UJyv6oAYZWVSNErNzNVb4POqLYcCNySuC6xKhs9FrEQnyKjyk8w" \
504
- "I4VnrEMGrQ8e+qYSwYk9Gh6dKGoRMAPYVXQAO0fIsHF/T0a"
505
-
506
- mongocrypt_t *
507
- _mongocrypt_tester_mongocrypt (tester_mongocrypt_flags flags)
508
- {
509
- mongocrypt_t *crypt;
510
- char localkey_data[MONGOCRYPT_KEY_LEN] = {0};
511
- mongocrypt_binary_t *localkey;
512
- bson_t *kms_providers;
513
- mongocrypt_binary_t *bin;
514
-
515
- crypt = mongocrypt_new ();
516
- mongocrypt_setopt_log_handler (crypt, _mongocrypt_stdout_log_fn, NULL);
517
- mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, "example", -1);
518
- localkey = mongocrypt_binary_new_from_data ((uint8_t *) localkey_data,
519
- sizeof localkey_data);
520
- mongocrypt_setopt_kms_provider_local (crypt, localkey);
521
- mongocrypt_binary_destroy (localkey);
522
- kms_providers = BCON_NEW ("azure",
421
+ #define PRIVATE_KEY_FOR_TESTING \
422
+ "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4JOyv5z05cL18ztpknRC7C" \
423
+ "FY2gYol4DAKerdVUoDJxCTmFMf39dVUEqD0WDiw/qcRtSO1/" \
424
+ "FRut08PlSPmvbyKetsLoxlpS8lukSzEFpFK7+L+R4miFOl6HvECyg7lbC1H/" \
425
+ "WGAhIz9yZRlXhRo9qmO/" \
426
+ "fB6PV9IeYtU+" \
427
+ "1xYuXicjCDPp36uuxBAnCz7JfvxJ3mdVc0vpSkbSb141nWuKNYR1mgyvvL6KzxO6mYsCo4hRA" \
428
+ "dhuizD9C4jDHk0V2gDCFBk0h8SLEdzStX8L0jG90/Og4y7J1b/cPo/" \
429
+ "kbYokkYisxe8cPlsvGBf+rZex7XPxc1yWaP080qeABJb+S88O//" \
430
+ "LAgMBAAECggEBAKVxP1m3FzHBUe2NZ3fYCc0Qa2zjK7xl1KPFp2u4CU+" \
431
+ "9sy0oZJUqQHUdm5CMprqWwIHPTftWboFenmCwrSXFOFzujljBO7Z3yc1WD3NJl1ZNepLcsRJ3" \
432
+ "WWFH5V+NLJ8Bdxlj1DMEZCwr7PC5+vpnCuYWzvT0qOPTl9RNVaW9VVjHouJ9Fg+" \
433
+ "s2DrShXDegFabl1iZEDdI4xScHoYBob06A5lw0WOCTayzw0Naf37lM8Y4psRAmI46XLiF/" \
434
+ "Vbuorna4hcChxDePlNLEfMipICcuxTcei1RBSlBa2t1tcnvoTy6cuYDqqImRYjp1KnMKlKQBn" \
435
+ "Q1NjS2TsRGm+F0FbreVCECgYEA4IDJlm8q/hVyNcPe4OzIcL1rsdYN3bNm2Y2O/" \
436
+ "YtRPIkQ446ItyxD06d9VuXsQpFp9jNACAPfCMSyHpPApqlxdc8z/" \
437
+ "xATlgHkcGezEOd1r4E7NdTpGg8y6Rj9b8kVlED6v4grbRhKcU6moyKUQT3+" \
438
+ "1B6ENZTOKyxuyDEgTwZHtFECgYEA0fqdv9h9s77d6eWmIioP7FSymq93pC4umxf6TVicpjpME" \
439
+ "rdD2ZfJGulN37dq8FOsOFnSmFYJdICj/PbJm6p1i8O21lsFCltEqVoVabJ7/" \
440
+ "0alPfdG2U76OeBqI8ZubL4BMnWXAB/" \
441
+ "VVEYbyWCNpQSDTjHQYs54qa2I0dJB7OgJt1sCgYEArctFQ02/" \
442
+ "7H5Rscl1yo3DBXO94SeiCFSPdC8f2Kt3MfOxvVdkAtkjkMACSbkoUsgbTVqTYSEOEc2jTgR3i" \
443
+ "Q13JgpHaFbbsq64V0QP3TAxbLIQUjYGVgQaF1UfLOBv8hrzgj45z/ST/" \
444
+ "G80lOl595+0nCUbmBcgG1AEWrmdF0/" \
445
+ "3RmECgYAKvIzKXXB3+19vcT2ga5Qq2l3TiPtOGsppRb2XrNs9qKdxIYvHmXo/" \
446
+ "9QP1V3SRW0XoD7ez8FpFabp42cmPOxUNk3FK3paQZABLxH5pzCWI9PzIAVfPDrm+" \
447
+ "sdnbgG7vAnwfL2IMMJSA3aDYGCbF9EgefG+" \
448
+ "STcpfqq7fQ6f5TBgLFwKBgCd7gn1xYL696SaKVSm7VngpXlczHVEpz3kStWR5gfzriPBxXgMV" \
449
+ "cWmcbajRser7ARpCEfbxM1UJyv6oAYZWVSNErNzNVb4POqLYcCNySuC6xKhs9FrEQnyKjyk8w" \
450
+ "I4VnrEMGrQ8e+qYSwYk9Gh6dKGoRMAPYVXQAO0fIsHF/T0a"
451
+
452
+ mongocrypt_t *_mongocrypt_tester_mongocrypt(tester_mongocrypt_flags flags) {
453
+ mongocrypt_t *crypt;
454
+ char localkey_data[MONGOCRYPT_KEY_LEN] = {0};
455
+ mongocrypt_binary_t *localkey;
456
+ bson_t *kms_providers;
457
+ mongocrypt_binary_t *bin;
458
+
459
+ crypt = mongocrypt_new();
460
+ mongocrypt_setopt_log_handler(crypt, _mongocrypt_stdout_log_fn, NULL);
461
+ mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, "example", -1);
462
+ localkey = mongocrypt_binary_new_from_data((uint8_t *)localkey_data, sizeof localkey_data);
463
+ mongocrypt_setopt_kms_provider_local(crypt, localkey);
464
+ mongocrypt_binary_destroy(localkey);
465
+ kms_providers = BCON_NEW("azure",
523
466
  "{",
524
467
  "tenantId",
525
468
  "",
@@ -540,521 +483,487 @@ _mongocrypt_tester_mongocrypt (tester_mongocrypt_flags flags)
540
483
  "endpoint",
541
484
  "localhost",
542
485
  "}");
543
- bin = mongocrypt_binary_new_from_data (
544
- (uint8_t *) bson_get_data (kms_providers), kms_providers->len);
545
- ASSERT_OK (mongocrypt_setopt_kms_providers (crypt, bin), crypt);
546
- bson_destroy (kms_providers);
547
- mongocrypt_binary_destroy (bin);
548
- if (flags & TESTER_MONGOCRYPT_WITH_CRYPT_SHARED_LIB) {
549
- mongocrypt_setopt_append_crypt_shared_lib_search_path (crypt, "$ORIGIN");
550
- }
551
- ASSERT_OK (mongocrypt_init (crypt), crypt);
552
- if (flags & TESTER_MONGOCRYPT_WITH_CRYPT_SHARED_LIB) {
553
- if (mongocrypt_crypt_shared_lib_version (crypt) == 0) {
554
- BSON_ASSERT (false &&
555
- "tester mongocrypt requested WITH_CRYPT_SHARED_LIB, but "
556
- "no crypt_shared library was loaded by mongocrypt_init");
557
- }
558
- }
559
- return crypt;
486
+ bin = mongocrypt_binary_new_from_data((uint8_t *)bson_get_data(kms_providers), kms_providers->len);
487
+ ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, bin), crypt);
488
+ bson_destroy(kms_providers);
489
+ mongocrypt_binary_destroy(bin);
490
+ if (flags & TESTER_MONGOCRYPT_WITH_CRYPT_V1) {
491
+ ASSERT(mongocrypt_setopt_fle2v2(crypt, false));
492
+ }
493
+ if (flags & TESTER_MONGOCRYPT_WITH_CRYPT_SHARED_LIB) {
494
+ mongocrypt_setopt_append_crypt_shared_lib_search_path(crypt, "$ORIGIN");
495
+ }
496
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
497
+ if (flags & TESTER_MONGOCRYPT_WITH_CRYPT_SHARED_LIB) {
498
+ if (mongocrypt_crypt_shared_lib_version(crypt) == 0) {
499
+ BSON_ASSERT(false
500
+ && "tester mongocrypt requested WITH_CRYPT_SHARED_LIB, but "
501
+ "no crypt_shared library was loaded by mongocrypt_init");
502
+ }
503
+ }
504
+ return crypt;
560
505
  }
561
506
 
507
+ static void _test_mongocrypt_bad_init(_mongocrypt_tester_t *tester) {
508
+ mongocrypt_t *crypt;
509
+ mongocrypt_binary_t *local_key;
510
+ char tmp;
511
+
512
+ /* Omitting a KMS provider must fail. */
513
+ crypt = mongocrypt_new();
514
+ ASSERT_FAILS(mongocrypt_init(crypt), crypt, "no kms provider set");
515
+ mongocrypt_destroy(crypt);
562
516
 
563
- static void
564
- _test_mongocrypt_bad_init (_mongocrypt_tester_t *tester)
565
- {
566
- mongocrypt_t *crypt;
567
- mongocrypt_binary_t *local_key;
568
- char tmp;
569
-
570
-
571
- /* Omitting a KMS provider must fail. */
572
- crypt = mongocrypt_new ();
573
- ASSERT_FAILS (mongocrypt_init (crypt), crypt, "no kms provider set");
574
- mongocrypt_destroy (crypt);
575
-
576
- /* Bad KMS provider options must fail. */
577
- crypt = mongocrypt_new ();
578
- ASSERT_FAILS (
579
- mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, NULL, -1),
580
- crypt,
581
- "invalid aws secret access key");
582
- mongocrypt_destroy (crypt);
583
-
584
- crypt = mongocrypt_new ();
585
- ASSERT_FAILS (
586
- mongocrypt_setopt_kms_provider_aws (crypt, NULL, -1, "example", -1),
587
- crypt,
588
- "invalid aws access key id");
589
- mongocrypt_destroy (crypt);
590
-
591
- /* Malformed UTF8 */
592
- /* An orphaned UTF-8 continuation byte (10xxxxxx) is malformed UTF-8. */
593
- tmp = (char) 0x80;
594
- crypt = mongocrypt_new ();
595
- ASSERT_FAILS (
596
- mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, &tmp, 1),
597
- crypt,
598
- "invalid aws secret access key");
599
- mongocrypt_destroy (crypt);
600
-
601
- crypt = mongocrypt_new ();
602
- ASSERT_FAILS (mongocrypt_setopt_kms_provider_local (crypt, NULL),
517
+ /* Bad KMS provider options must fail. */
518
+ crypt = mongocrypt_new();
519
+ ASSERT_FAILS(mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, NULL, -1),
603
520
  crypt,
604
- "passed null key");
605
- mongocrypt_destroy (crypt);
521
+ "invalid aws secret access key");
522
+ mongocrypt_destroy(crypt);
606
523
 
607
- crypt = mongocrypt_new ();
608
- local_key = mongocrypt_binary_new ();
609
- ASSERT_FAILS (mongocrypt_setopt_kms_provider_local (crypt, local_key),
524
+ crypt = mongocrypt_new();
525
+ ASSERT_FAILS(mongocrypt_setopt_kms_provider_aws(crypt, NULL, -1, "example", -1),
610
526
  crypt,
611
- "local key must be 96 bytes");
612
- mongocrypt_binary_destroy (local_key);
613
- mongocrypt_destroy (crypt);
614
-
615
- /* Reinitialization must fail. */
616
- crypt = mongocrypt_new ();
617
- ASSERT_OK (
618
- mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, "example", -1),
619
- crypt);
620
- ASSERT_OK (mongocrypt_init (crypt), crypt);
621
- ASSERT_FAILS (mongocrypt_init (crypt), crypt, "already initialized");
622
- mongocrypt_destroy (crypt);
623
- /* Setting options after initialization must fail. */
624
- crypt = mongocrypt_new ();
625
- ASSERT_OK (
626
- mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, "example", -1),
627
- crypt);
628
- ASSERT_OK (mongocrypt_init (crypt), crypt);
629
- ASSERT_FAILS (
630
- mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, "example", -1),
631
- crypt,
632
- "options cannot be set after initialization");
633
- mongocrypt_destroy (crypt);
527
+ "invalid aws access key id");
528
+ mongocrypt_destroy(crypt);
529
+
530
+ /* Malformed UTF8 */
531
+ /* An orphaned UTF-8 continuation byte (10xxxxxx) is malformed UTF-8. */
532
+ tmp = (char)0x80;
533
+ crypt = mongocrypt_new();
534
+ ASSERT_FAILS(mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, &tmp, 1),
535
+ crypt,
536
+ "invalid aws secret access key");
537
+ mongocrypt_destroy(crypt);
538
+
539
+ crypt = mongocrypt_new();
540
+ ASSERT_FAILS(mongocrypt_setopt_kms_provider_local(crypt, NULL), crypt, "passed null key");
541
+ mongocrypt_destroy(crypt);
542
+
543
+ crypt = mongocrypt_new();
544
+ local_key = mongocrypt_binary_new();
545
+ ASSERT_FAILS(mongocrypt_setopt_kms_provider_local(crypt, local_key), crypt, "local key must be 96 bytes");
546
+ mongocrypt_binary_destroy(local_key);
547
+ mongocrypt_destroy(crypt);
548
+
549
+ /* Reinitialization must fail. */
550
+ crypt = mongocrypt_new();
551
+ ASSERT_OK(mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, "example", -1), crypt);
552
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
553
+ ASSERT_FAILS(mongocrypt_init(crypt), crypt, "already initialized");
554
+ mongocrypt_destroy(crypt);
555
+ /* Setting options after initialization must fail. */
556
+ crypt = mongocrypt_new();
557
+ ASSERT_OK(mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, "example", -1), crypt);
558
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
559
+ ASSERT_FAILS(mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, "example", -1),
560
+ crypt,
561
+ "options cannot be set after initialization");
562
+ mongocrypt_destroy(crypt);
634
563
  }
635
564
 
565
+ static void _test_setopt_schema(_mongocrypt_tester_t *tester) {
566
+ mongocrypt_t *crypt;
636
567
 
637
- static void
638
- _test_setopt_schema (_mongocrypt_tester_t *tester)
639
- {
640
- mongocrypt_t *crypt;
641
-
642
- /* Test double setting. */
643
- crypt = mongocrypt_new ();
644
- ASSERT_OK (mongocrypt_setopt_schema_map (
645
- crypt, TEST_FILE ("./test/data/schema-map.json")),
646
- crypt);
647
- ASSERT_FAILS (mongocrypt_setopt_schema_map (
648
- crypt, TEST_FILE ("./test/data/schema-map.json")),
568
+ /* Test double setting. */
569
+ crypt = mongocrypt_new();
570
+ ASSERT_OK(mongocrypt_setopt_schema_map(crypt, TEST_FILE("./test/data/schema-map.json")), crypt);
571
+ ASSERT_FAILS(mongocrypt_setopt_schema_map(crypt, TEST_FILE("./test/data/schema-map.json")),
649
572
  crypt,
650
573
  "already set schema");
651
574
 
652
- /* Test NULL/empty input */
653
- mongocrypt_destroy (crypt);
654
- crypt = mongocrypt_new ();
655
- ASSERT_FAILS (
656
- mongocrypt_setopt_schema_map (crypt, NULL), crypt, "passed null schema");
575
+ /* Test NULL/empty input */
576
+ mongocrypt_destroy(crypt);
577
+ crypt = mongocrypt_new();
578
+ ASSERT_FAILS(mongocrypt_setopt_schema_map(crypt, NULL), crypt, "passed null schema");
657
579
 
658
- mongocrypt_destroy (crypt);
659
- crypt = mongocrypt_new ();
660
- ASSERT_FAILS (mongocrypt_setopt_schema_map (crypt, TEST_BIN (0)),
661
- crypt,
662
- "passed null schema");
580
+ mongocrypt_destroy(crypt);
581
+ crypt = mongocrypt_new();
582
+ ASSERT_FAILS(mongocrypt_setopt_schema_map(crypt, TEST_BIN(0)), crypt, "passed null schema");
663
583
 
664
- /* Test malformed BSON */
665
- mongocrypt_destroy (crypt);
666
- crypt = mongocrypt_new ();
667
- ASSERT_FAILS (mongocrypt_setopt_schema_map (crypt, TEST_BIN (10)),
668
- crypt,
669
- "invalid bson");
670
- mongocrypt_destroy (crypt);
584
+ /* Test malformed BSON */
585
+ mongocrypt_destroy(crypt);
586
+ crypt = mongocrypt_new();
587
+ ASSERT_FAILS(mongocrypt_setopt_schema_map(crypt, TEST_BIN(10)), crypt, "invalid bson");
588
+ mongocrypt_destroy(crypt);
671
589
  }
672
590
 
673
- static void
674
- _test_setopt_encrypted_field_config_map (_mongocrypt_tester_t *tester)
675
- {
676
- mongocrypt_t *crypt;
677
-
678
- /* Test success. */
679
- crypt = mongocrypt_new ();
680
- ASSERT_OK (
681
- mongocrypt_setopt_kms_providers (
682
- crypt,
683
- TEST_BSON (
684
- "{'aws': {'accessKeyId': 'foo', 'secretAccessKey': 'bar'}}")),
685
- crypt);
686
- ASSERT_OK (
687
- mongocrypt_setopt_encrypted_field_config_map (
688
- crypt, TEST_FILE ("./test/data/encrypted-field-config-map.json")),
689
- crypt);
690
- ASSERT_OK (mongocrypt_init (crypt), crypt);
691
- mongocrypt_destroy (crypt);
692
-
693
- /* Test double setting. */
694
- crypt = mongocrypt_new ();
695
- ASSERT_OK (
696
- mongocrypt_setopt_encrypted_field_config_map (
697
- crypt, TEST_FILE ("./test/data/encrypted-field-config-map.json")),
698
- crypt);
699
- ASSERT_FAILS (
700
- mongocrypt_setopt_encrypted_field_config_map (
701
- crypt, TEST_FILE ("./test/data/encrypted-field-config-map.json")),
702
- crypt,
703
- "already set encrypted_field_config_map");
704
- mongocrypt_destroy (crypt);
705
-
706
- /* Test NULL/empty input */
707
- crypt = mongocrypt_new ();
708
- ASSERT_FAILS (mongocrypt_setopt_encrypted_field_config_map (crypt, NULL),
591
+ static void _test_setopt_encrypted_field_config_map(_mongocrypt_tester_t *tester) {
592
+ mongocrypt_t *crypt;
593
+
594
+ /* Test success. */
595
+ crypt = mongocrypt_new();
596
+ ASSERT_OK(
597
+ mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'aws': {'accessKeyId': 'foo', 'secretAccessKey': 'bar'}}")),
598
+ crypt);
599
+ ASSERT_OK(
600
+ mongocrypt_setopt_encrypted_field_config_map(crypt, TEST_FILE("./test/data/encrypted-field-config-map.json")),
601
+ crypt);
602
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
603
+ mongocrypt_destroy(crypt);
604
+
605
+ /* Test double setting. */
606
+ crypt = mongocrypt_new();
607
+ ASSERT_OK(
608
+ mongocrypt_setopt_encrypted_field_config_map(crypt, TEST_FILE("./test/data/encrypted-field-config-map.json")),
609
+ crypt);
610
+ ASSERT_FAILS(
611
+ mongocrypt_setopt_encrypted_field_config_map(crypt, TEST_FILE("./test/data/encrypted-field-config-map.json")),
612
+ crypt,
613
+ "already set encrypted_field_config_map");
614
+ mongocrypt_destroy(crypt);
615
+
616
+ /* Test NULL/empty input */
617
+ crypt = mongocrypt_new();
618
+ ASSERT_FAILS(mongocrypt_setopt_encrypted_field_config_map(crypt, NULL),
709
619
  crypt,
710
620
  "passed null encrypted_field_config_map");
711
- mongocrypt_destroy (crypt);
712
-
713
- crypt = mongocrypt_new ();
714
- ASSERT_FAILS (
715
- mongocrypt_setopt_encrypted_field_config_map (crypt, TEST_BIN (0)),
716
- crypt,
717
- "passed null encrypted_field_config_map");
718
- mongocrypt_destroy (crypt);
719
-
720
- /* Test malformed BSON */
721
- crypt = mongocrypt_new ();
722
- ASSERT_FAILS (
723
- mongocrypt_setopt_encrypted_field_config_map (crypt, TEST_BIN (10)),
724
- crypt,
725
- "invalid bson");
726
- mongocrypt_destroy (crypt);
727
-
728
- /* Test that it is OK to set both the encrypted field config map and schema
729
- * map if there are no intersecting collections. */
730
- crypt = mongocrypt_new ();
731
- ASSERT_OK (mongocrypt_setopt_schema_map (
732
- crypt, TEST_BSON ("{'db.coll1': {}, 'db.coll2': {}}")),
733
- crypt);
734
- ASSERT_OK (mongocrypt_setopt_encrypted_field_config_map (
735
- crypt, TEST_BSON ("{'db.coll3': {}, 'db.coll3': {}}")),
736
- crypt);
737
- ASSERT_OK (
738
- mongocrypt_setopt_kms_providers (
739
- crypt,
740
- TEST_BSON (
741
- "{'aws': {'accessKeyId': 'foo', 'secretAccessKey': 'bar'}}")),
742
- crypt);
743
- ASSERT_OK (mongocrypt_init (crypt), crypt);
744
- mongocrypt_destroy (crypt);
745
-
746
- /* Test that it is an error to set both the encrypted field config map and
747
- * schema map referencing the same collection. */
748
- crypt = mongocrypt_new ();
749
- ASSERT_OK (mongocrypt_setopt_schema_map (
750
- crypt, TEST_BSON ("{'db.coll1': {}, 'db.coll2': {}}")),
621
+ mongocrypt_destroy(crypt);
622
+
623
+ crypt = mongocrypt_new();
624
+ ASSERT_FAILS(mongocrypt_setopt_encrypted_field_config_map(crypt, TEST_BIN(0)),
625
+ crypt,
626
+ "passed null encrypted_field_config_map");
627
+ mongocrypt_destroy(crypt);
628
+
629
+ /* Test malformed BSON */
630
+ crypt = mongocrypt_new();
631
+ ASSERT_FAILS(mongocrypt_setopt_encrypted_field_config_map(crypt, TEST_BIN(10)), crypt, "invalid bson");
632
+ mongocrypt_destroy(crypt);
633
+
634
+ /* Test that it is OK to set both the encrypted field config map and schema
635
+ * map if there are no intersecting collections. */
636
+ crypt = mongocrypt_new();
637
+ ASSERT_OK(mongocrypt_setopt_schema_map(crypt, TEST_BSON("{'db.coll1': {}, 'db.coll2': {}}")), crypt);
638
+ ASSERT_OK(mongocrypt_setopt_encrypted_field_config_map(crypt, TEST_BSON("{'db.coll3': {}, 'db.coll3': {}}")),
751
639
  crypt);
752
- ASSERT_OK (mongocrypt_setopt_encrypted_field_config_map (
753
- crypt, TEST_BSON ("{'db.coll1': {}, 'db.coll3': {}}")),
640
+ ASSERT_OK(
641
+ mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'aws': {'accessKeyId': 'foo', 'secretAccessKey': 'bar'}}")),
642
+ crypt);
643
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
644
+ mongocrypt_destroy(crypt);
645
+
646
+ /* Test that it is an error to set both the encrypted field config map and
647
+ * schema map referencing the same collection. */
648
+ crypt = mongocrypt_new();
649
+ ASSERT_OK(mongocrypt_setopt_schema_map(crypt, TEST_BSON("{'db.coll1': {}, 'db.coll2': {}}")), crypt);
650
+ ASSERT_OK(mongocrypt_setopt_encrypted_field_config_map(crypt, TEST_BSON("{'db.coll1': {}, 'db.coll3': {}}")),
754
651
  crypt);
755
- ASSERT_OK (
756
- mongocrypt_setopt_kms_providers (
757
- crypt,
758
- TEST_BSON (
759
- "{'aws': {'accessKeyId': 'foo', 'secretAccessKey': 'bar'}}")),
760
- crypt);
761
- ASSERT_FAILS (
762
- mongocrypt_init (crypt),
763
- crypt,
764
- "db.coll1 is present in both schema_map and encrypted_field_config_map");
765
- mongocrypt_destroy (crypt);
652
+ ASSERT_OK(
653
+ mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'aws': {'accessKeyId': 'foo', 'secretAccessKey': 'bar'}}")),
654
+ crypt);
655
+ ASSERT_FAILS(mongocrypt_init(crypt),
656
+ crypt,
657
+ "db.coll1 is present in both schema_map and encrypted_field_config_map");
658
+ mongocrypt_destroy(crypt);
766
659
  }
767
660
 
768
- static void
769
- _test_setopt_invalid_kms_providers (_mongocrypt_tester_t *tester)
770
- {
771
- mongocrypt_t *crypt;
772
- mongocrypt_ctx_t *ctx;
773
- mongocrypt_status_t *status;
774
-
775
- crypt = mongocrypt_new ();
776
- ASSERT_OK (mongocrypt_setopt_kms_provider_aws (crypt, "", 0, "", 0), crypt);
777
- ASSERT_OK (mongocrypt_init (crypt), crypt);
778
-
779
- ctx = mongocrypt_ctx_new (crypt);
780
- ASSERT_OK (mongocrypt_ctx_setopt_masterkey_aws (ctx, "region", -1, "cmk", 3),
781
- ctx);
782
- mongocrypt_ctx_datakey_init (ctx);
783
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_ERROR);
784
-
785
- status = mongocrypt_status_new ();
786
- BSON_ASSERT (!mongocrypt_ctx_status (ctx, status));
787
- ASSERT_STATUS_CONTAINS (status, "failed to create KMS message");
788
-
789
- mongocrypt_status_destroy (status);
790
- mongocrypt_ctx_destroy (ctx);
791
- mongocrypt_destroy (crypt);
792
-
793
- crypt = mongocrypt_new ();
794
- mongocrypt_setopt_use_need_kms_credentials_state (crypt);
795
- ASSERT_OK (mongocrypt_setopt_kms_providers (crypt, TEST_BSON ("{}")), crypt);
796
- ASSERT_FAILS (mongocrypt_init (crypt), crypt, "no kms provider set");
797
- mongocrypt_destroy (crypt);
661
+ static void _test_setopt_invalid_kms_providers(_mongocrypt_tester_t *tester) {
662
+ mongocrypt_t *crypt;
663
+ mongocrypt_ctx_t *ctx;
664
+ mongocrypt_status_t *status;
665
+
666
+ crypt = mongocrypt_new();
667
+ ASSERT_OK(mongocrypt_setopt_kms_provider_aws(crypt, "", 0, "", 0), crypt);
668
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
669
+
670
+ ctx = mongocrypt_ctx_new(crypt);
671
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, "region", -1, "cmk", 3), ctx);
672
+ mongocrypt_ctx_datakey_init(ctx);
673
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_ERROR);
674
+
675
+ status = mongocrypt_status_new();
676
+ BSON_ASSERT(!mongocrypt_ctx_status(ctx, status));
677
+ ASSERT_STATUS_CONTAINS(status, "failed to create KMS message");
678
+
679
+ mongocrypt_status_destroy(status);
680
+ mongocrypt_ctx_destroy(ctx);
681
+ mongocrypt_destroy(crypt);
682
+
683
+ crypt = mongocrypt_new();
684
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
685
+ ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{}")), crypt);
686
+ ASSERT_FAILS(mongocrypt_init(crypt), crypt, "no kms provider set");
687
+ mongocrypt_destroy(crypt);
798
688
  }
799
689
 
800
690
  typedef struct {
801
- char *value;
802
- /* errmsg is the expected error message from mongocrypt_setopt_kms_providers
803
- */
804
- char *errmsg;
805
- /* errmsg_init is the expected error message from mongocrypt_init */
806
- char *errmsg_init;
807
- bool use_need_kms_credentials_state;
691
+ char *value;
692
+ /* errmsg is the expected error message from mongocrypt_setopt_kms_providers
693
+ */
694
+ char *errmsg;
695
+ /* errmsg_init is the expected error message from mongocrypt_init */
696
+ char *errmsg_init;
697
+ bool use_need_kms_credentials_state;
808
698
  } setopt_kms_providers_testcase_t;
809
699
 
810
- #define EXAMPLE_LOCAL_MATERIAL \
811
- "TlPm8M/Uxs0eK13ReFeOUyxVC2rarCf5+LbKuY/dnFxS/" \
812
- "LoYc1CZqnfSXujqqWrrt3fOTQ2TdtNhO4bBfamOyJPx4uJSstehc7It4pLp3LHes70z64AYqJ" \
813
- "Uemk4G+2He"
814
-
815
- static void
816
- _test_setopt_kms_providers (_mongocrypt_tester_t *tester)
817
- {
818
- setopt_kms_providers_testcase_t *test;
819
- size_t i;
820
- setopt_kms_providers_testcase_t tests[] = {
821
- {"{'azure': {'tenantId': '', 'clientId': '', 'clientSecret': '', "
822
- "'identityPlatformEndpoint': 'example.com' }}",
823
- NULL},
824
- {"{'azure': {'tenantId': '', 'clientId': '', 'clientSecret': '' }}",
825
- NULL},
826
- {"{'azure': {'tenantId': '', 'clientId': '', 'clientSecret': '', "
827
- "'identityPlatformEndpoint': 'example' }}",
828
- "Invalid endpoint"},
829
- {"{'azure': {'tenantId': '', 'clientSecret': '' }}", "clientId"},
830
- {"{'aws': {'accessKeyId': 'abc', 'secretAccessKey': 'def'}}", NULL},
831
- {"{'local': {'key': {'$binary': {'base64': '" EXAMPLE_LOCAL_MATERIAL
832
- "', 'subType': '00'}} }}",
833
- NULL},
834
- {"{'local': {'key': '" EXAMPLE_LOCAL_MATERIAL "' }}", NULL},
835
- {"{'local': {'key': 'invalid base64' }}", "unable to parse base64"},
836
- /* either base64 string or binary is acceptable for privateKey */
837
- {"{'gcp': {'endpoint': 'oauth2.googleapis.com', 'email': 'test', "
838
- "'privateKey': 'AAAA' }}"},
839
- {"{'gcp': {'endpoint': 'oauth2.googleapis.com', 'email': 'test', "
840
- "'privateKey': {'$binary': {'base64': 'AAAA', 'subType': '00'}} }}"},
841
- /* endpoint is not required. */
842
- {"{'gcp': {'email': 'test', 'privateKey': 'AAAA' }}"},
843
- {"{'gcp': {'privateKey': 'AAAA'}}", "expected UTF-8 gcp.email"},
844
- {"{'gcp': {'email': 'test', 'privateKey': 'invalid base64' }}",
845
- "unable to parse base64"},
846
- {"{'gcp': {'endpoint': 'example', 'email': 'test', 'privateKey': "
847
- "'AAAA'}}",
848
- "Invalid endpoint"},
849
- {"{'azure': {'tenantId': '', 'clientId': '', 'clientSecret': '', "
850
- "'identityPlatformEndpoint': 'example.com', 'extra': 'invalid' }}",
851
- "Unexpected field: 'extra'"},
852
- {"{'aws': {'accessKeyId': 'abc', 'secretAccessKey': 'def', 'extra': "
853
- "'invalid'}}",
854
- "Unexpected field: 'extra'"},
855
- {"{'gcp': {'endpoint': 'oauth2.googleapis.com', 'email': 'test', "
856
- "'privateKey': 'AAAA', 'extra': 'invalid' }}",
857
- "Unexpected field: 'extra'"},
858
- {"{'local': {'key': '" EXAMPLE_LOCAL_MATERIAL "', 'extra': 'invalid' }}",
859
- "Unexpected field: 'extra'"},
860
- {"{'local': {'key': 'AAAA'}}", "local key must be 96 bytes"},
861
- /* KMIP test cases. */
862
- {"{'kmip': {'endpoint': '127.0.0.1:5696' }}", NULL},
863
- /* localhost is a valid endpoint for KMIP.
864
- * Unlike Azure, GCP, and AWS, applications run their own KMIP servers. */
865
- {"{'kmip': {'endpoint': 'localhost' }}", NULL},
866
- {"{'kmip': {'endpoint': '127.0.0.1:5696', 'extra': 'invalid' }}",
867
- "Unexpected field: 'extra'"},
868
- /* Empty documents are OK if on-demand KMS credentials are opted-in with
869
- * a call to mongocrypt_setopt_use_need_kms_credentials_state. */
870
- {"{'aws': {}}", NULL, NULL, true},
871
- {"{'azure': {}}", NULL, NULL, true},
872
- {"{'local': {}}", NULL, NULL, true},
873
- {"{'gcp': {}}", NULL, NULL, true},
874
- {"{'kmip': {}}", NULL, NULL, true},
875
- /* Empty documents are not OK if on-demand KMS credentials are not
876
- opted-in. */
877
- {"{'aws': {}}", NULL, "on-demand credentials not enabled", false},
878
- {"{'azure': {}}", NULL, "on-demand credentials not enabled", false},
879
- {"{'local': {}}", NULL, "on-demand credentials not enabled", false},
880
- {"{'gcp': {}}", NULL, "on-demand credentials not enabled", false},
881
- {"{'kmip': {}}", NULL, "on-demand credentials not enabled", false},
882
- {"{'gcp': {'accessToken': 'foobar', 'email': 'foo@bar.com' }}",
883
- "Unexpected field: 'email'"},
884
- {.value = "{ 'azure': { 'accessToken': 'secret' } }"},
885
- };
886
-
887
- for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) {
888
- mongocrypt_t *crypt;
889
-
890
- test = tests + i;
891
- crypt = mongocrypt_new ();
892
- if (test->use_need_kms_credentials_state) {
893
- mongocrypt_setopt_use_need_kms_credentials_state (crypt);
894
- }
895
- if (!test->errmsg) {
896
- ASSERT_OK (
897
- mongocrypt_setopt_kms_providers (crypt, TEST_BSON (test->value)),
898
- crypt);
899
- if (!test->errmsg_init) {
900
- ASSERT_OK (mongocrypt_init (crypt), crypt);
901
- } else {
902
- ASSERT_FAILS (mongocrypt_init (crypt), crypt, test->errmsg_init);
903
- }
904
- } else {
905
- ASSERT_FAILS (
906
- mongocrypt_setopt_kms_providers (crypt, TEST_BSON (test->value)),
907
- crypt,
908
- test->errmsg);
909
- }
910
- mongocrypt_destroy (crypt);
911
- }
700
+ #define EXAMPLE_LOCAL_MATERIAL \
701
+ "TlPm8M/Uxs0eK13ReFeOUyxVC2rarCf5+LbKuY/dnFxS/" \
702
+ "LoYc1CZqnfSXujqqWrrt3fOTQ2TdtNhO4bBfamOyJPx4uJSstehc7It4pLp3LHes70z64AYqJ" \
703
+ "Uemk4G+2He"
704
+
705
+ static void _test_setopt_kms_providers(_mongocrypt_tester_t *tester) {
706
+ setopt_kms_providers_testcase_t *test;
707
+ size_t i;
708
+ setopt_kms_providers_testcase_t tests[] = {
709
+ {"{'azure': {'tenantId': '', 'clientId': '', 'clientSecret': '', "
710
+ "'identityPlatformEndpoint': 'example.com' }}",
711
+ NULL},
712
+ {"{'azure': {'tenantId': '', 'clientId': '', 'clientSecret': '' }}", NULL},
713
+ {"{'azure': {'tenantId': '', 'clientId': '', 'clientSecret': '', "
714
+ "'identityPlatformEndpoint': 'example' }}",
715
+ "Invalid endpoint"},
716
+ {"{'azure': {'tenantId': '', 'clientSecret': '' }}", "clientId"},
717
+ {"{'aws': {'accessKeyId': 'abc', 'secretAccessKey': 'def'}}", NULL},
718
+ {"{'local': {'key': {'$binary': {'base64': '" EXAMPLE_LOCAL_MATERIAL "', 'subType': '00'}} }}", NULL},
719
+ {"{'local': {'key': '" EXAMPLE_LOCAL_MATERIAL "' }}", NULL},
720
+ {"{'local': {'key': 'invalid base64' }}", "unable to parse base64"},
721
+ /* either base64 string or binary is acceptable for privateKey */
722
+ {"{'gcp': {'endpoint': 'oauth2.googleapis.com', 'email': 'test', "
723
+ "'privateKey': 'AAAA' }}"},
724
+ {"{'gcp': {'endpoint': 'oauth2.googleapis.com', 'email': 'test', "
725
+ "'privateKey': {'$binary': {'base64': 'AAAA', 'subType': '00'}} }}"},
726
+ /* endpoint is not required. */
727
+ {"{'gcp': {'email': 'test', 'privateKey': 'AAAA' }}"},
728
+ {"{'gcp': {'privateKey': 'AAAA'}}", "expected UTF-8 gcp.email"},
729
+ {"{'gcp': {'email': 'test', 'privateKey': 'invalid base64' }}", "unable to parse base64"},
730
+ {"{'gcp': {'endpoint': 'example', 'email': 'test', 'privateKey': "
731
+ "'AAAA'}}",
732
+ "Invalid endpoint"},
733
+ {"{'azure': {'tenantId': '', 'clientId': '', 'clientSecret': '', "
734
+ "'identityPlatformEndpoint': 'example.com', 'extra': 'invalid' }}",
735
+ "Unexpected field: 'extra'"},
736
+ {"{'aws': {'accessKeyId': 'abc', 'secretAccessKey': 'def', 'extra': "
737
+ "'invalid'}}",
738
+ "Unexpected field: 'extra'"},
739
+ {"{'gcp': {'endpoint': 'oauth2.googleapis.com', 'email': 'test', "
740
+ "'privateKey': 'AAAA', 'extra': 'invalid' }}",
741
+ "Unexpected field: 'extra'"},
742
+ {"{'local': {'key': '" EXAMPLE_LOCAL_MATERIAL "', 'extra': 'invalid' }}", "Unexpected field: 'extra'"},
743
+ {"{'local': {'key': 'AAAA'}}", "local key must be 96 bytes"},
744
+ /* KMIP test cases. */
745
+ {"{'kmip': {'endpoint': '127.0.0.1:5696' }}", NULL},
746
+ /* localhost is a valid endpoint for KMIP.
747
+ * Unlike Azure, GCP, and AWS, applications run their own KMIP servers. */
748
+ {"{'kmip': {'endpoint': 'localhost' }}", NULL},
749
+ {"{'kmip': {'endpoint': '127.0.0.1:5696', 'extra': 'invalid' }}", "Unexpected field: 'extra'"},
750
+ /* Empty documents are OK if on-demand KMS credentials are opted-in with
751
+ * a call to mongocrypt_setopt_use_need_kms_credentials_state. */
752
+ {"{'aws': {}}", NULL, NULL, true},
753
+ {"{'azure': {}}", NULL, NULL, true},
754
+ {"{'local': {}}", NULL, NULL, true},
755
+ {"{'gcp': {}}", NULL, NULL, true},
756
+ {"{'kmip': {}}", NULL, NULL, true},
757
+ /* Empty documents are not OK if on-demand KMS credentials are not
758
+ opted-in. */
759
+ {"{'aws': {}}", NULL, "on-demand credentials not enabled", false},
760
+ {"{'azure': {}}", NULL, "on-demand credentials not enabled", false},
761
+ {"{'local': {}}", NULL, "on-demand credentials not enabled", false},
762
+ {"{'gcp': {}}", NULL, "on-demand credentials not enabled", false},
763
+ {"{'kmip': {}}", NULL, "on-demand credentials not enabled", false},
764
+ {"{'gcp': {'accessToken': 'foobar', 'email': 'foo@bar.com' }}", "Unexpected field: 'email'"},
765
+ {.value = "{ 'azure': { 'accessToken': 'secret' } }"},
766
+ };
767
+
768
+ for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
769
+ mongocrypt_t *crypt;
770
+
771
+ test = tests + i;
772
+ crypt = mongocrypt_new();
773
+ if (test->use_need_kms_credentials_state) {
774
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
775
+ }
776
+ if (!test->errmsg) {
777
+ ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, TEST_BSON(test->value)), crypt);
778
+ if (!test->errmsg_init) {
779
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
780
+ } else {
781
+ ASSERT_FAILS(mongocrypt_init(crypt), crypt, test->errmsg_init);
782
+ }
783
+ } else {
784
+ ASSERT_FAILS(mongocrypt_setopt_kms_providers(crypt, TEST_BSON(test->value)), crypt, test->errmsg);
785
+ }
786
+ mongocrypt_destroy(crypt);
787
+ }
912
788
  }
913
789
 
914
790
  bool _aes_ctr_is_supported_by_os = true;
915
791
 
916
- int
917
- main (int argc, char **argv)
918
- {
919
- _mongocrypt_tester_t tester = {0};
920
- int i;
921
-
922
- printf ("Pass a list of test names to run only specific tests. E.g.:\n");
923
- printf ("test-mongocrypt _mongocrypt_test_mcgrew\n\n");
924
-
925
- /* Install all tests. */
926
- _mongocrypt_tester_install_crypto (&tester);
927
- _mongocrypt_tester_install_log (&tester);
928
- _mongocrypt_tester_install_data_key (&tester);
929
- _mongocrypt_tester_install_ctx_encrypt (&tester);
930
- _mongocrypt_tester_install_ctx_decrypt (&tester);
931
- _mongocrypt_tester_install_ctx_rewrap_many_datakey (&tester);
932
- _mongocrypt_tester_install_ciphertext (&tester);
933
- _mongocrypt_tester_install_key_broker (&tester);
934
- _mongocrypt_tester_install (&tester,
935
- "_test_mongocrypt_bad_init",
936
- _test_mongocrypt_bad_init,
937
- CRYPTO_REQUIRED);
938
- _mongocrypt_tester_install_local_kms (&tester);
939
- _mongocrypt_tester_install_cache (&tester);
940
- _mongocrypt_tester_install_buffer (&tester);
941
- _mongocrypt_tester_install_ctx_setopt (&tester);
942
- _mongocrypt_tester_install_key (&tester);
943
- _mongocrypt_tester_install_marking (&tester);
944
- _mongocrypt_tester_install_traverse_util (&tester);
945
- _mongocrypt_tester_install (
946
- &tester, "_test_setopt_schema", _test_setopt_schema, CRYPTO_REQUIRED);
947
- _mongocrypt_tester_install (&tester,
792
+ int main(int argc, char **argv) {
793
+ _mongocrypt_tester_t tester = {0};
794
+ int i;
795
+
796
+ printf("Pass a list of test names to run only specific tests. E.g.:\n");
797
+ printf("test-mongocrypt _mongocrypt_test_mcgrew\n\n");
798
+
799
+ /* Install all tests. */
800
+ _mongocrypt_tester_install_crypto(&tester);
801
+ _mongocrypt_tester_install_log(&tester);
802
+ _mongocrypt_tester_install_data_key(&tester);
803
+ _mongocrypt_tester_install_ctx_encrypt(&tester);
804
+ _mongocrypt_tester_install_ctx_decrypt(&tester);
805
+ _mongocrypt_tester_install_ctx_rewrap_many_datakey(&tester);
806
+ _mongocrypt_tester_install_ciphertext(&tester);
807
+ _mongocrypt_tester_install_key_broker(&tester);
808
+ _mongocrypt_tester_install(&tester, "_test_mongocrypt_bad_init", _test_mongocrypt_bad_init, CRYPTO_REQUIRED);
809
+ _mongocrypt_tester_install_local_kms(&tester);
810
+ _mongocrypt_tester_install_cache(&tester);
811
+ _mongocrypt_tester_install_buffer(&tester);
812
+ _mongocrypt_tester_install_ctx_setopt(&tester);
813
+ _mongocrypt_tester_install_key(&tester);
814
+ _mongocrypt_tester_install_marking(&tester);
815
+ _mongocrypt_tester_install_traverse_util(&tester);
816
+ _mongocrypt_tester_install(&tester, "_test_setopt_schema", _test_setopt_schema, CRYPTO_REQUIRED);
817
+ _mongocrypt_tester_install(&tester,
948
818
  "_test_setopt_encrypted_field_config_map",
949
819
  _test_setopt_encrypted_field_config_map,
950
820
  CRYPTO_REQUIRED);
951
- _mongocrypt_tester_install (&tester,
821
+ _mongocrypt_tester_install(&tester,
952
822
  "_test_setopt_invalid_kms_providers",
953
823
  _test_setopt_invalid_kms_providers,
954
824
  CRYPTO_REQUIRED);
955
- _mongocrypt_tester_install_crypto_hooks (&tester);
956
- _mongocrypt_tester_install_key_cache (&tester);
957
- _mongocrypt_tester_install_kms_responses (&tester);
958
- _mongocrypt_tester_install_status (&tester);
959
- _mongocrypt_tester_install_endpoint (&tester);
960
- _mongocrypt_tester_install (&tester,
961
- "_test_setopt_kms_providers",
962
- _test_setopt_kms_providers,
963
- CRYPTO_OPTIONAL);
964
- _mongocrypt_tester_install_kek (&tester);
965
- _mongocrypt_tester_install_cache_oauth (&tester);
966
- _mongocrypt_tester_install_kms_ctx (&tester);
967
- _mongocrypt_tester_install_csfle_lib (&tester);
968
- _mongocrypt_tester_install_dll (&tester);
969
- _mongocrypt_tester_install_mc_tokens (&tester);
970
- _mongocrypt_tester_install_fle2_payloads (&tester);
971
- _mongocrypt_tester_install_efc (&tester);
972
- _mongocrypt_tester_install_compact (&tester);
973
- _mongocrypt_tester_install_fle2_payload_uev (&tester);
974
- _mongocrypt_tester_install_fle2_payload_iup (&tester);
975
- _mongocrypt_tester_install_range_encoding (&tester);
976
- _mongocrypt_tester_install_range_edge_generation (&tester);
977
- _mongocrypt_tester_install_range_mincover (&tester);
978
- _mongocrypt_tester_install_mc_RangeOpts (&tester);
979
- _mongocrypt_tester_install_mc_FLE2RangeFindDriverSpec (&tester);
980
- _mongocrypt_tester_install_gcp_auth (&tester);
981
- _mongocrypt_tester_install_mc_reader (&tester);
825
+ _mongocrypt_tester_install_crypto_hooks(&tester);
826
+ _mongocrypt_tester_install_key_cache(&tester);
827
+ _mongocrypt_tester_install_kms_responses(&tester);
828
+ _mongocrypt_tester_install_status(&tester);
829
+ _mongocrypt_tester_install_endpoint(&tester);
830
+ _mongocrypt_tester_install(&tester, "_test_setopt_kms_providers", _test_setopt_kms_providers, CRYPTO_OPTIONAL);
831
+ _mongocrypt_tester_install_kek(&tester);
832
+ _mongocrypt_tester_install_cache_oauth(&tester);
833
+ _mongocrypt_tester_install_kms_ctx(&tester);
834
+ _mongocrypt_tester_install_csfle_lib(&tester);
835
+ _mongocrypt_tester_install_dll(&tester);
836
+ _mongocrypt_tester_install_mc_tokens(&tester);
837
+ _mongocrypt_tester_install_fle2_payloads(&tester);
838
+ _mongocrypt_tester_install_fle2_iev_v2_payloads(&tester);
839
+ _mongocrypt_tester_install_efc(&tester);
840
+ _mongocrypt_tester_install_compact(&tester);
841
+ _mongocrypt_tester_install_fle2_payload_uev(&tester);
842
+ _mongocrypt_tester_install_fle2_payload_uev_v2(&tester);
843
+ _mongocrypt_tester_install_fle2_payload_iup(&tester);
844
+ _mongocrypt_tester_install_fle2_payload_iup_v2(&tester);
845
+ _mongocrypt_tester_install_fle2_payload_find_equality_v2(&tester);
846
+ _mongocrypt_tester_install_fle2_payload_find_range_v2(&tester);
847
+ _mongocrypt_tester_install_range_encoding(&tester);
848
+ _mongocrypt_tester_install_range_edge_generation(&tester);
849
+ _mongocrypt_tester_install_range_mincover(&tester);
850
+ _mongocrypt_tester_install_mc_RangeOpts(&tester);
851
+ _mongocrypt_tester_install_mc_FLE2RangeFindDriverSpec(&tester);
852
+ _mongocrypt_tester_install_gcp_auth(&tester);
853
+ _mongocrypt_tester_install_mc_reader(&tester);
854
+ _mongocrypt_tester_install_mc_writer(&tester);
982
855
 
983
856
  #ifdef MONGOCRYPT_ENABLE_CRYPTO_COMMON_CRYPTO
984
- char osversion[32];
985
- size_t osversion_len = sizeof (osversion) - 1;
986
- int osversion_name[] = {CTL_KERN, KERN_OSRELEASE};
987
-
988
- _aes_ctr_is_supported_by_os = false;
989
-
990
- if (sysctl (osversion_name, 2, osversion, &osversion_len, NULL, 0) == -1) {
991
- goto get_os_version_failed;
992
- }
993
-
994
- uint32_t major, minor;
995
- if (sscanf (osversion, "%u.%u", &major, &minor) != 2) {
996
- goto get_os_version_failed;
997
- }
998
-
999
- if (major >= 20) {
1000
- // macOS 11 and newer
1001
- _aes_ctr_is_supported_by_os = true;
1002
- } else {
1003
- major -= 4;
1004
- // macOS 10.1.1 and newer. CTR unsupported in 10.14 and earlier
1005
- _aes_ctr_is_supported_by_os = major > 14;
1006
- }
857
+ char osversion[32];
858
+ size_t osversion_len = sizeof(osversion) - 1;
859
+ int osversion_name[] = {CTL_KERN, KERN_OSRELEASE};
860
+
861
+ _aes_ctr_is_supported_by_os = false;
862
+
863
+ if (sysctl(osversion_name, 2, osversion, &osversion_len, NULL, 0) == -1) {
864
+ goto get_os_version_failed;
865
+ }
866
+
867
+ uint32_t major, minor;
868
+ if (sscanf(osversion, "%u.%u", &major, &minor) != 2) {
869
+ goto get_os_version_failed;
870
+ }
871
+
872
+ if (major >= 20) {
873
+ // macOS 11 and newer
874
+ _aes_ctr_is_supported_by_os = true;
875
+ } else {
876
+ major -= 4;
877
+ // macOS 10.1.1 and newer. CTR unsupported in 10.14 and earlier
878
+ _aes_ctr_is_supported_by_os = major > 14;
879
+ }
1007
880
  get_os_version_failed:
1008
881
  #endif
1009
882
 
1010
- printf ("Running tests...\n");
1011
- for (i = 0; tester.test_names[i]; i++) {
1012
- int j;
1013
- bool found = false;
1014
-
1015
- if (argc > 1) {
1016
- for (j = 1; j < argc; j++) {
1017
- found = (0 == strcmp (argv[j], tester.test_names[i]));
1018
- if (found)
1019
- break;
1020
- }
1021
- if (!found) {
1022
- continue;
1023
- }
1024
- }
1025
- printf (" begin %s\n", tester.test_names[i]);
1026
- tester.test_fns[i](&tester);
1027
- /* Clear state. */
1028
- memset (&tester.paths, 0, sizeof (tester.paths));
1029
- printf (" end %s\n", tester.test_names[i]);
1030
- }
1031
- printf ("... done running tests\n");
1032
-
1033
- if (i == 0) {
1034
- printf ("WARNING - no tests run.\n");
1035
- }
1036
-
1037
- /* Clean up tester. */
1038
- for (i = 0; i < tester.test_count; i++) {
1039
- bson_free (tester.test_names[i]);
1040
- }
1041
-
1042
- for (i = 0; i < tester.file_count; i++) {
1043
- _mongocrypt_buffer_cleanup (&tester.file_bufs[i]);
1044
- bson_free (tester.file_paths[i]);
1045
- }
1046
-
1047
- for (i = 0; i < tester.bin_count; i++) {
1048
- mongocrypt_binary_destroy (tester.test_bin[i]);
1049
- }
1050
-
1051
- for (i = 0; i < tester.bson_count; i++) {
1052
- bson_destroy (&tester.test_bson[i]);
1053
- }
1054
-
1055
- for (i = 0; i < tester.blob_count; i++) {
1056
- bson_free (tester.test_blob[i]);
1057
- }
1058
-
1059
- _mongocrypt_buffer_cleanup (&tester.encrypted_doc);
883
+ printf("Running tests...\n");
884
+ for (i = 0; tester.test_names[i]; i++) {
885
+ int j;
886
+ bool found = false;
887
+
888
+ if (argc > 1) {
889
+ for (j = 1; j < argc; j++) {
890
+ found = (0 == strcmp(argv[j], tester.test_names[i]));
891
+ if (found) {
892
+ break;
893
+ }
894
+ }
895
+ if (!found) {
896
+ continue;
897
+ }
898
+ }
899
+ printf(" begin %s\n", tester.test_names[i]);
900
+ tester.test_fns[i](&tester);
901
+ /* Clear state. */
902
+ memset(&tester.paths, 0, sizeof(tester.paths));
903
+ printf(" end %s\n", tester.test_names[i]);
904
+ }
905
+ printf("... done running tests\n");
906
+
907
+ if (i == 0) {
908
+ printf("WARNING - no tests run.\n");
909
+ }
910
+
911
+ /* Clean up tester. */
912
+ for (i = 0; i < tester.test_count; i++) {
913
+ bson_free(tester.test_names[i]);
914
+ }
915
+
916
+ for (i = 0; i < tester.file_count; i++) {
917
+ _mongocrypt_buffer_cleanup(&tester.file_bufs[i]);
918
+ bson_free(tester.file_paths[i]);
919
+ }
920
+
921
+ for (i = 0; i < tester.bin_count; i++) {
922
+ mongocrypt_binary_destroy(tester.test_bin[i]);
923
+ }
924
+
925
+ for (i = 0; i < tester.bson_count; i++) {
926
+ bson_destroy(&tester.test_bson[i]);
927
+ }
928
+
929
+ for (i = 0; i < tester.blob_count; i++) {
930
+ bson_free(tester.test_blob[i]);
931
+ }
932
+
933
+ _mongocrypt_buffer_cleanup(&tester.encrypted_doc);
934
+ }
935
+
936
+ void _test_ctx_wrap_and_feed_key(mongocrypt_ctx_t *ctx,
937
+ const _mongocrypt_buffer_t *id,
938
+ _mongocrypt_buffer_t *key,
939
+ mongocrypt_status_t *status) {
940
+ // Wrap key using local provider.
941
+ _mongocrypt_buffer_t kek = _mongocrypt_ctx_kms_providers(ctx)->local.key;
942
+ _mongocrypt_buffer_t encrypted_key;
943
+ _mongocrypt_buffer_init(&encrypted_key);
944
+ ASSERT_OK_STATUS(_mongocrypt_wrap_key(ctx->crypt->crypto, &kek, key, &encrypted_key, status), status);
945
+
946
+ bson_t doc;
947
+ bson_init(&doc);
948
+ ASSERT(bson_append_binary(&doc, "_id", (int)strlen("_id"), BSON_SUBTYPE_UUID, id->data, id->len));
949
+ ASSERT(bson_append_binary(&doc,
950
+ "keyMaterial",
951
+ (int)strlen("keyMaterial"),
952
+ BSON_SUBTYPE_BINARY,
953
+ encrypted_key.data,
954
+ encrypted_key.len));
955
+ ASSERT(bson_append_now_utc(&doc, "creationDate", (int)strlen("creationDate")));
956
+ ASSERT(bson_append_now_utc(&doc, "updateDate", (int)strlen("updateDate")));
957
+ ASSERT(bson_append_int32(&doc, "status", (int)strlen("status"), 0));
958
+ bson_t masterKey;
959
+ bson_init(&masterKey);
960
+ ASSERT(bson_append_document_begin(&doc, "masterKey", (int)strlen("masterKey"), &masterKey));
961
+ ASSERT(bson_append_utf8(&masterKey, "provider", (int)strlen("provider"), "local", (int)strlen("local")));
962
+ ASSERT(bson_append_document_end(&doc, &masterKey));
963
+ mongocrypt_binary_t *bin = mongocrypt_binary_new_from_data((uint8_t *)bson_get_data(&doc), doc.len);
964
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, bin), ctx);
965
+ mongocrypt_binary_destroy(bin);
966
+ bson_destroy(&doc);
967
+
968
+ _mongocrypt_buffer_cleanup(&encrypted_key);
1060
969
  }