Skip to content

Commit 94b7abd

Browse files
authored
CXX-2517 Add support for Range Explicit Encryption (#955)
* Sync Range Explicit Encryption test files with c94fefe3 * Add support for ClientEncryption.encryptExpression() * Add support for RangeOpts * Add support for EncryptOpts.algorithm "RangePreview" * Add support for EncryptOpts.queryType "rangePreview" * Add support for EncryptOpts.rangeOpts * Add Range Explicit Encryption prose tests * Document Public Technical Preview notes as warnings * Replace fprintf with WARN in run_encryption_tests_in_file * Use is_open() to improve context in error message * Reorder options::encrypt member functions for consistency * Replace raw owning pointers with RAII helpers
1 parent 56717a4 commit 94b7abd

19 files changed

+1418
-233
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedDate",
11+
"bsonType": "date",
12+
"queries": {
13+
"queryType": "rangePreview",
14+
"sparsity": {
15+
"$numberLong": "1"
16+
},
17+
"min": {
18+
"$date": {
19+
"$numberLong": "0"
20+
}
21+
},
22+
"max": {
23+
"$date": {
24+
"$numberLong": "200"
25+
}
26+
}
27+
}
28+
}
29+
]
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedDecimalNoPrecision",
11+
"bsonType": "decimal",
12+
"queries": {
13+
"queryType": "rangePreview",
14+
"sparsity": {
15+
"$numberInt": "1"
16+
}
17+
}
18+
}
19+
]
20+
}
21+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedDecimalPrecision",
11+
"bsonType": "decimal",
12+
"queries": {
13+
"queryType": "rangePreview",
14+
"sparsity": {
15+
"$numberInt": "1"
16+
},
17+
"min": {
18+
"$numberDecimal": "0.0"
19+
},
20+
"max": {
21+
"$numberDecimal": "200.0"
22+
},
23+
"precision": {
24+
"$numberInt": "2"
25+
}
26+
}
27+
}
28+
]
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedDoubleNoPrecision",
11+
"bsonType": "double",
12+
"queries": {
13+
"queryType": "rangePreview",
14+
"sparsity": {
15+
"$numberLong": "1"
16+
}
17+
}
18+
}
19+
]
20+
}
21+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedDoublePrecision",
11+
"bsonType": "double",
12+
"queries": {
13+
"queryType": "rangePreview",
14+
"sparsity": {
15+
"$numberLong": "1"
16+
},
17+
"min": {
18+
"$numberDouble": "0.0"
19+
},
20+
"max": {
21+
"$numberDouble": "200.0"
22+
},
23+
"precision": {
24+
"$numberInt": "2"
25+
}
26+
}
27+
}
28+
]
29+
}
30+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedInt",
11+
"bsonType": "int",
12+
"queries": {
13+
"queryType": "rangePreview",
14+
"sparsity": {
15+
"$numberLong": "1"
16+
},
17+
"min": {
18+
"$numberInt": "0"
19+
},
20+
"max": {
21+
"$numberInt": "200"
22+
}
23+
}
24+
}
25+
]
26+
}
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encryptedLong",
11+
"bsonType": "long",
12+
"queries": {
13+
"queryType": "rangePreview",
14+
"sparsity": {
15+
"$numberLong": "1"
16+
},
17+
"min": {
18+
"$numberLong": "0"
19+
},
20+
"max": {
21+
"$numberLong": "200"
22+
}
23+
}
24+
}
25+
]
26+
}
27+

