diff options
| author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2022-08-15 19:23:58 -0400 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-16 02:05:48 +0000 |
| commit | c71b4c28d3ab6eb4a651bc649c72189a5a31d3b3 (patch) | |
| tree | 50f6ea2cc8495a15675c57c55a61733101b55b51 /src/mongo/crypto | |
| parent | 35985c4d1f544eccc1281a74902f6888b1314f57 (diff) | |
| download | mongo-c71b4c28d3ab6eb4a651bc649c72189a5a31d3b3.tar.gz | |
SERVER-67753 Modify FLE2InsertUpdatePayload to support edges
Diffstat (limited to 'src/mongo/crypto')
| -rw-r--r-- | src/mongo/crypto/fle_crypto.cpp | 256 | ||||
| -rw-r--r-- | src/mongo/crypto/fle_crypto.h | 2 | ||||
| -rw-r--r-- | src/mongo/crypto/fle_crypto_test.cpp | 101 | ||||
| -rw-r--r-- | src/mongo/crypto/fle_field_schema.idl | 37 | ||||
| -rw-r--r-- | src/mongo/crypto/fle_fields_util.cpp | 28 |
5 files changed, 386 insertions, 38 deletions
diff --git a/src/mongo/crypto/fle_crypto.cpp b/src/mongo/crypto/fle_crypto.cpp index 7d90cf228e1..25777c04dca 100644 --- a/src/mongo/crypto/fle_crypto.cpp +++ b/src/mongo/crypto/fle_crypto.cpp @@ -621,6 +621,15 @@ public: FLEUserKeyAndId userKey, BSONElement element, uint64_t contentionFactor); + + + static FLE2InsertUpdatePayload serializeInsertUpdatePayloadForRange(FLEIndexKeyAndId indexKey, + FLEUserKeyAndId userKey, + BSONElement element, + BSONElement lowerBound, + BSONElement upperBound, + uint8_t sparsity, + uint64_t contentionFactor); }; @@ -683,6 +692,142 @@ FLE2InsertUpdatePayload EDCClientPayload::serializeInsertUpdatePayload(FLEIndexK return iupayload; } +// Note: Does not return the leaf node +std::vector<std::string> getEdges(BSONElement element, + BSONElement lowerBound, + BSONElement upperBound, + uint8_t sparsity) { + // TODO - SERVER-67751 + return {"1", "01", "001"}; +} + +std::vector<EdgeTokenSet> getEdgeTokenSet(BSONElement element, + BSONElement lowerBound, + BSONElement upperBound, + uint8_t sparsity, + uint64_t contentionFactor, + const EDCToken& edcToken, + const ESCToken& escToken, + const ECCToken& eccToken, + const ECOCToken& ecocToken) { + auto edges = getEdges(element, lowerBound, upperBound, sparsity); + + std::vector<EdgeTokenSet> tokens; + + for (const auto& edge : edges) { + ConstDataRange cdr(edge.data(), edge.size()); + + EDCDerivedFromDataToken edcDatakey = + FLEDerivedFromDataTokenGenerator::generateEDCDerivedFromDataToken(edcToken, cdr); + ESCDerivedFromDataToken escDatakey = + FLEDerivedFromDataTokenGenerator::generateESCDerivedFromDataToken(escToken, cdr); + ECCDerivedFromDataToken eccDatakey = + FLEDerivedFromDataTokenGenerator::generateECCDerivedFromDataToken(eccToken, cdr); + + EDCDerivedFromDataTokenAndContentionFactorToken edcDataCounterkey = + FLEDerivedFromDataTokenAndContentionFactorTokenGenerator:: + generateEDCDerivedFromDataTokenAndContentionFactorToken(edcDatakey, + contentionFactor); + ESCDerivedFromDataTokenAndContentionFactorToken escDataCounterkey = + FLEDerivedFromDataTokenAndContentionFactorTokenGenerator:: + generateESCDerivedFromDataTokenAndContentionFactorToken(escDatakey, + contentionFactor); + ECCDerivedFromDataTokenAndContentionFactorToken eccDataCounterkey = + FLEDerivedFromDataTokenAndContentionFactorTokenGenerator:: + generateECCDerivedFromDataTokenAndContentionFactorToken(eccDatakey, + contentionFactor); + + EdgeTokenSet ets; + + ets.setEdcDerivedToken(edcDataCounterkey.toCDR()); + ets.setEscDerivedToken(escDataCounterkey.toCDR()); + ets.setEccDerivedToken(eccDataCounterkey.toCDR()); + + auto swEncryptedTokens = + EncryptedStateCollectionTokens(escDataCounterkey, eccDataCounterkey) + .serialize(ecocToken); + uassertStatusOK(swEncryptedTokens); + ets.setEncryptedTokens(swEncryptedTokens.getValue()); + + tokens.push_back(ets); + } + + return tokens; +} + + +FLE2InsertUpdatePayload EDCClientPayload::serializeInsertUpdatePayloadForRange( + FLEIndexKeyAndId indexKey, + FLEUserKeyAndId userKey, + BSONElement element, + BSONElement lowerBound, + BSONElement upperBound, + uint8_t sparsity, + uint64_t contentionFactor) { + auto value = ConstDataRange(element.value(), element.value() + element.valuesize()); + + auto collectionToken = FLELevel1TokenGenerator::generateCollectionsLevel1Token(indexKey.key); + auto serverEncryptToken = + FLELevel1TokenGenerator::generateServerDataEncryptionLevel1Token(indexKey.key); + auto edcToken = FLECollectionTokenGenerator::generateEDCToken(collectionToken); + auto escToken = FLECollectionTokenGenerator::generateESCToken(collectionToken); + auto eccToken = FLECollectionTokenGenerator::generateECCToken(collectionToken); + auto ecocToken = FLECollectionTokenGenerator::generateECOCToken(collectionToken); + + + EDCDerivedFromDataToken edcDatakey = + FLEDerivedFromDataTokenGenerator::generateEDCDerivedFromDataToken(edcToken, value); + ESCDerivedFromDataToken escDatakey = + FLEDerivedFromDataTokenGenerator::generateESCDerivedFromDataToken(escToken, value); + ECCDerivedFromDataToken eccDatakey = + FLEDerivedFromDataTokenGenerator::generateECCDerivedFromDataToken(eccToken, value); + + EDCDerivedFromDataTokenAndContentionFactorToken edcDataCounterkey = + FLEDerivedFromDataTokenAndContentionFactorTokenGenerator:: + generateEDCDerivedFromDataTokenAndContentionFactorToken(edcDatakey, contentionFactor); + ESCDerivedFromDataTokenAndContentionFactorToken escDataCounterkey = + FLEDerivedFromDataTokenAndContentionFactorTokenGenerator:: + generateESCDerivedFromDataTokenAndContentionFactorToken(escDatakey, contentionFactor); + ECCDerivedFromDataTokenAndContentionFactorToken eccDataCounterkey = + FLEDerivedFromDataTokenAndContentionFactorTokenGenerator:: + generateECCDerivedFromDataTokenAndContentionFactorToken(eccDatakey, contentionFactor); + + FLE2InsertUpdatePayload iupayload; + + iupayload.setEdcDerivedToken(edcDataCounterkey.toCDR()); + iupayload.setEscDerivedToken(escDataCounterkey.toCDR()); + iupayload.setEccDerivedToken(eccDataCounterkey.toCDR()); + iupayload.setServerEncryptionToken(serverEncryptToken.toCDR()); + + auto swEncryptedTokens = + EncryptedStateCollectionTokens(escDataCounterkey, eccDataCounterkey).serialize(ecocToken); + uassertStatusOK(swEncryptedTokens); + iupayload.setEncryptedTokens(swEncryptedTokens.getValue()); + + auto swCipherText = KeyIdAndValue::serialize(userKey, value); + uassertStatusOK(swCipherText); + iupayload.setValue(swCipherText.getValue()); + iupayload.setType(element.type()); + + iupayload.setIndexKeyId(indexKey.keyId); + + auto edgeTokenSet = getEdgeTokenSet(element, + lowerBound, + upperBound, + sparsity, + contentionFactor, + edcToken, + escToken, + eccToken, + ecocToken); + + if (!edgeTokenSet.empty()) { + iupayload.setEdgeTokenSet(edgeTokenSet); + } + + return iupayload; +} + /** * Lightweight class to build a singly linked list of field names to represent the current field * name @@ -883,7 +1028,7 @@ void convertToFLE2Payload(FLEKeyVault* keyVault, if (ep.getAlgorithm() == Fle2AlgorithmInt::kEquality) { uassert(6338602, str::stream() << "Type '" << typeName(el.type()) - << "' is not a valid type for Queryable Encryption", + << "' is not a valid type for Queryable Encryption Equality", isFLE2EqualityIndexedSupportedType(el.type())); if (ep.getType() == Fle2PlaceholderType::kInsert) { @@ -903,8 +1048,38 @@ void convertToFLE2Payload(FLEKeyVault* keyVault, findpayload, builder); } else { - uasserted(6410100, - "No other Queryable Encryption placeholders supported at this time."); + uasserted(6410100, "Unsupported Queryable Encryption placeholder type"); + } + } else if (ep.getAlgorithm() == Fle2AlgorithmInt::kRange) { + + if (ep.getType() == Fle2PlaceholderType::kInsert) { + IDLParserContext ctx("root"); + auto rangeInsertSpec = + FLE2RangeInsertSpec::parse(ctx, ep.getValue().getElement().Obj()); + + auto elRange = rangeInsertSpec.getValue().getElement(); + + uassert(6775301, + str::stream() << "Type '" << typeName(elRange.type()) + << "' is not a valid type for Queryable Encryption Range", + isFLE2RangeIndexedSupportedType(elRange.type())); + + + auto iupayload = EDCClientPayload::serializeInsertUpdatePayloadForRange( + indexKey, + userKey, + rangeInsertSpec.getValue().getElement(), + rangeInsertSpec.getLowerBound().getElement(), + rangeInsertSpec.getUpperBound().getElement(), + rangeInsertSpec.getSparsity(), + contentionFactor(ep)); + + toEncryptedBinData(fieldNameToSerialize, + EncryptedBinDataType::kFLE2InsertUpdatePayload, + iupayload, + builder); + } else { + uasserted(6775303, "Unsupported Queryable Encryption placeholder type"); } } else if (ep.getAlgorithm() == Fle2AlgorithmInt::kUnindexed) { uassert(6379102, @@ -934,13 +1109,23 @@ void parseAndVerifyInsertUpdatePayload(std::vector<EDCServerPayloadInfo>* pField ConstDataRange subCdr) { auto iupayload = EDCClientPayload::parseInsertUpdatePayload(subCdr); - uassert(6373504, - str::stream() << "Type '" << typeName(static_cast<BSONType>(iupayload.getType())) - << "' is not a valid type for Queryable Encryption", - isValidBSONType(iupayload.getType()) && - isFLE2EqualityIndexedSupportedType(static_cast<BSONType>(iupayload.getType()))); + bool isRangePayload = iupayload.getEdgeTokenSet().has_value(); - pFields->push_back({std::move(iupayload), fieldPath.toString(), 0}); + if (isRangePayload) { + uassert(6775305, + str::stream() << "Type '" << typeName(static_cast<BSONType>(iupayload.getType())) + << "' is not a valid type for Queryable Encryption Range", + isValidBSONType(iupayload.getType()) && + isFLE2RangeIndexedSupportedType(static_cast<BSONType>(iupayload.getType()))); + } else { + uassert(6373504, + str::stream() << "Type '" << typeName(static_cast<BSONType>(iupayload.getType())) + << "' is not a valid type for Queryable Encryption Equality", + isValidBSONType(iupayload.getType()) && + isFLE2EqualityIndexedSupportedType(static_cast<BSONType>(iupayload.getType()))); + } + + pFields->push_back({std::move(iupayload), fieldPath.toString(), {}}); } void collectEDCServerInfo(std::vector<EDCServerPayloadInfo>* pFields, @@ -999,12 +1184,38 @@ void convertServerPayload(ConstDataRange cdr, auto payload = *(it.it); // TODO - validate field is actually indexed in the schema? + if (payload.payload.getEdgeTokenSet().has_value()) { + FLE2IndexedRangeEncryptedValue sp(payload.payload, payload.counts); + + uassert(6775311, + str::stream() << "Type '" << typeName(sp.bsonType) + << "' is not a valid type for Queryable Encryption Range", + isFLE2RangeIndexedSupportedType(sp.bsonType)); + + auto swEncrypted = + sp.serialize(FLETokenFromCDR<FLETokenType::ServerDataEncryptionLevel1Token>( + payload.payload.getServerEncryptionToken())); + uassertStatusOK(swEncrypted); + toEncryptedBinData(fieldPath, + EncryptedBinDataType::kFLE2RangeIndexedValue, + ConstDataRange(swEncrypted.getValue()), + builder); + + auto tagsRange = EDCServerCollection::generateTags(sp); + for (const auto& tag : tagsRange) { + pTags->push_back({tag}); + } + + return; + } + + dassert(payload.counts.size() == 1); - FLE2IndexedEqualityEncryptedValue sp(payload.payload, payload.count); + FLE2IndexedEqualityEncryptedValue sp(payload.payload, payload.counts[0]); uassert(6373506, str::stream() << "Type '" << typeName(sp.bsonType) - << "' is not a valid type for Queryable Encryption", + << "' is not a valid type for Queryable Encryption Equality", isFLE2EqualityIndexedSupportedType(sp.bsonType)); auto swEncrypted = @@ -2117,9 +2328,8 @@ FLE2IndexedRangeEncryptedValue::FLE2IndexedRangeEncryptedValue(FLE2InsertUpdateP uassert(6775312, "Invalid BSON Type in Queryable Encryption InsertUpdatePayload", isValidBSONType(payload.getType())); - // TODO SERVER-67755 - enable assertion when insert works - // uassert( - // 6775313, "Mismatch between tokens and counters count", tokens.size() == counters.size()); + uassert( + 6775313, "Mismatch between tokens and counters count", tokens.size() == counters.size()); } FLE2IndexedRangeEncryptedValue::FLE2IndexedRangeEncryptedValue( @@ -2133,9 +2343,8 @@ FLE2IndexedRangeEncryptedValue::FLE2IndexedRangeEncryptedValue( bsonType(typeParam), indexKeyId(indexKeyIdParam), clientEncryptedValue(clientEncryptedValueParam) { - // TODO SERVER-67755 - enable assertion when insert works - // uassert( - // 6775314, "Mismatch between tokens and counters count", tokens.size() == counters.size()); + uassert( + 6775314, "Mismatch between tokens and counters count", tokens.size() == counters.size()); } StatusWith<UUID> FLE2IndexedRangeEncryptedValue::readKeyId(ConstDataRange serializedServerValue) { @@ -2270,11 +2479,10 @@ StatusWith<std::vector<uint8_t>> FLE2IndexedRangeEncryptedValue::serialize( builder.appendNum(LittleEndian<uint64_t>(counters[c++])); } - // TODO SERVER-67755 - enable assertion when insert works - // dassert(builder.len() == - // static_cast<int>(clientEncryptedValue.size() + sizeof(uint64_t) * 1 + - // sizeof(uint64_t) * counters.size() + sizeof(uint32_t) + - // sizeof(PrfBlock) * 3 * tokens.size())); + dassert(builder.len() == + static_cast<int>(clientEncryptedValue.size() + sizeof(uint64_t) * 1 + + sizeof(uint64_t) * counters.size() + sizeof(uint32_t) + + sizeof(PrfBlock) * 3 * tokens.size())); auto swEncryptedData = encryptData(token.toCDR(), ConstDataRange(builder.buf(), builder.len())); if (!swEncryptedData.isOK()) { @@ -2358,7 +2566,9 @@ PrfBlock EDCServerCollection::generateTag(const EDCServerPayloadInfo& payload) { auto token = FLETokenFromCDR<FLETokenType::EDCDerivedFromDataTokenAndContentionFactorToken>( payload.payload.getEdcDerivedToken()); auto edcTwiceDerived = FLETwiceDerivedTokenGenerator::generateEDCTwiceDerivedToken(token); - return generateTag(edcTwiceDerived, payload.count); + dassert(payload.payload.getEdgeTokenSet().has_value() == false); + dassert(payload.counts.size() == 1); + return generateTag(edcTwiceDerived, payload.counts[0]); } PrfBlock EDCServerCollection::generateTag(const FLE2IndexedEqualityEncryptedValue& indexedValue) { diff --git a/src/mongo/crypto/fle_crypto.h b/src/mongo/crypto/fle_crypto.h index e979f98d76e..ab674c18aa0 100644 --- a/src/mongo/crypto/fle_crypto.h +++ b/src/mongo/crypto/fle_crypto.h @@ -1030,7 +1030,7 @@ struct EDCServerPayloadInfo { FLE2InsertUpdatePayload payload; std::string fieldPathName; - uint64_t count; + std::vector<uint64_t> counts; }; struct EDCIndexedFields { diff --git a/src/mongo/crypto/fle_crypto_test.cpp b/src/mongo/crypto/fle_crypto_test.cpp index 22726b03662..f74f29cc221 100644 --- a/src/mongo/crypto/fle_crypto_test.cpp +++ b/src/mongo/crypto/fle_crypto_test.cpp @@ -696,7 +696,7 @@ enum class Operation { kFind, kInsert }; std::vector<char> generatePlaceholder( BSONElement value, Operation operation, - mongo::Fle2AlgorithmInt algorithm = mongo::Fle2AlgorithmInt::kEquality, + mongo::Fle2AlgorithmInt algorithm = Fle2AlgorithmInt::kEquality, boost::optional<UUID> key = boost::none, uint64_t contention = 0) { FLE2EncryptionPlaceholder ep; @@ -710,9 +710,27 @@ std::vector<char> generatePlaceholder( ep.setAlgorithm(algorithm); ep.setUserKeyId(userKeyId); ep.setIndexKeyId(key.value_or(indexKeyId)); - ep.setValue(value); + + FLE2RangeInsertSpec insertSpec; + // Set a default lower and upper bound + auto lowerDoc = BSON("lb" << 0); + insertSpec.setLowerBound(lowerDoc.firstElement()); + auto upperDoc = BSON("ub" << 1234567890123456789LL); + + insertSpec.setUpperBound(upperDoc.firstElement()); + insertSpec.setValue(value); + insertSpec.setSparsity(0); + auto specDoc = BSON("s" << insertSpec.toBSON()); + + if (algorithm == Fle2AlgorithmInt::kRange) { + ep.setValue(IDLAnyType(specDoc.firstElement())); + ep.setSparsity(0); + } else { + ep.setValue(value); + } ep.setMaxContentionCounter(contention); + BSONObj obj = ep.toBSON(); std::vector<char> v; @@ -735,7 +753,13 @@ BSONObj encryptDocument(BSONObj obj, auto serverPayload = EDCServerCollection::getEncryptedFieldInfo(result); for (auto& payload : serverPayload) { - payload.count = 1; + if (payload.payload.getEdgeTokenSet().has_value()) { + for (size_t i = 0; i < payload.payload.getEdgeTokenSet()->size(); i++) { + payload.counts.push_back(1); + } + } + + payload.counts.push_back(1); } // Finalize document for insert @@ -925,6 +949,28 @@ TEST(FLE_EDC, Allowed_Types) { } } +TEST(FLE_EDC, Range_Allowed_Types) { + + const std::vector<std::pair<BSONObj, BSONType>> rangeAllowedObjects{ + {BSON("sample" << 123.456), NumberDouble}, + {BSON("sample" << Decimal128()), NumberDecimal}, + {BSON("sample" << 123456), NumberInt}, + {BSON("sample" << 12345678901234567LL), NumberLong}, + {BSON("sample" << Date_t::fromMillisSinceEpoch(12345)), Date}, + }; + + std::vector<Operation> opTypes{ + Operation::kInsert + // TODO - ,Operation::kFind + }; + + for (const auto& opType : opTypes) { + for (const auto& [obj, objType] : rangeAllowedObjects) { + roundTripTest(obj, objType, opType, Fle2AlgorithmInt::kRange); + } + }; +} + void illegalBSONType(BSONObj doc, BSONType type, Fle2AlgorithmInt algorithm, int expectCode) { auto element = doc.firstElement(); ASSERT_EQ(element.type(), type); @@ -971,6 +1017,46 @@ TEST(FLE_EDC, Disallowed_Types) { illegalBSONType(BSON("sample" << MAXKEY), MaxKey, Fle2AlgorithmInt::kUnindexed); } +void illegalRangeBSONType(BSONObj doc, BSONType type) { + illegalBSONType(doc, type, Fle2AlgorithmInt::kRange, ErrorCodes::TypeMismatch); +} + +TEST(FLE_EDC, Range_Disallowed_Types) { + + const std::vector<std::pair<BSONObj, BSONType>> disallowedObjects{ + {BSON("sample" + << "value123"), + String}, + {BSON("sample" << BSONBinData( + testValue.data(), testValue.size(), BinDataType::BinDataGeneral)), + BinData}, + {BSON("sample" << OID()), jstOID}, + {BSON("sample" << false), Bool}, + {BSON("sample" << true), Bool}, + {BSON("sample" << BSONRegEx("value1", "value2")), RegEx}, + {BSON("sample" << Timestamp()), bsonTimestamp}, + {BSON("sample" << BSONCode("value")), Code}, + {BSON("sample" << BSON("nested" + << "value")), + Object}, + {BSON("sample" << BSON_ARRAY(1 << 23)), Array}, + {BSON("sample" << BSONDBRef("value1", OID())), DBRef}, + {BSON("sample" << BSONSymbol("value")), Symbol}, + {BSON("sample" << BSONCodeWScope("value", + BSON("code" + << "something"))), + CodeWScope}, + {BSON("sample" << MINKEY), MinKey}, + {BSON("sample" << MAXKEY), MaxKey}, + }; + + for (const auto& typePair : disallowedObjects) { + illegalRangeBSONType(typePair.first, typePair.second); + } + + illegalBSONType(BSON("sample" << BSONNULL), jstNULL, Fle2AlgorithmInt::kRange, 40414); + illegalBSONType(BSON("sample" << BSONUndefined), Undefined, Fle2AlgorithmInt::kRange, 40414); +} BSONObj transformBSON( const BSONObj& object, @@ -1097,7 +1183,6 @@ TEST(FLE_EDC, Disallowed_Types_FLE2InsertUpdatePayload) { disallowedEqualityPayloadType(static_cast<BSONType>(fakeBSONType)); } - TEST(FLE_EDC, ServerSide_Payloads) { TestKeyVault keyVault; @@ -1803,7 +1888,13 @@ BSONObj encryptUpdateDocument(BSONObj obj, FLEKeyVault* keyVault) { auto serverPayload = EDCServerCollection::getEncryptedFieldInfo(result); for (auto& payload : serverPayload) { - payload.count = 1; + if (payload.payload.getEdgeTokenSet().has_value()) { + for (size_t i = 0; i < payload.payload.getEdgeTokenSet()->size(); i++) { + payload.counts.push_back(1); + } + } + + payload.counts.push_back(1); } return EDCServerCollection::finalizeForUpdate(result, serverPayload); diff --git a/src/mongo/crypto/fle_field_schema.idl b/src/mongo/crypto/fle_field_schema.idl index 1711c3b715a..45dde587d52 100644 --- a/src/mongo/crypto/fle_field_schema.idl +++ b/src/mongo/crypto/fle_field_schema.idl @@ -91,6 +91,19 @@ enums: kInsert: 1 kFind: 2 +types: + encrypted_numeric_element: + bson_serialization_type: + - date + - decimal + - double + - int + - long + description: A value with any encrypted range numeric BSON type. + cpp_type: "mongo::IDLAnyType" + serializer: mongo::IDLAnyType::serializeToBSON + deserializer: mongo::IDLAnyType::parseFromBSON + structs: EncryptionPlaceholder: description: "Implements Encryption BinData (subtype 6) sub-subtype 0, the intent-to-encrypt @@ -297,7 +310,7 @@ structs: type: bindata_generic FLE2RangeSpec: - description: "Range specification that is encoded inside of a FLE2EncryptionPlaceholder." + description: "Range find specification that is encoded inside of a FLE2EncryptionPlaceholder." strict: true cpp_validator_func: "validateIDLFLE2RangeSpec" fields: @@ -313,3 +326,25 @@ structs: maxIncluded: description: "Indicates if the upper bound should be included in the range." type: bool + + FLE2RangeInsertSpec: + description: "Range insert specification that is encoded inside of a FLE2EncryptionPlaceholder." + strict: true + fields: + v: + description: "Value to encrypt" + type: encrypted_numeric_element + cpp_name: value + lb: + description: "Queryable Encryption lower bound for range" + type: encrypted_numeric_element + cpp_name: lowerBound + ub: + description: "Queryable Encryption upper bound for range" + type: encrypted_numeric_element + cpp_name: upperBound + s: + description: "Lower value - higher storage overhead, faster query." + type: exactInt64 + cpp_name: sparsity + validator: { gte: 0, lte: 3 } diff --git a/src/mongo/crypto/fle_fields_util.cpp b/src/mongo/crypto/fle_fields_util.cpp index bfe32f9fe67..6a8366db747 100644 --- a/src/mongo/crypto/fle_fields_util.cpp +++ b/src/mongo/crypto/fle_fields_util.cpp @@ -27,7 +27,8 @@ * it in the license file. */ -#include "fle_fields_util.h" +#include "mongo/crypto/fle_fields_util.h" + #include "mongo/bson/bsonelement.h" #include "mongo/bson/bsontypes.h" #include "mongo/crypto/fle_field_schema_gen.h" @@ -36,19 +37,30 @@ namespace mongo { void validateIDLFLE2EncryptionPlaceholder(const FLE2EncryptionPlaceholder* placeholder) { if (placeholder->getAlgorithm() == Fle2AlgorithmInt::kRange) { - auto val = placeholder->getValue().getElement(); - uassert(6720200, "Range placeholder value must be an object.", val.isABSONObj()); - auto obj = val.Obj(); - FLE2RangeSpec::parse(IDLParserContext("v"), obj); - uassert(6832501, - "Sparsity must be defined for range placeholders.", - placeholder->getSparsity()); + if (placeholder->getType() == Fle2PlaceholderType::kFind) { + auto val = placeholder->getValue().getElement(); + uassert(6720200, "Range Find placeholder value must be an object.", val.isABSONObj()); + auto obj = val.Obj(); + FLE2RangeSpec::parse(IDLParserContext("v"), obj); + uassert(6832501, + "Sparsity must be defined for range placeholders.", + placeholder->getSparsity()); + } else if (placeholder->getType() == Fle2PlaceholderType::kInsert) { + auto val = placeholder->getValue().getElement(); + uassert(6775321, "Range Insert placeholder value must be an object.", val.isABSONObj()); + auto obj = val.Obj(); + FLE2RangeInsertSpec::parse(IDLParserContext("v"), obj); + uassert(6775322, + "Sparsity must be defined for range placeholders.", + placeholder->getSparsity()); + } } else { uassert(6832500, "Hypergraph sparsity can only be set for range placeholders.", !placeholder->getSparsity()); } } + void validateIDLFLE2RangeSpec(const FLE2RangeSpec* placeholder) { auto min = placeholder->getMin().getElement(); auto max = placeholder->getMax().getElement(); |
