Skip to content

MONGOCRYPT-810 Extend _fle2_append_compactionTokens to append tokens … #1024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/mongocrypt-ctx-encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,15 +695,20 @@ static moe_result must_omit_encryptionInformation(const char *command_name,
// `compactStructuredEncryptionData` is a special case:
// - Server 7.0 prohibits `encryptionInformation`.
// - Server 8.0 requires `encryptionInformation` if "range" fields are referenced. Otherwise ignores.
// Only send `encryptionInformation` if "range" fields are present to support both server versions.
bool uses_range_fields = false;
// - Server 8.2 requires `encryptionInformation` if any range or text-search fields are referenced. Otherwise
// ignores.
// Only send `encryptionInformation` if range or text-search fields are present to support all server
// versions.
bool has_fields_requiring_ei = false;
for (const mc_EncryptedField_t *ef = efc->fields; ef != NULL; ef = ef->next) {
if (ef->supported_queries & SUPPORTS_RANGE_QUERIES) {
uses_range_fields = true;
if (ef->supported_queries
& (SUPPORTS_RANGE_QUERIES | SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_PREVIEW_QUERIES
| SUPPORTS_PREFIX_PREVIEW_QUERIES)) {
has_fields_requiring_ei = true;
break;
}
}
return (moe_result){.ok = true, .must_omit = !uses_range_fields};
return (moe_result){.ok = true, .must_omit = !has_fields_requiring_ei};
}

for (i = 0; i < sizeof(prohibited_commands) / sizeof(prohibited_commands[0]); i++) {
Expand Down Expand Up @@ -817,7 +822,9 @@ static bool _fle2_append_compactionTokens(mongocrypt_t *crypt,

const _mongocrypt_buffer_t *ecoct_buf = mc_ECOCToken_get(ecoct);

if ((ptr->supported_queries & SUPPORTS_RANGE_QUERIES)) {
if (ptr->supported_queries
& (SUPPORTS_RANGE_QUERIES | SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_PREVIEW_QUERIES
| SUPPORTS_PREFIX_PREVIEW_QUERIES)) {
// Append the document {ecoc: <ECOCToken>, anchorPaddingToken: <AnchorPaddingTokenRoot>}
esct = mc_ESCToken_new(crypto, cl1t, status);
if (!esct) {
Expand Down
1 change: 1 addition & 0 deletions test/data/cleanup/text-search/cmd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "cleanupStructuredEncryptionData": "test" }
100 changes: 100 additions & 0 deletions test/data/cleanup/text-search/collinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"name": "test",
"options": {
"encryptedFields": {
"escCollection": "esc",
"ecocCollection": "ecoc",
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encrypted",
"bsonType": "string",
"queries": {
"queryType": "equality",
"contention": 0
}
},
{
"keyId": {
"$binary": {
"base64": "q83vqxI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "nested.encrypted",
"bsonType": "string",
"queries": {
"queryType": "equality",
"contention": 0
}
},
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
"subType": "04"
}
},
"path": "nested.notindexed",
"bsonType": "string"
},
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
"subType": "04"
}
},
"path": "textField1",
"bsonType": "string",
"queries": {
"queryType": "substringPreview",
"contention": {
"$numberLong": "0"
},
"strMaxLength": 100,
"strMinQueryLength": 5,
"strMaxQueryLength": 20,
"caseSensitive": false,
"diacriticSensitive": true
}
},
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
"subType": "04"
}
},
"path": "textField2",
"bsonType": "string",
"queries": [{
"queryType": "suffixPreview",
"contention": {
"$numberLong": "0"
},
"strMinQueryLength": 1,
"strMaxQueryLength": 10,
"caseSensitive": true,
"diacriticSensitive": false
},
{
"queryType": "prefixPreview",
"contention": {
"$numberLong": "0"
},
"strMinQueryLength": 5,
"strMaxQueryLength": 15,
"caseSensitive": true,
"diacriticSensitive": false
}]
}
]
}
}
}
97 changes: 97 additions & 0 deletions test/data/cleanup/text-search/encrypted-field-config-map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"db.test": {
"escCollection": "esc",
"ecocCollection": "ecoc",
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encrypted",
"bsonType": "string",
"queries": {
"queryType": "equality",
"contention": 0
}
},
{
"keyId": {
"$binary": {
"base64": "q83vqxI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "nested.encrypted",
"bsonType": "string",
"queries": {
"queryType": "equality",
"contention": 0
}
},
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
"subType": "04"
}
},
"path": "nested.notindexed",
"bsonType": "string"
},
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
"subType": "04"
}
},
"path": "textField1",
"bsonType": "string",
"queries": {
"queryType": "substringPreview",
"contention": {
"$numberLong": "0"
},
"strMaxLength": 100,
"strMinQueryLength": 5,
"strMaxQueryLength": 20,
"caseSensitive": false,
"diacriticSensitive": true
}
},
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
"subType": "04"
}
},
"path": "textField2",
"bsonType": "string",
"queries": [{
"queryType": "suffixPreview",
"contention": {
"$numberLong": "0"
},
"strMinQueryLength": 1,
"strMaxQueryLength": 10,
"caseSensitive": true,
"diacriticSensitive": false
},
{
"queryType": "prefixPreview",
"contention": {
"$numberLong": "0"
},
"strMinQueryLength": 5,
"strMaxQueryLength": 15,
"caseSensitive": true,
"diacriticSensitive": false
}]
}
]
}
}
51 changes: 51 additions & 0 deletions test/data/cleanup/text-search/encrypted-payload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"cleanupStructuredEncryptionData": "test",
"cleanupTokens": {
"textField2": {
"ecoc": {
"$binary": {
"base64": "27J6DZqcjkRzZ3lWEsxH7CsQHr4CZirrGmuPS8ZkRO0=",
"subType": "00"
}
},
"anchorPaddingToken": {
"$binary": {
"base64": "hjezd/cwUfInCg0WjvFlzdn9/BQa8upEyogsU5pMWMU=",
"subType": "00"
}
}
},
"textField1": {
"ecoc": {
"$binary": {
"base64": "27J6DZqcjkRzZ3lWEsxH7CsQHr4CZirrGmuPS8ZkRO0=",
"subType": "00"
}
},
"anchorPaddingToken": {
"$binary": {
"base64": "hjezd/cwUfInCg0WjvFlzdn9/BQa8upEyogsU5pMWMU=",
"subType": "00"
}
}
},
"nested.notindexed": {
"$binary": {
"base64": "27J6DZqcjkRzZ3lWEsxH7CsQHr4CZirrGmuPS8ZkRO0=",
"subType": "00"
}
},
"nested.encrypted": {
"$binary": {
"base64": "SWO8WEoZ2r2Kx/muQKb7+COizy85nIIUFiHh4K9kcvA=",
"subType": "00"
}
},
"encrypted": {
"$binary": {
"base64": "noN+05JsuO1oDg59yypIGj45i+eFH6HOTXOPpeZ//Mk=",
"subType": "00"
}
}
}
}
Loading