libmongocrypt-helper 1.8.0.0.1001 → 1.11.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (385) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +33 -0
  3. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +12 -1
  4. data/ext/libmongocrypt/libmongocrypt/CODEOWNERS +1 -4
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +151 -3
  6. data/ext/libmongocrypt/libmongocrypt/README.md +36 -40
  7. data/ext/libmongocrypt/libmongocrypt/bindings/cs/CMakeLists.txt +1 -0
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Driver.snk +0 -0
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/AssemblyInfo.cs +2 -2
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Binary.cs +16 -2
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClientFactory.cs +8 -4
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +10 -0
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/LibraryLoader.cs +81 -44
  14. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/MongoDB.Libmongocrypt.csproj +2 -1
  15. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/MongoDB.Libmongocrypt.Test.csproj +2 -0
  16. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test32/MongoDB.Libmongocrypt.Test32.csproj +2 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/cs/README.md +3 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +21 -26
  19. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.config +3 -0
  20. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.sh +0 -0
  21. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/build.gradle.kts +28 -0
  22. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/java/com/mongodb/crypt/benchmark/BenchmarkRunner.java +217 -0
  23. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/resources/keyDocument.json +24 -0
  24. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +21 -6
  25. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.jar +0 -0
  26. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.properties +1 -1
  27. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew +154 -108
  28. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew.bat +7 -18
  29. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/settings.gradle.kts +1 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPI.java +41 -6
  31. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPIHelper.java +5 -5
  32. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CipherCallback.java +27 -1
  33. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoCryptImpl.java +34 -19
  34. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoExplicitEncryptOptions.java +6 -4
  35. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/jni-config.json +180 -0
  36. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/reflect-config.json +134 -0
  37. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +44 -2
  38. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +1 -1
  39. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/rangeopts.json +3 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +4 -900
  41. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +60 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +41 -20
  43. data/ext/libmongocrypt/libmongocrypt/bindings/python/RELEASE.rst +6 -24
  44. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +4 -13
  45. data/ext/libmongocrypt/libmongocrypt/bindings/python/hatch_build.py +36 -0
  46. data/ext/libmongocrypt/libmongocrypt/bindings/python/libmongocrypt-version.txt +1 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/__init__.py +2 -2
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/auto_encrypter.py +61 -0
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/credentials.py +156 -0
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/explicit_encrypter.py +156 -0
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/state_machine.py +149 -0
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/auto_encrypter.py +2 -46
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binary.py +14 -17
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +107 -61
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +6 -4
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/credentials.py +2 -121
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/crypto.py +31 -20
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/errors.py +2 -2
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +2 -233
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +168 -238
  61. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/options.py +265 -0
  62. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/state_machine.py +2 -141
  63. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/auto_encrypter.py +61 -0
  64. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/credentials.py +156 -0
  65. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/explicit_encrypter.py +156 -0
  66. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/state_machine.py +149 -0
  67. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  68. data/ext/libmongocrypt/libmongocrypt/bindings/python/pyproject.toml +118 -0
  69. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +97 -61
  70. data/ext/libmongocrypt/libmongocrypt/bindings/python/{test-requirements.txt → requirements-test.txt} +4 -1
  71. data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements.txt +4 -0
  72. data/ext/libmongocrypt/libmongocrypt/bindings/python/sbom.json +76 -0
  73. data/ext/libmongocrypt/libmongocrypt/bindings/python/strip_header.py +6 -7
  74. data/ext/libmongocrypt/libmongocrypt/bindings/python/synchro.py +64 -0
  75. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -0
  76. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/collection-info.json +1 -1
  77. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/command.json +1 -1
  78. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/compact/success/encrypted-payload.json +21 -21
  79. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-command-reply.json +1 -1
  80. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-field-config-map.json +1 -1
  81. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +1 -1
  82. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/rangeopts.json +3 -0
  83. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-rangePreview-explicit/int32/rangeopts.json +11 -0
  84. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-rangePreview-explicit/int32/value-to-encrypt.json +20 -0
  85. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-azure.json +1 -1
  86. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-gcp.json +1 -1
  87. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document.json +1 -1
  88. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-filter.json +1 -1
  89. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/list-collections-filter.json +1 -1
  90. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-command.json +1 -1
  91. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-reply.json +1 -1
  92. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/schema-map.json +1 -1
  93. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/keyDocument.json +24 -0
  94. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/perf_test.py +165 -0
  95. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_binding.py +8 -12
  96. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_crypto.py +9 -11
  97. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +988 -340
  98. data/ext/libmongocrypt/libmongocrypt/bindings/python/update-sbom.sh +14 -0
  99. data/ext/libmongocrypt/libmongocrypt/cmake/FetchMongoC.cmake +19 -1
  100. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +23 -0
  101. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +19 -227
  102. data/ext/libmongocrypt/libmongocrypt/cmake/Patch.cmake +54 -0
  103. data/ext/libmongocrypt/libmongocrypt/doc/img/cli-icon.png +0 -0
  104. data/ext/libmongocrypt/libmongocrypt/doc/img/reference-targets.png +0 -0
  105. data/ext/libmongocrypt/libmongocrypt/doc/releasing.md +153 -0
  106. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version.py +61 -28
  107. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version_selftest.sh +73 -0
  108. data/ext/libmongocrypt/libmongocrypt/etc/cyclonedx.sbom.json +108 -0
  109. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +1 -1
  110. data/ext/libmongocrypt/libmongocrypt/etc/libbson-remove-GCC-diagnostic-pragma.patch +27 -0
  111. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-alpine-arm-fix.patch +17 -0
  112. data/ext/libmongocrypt/libmongocrypt/etc/packager.py +120 -91
  113. data/ext/libmongocrypt/libmongocrypt/etc/purls.txt +14 -0
  114. data/ext/libmongocrypt/libmongocrypt/etc/repo_config.yaml +56 -0
  115. data/ext/libmongocrypt/libmongocrypt/etc/silk-create-asset-group.sh +70 -0
  116. data/ext/libmongocrypt/libmongocrypt/etc/ssdlc_compliance_report.md +37 -0
  117. data/ext/libmongocrypt/libmongocrypt/etc/third_party_vulnerabilities.md +42 -0
  118. data/ext/libmongocrypt/libmongocrypt/integrating.md +18 -1
  119. data/ext/libmongocrypt/libmongocrypt/kms-message/CMakeLists.txt +11 -3
  120. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_gcp_request.c +1 -1
  121. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer.c +17 -0
  122. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer_private.h +6 -0
  123. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_request.c +211 -1
  124. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_response.c +163 -0
  125. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_tag_type_private.h +2 -1
  126. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_request.h +17 -0
  127. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_response.h +6 -0
  128. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_port.c +3 -2
  129. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request.c +4 -2
  130. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.c +2 -2
  131. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kmip_reader_writer.c +23 -2
  132. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +13 -10
  133. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +1 -1
  134. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +16 -2
  135. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +94 -6
  136. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +15 -5
  137. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +114 -53
  138. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +1 -1
  139. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +1 -1
  140. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +2 -2
  141. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +2 -2
  142. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +21 -6
  143. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +5 -5
  144. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +38 -2
  145. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +1 -1
  146. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +20 -7
  147. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +8 -8
  148. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +89 -1
  149. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +3 -3
  150. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +1 -23
  151. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +4 -3
  152. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +15 -12
  153. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +11 -0
  154. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +16 -6
  155. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +64 -22
  156. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +23 -4
  157. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +359 -65
  158. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +26 -14
  159. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +17 -6
  160. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +31 -13
  161. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +16 -3
  162. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +259 -63
  163. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +40 -24
  164. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +57 -13
  165. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +17 -0
  166. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +5 -0
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +0 -5
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +5 -7
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +1 -0
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +16 -18
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +105 -76
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +9 -3
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +170 -89
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +5 -5
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +505 -124
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +31 -6
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +81 -13
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +7 -0
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +5 -1
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +161 -103
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +2 -7
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +191 -69
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +1 -1
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +50 -15
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +365 -69
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +2 -1
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +200 -107
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +50 -5
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +591 -15
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +6 -13
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +3 -2
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +47 -234
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +75 -24
  194. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +18 -2
  195. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +4 -0
  196. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/bypassQueryAnalysis/payload.json +53 -0
  197. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd-to-mongocryptd.json +23 -0
  198. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd.json +20 -0
  199. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd-to-mongocryptd.json +50 -0
  200. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd.json +20 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/collinfo.json +44 -0
  202. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-field-map.json +24 -0
  203. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-payload-pattern.json +53 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/mongocryptd-reply.json +62 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd-to-mongocryptd.json +30 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd.json +17 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/mongocryptd-reply.json +39 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/payload.json +21 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/missing-key-id/collinfo.json +20 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/collinfo.json +9 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/encrypted-payload.json +4 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/cmd.json +1 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/collinfo.json +63 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-field-config-map.json +61 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload-range-v2.json +37 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload.json +29 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/cmd.json +1 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/collinfo.json +64 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload-range-v2.json +105 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload.json +30 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/cmd.json +1 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/collinfo.json +49 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-field-config-map.json +47 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-payload.json +23 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/collinfo.json +15 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-field-config-map.json +10 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload-range-v2.json +104 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload.json +6 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/collinfo.json +4 -4
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +3 -3
  231. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/decrypt-response.txt +16 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/encrypt-response.txt +16 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/oauth-response.txt +19 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/cmd.json +9 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-field-map.json +19 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-payload.json +62 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/mongocryptd-reply.json +69 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/cmd.json +11 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-field-map.json +19 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-payload.json +40 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/mongocryptd-reply.json +47 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_decimal128.cstruct +1 -1
  243. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_double.cstruct +8637 -7958
  244. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int32.cstruct +5522 -1382
  245. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int64.cstruct +5042 -1262
  246. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128.cstruct +1 -1
  247. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128_precision.cstruct +1 -1
  248. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double.cstruct +1 -1
  249. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double_precision.cstruct +2 -2
  250. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int32.cstruct +1 -1
  251. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int64.cstruct +1 -1
  252. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/cmd.json +8 -0
  253. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-field-map.json +19 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-payload.json +53 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/mongocryptd-reply.json +58 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/cmd.json +11 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-field-map.json +19 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-payload.json +40 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/mongocryptd-reply.json +45 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/expected.json +26 -0
  261. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/to-encrypt.json +20 -0
  262. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/expected.json +26 -0
  263. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/to-encrypt.json +20 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-double/expected.json +8 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32/expected.json +8 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32-defaults/expected.json +8 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +7 -4
  268. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +9 -5
  269. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +9 -5
  270. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +1 -0
  271. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +8 -8
  272. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +6 -4
  273. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +43 -3
  274. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +76 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +5 -5
  276. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +89 -14
  277. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +342 -76
  278. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +94 -12
  279. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +205 -7
  280. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +49 -23
  281. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +16 -19
  282. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +22 -1
  283. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +94 -11
  284. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cleanup.c +374 -0
  285. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +121 -42
  286. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +134 -4
  287. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +40 -0
  288. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +16 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +11 -11
  290. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +8 -5
  291. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +922 -92
  292. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +2 -2
  293. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +114 -12
  294. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +14 -9
  295. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +424 -3
  296. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +1 -1
  297. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +447 -28
  298. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-opts.c +42 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +30 -26
  300. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +7 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +3 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +66 -14
  303. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +11 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/test-named-kms-providers.c +2381 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/util/HELP.autogen +3 -1
  306. data/ext/libmongocrypt/libmongocrypt/test/util/README.md +1 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +4 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/util/make_includes.py +1 -1
  309. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +38 -3
  310. data/lib/libmongocrypt_helper/version.rb +2 -2
  311. metadata +112 -106
  312. checksums.yaml.gz.sig +0 -0
  313. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +0 -1
  314. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +0 -79
  315. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +0 -105
  316. data/ext/libmongocrypt/libmongocrypt/bindings/node/LICENSE +0 -201
  317. data/ext/libmongocrypt/libmongocrypt/bindings/node/binding.gyp +0 -79
  318. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/README.hbs +0 -44
  319. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +0 -36
  320. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +0 -641
  321. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +0 -420
  322. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/buffer_pool.js +0 -123
  323. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +0 -821
  324. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +0 -98
  325. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/cryptoCallbacks.js +0 -87
  326. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +0 -75
  327. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +0 -73
  328. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js +0 -66
  329. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +0 -26
  330. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +0 -178
  331. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +0 -24
  332. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +0 -54
  333. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +0 -39
  334. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +0 -492
  335. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +0 -15302
  336. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +0 -100
  337. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +0 -956
  338. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.h +0 -114
  339. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +0 -950
  340. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/buffer_pool.test.js +0 -91
  341. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +0 -1093
  342. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +0 -94
  343. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +0 -240
  344. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/README.md +0 -5
  345. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/cmd.json +0 -6
  346. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/collection-info.json +0 -37
  347. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document-nested.json +0 -8
  348. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document.json +0 -11
  349. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encryptedFields.json +0 -30
  350. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key-document.json +0 -32
  351. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key1-document.json +0 -30
  352. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/mongocryptd-reply.json +0 -18
  353. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +0 -45
  354. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +0 -48
  355. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +0 -551
  356. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +0 -66
  357. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +0 -51
  358. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +0 -331
  359. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +0 -8
  360. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/mongodb_reporter.js +0 -325
  361. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +0 -63
  362. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +0 -89
  363. data/ext/libmongocrypt/libmongocrypt/debian/build_snapshot.sh +0 -79
  364. data/ext/libmongocrypt/libmongocrypt/debian/changelog +0 -105
  365. data/ext/libmongocrypt/libmongocrypt/debian/compat +0 -1
  366. data/ext/libmongocrypt/libmongocrypt/debian/control +0 -41
  367. data/ext/libmongocrypt/libmongocrypt/debian/copyright +0 -129
  368. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +0 -23
  369. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.dirs +0 -2
  370. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.install +0 -5
  371. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.dirs +0 -1
  372. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.install +0 -1
  373. data/ext/libmongocrypt/libmongocrypt/debian/rules +0 -46
  374. data/ext/libmongocrypt/libmongocrypt/debian/source/format +0 -1
  375. data/ext/libmongocrypt/libmongocrypt/debian/source/lintian-overrides +0 -3
  376. data/ext/libmongocrypt/libmongocrypt/debian/source/options +0 -1
  377. data/ext/libmongocrypt/libmongocrypt/debian/watch +0 -3
  378. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/mongocryptd-reply.json +0 -72
  379. data.tar.gz.sig +0 -1
  380. metadata.gz.sig +0 -0
  381. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-decrypt-reply.txt → test/data/kms-aws/decrypt-response.txt} +0 -0
  382. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-encrypt-reply.txt → test/data/kms-aws/encrypt-response.txt} +0 -0
  383. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/decrypt-response.txt +0 -0
  384. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/encrypt-response.txt +0 -0
  385. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/oauth-response.txt +0 -0
