Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
terakilobyte committed Nov 15, 2019
1 parent 4629a93 commit 8653c55
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions python/clients.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,77 @@

from pymongo import MongoClient
from pymongo.encryption_options import AutoEncryptionOpts
from bson.binary import Binary
from bson import json_util
from bson.binary import Binary, UUID


"""
This file is meant to be run to demonstrate CSFLE in action. Prior to running
this file, ensure you've run make-local-data-key.py
"""

patient_schema = """
{
"medicalRecords.patients": {
"bsonType": "object",
"encryptMetadata": {
"keyId": [
{
"$binary": "9bF6oNFqTMqtTdAIYtjTFg==",
"subType": "04"
}
]
},
"properties": {
"insurance": {
"bsonType": "object",
"properties": {
"policyNumber": {
"encrypt": {
"bsonType": "int",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
}
}
}
},
"medicalRecords": {
"encrypt": {
"bsonType": "array",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random",
}
},
"bloodType": {
"encrypt": {
"bsonType": "string",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
}
},
"ssn": {
"encrypt": {
"bsonType": "int",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
}
}
}
}
}
"""

def get_patient_schema(key):
bin_key = Binary(data=key['_id'].bytes, subtype=4)

def get_patient_schema(key=None):
# bin_key = Binary(
# data=key.bytes, subtype=4)
# print('BIN_KEY', bin_key)
return {
"medicalRecords.patients": {
"bsonType": "object",
"encryptMetadata": {
"keyId": [bin_key]
"keyId": [
{
"$binary": "9bF6oNFqTMqtTdAIYtjTFg==",
"subType": "04"
}
]
},
"properties": {
"insurance": {
Expand Down Expand Up @@ -75,7 +130,7 @@ def get_patient_schema(key):
fle_opts = AutoEncryptionOpts(
kms_providers,
key_vault_namespace,
schema_map=get_patient_schema(key),
schema_map=json_util.loads(patient_schema)
# uncomment below if you've started mongocryptd in its own process
# mongocryptd_bypass_spawn=True
)
Expand Down

0 comments on commit 8653c55

Please sign in to comment.