Skip to content

Commit cf45741

Browse files
CDRIVER-4563 do not create or drop eccCollection (#1232)
* format mongoc-collection.c * do not create or drop eccCollection * add wire version macro for 7.0 * add wire version check and test * resync fle2v2 tests to aa28f787718eb4306ce7ff8e5a87bd46bb0a2c05 * add actual and expected maxWireVersion * use available WIRE_VERSION_* macros * sync fle2v2 tests to eb3d882bb8c08d0f25f54709abcd876caeccba7f * Update src/libmongoc/src/mongoc/mongoc-database.c Co-authored-by: vector-of-bool <[email protected]> --------- Co-authored-by: vector-of-bool <[email protected]>
1 parent 46a010f commit cf45741

File tree

66 files changed

+233
-876
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+233
-876
lines changed

src/libmongoc/src/mongoc/mongoc-client-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ BSON_BEGIN_DECLS
102102
#define WIRE_VERSION_5_1 14
103103
/* version corresponding to server 6.0 release */
104104
#define WIRE_VERSION_6_0 17
105+
/* version corresponding to server 7.0 release */
106+
#define WIRE_VERSION_7_0 21
105107

106108
struct _mongoc_collection_t;
107109

src/libmongoc/src/mongoc/mongoc-collection.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ mongoc_collection_count_with_opts (
764764
kv ("query",
765765
if (query, // If we have a query,
766766
then (bson (*query)), // Copy it
767-
else(doc ()))), // Otherwise, add an empty doc
767+
else (doc ()))), // Otherwise, add an empty doc
768768
if (limit, then (kv ("limit", int64 (limit)))),
769769
if (skip, then (kv ("skip", int64 (skip)))));
770770

@@ -1055,10 +1055,8 @@ drop_with_opts_with_encryptedFields (mongoc_collection_t *collection,
10551055
bson_error_t *error)
10561056
{
10571057
char *escName = NULL;
1058-
char *eccName = NULL;
10591058
char *ecocName = NULL;
10601059
mongoc_collection_t *escCollection = NULL;
1061-
mongoc_collection_t *eccCollection = NULL;
10621060
mongoc_collection_t *ecocCollection = NULL;
10631061
bool ok = false;
10641062
const char *name = mongoc_collection_get_name (collection);
@@ -1087,23 +1085,6 @@ drop_with_opts_with_encryptedFields (mongoc_collection_t *collection,
10871085
}
10881086
}
10891087

