@@ -181,6 +181,12 @@ if test "$PHP_MONGODB" != "no"; then
181181 [ MongoDB: Use system libmongoc [ default=no] ] ) ] ,
182182 [ no] ,
183183 [ no] )
184+ PHP_ARG_WITH([ mongodb-client-side-encryption] ,
185+ [ whether to enable client-side encryption] ,
186+ [ AS_HELP_STRING ( [ --with-mongodb-client-side-encryption=@<:@ auto/yes/no@:>@ ] ,
187+ [ MongoDB: Enable client-side encryption [ default=auto] ] ) ] ,
188+ [ auto] ,
189+ [ no] )
184190
185191 if test "$PHP_LIBBSON" != "no"; then
186192 if test "$PHP_LIBMONGOC" = "no"; then
@@ -230,8 +236,38 @@ if test "$PHP_MONGODB" != "no"; then
230236 AC_DEFINE ( HAVE_SYSTEM_LIBMONGOC , 1 , [ Use system libmongoc] )
231237 fi
232238
239+ if test "$PHP_MONGODB_CLIENT_SIDE_ENCRYPTION" != "no" -a "$PHP_LIBBSON" = "yes"; then
240+ AC_PATH_PROG ( PKG_CONFIG , pkg-config , no )
241+ AC_MSG_CHECKING ( for libmongocrypt )
242+ 243+ if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libmongocrypt-1.0; then
244+ if $PKG_CONFIG libmongocrypt-1.0 --atleast-version 1.0.1; then
245+ PHP_MONGODB_MONGOCRYPT_CFLAGS=`$PKG_CONFIG libmongocrypt-1.0 --cflags`
246+ PHP_MONGODB_MONGOCRYPT_LIBS=`$PKG_CONFIG libmongocrypt-1.0 --libs`
247+ PHP_MONGODB_MONGOCRYPT_VERSION=`$PKG_CONFIG libmongocrypt-1.0 --modversion`
248+ AC_MSG_RESULT ( version $PHP_MONGODB_MONGOCRYPT_VERSION found )
249+ 250+ PHP_MONGODB_CFLAGS="$PHP_MONGODB_CFLAGS $PHP_MONGODB_MONGOCRYPT_CFLAGS"
251+ PHP_EVAL_LIBLINE($PHP_MONGODB_MONGOCRYPT_LIBS, MONGODB_SHARED_LIBADD)
252+ AC_DEFINE ( HAVE_SYSTEM_LIBMONGOCRYPT , 1 , [ Use system libmongocrypt] )
253+ elif test "$PHP_MONGODB_CLIENT_SIDE_ENCRYPTION" = "yes"; then
254+ AC_MSG_ERROR ( system libmongocrypt must be upgraded to version >= 1.0.1 )
255+ else
256+ AC_MSG_RESULT ( found an older version , compiling without client-side encryption )
257+ fi
258+ else
259+ if test "$PHP_MONGODB_CLIENT_SIDE_ENCRYPTION" = "yes"; then
260+ AC_MSG_ERROR ( pkgconfig and libmongocrypt must be installed )
261+ else
262+ AC_MSG_RESULT ( not found , compiling without client-side encryption )
263+ fi
264+ fi
265+ fi
266+ 233267 if test "$PHP_LIBBSON" = "no" -a "$PHP_LIBMONGOC" = "no"; then
234268 PHP_MONGODB_BUNDLED_CFLAGS="$STD_CFLAGS -DBSON_COMPILATION -DMONGOC_COMPILATION"
269+ dnl TODO: MONGOCRYPT-219 makes the -std argument obsolete
270+ PHP_MONGODB_LIBMONGOCRYPT_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS -std=gnu99"
235271
236272 dnl M4 doesn't know if we're building statically or as a shared module, so
237273 dnl attempt to include both paths while ignoring errors. If neither path
@@ -273,6 +309,11 @@ if test "$PHP_MONGODB" != "no"; then
273309 _include([ scripts/autotools/libmongoc/Versions.m4] )
274310 _include([ scripts/autotools/libmongoc/WeakSymbols.m4] )
275311
312+ dnl This include modifies the value of $PHP_MONGODB_CLIENT_SIDE_ENCRYPTION to "yes"
313+ dnl or "no" depending on whether dependencies for libmongocrypt are fulfilled
314+ _include([ scripts/autotools/libmongocrypt/CheckSSL.m4] )
315+ _include([ scripts/autotools/libmongocrypt/Version.m4] )
316+ 276317 m4_popdef ( [ _include] )
277318
278319 AC_SUBST ( BSON_EXTRA_ALIGN , 0 )
@@ -283,16 +324,19 @@ if test "$PHP_MONGODB" != "no"; then
283324 AC_SUBST ( MONGOC_ENABLE_SHM_COUNTERS , 0 )
284325 AC_SUBST ( MONGOC_TRACE , 1 )
285326
286- dnl TODO: Replace with detection for libmongocrypt for PHPC-1293
287- AC_SUBST ( MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION , 0 )
288- 289327 dnl Assignments for metadata handshake. Leave CFLAGS/LDFLAGS empty as they
290328 dnl would likely cause platform info (PHP version) to be truncated. We can
291329 dnl consider restoring CFLAGS/LDFLAGS once CDRIVER-3134 is resolved.
292330 AC_SUBST ( MONGOC_CC , [ $CC] )
293331 AC_SUBST ( MONGOC_USER_SET_CFLAGS , [ ] )
294332 AC_SUBST ( MONGOC_USER_SET_LDFLAGS , [ ] )
295333
334+ if test "$PHP_MONGODB_CLIENT_SIDE_ENCRYPTION" = "yes"; then
335+ AC_SUBST ( MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION , 1 )
336+ else
337+ AC_SUBST ( MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION , 0 )
338+ fi
339+ 296340 dnl On MacOS, use gcut from the coreutils brew package instead of cut
297341 dnl Generated with: find src/libmongoc/src/common -name '*.c' -print0 | cut -sz -d / -f 5- | sort -dz | tr '000円' ' '
298342 PHP_MONGODB_COMMON_SOURCES="common-b64.c common-md5.c"
@@ -342,6 +386,46 @@ if test "$PHP_MONGODB" != "no"; then
342386 PHP_MONGODB_ADD_BUILD_DIR([ src/libmongoc/src/zlib-1.2.11/] )
343387 AC_CONFIG_FILES ( [ ${ac_config_dir}/src/libmongoc/src/zlib-1.2.11/zconf.h] )
344388 fi
389+ 390+ if test "$PHP_MONGODB_CLIENT_SIDE_ENCRYPTION" = "yes"; then
391+ AC_SUBST ( MONGOCRYPT_ENABLE_TRACE , 1 )
392+ 393+ dnl Generated with: find src/libmongocrypt/src -maxdepth 1 -name '*.c' -print0 | cut -sz -d / -f 4- | sort -dz | tr '000円' ' '
394+ PHP_MONGODB_MONGOCRYPT_SOURCES="mongocrypt-binary.c mongocrypt-buffer.c mongocrypt.c mongocrypt-cache.c mongocrypt-cache-collinfo.c mongocrypt-cache-key.c mongocrypt-ciphertext.c mongocrypt-crypto.c mongocrypt-ctx.c mongocrypt-ctx-datakey.c mongocrypt-ctx-decrypt.c mongocrypt-ctx-encrypt.c mongocrypt-key-broker.c mongocrypt-key.c mongocrypt-kms-ctx.c mongocrypt-log.c mongocrypt-marking.c mongocrypt-opts.c mongocrypt-status.c mongocrypt-traverse-util.c"
395+ 396+ dnl Generated with: find src/libmongocrypt/src/crypto -name '*.c' -print0 | cut -sz -d / -f 5- | sort -dz | tr '000円' ' '
397+ PHP_MONGODB_MONGOCRYPT_CRYPTO_SOURCES="cng.c commoncrypto.c libcrypto.c none.c"
398+ 399+ dnl Generated with: find src/libmongocrypt/src/os_posix -name '*.c' -print0 | cut -sz -d / -f 5- | sort -dz | tr '000円' ' '
400+ PHP_MONGODB_MONGOCRYPT_OS_POSIX_SOURCES="os_mutex.c os_once.c"
401+ 402+ dnl Generated with: find src/libmongocrypt/src/os_win -name '*.c' -print0 | cut -sz -d / -f 5- | sort -dz | tr '000円' ' '
403+ PHP_MONGODB_MONGOCRYPT_OS_WIN_SOURCES="os_mutex.c os_once.c"
404+ 405+ dnl Generated with: find src/libmongocrypt/kms-message/src -maxdepth 1 -name '*.c' -print0 | cut -sz -d / -f 5- | sort -dz | tr '000円' ' '
406+ PHP_MONGODB_MONGOCRYPT_KMS_MESSAGE_SOURCES="hexlify.c kms_b64.c kms_caller_identity_request.c kms_crypto_apple.c kms_crypto_libcrypto.c kms_crypto_none.c kms_crypto_windows.c kms_decrypt_request.c kms_encrypt_request.c kms_kv_list.c kms_message.c kms_request.c kms_request_opt.c kms_request_str.c kms_response.c kms_response_parser.c sort.c"
407+ 408+ PHP_MONGODB_ADD_SOURCES([ src/libmongocrypt/src/] , $PHP_MONGODB_MONGOCRYPT_SOURCES, $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS)
409+ PHP_MONGODB_ADD_SOURCES([ src/libmongocrypt/src/crypto/] , $PHP_MONGODB_MONGOCRYPT_CRYPTO_SOURCES, $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS)
410+ PHP_MONGODB_ADD_SOURCES([ src/libmongocrypt/src/os_posix/] , $PHP_MONGODB_MONGOCRYPT_OS_POSIX_SOURCES, $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS)
411+ PHP_MONGODB_ADD_SOURCES([ src/libmongocrypt/src/os_win/] , $PHP_MONGODB_MONGOCRYPT_OS_WIN_SOURCES, $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS)
412+ PHP_MONGODB_ADD_SOURCES([ src/libmongocrypt/kms-message/src/] , $PHP_MONGODB_MONGOCRYPT_KMS_MESSAGE_SOURCES, $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS)
413+ 414+ PHP_MONGODB_ADD_INCLUDE([ src/libmongocrypt/src/] )
415+ PHP_MONGODB_ADD_INCLUDE([ src/libmongocrypt/kms-message/src/] )
416+ PHP_MONGODB_ADD_INCLUDE([ src/libmongocrypt-compat/] )
417+ 418+ PHP_MONGODB_ADD_BUILD_DIR([ src/libmongocrypt/src/] )
419+ PHP_MONGODB_ADD_BUILD_DIR([ src/libmongocrypt/src/crypto/] )
420+ PHP_MONGODB_ADD_BUILD_DIR([ src/libmongocrypt/src/os_posix/] )
421+ PHP_MONGODB_ADD_BUILD_DIR([ src/libmongocrypt/src/os_win/] )
422+ PHP_MONGODB_ADD_BUILD_DIR([ src/libmongocrypt/kms-message/src/] )
423+ 424+ AC_CONFIG_FILES ( [
425+ ${ac_config_dir}/src/libmongocrypt/src/mongocrypt-config.h
426+ ${ac_config_dir}/src/libmongocrypt/src/mongocrypt.h
427+ ] )
428+ fi
345429 fi
346430
347431 PHP_NEW_EXTENSION(mongodb, $PHP_MONGODB_SOURCES, $ext_shared,, $PHP_MONGODB_CFLAGS)
@@ -373,6 +457,7 @@ if test "$PHP_MONGODB" != "no"; then
373457 dnl This must come after PHP_NEW_EXTENSION, otherwise the srcdir won't be set
374458 PHP_ADD_MAKEFILE_FRAGMENT
375459
460+ dnl The libmongocrypt line intentionally uses the PHP_LIBBSON flag as that decides whether to build against bundled or system libraries.
376461 AC_CONFIG_COMMANDS_POST ( [
377462 if test "$enable_static" = "no"; then
378463 echo "
@@ -385,6 +470,7 @@ Build configuration:
385470 Code Coverage flags (extra slow) : $COVERAGE_CFLAGS
386471 System mongoc : $PHP_LIBMONGOC
387472 System libbson : $PHP_LIBBSON
473+ System libmongocrypt : $PHP_LIBBSON
388474 LDFLAGS : $LDFLAGS
389475 EXTRA_LDFLAGS : $EXTRA_LDFLAGS
390476 MONGODB_SHARED_LIBADD : $MONGODB_SHARED_LIBADD
0 commit comments