Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions .evergreen/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ mkdir cmake-build
cd cmake-build

for suffix in "dll" "dylib" "so"; do
if test -f "mongo_csfle_v1.$suffix"; then
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DMONGOCRYPT_TESTING_CSFLE_FILE=$PWD/mongo_csfle_v1.$suffix"
if test -f "mongo_crypt_v1.$suffix"; then
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DMONGOCRYPT_TESTING_CRYPT_SHARED_FILE=$PWD/mongo_crypt_v1.$suffix"
fi
done

Expand Down
36 changes: 18 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,39 +327,39 @@ if (BUILD_TESTING)
PREFIX ""
)

# Create two stubbed csfle libraries
add_library (stubbed-csfle SHARED test/csfle-stub.cpp)
add_library (stubbed-csfle-2 SHARED test/csfle-stub.cpp)
# Create two stubbed crypt_shared libraries
add_library (stubbed-crypt_shared SHARED test/crypt_shared-stub.cpp)
add_library (stubbed-crypt_shared-2 SHARED test/crypt_shared-stub.cpp)

set_target_properties(stubbed-csfle stubbed-csfle-2 PROPERTIES
set_target_properties(stubbed-crypt_shared stubbed-crypt_shared-2 PROPERTIES
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/src"
LINK_LIBRARIES "mongo::bson_static"
COMPILE_FEATURES cxx_std_11
PREFIX ""
)

set_target_properties(stubbed-csfle-2 PROPERTIES SUFFIX ".dll")
set_target_properties(stubbed-crypt_shared-2 PROPERTIES SUFFIX ".dll")

if (MONGOCRYPT_TESTING_CSFLE_FILE)
if (MONGOCRYPT_TESTING_CRYPT_SHARED_FILE)
# Generate a target that copies the CSFLE library into the binary directory of test-mongocrypt
set (stamp "${CMAKE_CURRENT_BINARY_DIR}/mongo_csfle_v1.copied.$<CONFIG>.stamp")
set (stamp "${CMAKE_CURRENT_BINARY_DIR}/mongo_crypt_v1.copied.$<CONFIG>.stamp")
add_custom_command (
OUTPUT "${stamp}"
COMMAND "${CMAKE_COMMAND}" -E copy
"${MONGOCRYPT_TESTING_CSFLE_FILE}"
"$<TARGET_FILE_DIR:test-mongocrypt>/mongo_csfle_v1${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${MONGOCRYPT_TESTING_CRYPT_SHARED_FILE}"
"$<TARGET_FILE_DIR:test-mongocrypt>/mongo_crypt_v1${CMAKE_SHARED_LIBRARY_SUFFIX}"
COMMAND "${CMAKE_COMMAND}" -E touch "${stamp}"
DEPENDS "${MONGOCRYPT_TESTING_CSFLE_FILE}"
COMMENT "Getting mongo_csfle library"
DEPENDS "${MONGOCRYPT_TESTING_CRYPT_SHARED_FILE}"
COMMENT "Getting mongo_crypt library"
)
add_custom_target (copy-csfle ALL DEPENDS "${stamp}")
add_custom_target (copy-crypt_shared ALL DEPENDS "${stamp}")
else ()
# The first stubbed csfle library will take the place of the actual csfle for testing
message (STATUS "Generating a stubbed csfle dynamic library for use in testing.")
message (STATUS "Provide a MONGOCRYPT_TESTING_CSFLE_FILE=<filepath> to provide a csfle for use in testing")
set_target_properties (stubbed-csfle PROPERTIES
# The first stubbed crypt_shared library will take the place of the actual crypt_shared for testing
message (STATUS "Generating a stubbed crypt_shared dynamic library for use in testing.")
message (STATUS "Provide a MONGOCRYPT_TESTING_CRYPT_SHARED_FILE=<filepath> to provide a crypt_shared for use in testing")
set_target_properties (stubbed-crypt_shared PROPERTIES
# Normalize the output name expected by libmongocrypt
OUTPUT_NAME "mongo_csfle_v1"
OUTPUT_NAME "mongo_crypt_v1"
)
endif ()
endif ()
Expand Down Expand Up @@ -415,7 +415,7 @@ target_compile_definitions (test-mongocrypt PRIVATE
# Set a definition so that testcases can know where test-mongocrypt.exe was written to
"TEST_MONGOCRYPT_OUTPUT_PATH=\"$<TARGET_FILE:test-mongocrypt>\""
# Tell test-mongocrypt whether we have a real csfle library for testing
TEST_MONGOCRYPT_HAVE_REAL_CSFLE=$<BOOL:${MONGOCRYPT_TESTING_CSFLE_FILE}>
TEST_MONGOCRYPT_HAVE_REAL_CRYPT_SHARED_LIB=$<BOOL:${MONGOCRYPT_TESTING_CRYPT_SHARED_FILE}>
)

add_test (
Expand Down
31 changes: 18 additions & 13 deletions bindings/node/lib/autoEncrypter.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,39 @@ module.exports = function (modules) {
mongoCryptOptions.logger = options.logger;
}

if (options.extraOptions && options.extraOptions.csflePath) {
mongoCryptOptions.csflePath = options.extraOptions.csflePath;
if (options.extraOptions && options.extraOptions.cryptSharedLibPath) {
mongoCryptOptions.cryptSharedLibPath = options.extraOptions.cryptSharedLibPath;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing this as well! 💙

@nbbeeken @durran @dariakp @baileympearson Heads up that this is a breaking change from 2.1.0 – that should be okay on our side, and I don’t think the team really announced shared library support, so I’d be okay with not introducing aliases here.

I’ve opened mongodb/node-mongodb-native#3280 to adjust the typings.

}

if (options.bypassQueryAnalysis) {
mongoCryptOptions.bypassQueryAnalysis = options.bypassQueryAnalysis;
}

this._bypassMongocryptdAndCSFLE = this._bypassEncryption || options.bypassQueryAnalysis;
this._bypassMongocryptdAndCryptShared = this._bypassEncryption || options.bypassQueryAnalysis;

if (options.extraOptions && options.extraOptions.csfleSearchPaths) {
if (options.extraOptions && options.extraOptions.cryptSharedLibSearchPaths) {
// Only for driver testing
mongoCryptOptions.csfleSearchPaths = options.extraOptions.csfleSearchPaths;
} else if (!this._bypassMongocryptdAndCSFLE) {
mongoCryptOptions.csfleSearchPaths = ['$SYSTEM'];
mongoCryptOptions.cryptSharedLibSearchPaths =
options.extraOptions.cryptSharedLibSearchPaths;
} else if (!this._bypassMongocryptdAndCryptShared) {
mongoCryptOptions.cryptSharedLibSearchPaths = ['$SYSTEM'];
}

Object.assign(mongoCryptOptions, { cryptoCallbacks });
this._mongocrypt = new mc.MongoCrypt(mongoCryptOptions);
this._contextCounter = 0;

if (options.extraOptions && options.extraOptions.csfleRequired && !this.csfleVersionInfo) {
throw new MongoError('`csfleRequired` set but no csfle shared library loaded');
if (
options.extraOptions &&
options.extraOptions.cryptSharedLibRequired &&
!this.cryptSharedLibVersionInfo
) {
throw new MongoError('`cryptSharedLibRequired` set but no crypt_shared library loaded');
}

// Only instantiate mongocryptd manager/client once we know for sure
// that we are not using the CSFLE shared library.
if (!this._bypassMongocryptdAndCSFLE && !this.csfleVersionInfo) {
if (!this._bypassMongocryptdAndCryptShared && !this.cryptSharedLibVersionInfo) {
this._mongocryptdManager = new MongocryptdManager(options.extraOptions);
this._mongocryptdClient = new MongoClient(this._mongocryptdManager.uri, {
useNewUrlParser: true,
Expand All @@ -168,7 +173,7 @@ module.exports = function (modules) {
* @param {Function} callback Invoked when the mongocryptd client either successfully connects or errors
*/
init(callback) {
if (this._bypassMongocryptdAndCSFLE || this.csfleVersionInfo) {
if (this._bypassMongocryptdAndCryptShared || this.cryptSharedLibVersionInfo) {
return callback();
}
const _callback = (err, res) => {
Expand Down Expand Up @@ -323,8 +328,8 @@ module.exports = function (modules) {
* as `{ version: bigint, versionStr: string }`, or `null` if no CSFLE
* shared library was loaded.
*/
get csfleVersionInfo() {
return this._mongocrypt.csfleVersionInfo;
get cryptSharedLibVersionInfo() {
return this._mongocrypt.cryptSharedLibVersionInfo;
}
}

Expand Down
22 changes: 11 additions & 11 deletions bindings/node/src/mongocrypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Function MongoCrypt::Init(Napi::Env env) {
InstanceMethod("makeDataKeyContext", &MongoCrypt::MakeDataKeyContext),
InstanceMethod("makeRewrapManyDataKeyContext", &MongoCrypt::MakeRewrapManyDataKeyContext),
InstanceAccessor("status", &MongoCrypt::Status, nullptr),
InstanceAccessor("csfleVersionInfo", &MongoCrypt::CSFLEVersionInfo, nullptr)
InstanceAccessor("cryptSharedLibVersionInfo", &MongoCrypt::CryptSharedLibVersionInfo, nullptr)
});
}

Expand Down Expand Up @@ -449,23 +449,23 @@ MongoCrypt::MongoCrypt(const CallbackInfo& info)
}
}

if (options.Has("csfleSearchPaths")) {
Napi::Value search_paths_v = options["csfleSearchPaths"];
if (options.Has("cryptSharedLibSearchPaths")) {
Napi::Value search_paths_v = options["cryptSharedLibSearchPaths"];
if (!search_paths_v.IsArray()) {
throw TypeError::New(Env(), "Option `csfleSearchPaths` must be an array");
throw TypeError::New(Env(), "Option `cryptSharedLibSearchPaths` must be an array");
}
Array search_paths = search_paths_v.As<Array>();
for (uint32_t i = 0; i < search_paths.Length(); i++) {
mongocrypt_setopt_append_csfle_search_path(
mongocrypt_setopt_append_crypt_shared_lib_search_path(
_mongo_crypt.get(),
search_paths.Get(i).ToString().Utf8Value().c_str());
}
}

if (options.Has("csflePath")) {
mongocrypt_setopt_set_csfle_lib_path_override(
if (options.Has("cryptSharedLibPath")) {
mongocrypt_setopt_set_crypt_shared_lib_path_override(
_mongo_crypt.get(),
options.Get("csflePath").ToString().Utf8Value().c_str());
options.Get("cryptSharedLibPath").ToString().Utf8Value().c_str());
}

if (options.Get("bypassQueryAnalysis").ToBoolean()) {
Expand All @@ -480,9 +480,9 @@ MongoCrypt::MongoCrypt(const CallbackInfo& info)
}
}

Value MongoCrypt::CSFLEVersionInfo(const CallbackInfo& info) {
uint64_t version_numeric = mongocrypt_csfle_version(_mongo_crypt.get());
const char* version_string = mongocrypt_csfle_version_string(_mongo_crypt.get(), nullptr);
Value MongoCrypt::CryptSharedLibVersionInfo(const CallbackInfo& info) {
uint64_t version_numeric = mongocrypt_crypt_shared_lib_version(_mongo_crypt.get());
const char* version_string = mongocrypt_crypt_shared_lib_version_string(_mongo_crypt.get(), nullptr);
if (version_string == nullptr) {
return Env().Null();
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/node/src/mongocrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MongoCrypt : public Napi::ObjectWrap<MongoCrypt> {
Napi::Value MakeRewrapManyDataKeyContext(const Napi::CallbackInfo& info);

Napi::Value Status(const Napi::CallbackInfo& info);
Napi::Value CSFLEVersionInfo(const Napi::CallbackInfo& info);
Napi::Value CryptSharedLibVersionInfo(const Napi::CallbackInfo& info);

private:
friend class Napi::ObjectWrap<MongoCrypt>;
Expand Down
30 changes: 15 additions & 15 deletions bindings/node/test/autoEncrypter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let sharedLibraryStub = path.resolve(
'..',
'..',
'..',
`mongo_csfle_v1.${sharedLibrarySuffix}`
`mongo_crypt_v1.${sharedLibrarySuffix}`
);
if (!fs.existsSync(sharedLibraryStub)) {
sharedLibraryStub = path.resolve(
Expand All @@ -35,7 +35,7 @@ if (!fs.existsSync(sharedLibraryStub)) {
'tmp',
'libmongocrypt-build',
...(process.platform === 'win32' ? ['RelWithDebInfo'] : []),
`mongo_csfle_v1.${sharedLibrarySuffix}`
`mongo_crypt_v1.${sharedLibrarySuffix}`
);
}

Expand Down Expand Up @@ -285,7 +285,7 @@ describe('AutoEncrypter', function () {
});

// TODO(NODE-4089): Enable test once https://github.com/mongodb/libmongocrypt/pull/263 is done
it.skip('should encrypt mock data when using the CSFLE shared library', function (done) {
it.skip('should encrypt mock data when using the crypt_shared library', function (done) {
const client = new MockClient();
const mc = new AutoEncrypter(client, {
keyVaultNamespace: 'admin.datakeys',
Expand All @@ -297,7 +297,7 @@ describe('AutoEncrypter', function () {
return { aws: { accessKeyId: 'example', secretAccessKey: 'example' } };
},
extraOptions: {
csflePath: sharedLibraryStub
cryptSharedLibPath: sharedLibraryStub
}
});

Expand Down Expand Up @@ -641,8 +641,8 @@ describe('AutoEncrypter', function () {
});
});

describe('CSFLE shared library', function () {
it('should fail if no library can be found in the search path and csfleRequired is set', function () {
describe('crypt_shared library', function () {
it('should fail if no library can be found in the search path and cryptSharedLibRequired is set', function () {
// NB: This test has to be run before the tests/without having previously
// loaded a CSFLE shared library below to get the right error path.
const client = new MockClient();
Expand All @@ -655,13 +655,13 @@ describe('AutoEncrypter', function () {
local: { key: Buffer.alloc(96) }
},
extraOptions: {
csfleSearchPaths: ['/nonexistent'],
csfleRequired: true
cryptSharedLibSearchPaths: ['/nonexistent'],
cryptSharedLibRequired: true
}
});
expect.fail('missed exception');
} catch (err) {
expect(err.message).to.include('`csfleRequired` set but no csfle shared library loaded');
expect(err.message).to.include('`cryptSharedLibRequired` set but no crypt_shared library loaded');
}
});

Expand All @@ -675,16 +675,16 @@ describe('AutoEncrypter', function () {
local: { key: Buffer.alloc(96) }
},
extraOptions: {
csflePath: sharedLibraryStub
cryptSharedLibPath: sharedLibraryStub
}
});

expect(this.mc).to.not.have.property('_mongocryptdManager');
expect(this.mc).to.not.have.property('_mongocryptdClient');
expect(this.mc).to.have.deep.property('csfleVersionInfo', {
expect(this.mc).to.have.deep.property('cryptSharedLibVersionInfo', {
// eslint-disable-next-line no-undef
version: BigInt(0x000600020001000),
versionStr: 'stubbed-mongo_csfle'
versionStr: 'stubbed-crypt_shared'
});

this.mc.teardown(true, done);
Expand All @@ -700,16 +700,16 @@ describe('AutoEncrypter', function () {
local: { key: Buffer.alloc(96) }
},
extraOptions: {
csfleSearchPaths: [path.dirname(sharedLibraryStub)]
cryptSharedLibSearchPaths: [path.dirname(sharedLibraryStub)]
}
});

expect(this.mc).to.not.have.property('_mongocryptdManager');
expect(this.mc).to.not.have.property('_mongocryptdClient');
expect(this.mc).to.have.deep.property('csfleVersionInfo', {
expect(this.mc).to.have.deep.property('cryptSharedLibVersionInfo', {
// eslint-disable-next-line no-undef
version: BigInt(0x000600020001000),
versionStr: 'stubbed-mongo_csfle'
versionStr: 'stubbed-crypt_shared'
});

this.mc.teardown(true, done);
Expand Down
16 changes: 8 additions & 8 deletions bindings/python/.evergreen/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
"C:/python/Python38/python.exe"
"C:/python/Python39/python.exe"
"C:/python/Python310/python.exe")
export CSFLE_PATH=../csfle/bin/mongo_csfle_v1.dll
C:/python/Python310/python.exe drivers-evergreen-tools/.evergreen/mongodl.py --component csfle \
--version latest --out ../csfle/
export CSFLE_PATH=../crypt_shared/bin/mongo_crypt_v1.dll
C:/python/Python310/python.exe drivers-evergreen-tools/.evergreen/mongodl.py --component crypt_shared \
--version latest --out ../crypt_shared/
elif [ "Darwin" = "$(uname -s)" ]; then
export PYMONGOCRYPT_LIB=${MONGOCRYPT_DIR}/nocrypto/lib/libmongocrypt.dylib
PYTHONS=("python" # Python 2.7 from brew
Expand All @@ -38,9 +38,9 @@ elif [ "Darwin" = "$(uname -s)" ]; then
"/Library/Frameworks/Python.framework/Versions/3.8/bin/python3"
"/Library/Frameworks/Python.framework/Versions/3.9/bin/python3"
"/Library/Frameworks/Python.framework/Versions/3.10/bin/python3")
export CSFLE_PATH="../csfle/lib/mongo_csfle_v1.dylib"
python3 drivers-evergreen-tools/.evergreen/mongodl.py --component csfle \
--version latest --out ../csfle/
export CSFLE_PATH="../crypt_shared/lib/mongo_crypt_v1.dylib"
python3 drivers-evergreen-tools/.evergreen/mongodl.py --component crypt_shared \
--version latest --out ../crypt_shared/
else
export PYMONGOCRYPT_LIB=${MONGOCRYPT_DIR}/nocrypto/lib64/libmongocrypt.so
PYTHONS=("/opt/python/2.7/bin/python"
Expand All @@ -49,9 +49,9 @@ else
"/opt/python/3.6/bin/python3"
"/opt/python/pypy/bin/pypy"
"/opt/python/pypy3.6/bin/pypy3")
export CSFLE_PATH="../csfle/lib/mongo_csfle_v1.so"
export CSFLE_PATH="../crypt_shared/lib/mongo_crypt_v1.so"
/opt/mongodbtoolchain/v3/bin/python3 drivers-evergreen-tools/.evergreen/mongodl.py --component \
csfle --version latest --out ../csfle/ --target rhel70
crypt_shared --version latest --out ../crypt_shared/ --target rhel70
fi


Expand Down
Loading