1090-
/* Drop ECC collection. */
1091-
eccName = _mongoc_get_encryptedField_state_collection (
1092-
encryptedFields, name, "ecc", error);
1093-
if (!eccName) {
1094-
goto fail;
1095-
}
1096-
1097-
eccCollection = mongoc_client_get_collection (
1098-
collection->client, collection->db, eccName);
1099-
if (!drop_with_opts (eccCollection, NULL /* opts */, error)) {
1100-
if (error->code == MONGOC_SERVER_ERR_NS_NOT_FOUND) {
1101-
memset (error, 0, sizeof (bson_error_t));
1102-
} else {
1103-
goto fail;
1104-
}
1105-
}
1106-
11071088
/* Drop ECOC collection. */
11081089
ecocName = _mongoc_get_encryptedField_state_collection (
11091090
encryptedFields, name, "ecoc", error);
@@ -1134,8 +1115,6 @@ drop_with_opts_with_encryptedFields (mongoc_collection_t *collection,
11341115
fail:
11351116
mongoc_collection_destroy (ecocCollection);
11361117
bson_free (ecocName);
1137-
mongoc_collection_destroy (eccCollection);
1138-
bson_free (eccName);
11391118
mongoc_collection_destroy (escCollection);
11401119
bson_free (escName);
11411120
return ok;

src/libmongoc/src/mongoc/mongoc-database.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,15 +1015,13 @@ _mongoc_get_encryptedField_state_collection (
10151015

10161016
if (0 == strcmp (state_collection_suffix, "esc")) {
10171017
fieldName = "escCollection";
1018-
} else if (0 == strcmp (state_collection_suffix, "ecc")) {
1019-
fieldName = "eccCollection";
10201018
} else if (0 == strcmp (state_collection_suffix, "ecoc")) {
10211019
fieldName = "ecocCollection";
10221020
} else {
10231021
bson_set_error (error,
10241022
MONGOC_ERROR_COMMAND,
10251023
MONGOC_ERROR_COMMAND_INVALID_ARG,
1026-
"expected state_collection_suffix to be 'esc', 'ecc', or "
1024+
"expected state_collection_suffix to be 'esc' or "
10271025
"'ecoc', got: %s",
10281026
state_collection_suffix);
10291027
return NULL;
@@ -1100,15 +1098,40 @@ create_collection_with_encryptedFields (mongoc_database_t *database,
11001098
bool state_collections_ok =
11011099
create_encField_state_collection (
11021100
database, encryptedFields, name, "esc", error) &&
1103-
create_encField_state_collection (
1104-
database, encryptedFields, name, "ecc", error) &&
11051101
create_encField_state_collection (
11061102
database, encryptedFields, name, "ecoc", error);
11071103
if (!state_collections_ok) {
11081104
// Failed to create one or more state collections
11091105
goto fail;
11101106
}
11111107

1108+
// Check the wire version to ensure server is 7.0.0 or newer.
1109+
{
1110+
mongoc_server_stream_t *stream =
1111+
mongoc_cluster_stream_for_writes (&database->client->cluster,
1112+
NULL /* client session */,
1113+
NULL /* reply */,
1114+
error);
1115+
if (!stream) {
1116+
goto fail;
1117+
}
1118+
if (stream->sd->max_wire_version < WIRE_VERSION_7_0) {
1119+
bson_set_error (
1120+
error,
1121+
MONGOC_ERROR_PROTOCOL,
1122+
MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION,
1123+
"Driver support of Queryable Encryption is incompatible "
1124+
"with server. Upgrade server to use Queryable Encryption. "
1125+
"Got maxWireVersion %" PRId32 " but need maxWireVersion >= %d",
1126+
stream->sd->max_wire_version,
1127+
WIRE_VERSION_7_0);
1128+
mongoc_server_stream_cleanup (stream);
1129+
goto fail;
1130+
}
1131+
mongoc_server_stream_cleanup (stream);
1132+
}
1133+
1134+
11121135
/* Create data collection. */
11131136
cc_opts = bson_copy (opts);
11141137
if (!BSON_APPEND_DOCUMENT (cc_opts, "encryptedFields", encryptedFields)) {

src/libmongoc/src/mongoc/mongoc-util.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "mongoc-rand-private.h"
2828
#include "mongoc-util-private.h"
2929
#include "mongoc-client.h"
30+
#include "mongoc-client-private.h" // WIRE_VERSION_* macros.
3031
#include "mongoc-client-session-private.h"
3132
#include "mongoc-trace-private.h"
3233

@@ -288,28 +289,30 @@ _mongoc_wire_version_to_server_version (int32_t version)
288289
return "3.4";
289290
case 6:
290291
return "3.6";
291-
case 7:
292+
case WIRE_VERSION_4_0:
292293
return "4.0";
293-
case 8:
294+
case WIRE_VERSION_4_2:
294295
return "4.2";
295-
case 9:
296+
case WIRE_VERSION_4_4:
296297
return "4.4";
297298
case 10:
298299
return "4.7";
299300
case 11:
300301
return "4.8";
301-
case 12:
302+
case WIRE_VERSION_4_9:
302303
return "4.9";
303-
case 13:
304+
case WIRE_VERSION_5_0:
304305
return "5.0";
305-
case 14:
306+
case WIRE_VERSION_5_1:
306307
return "5.1";
307308
case 15:
308309
return "5.2";
309310
case 16:
310311
return "5.3";
311-
case 17:
312+
case WIRE_VERSION_6_0:
312313
return "6.0";
314+
case WIRE_VERSION_7_0:
315+
return "7.0";
313316
default:
314317
return "Unknown";
315318
}

src/libmongoc/tests/client_side_encryption_prose/explicit_encryption/range-encryptedFields-Date.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
}
2828
}
2929
]
30-
}
30+
}

