1111KEY_VAULT_COLLECTION_NAME = "__keyVault"
1212
1313
14+ def get_customer_master_key ():
15+ """
16+ Returns a 96-byte local master key for use with MongoDB Client-Side Field Level
17+ Encryption (CSFLE). For local testing purposes only. In production, use a secure KMS
18+ like AWS, Azure, GCP, or KMIP.
19+ Returns:
20+ bytes: A 96-byte key.
21+ """
22+ # WARNING: This is a static key for testing only.
23+ # Generate with: os.urandom(96)
24+ return bytes .fromhex (
25+ "000102030405060708090a0b0c0d0e0f"
26+ "101112131415161718191a1b1c1d1e1f"
27+ "202122232425262728292a2b2c2d2e2f"
28+ "303132333435363738393a3b3c3d3e3f"
29+ "404142434445464748494a4b4c4d4e4f"
30+ "505152535455565758595a5b5c5d5e5f"
31+ )
32+
33+
1434def get_kms_providers ():
1535 """
1636 Return supported KMS providers for MongoDB Client-Side Field Level Encryption (CSFLE).
@@ -22,16 +42,7 @@ def get_kms_providers():
2242 }
2343
2444
25- def get_client_encryption (client ):
26- """
27- Returns a `ClientEncryption` instance for MongoDB Client-Side Field Level
28- Encryption (CSFLE) that can be used to create an encrypted collection.
29- """
30-
31- key_vault_namespace = get_key_vault_namespace ()
32- kms_providers = get_kms_providers ()
33- codec_options = CodecOptions (uuid_representation = STANDARD )
34- return ClientEncryption (kms_providers , key_vault_namespace , client , codec_options )
45+ KMS_PROVIDERS = get_kms_providers ()
3546
3647
3748def get_key_vault_namespace (
@@ -44,6 +55,18 @@ def get_key_vault_namespace(
4455KEY_VAULT_NAMESPACE = get_key_vault_namespace ()
4556
4657
58+ def get_client_encryption (
59+ client , key_vault_namespace = KEY_VAULT_NAMESPACE , kms_providers = KMS_PROVIDERS
60+ ):
61+ """
62+ Returns a `ClientEncryption` instance for MongoDB Client-Side Field Level
63+ Encryption (CSFLE) that can be used to create an encrypted collection.
64+ """
65+
66+ codec_options = CodecOptions (uuid_representation = STANDARD )
67+ return ClientEncryption (kms_providers , key_vault_namespace , client , codec_options )
68+
69+
4770def get_auto_encryption_opts (
4871 key_vault_namespace = KEY_VAULT_NAMESPACE , crypt_shared_lib_path = None , kms_providers = None
4972):
@@ -56,23 +79,3 @@ def get_auto_encryption_opts(
5679 kms_providers = kms_providers ,
5780 crypt_shared_lib_path = crypt_shared_lib_path ,
5881 )
59-
60-
61- def get_customer_master_key ():
62- """
63- Returns a 96-byte local master key for use with MongoDB Client-Side Field Level
64- Encryption (CSFLE). For local testing purposes only. In production, use a secure KMS
65- like AWS, Azure, GCP, or KMIP.
66- Returns:
67- bytes: A 96-byte key.
68- """
69- # WARNING: This is a static key for testing only.
70- # Generate with: os.urandom(96)
71- return bytes .fromhex (
72- "000102030405060708090a0b0c0d0e0f"
73- "101112131415161718191a1b1c1d1e1f"
74- "202122232425262728292a2b2c2d2e2f"
75- "303132333435363738393a3b3c3d3e3f"
76- "404142434445464748494a4b4c4d4e4f"
77- "505152535455565758595a5b5c5d5e5f"
78- )
0 commit comments