Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mongodb-js/mongodb-client-encryption
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0-beta.0
Choose a base ref
...
head repository: mongodb-js/mongodb-client-encryption
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.0-beta.3
Choose a head ref
  • 16 commits
  • 14 files changed
  • 5 contributors

Commits on Nov 23, 2021

  1. Copy the full SHA
    0e3571f View commit details

Commits on Dec 1, 2021

  1. Copy the full SHA
    68adc88 View commit details

Commits on Dec 15, 2021

  1. Copy the full SHA
    e049059 View commit details

Commits on Dec 17, 2021

  1. Copy the full SHA
    5816a19 View commit details

Commits on Dec 20, 2021

  1. Copy the full SHA
    7e4280b View commit details

Commits on Dec 21, 2021

  1. chore(NODE-3633): update Socks5 support for driver PR feedback (#227)

    - Update the Socks5 options naming to use the connection string
      parameter names as keys, rather than shortened variants,
      for easier integration into the Node.js driver
    - Fix and test username/password authentication (noticed while
      addressing the above, this is absolutely my bad)
    addaleax authored Dec 21, 2021
    Copy the full SHA
    d922e23 View commit details
  2. Copy the full SHA
    afa1838 View commit details
  3. Copy the full SHA
    27dec0e View commit details

Commits on Dec 29, 2021

  1. Copy the full SHA
    4e2c818 View commit details

Commits on Jan 5, 2022

  1. Copy the full SHA
    54a909b View commit details

Commits on Jan 18, 2022

  1. Copy the full SHA
    8a173b2 View commit details

Commits on Jan 20, 2022

  1. Copy the full SHA
    bca4a84 View commit details

Commits on Jan 25, 2022

  1. fix(NODE-3777): destroy socket on end (#236)

    Co-authored-by: Anna Henningsen <[email protected]>
    durran and addaleax authored Jan 25, 2022
    Copy the full SHA
    b886970 View commit details
  2. Move CMAKE_C_FLAGS from CMakeLists.txt into Evergreen build scripts (…

    …#224)
    
    * Move CMAKE_C_FLAGS from CMakeLists.txt into Evergreen build scripts
    
    * Add LIBMONGOCRYPT_CFLAGS to build-static.sh
    
    * Remove unrecognized -fPIC flag from Windows compile options
    eramongodb authored Jan 25, 2022
    Copy the full SHA
    99b8461 View commit details

Commits on Jan 27, 2022

  1. Copy the full SHA
    3b2d83d View commit details

Commits on Jan 31, 2022

  1. chore(release): 2.0.0-beta.3

    durran committed Jan 31, 2022
    Copy the full SHA
    54cb056 View commit details
Showing with 574 additions and 75 deletions.
  1. +9 −1 .evergreen/find_cmake.sh
  2. +1 −1 .evergreen/setup_environment.sh
  3. +6 −0 CHANGELOG.md
  4. +12 −3 etc/build-static.sh
  5. +64 −1 index.d.ts
  6. +15 −3 lib/autoEncrypter.js
  7. +18 −3 lib/clientEncryption.js
  8. +118 −13 lib/stateMachine.js
  9. +50 −3 package-lock.json
  10. +3 −2 package.json
  11. +5 −0 src/mongocrypt.cc
  12. +1 −0 src/mongocrypt.h
  13. +18 −0 test/autoEncrypter.test.js
  14. +254 −45 test/stateMachine.test.js
10 changes: 9 additions & 1 deletion .evergreen/find_cmake.sh
Original file line number Diff line number Diff line change
@@ -3,6 +3,14 @@
# Copied from the mongo-c-driver
find_cmake ()
{
# Check if on macOS with arm64. Use system cmake. See BUILD-14565.
OS_NAME=$(uname -s | tr '[:upper:]' '[:lower:]')
MARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
if [ "darwin" = "$OS_NAME" -a "arm64" = "$MARCH" ]; then
CMAKE=cmake
return 0
fi

if [ ! -z "$CMAKE" ]; then
return 0
elif [ -f "/Applications/cmake-3.2.2-Darwin-x86_64/CMake.app/Contents/bin/cmake" ]; then
@@ -11,7 +19,7 @@ find_cmake ()
CMAKE="/Applications/Cmake.app/Contents/bin/cmake"
elif [ -f "/opt/cmake/bin/cmake" ]; then
CMAKE="/opt/cmake/bin/cmake"
elif command -v cmake 2>/dev/null; then
elif [ -z "$IGNORE_SYSTEM_CMAKE" ] && command -v cmake 2>/dev/null; then
CMAKE=cmake
elif uname -a | grep -iq 'x86_64 GNU/Linux'; then
curl --retry 5 https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.tar.gz -sS --max-time 120 --fail --output cmake.tar.gz
2 changes: 1 addition & 1 deletion .evergreen/setup_environment.sh
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ if [ "$OS" == "Windows_NT" ]; then
ADDITIONAL_CMAKE_FLAGS="-Thost=x64 -A x64"
else
chmod u+x ./.evergreen/find_cmake.sh
. ./.evergreen/find_cmake.sh
IGNORE_SYSTEM_CMAKE=1 . ./.evergreen/find_cmake.sh
fi

# this needs to be explicitly exported for the nvm install below
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.0.0-beta.3](https://github.com/mongodb/libmongocrypt/compare/node-v2.0.0-beta.0...node-v2.0.0-beta.3) (2022-01-31)

## [2.0.0-beta.2](https://github.com/mongodb/libmongocrypt/compare/node-v2.0.0-beta.0...node-v2.0.0-beta.2) (2021-12-22)

## [2.0.0-beta.1](https://github.com/mongodb/libmongocrypt/compare/node-v2.0.0-beta.0...node-v2.0.0-beta.1) (2021-12-21)

## [2.0.0-beta.0](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.7...node-v2.0.0-beta.0) (2021-10-07)

### [1.2.7](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.6...node-v1.2.7) (2021-09-14)
15 changes: 12 additions & 3 deletions etc/build-static.sh
Original file line number Diff line number Diff line change
@@ -41,12 +41,21 @@ popd #./deps/tmp
# build and install libmongocrypt
pushd libmongocrypt-build #./deps/tmp/libmongocrypt-build

CMAKE_FLAGS="-DDISABLE_NATIVE_CRYPTO=1 -DCMAKE_C_FLAGS=\"-fPIC\" -DCMAKE_INSTALL_LIBDIR=lib "
if [ "$OS" = "Windows_NT" ]; then
# W4996 - POSIX name for this item is deprecated
# TODO: add support for clang-cl which is detected as MSVC
LIBMONGOCRYPT_CFLAGS="/WX"
else
# GNU, Clang, AppleClang
LIBMONGOCRYPT_CFLAGS="-fPIC -Werror"
fi

CMAKE_FLAGS="-DDISABLE_NATIVE_CRYPTO=1 -DCMAKE_INSTALL_LIBDIR=lib"
if [ "$OS" == "Windows_NT" ]; then
WINDOWS_CMAKE_FLAGS="-Thost=x64 -A x64 -DCMAKE_C_FLAGS_RELWITHDEBINFO=\"/MT\""
$CMAKE $CMAKE_FLAGS $WINDOWS_CMAKE_FLAGS -DCMAKE_PREFIX_PATH="`cygpath -w $DEPS_PREFIX`" -DCMAKE_INSTALL_PREFIX="`cygpath -w $DEPS_PREFIX`" "`cygpath -w $LIBMONGOCRYPT_DIR`"
$CMAKE $CMAKE_FLAGS $WINDOWS_CMAKE_FLAGS -DCMAKE_C_FLAGS="${LIBMONGOCRYPT_CFLAGS}" -DCMAKE_PREFIX_PATH="`cygpath -w $DEPS_PREFIX`" -DCMAKE_INSTALL_PREFIX="`cygpath -w $DEPS_PREFIX`" "`cygpath -w $LIBMONGOCRYPT_DIR`"
else
$CMAKE $CMAKE_FLAGS -DCMAKE_PREFIX_PATH=$DEPS_PREFIX -DCMAKE_INSTALL_PREFIX=$DEPS_PREFIX -DCMAKE_OSX_DEPLOYMENT_TARGET="10.12" $LIBMONGOCRYPT_DIR
$CMAKE $CMAKE_FLAGS -DCMAKE_C_FLAGS="${LIBMONGOCRYPT_CFLAGS}" -DCMAKE_PREFIX_PATH=$DEPS_PREFIX -DCMAKE_INSTALL_PREFIX=$DEPS_PREFIX -DCMAKE_OSX_DEPLOYMENT_TARGET="10.12" $LIBMONGOCRYPT_DIR
fi

$CMAKE --build . --target install --config RelWithDebInfo
65 changes: 64 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import type { Binary } from 'bson';
import type { MongoClient } from 'mongodb';

export type ClientEncryptionDataKeyProvider = 'aws' | 'azure' | 'gcp' | 'local';
export type ClientEncryptionDataKeyProvider = 'aws' | 'azure' | 'gcp' | 'local' | 'kmip';

/**
* An error indicating that something went wrong specifically with MongoDB Client Encryption
*/
export class MongoCryptError extends Error {
}

/**
* A set of options for specifying a Socks5 proxy.
*/
export interface ProxyOptions {
proxyHost: string;
proxyPort?: number;
proxyUsername?: string;
proxyPassword?: string;
}

export interface ClientEncryptionCreateDataKeyCallback {
/**
* @param error If present, indicates an error that occurred in the creation of the data key
@@ -69,6 +79,18 @@ export interface KMSProviders {
key: Buffer | string;
};

/**
* Configuration options for using 'kmip' as your KMS provider
*/
kmip?: {
/**
* The output endpoint string.
* The endpoint consists of a hostname and port separated by a colon.
* E.g. "example.com:123". A port is always present.
*/
endpoint?: string;
};

/**
* Configuration options for using 'azure' as your KMS provider
*/
@@ -119,6 +141,37 @@ export interface KMSProviders {
}
}

/**
* TLS options to use when connecting. The spec specifically calls out which insecure
* tls options are not allowed:
*
* - tlsAllowInvalidCertificates
* - tlsAllowInvalidHostnames
* - tlsInsecure
* - tlsDisableOCSPEndpointCheck
* - tlsDisableCertificateRevocationCheck
*/
export interface ClientEncryptionTlsOptions {
/**
* Specifies the location of a local .pem file that contains
* either the client's TLS/SSL certificate and key or only the
* client's TLS/SSL key when tlsCertificateFile is used to
* provide the certificate.
*/
tlsCertificateKeyFile?: string;
/**
* Specifies the password to de-crypt the tlsCertificateKeyFile.
*/
tlsCertificateKeyFilePassword?: string;
/**
* Specifies the location of a local .pem file that contains the
* root certificate chain from the Certificate Authority.
* This file is used to validate the certificate presented by the
* KMS provider.
*/
tlsCAFile?: string;
}

/**
* Additional settings to provide when creating a new `ClientEncryption` instance.
*/
@@ -137,6 +190,16 @@ export interface ClientEncryptionOptions {
* Options for specific KMS providers to use
*/
kmsProviders?: KMSProviders;

/**
* Options for specifying a Socks5 proxy to use for connecting to the KMS.
*/
proxyOptions?: ProxyOptions;

/**
* TLS options for kms providers to use.
*/
tlsOptions?: { [kms in keyof KMSProviders]?: ClientEncryptionTLSOptions };
}

/**
18 changes: 15 additions & 3 deletions lib/autoEncrypter.js
Original file line number Diff line number Diff line change
@@ -98,13 +98,15 @@ module.exports = function(modules) {
this._mongocryptdClient = new MongoClient(this._mongocryptdManager.uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 1000
serverSelectionTimeoutMS: 10000
});
}

this._keyVaultNamespace = options.keyVaultNamespace || 'admin.datakeys';
this._keyVaultClient = options.keyVaultClient || client;
this._metaDataClient = options.metadataClient || client;
this._proxyOptions = options.proxyOptions || {};
this._tlsOptions = options.tlsOptions || {};

const mongoCryptOptions = {};
if (options.schemaMap) {
@@ -212,7 +214,12 @@ module.exports = function(modules) {
context.ns = ns;
context.document = cmd;

const stateMachine = new StateMachine(Object.assign({ bson }, options));
const stateMachine = new StateMachine({
bson,
...options,
proxyOptions: this._proxyOptions,
tlsOptions: this._tlsOptions
});
stateMachine.execute(this, context, callback);
}

@@ -243,7 +250,12 @@ module.exports = function(modules) {
// TODO: should this be an accessor from the addon?
context.id = this._contextCounter++;

const stateMachine = new StateMachine(Object.assign({ bson }, options));
const stateMachine = new StateMachine({
bson,
...options,
proxyOptions: this._proxyOptions,
tlsOptions: this._tlsOptions
});
stateMachine.execute(this, context, callback);
}
}
21 changes: 18 additions & 3 deletions lib/clientEncryption.js
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ module.exports = function(modules) {
* @param {MongoClient} client The client used for encryption
* @param {object} options Additional settings
* @param {string} options.keyVaultNamespace The namespace of the key vault, used to store encryption keys
* @param {object} options.tlsOptions An object that maps KMS provider names to TLS options.
* @param {MongoClient} [options.keyVaultClient] A `MongoClient` used to fetch keys from a key vault. Defaults to `client`
* @param {KMSProviders} [options.kmsProviders] options for specific KMS providers to use
*
@@ -65,6 +66,8 @@ module.exports = function(modules) {
constructor(client, options) {
this._client = client;
this._bson = options.bson || client.topology.bson;
this._proxyOptions = options.proxyOptions;
this._tlsOptions = options.tlsOptions;

if (options.keyVaultNamespace == null) {
throw new TypeError('Missing required option `keyVaultNamespace`');
@@ -198,7 +201,11 @@ module.exports = function(modules) {

const dataKeyBson = bson.serialize(dataKey);
const context = this._mongoCrypt.makeDataKeyContext(dataKeyBson, { keyAltNames });
const stateMachine = new StateMachine({ bson });
const stateMachine = new StateMachine({
bson,
proxyOptions: this._proxyOptions,
tlsOptions: this._tlsOptions
});

return promiseOrCallback(callback, cb => {
stateMachine.execute(this, context, (err, dataKey) => {
@@ -290,7 +297,11 @@ module.exports = function(modules) {
contextOptions.keyAltName = bson.serialize({ keyAltName });
}

const stateMachine = new StateMachine({ bson });
const stateMachine = new StateMachine({
bson,
proxyOptions: this._proxyOptions,
tlsOptions: this._tlsOptions
});
const context = this._mongoCrypt.makeExplicitEncryptionContext(valueBuffer, contextOptions);

return promiseOrCallback(callback, cb => {
@@ -335,7 +346,11 @@ module.exports = function(modules) {
const valueBuffer = bson.serialize({ v: value });
const context = this._mongoCrypt.makeExplicitDecryptionContext(valueBuffer);

const stateMachine = new StateMachine({ bson });
const stateMachine = new StateMachine({
bson,
proxyOptions: this._proxyOptions,
tlsOptions: this._tlsOptions
});

return promiseOrCallback(callback, cb => {
stateMachine.execute(this, context, (err, result) => {
Loading