[CDRIVER-4414] Allow applications and wrapping drivers to detect crypt_shared availability Created: 23/Jun/22  Updated: 03/Aug/22  Resolved: 03/Aug/22

Status: Closed
Project: C Driver
Component/s: libmongocrypt
Affects Version/s: 1.22.0-beta0
Fix Version/s: 1.23.0

Type: Improvement Priority: Unknown
Reporter: Jeremy Mikola Assignee: Colby Pike
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by PHPC-2103 Allow applications to detect crypt_sh... Closed
Related
is related to CDRIVER-4450 Initializing client-side encryption s... Closed

 Description   

Related to: Detecting crypt_shared Availability in the CSFLE spec.

Applications and drivers wrapping libmongoc don't have any way to determine if crypt_shared is used, because mongocrypt_crypt_shared_lib_version_string requires a mongocrypt_t * resource, which is internal to libmongoc's private struct __mongoc_crypt_t (typedef-ed as _mongoc_crypt_t).

_mongoc_crypt_t is created by _mongoc_crypt_new, which is only called in three places within libmongoc:

  • Initializing topology->crypt member for single-threaded and pooled modes.
  • Creating mongoc_client_encryption_t, which isn't relevant since crypt_shared is never required there.

In a previous discussion with colby.pike@mongodb.com I asked if libmongoc or libmongocrypt had any safeguards in place to avoid loading multiple versions of crypt_shared. His response was:

1: Correct, the version of crypt_shared is orthogonal to the version of libmongocrypt, since crypt_shared is loaded dynamically.
2: Applications cannot load more than one version of crypt_shared library simultaneously, even if they are of the same version (multiple uses of the same library is allowed, as long as it is the same file every time). There are some guards in check to prevent this as well, but they aren't fool-proof.

Ideally, it'd be great if libmongoc or libmongocrypt could provide some global API (not tied to a client/pool) that allowed applications to query the crypt_shared version. This would allow PHP to report its version the same way we do libmongoc and libmongocrypt itself. If that's not possible, providing some API to query the crypt_shared version through a pool or client would be sufficient (although that could be more complicated as it would require exposing mongoc_crypt_t _and its mongocrypt_t *.



 Comments   
Comment by Jeremy Mikola [ 27/Jun/22 ]

The API I was thinking of would likely need to be some global function that would be expected to return NULL until the process happens to dynamically load the library. It looks like there's always some global state tracked in mongocrypt.c around where _try_load_csfle is called, so that's what I was expecting could be updated.

If that's not feasible, then an API on mongoc_client_t works.

Comment by Kevin Albertson [ 27/Jun/22 ]

Ideally, it'd be great if libmongoc or libmongocrypt could provide some global API (not tied to a client/pool) that allowed applications or query the crypt_shared version.

I am not sure if that is possible. crypt_shared is dynamically linked at runtime. It will not be linked until a mongoc_client_t or mongoc_client_pool_t is created with auto encryption options.

I think it is OK to add an API on mongoc_client_t or mongoc_client_pool_t. jmikola@mongodb.com would this API be sufficient?

// Returns shared library version string. Returns NULL if not loaded or not found.
const char* mongoc_client_crypt_shared_lib_version_string (mongoc_client_t* client);
 
// Returns shared library version string. Returns NULL if not loaded or not found.
const char* mongoc_client_pool_crypt_shared_lib_version_string (mongoc_client_pool_t* pool);

Generated at Wed Feb 07 21:20:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.