@@ -0,0 +1,265 @@
1
+ from pymongocrypt.compat import unicode_type
2
+
3
+
4
+ class MongoCryptOptions:
5
+ def __init__(
6
+ self,
7
+ kms_providers,
8
+ schema_map=None,
9
+ encrypted_fields_map=None,
10
+ bypass_query_analysis=False,
11
+ crypt_shared_lib_path=None,
12
+ crypt_shared_lib_required=False,
13
+ bypass_encryption=False,
14
+ ):
15
+ """Options for :class:`MongoCrypt`.
16
+
17
+ :Parameters:
18
+ - `kms_providers`: Map of KMS provider options. The kms_providers
19
+ map values differ by provider:
20
+ - `aws`: Map with "accessKeyId" and "secretAccessKey" as strings,
21
+ and optionally a "sessionToken" for temporary credentials.
22
+ - `azure`: Map with "clientId" and "clientSecret" as strings.
23
+ - `gcp`: Map with "email" as a string and "privateKey" as
24
+ a byte array or a base64-encoded string.
25
+ - `kmip`: Map with "endpoint" as a string.
26
+ - `local`: Map with "key" as a 96-byte array or the equivalent
27
+ base64-encoded string.
28
+
29
+ KMS providers may be specified with an optional name suffix
30
+ separated by a colon, for example "kmip:name". Named KMS providers
31
+ do not support automatic credential lookup.
32
+ - `schema_map`: Optional map of collection namespace ("db.coll") to
33
+ JSON Schema. By default, a collection's JSONSchema is periodically
34
+ polled with the listCollections command. But a JSONSchema may be
35
+ specified locally with the schemaMap option.
36
+
37
+ Supplying a `schema_map` provides more security than relying on
38
+ JSON Schemas obtained from the server. It protects against a
39
+ malicious server advertising a false JSON Schema, which could trick
40
+ the client into sending unencrypted data that should be encrypted.
41
+
42
+ Schemas supplied in the schemaMap only apply to configuring
43
+ automatic encryption for client side encryption. Other validation
44
+ rules in the JSON schema will not be enforced by the driver and
45
+ will result in an error.
46
+ - `encrypted_fields_map`: Optional map encoded to BSON `bytes`.
47
+ - `bypass_query_analysis`: If ``True``, disable automatic analysis of
48
+ outgoing commands. Set `bypass_query_analysis` to use explicit
49
+ encryption on indexed fields without the MongoDB Enterprise Advanced
50
+ licensed crypt_shared library.
51
+ - `crypt_shared_lib_path`: Optional string path to the crypt_shared
52
+ library.
53
+ - `crypt_shared_lib_required`: Whether to require a crypt_shared
54
+ library.
55
+ - `bypass_encryption`: Whether to bypass encryption.
56
+
57
+ .. versionremoved:: 1.11
58
+ Removed the ``enable_range_v2`` parameter.
59
+
60
+ .. versionadded:: 1.10
61
+ Added the ``enable_range_v2`` parameter.
62
+
63
+ .. versionadded:: 1.3
64
+ Added the ``crypt_shared_lib_path``, ``crypt_shared_lib_path``, and
65
+ ``bypass_encryption`` parameters.
66
+
67
+ .. versionadded:: 1.1
68
+ Support for "azure" and "gcp" kms_providers.
69
+ Support for temporary AWS credentials via "sessionToken".
70
+
71
+ .. versionchanged:: 1.1
72
+ For kmsProvider "local", the "key" field can now be specified
73
+ as either a 96-byte array or the equivalent base64-encoded string.
74
+ """
75
+ if not isinstance(kms_providers, dict):
76
+ raise ValueError("kms_providers must be a dict")
77
+ if not kms_providers:
78
+ raise ValueError("at least one KMS provider must be configured")
79
+
80
+ for name, provider in kms_providers.items():
81
+ # Account for provider names like "local:myname".
82
+ provider_type = name.split(":")[0]
83
+ if provider_type in ("aws", "gcp", "azure", "kmip", "local"):
84
+ if not isinstance(provider, dict):
85
+ raise ValueError(f"kms_providers[{name!r}] must be a dict")
86
+ if provider_type == "aws":
87
+ if len(provider):
88
+ if (
89
+ "accessKeyId" not in provider
90
+ or "secretAccessKey" not in provider
91
+ ):
92
+ raise ValueError(
93
+ f"kms_providers[{name!r}] must contain "
94
+ "'accessKeyId' and 'secretAccessKey'"
95
+ )
96
+ elif provider_type == "azure":
97
+ if len(provider):
98
+ if "clientId" not in provider or "clientSecret" not in provider:
99
+ raise ValueError(
100
+ f"kms_providers[{name!r}] must contain "
101
+ "'clientId' and 'clientSecret'"
102
+ )
103
+ elif provider_type == "gcp":
104
+ if len(provider):
105
+ if "email" not in provider or "privateKey" not in provider:
106
+ raise ValueError(
107
+ f"kms_providers[{name!r}] must contain "
108
+ "'email' and 'privateKey'"
109
+ )
110
+ if not isinstance(provider["privateKey"], (bytes, unicode_type)):
111
+ raise TypeError(
112
+ f"kms_providers[{name!r}]['privateKey'] must "
113
+ "be an instance of bytes or str"
114
+ )
115
+ elif provider_type == "kmip":
116
+ if "endpoint" not in provider:
117
+ raise ValueError(f"kms_providers[{name!r}] must contain 'endpoint'")
118
+ if not isinstance(provider["endpoint"], (str, unicode_type)):
119
+ raise TypeError(
120
+ f"kms_providers[{name!r}]['endpoint'] must "
121
+ "be an instance of str"
122
+ )
123
+ elif provider_type == "local":
124
+ if "key" not in provider:
125
+ raise ValueError(f"kms_providers[{name!r}] must contain 'key'")
126
+ if not isinstance(provider["key"], (bytes, unicode_type)):
127
+ raise TypeError(
128
+ f"kms_providers[{name!r}]['key'] must be an "
129
+ "instance of bytes or str"
130
+ )
131
+
132
+ if schema_map is not None and not isinstance(schema_map, bytes):
133
+ raise TypeError("schema_map must be bytes or None")
134
+
135
+ if encrypted_fields_map is not None and not isinstance(
136
+ encrypted_fields_map, bytes
137
+ ):
138
+ raise TypeError("encrypted_fields_map must be bytes or None")
139
+
140
+ self.kms_providers = kms_providers
141
+ self.schema_map = schema_map
142
+ self.encrypted_fields_map = encrypted_fields_map
143
+ self.bypass_query_analysis = bypass_query_analysis
144
+ self.crypt_shared_lib_path = crypt_shared_lib_path
145
+ self.crypt_shared_lib_required = crypt_shared_lib_required
146
+ self.bypass_encryption = bypass_encryption
147
+
148
+
149
+ class ExplicitEncryptOpts:
150
+ def __init__(
151
+ self,
152
+ algorithm,
153
+ key_id=None,
154
+ key_alt_name=None,
155
+ query_type=None,
156
+ contention_factor=None,
157
+ range_opts=None,
158
+ is_expression=False,
159
+ ):
160
+ """Options for explicit encryption.
161
+
162
+ :Parameters:
163
+ - `algorithm` (str): The algorithm to use.
164
+ - `key_id`: The data key _id.
165
+ - `key_alt_name` (bytes): Identifies a key vault document by
166
+ 'keyAltName'. Must be BSON encoded document in the form:
167
+ { "keyAltName" : (BSON UTF8 value) }
168
+ - `query_type` (str): The query type to execute.
169
+ - `contention_factor` (int): The contention factor to use
170
+ when the algorithm is "Indexed".
171
+ - `range_opts` (bytes): Options for explicit encryption
172
+ with the "range" algorithm encoded as a BSON document.
173
+ - `is_expression` (boolean): True if this is an encryptExpression()
174
+ context. Defaults to False.
175
+
176
+ .. versionchanged:: 1.3
177
+ Added the `query_type` and `contention_factor` parameters.
178
+ .. versionchanged:: 1.5
179
+ Added the `range_opts` and `is_expression` parameters.
180
+ """
181
+ self.algorithm = algorithm
182
+ self.key_id = key_id
183
+ self.key_alt_name = key_alt_name
184
+ if query_type is not None:
185
+ if not isinstance(query_type, str):
186
+ raise TypeError(
187
+ f"query_type must be str or None, not: {type(query_type)}"
188
+ )
189
+ self.query_type = query_type
190
+ if contention_factor is not None and not isinstance(contention_factor, int):
191
+ raise TypeError(
192
+ f"contention_factor must be an int or None, not: {type(contention_factor)}"
193
+ )
194
+ self.contention_factor = contention_factor
195
+ if range_opts is not None and not isinstance(range_opts, bytes):
196
+ raise TypeError(
197
+ f"range_opts must be an bytes or None, not: {type(range_opts)}"
198
+ )
199
+ self.range_opts = range_opts
200
+ self.is_expression = is_expression
201
+
202
+
203
+ class DataKeyOpts:
204
+ def __init__(self, master_key=None, key_alt_names=None, key_material=None):
205
+ """Options for creating encryption keys.
206
+
207
+ :Parameters:
208
+ - `master_key`: Identifies a KMS-specific key used to encrypt the
209
+ new data key. If the kmsProvider is "local" the `master_key` is
210
+ not applicable and may be omitted.
211
+
212
+ If the `kms_provider` is "aws" it is required and has the
213
+ following fields::
214
+
215
+ - `region` (string): Required. The AWS region, e.g. "us-east-1".
216
+ - `key` (string): Required. The Amazon Resource Name (ARN) to
217
+ the AWS customer.
218
+ - `endpoint` (string): Optional. An alternate host to send KMS
219
+ requests to. May include port number, e.g.
220
+ "kms.us-east-1.amazonaws.com:443".
221
+
222
+ If the `kms_provider` is "azure" it is required and has the
223
+ following fields::
224
+
225
+ - `keyVaultEndpoint` (string): Required. Host with optional
226
+ port, e.g. "example.vault.azure.net".
227
+ - `keyName` (string): Required. Key name in the key vault.
228
+ - `keyVersion` (string): Optional. Version of the key to use.
229
+
230
+ If the `kms_provider` is "gcp" it is required and has the
231
+ following fields::
232
+
233
+ - `projectId` (string): Required. The Google cloud project ID.
234
+ - `location` (string): Required. The GCP location, e.g. "us-east1".
235
+ - `keyRing` (string): Required. Name of the key ring that contains
236
+ the key to use.
237
+ - `keyName` (string): Required. Name of the key to use.
238
+ - `keyVersion` (string): Optional. Version of the key to use.
239
+ - `endpoint` (string): Optional. Host with optional port.
240
+ Defaults to "cloudkms.googleapis.com".
241
+
242
+ If the `kms_provider` is "kmip" it is optional and has the
243
+ following fields::
244
+
245
+ - `keyId` (string): Optional. `keyId` is the KMIP Unique
246
+ Identifier to a 96 byte KMIP Secret Data managed object. If
247
+ keyId is omitted, the driver creates a random 96 byte KMIP
248
+ Secret Data managed object.
249
+ - `endpoint` (string): Optional. Host with optional
250
+ port, e.g. "example.vault.azure.net:".
251
+
252
+ - `key_alt_names`: An optional list of bytes suitable to be passed to
253
+ mongocrypt_ctx_setopt_key_alt_name. Each element must be BSON
254
+ encoded document in the form: { "keyAltName" : (BSON UTF8 value) }
255
+
256
+ - `key_material`: An optional binary value of 96 bytes to use as
257
+ custom key material for the data key being created. If
258
+ ``key_material`` is given, the custom key material is used for
259
+ encrypting and decrypting data. Otherwise, the key material for the
260
+ new data key is generated from a cryptographically secure random
261
+ device.
262
+ """
263
+ self.master_key = master_key
264
+ self.key_alt_names = key_alt_names
265
+ self.key_material = key_material
@@ -12,145 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from abc import abstractmethod
15
+ # Alias file for import compatibility
16
16
 
