@depup/mongodb 7.1.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +201 -0
- package/README.md +33 -0
- package/etc/prepare.js +12 -0
- package/lib/admin.js +136 -0
- package/lib/admin.js.map +1 -0
- package/lib/bson.js +85 -0
- package/lib/bson.js.map +1 -0
- package/lib/bulk/common.js +835 -0
- package/lib/bulk/common.js.map +1 -0
- package/lib/bulk/ordered.js +67 -0
- package/lib/bulk/ordered.js.map +1 -0
- package/lib/bulk/unordered.js +92 -0
- package/lib/bulk/unordered.js.map +1 -0
- package/lib/change_stream.js +513 -0
- package/lib/change_stream.js.map +1 -0
- package/lib/client-side-encryption/auto_encrypter.js +272 -0
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -0
- package/lib/client-side-encryption/client_encryption.js +609 -0
- package/lib/client-side-encryption/client_encryption.js.map +1 -0
- package/lib/client-side-encryption/errors.js +138 -0
- package/lib/client-side-encryption/errors.js.map +1 -0
- package/lib/client-side-encryption/mongocryptd_manager.js +85 -0
- package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -0
- package/lib/client-side-encryption/providers/aws.js +23 -0
- package/lib/client-side-encryption/providers/aws.js.map +1 -0
- package/lib/client-side-encryption/providers/azure.js +132 -0
- package/lib/client-side-encryption/providers/azure.js.map +1 -0
- package/lib/client-side-encryption/providers/gcp.js +16 -0
- package/lib/client-side-encryption/providers/gcp.js.map +1 -0
- package/lib/client-side-encryption/providers/index.js +43 -0
- package/lib/client-side-encryption/providers/index.js.map +1 -0
- package/lib/client-side-encryption/state_machine.js +427 -0
- package/lib/client-side-encryption/state_machine.js.map +1 -0
- package/lib/cmap/auth/auth_provider.js +51 -0
- package/lib/cmap/auth/auth_provider.js.map +1 -0
- package/lib/cmap/auth/aws4.js +161 -0
- package/lib/cmap/auth/aws4.js.map +1 -0
- package/lib/cmap/auth/aws_temporary_credentials.js +103 -0
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
- package/lib/cmap/auth/gssapi.js +155 -0
- package/lib/cmap/auth/gssapi.js.map +1 -0
- package/lib/cmap/auth/mongo_credentials.js +169 -0
- package/lib/cmap/auth/mongo_credentials.js.map +1 -0
- package/lib/cmap/auth/mongodb_aws.js +128 -0
- package/lib/cmap/auth/mongodb_aws.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +84 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +62 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +141 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js +44 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +39 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +122 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +32 -0
- package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js +52 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +23 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +73 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -0
- package/lib/cmap/auth/plain.js +26 -0
- package/lib/cmap/auth/plain.js.map +1 -0
- package/lib/cmap/auth/providers.js +22 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +254 -0
- package/lib/cmap/auth/scram.js.map +1 -0
- package/lib/cmap/auth/x509.js +36 -0
- package/lib/cmap/auth/x509.js.map +1 -0
- package/lib/cmap/command_monitoring_events.js +223 -0
- package/lib/cmap/command_monitoring_events.js.map +1 -0
- package/lib/cmap/commands.js +535 -0
- package/lib/cmap/commands.js.map +1 -0
- package/lib/cmap/connect.js +381 -0
- package/lib/cmap/connect.js.map +1 -0
- package/lib/cmap/connection.js +571 -0
- package/lib/cmap/connection.js.map +1 -0
- package/lib/cmap/connection_pool.js +558 -0
- package/lib/cmap/connection_pool.js.map +1 -0
- package/lib/cmap/connection_pool_events.js +190 -0
- package/lib/cmap/connection_pool_events.js.map +1 -0
- package/lib/cmap/errors.js +108 -0
- package/lib/cmap/errors.js.map +1 -0
- package/lib/cmap/handshake/client_metadata.js +242 -0
- package/lib/cmap/handshake/client_metadata.js.map +1 -0
- package/lib/cmap/metrics.js +62 -0
- package/lib/cmap/metrics.js.map +1 -0
- package/lib/cmap/stream_description.js +70 -0
- package/lib/cmap/stream_description.js.map +1 -0
- package/lib/cmap/wire_protocol/compression.js +178 -0
- package/lib/cmap/wire_protocol/compression.js.map +1 -0
- package/lib/cmap/wire_protocol/constants.js +21 -0
- package/lib/cmap/wire_protocol/constants.js.map +1 -0
- package/lib/cmap/wire_protocol/on_data.js +111 -0
- package/lib/cmap/wire_protocol/on_data.js.map +1 -0
- package/lib/cmap/wire_protocol/on_demand/document.js +222 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/cmap/wire_protocol/responses.js +315 -0
- package/lib/cmap/wire_protocol/responses.js.map +1 -0
- package/lib/cmap/wire_protocol/shared.js +35 -0
- package/lib/cmap/wire_protocol/shared.js.map +1 -0
- package/lib/collection.js +751 -0
- package/lib/collection.js.map +1 -0
- package/lib/connection_string.js +1090 -0
- package/lib/connection_string.js.map +1 -0
- package/lib/constants.js +170 -0
- package/lib/constants.js.map +1 -0
- package/lib/cursor/abstract_cursor.js +924 -0
- package/lib/cursor/abstract_cursor.js.map +1 -0
- package/lib/cursor/aggregation_cursor.js +164 -0
- package/lib/cursor/aggregation_cursor.js.map +1 -0
- package/lib/cursor/change_stream_cursor.js +104 -0
- package/lib/cursor/change_stream_cursor.js.map +1 -0
- package/lib/cursor/client_bulk_write_cursor.js +52 -0
- package/lib/cursor/client_bulk_write_cursor.js.map +1 -0
- package/lib/cursor/explainable_cursor.js +36 -0
- package/lib/cursor/explainable_cursor.js.map +1 -0
- package/lib/cursor/find_cursor.js +399 -0
- package/lib/cursor/find_cursor.js.map +1 -0
- package/lib/cursor/list_collections_cursor.js +34 -0
- package/lib/cursor/list_collections_cursor.js.map +1 -0
- package/lib/cursor/list_indexes_cursor.js +32 -0
- package/lib/cursor/list_indexes_cursor.js.map +1 -0
- package/lib/cursor/list_search_indexes_cursor.js +14 -0
- package/lib/cursor/list_search_indexes_cursor.js.map +1 -0
- package/lib/cursor/run_command_cursor.js +94 -0
- package/lib/cursor/run_command_cursor.js.map +1 -0
- package/lib/db.js +419 -0
- package/lib/db.js.map +1 -0
- package/lib/deps.js +112 -0
- package/lib/deps.js.map +1 -0
- package/lib/encrypter.js +106 -0
- package/lib/encrypter.js.map +1 -0
- package/lib/error.js +1380 -0
- package/lib/error.js.map +1 -0
- package/lib/explain.js +59 -0
- package/lib/explain.js.map +1 -0
- package/lib/gridfs/download.js +305 -0
- package/lib/gridfs/download.js.map +1 -0
- package/lib/gridfs/index.js +164 -0
- package/lib/gridfs/index.js.map +1 -0
- package/lib/gridfs/upload.js +358 -0
- package/lib/gridfs/upload.js.map +1 -0
- package/lib/index.js +193 -0
- package/lib/index.js.map +1 -0
- package/lib/mongo_client.js +557 -0
- package/lib/mongo_client.js.map +1 -0
- package/lib/mongo_client_auth_providers.js +80 -0
- package/lib/mongo_client_auth_providers.js.map +1 -0
- package/lib/mongo_logger.js +655 -0
- package/lib/mongo_logger.js.map +1 -0
- package/lib/mongo_types.js +56 -0
- package/lib/mongo_types.js.map +1 -0
- package/lib/operations/aggregate.js +90 -0
- package/lib/operations/aggregate.js.map +1 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js +51 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -0
- package/lib/operations/client_bulk_write/command_builder.js +340 -0
- package/lib/operations/client_bulk_write/command_builder.js.map +1 -0
- package/lib/operations/client_bulk_write/common.js +3 -0
- package/lib/operations/client_bulk_write/common.js.map +1 -0
- package/lib/operations/client_bulk_write/executor.js +120 -0
- package/lib/operations/client_bulk_write/executor.js.map +1 -0
- package/lib/operations/client_bulk_write/results_merger.js +204 -0
- package/lib/operations/client_bulk_write/results_merger.js.map +1 -0
- package/lib/operations/command.js +83 -0
- package/lib/operations/command.js.map +1 -0
- package/lib/operations/count.js +45 -0
- package/lib/operations/count.js.map +1 -0
- package/lib/operations/create_collection.js +109 -0
- package/lib/operations/create_collection.js.map +1 -0
- package/lib/operations/delete.js +125 -0
- package/lib/operations/delete.js.map +1 -0
- package/lib/operations/distinct.js +61 -0
- package/lib/operations/distinct.js.map +1 -0
- package/lib/operations/drop.js +93 -0
- package/lib/operations/drop.js.map +1 -0
- package/lib/operations/end_sessions.js +34 -0
- package/lib/operations/end_sessions.js.map +1 -0
- package/lib/operations/estimated_document_count.js +41 -0
- package/lib/operations/estimated_document_count.js.map +1 -0
- package/lib/operations/execute_operation.js +239 -0
- package/lib/operations/execute_operation.js.map +1 -0
- package/lib/operations/find.js +148 -0
- package/lib/operations/find.js.map +1 -0
- package/lib/operations/find_and_modify.js +158 -0
- package/lib/operations/find_and_modify.js.map +1 -0
- package/lib/operations/get_more.js +62 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +186 -0
- package/lib/operations/indexes.js.map +1 -0
- package/lib/operations/insert.js +70 -0
- package/lib/operations/insert.js.map +1 -0
- package/lib/operations/kill_cursors.js +43 -0
- package/lib/operations/kill_cursors.js.map +1 -0
- package/lib/operations/list_collections.js +53 -0
- package/lib/operations/list_collections.js.map +1 -0
- package/lib/operations/list_databases.js +40 -0
- package/lib/operations/list_databases.js.map +1 -0
- package/lib/operations/operation.js +102 -0
- package/lib/operations/operation.js.map +1 -0
- package/lib/operations/profiling_level.js +43 -0
- package/lib/operations/profiling_level.js.map +1 -0
- package/lib/operations/remove_user.js +27 -0
- package/lib/operations/remove_user.js.map +1 -0
- package/lib/operations/rename.js +38 -0
- package/lib/operations/rename.js.map +1 -0
- package/lib/operations/run_command.js +47 -0
- package/lib/operations/run_command.js.map +1 -0
- package/lib/operations/search_indexes/create.js +33 -0
- package/lib/operations/search_indexes/create.js.map +1 -0
- package/lib/operations/search_indexes/drop.js +43 -0
- package/lib/operations/search_indexes/drop.js.map +1 -0
- package/lib/operations/search_indexes/update.js +35 -0
- package/lib/operations/search_indexes/update.js.map +1 -0
- package/lib/operations/set_profiling_level.js +53 -0
- package/lib/operations/set_profiling_level.js.map +1 -0
- package/lib/operations/stats.js +27 -0
- package/lib/operations/stats.js.map +1 -0
- package/lib/operations/update.js +188 -0
- package/lib/operations/update.js.map +1 -0
- package/lib/operations/validate_collection.js +37 -0
- package/lib/operations/validate_collection.js.map +1 -0
- package/lib/read_concern.js +73 -0
- package/lib/read_concern.js.map +1 -0
- package/lib/read_preference.js +191 -0
- package/lib/read_preference.js.map +1 -0
- package/lib/sdam/common.js +49 -0
- package/lib/sdam/common.js.map +1 -0
- package/lib/sdam/events.js +146 -0
- package/lib/sdam/events.js.map +1 -0
- package/lib/sdam/monitor.js +544 -0
- package/lib/sdam/monitor.js.map +1 -0
- package/lib/sdam/server.js +404 -0
- package/lib/sdam/server.js.map +1 -0
- package/lib/sdam/server_description.js +204 -0
- package/lib/sdam/server_description.js.map +1 -0
- package/lib/sdam/server_selection.js +294 -0
- package/lib/sdam/server_selection.js.map +1 -0
- package/lib/sdam/server_selection_events.js +85 -0
- package/lib/sdam/server_selection_events.js.map +1 -0
- package/lib/sdam/srv_polling.js +108 -0
- package/lib/sdam/srv_polling.js.map +1 -0
- package/lib/sdam/topology.js +652 -0
- package/lib/sdam/topology.js.map +1 -0
- package/lib/sdam/topology_description.js +383 -0
- package/lib/sdam/topology_description.js.map +1 -0
- package/lib/sessions.js +892 -0
- package/lib/sessions.js.map +1 -0
- package/lib/sort.js +103 -0
- package/lib/sort.js.map +1 -0
- package/lib/timeout.js +296 -0
- package/lib/timeout.js.map +1 -0
- package/lib/transactions.js +135 -0
- package/lib/transactions.js.map +1 -0
- package/lib/utils.js +1163 -0
- package/lib/utils.js.map +1 -0
- package/lib/write_concern.js +100 -0
- package/lib/write_concern.js.map +1 -0
- package/mongodb.d.ts +9018 -0
- package/package.json +197 -0
- package/src/admin.ts +173 -0
- package/src/bson.ts +149 -0
- package/src/bulk/common.ts +1251 -0
- package/src/bulk/ordered.ts +83 -0
- package/src/bulk/unordered.ts +115 -0
- package/src/change_stream.ts +1160 -0
- package/src/client-side-encryption/auto_encrypter.ts +469 -0
- package/src/client-side-encryption/client_encryption.ts +1150 -0
- package/src/client-side-encryption/errors.ts +144 -0
- package/src/client-side-encryption/mongocryptd_manager.ts +100 -0
- package/src/client-side-encryption/providers/aws.ts +33 -0
- package/src/client-side-encryption/providers/azure.ts +181 -0
- package/src/client-side-encryption/providers/gcp.ts +16 -0
- package/src/client-side-encryption/providers/index.ts +207 -0
- package/src/client-side-encryption/state_machine.ts +651 -0
- package/src/cmap/auth/auth_provider.ts +77 -0
- package/src/cmap/auth/aws4.ts +207 -0
- package/src/cmap/auth/aws_temporary_credentials.ts +129 -0
- package/src/cmap/auth/gssapi.ts +203 -0
- package/src/cmap/auth/mongo_credentials.ts +292 -0
- package/src/cmap/auth/mongodb_aws.ts +179 -0
- package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +88 -0
- package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +73 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +188 -0
- package/src/cmap/auth/mongodb_oidc/command_builders.ts +53 -0
- package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +46 -0
- package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +141 -0
- package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +31 -0
- package/src/cmap/auth/mongodb_oidc/token_cache.ts +62 -0
- package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +22 -0
- package/src/cmap/auth/mongodb_oidc.ts +185 -0
- package/src/cmap/auth/plain.ts +25 -0
- package/src/cmap/auth/providers.ts +22 -0
- package/src/cmap/auth/scram.ts +344 -0
- package/src/cmap/auth/x509.ts +43 -0
- package/src/cmap/command_monitoring_events.ts +316 -0
- package/src/cmap/commands.ts +788 -0
- package/src/cmap/connect.ts +518 -0
- package/src/cmap/connection.ts +931 -0
- package/src/cmap/connection_pool.ts +831 -0
- package/src/cmap/connection_pool_events.ts +300 -0
- package/src/cmap/errors.ts +119 -0
- package/src/cmap/handshake/client_metadata.ts +353 -0
- package/src/cmap/metrics.ts +58 -0
- package/src/cmap/stream_description.ts +96 -0
- package/src/cmap/wire_protocol/compression.ts +211 -0
- package/src/cmap/wire_protocol/constants.ts +17 -0
- package/src/cmap/wire_protocol/on_data.ts +139 -0
- package/src/cmap/wire_protocol/on_demand/document.ts +358 -0
- package/src/cmap/wire_protocol/responses.ts +393 -0
- package/src/cmap/wire_protocol/shared.ts +48 -0
- package/src/collection.ts +1314 -0
- package/src/connection_string.ts +1297 -0
- package/src/constants.ts +176 -0
- package/src/cursor/abstract_cursor.ts +1247 -0
- package/src/cursor/aggregation_cursor.ts +245 -0
- package/src/cursor/change_stream_cursor.ts +171 -0
- package/src/cursor/client_bulk_write_cursor.ts +83 -0
- package/src/cursor/explainable_cursor.ts +51 -0
- package/src/cursor/find_cursor.ts +497 -0
- package/src/cursor/list_collections_cursor.ts +50 -0
- package/src/cursor/list_indexes_cursor.ts +37 -0
- package/src/cursor/list_search_indexes_cursor.ts +20 -0
- package/src/cursor/run_command_cursor.ts +178 -0
- package/src/db.ts +621 -0
- package/src/deps.ts +227 -0
- package/src/encrypter.ts +127 -0
- package/src/error.ts +1567 -0
- package/src/explain.ts +124 -0
- package/src/gridfs/download.ts +483 -0
- package/src/gridfs/index.ts +264 -0
- package/src/gridfs/upload.ts +537 -0
- package/src/index.ts +633 -0
- package/src/mongo_client.ts +1155 -0
- package/src/mongo_client_auth_providers.ts +87 -0
- package/src/mongo_logger.ts +1081 -0
- package/src/mongo_types.ts +678 -0
- package/src/operations/aggregate.ts +153 -0
- package/src/operations/client_bulk_write/client_bulk_write.ts +72 -0
- package/src/operations/client_bulk_write/command_builder.ts +487 -0
- package/src/operations/client_bulk_write/common.ts +276 -0
- package/src/operations/client_bulk_write/executor.ts +149 -0
- package/src/operations/client_bulk_write/results_merger.ts +260 -0
- package/src/operations/command.ts +171 -0
- package/src/operations/count.ts +74 -0
- package/src/operations/create_collection.ts +218 -0
- package/src/operations/delete.ts +183 -0
- package/src/operations/distinct.ts +92 -0
- package/src/operations/drop.ts +130 -0
- package/src/operations/end_sessions.ts +44 -0
- package/src/operations/estimated_document_count.ts +61 -0
- package/src/operations/execute_operation.ts +319 -0
- package/src/operations/find.ts +254 -0
- package/src/operations/find_and_modify.ts +319 -0
- package/src/operations/get_more.ts +108 -0
- package/src/operations/indexes.ts +418 -0
- package/src/operations/insert.ts +108 -0
- package/src/operations/kill_cursors.ts +64 -0
- package/src/operations/list_collections.ts +108 -0
- package/src/operations/list_databases.ts +68 -0
- package/src/operations/operation.ts +181 -0
- package/src/operations/profiling_level.ts +46 -0
- package/src/operations/remove_user.ts +36 -0
- package/src/operations/rename.ts +60 -0
- package/src/operations/run_command.ts +79 -0
- package/src/operations/search_indexes/create.ts +56 -0
- package/src/operations/search_indexes/drop.ts +58 -0
- package/src/operations/search_indexes/update.ts +45 -0
- package/src/operations/set_profiling_level.ts +74 -0
- package/src/operations/stats.ts +37 -0
- package/src/operations/update.ts +318 -0
- package/src/operations/validate_collection.ts +50 -0
- package/src/read_concern.ts +88 -0
- package/src/read_preference.ts +256 -0
- package/src/sdam/common.ts +74 -0
- package/src/sdam/events.ts +219 -0
- package/src/sdam/monitor.ts +771 -0
- package/src/sdam/server.ts +595 -0
- package/src/sdam/server_description.ts +297 -0
- package/src/sdam/server_selection.ts +415 -0
- package/src/sdam/server_selection_events.ts +142 -0
- package/src/sdam/srv_polling.ts +146 -0
- package/src/sdam/topology.ts +1100 -0
- package/src/sdam/topology_description.ts +548 -0
- package/src/sessions.ts +1244 -0
- package/src/sort.ts +141 -0
- package/src/timeout.ts +405 -0
- package/src/transactions.ts +181 -0
- package/src/utils.ts +1434 -0
- package/src/write_concern.ts +183 -0
- package/tsconfig.json +46 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateMachine = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const net = require("net");
|
|
6
|
+
const process = require("process");
|
|
7
|
+
const tls = require("tls");
|
|
8
|
+
const bson_1 = require("../bson");
|
|
9
|
+
const abstract_cursor_1 = require("../cursor/abstract_cursor");
|
|
10
|
+
const deps_1 = require("../deps");
|
|
11
|
+
const error_1 = require("../error");
|
|
12
|
+
const timeout_1 = require("../timeout");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
const client_encryption_1 = require("./client_encryption");
|
|
15
|
+
const errors_1 = require("./errors");
|
|
16
|
+
let socks = null;
|
|
17
|
+
function loadSocks() {
|
|
18
|
+
if (socks == null) {
|
|
19
|
+
const socksImport = (0, deps_1.getSocks)();
|
|
20
|
+
if ('kModuleError' in socksImport) {
|
|
21
|
+
throw socksImport.kModuleError;
|
|
22
|
+
}
|
|
23
|
+
socks = socksImport;
|
|
24
|
+
}
|
|
25
|
+
return socks;
|
|
26
|
+
}
|
|
27
|
+
// libmongocrypt states
|
|
28
|
+
const MONGOCRYPT_CTX_ERROR = 0;
|
|
29
|
+
const MONGOCRYPT_CTX_NEED_MONGO_COLLINFO = 1;
|
|
30
|
+
const MONGOCRYPT_CTX_NEED_MONGO_MARKINGS = 2;
|
|
31
|
+
const MONGOCRYPT_CTX_NEED_MONGO_KEYS = 3;
|
|
32
|
+
const MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS = 7;
|
|
33
|
+
const MONGOCRYPT_CTX_NEED_KMS = 4;
|
|
34
|
+
const MONGOCRYPT_CTX_READY = 5;
|
|
35
|
+
const MONGOCRYPT_CTX_DONE = 6;
|
|
36
|
+
const HTTPS_PORT = 443;
|
|
37
|
+
const stateToString = new Map([
|
|
38
|
+
[MONGOCRYPT_CTX_ERROR, 'MONGOCRYPT_CTX_ERROR'],
|
|
39
|
+
[MONGOCRYPT_CTX_NEED_MONGO_COLLINFO, 'MONGOCRYPT_CTX_NEED_MONGO_COLLINFO'],
|
|
40
|
+
[MONGOCRYPT_CTX_NEED_MONGO_MARKINGS, 'MONGOCRYPT_CTX_NEED_MONGO_MARKINGS'],
|
|
41
|
+
[MONGOCRYPT_CTX_NEED_MONGO_KEYS, 'MONGOCRYPT_CTX_NEED_MONGO_KEYS'],
|
|
42
|
+
[MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS, 'MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS'],
|
|
43
|
+
[MONGOCRYPT_CTX_NEED_KMS, 'MONGOCRYPT_CTX_NEED_KMS'],
|
|
44
|
+
[MONGOCRYPT_CTX_READY, 'MONGOCRYPT_CTX_READY'],
|
|
45
|
+
[MONGOCRYPT_CTX_DONE, 'MONGOCRYPT_CTX_DONE']
|
|
46
|
+
]);
|
|
47
|
+
const INSECURE_TLS_OPTIONS = [
|
|
48
|
+
'tlsInsecure',
|
|
49
|
+
'tlsAllowInvalidCertificates',
|
|
50
|
+
'tlsAllowInvalidHostnames'
|
|
51
|
+
];
|
|
52
|
+
/**
|
|
53
|
+
* Helper function for logging. Enabled by setting the environment flag MONGODB_CRYPT_DEBUG.
|
|
54
|
+
* @param msg - Anything you want to be logged.
|
|
55
|
+
*/
|
|
56
|
+
function debug(msg) {
|
|
57
|
+
if (process.env.MONGODB_CRYPT_DEBUG) {
|
|
58
|
+
// eslint-disable-next-line no-console
|
|
59
|
+
console.error(msg);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* This is kind of a hack. For `rewrapManyDataKey`, we have tests that
|
|
64
|
+
* guarantee that when there are no matching keys, `rewrapManyDataKey` returns
|
|
65
|
+
* nothing. We also have tests for auto encryption that guarantee for `encrypt`
|
|
66
|
+
* we return an error when there are no matching keys. This error is generated in
|
|
67
|
+
* subsequent iterations of the state machine.
|
|
68
|
+
* Some apis (`encrypt`) throw if there are no filter matches and others (`rewrapManyDataKey`)
|
|
69
|
+
* do not. We set the result manually here, and let the state machine continue. `libmongocrypt`
|
|
70
|
+
* will inform us if we need to error by setting the state to `MONGOCRYPT_CTX_ERROR` but
|
|
71
|
+
* otherwise we'll return `{ v: [] }`.
|
|
72
|
+
*/
|
|
73
|
+
let EMPTY_V;
|
|
74
|
+
/**
|
|
75
|
+
* @internal
|
|
76
|
+
* An internal class that executes across a MongoCryptContext until either
|
|
77
|
+
* a finishing state or an error is reached. Do not instantiate directly.
|
|
78
|
+
*/
|
|
79
|
+
// TODO(DRIVERS-2671): clarify CSOT behavior for FLE APIs
|
|
80
|
+
class StateMachine {
|
|
81
|
+
constructor(options, bsonOptions = (0, bson_1.pluckBSONSerializeOptions)(options)) {
|
|
82
|
+
this.options = options;
|
|
83
|
+
this.bsonOptions = bsonOptions;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Executes the state machine according to the specification
|
|
87
|
+
*/
|
|
88
|
+
async execute(executor, context, options) {
|
|
89
|
+
const keyVaultNamespace = executor._keyVaultNamespace;
|
|
90
|
+
const keyVaultClient = executor._keyVaultClient;
|
|
91
|
+
const metaDataClient = executor._metaDataClient;
|
|
92
|
+
const mongocryptdClient = executor._mongocryptdClient;
|
|
93
|
+
const mongocryptdManager = executor._mongocryptdManager;
|
|
94
|
+
let result = null;
|
|
95
|
+
// Typescript treats getters just like properties: Once you've tested it for equality
|
|
96
|
+
// it cannot change. Which is exactly the opposite of what we use state and status for.
|
|
97
|
+
// Every call to at least `addMongoOperationResponse` and `finalize` can change the state.
|
|
98
|
+
// These wrappers let us write code more naturally and not add compiler exceptions
|
|
99
|
+
// to conditions checks inside the state machine.
|
|
100
|
+
const getStatus = () => context.status;
|
|
101
|
+
const getState = () => context.state;
|
|
102
|
+
while (getState() !== MONGOCRYPT_CTX_DONE && getState() !== MONGOCRYPT_CTX_ERROR) {
|
|
103
|
+
options.signal?.throwIfAborted();
|
|
104
|
+
debug(`[context#${context.id}] ${stateToString.get(getState()) || getState()}`);
|
|
105
|
+
switch (getState()) {
|
|
106
|
+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO: {
|
|
107
|
+
const filter = (0, bson_1.deserialize)(context.nextMongoOperation());
|
|
108
|
+
if (!metaDataClient) {
|
|
109
|
+
throw new errors_1.MongoCryptError('unreachable state machine state: entered MONGOCRYPT_CTX_NEED_MONGO_COLLINFO but metadata client is undefined');
|
|
110
|
+
}
|
|
111
|
+
const collInfoCursor = this.fetchCollectionInfo(metaDataClient, context.ns, filter, options);
|
|
112
|
+
for await (const collInfo of collInfoCursor) {
|
|
113
|
+
context.addMongoOperationResponse((0, bson_1.serialize)(collInfo));
|
|
114
|
+
if (getState() === MONGOCRYPT_CTX_ERROR)
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (getState() === MONGOCRYPT_CTX_ERROR)
|
|
118
|
+
break;
|
|
119
|
+
context.finishMongoOperation();
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS: {
|
|
123
|
+
const command = context.nextMongoOperation();
|
|
124
|
+
if (getState() === MONGOCRYPT_CTX_ERROR)
|
|
125
|
+
break;
|
|
126
|
+
if (!mongocryptdClient) {
|
|
127
|
+
throw new errors_1.MongoCryptError('unreachable state machine state: entered MONGOCRYPT_CTX_NEED_MONGO_MARKINGS but mongocryptdClient is undefined');
|
|
128
|
+
}
|
|
129
|
+
// When we are using the shared library, we don't have a mongocryptd manager.
|
|
130
|
+
const markedCommand = mongocryptdManager
|
|
131
|
+
? await mongocryptdManager.withRespawn(this.markCommand.bind(this, mongocryptdClient, context.ns, command, options))
|
|
132
|
+
: await this.markCommand(mongocryptdClient, context.ns, command, options);
|
|
133
|
+
context.addMongoOperationResponse(markedCommand);
|
|
134
|
+
context.finishMongoOperation();
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case MONGOCRYPT_CTX_NEED_MONGO_KEYS: {
|
|
138
|
+
const filter = context.nextMongoOperation();
|
|
139
|
+
const keys = await this.fetchKeys(keyVaultClient, keyVaultNamespace, filter, options);
|
|
140
|
+
if (keys.length === 0) {
|
|
141
|
+
// See docs on EMPTY_V
|
|
142
|
+
result = EMPTY_V ??= (0, bson_1.serialize)({ v: [] });
|
|
143
|
+
}
|
|
144
|
+
for (const key of keys) {
|
|
145
|
+
context.addMongoOperationResponse((0, bson_1.serialize)(key));
|
|
146
|
+
}
|
|
147
|
+
context.finishMongoOperation();
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS: {
|
|
151
|
+
const kmsProviders = await executor.askForKMSCredentials();
|
|
152
|
+
context.provideKMSProviders((0, bson_1.serialize)(kmsProviders));
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
case MONGOCRYPT_CTX_NEED_KMS: {
|
|
156
|
+
await Promise.all(this.requests(context, options));
|
|
157
|
+
context.finishKMSRequests();
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case MONGOCRYPT_CTX_READY: {
|
|
161
|
+
const finalizedContext = context.finalize();
|
|
162
|
+
if (getState() === MONGOCRYPT_CTX_ERROR) {
|
|
163
|
+
const message = getStatus().message || 'Finalization error';
|
|
164
|
+
throw new errors_1.MongoCryptError(message);
|
|
165
|
+
}
|
|
166
|
+
result = finalizedContext;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
default:
|
|
170
|
+
throw new errors_1.MongoCryptError(`Unknown state: ${getState()}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (getState() === MONGOCRYPT_CTX_ERROR || result == null) {
|
|
174
|
+
const message = getStatus().message;
|
|
175
|
+
if (!message) {
|
|
176
|
+
debug(`unidentifiable error in MongoCrypt - received an error status from \`libmongocrypt\` but received no error message.`);
|
|
177
|
+
}
|
|
178
|
+
throw new errors_1.MongoCryptError(message ??
|
|
179
|
+
'unidentifiable error in MongoCrypt - received an error status from `libmongocrypt` but received no error message.');
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Handles the request to the KMS service. Exposed for testing purposes. Do not directly invoke.
|
|
185
|
+
* @param kmsContext - A C++ KMS context returned from the bindings
|
|
186
|
+
* @returns A promise that resolves when the KMS reply has be fully parsed
|
|
187
|
+
*/
|
|
188
|
+
async kmsRequest(request, options) {
|
|
189
|
+
const parsedUrl = request.endpoint.split(':');
|
|
190
|
+
const port = parsedUrl[1] != null ? Number.parseInt(parsedUrl[1], 10) : HTTPS_PORT;
|
|
191
|
+
const socketOptions = {
|
|
192
|
+
host: parsedUrl[0],
|
|
193
|
+
servername: parsedUrl[0],
|
|
194
|
+
port,
|
|
195
|
+
...(0, client_encryption_1.autoSelectSocketOptions)(this.options.socketOptions || {})
|
|
196
|
+
};
|
|
197
|
+
const message = request.message;
|
|
198
|
+
const buffer = new utils_1.BufferPool();
|
|
199
|
+
let netSocket;
|
|
200
|
+
let socket;
|
|
201
|
+
function destroySockets() {
|
|
202
|
+
for (const sock of [socket, netSocket]) {
|
|
203
|
+
if (sock) {
|
|
204
|
+
sock.destroy();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function onerror(cause) {
|
|
209
|
+
return new errors_1.MongoCryptError('KMS request failed', { cause });
|
|
210
|
+
}
|
|
211
|
+
function onclose() {
|
|
212
|
+
return new errors_1.MongoCryptError('KMS request closed');
|
|
213
|
+
}
|
|
214
|
+
const tlsOptions = this.options.tlsOptions;
|
|
215
|
+
if (tlsOptions) {
|
|
216
|
+
const kmsProvider = request.kmsProvider;
|
|
217
|
+
const providerTlsOptions = tlsOptions[kmsProvider];
|
|
218
|
+
if (providerTlsOptions) {
|
|
219
|
+
const error = this.validateTlsOptions(kmsProvider, providerTlsOptions);
|
|
220
|
+
if (error) {
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
await this.setTlsOptions(providerTlsOptions, socketOptions);
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
throw onerror(err);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
let abortListener;
|
|
232
|
+
try {
|
|
233
|
+
if (this.options.proxyOptions && this.options.proxyOptions.proxyHost) {
|
|
234
|
+
netSocket = new net.Socket();
|
|
235
|
+
const { promise: willConnect, reject: rejectOnNetSocketError, resolve: resolveOnNetSocketConnect } = (0, utils_1.promiseWithResolvers)();
|
|
236
|
+
netSocket
|
|
237
|
+
.once('error', err => rejectOnNetSocketError(onerror(err)))
|
|
238
|
+
.once('close', () => rejectOnNetSocketError(onclose()))
|
|
239
|
+
.once('connect', () => resolveOnNetSocketConnect());
|
|
240
|
+
const netSocketOptions = {
|
|
241
|
+
...socketOptions,
|
|
242
|
+
host: this.options.proxyOptions.proxyHost,
|
|
243
|
+
port: this.options.proxyOptions.proxyPort || 1080
|
|
244
|
+
};
|
|
245
|
+
netSocket.connect(netSocketOptions);
|
|
246
|
+
await willConnect;
|
|
247
|
+
try {
|
|
248
|
+
socks ??= loadSocks();
|
|
249
|
+
socketOptions.socket = (await socks.SocksClient.createConnection({
|
|
250
|
+
existing_socket: netSocket,
|
|
251
|
+
command: 'connect',
|
|
252
|
+
destination: { host: socketOptions.host, port: socketOptions.port },
|
|
253
|
+
proxy: {
|
|
254
|
+
// host and port are ignored because we pass existing_socket
|
|
255
|
+
host: 'iLoveJavaScript',
|
|
256
|
+
port: 0,
|
|
257
|
+
type: 5,
|
|
258
|
+
userId: this.options.proxyOptions.proxyUsername,
|
|
259
|
+
password: this.options.proxyOptions.proxyPassword
|
|
260
|
+
}
|
|
261
|
+
})).socket;
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
throw onerror(err);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
socket = tls.connect(socketOptions, () => {
|
|
268
|
+
socket.write(message);
|
|
269
|
+
});
|
|
270
|
+
const { promise: willResolveKmsRequest, reject: rejectOnTlsSocketError, resolve } = (0, utils_1.promiseWithResolvers)();
|
|
271
|
+
abortListener = (0, utils_1.addAbortListener)(options?.signal, function () {
|
|
272
|
+
destroySockets();
|
|
273
|
+
rejectOnTlsSocketError(this.reason);
|
|
274
|
+
});
|
|
275
|
+
socket
|
|
276
|
+
.once('error', err => rejectOnTlsSocketError(onerror(err)))
|
|
277
|
+
.once('close', () => rejectOnTlsSocketError(onclose()))
|
|
278
|
+
.on('data', data => {
|
|
279
|
+
buffer.append(data);
|
|
280
|
+
while (request.bytesNeeded > 0 && buffer.length) {
|
|
281
|
+
const bytesNeeded = Math.min(request.bytesNeeded, buffer.length);
|
|
282
|
+
request.addResponse(buffer.read(bytesNeeded));
|
|
283
|
+
}
|
|
284
|
+
if (request.bytesNeeded <= 0) {
|
|
285
|
+
resolve();
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
await (options?.timeoutContext?.csotEnabled()
|
|
289
|
+
? Promise.all([
|
|
290
|
+
willResolveKmsRequest,
|
|
291
|
+
timeout_1.Timeout.expires(options.timeoutContext?.remainingTimeMS)
|
|
292
|
+
])
|
|
293
|
+
: willResolveKmsRequest);
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
if (error instanceof timeout_1.TimeoutError)
|
|
297
|
+
throw new error_1.MongoOperationTimeoutError('KMS request timed out');
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
finally {
|
|
301
|
+
// There's no need for any more activity on this socket at this point.
|
|
302
|
+
destroySockets();
|
|
303
|
+
abortListener?.[utils_1.kDispose]();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
*requests(context, options) {
|
|
307
|
+
for (let request = context.nextKMSRequest(); request != null; request = context.nextKMSRequest()) {
|
|
308
|
+
yield this.kmsRequest(request, options);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Validates the provided TLS options are secure.
|
|
313
|
+
*
|
|
314
|
+
* @param kmsProvider - The KMS provider name.
|
|
315
|
+
* @param tlsOptions - The client TLS options for the provider.
|
|
316
|
+
*
|
|
317
|
+
* @returns An error if any option is invalid.
|
|
318
|
+
*/
|
|
319
|
+
validateTlsOptions(kmsProvider, tlsOptions) {
|
|
320
|
+
const tlsOptionNames = Object.keys(tlsOptions);
|
|
321
|
+
for (const option of INSECURE_TLS_OPTIONS) {
|
|
322
|
+
if (tlsOptionNames.includes(option)) {
|
|
323
|
+
return new errors_1.MongoCryptError(`Insecure TLS options prohibited for ${kmsProvider}: ${option}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Sets only the valid secure TLS options.
|
|
329
|
+
*
|
|
330
|
+
* @param tlsOptions - The client TLS options for the provider.
|
|
331
|
+
* @param options - The existing connection options.
|
|
332
|
+
*/
|
|
333
|
+
async setTlsOptions(tlsOptions, options) {
|
|
334
|
+
// If a secureContext is provided, ensure it is set.
|
|
335
|
+
if (tlsOptions.secureContext) {
|
|
336
|
+
options.secureContext = tlsOptions.secureContext;
|
|
337
|
+
}
|
|
338
|
+
if (tlsOptions.tlsCertificateKeyFile) {
|
|
339
|
+
const cert = await fs.readFile(tlsOptions.tlsCertificateKeyFile);
|
|
340
|
+
options.cert = options.key = cert;
|
|
341
|
+
}
|
|
342
|
+
if (tlsOptions.tlsCAFile) {
|
|
343
|
+
options.ca = await fs.readFile(tlsOptions.tlsCAFile);
|
|
344
|
+
}
|
|
345
|
+
if (tlsOptions.tlsCertificateKeyFilePassword) {
|
|
346
|
+
options.passphrase = tlsOptions.tlsCertificateKeyFilePassword;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Fetches collection info for a provided namespace, when libmongocrypt
|
|
351
|
+
* enters the `MONGOCRYPT_CTX_NEED_MONGO_COLLINFO` state. The result is
|
|
352
|
+
* used to inform libmongocrypt of the schema associated with this
|
|
353
|
+
* namespace. Exposed for testing purposes. Do not directly invoke.
|
|
354
|
+
*
|
|
355
|
+
* @param client - A MongoClient connected to the topology
|
|
356
|
+
* @param ns - The namespace to list collections from
|
|
357
|
+
* @param filter - A filter for the listCollections command
|
|
358
|
+
* @param callback - Invoked with the info of the requested collection, or with an error
|
|
359
|
+
*/
|
|
360
|
+
fetchCollectionInfo(client, ns, filter, options) {
|
|
361
|
+
const { db } = utils_1.MongoDBCollectionNamespace.fromString(ns);
|
|
362
|
+
const cursor = client.db(db).listCollections(filter, {
|
|
363
|
+
promoteLongs: false,
|
|
364
|
+
promoteValues: false,
|
|
365
|
+
timeoutContext: options?.timeoutContext && new abstract_cursor_1.CursorTimeoutContext(options?.timeoutContext, Symbol()),
|
|
366
|
+
signal: options?.signal,
|
|
367
|
+
nameOnly: false
|
|
368
|
+
});
|
|
369
|
+
return cursor;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Calls to the mongocryptd to provide markings for a command.
|
|
373
|
+
* Exposed for testing purposes. Do not directly invoke.
|
|
374
|
+
* @param client - A MongoClient connected to a mongocryptd
|
|
375
|
+
* @param ns - The namespace (database.collection) the command is being executed on
|
|
376
|
+
* @param command - The command to execute.
|
|
377
|
+
* @param callback - Invoked with the serialized and marked bson command, or with an error
|
|
378
|
+
*/
|
|
379
|
+
async markCommand(client, ns, command, options) {
|
|
380
|
+
const { db } = utils_1.MongoDBCollectionNamespace.fromString(ns);
|
|
381
|
+
const bsonOptions = { promoteLongs: false, promoteValues: false };
|
|
382
|
+
const rawCommand = (0, bson_1.deserialize)(command, bsonOptions);
|
|
383
|
+
const commandOptions = {
|
|
384
|
+
timeoutMS: undefined,
|
|
385
|
+
signal: undefined
|
|
386
|
+
};
|
|
387
|
+
if (options?.timeoutContext?.csotEnabled()) {
|
|
388
|
+
commandOptions.timeoutMS = options.timeoutContext.remainingTimeMS;
|
|
389
|
+
}
|
|
390
|
+
if (options?.signal) {
|
|
391
|
+
commandOptions.signal = options.signal;
|
|
392
|
+
}
|
|
393
|
+
const response = await client.db(db).command(rawCommand, {
|
|
394
|
+
...bsonOptions,
|
|
395
|
+
...commandOptions
|
|
396
|
+
});
|
|
397
|
+
return (0, bson_1.serialize)(response, this.bsonOptions);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Requests keys from the keyVault collection on the topology.
|
|
401
|
+
* Exposed for testing purposes. Do not directly invoke.
|
|
402
|
+
* @param client - A MongoClient connected to the topology
|
|
403
|
+
* @param keyVaultNamespace - The namespace (database.collection) of the keyVault Collection
|
|
404
|
+
* @param filter - The filter for the find query against the keyVault Collection
|
|
405
|
+
* @param callback - Invoked with the found keys, or with an error
|
|
406
|
+
*/
|
|
407
|
+
fetchKeys(client, keyVaultNamespace, filter, options) {
|
|
408
|
+
const { db: dbName, collection: collectionName } = utils_1.MongoDBCollectionNamespace.fromString(keyVaultNamespace);
|
|
409
|
+
const commandOptions = {
|
|
410
|
+
timeoutContext: undefined,
|
|
411
|
+
signal: undefined
|
|
412
|
+
};
|
|
413
|
+
if (options?.timeoutContext != null) {
|
|
414
|
+
commandOptions.timeoutContext = new abstract_cursor_1.CursorTimeoutContext(options.timeoutContext, Symbol());
|
|
415
|
+
}
|
|
416
|
+
if (options?.signal != null) {
|
|
417
|
+
commandOptions.signal = options.signal;
|
|
418
|
+
}
|
|
419
|
+
return client
|
|
420
|
+
.db(dbName)
|
|
421
|
+
.collection(collectionName, { readConcern: { level: 'majority' } })
|
|
422
|
+
.find((0, bson_1.deserialize)(filter), commandOptions)
|
|
423
|
+
.toArray();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
exports.StateMachine = StateMachine;
|
|
427
|
+
//# sourceMappingURL=state_machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state_machine.js","sourceRoot":"","sources":["../../src/client-side-encryption/state_machine.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAElC,2BAA2B;AAC3B,mCAAmC;AACnC,2BAA2B;AAE3B,kCAMiB;AAEjB,+DAAiE;AACjE,kCAAkD;AAClD,oCAAsD;AAItD,wCAAwE;AACxE,oCAMkB;AAClB,2DAA4E;AAC5E,qCAA2C;AAI3C,IAAI,KAAK,GAAoB,IAAI,CAAC;AAClC,SAAS,SAAS;IAChB,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,MAAM,WAAW,GAAG,IAAA,eAAQ,GAAE,CAAC;QAC/B,IAAI,cAAc,IAAI,WAAW,EAAE,CAAC;YAClC,MAAM,WAAW,CAAC,YAAY,CAAC;QACjC,CAAC;QACD,KAAK,GAAG,WAAW,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,uBAAuB;AACvB,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,kCAAkC,GAAG,CAAC,CAAC;AAC7C,MAAM,kCAAkC,GAAG,CAAC,CAAC;AAC7C,MAAM,8BAA8B,GAAG,CAAC,CAAC;AACzC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAC9C,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAClC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,MAAM,aA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AAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE;YACvD,GAAG,WAAW;YACd,GAAG,cAAc;SAClB,CAAC,CAAC;QAEH,OAAO,IAAA,gBAAS,EAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;OAOG;IACH,SAAS,CACP,MAAmB,EACnB,iBAAyB,EACzB,MAAkB,EAClB,OAAyD;QAEzD,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,GAC9C,kCAA0B,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;QAE3D,MAAM,cAAc,GAGhB;YACF,cAAc,EAAE,SAAS;YACzB,MAAM,EAAE,SAAS;SAClB,CAAC;QAEF,IAAI,OAAO,EAAE,cAAc,IAAI,IAAI,EAAE,CAAC;YACpC,cAAc,CAAC,cAAc,GAAG,IAAI,sCAAoB,CAAC,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7F,CAAC;QACD,IAAI,OAAO,EAAE,MAAM,IAAI,IAAI,EAAE,CAAC;YAC5B,cAAc,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QACzC,CAAC;QAED,OAAO,MAAM;aACV,EAAE,CAAC,MAAM,CAAC;aACV,UAAU,CAAU,cAAc,EAAE,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC;aAC3E,IAAI,CAAC,IAAA,kBAAW,EAAC,MAAM,CAAC,EAAE,cAAc,CAAC;aACzC,OAAO,EAAE,CAAC;IACf,CAAC;CACF;AAndD,oCAmdC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthProvider = exports.AuthContext = void 0;
|
|
4
|
+
const error_1 = require("../../error");
|
|
5
|
+
/**
|
|
6
|
+
* Context used during authentication
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
class AuthContext {
|
|
10
|
+
constructor(connection, credentials, options) {
|
|
11
|
+
/** If the context is for reauthentication. */
|
|
12
|
+
this.reauthenticating = false;
|
|
13
|
+
this.connection = connection;
|
|
14
|
+
this.credentials = credentials;
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.AuthContext = AuthContext;
|
|
19
|
+
/**
|
|
20
|
+
* Provider used during authentication.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
class AuthProvider {
|
|
24
|
+
/**
|
|
25
|
+
* Prepare the handshake document before the initial handshake.
|
|
26
|
+
*
|
|
27
|
+
* @param handshakeDoc - The document used for the initial handshake on a connection
|
|
28
|
+
* @param authContext - Context for authentication flow
|
|
29
|
+
*/
|
|
30
|
+
async prepare(handshakeDoc, _authContext) {
|
|
31
|
+
return handshakeDoc;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reauthenticate.
|
|
35
|
+
* @param context - The shared auth context.
|
|
36
|
+
*/
|
|
37
|
+
async reauth(context) {
|
|
38
|
+
if (context.reauthenticating) {
|
|
39
|
+
throw new error_1.MongoRuntimeError('Reauthentication already in progress.');
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
context.reauthenticating = true;
|
|
43
|
+
await this.auth(context);
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
context.reauthenticating = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.AuthProvider = AuthProvider;
|
|
51
|
+
//# sourceMappingURL=auth_provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth_provider.js","sourceRoot":"","sources":["../../../src/cmap/auth/auth_provider.ts"],"names":[],"mappings":";;;AACA,uCAAgD;AAKhD;;;GAGG;AACH,MAAa,WAAW;IAetB,YACE,UAAsB,EACtB,WAAyC,EACzC,OAA0B;QAb5B,8CAA8C;QAC9C,qBAAgB,GAAG,KAAK,CAAC;QAcvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAxBD,kCAwBC;AAED;;;GAGG;AACH,MAAsB,YAAY;IAChC;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CACX,YAA+B,EAC/B,YAAyB;QAEzB,OAAO,YAAY,CAAC;IACtB,CAAC;IASD;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,OAAoB;QAC/B,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC7B,MAAM,IAAI,yBAAiB,CAAC,uCAAuC,CAAC,CAAC;QACvE,CAAC;QACD,IAAI,CAAC;YACH,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAChC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,gBAAgB,GAAG,KAAK,CAAC;QACnC,CAAC;IACH,CAAC;CACF;AApCD,oCAoCC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aws4Sign = aws4Sign;
|
|
4
|
+
const bson_1 = require("../../bson");
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the SHA-256 hash of a string.
|
|
7
|
+
*
|
|
8
|
+
* @param str - String to hash.
|
|
9
|
+
* @returns Hexadecimal representation of the hash.
|
|
10
|
+
*/
|
|
11
|
+
const getHexSha256 = async (str) => {
|
|
12
|
+
const data = stringToBuffer(str);
|
|
13
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
14
|
+
const hashHex = bson_1.BSON.onDemand.ByteUtils.toHex(new Uint8Array(hashBuffer));
|
|
15
|
+
return hashHex;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Calculates the HMAC-SHA256 of a string using the provided key.
|
|
19
|
+
* @param key - Key to use for HMAC calculation. Can be a string or Uint8Array.
|
|
20
|
+
* @param str - String to calculate HMAC for.
|
|
21
|
+
* @returns Uint8Array containing the HMAC-SHA256 digest.
|
|
22
|
+
*/
|
|
23
|
+
const getHmacSha256 = async (key, str) => {
|
|
24
|
+
let keyData;
|
|
25
|
+
if (typeof key === 'string') {
|
|
26
|
+
keyData = stringToBuffer(key);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
keyData = key;
|
|
30
|
+
}
|
|
31
|
+
const importedKey = await crypto.subtle.importKey('raw', keyData, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']);
|
|
32
|
+
const strData = stringToBuffer(str);
|
|
33
|
+
const signature = await crypto.subtle.sign('HMAC', importedKey, strData);
|
|
34
|
+
const digest = new Uint8Array(signature);
|
|
35
|
+
return digest;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Converts header values according to AWS requirements,
|
|
39
|
+
* From https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-create-signed-request.html#create-canonical-request
|
|
40
|
+
* For values, you must:
|
|
41
|
+
- trim any leading or trailing spaces.
|
|
42
|
+
- convert sequential spaces to a single space.
|
|
43
|
+
* @param value - Header value to convert.
|
|
44
|
+
* @returns - Converted header value.
|
|
45
|
+
*/
|
|
46
|
+
const convertHeaderValue = (value) => {
|
|
47
|
+
return value.toString().trim().replace(/\s+/g, ' ');
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Returns a Uint8Array representation of a string, encoded in UTF-8.
|
|
51
|
+
* @param str - String to convert.
|
|
52
|
+
* @returns Uint8Array containing the UTF-8 encoded string.
|
|
53
|
+
*/
|
|
54
|
+
function stringToBuffer(str) {
|
|
55
|
+
const data = new Uint8Array(bson_1.BSON.onDemand.ByteUtils.utf8ByteLength(str));
|
|
56
|
+
bson_1.BSON.onDemand.ByteUtils.encodeUTF8Into(data, str, 0);
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* This method implements AWS Signature 4 logic for a very specific request format.
|
|
61
|
+
* The signing logic is described here: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-create-signed-request.html
|
|
62
|
+
*/
|
|
63
|
+
async function aws4Sign(options, credentials) {
|
|
64
|
+
/**
|
|
65
|
+
* From the spec: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-create-signed-request.html
|
|
66
|
+
*
|
|
67
|
+
* Summary of signing steps
|
|
68
|
+
* 1. Create a canonical request
|
|
69
|
+
* Arrange the contents of your request (host, action, headers, etc.) into a standard canonical format. The canonical request is one of the inputs used to create the string to sign.
|
|
70
|
+
* 2. Create a hash of the canonical request
|
|
71
|
+
* Hash the canonical request using the same algorithm that you used to create the hash of the payload. The hash of the canonical request is a string of lowercase hexadecimal characters.
|
|
72
|
+
* 3. Create a string to sign
|
|
73
|
+
* Create a string to sign with the canonical request and extra information such as the algorithm, request date, credential scope, and the hash of the canonical request.
|
|
74
|
+
* 4. Derive a signing key
|
|
75
|
+
* Use the secret access key to derive the key used to sign the request.
|
|
76
|
+
* 5. Calculate the signature
|
|
77
|
+
* Perform a keyed hash operation on the string to sign using the derived signing key as the hash key.
|
|
78
|
+
* 6. Add the signature to the request
|
|
79
|
+
* Add the calculated signature to an HTTP header or to the query string of the request.
|
|
80
|
+
*/
|
|
81
|
+
// 1: Create a canonical request
|
|
82
|
+
// Date – The date and time used to sign the request.
|
|
83
|
+
const date = options.date;
|
|
84
|
+
// RequestDateTime – The date and time used in the credential scope. This value is the current UTC time in ISO 8601 format (for example, 20130524T000000Z).
|
|
85
|
+
const requestDateTime = date.toISOString().replace(/[:-]|\.\d{3}/g, '');
|
|
86
|
+
// RequestDate – The date used in the credential scope. This value is the current UTC date in YYYYMMDD format (for example, 20130524).
|
|
87
|
+
const requestDate = requestDateTime.substring(0, 8);
|
|
88
|
+
// Method – The HTTP request method. For us, this is always 'POST'.
|
|
89
|
+
const method = options.method;
|
|
90
|
+
// CanonicalUri – The URI-encoded version of the absolute path component URI, starting with the / that follows the domain name and up to the end of the string
|
|
91
|
+
// For our requests, this is always '/'
|
|
92
|
+
const canonicalUri = options.path;
|
|
93
|
+
// CanonicalQueryString – The URI-encoded query string parameters. For our requests, there are no query string parameters, so this is always an empty string.
|
|
94
|
+
const canonicalQuerystring = '';
|
|
95
|
+
// CanonicalHeaders – A list of request headers with their values. Individual header name and value pairs are separated by the newline character ("\n").
|
|
96
|
+
// All of our known/expected headers are included here, there are no extra headers.
|
|
97
|
+
const headers = new Headers({
|
|
98
|
+
'content-length': convertHeaderValue(options.headers['Content-Length']),
|
|
99
|
+
'content-type': convertHeaderValue(options.headers['Content-Type']),
|
|
100
|
+
host: convertHeaderValue(options.host),
|
|
101
|
+
'x-amz-date': convertHeaderValue(requestDateTime),
|
|
102
|
+
'x-mongodb-gs2-cb-flag': convertHeaderValue(options.headers['X-MongoDB-GS2-CB-Flag']),
|
|
103
|
+
'x-mongodb-server-nonce': convertHeaderValue(options.headers['X-MongoDB-Server-Nonce'])
|
|
104
|
+
});
|
|
105
|
+
// If session token is provided, include it in the headers
|
|
106
|
+
if ('sessionToken' in credentials && credentials.sessionToken) {
|
|
107
|
+
headers.append('x-amz-security-token', convertHeaderValue(credentials.sessionToken));
|
|
108
|
+
}
|
|
109
|
+
// Canonical headers are lowercased and sorted.
|
|
110
|
+
const canonicalHeaders = Array.from(headers.entries())
|
|
111
|
+
.map(([key, value]) => `${key.toLowerCase()}:${value}`)
|
|
112
|
+
.sort()
|
|
113
|
+
.join('\n');
|
|
114
|
+
const canonicalHeaderNames = Array.from(headers.keys()).map(header => header.toLowerCase());
|
|
115
|
+
// SignedHeaders – An alphabetically sorted, semicolon-separated list of lowercase request header names.
|
|
116
|
+
const signedHeaders = canonicalHeaderNames.sort().join(';');
|
|
117
|
+
// HashedPayload – A string created using the payload in the body of the HTTP request as input to a hash function. This string uses lowercase hexadecimal characters.
|
|
118
|
+
const hashedPayload = await getHexSha256(options.body);
|
|
119
|
+
// CanonicalRequest – A string that includes the above elements, separated by newline characters.
|
|
120
|
+
const canonicalRequest = [
|
|
121
|
+
method,
|
|
122
|
+
canonicalUri,
|
|
123
|
+
canonicalQuerystring,
|
|
124
|
+
canonicalHeaders + '\n',
|
|
125
|
+
signedHeaders,
|
|
126
|
+
hashedPayload
|
|
127
|
+
].join('\n');
|
|
128
|
+
// 2. Create a hash of the canonical request
|
|
129
|
+
// HashedCanonicalRequest – A string created by using the canonical request as input to a hash function.
|
|
130
|
+
const hashedCanonicalRequest = await getHexSha256(canonicalRequest);
|
|
131
|
+
// 3. Create a string to sign
|
|
132
|
+
// Algorithm – The algorithm used to create the hash of the canonical request. For SigV4, use AWS4-HMAC-SHA256.
|
|
133
|
+
const algorithm = 'AWS4-HMAC-SHA256';
|
|
134
|
+
// CredentialScope – The credential scope, which restricts the resulting signature to the specified Region and service.
|
|
135
|
+
// Has the following format: YYYYMMDD/region/service/aws4_request.
|
|
136
|
+
const credentialScope = `${requestDate}/${options.region}/${options.service}/aws4_request`;
|
|
137
|
+
// StringToSign – A string that includes the above elements, separated by newline characters.
|
|
138
|
+
const stringToSign = [algorithm, requestDateTime, credentialScope, hashedCanonicalRequest].join('\n');
|
|
139
|
+
// 4. Derive a signing key
|
|
140
|
+
// To derive a signing key for SigV4, perform a succession of keyed hash operations (HMAC) on the request date, Region, and service, with your AWS secret access key as the key for the initial hashing operation.
|
|
141
|
+
const dateKey = await getHmacSha256('AWS4' + credentials.secretAccessKey, requestDate);
|
|
142
|
+
const dateRegionKey = await getHmacSha256(dateKey, options.region);
|
|
143
|
+
const dateRegionServiceKey = await getHmacSha256(dateRegionKey, options.service);
|
|
144
|
+
const signingKey = await getHmacSha256(dateRegionServiceKey, 'aws4_request');
|
|
145
|
+
// 5. Calculate the signature
|
|
146
|
+
const signatureBuffer = await getHmacSha256(signingKey, stringToSign);
|
|
147
|
+
const signature = bson_1.BSON.onDemand.ByteUtils.toHex(signatureBuffer);
|
|
148
|
+
// 6. Add the signature to the request
|
|
149
|
+
// Calculate the Authorization header
|
|
150
|
+
const authorizationHeader = [
|
|
151
|
+
'AWS4-HMAC-SHA256 Credential=' + credentials.accessKeyId + '/' + credentialScope,
|
|
152
|
+
'SignedHeaders=' + signedHeaders,
|
|
153
|
+
'Signature=' + signature
|
|
154
|
+
].join(', ');
|
|
155
|
+
// Return the calculated headers
|
|
156
|
+
return {
|
|
157
|
+
Authorization: authorizationHeader,
|
|
158
|
+
'X-Amz-Date': requestDateTime
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=aws4.js.map
|