11
11
KEY_VAULT_COLLECTION_NAME = "__keyVault"
12
12
13
13
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
+
14
34
def get_kms_providers ():
15
35
"""
16
36
Return supported KMS providers for MongoDB Client-Side Field Level Encryption (CSFLE).
@@ -22,16 +42,7 @@ def get_kms_providers():
22
42
}
23
43
24
44
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 ()
35
46
36
47
37
48
def get_key_vault_namespace (
@@ -44,6 +55,18 @@ def get_key_vault_namespace(
44
55
KEY_VAULT_NAMESPACE = get_key_vault_namespace ()
45
56
46
57
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
+
47
70
def get_auto_encryption_opts (
48
71
key_vault_namespace = KEY_VAULT_NAMESPACE , crypt_shared_lib_path = None , kms_providers = None
49
72
):
@@ -56,23 +79,3 @@ def get_auto_encryption_opts(
56
79
kms_providers = kms_providers ,
57
80
crypt_shared_lib_path = crypt_shared_lib_path ,
58
81
)
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