17
- from pymongocrypt.binding import lib
18
- from pymongocrypt.compat import ABC
19
- from pymongocrypt.errors import MongoCryptError
20
-
21
-
22
- class MongoCryptCallback(ABC):
23
- """Callback ABC to perform I/O on behalf of libbmongocrypt."""
24
-
25
- @abstractmethod
26
- def kms_request(self, kms_context):
27
- """Complete a KMS request.
28
-
29
- :Parameters:
30
- - `kms_context`: A :class:`MongoCryptKmsContext`.
31
-
32
- :Returns:
33
- None
34
- """
35
- pass
36
-
37
- @abstractmethod
38
- def collection_info(self, database, filter):
39
- """Get the collection info for a namespace.
40
-
41
- The returned collection info is passed to libmongocrypt which reads
42
- the JSON schema.
43
-
44
- :Parameters:
45
- - `database`: The database on which to run listCollections.
46
- - `filter`: The filter to pass to listCollections.
47
-
48
- :Returns:
49
- The first document from the listCollections command response as BSON.
50
- """
51
- pass
52
-
53
- @abstractmethod
54
- def mark_command(self, database, cmd):
55
- """Mark a command for encryption.
56
-
57
- :Parameters:
58
- - `database`: The database on which to run this command.
59
- - `cmd`: The BSON command to run.
60
-
61
- :Returns:
62
- The marked command response from mongocryptd.
63
- """
64
- pass
65
-
66
- @abstractmethod
67
- def fetch_keys(self, filter):
68
- """Yields one or more keys from the key vault.
69
-
70
- :Parameters:
71
- - `filter`: The filter to pass to find.
72
-
73
- :Returns:
74
- A generator which yields the requested keys from the key vault.
75
- """
76
- pass
77
-
78
- @abstractmethod
79
- def insert_data_key(self, data_key):
80
- """Insert a data key into the key vault.
81
-
82
- :Parameters:
83
- - `data_key`: The data key document to insert.
84
-
85
- :Returns:
86
- The _id of the inserted data key document.
87
- """
88
- pass
89
-
90
- @abstractmethod
91
- def bson_encode(self, doc):
92
- """Encode a document to BSON.
93
-
94
- A document can be any mapping type (like :class:`dict`).
95
-
96
- :Parameters:
97
- - `doc`: mapping type representing a document
98
-
99
- :Returns:
100
- The encoded BSON bytes.
101
- """
102
- pass
103
-
104
- @abstractmethod
105
- def close(self):
106
- """Release resources."""
107
- pass
108
-
109
-
110
- def run_state_machine(ctx, callback):
111
- """Run the libmongocrypt state machine until completion.
112
-
113
- :Parameters:
114
- - `ctx`: A :class:`MongoCryptContext`.
115
- - `callback`: A :class:`MongoCryptCallback`.
116
-
117
- :Returns:
118
- The completed libmongocrypt operation.
119
- """
120
- while True:
121
- state = ctx.state
122
- # Check for terminal states first.
123
- if state == lib.MONGOCRYPT_CTX_ERROR:
124
- ctx._raise_from_status()
125
- elif state == lib.MONGOCRYPT_CTX_READY:
126
- return ctx.finish()
127
- elif state == lib.MONGOCRYPT_CTX_DONE:
128
- return None
129
-
130
- if state == lib.MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
131
- list_colls_filter = ctx.mongo_operation()
132
- coll_info = callback.collection_info(
133
- ctx.database, list_colls_filter)
134
- if coll_info:
135
- ctx.add_mongo_operation_result(coll_info)
136
- ctx.complete_mongo_operation()
137
- elif state == lib.MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
138
- mongocryptd_cmd = ctx.mongo_operation()
139
- result = callback.mark_command(ctx.database, mongocryptd_cmd)
140
- ctx.add_mongo_operation_result(result)
141
- ctx.complete_mongo_operation()
142
- elif state == lib.MONGOCRYPT_CTX_NEED_MONGO_KEYS:
143
- key_filter = ctx.mongo_operation()
144
- for key in callback.fetch_keys(key_filter):
145
- ctx.add_mongo_operation_result(key)
146
- ctx.complete_mongo_operation()
147
- elif state == lib.MONGOCRYPT_CTX_NEED_KMS:
148
- for kms_ctx in ctx.kms_contexts():
149
- with kms_ctx:
150
- callback.kms_request(kms_ctx)
151
- ctx.complete_kms()
152
- elif state == lib.MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
153
- creds = ctx.ask_for_kms_credentials()
154
- ctx.provide_kms_providers(callback.bson_encode(creds))
155
- else:
156
- raise MongoCryptError('unknown state: %r' % (state,))
17
+ from pymongocrypt.synchronous.state_machine import *
@@ -0,0 +1,61 @@
1
+ # Copyright 2024-present MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from pymongocrypt.mongocrypt import MongoCrypt
16
+ from pymongocrypt.synchronous.state_machine import run_state_machine
17
+
18
+
19
+ class AutoEncrypter:
20
+ def __init__(self, callback, mongo_crypt_opts):
21
+ """Encrypts and decrypts MongoDB commands.
22
+
23
+ This class is used by a driver to support automatic encryption and
24
+ decryption of MongoDB commands.
25
+
26
+ :Parameters:
27
+ - `callback`: A :class:`MongoCryptCallback`.
28
+ - `mongo_crypt_opts`: A :class:`MongoCryptOptions`.
29
+ """
30
+ self.callback = callback
31
+ self.mongocrypt = MongoCrypt(mongo_crypt_opts, callback)
32
+
33
+ def encrypt(self, database, cmd):
34
+ """Encrypt a MongoDB command.
35
+
36
+ :Parameters:
37
+ - `database`: The database for this command.
38
+ - `cmd`: A MongoDB command as BSON.
39
+
40
+ :Returns:
41
+ The encrypted command.
42
+ """
43
+ with self.mongocrypt.encryption_context(database, cmd) as ctx:
44
+ return run_state_machine(ctx, self.callback)
45
+
46
+ def decrypt(self, response):
47
+ """Decrypt a MongoDB command response.
48
+
49
+ :Parameters:
50
+ - `response`: A MongoDB command response as BSON.
51
+
52
+ :Returns:
53
+ The decrypted command response.
54
+ """
55
+ with self.mongocrypt.decryption_context(response) as ctx:
56
+ return run_state_machine(ctx, self.callback)
57
+
58
+ def close(self):
59
+ """Cleanup resources."""
60
+ self.mongocrypt.close()
61
+ self.callback.close()
@@ -0,0 +1,156 @@
1
+ # Copyright 2024-present MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ import os
15
+ from collections import namedtuple
16
+ from datetime import datetime, timedelta, timezone
17
+
18
+ try:
19
+ from pymongo_auth_aws.auth import aws_temp_credentials
20
+
21
+ _HAVE_AUTH_AWS = True
22
+ except ImportError:
23
+ _HAVE_AUTH_AWS = False
24
+
25
+ import httpx
26
+
27
+ from pymongocrypt.errors import MongoCryptError
28
+
29
+ _azure_creds = namedtuple("_azure_creds", ["access_token", "expires_utc"])
30
+ _azure_creds_cache = None
31
+
32
+
33
+ def _get_gcp_credentials():
34
+ """Get on-demand GCP credentials"""
35
+ metadata_host = os.getenv("GCE_METADATA_HOST") or "metadata.google.internal"
36
+ url = (
37
+ "http://%s/computeMetadata/v1/instance/service-accounts/default/token"
38
+ % metadata_host
39
+ )
40
+
41
+ headers = {"Metadata-Flavor": "Google"}
42
+ client = httpx.Client()
43
+ try:
44
+ response = client.get(url, headers=headers)
45
+ except Exception as e:
46
+ msg = "unable to retrieve GCP credentials: %s" % e
47
+ raise MongoCryptError(msg) from e
48
+ finally:
49
+ client.close()
50
+
51
+ if response.status_code != 200:
52
+ msg = f"Unable to retrieve GCP credentials: expected StatusCode 200, got StatusCode: {response.status_code}. Response body:\n{response.content}"
53
+ raise MongoCryptError(msg)
54
+ try:
55
+ data = response.json()
56
+ except Exception as e:
57
+ raise MongoCryptError(
58
+ f"unable to retrieve GCP credentials: error reading response body\n{response.content}"
59
+ ) from e
60
+
61
+ if not data.get("access_token"):
62
+ msg = (
63
+ "unable to retrieve GCP credentials: got unexpected empty accessToken from GCP Metadata Server. Response body: %s"
64
+ % response.content
65
+ )
66
+ raise MongoCryptError(msg)
67
+
68
+ return {"accessToken": data["access_token"]}
69
+
70
+
71
+ def _get_azure_credentials():
72
+ """Get on-demand Azure credentials"""
73
+ global _azure_creds_cache
74
+ # Credentials are considered expired when: Expiration - now < 1 mins.
75
+ creds = _azure_creds_cache
76
+ if creds:
77
+ if creds.expires_utc - datetime.now(tz=timezone.utc) < timedelta(seconds=60):
78
+ _azure_creds_cache = None
79
+ else:
80
+ return {"accessToken": creds.access_token}
81
+
82
+ url = "http://169.254.169.254/metadata/identity/oauth2/token"
83
+ url += "?api-version=2018-02-01"
84
+ url += "&resource=https://vault.azure.net"
85
+ headers = {"Metadata": "true", "Accept": "application/json"}
86
+ client = httpx.Client()
87
+ try:
88
+ response = client.get(url, headers=headers)
89
+ except Exception as e:
90
+ msg = "Failed to acquire IMDS access token: %s" % e
91
+ raise MongoCryptError(msg) from e
92
+ finally:
93
+ client.close()
94
+
95
+ if response.status_code != 200:
96
+ msg = "Failed to acquire IMDS access token."
97
+ raise MongoCryptError(msg)
98
+ try:
99
+ data = response.json()
100
+ except Exception as e:
101
+ raise MongoCryptError("Azure IMDS response must be in JSON format.") from e
102
+
103
+ for key in ["access_token", "expires_in"]:
104
+ if not data.get(key):
105
+ msg = "Azure IMDS response must contain %s, but was %s."
106
+ msg = msg % (key, response.content)
107
+ raise MongoCryptError(msg)
108
+
109
+ try:
110
+ expires_in = int(data["expires_in"])
111
+ except ValueError as e:
112
+ raise MongoCryptError(
113
+ 'Azure IMDS response must contain "expires_in" integer, but was %s.'
114
+ % response.content
115
+ ) from e
116
+
117
+ expires_utc = datetime.now(tz=timezone.utc) + timedelta(seconds=expires_in)
118
+ _azure_creds_cache = _azure_creds(data["access_token"], expires_utc)
119
+ return {"accessToken": data["access_token"]}
120
+
121
+
122
+ def _ask_for_kms_credentials(kms_providers):
123
+ """Get on-demand kms credentials.
124
+
125
+ This is a separate function so it can be overridden in unit tests."""
126
+ global _azure_creds_cache
127
+ on_demand_aws = "aws" in kms_providers and not len(kms_providers["aws"])
128
+ on_demand_gcp = "gcp" in kms_providers and not len(kms_providers["gcp"])
129
+ on_demand_azure = "azure" in kms_providers and not len(kms_providers["azure"])
130
+
131
+ if not any([on_demand_aws, on_demand_gcp, on_demand_azure]):
132
+ return {}
133
+ creds = {}
134
+ if on_demand_aws:
135
+ if not _HAVE_AUTH_AWS:
136
+ raise RuntimeError(
137
+ "On-demand AWS credentials require pymongo-auth-aws: "
138
+ "install with: python -m pip install 'pymongo[aws]'"
139
+ )
140
+ aws_creds = aws_temp_credentials()
141
+ creds_dict = {
142
+ "accessKeyId": aws_creds.username,
143
+ "secretAccessKey": aws_creds.password,
144
+ }
145
+ if aws_creds.token:
146
+ creds_dict["sessionToken"] = aws_creds.token
147
+ creds["aws"] = creds_dict
148
+ if on_demand_gcp:
149
+ creds["gcp"] = _get_gcp_credentials()
150
+ if on_demand_azure:
151
+ try:
152
+ creds["azure"] = _get_azure_credentials()
153
+ except Exception:
154
+ _azure_creds_cache = None
155
+ raise
156
+ return creds