src/mongocxx/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ set(mongocxx_sources
155155
options/index_view.cpp
156156
options/insert.cpp
157157
options/pool.cpp
158+
options/range.cpp
158159
options/replace.cpp
159160
options/rewrap_many_datakey.cpp
160161
options/server_api.cpp
@@ -406,6 +407,8 @@ set_local_dist (src_mongocxx_DIST_local
406407
options/private/server_api.hh
407408
options/private/ssl.hh
408409
options/private/transaction.hh
410+
options/range.cpp
411+
options/range.hpp
409412
options/replace.cpp
410413
options/replace.hpp
411414
options/rewrap_many_datakey.cpp

src/mongocxx/client_encryption.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ bsoncxx::types::bson_value::value client_encryption::encrypt(bsoncxx::types::bso
4040
return _impl->encrypt(value, opts);
4141
}
4242

43+
bsoncxx::document::value client_encryption::encrypt_expression(
44+
bsoncxx::document::view_or_value expr, const options::encrypt& opts) {
45+
return _impl->encrypt_expression(expr, opts);
46+
}
47+
4348
bsoncxx::types::bson_value::value client_encryption::decrypt(
4449
bsoncxx::types::bson_value::view value) {
4550
return _impl->decrypt(value);

src/mongocxx/client_encryption.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ class MONGOCXX_API client_encryption {
101101
bsoncxx::types::bson_value::value encrypt(bsoncxx::types::bson_value::view value,
102102
const options::encrypt& opts);
103103

104+
///
105+
/// Encrypts a Match Expression or Aggregate Expression to query a range index.
106+
///
107+
/// @note Only supported when queryType is "rangePreview" and algorithm is "RangePreview".
108+
///
109+
/// @param expr A BSON document corresponding to either a Match Expression or an Aggregate
110+
/// Expression.
111+
/// @param opts Options must be given in order to specify queryType and algorithm.
112+
///
113+
/// @returns The encrypted expression.
114+
///
115+
/// @warning The Range algorithm is experimental only. It is not intended for public use. It is
116+
/// subject to breaking changes.
117+
bsoncxx::document::value encrypt_expression(bsoncxx::document::view_or_value expr,
118+
const options::encrypt& opts);
119+
104120
///
105121
/// Decrypts an encrypted value (BSON binary of subtype 6).
106122
///

src/mongocxx/options/auto_encryption.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@ class MONGOCXX_API auto_encryption {
244244
/// an encryptedFields obtained from the server. It protects against a
245245
/// malicious server advertising a false encryptedFields.
246246
///
247-
/// Queryable Encryption is in Public Technical Preview. Queryable Encryption should not be used
248-
/// in production and is subject to backwards breaking changes.
249-
///
250247
/// @param encrypted_fields_map
251248
/// The mapping of which fields to encrypt.
252249
///
@@ -257,17 +254,20 @@ class MONGOCXX_API auto_encryption {
257254
///
258255
/// @see https://docs.mongodb.com/manual/core/security-client-side-encryption/
259256
///
257+
/// @warning Queryable Encryption is in Public Technical Preview. Queryable Encryption should
258+
/// not be used in production and is subject to backwards breaking changes.
259+
///
260260
auto_encryption& encrypted_fields_map(bsoncxx::document::view_or_value encrypted_fields_map);
261261

262262
///
263263
/// Get encrypted fields map
264264
///
265-
/// Queryable Encryption is in Public Technical Preview. Queryable Encryption should not be used
266-
/// in production and is subject to backwards breaking changes.
267-
///
268265
/// @return
269266
/// An optional document containing the encrypted fields map
270267
///
268+
/// @warning Queryable Encryption is in Public Technical Preview. Queryable Encryption should
269+
/// not be used in production and is subject to backwards breaking changes.
270+
///
271271
const stdx::optional<bsoncxx::document::view_or_value>& encrypted_fields_map() const;
272272

273273
///
@@ -296,9 +296,6 @@ class MONGOCXX_API auto_encryption {
296296
/// Query analysis is disabled when the 'bypassQueryAnalysis'
297297
/// option is true. Default is 'false' (i.e. query analysis is enabled).
298298
///
299-
/// Queryable Encryption is in Public Technical Preview. Queryable Encryption should not be used
300-
/// in production and is subject to backwards breaking changes.
301-
///
302299
/// @param should_bypass
303300
/// Whether or not to bypass query analysis.
304301
///
@@ -307,17 +304,20 @@ class MONGOCXX_API auto_encryption {
307304
///
308305
/// @see https://docs.mongodb.com/manual/core/security-client-side-encryption/
309306
///
307+
/// @warning Queryable Encryption is in Public Technical Preview. Queryable Encryption should
308+
/// not be used in production and is subject to backwards breaking changes.
309+
///
310310
auto_encryption& bypass_query_analysis(bool should_bypass);
311311

312312
///
313313
/// Gets a boolean specifying whether or not query analysis is bypassed.
314314
///
315-
/// Queryable Encryption is in Public Technical Preview. Queryable Encryption should not be used
316-
/// in production and is subject to backwards breaking changes.
317-
///
318315
/// @return
319316
/// A boolean specifying whether query analysis is bypassed.
320317
///
318+
/// @warning Queryable Encryption is in Public Technical Preview. Queryable Encryption should
319+
/// not be used in production and is subject to backwards breaking changes.
320+
///
321321
bool bypass_query_analysis() const;
322322

323323
///

0 commit comments

Comments
 (0)