src/libmongoc/tests/client_side_encryption_prose/explicit_encryption/range-encryptedFields-DoubleNoPrecision.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
}
1818
}
1919
]
20-
}
20+
}
21+

src/libmongoc/tests/client_side_encryption_prose/explicit_encryption/range-encryptedFields-DoublePrecision.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@
2626
}
2727
}
2828
]
29-
}
29+
}
30+

src/libmongoc/tests/client_side_encryption_prose/explicit_encryption/range-encryptedFields-Int.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
}
2424
}
2525
]
26-
}
26+
}
27+

src/libmongoc/tests/client_side_encryption_prose/explicit_encryption/range-encryptedFields-Long.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
}
2424
}
2525
]
26-
}
26+
}
27+

src/libmongoc/tests/json/client_side_encryption/legacy/fle2v2-BypassQueryAnalysis.json

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"collection_name": "default",
1515
"data": [],
1616
"encrypted_fields": {
17-
"escCollection": "enxcol_.default.esc",
18-
"eccCollection": "enxcol_.default.ecc",
19-
"ecocCollection": "enxcol_.default.ecoc",
2017
"fields": [
2118
{
2219
"keyId": {
@@ -153,7 +150,44 @@
153150
}
154151
}
155152
],
156-
"ordered": true
153+
"ordered": true,
154+
"encryptionInformation": {
155+
"type": 1,
156+
"schema": {
157+
"default.default": {
158+
"escCollection": "enxcol_.default.esc",
159+
"ecocCollection": "enxcol_.default.ecoc",
160+
"fields": [
161+
{
162+
"keyId": {
163+
"$binary": {
164+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
165+
"subType": "04"
166+
}
167+
},
168+
"path": "encryptedIndexed",
169+
"bsonType": "string",
170+
"queries": {
171+
"queryType": "equality",
172+
"contention": {
173+
"$numberLong": "0"
174+
}
175+
}
176+
},
177+
{
178+
"keyId": {
179+
"$binary": {
180+
"base64": "q83vqxI0mHYSNBI0VniQEg==",
181+
"subType": "04"
182+
}
183+
},
184+
"path": "encryptedUnindexed",
185+
"bsonType": "string"
186+
}
187+
]
188+
}
189+
}
190+
}
157191
},
158192
"command_name": "insert"
159193
}

src/libmongoc/tests/json/client_side_encryption/legacy/fle2v2-Compact.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"collection_name": "default",
1515
"data": [],
1616
"encrypted_fields": {
17-
"escCollection": "enxcol_.default.esc",
18-
"eccCollection": "enxcol_.default.ecc",
19-
"ecocCollection": "enxcol_.default.ecoc",
2017
"fields": [
2118
{
2219
"keyId": {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "6.0.0",
5+
"maxServerVersion": "6.3.99",
6+
"topology": [
7+
"replicaset",
8+
"sharded",
9+
"load-balanced"
10+
]
11+
}
12+
],
13+
"database_name": "default",
14+
"collection_name": "default",
15+
"tests": [
16+
{
17+
"description": "driver returns an error if creating a QEv2 collection on unsupported server",
18+
"clientOptions": {
19+
"autoEncryptOpts": {
20+
"kmsProviders": {
21+
"aws": {}
22+
},
23+
"encryptedFieldsMap": {
24+
"default.encryptedCollection": {
25+
"fields": [
26+
{
27+
"path": "firstName",
28+
"bsonType": "string",
29+
"keyId": {
30+
"$binary": {
31+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
32+
"subType": "04"
33+
}
34+
}
35+
}
36+
]
37+
}
38+
}
39+
}
40+
},
41+
"operations": [
42+
{
43+
"name": "dropCollection",
44+
"object": "database",
45+
"arguments": {
46+
"collection": "encryptedCollection"
47+
}
48+
},
49+
{
50+
"name": "createCollection",
51+
"object": "database",
52+
"arguments": {
53+
"collection": "encryptedCollection"
54+
},
55+
"result": {
56+
"errorContains": "Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption."
57+
}
58+
}
59+
]
60+
}
61+
]
62+
}

0 commit comments

Comments
 (0)