Skip to content

CXX-2517 Add support for Range Explicit Encryption #955

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 17 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberLong": "1"
},
"min": {
"$date": {
"$numberLong": "0"
}
},
"max": {
"$date": {
"$numberLong": "200"
}
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedDecimalNoPrecision",
"bsonType": "decimal",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberInt": "1"
}
}
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedDecimalPrecision",
"bsonType": "decimal",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberInt": "1"
},
"min": {
"$numberDecimal": "0.0"
},
"max": {
"$numberDecimal": "200.0"
},
"precision": {
"$numberInt": "2"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedDoubleNoPrecision",
"bsonType": "double",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberLong": "1"
}
}
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedDoublePrecision",
"bsonType": "double",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberLong": "1"
},
"min": {
"$numberDouble": "0.0"
},
"max": {
"$numberDouble": "200.0"
},
"precision": {
"$numberInt": "2"
}
}
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedInt",
"bsonType": "int",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberLong": "1"
},
"min": {
"$numberInt": "0"
},
"max": {
"$numberInt": "200"
}
}
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedLong",
"bsonType": "long",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberLong": "1"
},
"min": {
"$numberLong": "0"
},
"max": {
"$numberLong": "200"
}
}
}
]
}

3 changes: 3 additions & 0 deletions src/mongocxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ set(mongocxx_sources
options/index_view.cpp
options/insert.cpp
options/pool.cpp
options/range.cpp
options/replace.cpp
options/rewrap_many_datakey.cpp
options/server_api.cpp
Expand Down Expand Up @@ -406,6 +407,8 @@ set_local_dist (src_mongocxx_DIST_local
options/private/server_api.hh
options/private/ssl.hh
options/private/transaction.hh
options/range.cpp
options/range.hpp
options/replace.cpp
options/replace.hpp
options/rewrap_many_datakey.cpp
Expand Down
5 changes: 5 additions & 0 deletions src/mongocxx/client_encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ bsoncxx::types::bson_value::value client_encryption::encrypt(bsoncxx::types::bso
return _impl->encrypt(value, opts);
}

bsoncxx::document::value client_encryption::encrypt_expression(
bsoncxx::document::view_or_value expr, const options::encrypt& opts) {
return _impl->encrypt_expression(expr, opts);
}

bsoncxx::types::bson_value::value client_encryption::decrypt(
bsoncxx::types::bson_value::view value) {
return _impl->decrypt(value);
Expand Down
16 changes: 16 additions & 0 deletions src/mongocxx/client_encryption.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ class MONGOCXX_API client_encryption {
bsoncxx::types::bson_value::value encrypt(bsoncxx::types::bson_value::view value,
const options::encrypt& opts);

///
/// Encrypts a Match Expression or Aggregate Expression to query a range index.
///
/// @note Only supported when queryType is "rangePreview" and algorithm is "RangePreview".
///
/// @param expr A BSON document corresponding to either a Match Expression or an Aggregate
/// Expression.
/// @param opts Options must be given in order to specify queryType and algorithm.
///
/// @returns The encrypted expression.
///
/// @warning The Range algorithm is experimental only. It is not intended for public use. It is
/// subject to breaking changes.
bsoncxx::document::value encrypt_expression(bsoncxx::document::view_or_value expr,
const options::encrypt& opts);

///
/// Decrypts an encrypted value (BSON binary of subtype 6).
///
Expand Down
24 changes: 12 additions & 12 deletions src/mongocxx/options/auto_encryption.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ class MONGOCXX_API auto_encryption {
/// an encryptedFields obtained from the server. It protects against a
/// malicious server advertising a false encryptedFields.
///
/// Queryable Encryption is in Public Technical Preview. Queryable Encryption should not be used
/// in production and is subject to backwards breaking changes.
///
/// @param encrypted_fields_map
/// The mapping of which fields to encrypt.
///
Expand All @@ -257,17 +254,20 @@ class MONGOCXX_API auto_encryption {
///
/// @see https://docs.mongodb.com/manual/core/security-client-side-encryption/
///
/// @warning Queryable Encryption is in Public Technical Preview. Queryable Encryption should
/// not be used in production and is subject to backwards breaking changes.
///
auto_encryption& encrypted_fields_map(bsoncxx::document::view_or_value encrypted_fields_map);

///
/// Get encrypted fields map
///
/// Queryable Encryption is in Public Technical Preview. Queryable Encryption should not be used
/// in production and is subject to backwards breaking changes.
///
/// @return
/// An optional document containing the encrypted fields map
///
/// @warning Queryable Encryption is in Public Technical Preview. Queryable Encryption should
/// not be used in production and is subject to backwards breaking changes.
///
const stdx::optional<bsoncxx::document::view_or_value>& encrypted_fields_map() const;

///
Expand Down Expand Up @@ -296,9 +296,6 @@ class MONGOCXX_API auto_encryption {
/// Query analysis is disabled when the 'bypassQueryAnalysis'
/// option is true. Default is 'false' (i.e. query analysis is enabled).
///
/// Queryable Encryption is in Public Technical Preview. Queryable Encryption should not be used
/// in production and is subject to backwards breaking changes.
///
/// @param should_bypass
/// Whether or not to bypass query analysis.
///
Expand All @@ -307,17 +304,20 @@ class MONGOCXX_API auto_encryption {
///
/// @see https://docs.mongodb.com/manual/core/security-client-side-encryption/
///
/// @warning Queryable Encryption is in Public Technical Preview. Queryable Encryption should
/// not be used in production and is subject to backwards breaking changes.
///
auto_encryption& bypass_query_analysis(bool should_bypass);

///
/// Gets a boolean specifying whether or not query analysis is bypassed.
///
/// Queryable Encryption is in Public Technical Preview. Queryable Encryption should not be used
/// in production and is subject to backwards breaking changes.
///
/// @return
/// A boolean specifying whether query analysis is bypassed.
///
/// @warning Queryable Encryption is in Public Technical Preview. Queryable Encryption should
/// not be used in production and is subject to backwards breaking changes.
///
bool bypass_query_analysis() const;

///
Expand Down
Loading