├── csfle ├── python │ ├── aws │ │ └── reader │ │ │ ├── requirements.txt │ │ │ ├── your_credentials.py │ │ │ ├── make_data_key.py │ │ │ └── insert_encrypted_document.py │ ├── azure │ │ └── reader │ │ │ ├── requirements.txt │ │ │ ├── your_credentials.py │ │ │ ├── make_data_key.py │ │ │ └── insert_encrypted_document.py │ ├── gcp │ │ └── reader │ │ │ ├── requirements.txt │ │ │ ├── your_credentials.py │ │ │ ├── make_data_key.py │ │ │ └── insert_encrypted_document.py │ ├── kmip │ │ └── reader │ │ │ ├── requirements.txt │ │ │ ├── your_credentials.py │ │ │ └── make_data_key.py │ └── local │ │ └── reader │ │ ├── requirements.txt │ │ ├── your_credentials.py │ │ ├── make_data_key.py │ │ └── insert_encrypted_document.py ├── go │ ├── aws │ │ └── reader │ │ │ ├── main.go │ │ │ ├── go.mod │ │ │ ├── your-credentials.go │ │ │ └── make-data-key.go │ ├── azure │ │ └── reader │ │ │ ├── main.go │ │ │ ├── go.mod │ │ │ ├── your-credentials.go │ │ │ └── make-data-key.go │ ├── gcp │ │ └── reader │ │ │ ├── main.go │ │ │ ├── go.mod │ │ │ ├── your-credentials.go │ │ │ └── make-data-key.go │ ├── kmip │ │ └── reader │ │ │ ├── main.go │ │ │ ├── go.mod │ │ │ ├── your-credentials.go │ │ │ └── make-data-key.go │ └── local │ │ └── reader │ │ ├── main.go │ │ ├── go.mod │ │ ├── your-credentials.go │ │ └── make-data-key.go ├── dotnet │ ├── aws │ │ └── reader │ │ │ └── CSFLE │ │ │ ├── Program.cs │ │ │ ├── CSFLE.csproj │ │ │ └── YourCredentials.cs │ ├── gcp │ │ └── reader │ │ │ └── CSFLE │ │ │ ├── Program.cs │ │ │ ├── CSFLE.csproj │ │ │ └── YourCredentials.cs │ ├── kmip │ │ └── reader │ │ │ └── CSFLE │ │ │ ├── Program.cs │ │ │ ├── CSFLE.csproj │ │ │ └── YourCredentials.cs │ ├── azure │ │ └── reader │ │ │ └── CSFLE │ │ │ ├── Program.cs │ │ │ ├── CSFLE.csproj │ │ │ └── YourCredentials.cs │ └── local │ │ └── reader │ │ └── CSFLE │ │ ├── Program.cs │ │ ├── CSFLE.csproj │ │ └── YourCredentials.cs ├── node │ ├── aws │ │ └── reader │ │ │ ├── package.json │ │ │ ├── your_credentials.js │ │ │ ├── make_data_key.js │ │ │ └── insert_encrypted_document.js │ ├── azure │ │ └── reader │ │ │ ├── package.json │ │ │ ├── your_credentials.js │ │ │ └── make_data_key.js │ ├── gcp │ │ └── reader │ │ │ ├── package.json │ │ │ ├── your_credentials.js │ │ │ ├── make_data_key.js │ │ │ └── insert_encrypted_document.js │ ├── kmip │ │ └── reader │ │ │ ├── package.json │ │ │ ├── your_credentials.js │ │ │ └── make_data_key.js │ └── local │ │ └── reader │ │ ├── package.json │ │ ├── your_credentials.js │ │ └── make_data_key.js └── java │ ├── aws │ └── reader │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── mongodb │ │ └── csfle │ │ └── YourCredentials.java │ ├── azure │ └── reader │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── mongodb │ │ └── csfle │ │ └── YourCredentials.java │ ├── gcp │ └── reader │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── mongodb │ │ └── csfle │ │ └── YourCredentials.java │ ├── kmip │ └── reader │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── mongodb │ │ └── csfle │ │ └── YourCredentials.java │ └── local │ └── reader │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── mongodb │ └── csfle │ └── YourCredentials.java ├── queryable-encryption ├── python │ ├── aws │ │ └── reader │ │ │ ├── requirements.txt │ │ │ └── your_credentials.py │ ├── azure │ │ └── reader │ │ │ ├── requirements.txt │ │ │ └── your_credentials.py │ ├── exp │ │ └── reader │ │ │ ├── requirements.txt │ │ │ ├── your_credentials.py │ │ │ └── insert_encrypted_document.py │ ├── gcp │ │ └── reader │ │ │ ├── requirements.txt │ │ │ └── your_credentials.py │ ├── kmip │ │ └── reader │ │ │ ├── requirements.txt │ │ │ └── your_credentials.py │ └── local │ │ └── reader │ │ ├── requirements.txt │ │ └── your_credentials.py ├── go │ ├── aws │ │ └── reader │ │ │ ├── go.mod │ │ │ ├── main.go │ │ │ └── your-credentials.go │ ├── azure │ │ └── reader │ │ │ ├── go.mod │ │ │ ├── main.go │ │ │ └── your-credentials.go │ ├── exp │ │ └── reader │ │ │ ├── go.mod │ │ │ ├── main.go │ │ │ └── your-credentials.go │ ├── gcp │ │ └── reader │ │ │ ├── go.mod │ │ │ ├── main.go │ │ │ └── your-credentials.go │ ├── kmip │ │ └── reader │ │ │ ├── go.mod │ │ │ ├── main.go │ │ │ └── your-credentials.go │ └── local │ │ └── reader │ │ ├── go.mod │ │ ├── main.go │ │ └── your-credentials.go ├── node │ ├── aws │ │ └── reader │ │ │ ├── package.json │ │ │ └── your_credentials.js │ ├── exp │ │ └── reader │ │ │ ├── package.json │ │ │ ├── your_credentials.js │ │ │ └── insert_encrypted_document.js │ ├── gcp │ │ └── reader │ │ │ ├── package.json │ │ │ └── your_credentials.js │ ├── azure │ │ └── reader │ │ │ ├── package.json │ │ │ └── your_credentials.js │ ├── kmip │ │ └── reader │ │ │ ├── package.json │ │ │ └── your_credentials.js │ └── local │ │ └── reader │ │ ├── package.json │ │ └── your_credentials.js ├── dotnet │ ├── aws │ │ └── reader │ │ │ └── QueryableEncryption │ │ │ ├── Program.cs │ │ │ ├── QueryableEncryption.csproj │ │ │ └── YourCredentials.cs │ ├── azure │ │ └── reader │ │ │ └── QueryableEncryption │ │ │ ├── Program.cs │ │ │ ├── QueryableEncryption.csproj │ │ │ └── YourCredentials.cs │ ├── exp │ │ └── reader │ │ │ └── QueryableEncryption │ │ │ ├── Program.cs │ │ │ ├── QueryableEncryption.csproj │ │ │ └── YourCredentials.cs │ ├── gcp │ │ └── reader │ │ │ └── QueryableEncryption │ │ │ ├── Program.cs │ │ │ ├── QueryableEncryption.csproj │ │ │ └── YourCredentials.cs │ ├── kmip │ │ └── reader │ │ │ └── QueryableEncryption │ │ │ ├── Program.cs │ │ │ ├── QueryableEncryption.csproj │ │ │ └── YourCredentials.cs │ └── local │ │ └── reader │ │ └── QueryableEncryption │ │ ├── Program.cs │ │ ├── QueryableEncryption.csproj │ │ └── YourCredentials.cs ├── java │ ├── kmip │ │ └── reader │ │ │ ├── pom.xml │ │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── mongodb │ │ │ └── qe │ │ │ └── YourCredentials.java │ ├── aws │ │ └── reader │ │ │ ├── pom.xml │ │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── mongodb │ │ │ └── qe │ │ │ └── YourCredentials.java │ ├── gcp │ │ └── reader │ │ │ ├── pom.xml │ │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── mongodb │ │ │ └── qe │ │ │ └── YourCredentials.java │ ├── azure │ │ └── reader │ │ │ ├── pom.xml │ │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── mongodb │ │ │ └── qe │ │ │ └── YourCredentials.java │ ├── exp │ │ └── reader │ │ │ ├── pom.xml │ │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── mongodb │ │ │ └── qe │ │ │ └── YourCredentials.java │ └── local │ │ └── reader │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── mongodb │ │ └── qe │ │ └── YourCredentials.java └── mongosh │ ├── local │ └── reader │ │ └── your_credentials.js │ ├── aws │ └── reader │ │ └── your_credentials.js │ ├── gcp │ └── reader │ │ └── your_credentials.js │ ├── azure │ └── reader │ │ └── your_credentials.js │ └── kmip │ └── reader │ └── your_credentials.js └── README.md /csfle/python/aws/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /csfle/python/azure/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /csfle/python/gcp/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /csfle/python/kmip/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /csfle/python/local/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /queryable-encryption/python/aws/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /queryable-encryption/python/azure/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /queryable-encryption/python/exp/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /queryable-encryption/python/gcp/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /queryable-encryption/python/kmip/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /queryable-encryption/python/local/reader/requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | pymongocrypt 3 | -------------------------------------------------------------------------------- /queryable-encryption/go/aws/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require go.mongodb.org/mongo-driver v1.10.3 6 | -------------------------------------------------------------------------------- /queryable-encryption/go/azure/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require go.mongodb.org/mongo-driver v1.10.3 6 | -------------------------------------------------------------------------------- /queryable-encryption/go/exp/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require go.mongodb.org/mongo-driver v1.10.3 6 | -------------------------------------------------------------------------------- /queryable-encryption/go/gcp/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require go.mongodb.org/mongo-driver v1.10.3 6 | -------------------------------------------------------------------------------- /queryable-encryption/go/kmip/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require go.mongodb.org/mongo-driver v1.10.3 6 | -------------------------------------------------------------------------------- /queryable-encryption/go/local/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require go.mongodb.org/mongo-driver v1.10.3 6 | -------------------------------------------------------------------------------- /queryable-encryption/node/aws/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mongodb": "^4.9.0", 4 | "mongodb-client-encryption": "^2.2.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /queryable-encryption/node/exp/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mongodb": "^4.9.0", 4 | "mongodb-client-encryption": "^2.2.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /queryable-encryption/node/gcp/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mongodb": "^4.9.0", 4 | "mongodb-client-encryption": "^2.2.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /queryable-encryption/node/azure/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mongodb": "^4.9.0", 4 | "mongodb-client-encryption": "^2.2.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /queryable-encryption/node/kmip/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mongodb": "^4.9.0", 4 | "mongodb-client-encryption": "^2.2.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /queryable-encryption/node/local/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mongodb": "^4.9.0", 4 | "mongodb-client-encryption": "^2.2.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /csfle/go/aws/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /csfle/go/azure/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /csfle/go/gcp/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /csfle/go/kmip/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /csfle/go/local/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /queryable-encryption/go/aws/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /queryable-encryption/go/azure/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /queryable-encryption/go/exp/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /queryable-encryption/go/gcp/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /queryable-encryption/go/kmip/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /queryable-encryption/go/local/reader/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | func main() { 8 | err := MakeKey() 9 | if err != nil { 10 | log.Fatal(err) 11 | } 12 | err = Insert() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /csfle/dotnet/aws/reader/CSFLE/Program.cs: -------------------------------------------------------------------------------- 1 | using Insert; 2 | using Key; 3 | 4 | namespace Run 5 | { 6 | class Run 7 | { 8 | static void Main(string[] args) 9 | { 10 | MakeDataKey.MakeKey(); 11 | InsertEncryptedDocument.Insert(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /csfle/dotnet/gcp/reader/CSFLE/Program.cs: -------------------------------------------------------------------------------- 1 | using Insert; 2 | using Key; 3 | 4 | namespace Run 5 | { 6 | class Run 7 | { 8 | static void Main(string[] args) 9 | { 10 | MakeDataKey.MakeKey(); 11 | InsertEncryptedDocument.Insert(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /csfle/dotnet/kmip/reader/CSFLE/Program.cs: -------------------------------------------------------------------------------- 1 | using Insert; 2 | using Key; 3 | 4 | namespace Run 5 | { 6 | class Run 7 | { 8 | static void Main(string[] args) 9 | { 10 | MakeDataKey.MakeKey(); 11 | InsertEncryptedDocument.Insert(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /csfle/dotnet/azure/reader/CSFLE/Program.cs: -------------------------------------------------------------------------------- 1 | using Insert; 2 | using Key; 3 | 4 | namespace Run 5 | { 6 | class Run 7 | { 8 | static void Main(string[] args) 9 | { 10 | MakeDataKey.MakeKey(); 11 | InsertEncryptedDocument.Insert(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /csfle/dotnet/local/reader/CSFLE/Program.cs: -------------------------------------------------------------------------------- 1 | using Insert; 2 | using Key; 3 | 4 | namespace Run 5 | { 6 | class Run 7 | { 8 | static void Main(string[] args) 9 | { 10 | MakeDataKey.MakeKey(); 11 | InsertEncryptedDocument.Insert(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/aws/reader/QueryableEncryption/Program.cs: -------------------------------------------------------------------------------- 1 | namespace QueryableEncryption 2 | { 3 | internal static class Run 4 | { 5 | private static void Main(string[] args) 6 | { 7 | MakeDataKey.MakeKey(); 8 | InsertEncryptedDocument.Insert(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/azure/reader/QueryableEncryption/Program.cs: -------------------------------------------------------------------------------- 1 | namespace QueryableEncryption 2 | { 3 | internal static class Run 4 | { 5 | private static void Main(string[] args) 6 | { 7 | MakeDataKey.MakeKey(); 8 | InsertEncryptedDocument.Insert(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/exp/reader/QueryableEncryption/Program.cs: -------------------------------------------------------------------------------- 1 | namespace QueryableEncryption 2 | { 3 | internal static class Run 4 | { 5 | private static void Main(string[] args) 6 | { 7 | MakeDataKey.MakeKey(); 8 | InsertEncryptedDocument.Insert(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/gcp/reader/QueryableEncryption/Program.cs: -------------------------------------------------------------------------------- 1 | namespace QueryableEncryption 2 | { 3 | internal static class Run 4 | { 5 | private static void Main(string[] args) 6 | { 7 | MakeDataKey.MakeKey(); 8 | InsertEncryptedDocument.Insert(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/kmip/reader/QueryableEncryption/Program.cs: -------------------------------------------------------------------------------- 1 | namespace QueryableEncryption 2 | { 3 | internal static class Run 4 | { 5 | private static void Main(string[] args) 6 | { 7 | MakeDataKey.MakeKey(); 8 | InsertEncryptedDocument.Insert(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/local/reader/QueryableEncryption/Program.cs: -------------------------------------------------------------------------------- 1 | namespace QueryableEncryption 2 | { 3 | internal static class Run 4 | { 5 | private static void Main(string[] args) 6 | { 7 | MakeDataKey.MakeKey(); 8 | InsertEncryptedDocument.Insert(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /csfle/dotnet/aws/reader/CSFLE/CSFLE.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /csfle/dotnet/gcp/reader/CSFLE/CSFLE.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /csfle/dotnet/azure/reader/CSFLE/CSFLE.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /csfle/dotnet/kmip/reader/CSFLE/CSFLE.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /csfle/dotnet/local/reader/CSFLE/CSFLE.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /csfle/go/aws/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/aws/aws-sdk-go v1.34.28 // indirect 7 | github.com/fatih/structs v1.1.0 8 | github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect 9 | github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect 10 | go.mongodb.org/mongo-driver v1.10.1 11 | ) 12 | -------------------------------------------------------------------------------- /csfle/go/azure/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/aws/aws-sdk-go v1.34.28 // indirect 7 | github.com/fatih/structs v1.1.0 8 | github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect 9 | github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect 10 | go.mongodb.org/mongo-driver v1.10.1 11 | ) 12 | -------------------------------------------------------------------------------- /csfle/go/gcp/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/aws/aws-sdk-go v1.34.28 // indirect 7 | github.com/fatih/structs v1.1.0 8 | github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect 9 | github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect 10 | go.mongodb.org/mongo-driver v1.10.1 11 | ) 12 | -------------------------------------------------------------------------------- /csfle/go/kmip/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/aws/aws-sdk-go v1.34.28 // indirect 7 | github.com/fatih/structs v1.1.0 8 | github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect 9 | github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect 10 | go.mongodb.org/mongo-driver v1.10.1 11 | ) 12 | -------------------------------------------------------------------------------- /csfle/go/local/reader/go.mod: -------------------------------------------------------------------------------- 1 | module goCsfle 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/aws/aws-sdk-go v1.34.28 // indirect 7 | github.com/fatih/structs v1.1.0 8 | github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect 9 | github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect 10 | go.mongodb.org/mongo-driver v1.10.1 11 | ) 12 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/aws/reader/QueryableEncryption/QueryableEncryption.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/exp/reader/QueryableEncryption/QueryableEncryption.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/gcp/reader/QueryableEncryption/QueryableEncryption.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/azure/reader/QueryableEncryption/QueryableEncryption.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/kmip/reader/QueryableEncryption/QueryableEncryption.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/local/reader/QueryableEncryption/QueryableEncryption.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # In Use Encryption Sample Applications 2 | 3 | This repo contains sample applications that show how to use MongoDB's In-Use Encryption products: Queryable Encryption and Client-Side Field Level Encryption. 4 | 5 | This repository contains sample applications detailing how to use Queryable Encryption and Client-Side Field Level Encryption with all combinations of the following MongoDB Language Drivers and Key Management Service Providers: 6 | 7 | ## MongoDB Language Drivers: 8 | 9 | - Python 10 | - Java Sync 11 | - Node.js 12 | - Go 13 | - C#/Dotnet 14 | 15 | ## KMS Providers: 16 | 17 | - Amazon Web Services Key Management Service 18 | - Azure Key Vault 19 | - Google Cloud Key Management Service 20 | - Local Key Provider 21 | 22 | # About this Repo 23 | 24 | This repository is automatically generated. Please do not submit Pull Requests directly to this repository. 25 | -------------------------------------------------------------------------------- /queryable-encryption/java/kmip/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-QE-guide 4 | 1.0-SNAPSHOT 5 | 6 | 7 | 1.8 8 | 1.8 9 | 10 | 11 | 12 | 13 | 14 | org.mongodb 15 | mongodb-driver-sync 16 | 4.7.1 17 | 18 | 19 | 20 | org.mongodb 21 | mongodb-crypt 22 | 1.5.2 23 | 24 | 25 | 26 | 27 | 28 | ${project.artifactId} 29 | 30 | 31 | -------------------------------------------------------------------------------- /csfle/node/aws/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csfle", 3 | "version": "1.0.0", 4 | "description": "A sample implementation of field level encryption in MongoDB, meant to accompany the CSFLE guide at https://www.mongodb.com/docs/drivers/security/client-side-field-level-encryption-guide/", 5 | "main": "clients.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/mongodb-university/csfle-guides.git" 12 | }, 13 | "author": "Developer Education Team", 14 | "license": "Apache-2.0", 15 | "bugs": { 16 | "url": "https://github.com/mongodb-university/csfle-guides/issues" 17 | }, 18 | "homepage": "https://github.com/mongodb-university/csfle-guides#readme", 19 | "dependencies": { 20 | "dotenv": "^8.2.0", 21 | "mongodb": "^6.0.0", 22 | "mongodb-client-encryption": "^6.0.0" 23 | }, 24 | "prettier": { 25 | "semi": true 26 | }, 27 | "devDependencies": { 28 | "eslint": "^7.15.0", 29 | "prettier": "^2.2.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /csfle/node/azure/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csfle", 3 | "version": "1.0.0", 4 | "description": "A sample implementation of field level encryption in MongoDB, meant to accompany the CSFLE guide at https://www.mongodb.com/docs/drivers/security/client-side-field-level-encryption-guide/", 5 | "main": "clients.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/mongodb-university/csfle-guides.git" 12 | }, 13 | "author": "Developer Education Team", 14 | "license": "Apache-2.0", 15 | "bugs": { 16 | "url": "https://github.com/mongodb-university/csfle-guides/issues" 17 | }, 18 | "homepage": "https://github.com/mongodb-university/csfle-guides#readme", 19 | "dependencies": { 20 | "dotenv": "^8.2.0", 21 | "mongodb": "^6.0.0", 22 | "mongodb-client-encryption": "^6.0.0" 23 | }, 24 | "prettier": { 25 | "semi": true 26 | }, 27 | "devDependencies": { 28 | "eslint": "^7.15.0", 29 | "prettier": "^2.2.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /csfle/node/gcp/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csfle", 3 | "version": "1.0.0", 4 | "description": "A sample implementation of field level encryption in MongoDB, meant to accompany the CSFLE guide at https://www.mongodb.com/docs/drivers/security/client-side-field-level-encryption-guide/", 5 | "main": "clients.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/mongodb-university/csfle-guides.git" 12 | }, 13 | "author": "Developer Education Team", 14 | "license": "Apache-2.0", 15 | "bugs": { 16 | "url": "https://github.com/mongodb-university/csfle-guides/issues" 17 | }, 18 | "homepage": "https://github.com/mongodb-university/csfle-guides#readme", 19 | "dependencies": { 20 | "dotenv": "^8.2.0", 21 | "mongodb": "^6.0.0", 22 | "mongodb-client-encryption": "^6.0.0" 23 | }, 24 | "prettier": { 25 | "semi": true 26 | }, 27 | "devDependencies": { 28 | "eslint": "^7.15.0", 29 | "prettier": "^2.2.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /csfle/node/kmip/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csfle", 3 | "version": "1.0.0", 4 | "description": "A sample implementation of field level encryption in MongoDB, meant to accompany the CSFLE guide at https://www.mongodb.com/docs/drivers/security/client-side-field-level-encryption-guide/", 5 | "main": "clients.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/mongodb-university/csfle-guides.git" 12 | }, 13 | "author": "Developer Education Team", 14 | "license": "Apache-2.0", 15 | "bugs": { 16 | "url": "https://github.com/mongodb-university/csfle-guides/issues" 17 | }, 18 | "homepage": "https://github.com/mongodb-university/csfle-guides#readme", 19 | "dependencies": { 20 | "dotenv": "^8.2.0", 21 | "mongodb": "^6.0.0", 22 | "mongodb-client-encryption": "^6.0.0" 23 | }, 24 | "prettier": { 25 | "semi": true 26 | }, 27 | "devDependencies": { 28 | "eslint": "^7.15.0", 29 | "prettier": "^2.2.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /csfle/node/local/reader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csfle", 3 | "version": "1.0.0", 4 | "description": "A sample implementation of field level encryption in MongoDB, meant to accompany the CSFLE guide at https://www.mongodb.com/docs/drivers/security/client-side-field-level-encryption-guide/", 5 | "main": "clients.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/mongodb-university/csfle-guides.git" 12 | }, 13 | "author": "Developer Education Team", 14 | "license": "Apache-2.0", 15 | "bugs": { 16 | "url": "https://github.com/mongodb-university/csfle-guides/issues" 17 | }, 18 | "homepage": "https://github.com/mongodb-university/csfle-guides#readme", 19 | "dependencies": { 20 | "dotenv": "^8.2.0", 21 | "mongodb": "^6.0.0", 22 | "mongodb-client-encryption": "^6.0.0" 23 | }, 24 | "prettier": { 25 | "semi": true 26 | }, 27 | "devDependencies": { 28 | "eslint": "^7.15.0", 29 | "prettier": "^2.2.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /csfle/java/aws/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-CSFLE-guide 4 | Java-CSFLE-guide-AWS 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.4.0 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /csfle/java/azure/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-CSFLE-guide 4 | Java-CSFLE-guide-Azure 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.4.0 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /csfle/java/gcp/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-CSFLE-guide 4 | Java-CSFLE-guide-GCP 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.4.0 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /csfle/java/kmip/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-CSFLE-guide 4 | Java-CSFLE-guide-KMIP 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.4.0 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /csfle/java/local/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-CSFLE-guide 4 | Java-CSFLE-guide-Local 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.4.0 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /queryable-encryption/java/aws/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-QE-guide 4 | Java-QE-guide-AWS 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.7.1 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /queryable-encryption/java/gcp/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-QE-guide 4 | Java-QE-guide-GCP 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.7.1 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /queryable-encryption/java/azure/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-QE-guide 4 | Java-QE-guide-Azure 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.7.1 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /queryable-encryption/java/exp/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-QE-guide 4 | Java-QE-guide-Explicit 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.7.1 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /queryable-encryption/java/local/reader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | Java-QE-guide 4 | Java-QE-guide-Local 5 | 1.0-SNAPSHOT 6 | 7 | 8 | 1.8 9 | 1.8 10 | 11 | 12 | 13 | 14 | 15 | org.mongodb 16 | mongodb-driver-sync 17 | 4.7.1 18 | 19 | 20 | 21 | org.mongodb 22 | mongodb-crypt 23 | 1.5.2 24 | 25 | 26 | 27 | 28 | 29 | ${project.artifactId} 30 | 31 | 32 | -------------------------------------------------------------------------------- /queryable-encryption/go/exp/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | } 15 | 16 | // check if credentials object contains placeholder values 17 | func check_for_placeholders() { 18 | var error_buffer []string 19 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 20 | for key, value := range credentials { 21 | // check for placeholder text 22 | if placeholder_pattern.MatchString(string(value)) { 23 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 24 | error_buffer = append(error_buffer, error_message) 25 | } 26 | } 27 | // raise an error if errors in buffer 28 | if len(error_buffer) > 0 { 29 | message := strings.Join(error_buffer[:], "\n") 30 | log.Fatal(message) 31 | } 32 | } 33 | 34 | // return credentials object and ensure it has been populated 35 | func GetCredentials() map[string]string { 36 | check_for_placeholders() 37 | return credentials 38 | } 39 | -------------------------------------------------------------------------------- /queryable-encryption/go/local/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | } 15 | 16 | // check if credentials object contains placeholder values 17 | func check_for_placeholders() { 18 | var error_buffer []string 19 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 20 | for key, value := range credentials { 21 | // check for placeholder text 22 | if placeholder_pattern.MatchString(string(value)) { 23 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 24 | error_buffer = append(error_buffer, error_message) 25 | } 26 | } 27 | // raise an error if errors in buffer 28 | if len(error_buffer) > 0 { 29 | message := strings.Join(error_buffer[:], "\n") 30 | log.Fatal(message) 31 | } 32 | } 33 | 34 | // return credentials object and ensure it has been populated 35 | func GetCredentials() map[string]string { 36 | check_for_placeholders() 37 | return credentials 38 | } 39 | -------------------------------------------------------------------------------- /csfle/go/local/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | } 15 | 16 | // check if credentials object contains placeholder values 17 | func check_for_placeholders() { 18 | var error_buffer []string 19 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 20 | for key, value := range credentials { 21 | // check for placeholder text 22 | if placeholder_pattern.MatchString(string(value)) { 23 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 24 | error_buffer = append(error_buffer, error_message) 25 | } 26 | } 27 | // raise an error if errors in buffer 28 | if len(error_buffer) > 0 { 29 | message := strings.Join(error_buffer[:], "\n") 30 | log.Fatal(message) 31 | } 32 | } 33 | 34 | // return credentials object and ensure it has been populated 35 | func GetCredentials() map[string]string { 36 | check_for_placeholders() 37 | return credentials 38 | } 39 | -------------------------------------------------------------------------------- /queryable-encryption/mongosh/local/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | }; 13 | 14 | /* 15 | check if credentials object contains placeholder values 16 | **/ 17 | function checkForPlaceholders() { 18 | const errorBuffer = Array(); 19 | const placeholderPattern = /^<.*>$/; 20 | for (const [key, value] of Object.entries(credentials)) { 21 | // check for placeholder text 22 | if (`${value}`.match(placeholderPattern)) { 23 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 24 | errorBuffer.push(errorMessage); 25 | } 26 | // check if value is empty 27 | else if (value == undefined) { 28 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 29 | } 30 | } 31 | // raise an error if errors in buffer 32 | if (errorBuffer.length > 0) { 33 | message = errorBuffer.join("\n"); 34 | throw message; 35 | } 36 | } 37 | 38 | module.exports = { getCredentials }; 39 | -------------------------------------------------------------------------------- /queryable-encryption/node/exp/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: "", 13 | }; 14 | 15 | /* 16 | check if credentials object contains placeholder values 17 | **/ 18 | function checkForPlaceholders() { 19 | const errorBuffer = Array(); 20 | const placeholderPattern = /^<.*>$/; 21 | for (const [key, value] of Object.entries(credentials)) { 22 | // check for placeholder text 23 | if (`${value}`.match(placeholderPattern)) { 24 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 25 | errorBuffer.push(errorMessage); 26 | } 27 | // check if value is empty 28 | else if (value == undefined) { 29 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 30 | } 31 | } 32 | // raise an error if errors in buffer 33 | if (errorBuffer.length > 0) { 34 | message = errorBuffer.join("\n"); 35 | throw message; 36 | } 37 | } 38 | 39 | module.exports = { getCredentials }; 40 | -------------------------------------------------------------------------------- /queryable-encryption/node/local/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: "", 13 | }; 14 | 15 | /* 16 | check if credentials object contains placeholder values 17 | **/ 18 | function checkForPlaceholders() { 19 | const errorBuffer = Array(); 20 | const placeholderPattern = /^<.*>$/; 21 | for (const [key, value] of Object.entries(credentials)) { 22 | // check for placeholder text 23 | if (`${value}`.match(placeholderPattern)) { 24 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 25 | errorBuffer.push(errorMessage); 26 | } 27 | // check if value is empty 28 | else if (value == undefined) { 29 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 30 | } 31 | } 32 | // raise an error if errors in buffer 33 | if (errorBuffer.length > 0) { 34 | message = errorBuffer.join("\n"); 35 | throw message; 36 | } 37 | } 38 | 39 | module.exports = { getCredentials }; 40 | -------------------------------------------------------------------------------- /queryable-encryption/python/exp/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | } 8 | 9 | 10 | def check_for_placeholders(): 11 | """check if credentials object contains placeholder values""" 12 | error_buffer = [] 13 | placeholder_pattern = re.compile("^<.*>$") 14 | for key, value in _credentials.items(): 15 | # check for placeholder text 16 | if placeholder_pattern.match(str(value)): 17 | error_message = ( 18 | f"You must fill out the {key} field of your credentials object." 19 | ) 20 | error_buffer.append(error_message) 21 | # check if value is empty 22 | elif not value: 23 | error_message = ( 24 | f"The value for {key} is empty. Please enter something for this value." 25 | ) 26 | # raise an error if errors in buffer 27 | if error_buffer: 28 | message = "\n".join(error_buffer) 29 | raise ValueError(message) 30 | 31 | 32 | def get_credentials(): 33 | """return credentials object and ensure it has been populated""" 34 | check_for_placeholders() 35 | return _credentials 36 | -------------------------------------------------------------------------------- /queryable-encryption/python/local/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | } 8 | 9 | 10 | def check_for_placeholders(): 11 | """check if credentials object contains placeholder values""" 12 | error_buffer = [] 13 | placeholder_pattern = re.compile("^<.*>$") 14 | for key, value in _credentials.items(): 15 | # check for placeholder text 16 | if placeholder_pattern.match(str(value)): 17 | error_message = ( 18 | f"You must fill out the {key} field of your credentials object." 19 | ) 20 | error_buffer.append(error_message) 21 | # check if value is empty 22 | elif not value: 23 | error_message = ( 24 | f"The value for {key} is empty. Please enter something for this value." 25 | ) 26 | # raise an error if errors in buffer 27 | if error_buffer: 28 | message = "\n".join(error_buffer) 29 | raise ValueError(message) 30 | 31 | 32 | def get_credentials(): 33 | """return credentials object and ensure it has been populated""" 34 | check_for_placeholders() 35 | return _credentials 36 | -------------------------------------------------------------------------------- /csfle/node/local/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: 13 | "", 14 | }; 15 | 16 | /* 17 | check if credentials object contains placeholder values 18 | **/ 19 | function checkForPlaceholders() { 20 | const errorBuffer = Array(); 21 | const placeholderPattern = /^<.*>$/; 22 | for (const [key, value] of Object.entries(credentials)) { 23 | // check for placeholder text 24 | if (`${value}`.match(placeholderPattern)) { 25 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 26 | errorBuffer.push(errorMessage); 27 | } 28 | // check if value is empty 29 | else if (value == undefined) { 30 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 31 | } 32 | } 33 | // raise an error if errors in buffer 34 | if (errorBuffer.length > 0) { 35 | message = errorBuffer.join("\n"); 36 | throw message; 37 | } 38 | } 39 | 40 | module.exports = { getCredentials }; 41 | -------------------------------------------------------------------------------- /csfle/python/local/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | } 8 | 9 | 10 | def check_for_placeholders(): 11 | """check if credentials object contains placeholder values""" 12 | error_buffer = [] 13 | placeholder_pattern = re.compile("^<.*>$") 14 | for key, value in _credentials.items(): 15 | # check for placeholder text 16 | if placeholder_pattern.match(str(value)): 17 | error_message = ( 18 | f"You must fill out the {key} field of your credentials object." 19 | ) 20 | error_buffer.append(error_message) 21 | # check if value is empty 22 | elif not value: 23 | error_message = ( 24 | f"The value for {key} is empty. Please enter something for this value." 25 | ) 26 | # raise an error if errors in buffer 27 | if error_buffer: 28 | message = "\n".join(error_buffer) 29 | raise ValueError(message) 30 | 31 | 32 | def get_credentials(): 33 | """return credentials object and ensure it has been populated""" 34 | check_for_placeholders() 35 | return _credentials 36 | -------------------------------------------------------------------------------- /queryable-encryption/go/aws/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | // AWS Credentials 15 | "AWS_ACCESS_KEY_ID": "", 16 | "AWS_SECRET_ACCESS_KEY": "", 17 | "AWS_KEY_REGION": "", 18 | "AWS_KEY_ARN": "", 19 | } 20 | 21 | // check if credentials object contains placeholder values 22 | func check_for_placeholders() { 23 | var error_buffer []string 24 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 25 | for key, value := range credentials { 26 | // check for placeholder text 27 | if placeholder_pattern.MatchString(string(value)) { 28 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 29 | error_buffer = append(error_buffer, error_message) 30 | } 31 | } 32 | // raise an error if errors in buffer 33 | if len(error_buffer) > 0 { 34 | message := strings.Join(error_buffer[:], "\n") 35 | log.Fatal(message) 36 | } 37 | } 38 | 39 | // return credentials object and ensure it has been populated 40 | func GetCredentials() map[string]string { 41 | check_for_placeholders() 42 | return credentials 43 | } 44 | -------------------------------------------------------------------------------- /csfle/go/aws/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | // AWS Credentials 15 | "AWS_ACCESS_KEY_ID": "", 16 | "AWS_SECRET_ACCESS_KEY": "", 17 | "AWS_KEY_REGION": "", 18 | "AWS_KEY_ARN": "", 19 | } 20 | 21 | // check if credentials object contains placeholder values 22 | func check_for_placeholders() { 23 | var error_buffer []string 24 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 25 | for key, value := range credentials { 26 | // check for placeholder text 27 | if placeholder_pattern.MatchString(string(value)) { 28 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 29 | error_buffer = append(error_buffer, error_message) 30 | } 31 | } 32 | // raise an error if errors in buffer 33 | if len(error_buffer) > 0 { 34 | message := strings.Join(error_buffer[:], "\n") 35 | log.Fatal(message) 36 | } 37 | } 38 | 39 | // return credentials object and ensure it has been populated 40 | func GetCredentials() map[string]string { 41 | check_for_placeholders() 42 | return credentials 43 | } 44 | -------------------------------------------------------------------------------- /queryable-encryption/mongosh/aws/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | 13 | // AWS Credentials 14 | AWS_ACCESS_KEY_ID: "", 15 | AWS_SECRET_ACCESS_KEY: "", 16 | AWS_KEY_REGION: "", 17 | AWS_KEY_ARN: "", 18 | }; 19 | 20 | /* 21 | check if credentials object contains placeholder values 22 | **/ 23 | function checkForPlaceholders() { 24 | const errorBuffer = Array(); 25 | const placeholderPattern = /^<.*>$/; 26 | for (const [key, value] of Object.entries(credentials)) { 27 | // check for placeholder text 28 | if (`${value}`.match(placeholderPattern)) { 29 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 30 | errorBuffer.push(errorMessage); 31 | } 32 | // check if value is empty 33 | else if (value == undefined) { 34 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 35 | } 36 | } 37 | // raise an error if errors in buffer 38 | if (errorBuffer.length > 0) { 39 | message = errorBuffer.join("\n"); 40 | throw message; 41 | } 42 | } 43 | 44 | module.exports = { getCredentials }; 45 | -------------------------------------------------------------------------------- /queryable-encryption/go/gcp/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | // GCP Credentials 15 | "GCP_EMAIL": "", 16 | "GCP_PRIVATE_KEY": "", 17 | "GCP_PROJECT_ID": "", 18 | "GCP_LOCATION": "", 19 | "GCP_KEY_RING": "", 20 | "GCP_KEY_NAME": "", 21 | "GCP_KEY_VERSION": "", 22 | } 23 | 24 | // check if credentials object contains placeholder values 25 | func check_for_placeholders() { 26 | var error_buffer []string 27 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 28 | for key, value := range credentials { 29 | // check for placeholder text 30 | if placeholder_pattern.MatchString(string(value)) { 31 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 32 | error_buffer = append(error_buffer, error_message) 33 | } 34 | } 35 | // raise an error if errors in buffer 36 | if len(error_buffer) > 0 { 37 | message := strings.Join(error_buffer[:], "\n") 38 | log.Fatal(message) 39 | } 40 | } 41 | 42 | // return credentials object and ensure it has been populated 43 | func GetCredentials() map[string]string { 44 | check_for_placeholders() 45 | return credentials 46 | } 47 | -------------------------------------------------------------------------------- /queryable-encryption/node/aws/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: "", 13 | 14 | // AWS Credentials 15 | AWS_ACCESS_KEY_ID: "", 16 | AWS_SECRET_ACCESS_KEY: "", 17 | AWS_KEY_REGION: "", 18 | AWS_KEY_ARN: "", 19 | }; 20 | 21 | /* 22 | check if credentials object contains placeholder values 23 | **/ 24 | function checkForPlaceholders() { 25 | const errorBuffer = Array(); 26 | const placeholderPattern = /^<.*>$/; 27 | for (const [key, value] of Object.entries(credentials)) { 28 | // check for placeholder text 29 | if (`${value}`.match(placeholderPattern)) { 30 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 31 | errorBuffer.push(errorMessage); 32 | } 33 | // check if value is empty 34 | else if (value == undefined) { 35 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 36 | } 37 | } 38 | // raise an error if errors in buffer 39 | if (errorBuffer.length > 0) { 40 | message = errorBuffer.join("\n"); 41 | throw message; 42 | } 43 | } 44 | 45 | module.exports = { getCredentials }; 46 | -------------------------------------------------------------------------------- /csfle/go/gcp/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | // GCP Credentials 15 | "GCP_EMAIL": "", 16 | "GCP_PRIVATE_KEY": "", 17 | "GCP_PROJECT_ID": "", 18 | "GCP_LOCATION": "", 19 | "GCP_KEY_RING": "", 20 | "GCP_KEY_NAME": "", 21 | "GCP_KEY_VERSION": "", 22 | } 23 | 24 | // check if credentials object contains placeholder values 25 | func check_for_placeholders() { 26 | var error_buffer []string 27 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 28 | for key, value := range credentials { 29 | // check for placeholder text 30 | if placeholder_pattern.MatchString(string(value)) { 31 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 32 | error_buffer = append(error_buffer, error_message) 33 | } 34 | } 35 | // raise an error if errors in buffer 36 | if len(error_buffer) > 0 { 37 | message := strings.Join(error_buffer[:], "\n") 38 | log.Fatal(message) 39 | } 40 | } 41 | 42 | // return credentials object and ensure it has been populated 43 | func GetCredentials() map[string]string { 44 | check_for_placeholders() 45 | return credentials 46 | } 47 | -------------------------------------------------------------------------------- /csfle/node/aws/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: 13 | "", 14 | 15 | // AWS Credentials 16 | AWS_ACCESS_KEY_ID: "", 17 | AWS_SECRET_ACCESS_KEY: "", 18 | AWS_KEY_REGION: "", 19 | AWS_KEY_ARN: "", 20 | }; 21 | 22 | /* 23 | check if credentials object contains placeholder values 24 | **/ 25 | function checkForPlaceholders() { 26 | const errorBuffer = Array(); 27 | const placeholderPattern = /^<.*>$/; 28 | for (const [key, value] of Object.entries(credentials)) { 29 | // check for placeholder text 30 | if (`${value}`.match(placeholderPattern)) { 31 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 32 | errorBuffer.push(errorMessage); 33 | } 34 | // check if value is empty 35 | else if (value == undefined) { 36 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 37 | } 38 | } 39 | // raise an error if errors in buffer 40 | if (errorBuffer.length > 0) { 41 | message = errorBuffer.join("\n"); 42 | throw message; 43 | } 44 | } 45 | 46 | module.exports = { getCredentials }; 47 | -------------------------------------------------------------------------------- /queryable-encryption/python/aws/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | # AWS Credentials 8 | "AWS_ACCESS_KEY_ID": "", 9 | "AWS_SECRET_ACCESS_KEY": "", 10 | "AWS_KEY_REGION": "", 11 | "AWS_KEY_ARN": "", 12 | } 13 | 14 | 15 | def check_for_placeholders(): 16 | """check if credentials object contains placeholder values""" 17 | error_buffer = [] 18 | placeholder_pattern = re.compile("^<.*>$") 19 | for key, value in _credentials.items(): 20 | # check for placeholder text 21 | if placeholder_pattern.match(str(value)): 22 | error_message = ( 23 | f"You must fill out the {key} field of your credentials object." 24 | ) 25 | error_buffer.append(error_message) 26 | # check if value is empty 27 | elif not value: 28 | error_message = ( 29 | f"The value for {key} is empty. Please enter something for this value." 30 | ) 31 | # raise an error if errors in buffer 32 | if error_buffer: 33 | message = "\n".join(error_buffer) 34 | raise ValueError(message) 35 | 36 | 37 | def get_credentials(): 38 | """return credentials object and ensure it has been populated""" 39 | check_for_placeholders() 40 | return _credentials 41 | -------------------------------------------------------------------------------- /queryable-encryption/mongosh/gcp/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | 13 | // GCP Credentials 14 | GCP_EMAIL: "", 15 | GCP_PRIVATE_KEY: "", 16 | GCP_PROJECT_ID: "", 17 | GCP_LOCATION: "", 18 | GCP_KEY_RING: "", 19 | GCP_KEY_NAME: "", 20 | GCP_KEY_VERSION: "", 21 | }; 22 | 23 | /* 24 | check if credentials object contains placeholder values 25 | **/ 26 | function checkForPlaceholders() { 27 | const errorBuffer = Array(); 28 | const placeholderPattern = /^<.*>$/; 29 | for (const [key, value] of Object.entries(credentials)) { 30 | // check for placeholder text 31 | if (`${value}`.match(placeholderPattern)) { 32 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 33 | errorBuffer.push(errorMessage); 34 | } 35 | // check if value is empty 36 | else if (value == undefined) { 37 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 38 | } 39 | } 40 | // raise an error if errors in buffer 41 | if (errorBuffer.length > 0) { 42 | message = errorBuffer.join("\n"); 43 | throw message; 44 | } 45 | } 46 | 47 | module.exports = { getCredentials }; 48 | -------------------------------------------------------------------------------- /csfle/python/aws/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | # AWS Credentials 8 | "AWS_ACCESS_KEY_ID": "", 9 | "AWS_SECRET_ACCESS_KEY": "", 10 | "AWS_KEY_REGION": "", 11 | "AWS_KEY_ARN": "", 12 | } 13 | 14 | 15 | def check_for_placeholders(): 16 | """check if credentials object contains placeholder values""" 17 | error_buffer = [] 18 | placeholder_pattern = re.compile("^<.*>$") 19 | for key, value in _credentials.items(): 20 | # check for placeholder text 21 | if placeholder_pattern.match(str(value)): 22 | error_message = ( 23 | f"You must fill out the {key} field of your credentials object." 24 | ) 25 | error_buffer.append(error_message) 26 | # check if value is empty 27 | elif not value: 28 | error_message = ( 29 | f"The value for {key} is empty. Please enter something for this value." 30 | ) 31 | # raise an error if errors in buffer 32 | if error_buffer: 33 | message = "\n".join(error_buffer) 34 | raise ValueError(message) 35 | 36 | 37 | def get_credentials(): 38 | """return credentials object and ensure it has been populated""" 39 | check_for_placeholders() 40 | return _credentials 41 | -------------------------------------------------------------------------------- /csfle/dotnet/local/reader/CSFLE/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | 16 | 17 | }; 18 | 19 | private void CheckThatValuesAreSet() 20 | { 21 | var placeholder = new Regex("^<.*>$"); 22 | var errorBuffer = new List(); 23 | foreach (KeyValuePair entry in credentials) 24 | { 25 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 26 | { 27 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 28 | errorBuffer.Add(message); 29 | } 30 | } 31 | if (errorBuffer.Count > 0) 32 | { 33 | var message = String.Join("\n", errorBuffer); 34 | throw new Exception(message); 35 | } 36 | } 37 | 38 | public Dictionary GetCredentials() 39 | { 40 | CheckThatValuesAreSet(); 41 | return credentials; 42 | } 43 | 44 | } 45 | } -------------------------------------------------------------------------------- /queryable-encryption/go/azure/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | // Azure Credentials 15 | "AZURE_TENANT_ID": "", 16 | "AZURE_CLIENT_ID": "", 17 | "AZURE_CLIENT_SECRET": "", 18 | "AZURE_KEY_NAME": "", 19 | "AZURE_KEY_VERSION": "", 20 | "AZURE_KEY_VAULT_ENDPOINT": "", 21 | } 22 | 23 | // check if credentials object contains placeholder values 24 | func check_for_placeholders() { 25 | var error_buffer []string 26 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 27 | for key, value := range credentials { 28 | // check for placeholder text 29 | if placeholder_pattern.MatchString(string(value)) { 30 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 31 | error_buffer = append(error_buffer, error_message) 32 | } 33 | } 34 | // raise an error if errors in buffer 35 | if len(error_buffer) > 0 { 36 | message := strings.Join(error_buffer[:], "\n") 37 | log.Fatal(message) 38 | } 39 | } 40 | 41 | // return credentials object and ensure it has been populated 42 | func GetCredentials() map[string]string { 43 | check_for_placeholders() 44 | return credentials 45 | } 46 | -------------------------------------------------------------------------------- /queryable-encryption/mongosh/azure/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | 13 | // Azure Credentials 14 | AZURE_TENANT_ID: "", 15 | AZURE_CLIENT_ID: "", 16 | AZURE_CLIENT_SECRET: "", 17 | AZURE_KEY_NAME: "", 18 | AZURE_KEY_VERSION: "", 19 | AZURE_KEY_VAULT_ENDPOINT: "", 20 | }; 21 | 22 | /* 23 | check if credentials object contains placeholder values 24 | **/ 25 | function checkForPlaceholders() { 26 | const errorBuffer = Array(); 27 | const placeholderPattern = /^<.*>$/; 28 | for (const [key, value] of Object.entries(credentials)) { 29 | // check for placeholder text 30 | if (`${value}`.match(placeholderPattern)) { 31 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 32 | errorBuffer.push(errorMessage); 33 | } 34 | // check if value is empty 35 | else if (value == undefined) { 36 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 37 | } 38 | } 39 | // raise an error if errors in buffer 40 | if (errorBuffer.length > 0) { 41 | message = errorBuffer.join("\n"); 42 | throw message; 43 | } 44 | } 45 | 46 | module.exports = { getCredentials }; 47 | -------------------------------------------------------------------------------- /csfle/go/azure/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | // Azure Credentials 15 | "AZURE_TENANT_ID": "", 16 | "AZURE_CLIENT_ID": "", 17 | "AZURE_CLIENT_SECRET": "", 18 | "AZURE_KEY_NAME": "", 19 | "AZURE_KEY_VERSION": "", 20 | "AZURE_KEY_VAULT_ENDPOINT": "", 21 | } 22 | 23 | // check if credentials object contains placeholder values 24 | func check_for_placeholders() { 25 | var error_buffer []string 26 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 27 | for key, value := range credentials { 28 | // check for placeholder text 29 | if placeholder_pattern.MatchString(string(value)) { 30 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 31 | error_buffer = append(error_buffer, error_message) 32 | } 33 | } 34 | // raise an error if errors in buffer 35 | if len(error_buffer) > 0 { 36 | message := strings.Join(error_buffer[:], "\n") 37 | log.Fatal(message) 38 | } 39 | } 40 | 41 | // return credentials object and ensure it has been populated 42 | func GetCredentials() map[string]string { 43 | check_for_placeholders() 44 | return credentials 45 | } 46 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/exp/reader/QueryableEncryption/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | 16 | 17 | }; 18 | 19 | private void CheckThatValuesAreSet() 20 | { 21 | var placeholder = new Regex("^<.*>$"); 22 | var errorBuffer = new List(); 23 | foreach (KeyValuePair entry in credentials) 24 | { 25 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 26 | { 27 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 28 | errorBuffer.Add(message); 29 | } 30 | } 31 | if (errorBuffer.Count > 0) 32 | { 33 | var message = String.Join("\n", errorBuffer); 34 | throw new Exception(message); 35 | } 36 | } 37 | 38 | public Dictionary GetCredentials() 39 | { 40 | CheckThatValuesAreSet(); 41 | return credentials; 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/local/reader/QueryableEncryption/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | 16 | 17 | }; 18 | 19 | private void CheckThatValuesAreSet() 20 | { 21 | var placeholder = new Regex("^<.*>$"); 22 | var errorBuffer = new List(); 23 | foreach (KeyValuePair entry in credentials) 24 | { 25 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 26 | { 27 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 28 | errorBuffer.Add(message); 29 | } 30 | } 31 | if (errorBuffer.Count > 0) 32 | { 33 | var message = String.Join("\n", errorBuffer); 34 | throw new Exception(message); 35 | } 36 | } 37 | 38 | public Dictionary GetCredentials() 39 | { 40 | CheckThatValuesAreSet(); 41 | return credentials; 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /queryable-encryption/node/gcp/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: "", 13 | 14 | // GCP Credentials 15 | GCP_EMAIL: "", 16 | GCP_PRIVATE_KEY: "", 17 | GCP_PROJECT_ID: "", 18 | GCP_LOCATION: "", 19 | GCP_KEY_RING: "", 20 | GCP_KEY_NAME: "", 21 | GCP_KEY_VERSION: "", 22 | }; 23 | 24 | /* 25 | check if credentials object contains placeholder values 26 | **/ 27 | function checkForPlaceholders() { 28 | const errorBuffer = Array(); 29 | const placeholderPattern = /^<.*>$/; 30 | for (const [key, value] of Object.entries(credentials)) { 31 | // check for placeholder text 32 | if (`${value}`.match(placeholderPattern)) { 33 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 34 | errorBuffer.push(errorMessage); 35 | } 36 | // check if value is empty 37 | else if (value == undefined) { 38 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 39 | } 40 | } 41 | // raise an error if errors in buffer 42 | if (errorBuffer.length > 0) { 43 | message = errorBuffer.join("\n"); 44 | throw message; 45 | } 46 | } 47 | 48 | module.exports = { getCredentials }; 49 | -------------------------------------------------------------------------------- /csfle/node/gcp/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: 13 | "", 14 | 15 | // GCP Credentials 16 | GCP_EMAIL: "", 17 | GCP_PRIVATE_KEY: "", 18 | GCP_PROJECT_ID: "", 19 | GCP_LOCATION: "", 20 | GCP_KEY_RING: "", 21 | GCP_KEY_NAME: "", 22 | GCP_KEY_VERSION: "", 23 | }; 24 | 25 | /* 26 | check if credentials object contains placeholder values 27 | **/ 28 | function checkForPlaceholders() { 29 | const errorBuffer = Array(); 30 | const placeholderPattern = /^<.*>$/; 31 | for (const [key, value] of Object.entries(credentials)) { 32 | // check for placeholder text 33 | if (`${value}`.match(placeholderPattern)) { 34 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 35 | errorBuffer.push(errorMessage); 36 | } 37 | // check if value is empty 38 | else if (value == undefined) { 39 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 40 | } 41 | } 42 | // raise an error if errors in buffer 43 | if (errorBuffer.length > 0) { 44 | message = errorBuffer.join("\n"); 45 | throw message; 46 | } 47 | } 48 | 49 | module.exports = { getCredentials }; 50 | -------------------------------------------------------------------------------- /queryable-encryption/python/gcp/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | # GCP Credentials 8 | "GCP_EMAIL": "", 9 | "GCP_PRIVATE_KEY": "", 10 | "GCP_PROJECT_ID": "", 11 | "GCP_LOCATION": "", 12 | "GCP_KEY_RING": "", 13 | "GCP_KEY_NAME": "", 14 | "GCP_KEY_VERSION": "", 15 | } 16 | 17 | 18 | def check_for_placeholders(): 19 | """check if credentials object contains placeholder values""" 20 | error_buffer = [] 21 | placeholder_pattern = re.compile("^<.*>$") 22 | for key, value in _credentials.items(): 23 | # check for placeholder text 24 | if placeholder_pattern.match(str(value)): 25 | error_message = ( 26 | f"You must fill out the {key} field of your credentials object." 27 | ) 28 | error_buffer.append(error_message) 29 | # check if value is empty 30 | elif not value: 31 | error_message = ( 32 | f"The value for {key} is empty. Please enter something for this value." 33 | ) 34 | # raise an error if errors in buffer 35 | if error_buffer: 36 | message = "\n".join(error_buffer) 37 | raise ValueError(message) 38 | 39 | 40 | def get_credentials(): 41 | """return credentials object and ensure it has been populated""" 42 | check_for_placeholders() 43 | return _credentials 44 | -------------------------------------------------------------------------------- /queryable-encryption/node/azure/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: "", 13 | 14 | // Azure Credentials 15 | AZURE_TENANT_ID: "", 16 | AZURE_CLIENT_ID: "", 17 | AZURE_CLIENT_SECRET: "", 18 | AZURE_KEY_NAME: "", 19 | AZURE_KEY_VERSION: "", 20 | AZURE_KEY_VAULT_ENDPOINT: "", 21 | }; 22 | 23 | /* 24 | check if credentials object contains placeholder values 25 | **/ 26 | function checkForPlaceholders() { 27 | const errorBuffer = Array(); 28 | const placeholderPattern = /^<.*>$/; 29 | for (const [key, value] of Object.entries(credentials)) { 30 | // check for placeholder text 31 | if (`${value}`.match(placeholderPattern)) { 32 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 33 | errorBuffer.push(errorMessage); 34 | } 35 | // check if value is empty 36 | else if (value == undefined) { 37 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 38 | } 39 | } 40 | // raise an error if errors in buffer 41 | if (errorBuffer.length > 0) { 42 | message = errorBuffer.join("\n"); 43 | throw message; 44 | } 45 | } 46 | 47 | module.exports = { getCredentials }; 48 | -------------------------------------------------------------------------------- /csfle/python/gcp/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | # GCP Credentials 8 | "GCP_EMAIL": "", 9 | "GCP_PRIVATE_KEY": "", 10 | "GCP_PROJECT_ID": "", 11 | "GCP_LOCATION": "", 12 | "GCP_KEY_RING": "", 13 | "GCP_KEY_NAME": "", 14 | "GCP_KEY_VERSION": "", 15 | } 16 | 17 | 18 | def check_for_placeholders(): 19 | """check if credentials object contains placeholder values""" 20 | error_buffer = [] 21 | placeholder_pattern = re.compile("^<.*>$") 22 | for key, value in _credentials.items(): 23 | # check for placeholder text 24 | if placeholder_pattern.match(str(value)): 25 | error_message = ( 26 | f"You must fill out the {key} field of your credentials object." 27 | ) 28 | error_buffer.append(error_message) 29 | # check if value is empty 30 | elif not value: 31 | error_message = ( 32 | f"The value for {key} is empty. Please enter something for this value." 33 | ) 34 | # raise an error if errors in buffer 35 | if error_buffer: 36 | message = "\n".join(error_buffer) 37 | raise ValueError(message) 38 | 39 | 40 | def get_credentials(): 41 | """return credentials object and ensure it has been populated""" 42 | check_for_placeholders() 43 | return _credentials 44 | -------------------------------------------------------------------------------- /csfle/node/azure/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: 13 | "", 14 | 15 | // Azure Credentials 16 | AZURE_TENANT_ID: "", 17 | AZURE_CLIENT_ID: "", 18 | AZURE_CLIENT_SECRET: "", 19 | AZURE_KEY_NAME: "", 20 | AZURE_KEY_VERSION: "", 21 | AZURE_KEY_VAULT_ENDPOINT: "", 22 | }; 23 | 24 | /* 25 | check if credentials object contains placeholder values 26 | **/ 27 | function checkForPlaceholders() { 28 | const errorBuffer = Array(); 29 | const placeholderPattern = /^<.*>$/; 30 | for (const [key, value] of Object.entries(credentials)) { 31 | // check for placeholder text 32 | if (`${value}`.match(placeholderPattern)) { 33 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 34 | errorBuffer.push(errorMessage); 35 | } 36 | // check if value is empty 37 | else if (value == undefined) { 38 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 39 | } 40 | } 41 | // raise an error if errors in buffer 42 | if (errorBuffer.length > 0) { 43 | message = errorBuffer.join("\n"); 44 | throw message; 45 | } 46 | } 47 | 48 | module.exports = { getCredentials }; 49 | -------------------------------------------------------------------------------- /queryable-encryption/python/azure/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | # Azure Credentials 8 | "AZURE_TENANT_ID": "", 9 | "AZURE_CLIENT_ID": "", 10 | "AZURE_CLIENT_SECRET": "", 11 | "AZURE_KEY_NAME": "", 12 | "AZURE_KEY_VERSION": "", 13 | "AZURE_KEY_VAULT_ENDPOINT": "", 14 | } 15 | 16 | 17 | def check_for_placeholders(): 18 | """check if credentials object contains placeholder values""" 19 | error_buffer = [] 20 | placeholder_pattern = re.compile("^<.*>$") 21 | for key, value in _credentials.items(): 22 | # check for placeholder text 23 | if placeholder_pattern.match(str(value)): 24 | error_message = ( 25 | f"You must fill out the {key} field of your credentials object." 26 | ) 27 | error_buffer.append(error_message) 28 | # check if value is empty 29 | elif not value: 30 | error_message = ( 31 | f"The value for {key} is empty. Please enter something for this value." 32 | ) 33 | # raise an error if errors in buffer 34 | if error_buffer: 35 | message = "\n".join(error_buffer) 36 | raise ValueError(message) 37 | 38 | 39 | def get_credentials(): 40 | """return credentials object and ensure it has been populated""" 41 | check_for_placeholders() 42 | return _credentials 43 | -------------------------------------------------------------------------------- /csfle/python/azure/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | # Azure Credentials 8 | "AZURE_TENANT_ID": "", 9 | "AZURE_CLIENT_ID": "", 10 | "AZURE_CLIENT_SECRET": "", 11 | "AZURE_KEY_NAME": "", 12 | "AZURE_KEY_VERSION": "", 13 | "AZURE_KEY_VAULT_ENDPOINT": "", 14 | } 15 | 16 | 17 | def check_for_placeholders(): 18 | """check if credentials object contains placeholder values""" 19 | error_buffer = [] 20 | placeholder_pattern = re.compile("^<.*>$") 21 | for key, value in _credentials.items(): 22 | # check for placeholder text 23 | if placeholder_pattern.match(str(value)): 24 | error_message = ( 25 | f"You must fill out the {key} field of your credentials object." 26 | ) 27 | error_buffer.append(error_message) 28 | # check if value is empty 29 | elif not value: 30 | error_message = ( 31 | f"The value for {key} is empty. Please enter something for this value." 32 | ) 33 | # raise an error if errors in buffer 34 | if error_buffer: 35 | message = "\n".join(error_buffer) 36 | raise ValueError(message) 37 | 38 | 39 | def get_credentials(): 40 | """return credentials object and ensure it has been populated""" 41 | check_for_placeholders() 42 | return _credentials 43 | -------------------------------------------------------------------------------- /queryable-encryption/go/kmip/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | // KMIP Credentials 15 | "KMIP_KMS_ENDPOINT": "", 16 | "KMIP_TLS_CA_FILE": "/kmip_utils/certs/ca.pem'>", 17 | "KMIP_TLS_CERT_FILE": "/kmip_utils/certs/client.pem'>", 18 | "KMIP_TLS_CERT_P12": "/kmip_utils/certs/pcks_client.p12'>", 19 | } 20 | 21 | // check if credentials object contains placeholder values 22 | func check_for_placeholders() { 23 | var error_buffer []string 24 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 25 | for key, value := range credentials { 26 | // check for placeholder text 27 | if placeholder_pattern.MatchString(string(value)) { 28 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 29 | error_buffer = append(error_buffer, error_message) 30 | } 31 | } 32 | // raise an error if errors in buffer 33 | if len(error_buffer) > 0 { 34 | message := strings.Join(error_buffer[:], "\n") 35 | log.Fatal(message) 36 | } 37 | } 38 | 39 | // return credentials object and ensure it has been populated 40 | func GetCredentials() map[string]string { 41 | check_for_placeholders() 42 | return credentials 43 | } 44 | -------------------------------------------------------------------------------- /csfle/go/kmip/reader/your-credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | var credentials = map[string]string{ 11 | // Mongo Paths + URI 12 | "MONGODB_URI": "", 13 | "SHARED_LIB_PATH": "", 14 | // KMIP Credentials 15 | "KMIP_KMS_ENDPOINT": "", 16 | "KMIP_TLS_CA_FILE": "/kmip_utils/certs/ca.pem'>", 17 | "KMIP_TLS_CERT_FILE": "/kmip_utils/certs/client.pem'>", 18 | "KMIP_TLS_CERT_P12": "/kmip_utils/certs/pcks_client.p12'>", 19 | } 20 | 21 | // check if credentials object contains placeholder values 22 | func check_for_placeholders() { 23 | var error_buffer []string 24 | placeholder_pattern, _ := regexp.Compile("^<.*>$") 25 | for key, value := range credentials { 26 | // check for placeholder text 27 | if placeholder_pattern.MatchString(string(value)) { 28 | error_message := fmt.Sprintf("You must fill out the %s field of your credentials object.\n", key) 29 | error_buffer = append(error_buffer, error_message) 30 | } 31 | } 32 | // raise an error if errors in buffer 33 | if len(error_buffer) > 0 { 34 | message := strings.Join(error_buffer[:], "\n") 35 | log.Fatal(message) 36 | } 37 | } 38 | 39 | // return credentials object and ensure it has been populated 40 | func GetCredentials() map[string]string { 41 | check_for_placeholders() 42 | return credentials 43 | } 44 | -------------------------------------------------------------------------------- /queryable-encryption/mongosh/kmip/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | 13 | // KMIP Credentials 14 | KMIP_KMS_ENDPOINT: 15 | "", 16 | KMIP_TLS_CA_FILE: 17 | "/kmip_utils/certs/ca.pem'>", 18 | KMIP_TLS_CERT_FILE: 19 | "/kmip_utils/certs/client.pem'>", 20 | KMIP_TLS_CERT_P12: 21 | "/kmip_utils/certs/pcks_client.p12'>", 22 | }; 23 | 24 | /* 25 | check if credentials object contains placeholder values 26 | **/ 27 | function checkForPlaceholders() { 28 | const errorBuffer = Array(); 29 | const placeholderPattern = /^<.*>$/; 30 | for (const [key, value] of Object.entries(credentials)) { 31 | // check for placeholder text 32 | if (`${value}`.match(placeholderPattern)) { 33 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 34 | errorBuffer.push(errorMessage); 35 | } 36 | // check if value is empty 37 | else if (value == undefined) { 38 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 39 | } 40 | } 41 | // raise an error if errors in buffer 42 | if (errorBuffer.length > 0) { 43 | message = errorBuffer.join("\n"); 44 | throw message; 45 | } 46 | } 47 | 48 | module.exports = { getCredentials }; 49 | -------------------------------------------------------------------------------- /queryable-encryption/python/kmip/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | # KMIP Credentials 8 | "KMIP_KMS_ENDPOINT": "", 9 | "KMIP_TLS_CA_FILE": "/kmip_utils/certs/ca.pem'>", 10 | "KMIP_TLS_CERT_FILE": "/kmip_utils/certs/client.pem'>", 11 | "KMIP_TLS_CERT_P12": "/kmip_utils/certs/pcks_client.p12'>", 12 | } 13 | 14 | 15 | def check_for_placeholders(): 16 | """check if credentials object contains placeholder values""" 17 | error_buffer = [] 18 | placeholder_pattern = re.compile("^<.*>$") 19 | for key, value in _credentials.items(): 20 | # check for placeholder text 21 | if placeholder_pattern.match(str(value)): 22 | error_message = ( 23 | f"You must fill out the {key} field of your credentials object." 24 | ) 25 | error_buffer.append(error_message) 26 | # check if value is empty 27 | elif not value: 28 | error_message = ( 29 | f"The value for {key} is empty. Please enter something for this value." 30 | ) 31 | # raise an error if errors in buffer 32 | if error_buffer: 33 | message = "\n".join(error_buffer) 34 | raise ValueError(message) 35 | 36 | 37 | def get_credentials(): 38 | """return credentials object and ensure it has been populated""" 39 | check_for_placeholders() 40 | return _credentials 41 | -------------------------------------------------------------------------------- /csfle/python/kmip/reader/your_credentials.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | _credentials = { 4 | # Mongo Paths + URI 5 | "MONGODB_URI": "", 6 | "SHARED_LIB_PATH": "", 7 | # KMIP Credentials 8 | "KMIP_KMS_ENDPOINT": "", 9 | "KMIP_TLS_CA_FILE": "/kmip_utils/certs/ca.pem'>", 10 | "KMIP_TLS_CERT_FILE": "/kmip_utils/certs/client.pem'>", 11 | "KMIP_TLS_CERT_P12": "/kmip_utils/certs/pcks_client.p12'>", 12 | } 13 | 14 | 15 | def check_for_placeholders(): 16 | """check if credentials object contains placeholder values""" 17 | error_buffer = [] 18 | placeholder_pattern = re.compile("^<.*>$") 19 | for key, value in _credentials.items(): 20 | # check for placeholder text 21 | if placeholder_pattern.match(str(value)): 22 | error_message = ( 23 | f"You must fill out the {key} field of your credentials object." 24 | ) 25 | error_buffer.append(error_message) 26 | # check if value is empty 27 | elif not value: 28 | error_message = ( 29 | f"The value for {key} is empty. Please enter something for this value." 30 | ) 31 | # raise an error if errors in buffer 32 | if error_buffer: 33 | message = "\n".join(error_buffer) 34 | raise ValueError(message) 35 | 36 | 37 | def get_credentials(): 38 | """return credentials object and ensure it has been populated""" 39 | check_for_placeholders() 40 | return _credentials 41 | -------------------------------------------------------------------------------- /queryable-encryption/node/kmip/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: "", 13 | 14 | // KMIP Credentials 15 | KMIP_KMS_ENDPOINT: 16 | "", 17 | KMIP_TLS_CA_FILE: 18 | "/kmip_utils/certs/ca.pem'>", 19 | KMIP_TLS_CERT_FILE: 20 | "/kmip_utils/certs/client.pem'>", 21 | KMIP_TLS_CERT_P12: 22 | "/kmip_utils/certs/pcks_client.p12'>", 23 | }; 24 | 25 | /* 26 | check if credentials object contains placeholder values 27 | **/ 28 | function checkForPlaceholders() { 29 | const errorBuffer = Array(); 30 | const placeholderPattern = /^<.*>$/; 31 | for (const [key, value] of Object.entries(credentials)) { 32 | // check for placeholder text 33 | if (`${value}`.match(placeholderPattern)) { 34 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 35 | errorBuffer.push(errorMessage); 36 | } 37 | // check if value is empty 38 | else if (value == undefined) { 39 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 40 | } 41 | } 42 | // raise an error if errors in buffer 43 | if (errorBuffer.length > 0) { 44 | message = errorBuffer.join("\n"); 45 | throw message; 46 | } 47 | } 48 | 49 | module.exports = { getCredentials }; 50 | -------------------------------------------------------------------------------- /csfle/node/kmip/reader/your_credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | return credentials object and ensure it has been populated 3 | **/ 4 | function getCredentials() { 5 | checkForPlaceholders(); 6 | return credentials; 7 | } 8 | 9 | const credentials = { 10 | // Mongo Paths + URI 11 | MONGODB_URI: "", 12 | SHARED_LIB_PATH: 13 | "", 14 | 15 | // KMIP Credentials 16 | KMIP_KMS_ENDPOINT: 17 | "", 18 | KMIP_TLS_CA_FILE: 19 | "/kmip_utils/certs/ca.pem'>", 20 | KMIP_TLS_CERT_FILE: 21 | "/kmip_utils/certs/client.pem'>", 22 | KMIP_TLS_CERT_P12: 23 | "/kmip_utils/certs/pcks_client.p12'>", 24 | }; 25 | 26 | /* 27 | check if credentials object contains placeholder values 28 | **/ 29 | function checkForPlaceholders() { 30 | const errorBuffer = Array(); 31 | const placeholderPattern = /^<.*>$/; 32 | for (const [key, value] of Object.entries(credentials)) { 33 | // check for placeholder text 34 | if (`${value}`.match(placeholderPattern)) { 35 | errorMessage = `You must fill out the ${key} field of your credentials object.`; 36 | errorBuffer.push(errorMessage); 37 | } 38 | // check if value is empty 39 | else if (value == undefined) { 40 | error_message = `The value for ${key} is empty. Please enter something for this value.`; 41 | } 42 | } 43 | // raise an error if errors in buffer 44 | if (errorBuffer.length > 0) { 45 | message = errorBuffer.join("\n"); 46 | throw message; 47 | } 48 | } 49 | 50 | module.exports = { getCredentials }; 51 | -------------------------------------------------------------------------------- /csfle/dotnet/aws/reader/CSFLE/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | // AWS Credentials 16 | {"AWS_ACCESS_KEY_ID", ""}, 17 | {"AWS_SECRET_ACCESS_KEY", ""}, 18 | {"AWS_KEY_REGION", ""}, 19 | {"AWS_KEY_ARN", ""}, 20 | 21 | 22 | }; 23 | 24 | private void CheckThatValuesAreSet() 25 | { 26 | var placeholder = new Regex("^<.*>$"); 27 | var errorBuffer = new List(); 28 | foreach (KeyValuePair entry in credentials) 29 | { 30 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 31 | { 32 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 33 | errorBuffer.Add(message); 34 | } 35 | } 36 | if (errorBuffer.Count > 0) 37 | { 38 | var message = String.Join("\n", errorBuffer); 39 | throw new Exception(message); 40 | } 41 | } 42 | 43 | public Dictionary GetCredentials() 44 | { 45 | CheckThatValuesAreSet(); 46 | return credentials; 47 | } 48 | 49 | } 50 | } -------------------------------------------------------------------------------- /queryable-encryption/dotnet/aws/reader/QueryableEncryption/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | // AWS Credentials 16 | {"AWS_ACCESS_KEY_ID", ""}, 17 | {"AWS_SECRET_ACCESS_KEY", ""}, 18 | {"AWS_KEY_REGION", ""}, 19 | {"AWS_KEY_ARN", ""}, 20 | 21 | 22 | }; 23 | 24 | private void CheckThatValuesAreSet() 25 | { 26 | var placeholder = new Regex("^<.*>$"); 27 | var errorBuffer = new List(); 28 | foreach (KeyValuePair entry in credentials) 29 | { 30 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 31 | { 32 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 33 | errorBuffer.Add(message); 34 | } 35 | } 36 | if (errorBuffer.Count > 0) 37 | { 38 | var message = String.Join("\n", errorBuffer); 39 | throw new Exception(message); 40 | } 41 | } 42 | 43 | public Dictionary GetCredentials() 44 | { 45 | CheckThatValuesAreSet(); 46 | return credentials; 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /csfle/dotnet/gcp/reader/CSFLE/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | 16 | // GCP Credentials 17 | {"GCP_EMAIL", ""}, 18 | {"GCP_PRIVATE_KEY", ""}, 19 | {"GCP_PROJECT_ID", ""}, 20 | {"GCP_LOCATION", ""}, 21 | {"GCP_KEY_RING", ""}, 22 | {"GCP_KEY_NAME", ""}, 23 | {"GCP_KEY_VERSION", ""}, 24 | 25 | }; 26 | 27 | private void CheckThatValuesAreSet() 28 | { 29 | var placeholder = new Regex("^<.*>$"); 30 | var errorBuffer = new List(); 31 | foreach (KeyValuePair entry in credentials) 32 | { 33 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 34 | { 35 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 36 | errorBuffer.Add(message); 37 | } 38 | } 39 | if (errorBuffer.Count > 0) 40 | { 41 | var message = String.Join("\n", errorBuffer); 42 | throw new Exception(message); 43 | } 44 | } 45 | 46 | public Dictionary GetCredentials() 47 | { 48 | CheckThatValuesAreSet(); 49 | return credentials; 50 | } 51 | 52 | } 53 | } -------------------------------------------------------------------------------- /csfle/dotnet/azure/reader/CSFLE/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | 16 | // Azure Credentials 17 | {"AZURE_TENANT_ID", ""}, 18 | {"AZURE_CLIENT_ID", ""}, 19 | {"AZURE_CLIENT_SECRET", ""}, 20 | {"AZURE_KEY_NAME", ""}, 21 | {"AZURE_KEY_VERSION", ""}, 22 | {"AZURE_KEY_VAULT_ENDPOINT", ""}, 23 | 24 | }; 25 | 26 | private void CheckThatValuesAreSet() 27 | { 28 | var placeholder = new Regex("^<.*>$"); 29 | var errorBuffer = new List(); 30 | foreach (KeyValuePair entry in credentials) 31 | { 32 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 33 | { 34 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 35 | errorBuffer.Add(message); 36 | } 37 | } 38 | if (errorBuffer.Count > 0) 39 | { 40 | var message = String.Join("\n", errorBuffer); 41 | throw new Exception(message); 42 | } 43 | } 44 | 45 | public Dictionary GetCredentials() 46 | { 47 | CheckThatValuesAreSet(); 48 | return credentials; 49 | } 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /queryable-encryption/dotnet/gcp/reader/QueryableEncryption/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | 16 | // GCP Credentials 17 | {"GCP_EMAIL", ""}, 18 | {"GCP_PRIVATE_KEY", ""}, 19 | {"GCP_PROJECT_ID", ""}, 20 | {"GCP_LOCATION", ""}, 21 | {"GCP_KEY_RING", ""}, 22 | {"GCP_KEY_NAME", ""}, 23 | {"GCP_KEY_VERSION", ""}, 24 | 25 | }; 26 | 27 | private void CheckThatValuesAreSet() 28 | { 29 | var placeholder = new Regex("^<.*>$"); 30 | var errorBuffer = new List(); 31 | foreach (KeyValuePair entry in credentials) 32 | { 33 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 34 | { 35 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 36 | errorBuffer.Add(message); 37 | } 38 | } 39 | if (errorBuffer.Count > 0) 40 | { 41 | var message = String.Join("\n", errorBuffer); 42 | throw new Exception(message); 43 | } 44 | } 45 | 46 | public Dictionary GetCredentials() 47 | { 48 | CheckThatValuesAreSet(); 49 | return credentials; 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/azure/reader/QueryableEncryption/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | 16 | // Azure Credentials 17 | {"AZURE_TENANT_ID", ""}, 18 | {"AZURE_CLIENT_ID", ""}, 19 | {"AZURE_CLIENT_SECRET", ""}, 20 | {"AZURE_KEY_NAME", ""}, 21 | {"AZURE_KEY_VERSION", ""}, 22 | {"AZURE_KEY_VAULT_ENDPOINT", ""}, 23 | 24 | }; 25 | 26 | private void CheckThatValuesAreSet() 27 | { 28 | var placeholder = new Regex("^<.*>$"); 29 | var errorBuffer = new List(); 30 | foreach (KeyValuePair entry in credentials) 31 | { 32 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 33 | { 34 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 35 | errorBuffer.Add(message); 36 | } 37 | } 38 | if (errorBuffer.Count > 0) 39 | { 40 | var message = String.Join("\n", errorBuffer); 41 | throw new Exception(message); 42 | } 43 | } 44 | 45 | public Dictionary GetCredentials() 46 | { 47 | CheckThatValuesAreSet(); 48 | return credentials; 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /csfle/dotnet/kmip/reader/CSFLE/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | 16 | // KMIP Credentials 17 | {"KMIP_KMS_ENDPOINT", ""}, 18 | {"KMIP_TLS_CA_FILE", "/kmip_utils/certs/ca.pem'>"}, 19 | {"KMIP_TLS_CERT_FILE", "/kmip_utils/certs/client.pem'>"}, 20 | {"KMIP_TLS_CERT_P12", "/kmip_utils/certs/pcks_client.p12'>"}, 21 | 22 | }; 23 | 24 | private void CheckThatValuesAreSet() 25 | { 26 | var placeholder = new Regex("^<.*>$"); 27 | var errorBuffer = new List(); 28 | foreach (KeyValuePair entry in credentials) 29 | { 30 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 31 | { 32 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 33 | errorBuffer.Add(message); 34 | } 35 | } 36 | if (errorBuffer.Count > 0) 37 | { 38 | var message = String.Join("\n", errorBuffer); 39 | throw new Exception(message); 40 | } 41 | } 42 | 43 | public Dictionary GetCredentials() 44 | { 45 | CheckThatValuesAreSet(); 46 | return credentials; 47 | } 48 | 49 | } 50 | } -------------------------------------------------------------------------------- /queryable-encryption/java/exp/reader/src/main/java/com/mongodb/qe/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.qe; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | 33 | } 34 | private static void checkPlaceholders() throws Exception { 35 | Pattern p = Pattern.compile("<.*>$"); 36 | ArrayList errorBuffer = new ArrayList(); 37 | for (Map.Entry entry : yourCredentials.entrySet()) { 38 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 39 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 40 | errorBuffer.add(message); 41 | } 42 | } 43 | if (!errorBuffer.isEmpty()){ 44 | String message = String.join("\n", errorBuffer); 45 | throw new Exception(message); 46 | } 47 | } 48 | public static Map getCredentials() throws Exception { 49 | checkPlaceholders(); 50 | return yourCredentials; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /queryable-encryption/java/local/reader/src/main/java/com/mongodb/qe/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.qe; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | 33 | } 34 | private static void checkPlaceholders() throws Exception { 35 | Pattern p = Pattern.compile("<.*>$"); 36 | ArrayList errorBuffer = new ArrayList(); 37 | for (Map.Entry entry : yourCredentials.entrySet()) { 38 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 39 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 40 | errorBuffer.add(message); 41 | } 42 | } 43 | if (!errorBuffer.isEmpty()){ 44 | String message = String.join("\n", errorBuffer); 45 | throw new Exception(message); 46 | } 47 | } 48 | public static Map getCredentials() throws Exception { 49 | checkPlaceholders(); 50 | return yourCredentials; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /csfle/java/local/reader/src/main/java/com/mongodb/csfle/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.csfle; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | 33 | } 34 | private static void checkPlaceholders() throws Exception { 35 | Pattern p = Pattern.compile("<.*>$"); 36 | ArrayList errorBuffer = new ArrayList(); 37 | for (Map.Entry entry : yourCredentials.entrySet()) { 38 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 39 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 40 | errorBuffer.add(message); 41 | } 42 | } 43 | if (!errorBuffer.isEmpty()){ 44 | String message = String.join("\n", errorBuffer); 45 | throw new Exception(message); 46 | } 47 | } 48 | public static Map getCredentials() throws Exception { 49 | checkPlaceholders(); 50 | return yourCredentials; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /queryable-encryption/dotnet/kmip/reader/QueryableEncryption/YourCredentials.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Credentials 6 | { 7 | class YourCredentials 8 | { 9 | 10 | private Dictionary credentials = new Dictionary() 11 | { 12 | // Mongo Paths + URI 13 | {"MONGODB_URI", ""}, 14 | {"SHARED_LIB_PATH", ""}, 15 | 16 | // KMIP Credentials 17 | {"KMIP_KMS_ENDPOINT", ""}, 18 | {"KMIP_TLS_CA_FILE", "/kmip_utils/certs/ca.pem'>"}, 19 | {"KMIP_TLS_CERT_FILE", "/kmip_utils/certs/client.pem'>"}, 20 | {"KMIP_TLS_CERT_P12", "/kmip_utils/certs/pcks_client.p12'>"}, 21 | 22 | }; 23 | 24 | private void CheckThatValuesAreSet() 25 | { 26 | var placeholder = new Regex("^<.*>$"); 27 | var errorBuffer = new List(); 28 | foreach (KeyValuePair entry in credentials) 29 | { 30 | if (entry.Value != null && placeholder.IsMatch(Convert.ToString(entry.Value))) 31 | { 32 | var message = String.Format("You must fill out the {0} field of your credentials object.", entry.Key); 33 | errorBuffer.Add(message); 34 | } 35 | } 36 | if (errorBuffer.Count > 0) 37 | { 38 | var message = String.Join("\n", errorBuffer); 39 | throw new Exception(message); 40 | } 41 | } 42 | 43 | public Dictionary GetCredentials() 44 | { 45 | CheckThatValuesAreSet(); 46 | return credentials; 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /csfle/node/aws/reader/make_data_key.js: -------------------------------------------------------------------------------- 1 | const mongodb = require("mongodb"); 2 | const { MongoClient, Binary, ClientEncryption } = mongodb; 3 | 4 | const { getCredentials } = require("./your_credentials"); 5 | credentials = getCredentials(); 6 | 7 | // start-kmsproviders 8 | const provider = "aws"; 9 | const kmsProviders = { 10 | aws: { 11 | accessKeyId: credentials["AWS_ACCESS_KEY_ID"], 12 | secretAccessKey: credentials["AWS_SECRET_ACCESS_KEY"], 13 | }, 14 | }; 15 | // end-kmsproviders 16 | 17 | // start-datakeyopts 18 | const masterKey = { 19 | key: credentials["AWS_KEY_ARN"], 20 | region: credentials["AWS_KEY_REGION"], 21 | }; 22 | // end-datakeyopts 23 | 24 | async function main() { 25 | // start-create-index 26 | const uri = credentials.MONGODB_URI; 27 | const keyVaultDatabase = "encryption"; 28 | const keyVaultCollection = "__keyVault"; 29 | const keyVaultNamespace = `${keyVaultDatabase}.${keyVaultCollection}`; 30 | const keyVaultClient = new MongoClient(uri); 31 | await keyVaultClient.connect(); 32 | const keyVaultDB = keyVaultClient.db(keyVaultDatabase); 33 | // Drop the Key Vault Collection in case you created this collection 34 | // in a previous run of this application. 35 | await keyVaultDB.dropDatabase(); 36 | // Drop the database storing your encrypted fields as all 37 | // the DEKs encrypting those fields were deleted in the preceding line. 38 | await keyVaultClient.db("medicalRecords").dropDatabase(); 39 | const keyVaultColl = keyVaultDB.collection(keyVaultCollection); 40 | await keyVaultColl.createIndex( 41 | { keyAltNames: 1 }, 42 | { 43 | unique: true, 44 | partialFilterExpression: { keyAltNames: { $exists: true } }, 45 | } 46 | ); 47 | // end-create-index 48 | 49 | // start-create-dek 50 | const client = new MongoClient(uri, { 51 | useNewUrlParser: true, 52 | useUnifiedTopology: true, 53 | }); 54 | await client.connect(); 55 | 56 | const encryption = new ClientEncryption(client, { 57 | keyVaultNamespace, 58 | kmsProviders, 59 | }); 60 | const key = await encryption.createDataKey(provider, { 61 | masterKey: masterKey, 62 | keyAltNames: ["demo-data-key"], 63 | }); 64 | console.log("DataKeyId [base64]: ", key.toString("base64")); 65 | await keyVaultClient.close(); 66 | await client.close(); 67 | // end-create-dek 68 | } 69 | main(); 70 | -------------------------------------------------------------------------------- /csfle/python/aws/reader/make_data_key.py: -------------------------------------------------------------------------------- 1 | from pymongo import MongoClient, ASCENDING 2 | from pymongo.encryption_options import AutoEncryptionOpts 3 | from pymongo.encryption import ClientEncryption 4 | import base64 5 | import os 6 | from bson.codec_options import CodecOptions 7 | from bson.binary import STANDARD, UUID 8 | from your_credentials import get_credentials 9 | 10 | credentials = get_credentials() 11 | 12 | 13 | # start-kmsproviders 14 | provider = "aws" 15 | kms_providers = { 16 | provider: { 17 | "accessKeyId": credentials["AWS_ACCESS_KEY_ID"], 18 | "secretAccessKey": credentials["AWS_SECRET_ACCESS_KEY"], 19 | } 20 | } 21 | # end-kmsproviders 22 | 23 | # start-datakeyopts 24 | master_key = { 25 | "region": credentials["AWS_KEY_REGION"], 26 | "key": credentials["AWS_KEY_ARN"], 27 | } 28 | # end-datakeyopts 29 | 30 | # start-create-index 31 | connection_string = credentials["MONGODB_URI"] 32 | 33 | key_vault_coll = "__keyVault" 34 | key_vault_db = "encryption" 35 | key_vault_namespace = f"{key_vault_db}.{key_vault_coll}" 36 | key_vault_client = MongoClient(connection_string) 37 | # Drop the Key Vault Collection in case you created this collection 38 | # in a previous run of this application. 39 | key_vault_client.drop_database(key_vault_db) 40 | # Drop the database storing your encrypted fields as all 41 | # the DEKs encrypting those fields were deleted in the preceding line. 42 | key_vault_client["medicalRecords"].drop_collection("patients") 43 | key_vault_client[key_vault_db][key_vault_coll].create_index( 44 | [("keyAltNames", ASCENDING)], 45 | unique=True, 46 | partialFilterExpression={"keyAltNames": {"$exists": True}}, 47 | ) 48 | # end-create-index 49 | 50 | 51 | # start-create-dek 52 | key_vault_database = "encryption" 53 | key_vault_collection = "__keyVault" 54 | key_vault_namespace = f"{key_vault_database}.{key_vault_collection}" 55 | 56 | client = MongoClient(connection_string) 57 | client_encryption = ClientEncryption( 58 | kms_providers, # pass in the kms_providers variable from the previous step 59 | key_vault_namespace, 60 | client, 61 | CodecOptions(uuid_representation=STANDARD), 62 | ) 63 | data_key_id = client_encryption.create_data_key( 64 | provider, master_key, key_alt_names=["demo-data-key"] 65 | ) 66 | 67 | base_64_data_key_id = base64.b64encode(data_key_id) 68 | print("DataKeyId [base64]: ", base_64_data_key_id) 69 | # end-create-dek 70 | -------------------------------------------------------------------------------- /csfle/node/azure/reader/make_data_key.js: -------------------------------------------------------------------------------- 1 | const mongodb = require("mongodb"); 2 | const { MongoClient, Binary, ClientEncryption } = mongodb; 3 | 4 | const { getCredentials } = require("./your_credentials"); 5 | credentials = getCredentials(); 6 | 7 | // start-kmsproviders 8 | const provider = "azure"; 9 | const kmsProviders = { 10 | azure: { 11 | tenantId: credentials["AZURE_TENANT_ID"], 12 | clientId: credentials["AZURE_CLIENT_ID"], 13 | clientSecret: credentials["AZURE_CLIENT_SECRET"], 14 | }, 15 | }; 16 | // end-kmsproviders 17 | 18 | // start-datakeyopts 19 | const masterKey = { 20 | keyVaultEndpoint: credentials["AZURE_KEY_VAULT_ENDPOINT"], 21 | keyName: credentials["AZURE_KEY_NAME"], 22 | }; 23 | // end-datakeyopts 24 | 25 | async function main() { 26 | // start-create-index 27 | const uri = credentials.MONGODB_URI; 28 | const keyVaultDatabase = "encryption"; 29 | const keyVaultCollection = "__keyVault"; 30 | const keyVaultNamespace = `${keyVaultDatabase}.${keyVaultCollection}`; 31 | const keyVaultClient = new MongoClient(uri); 32 | await keyVaultClient.connect(); 33 | const keyVaultDB = keyVaultClient.db(keyVaultDatabase); 34 | // Drop the Key Vault Collection in case you created this collection 35 | // in a previous run of this application. 36 | await keyVaultDB.dropDatabase(); 37 | // Drop the database storing your encrypted fields as all 38 | // the DEKs encrypting those fields were deleted in the preceding line. 39 | await keyVaultClient.db("medicalRecords").dropDatabase(); 40 | const keyVaultColl = keyVaultDB.collection(keyVaultCollection); 41 | await keyVaultColl.createIndex( 42 | { keyAltNames: 1 }, 43 | { 44 | unique: true, 45 | partialFilterExpression: { keyAltNames: { $exists: true } }, 46 | } 47 | ); 48 | // end-create-index 49 | 50 | // start-create-dek 51 | const client = new MongoClient(uri, { 52 | useNewUrlParser: true, 53 | useUnifiedTopology: true, 54 | }); 55 | await client.connect(); 56 | 57 | const encryption = new ClientEncryption(client, { 58 | keyVaultNamespace, 59 | kmsProviders, 60 | }); 61 | const key = await encryption.createDataKey(provider, { 62 | masterKey: masterKey, 63 | keyAltNames: ["demo-data-key"], 64 | }); 65 | console.log("DataKeyId [base64]: ", key.toString("base64")); 66 | await keyVaultClient.close(); 67 | await client.close(); 68 | // end-create-dek 69 | } 70 | main(); 71 | -------------------------------------------------------------------------------- /csfle/node/gcp/reader/make_data_key.js: -------------------------------------------------------------------------------- 1 | const mongodb = require("mongodb"); 2 | const { MongoClient, Binary, ClientEncryption } = mongodb; 3 | 4 | const { getCredentials } = require("./your_credentials"); 5 | credentials = getCredentials(); 6 | 7 | // start-kmsproviders 8 | const provider = "gcp"; 9 | const kmsProviders = { 10 | gcp: { 11 | email: credentials["GCP_EMAIL"], 12 | privateKey: credentials["GCP_PRIVATE_KEY"], 13 | }, 14 | }; 15 | // end-kmsproviders 16 | 17 | // start-datakeyopts 18 | const masterKey = { 19 | projectId: credentials["GCP_PROJECT_ID"], 20 | location: credentials["GCP_LOCATION"], 21 | keyRing: credentials["GCP_KEY_RING"], 22 | keyName: credentials["GCP_KEY_NAME"], 23 | }; 24 | // end-datakeyopts 25 | 26 | async function main() { 27 | // start-create-index 28 | const uri = credentials.MONGODB_URI; 29 | const keyVaultDatabase = "encryption"; 30 | const keyVaultCollection = "__keyVault"; 31 | const keyVaultNamespace = `${keyVaultDatabase}.${keyVaultCollection}`; 32 | const keyVaultClient = new MongoClient(uri); 33 | await keyVaultClient.connect(); 34 | const keyVaultDB = keyVaultClient.db(keyVaultDatabase); 35 | // Drop the Key Vault Collection in case you created this collection 36 | // in a previous run of this application. 37 | await keyVaultDB.dropDatabase(); 38 | // Drop the database storing your encrypted fields as all 39 | // the DEKs encrypting those fields were deleted in the preceding line. 40 | await keyVaultClient.db("medicalRecords").dropDatabase(); 41 | const keyVaultColl = keyVaultDB.collection(keyVaultCollection); 42 | await keyVaultColl.createIndex( 43 | { keyAltNames: 1 }, 44 | { 45 | unique: true, 46 | partialFilterExpression: { keyAltNames: { $exists: true } }, 47 | } 48 | ); 49 | // end-create-index 50 | 51 | // start-create-dek 52 | const client = new MongoClient(uri, { 53 | useNewUrlParser: true, 54 | useUnifiedTopology: true, 55 | }); 56 | await client.connect(); 57 | 58 | const encryption = new ClientEncryption(client, { 59 | keyVaultNamespace, 60 | kmsProviders, 61 | }); 62 | const key = await encryption.createDataKey(provider, { 63 | masterKey: masterKey, 64 | keyAltNames: ["demo-data-key"], 65 | }); 66 | console.log("DataKeyId [base64]: ", key.toString("base64")); 67 | await keyVaultClient.close(); 68 | await client.close(); 69 | // end-create-dek 70 | } 71 | main(); 72 | -------------------------------------------------------------------------------- /csfle/node/local/reader/make_data_key.js: -------------------------------------------------------------------------------- 1 | const mongodb = require("mongodb"); 2 | const { MongoClient, Binary, ClientEncryption } = mongodb; 3 | 4 | const { getCredentials } = require("./your_credentials"); 5 | credentials = getCredentials(); 6 | 7 | // start-local-cmk 8 | const fs = require("fs"); 9 | const crypto = require("crypto"); 10 | try { 11 | fs.writeFileSync("master-key.txt", crypto.randomBytes(96)); 12 | } catch (err) { 13 | console.error(err); 14 | } 15 | // end-local-cmk 16 | 17 | // start-kmsproviders 18 | const provider = "local"; 19 | const path = "./master-key.txt"; 20 | const localMasterKey = fs.readFileSync(path); 21 | const kmsProviders = { 22 | local: { 23 | key: localMasterKey, 24 | }, 25 | }; 26 | // end-kmsproviders 27 | 28 | // start-datakeyopts 29 | // end-datakeyopts 30 | 31 | async function main() { 32 | // start-create-index 33 | const uri = credentials.MONGODB_URI; 34 | const keyVaultDatabase = "encryption"; 35 | const keyVaultCollection = "__keyVault"; 36 | const keyVaultNamespace = `${keyVaultDatabase}.${keyVaultCollection}`; 37 | const keyVaultClient = new MongoClient(uri); 38 | await keyVaultClient.connect(); 39 | const keyVaultDB = keyVaultClient.db(keyVaultDatabase); 40 | // Drop the Key Vault Collection in case you created this collection 41 | // in a previous run of this application. 42 | await keyVaultDB.dropDatabase(); 43 | // Drop the database storing your encrypted fields as all 44 | // the DEKs encrypting those fields were deleted in the preceding line. 45 | await keyVaultClient.db("medicalRecords").dropDatabase(); 46 | const keyVaultColl = keyVaultDB.collection(keyVaultCollection); 47 | await keyVaultColl.createIndex( 48 | { keyAltNames: 1 }, 49 | { 50 | unique: true, 51 | partialFilterExpression: { keyAltNames: { $exists: true } }, 52 | } 53 | ); 54 | // end-create-index 55 | 56 | // start-create-dek 57 | const client = new MongoClient(uri, { 58 | useNewUrlParser: true, 59 | useUnifiedTopology: true, 60 | }); 61 | await client.connect(); 62 | 63 | const encryption = new ClientEncryption(client, { 64 | keyVaultNamespace, 65 | kmsProviders, 66 | }); 67 | const key = await encryption.createDataKey(provider, { 68 | keyAltNames: ["demo-data-key"], 69 | }); 70 | console.log("DataKeyId [base64]: ", key.toString("base64")); 71 | await keyVaultClient.close(); 72 | await client.close(); 73 | // end-create-dek 74 | } 75 | main(); 76 | -------------------------------------------------------------------------------- /csfle/python/azure/reader/make_data_key.py: -------------------------------------------------------------------------------- 1 | from pymongo import MongoClient, ASCENDING 2 | from pymongo.encryption_options import AutoEncryptionOpts 3 | from pymongo.encryption import ClientEncryption 4 | import base64 5 | import os 6 | from bson.codec_options import CodecOptions 7 | from bson.binary import STANDARD, UUID 8 | from your_credentials import get_credentials 9 | 10 | credentials = get_credentials() 11 | 12 | 13 | # start-kmsproviders 14 | provider = "azure" 15 | kms_providers = { 16 | provider: { 17 | "tenantId": credentials["AZURE_TENANT_ID"], 18 | "clientId": credentials["AZURE_CLIENT_ID"], 19 | "clientSecret": credentials["AZURE_CLIENT_SECRET"], 20 | } 21 | } 22 | # end-kmsproviders 23 | 24 | # start-datakeyopts 25 | master_key = { 26 | "keyName": credentials["AZURE_KEY_NAME"], 27 | "keyVaultEndpoint": credentials["AZURE_KEY_VAULT_ENDPOINT"], 28 | } 29 | # end-datakeyopts 30 | 31 | # start-create-index 32 | connection_string = credentials["MONGODB_URI"] 33 | 34 | key_vault_coll = "__keyVault" 35 | key_vault_db = "encryption" 36 | key_vault_namespace = f"{key_vault_db}.{key_vault_coll}" 37 | key_vault_client = MongoClient(connection_string) 38 | # Drop the Key Vault Collection in case you created this collection 39 | # in a previous run of this application. 40 | key_vault_client.drop_database(key_vault_db) 41 | # Drop the database storing your encrypted fields as all 42 | # the DEKs encrypting those fields were deleted in the preceding line. 43 | key_vault_client["medicalRecords"].drop_collection("patients") 44 | key_vault_client[key_vault_db][key_vault_coll].create_index( 45 | [("keyAltNames", ASCENDING)], 46 | unique=True, 47 | partialFilterExpression={"keyAltNames": {"$exists": True}}, 48 | ) 49 | # end-create-index 50 | 51 | 52 | # start-create-dek 53 | key_vault_database = "encryption" 54 | key_vault_collection = "__keyVault" 55 | key_vault_namespace = f"{key_vault_database}.{key_vault_collection}" 56 | 57 | client = MongoClient(connection_string) 58 | client_encryption = ClientEncryption( 59 | kms_providers, # pass in the kms_providers variable from the previous step 60 | key_vault_namespace, 61 | client, 62 | CodecOptions(uuid_representation=STANDARD), 63 | ) 64 | data_key_id = client_encryption.create_data_key( 65 | provider, master_key, key_alt_names=["demo-data-key"] 66 | ) 67 | 68 | base_64_data_key_id = base64.b64encode(data_key_id) 69 | print("DataKeyId [base64]: ", base_64_data_key_id) 70 | # end-create-dek 71 | -------------------------------------------------------------------------------- /csfle/python/local/reader/make_data_key.py: -------------------------------------------------------------------------------- 1 | from pymongo import MongoClient, ASCENDING 2 | from pymongo.encryption_options import AutoEncryptionOpts 3 | from pymongo.encryption import ClientEncryption 4 | import base64 5 | import os 6 | from bson.codec_options import CodecOptions 7 | from bson.binary import STANDARD, UUID 8 | from your_credentials import get_credentials 9 | 10 | credentials = get_credentials() 11 | 12 | # start-local-cmk 13 | import os 14 | 15 | path = "master-key.txt" 16 | file_bytes = os.urandom(96) 17 | with open(path, "wb") as f: 18 | f.write(file_bytes) 19 | # end-local-cmk 20 | 21 | # start-kmsproviders 22 | path = "./master-key.txt" 23 | with open(path, "rb") as f: 24 | local_master_key = f.read() 25 | kms_providers = { 26 | "local": { 27 | "key": local_master_key # local_master_key variable from the previous step 28 | }, 29 | } 30 | # end-kmsproviders 31 | 32 | # start-datakeyopts 33 | # end-datakeyopts 34 | 35 | # start-create-index 36 | connection_string = credentials["MONGODB_URI"] 37 | 38 | key_vault_coll = "__keyVault" 39 | key_vault_db = "encryption" 40 | key_vault_namespace = f"{key_vault_db}.{key_vault_coll}" 41 | key_vault_client = MongoClient(connection_string) 42 | # Drop the Key Vault Collection in case you created this collection 43 | # in a previous run of this application. 44 | key_vault_client.drop_database(key_vault_db) 45 | # Drop the database storing your encrypted fields as all 46 | # the DEKs encrypting those fields were deleted in the preceding line. 47 | key_vault_client["medicalRecords"].drop_collection("patients") 48 | key_vault_client[key_vault_db][key_vault_coll].create_index( 49 | [("keyAltNames", ASCENDING)], 50 | unique=True, 51 | partialFilterExpression={"keyAltNames": {"$exists": True}}, 52 | ) 53 | # end-create-index 54 | 55 | 56 | # start-create-dek 57 | key_vault_database = "encryption" 58 | key_vault_collection = "__keyVault" 59 | key_vault_namespace = f"{key_vault_database}.{key_vault_collection}" 60 | 61 | client = MongoClient(connection_string) 62 | client_encryption = ClientEncryption( 63 | kms_providers, # pass in the kms_providers variable from the previous step 64 | key_vault_namespace, 65 | client, 66 | CodecOptions(uuid_representation=STANDARD), 67 | ) 68 | data_key_id = client_encryption.create_data_key( 69 | "local", key_alt_names=["demo-data-key"] 70 | ) 71 | 72 | base_64_data_key_id = base64.b64encode(data_key_id) 73 | print("DataKeyId [base64]: ", base_64_data_key_id) 74 | # end-create-dek 75 | -------------------------------------------------------------------------------- /csfle/python/gcp/reader/make_data_key.py: -------------------------------------------------------------------------------- 1 | from pymongo import MongoClient, ASCENDING 2 | from pymongo.encryption_options import AutoEncryptionOpts 3 | from pymongo.encryption import ClientEncryption 4 | import base64 5 | import os 6 | from bson.codec_options import CodecOptions 7 | from bson.binary import STANDARD, UUID 8 | from your_credentials import get_credentials 9 | 10 | credentials = get_credentials() 11 | 12 | 13 | # start-kmsproviders 14 | provider = "azure" 15 | provider = "gcp" 16 | kms_providers = { 17 | provider: { 18 | "email": credentials["GCP_EMAIL"], 19 | "privateKey": credentials["GCP_PRIVATE_KEY"], 20 | } 21 | } 22 | # end-kmsproviders 23 | 24 | # start-datakeyopts 25 | master_key = { 26 | "projectId": credentials["GCP_PROJECT_ID"], 27 | "location": credentials["GCP_LOCATION"], 28 | "keyRing": credentials["GCP_KEY_RING"], 29 | "keyName": credentials["GCP_KEY_NAME"], 30 | } 31 | # end-datakeyopts 32 | 33 | # start-create-index 34 | connection_string = credentials["MONGODB_URI"] 35 | 36 | key_vault_coll = "__keyVault" 37 | key_vault_db = "encryption" 38 | key_vault_namespace = f"{key_vault_db}.{key_vault_coll}" 39 | key_vault_client = MongoClient(connection_string) 40 | # Drop the Key Vault Collection in case you created this collection 41 | # in a previous run of this application. 42 | key_vault_client.drop_database(key_vault_db) 43 | # Drop the database storing your encrypted fields as all 44 | # the DEKs encrypting those fields were deleted in the preceding line. 45 | key_vault_client["medicalRecords"].drop_collection("patients") 46 | key_vault_client[key_vault_db][key_vault_coll].create_index( 47 | [("keyAltNames", ASCENDING)], 48 | unique=True, 49 | partialFilterExpression={"keyAltNames": {"$exists": True}}, 50 | ) 51 | # end-create-index 52 | 53 | 54 | # start-create-dek 55 | key_vault_database = "encryption" 56 | key_vault_collection = "__keyVault" 57 | key_vault_namespace = f"{key_vault_database}.{key_vault_collection}" 58 | 59 | client = MongoClient(connection_string) 60 | client_encryption = ClientEncryption( 61 | kms_providers, # pass in the kms_providers variable from the previous step 62 | key_vault_namespace, 63 | client, 64 | CodecOptions(uuid_representation=STANDARD), 65 | ) 66 | data_key_id = client_encryption.create_data_key( 67 | provider, master_key, key_alt_names=["demo-data-key"] 68 | ) 69 | 70 | base_64_data_key_id = base64.b64encode(data_key_id) 71 | print("DataKeyId [base64]: ", base_64_data_key_id) 72 | # end-create-dek 73 | -------------------------------------------------------------------------------- /csfle/node/kmip/reader/make_data_key.js: -------------------------------------------------------------------------------- 1 | const mongodb = require("mongodb"); 2 | const { MongoClient, Binary, ClientEncryption } = mongodb; 3 | 4 | const { getCredentials } = require("./your_credentials"); 5 | credentials = getCredentials(); 6 | 7 | // start-kmsproviders 8 | const provider = "kmip"; 9 | const kmsProviders = { 10 | kmip: { 11 | endpoint: credentials["KMIP_KMS_ENDPOINT"], 12 | }, 13 | }; 14 | // end-kmsproviders 15 | 16 | // start-datakeyopts 17 | const masterKey = {}; // an empty key object prompts your KMIP-compliant key provider to generate a new Customer Master Key 18 | // end-datakeyopts 19 | 20 | async function main() { 21 | // start-create-index 22 | const uri = credentials.MONGODB_URI; 23 | const keyVaultDatabase = "encryption"; 24 | const keyVaultCollection = "__keyVault"; 25 | const keyVaultNamespace = `${keyVaultDatabase}.${keyVaultCollection}`; 26 | const keyVaultClient = new MongoClient(uri); 27 | await keyVaultClient.connect(); 28 | const keyVaultDB = keyVaultClient.db(keyVaultDatabase); 29 | // Drop the Key Vault Collection in case you created this collection 30 | // in a previous run of this application. 31 | await keyVaultDB.dropDatabase(); 32 | // Drop the database storing your encrypted fields as all 33 | // the DEKs encrypting those fields were deleted in the preceding line. 34 | await keyVaultClient.db("medicalRecords").dropDatabase(); 35 | const keyVaultColl = keyVaultDB.collection(keyVaultCollection); 36 | await keyVaultColl.createIndex( 37 | { keyAltNames: 1 }, 38 | { 39 | unique: true, 40 | partialFilterExpression: { keyAltNames: { $exists: true } }, 41 | } 42 | ); 43 | // end-create-index 44 | 45 | // start-create-tls 46 | const tlsOptions = { 47 | kmip: { 48 | tlsCAFile: credentials.KMIP_TLS_CA_FILE, 49 | tlsCertificateKeyFile: credentials.KMIP_TLS_CERT_FILE, 50 | }, 51 | }; 52 | // end-create-tls 53 | 54 | // start-create-dek 55 | const client = new MongoClient(uri, { 56 | useNewUrlParser: true, 57 | useUnifiedTopology: true, 58 | }); 59 | await client.connect(); 60 | 61 | const encryption = new ClientEncryption(client, { 62 | keyVaultNamespace, 63 | kmsProviders, 64 | tlsOptions, 65 | }); 66 | const key = await encryption.createDataKey(provider, { 67 | masterKey: masterKey, 68 | keyAltNames: ["demo-data-key"], 69 | }); 70 | console.log("DataKeyId [base64]: ", key.toString("base64")); 71 | await keyVaultClient.close(); 72 | await client.close(); 73 | // end-create-dek 74 | } 75 | main(); 76 | -------------------------------------------------------------------------------- /queryable-encryption/java/aws/reader/src/main/java/com/mongodb/qe/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.qe; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | // AWS Credentials 33 | yourCredentials.put("AWS_ACCESS_KEY_ID", ""); 34 | yourCredentials.put("AWS_SECRET_ACCESS_KEY", ""); 35 | yourCredentials.put("AWS_KEY_REGION", ""); 36 | yourCredentials.put("AWS_KEY_ARN", ""); 37 | 38 | } 39 | private static void checkPlaceholders() throws Exception { 40 | Pattern p = Pattern.compile("<.*>$"); 41 | ArrayList errorBuffer = new ArrayList(); 42 | for (Map.Entry entry : yourCredentials.entrySet()) { 43 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 44 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 45 | errorBuffer.add(message); 46 | } 47 | } 48 | if (!errorBuffer.isEmpty()){ 49 | String message = String.join("\n", errorBuffer); 50 | throw new Exception(message); 51 | } 52 | } 53 | public static Map getCredentials() throws Exception { 54 | checkPlaceholders(); 55 | return yourCredentials; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /csfle/java/aws/reader/src/main/java/com/mongodb/csfle/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.csfle; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | // AWS Credentials 33 | yourCredentials.put("AWS_ACCESS_KEY_ID", ""); 34 | yourCredentials.put("AWS_SECRET_ACCESS_KEY", ""); 35 | yourCredentials.put("AWS_KEY_REGION", ""); 36 | yourCredentials.put("AWS_KEY_ARN", ""); 37 | 38 | } 39 | private static void checkPlaceholders() throws Exception { 40 | Pattern p = Pattern.compile("<.*>$"); 41 | ArrayList errorBuffer = new ArrayList(); 42 | for (Map.Entry entry : yourCredentials.entrySet()) { 43 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 44 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 45 | errorBuffer.add(message); 46 | } 47 | } 48 | if (!errorBuffer.isEmpty()){ 49 | String message = String.join("\n", errorBuffer); 50 | throw new Exception(message); 51 | } 52 | } 53 | public static Map getCredentials() throws Exception { 54 | checkPlaceholders(); 55 | return yourCredentials; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /csfle/python/kmip/reader/make_data_key.py: -------------------------------------------------------------------------------- 1 | from pymongo import MongoClient, ASCENDING 2 | from pymongo.encryption_options import AutoEncryptionOpts 3 | from pymongo.encryption import ClientEncryption 4 | import base64 5 | import os 6 | from bson.codec_options import CodecOptions 7 | from bson.binary import STANDARD, UUID 8 | from your_credentials import get_credentials 9 | 10 | credentials = get_credentials() 11 | 12 | 13 | # start-kmsproviders 14 | provider = "kmip" 15 | kms_providers = {provider: {"endpoint": credentials["KMIP_KMS_ENDPOINT"]}} 16 | # end-kmsproviders 17 | 18 | # start-datakeyopts 19 | master_key = ( 20 | {} 21 | ) # an empty key object prompts your KMIP-compliant key provider to generate a new Customer Master Key 22 | # end-datakeyopts 23 | 24 | # start-create-index 25 | connection_string = credentials["MONGODB_URI"] 26 | 27 | key_vault_coll = "__keyVault" 28 | key_vault_db = "encryption" 29 | key_vault_namespace = f"{key_vault_db}.{key_vault_coll}" 30 | key_vault_client = MongoClient(connection_string) 31 | # Drop the Key Vault Collection in case you created this collection 32 | # in a previous run of this application. 33 | key_vault_client.drop_database(key_vault_db) 34 | # Drop the database storing your encrypted fields as all 35 | # the DEKs encrypting those fields were deleted in the preceding line. 36 | key_vault_client["medicalRecords"].drop_collection("patients") 37 | key_vault_client[key_vault_db][key_vault_coll].create_index( 38 | [("keyAltNames", ASCENDING)], 39 | unique=True, 40 | partialFilterExpression={"keyAltNames": {"$exists": True}}, 41 | ) 42 | # end-create-index 43 | 44 | # start-create-tls 45 | tls_options = { 46 | "kmip": { 47 | "tlsCAFile": credentials["KMIP_TLS_CA_FILE"], 48 | "tlsCertificateKeyFile": credentials["KMIP_TLS_CERT_FILE"], 49 | } 50 | } 51 | # end-create-tls 52 | 53 | # start-create-dek 54 | key_vault_database = "encryption" 55 | key_vault_collection = "__keyVault" 56 | key_vault_namespace = f"{key_vault_database}.{key_vault_collection}" 57 | 58 | client = MongoClient(connection_string) 59 | client_encryption = ClientEncryption( 60 | kms_providers, # pass in the kms_providers variable from the previous step 61 | key_vault_namespace, 62 | client, 63 | CodecOptions(uuid_representation=STANDARD), 64 | kms_tls_options=tls_options, 65 | ) 66 | data_key_id = client_encryption.create_data_key( 67 | provider, master_key, key_alt_names=["demo-data-key"] 68 | ) 69 | 70 | base_64_data_key_id = base64.b64encode(data_key_id) 71 | print("DataKeyId [base64]: ", base_64_data_key_id) 72 | # end-create-dek 73 | -------------------------------------------------------------------------------- /queryable-encryption/java/gcp/reader/src/main/java/com/mongodb/qe/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.qe; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | // GCP Credentials 33 | yourCredentials.put("GCP_EMAIL", ""); 34 | yourCredentials.put("GCP_PRIVATE_KEY", ""); 35 | yourCredentials.put("GCP_PROJECT_ID", ""); 36 | yourCredentials.put("GCP_LOCATION", ""); 37 | yourCredentials.put("GCP_KEY_RING", ""); 38 | yourCredentials.put("GCP_KEY_NAME", ""); 39 | yourCredentials.put("GCP_KEY_VERSION", ""); 40 | 41 | } 42 | private static void checkPlaceholders() throws Exception { 43 | Pattern p = Pattern.compile("<.*>$"); 44 | ArrayList errorBuffer = new ArrayList(); 45 | for (Map.Entry entry : yourCredentials.entrySet()) { 46 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 47 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 48 | errorBuffer.add(message); 49 | } 50 | } 51 | if (!errorBuffer.isEmpty()){ 52 | String message = String.join("\n", errorBuffer); 53 | throw new Exception(message); 54 | } 55 | } 56 | public static Map getCredentials() throws Exception { 57 | checkPlaceholders(); 58 | return yourCredentials; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /csfle/java/gcp/reader/src/main/java/com/mongodb/csfle/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.csfle; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | // GCP Credentials 33 | yourCredentials.put("GCP_EMAIL", ""); 34 | yourCredentials.put("GCP_PRIVATE_KEY", ""); 35 | yourCredentials.put("GCP_PROJECT_ID", ""); 36 | yourCredentials.put("GCP_LOCATION", ""); 37 | yourCredentials.put("GCP_KEY_RING", ""); 38 | yourCredentials.put("GCP_KEY_NAME", ""); 39 | yourCredentials.put("GCP_KEY_VERSION", ""); 40 | 41 | } 42 | private static void checkPlaceholders() throws Exception { 43 | Pattern p = Pattern.compile("<.*>$"); 44 | ArrayList errorBuffer = new ArrayList(); 45 | for (Map.Entry entry : yourCredentials.entrySet()) { 46 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 47 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 48 | errorBuffer.add(message); 49 | } 50 | } 51 | if (!errorBuffer.isEmpty()){ 52 | String message = String.join("\n", errorBuffer); 53 | throw new Exception(message); 54 | } 55 | } 56 | public static Map getCredentials() throws Exception { 57 | checkPlaceholders(); 58 | return yourCredentials; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /queryable-encryption/java/azure/reader/src/main/java/com/mongodb/qe/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.qe; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | // Azure Credentials 33 | yourCredentials.put("AZURE_TENANT_ID", ""); 34 | yourCredentials.put("AZURE_CLIENT_ID", ""); 35 | yourCredentials.put("AZURE_CLIENT_SECRET", ""); 36 | yourCredentials.put("AZURE_KEY_NAME", ""); 37 | yourCredentials.put("AZURE_KEY_VERSION", ""); 38 | yourCredentials.put("AZURE_KEY_VAULT_ENDPOINT", ""); 39 | 40 | } 41 | private static void checkPlaceholders() throws Exception { 42 | Pattern p = Pattern.compile("<.*>$"); 43 | ArrayList errorBuffer = new ArrayList(); 44 | for (Map.Entry entry : yourCredentials.entrySet()) { 45 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 46 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 47 | errorBuffer.add(message); 48 | } 49 | } 50 | if (!errorBuffer.isEmpty()){ 51 | String message = String.join("\n", errorBuffer); 52 | throw new Exception(message); 53 | } 54 | } 55 | public static Map getCredentials() throws Exception { 56 | checkPlaceholders(); 57 | return yourCredentials; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /csfle/java/azure/reader/src/main/java/com/mongodb/csfle/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.csfle; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | // Azure Credentials 33 | yourCredentials.put("AZURE_TENANT_ID", ""); 34 | yourCredentials.put("AZURE_CLIENT_ID", ""); 35 | yourCredentials.put("AZURE_CLIENT_SECRET", ""); 36 | yourCredentials.put("AZURE_KEY_NAME", ""); 37 | yourCredentials.put("AZURE_KEY_VERSION", ""); 38 | yourCredentials.put("AZURE_KEY_VAULT_ENDPOINT", ""); 39 | 40 | } 41 | private static void checkPlaceholders() throws Exception { 42 | Pattern p = Pattern.compile("<.*>$"); 43 | ArrayList errorBuffer = new ArrayList(); 44 | for (Map.Entry entry : yourCredentials.entrySet()) { 45 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 46 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 47 | errorBuffer.add(message); 48 | } 49 | } 50 | if (!errorBuffer.isEmpty()){ 51 | String message = String.join("\n", errorBuffer); 52 | throw new Exception(message); 53 | } 54 | } 55 | public static Map getCredentials() throws Exception { 56 | checkPlaceholders(); 57 | return yourCredentials; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /queryable-encryption/python/exp/reader/insert_encrypted_document.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from pymongo import MongoClient 4 | from pymongo.encryption import ( 5 | Algorithm, 6 | AutoEncryptionOpts, 7 | ClientEncryption, 8 | QueryType, 9 | ) 10 | import pprint 11 | from your_credentials import get_credentials 12 | 13 | credentials = get_credentials() 14 | 15 | # start-key-vault 16 | key_vault_namespace = "encryption.__keyVault" 17 | key_vault_db_name, key_vault_coll_name = key_vault_namespace.split(".", 1) 18 | # end-key-vault 19 | 20 | # start-kmsproviders 21 | path = "./master-key.txt" 22 | with open(path, "rb") as f: 23 | local_master_key = f.read() 24 | 25 | kms_providers = { 26 | "local": { 27 | "key": local_master_key # local_master_key variable from the previous step 28 | }, 29 | } 30 | # end-kmsproviders 31 | 32 | # start-retrieve-deks 33 | connection_string = credentials["MONGODB_URI"] 34 | client = MongoClient(connection_string) 35 | key_vault = client[key_vault_db_name][key_vault_coll_name] 36 | 37 | data_key_id_1 = key_vault.find_one({"keyAltNames": "dataKey1"})["_id"] 38 | data_key_id_2 = key_vault.find_one({"keyAltNames": "dataKey2"})["_id"] 39 | # end-retrieve-deks 40 | 41 | # start-extra-options 42 | opts = AutoEncryptionOpts( 43 | kms_providers, 44 | key_vault.full_name, 45 | bypass_query_analysis=True, 46 | key_vault_client=client, 47 | crypt_shared_lib_path=credentials["SHARED_LIB_PATH"], 48 | ) 49 | # end-extra-options 50 | 51 | # start-client 52 | encrypted_client = MongoClient(connection_string, auto_encryption_opts=opts) 53 | db = encrypted_client.medicalRecords 54 | coll = db.patients 55 | # end-client 56 | 57 | # start-client-enc 58 | client_encryption = ClientEncryption( 59 | kms_providers, key_vault_namespace, client, client.codec_options 60 | ) 61 | # end-client-enc 62 | 63 | # start-insert 64 | patientId = 12345678 65 | medications = ["Atorvastatin", "Levothyroxine"] 66 | indexed_insert_payload = client_encryption.encrypt( 67 | patientId, Algorithm.INDEXED, data_key_id_1, contention_factor=1 68 | ) 69 | unindexed_insert_payload = client_encryption.encrypt( 70 | medications, Algorithm.UNINDEXED, data_key_id_2 71 | ) 72 | coll.insert_one( 73 | { 74 | "firstName": "Jon", 75 | "patientId": indexed_insert_payload, 76 | "medications": unindexed_insert_payload, 77 | } 78 | ) 79 | # end-insert 80 | 81 | # start-find 82 | find_payload = client_encryption.encrypt( 83 | patientId, 84 | Algorithm.INDEXED, 85 | data_key_id_1, 86 | query_type=QueryType.EQUALITY, 87 | contention_factor=1, 88 | ) 89 | doc = coll.find_one({"encryptedIndexed": find_payload}) 90 | print("\nReturned document:\n") 91 | pprint.pprint(doc) 92 | # end-find 93 | 94 | client_encryption.close() 95 | encrypted_client.close() 96 | client.close() 97 | -------------------------------------------------------------------------------- /queryable-encryption/java/kmip/reader/src/main/java/com/mongodb/qe/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.qe; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | // KMIP Credentials 33 | yourCredentials.put("KMIP_KMS_ENDPOINT", ""); 34 | yourCredentials.put("KMIP_TLS_CA_FILE", "/kmip_utils/certs/ca.pem'>"); 35 | yourCredentials.put("KMIP_TLS_CERT_FILE", "/kmip_utils/certs/client.pem'>"); 36 | yourCredentials.put("KMIP_TLS_CERT_P12", "/kmip_utils/certs/pcks_client.p12'>"); 37 | 38 | } 39 | private static void checkPlaceholders() throws Exception { 40 | Pattern p = Pattern.compile("<.*>$"); 41 | ArrayList errorBuffer = new ArrayList(); 42 | for (Map.Entry entry : yourCredentials.entrySet()) { 43 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 44 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 45 | errorBuffer.add(message); 46 | } 47 | } 48 | if (!errorBuffer.isEmpty()){ 49 | String message = String.join("\n", errorBuffer); 50 | throw new Exception(message); 51 | } 52 | } 53 | public static Map getCredentials() throws Exception { 54 | checkPlaceholders(); 55 | return yourCredentials; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /csfle/java/kmip/reader/src/main/java/com/mongodb/csfle/YourCredentials.java: -------------------------------------------------------------------------------- 1 | package com.mongodb.csfle; 2 | /* 3 | * Copyright 2008-present MongoDB, Inc. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.regex.Pattern; 24 | 25 | public class YourCredentials { 26 | private static Map yourCredentials; 27 | static { 28 | yourCredentials = new HashMap<>(); 29 | // Mongo Paths + URI 30 | yourCredentials.put("MONGODB_URI", ""); 31 | yourCredentials.put("SHARED_LIB_PATH", ""); 32 | // KMIP Credentials 33 | yourCredentials.put("KMIP_KMS_ENDPOINT", ""); 34 | yourCredentials.put("KMIP_TLS_CA_FILE", "/kmip_utils/certs/ca.pem'>"); 35 | yourCredentials.put("KMIP_TLS_CERT_FILE", "/kmip_utils/certs/client.pem'>"); 36 | yourCredentials.put("KMIP_TLS_CERT_P12", "/kmip_utils/certs/pcks_client.p12'>"); 37 | 38 | } 39 | private static void checkPlaceholders() throws Exception { 40 | Pattern p = Pattern.compile("<.*>$"); 41 | ArrayList errorBuffer = new ArrayList(); 42 | for (Map.Entry entry : yourCredentials.entrySet()) { 43 | if(p.matcher(String.valueOf(entry.getValue())).matches()){ 44 | String message = String.format("The value for %s is empty. Please enter something for this value.", entry.getKey()); 45 | errorBuffer.add(message); 46 | } 47 | } 48 | if (!errorBuffer.isEmpty()){ 49 | String message = String.join("\n", errorBuffer); 50 | throw new Exception(message); 51 | } 52 | } 53 | public static Map getCredentials() throws Exception { 54 | checkPlaceholders(); 55 | return yourCredentials; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /csfle/go/aws/reader/make-data-key.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/base64" 6 | "fmt" 7 | "log" 8 | 9 | "go.mongodb.org/mongo-driver/bson" 10 | "go.mongodb.org/mongo-driver/mongo" 11 | "go.mongodb.org/mongo-driver/mongo/options" 12 | ) 13 | 14 | func MakeKey() error { 15 | 16 | credentials := GetCredentials() 17 | 18 | // start-kmsproviders 19 | provider := "aws" 20 | kmsProviders := map[string]map[string]interface{}{ 21 | provider: { 22 | "accessKeyId": credentials["AWS_ACCESS_KEY_ID"], 23 | "secretAccessKey": credentials["AWS_SECRET_ACCESS_KEY"], 24 | }, 25 | } 26 | // end-kmsproviders 27 | 28 | // start-datakeyopts 29 | masterKey := map[string]interface{}{ 30 | "key": credentials["AWS_KEY_ARN"], 31 | "region": credentials["AWS_KEY_REGION"], 32 | } 33 | // end-datakeyopts 34 | 35 | // start-create-index 36 | uri := credentials["MONGODB_URI"] 37 | keyVaultClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) 38 | if err != nil { 39 | return fmt.Errorf("Connect error for regular client: %v", err) 40 | } 41 | defer func() { 42 | _ = keyVaultClient.Disconnect(context.TODO()) 43 | }() 44 | 45 | keyVaultColl := "__keyVault" 46 | keyVaultDb := "encryption" 47 | keyVaultNamespace := keyVaultDb + "." + keyVaultColl 48 | keyVaultIndex := mongo.IndexModel{ 49 | Keys: bson.D{{"keyAltNames", 1}}, 50 | Options: options.Index(). 51 | SetUnique(true). 52 | SetPartialFilterExpression(bson.D{ 53 | {"keyAltNames", bson.D{ 54 | {"$exists", true}, 55 | }}, 56 | }), 57 | } 58 | // Drop the Key Vault Collection in case you created this collection 59 | // in a previous run of this application. 60 | if err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Drop(context.TODO()); err != nil { 61 | log.Fatalf("Collection.Drop error: %v", err) 62 | } 63 | // Drop the database storing your encrypted fields as all 64 | // the DEKs encrypting those fields were deleted in the preceding line. 65 | if err = keyVaultClient.Database("medicalRecords").Collection("patients").Drop(context.TODO()); err != nil { 66 | log.Fatalf("Collection.Drop error: %v", err) 67 | } 68 | _, err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Indexes().CreateOne(context.TODO(), keyVaultIndex) 69 | if err != nil { 70 | panic(err) 71 | } 72 | // end-create-index 73 | 74 | // start-create-dek 75 | clientEncryptionOpts := options.ClientEncryption().SetKeyVaultNamespace(keyVaultNamespace). 76 | SetKmsProviders(kmsProviders) 77 | clientEnc, err := mongo.NewClientEncryption(keyVaultClient, clientEncryptionOpts) 78 | if err != nil { 79 | return fmt.Errorf("NewClientEncryption error %v", err) 80 | } 81 | defer func() { 82 | _ = clientEnc.Close(context.TODO()) 83 | }() 84 | dataKeyOpts := options.DataKey(). 85 | SetMasterKey(masterKey). 86 | SetKeyAltNames([]string{"demo-data-key"}) 87 | 88 | dataKeyID, err := clientEnc.CreateDataKey(context.TODO(), provider, dataKeyOpts) 89 | if err != nil { 90 | return fmt.Errorf("create data key error %v", err) 91 | } 92 | 93 | fmt.Printf("DataKeyId [base64]: %s\n", base64.StdEncoding.EncodeToString(dataKeyID.Data)) 94 | // end-create-dek 95 | return nil 96 | } 97 | -------------------------------------------------------------------------------- /csfle/go/azure/reader/make-data-key.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/base64" 6 | "fmt" 7 | "log" 8 | 9 | "go.mongodb.org/mongo-driver/bson" 10 | "go.mongodb.org/mongo-driver/mongo" 11 | "go.mongodb.org/mongo-driver/mongo/options" 12 | ) 13 | 14 | func MakeKey() error { 15 | 16 | credentials := GetCredentials() 17 | 18 | // start-kmsproviders 19 | provider := "azure" 20 | kmsProviders := map[string]map[string]interface{}{ 21 | provider: { 22 | "tenantId": credentials["AZURE_TENANT_ID"], 23 | "clientId": credentials["AZURE_CLIENT_ID"], 24 | "clientSecret": credentials["AZURE_CLIENT_SECRET"], 25 | }, 26 | } 27 | // end-kmsproviders 28 | 29 | // start-datakeyopts 30 | masterKey := map[string]interface{}{ 31 | "keyVaultEndpoint": credentials["AZURE_KEY_VAULT_ENDPOINT"], 32 | "keyName": credentials["AZURE_KEY_NAME"], 33 | } 34 | // end-datakeyopts 35 | 36 | // start-create-index 37 | uri := credentials["MONGODB_URI"] 38 | keyVaultClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) 39 | if err != nil { 40 | return fmt.Errorf("Connect error for regular client: %v", err) 41 | } 42 | defer func() { 43 | _ = keyVaultClient.Disconnect(context.TODO()) 44 | }() 45 | 46 | keyVaultColl := "__keyVault" 47 | keyVaultDb := "encryption" 48 | keyVaultNamespace := keyVaultDb + "." + keyVaultColl 49 | keyVaultIndex := mongo.IndexModel{ 50 | Keys: bson.D{{"keyAltNames", 1}}, 51 | Options: options.Index(). 52 | SetUnique(true). 53 | SetPartialFilterExpression(bson.D{ 54 | {"keyAltNames", bson.D{ 55 | {"$exists", true}, 56 | }}, 57 | }), 58 | } 59 | // Drop the Key Vault Collection in case you created this collection 60 | // in a previous run of this application. 61 | if err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Drop(context.TODO()); err != nil { 62 | log.Fatalf("Collection.Drop error: %v", err) 63 | } 64 | // Drop the database storing your encrypted fields as all 65 | // the DEKs encrypting those fields were deleted in the preceding line. 66 | if err = keyVaultClient.Database("medicalRecords").Collection("patients").Drop(context.TODO()); err != nil { 67 | log.Fatalf("Collection.Drop error: %v", err) 68 | } 69 | _, err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Indexes().CreateOne(context.TODO(), keyVaultIndex) 70 | if err != nil { 71 | panic(err) 72 | } 73 | // end-create-index 74 | 75 | // start-create-dek 76 | clientEncryptionOpts := options.ClientEncryption().SetKeyVaultNamespace(keyVaultNamespace). 77 | SetKmsProviders(kmsProviders) 78 | clientEnc, err := mongo.NewClientEncryption(keyVaultClient, clientEncryptionOpts) 79 | if err != nil { 80 | return fmt.Errorf("NewClientEncryption error %v", err) 81 | } 82 | defer func() { 83 | _ = clientEnc.Close(context.TODO()) 84 | }() 85 | dataKeyOpts := options.DataKey(). 86 | SetMasterKey(masterKey). 87 | SetKeyAltNames([]string{"demo-data-key"}) 88 | 89 | dataKeyID, err := clientEnc.CreateDataKey(context.TODO(), provider, dataKeyOpts) 90 | if err != nil { 91 | return fmt.Errorf("create data key error %v", err) 92 | } 93 | 94 | fmt.Printf("DataKeyId [base64]: %s\n", base64.StdEncoding.EncodeToString(dataKeyID.Data)) 95 | // end-create-dek 96 | return nil 97 | } 98 | -------------------------------------------------------------------------------- /csfle/go/gcp/reader/make-data-key.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/base64" 6 | "fmt" 7 | "log" 8 | 9 | "go.mongodb.org/mongo-driver/bson" 10 | "go.mongodb.org/mongo-driver/mongo" 11 | "go.mongodb.org/mongo-driver/mongo/options" 12 | ) 13 | 14 | func MakeKey() error { 15 | 16 | credentials := GetCredentials() 17 | 18 | // start-kmsproviders 19 | provider := "gcp" 20 | kmsProviders := map[string]map[string]interface{}{ 21 | provider: { 22 | "email": credentials["GCP_EMAIL"], 23 | "privateKey": credentials["GCP_PRIVATE_KEY"], 24 | }, 25 | } 26 | // end-kmsproviders 27 | 28 | // start-datakeyopts 29 | masterKey := map[string]interface{}{ 30 | "projectId": credentials["GCP_PROJECT_ID"], 31 | "location": credentials["GCP_LOCATION"], 32 | "keyRing": credentials["GCP_KEY_RING"], 33 | "keyName": credentials["GCP_KEY_NAME"], 34 | } 35 | // end-datakeyopts 36 | 37 | // start-create-index 38 | uri := credentials["MONGODB_URI"] 39 | keyVaultClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) 40 | if err != nil { 41 | return fmt.Errorf("Connect error for regular client: %v", err) 42 | } 43 | defer func() { 44 | _ = keyVaultClient.Disconnect(context.TODO()) 45 | }() 46 | 47 | keyVaultColl := "__keyVault" 48 | keyVaultDb := "encryption" 49 | keyVaultNamespace := keyVaultDb + "." + keyVaultColl 50 | keyVaultIndex := mongo.IndexModel{ 51 | Keys: bson.D{{"keyAltNames", 1}}, 52 | Options: options.Index(). 53 | SetUnique(true). 54 | SetPartialFilterExpression(bson.D{ 55 | {"keyAltNames", bson.D{ 56 | {"$exists", true}, 57 | }}, 58 | }), 59 | } 60 | // Drop the Key Vault Collection in case you created this collection 61 | // in a previous run of this application. 62 | if err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Drop(context.TODO()); err != nil { 63 | log.Fatalf("Collection.Drop error: %v", err) 64 | } 65 | // Drop the database storing your encrypted fields as all 66 | // the DEKs encrypting those fields were deleted in the preceding line. 67 | if err = keyVaultClient.Database("medicalRecords").Collection("patients").Drop(context.TODO()); err != nil { 68 | log.Fatalf("Collection.Drop error: %v", err) 69 | } 70 | _, err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Indexes().CreateOne(context.TODO(), keyVaultIndex) 71 | if err != nil { 72 | panic(err) 73 | } 74 | // end-create-index 75 | 76 | // start-create-dek 77 | clientEncryptionOpts := options.ClientEncryption().SetKeyVaultNamespace(keyVaultNamespace). 78 | SetKmsProviders(kmsProviders) 79 | clientEnc, err := mongo.NewClientEncryption(keyVaultClient, clientEncryptionOpts) 80 | if err != nil { 81 | return fmt.Errorf("NewClientEncryption error %v", err) 82 | } 83 | defer func() { 84 | _ = clientEnc.Close(context.TODO()) 85 | }() 86 | dataKeyOpts := options.DataKey(). 87 | SetMasterKey(masterKey). 88 | SetKeyAltNames([]string{"demo-data-key"}) 89 | 90 | dataKeyID, err := clientEnc.CreateDataKey(context.TODO(), provider, dataKeyOpts) 91 | if err != nil { 92 | return fmt.Errorf("create data key error %v", err) 93 | } 94 | 95 | fmt.Printf("DataKeyId [base64]: %s\n", base64.StdEncoding.EncodeToString(dataKeyID.Data)) 96 | // end-create-dek 97 | return nil 98 | } 99 | -------------------------------------------------------------------------------- /queryable-encryption/node/exp/reader/insert_encrypted_document.js: -------------------------------------------------------------------------------- 1 | const { MongoClient } = require("mongodb"); 2 | const { ClientEncryption } = require("mongodb-client-encryption"); 3 | 4 | const { getCredentials } = require("./your_credentials"); 5 | credentials = getCredentials(); 6 | 7 | // start-key-vault 8 | const eDB = "encryption"; 9 | const eKV = "__keyVault"; 10 | const keyVaultNamespace = `${eDB}.${eKV}`; 11 | const secretDB = "medicalRecords"; 12 | const secretCollection = "patients"; 13 | // end-key-vault 14 | 15 | // start-kmsproviders 16 | const fs = require("fs"); 17 | const path = "./master-key.txt"; 18 | // WARNING: Do not use a local key file in a production application 19 | const localMasterKey = fs.readFileSync(path); 20 | const kmsProviders = { 21 | local: { 22 | key: localMasterKey, 23 | }, 24 | }; 25 | // end-kmsproviders 26 | 27 | async function run() { 28 | // start-retrieve-deks 29 | const uri = credentials.MONGODB_URI; 30 | const unencryptedClient = new MongoClient(uri); 31 | await unencryptedClient.connect(); 32 | const keyVaultClient = unencryptedClient.db(eDB).collection(eKV); 33 | const dek1 = await keyVaultClient.findOne({ keyAltNames: "dataKey1" }); 34 | const dek2 = await keyVaultClient.findOne({ keyAltNames: "dataKey2" }); 35 | // end-retrieve-deks 36 | 37 | // start-extra-options 38 | const extraOptions = { 39 | cryptSharedLibPath: credentials["SHARED_LIB_PATH"], 40 | }; 41 | // end-extra-options 42 | 43 | // start-client 44 | const encryptedClient = new MongoClient(uri, { 45 | autoEncryption: { 46 | kmsProviders: kmsProviders, 47 | keyVaultNamespace: keyVaultNamespace, 48 | bypassQueryAnalysis: true, 49 | keyVaultClient: unencryptedClient, 50 | extraOptions: extraOptions, 51 | }, 52 | }); 53 | await encryptedClient.connect(); 54 | // end-client 55 | 56 | // start-client-enc 57 | const encryption = new ClientEncryption(unencryptedClient, { 58 | keyVaultNamespace, 59 | kmsProviders, 60 | }); 61 | // end-client-enc 62 | 63 | try { 64 | // start-insert 65 | const patientId = 12345678; 66 | const medications = ["Atorvastatin", "Levothyroxine"]; 67 | 68 | const indexedInsertPayload = await encryption.encrypt(patientId, { 69 | algorithm: "Indexed", 70 | keyId: dek1._id, 71 | contentionFactor: 1, 72 | }); 73 | const unindexedInsertPayload = await encryption.encrypt(medications, { 74 | algorithm: "Unindexed", 75 | keyId: dek2._id, 76 | }); 77 | const encryptedColl = encryptedClient 78 | .db(secretDB) 79 | .collection(secretCollection); 80 | await encryptedColl.insertOne({ 81 | firstName: "Jon", 82 | patientId: indexedInsertPayload, 83 | medications: unindexedInsertPayload, 84 | }); 85 | // end-insert 86 | // start-find 87 | const findPayload = await encryption.encrypt(patientId, { 88 | algorithm: "Indexed", 89 | keyId: dek1._id, 90 | queryType: "equality", 91 | contentionFactor: 1, 92 | }); 93 | 94 | console.log("Finding a document with manually encrypted field:"); 95 | console.log(await encryptedColl.findOne({ patientId: findPayload })); 96 | // end-find 97 | } finally { 98 | await unencryptedClient.close(); 99 | await encryptedClient.close(); 100 | } 101 | } 102 | 103 | run().catch(console.dir); 104 | -------------------------------------------------------------------------------- /csfle/go/kmip/reader/make-data-key.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/base64" 6 | "fmt" 7 | "log" 8 | 9 | "crypto/tls" 10 | 11 | "go.mongodb.org/mongo-driver/bson" 12 | "go.mongodb.org/mongo-driver/mongo" 13 | "go.mongodb.org/mongo-driver/mongo/options" 14 | ) 15 | 16 | func MakeKey() error { 17 | 18 | credentials := GetCredentials() 19 | 20 | // start-kmsproviders 21 | provider := "kmip" 22 | kmsProviders := map[string]map[string]interface{}{ 23 | provider: { 24 | "endpoint": credentials["KMIP_KMS_ENDPOINT"], 25 | }, 26 | } 27 | // end-kmsproviders 28 | 29 | // start-datakeyopts 30 | masterKey := map[string]interface{}{} // an empty key object prompts your KMIP-compliant key provider to generate a new Customer Master Key 31 | // end-datakeyopts 32 | 33 | // start-create-index 34 | uri := credentials["MONGODB_URI"] 35 | keyVaultClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) 36 | if err != nil { 37 | return fmt.Errorf("Connect error for regular client: %v", err) 38 | } 39 | defer func() { 40 | _ = keyVaultClient.Disconnect(context.TODO()) 41 | }() 42 | 43 | keyVaultColl := "__keyVault" 44 | keyVaultDb := "encryption" 45 | keyVaultNamespace := keyVaultDb + "." + keyVaultColl 46 | keyVaultIndex := mongo.IndexModel{ 47 | Keys: bson.D{{"keyAltNames", 1}}, 48 | Options: options.Index(). 49 | SetUnique(true). 50 | SetPartialFilterExpression(bson.D{ 51 | {"keyAltNames", bson.D{ 52 | {"$exists", true}, 53 | }}, 54 | }), 55 | } 56 | // Drop the Key Vault Collection in case you created this collection 57 | // in a previous run of this application. 58 | if err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Drop(context.TODO()); err != nil { 59 | log.Fatalf("Collection.Drop error: %v", err) 60 | } 61 | // Drop the database storing your encrypted fields as all 62 | // the DEKs encrypting those fields were deleted in the preceding line. 63 | if err = keyVaultClient.Database("medicalRecords").Collection("patients").Drop(context.TODO()); err != nil { 64 | log.Fatalf("Collection.Drop error: %v", err) 65 | } 66 | _, err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Indexes().CreateOne(context.TODO(), keyVaultIndex) 67 | if err != nil { 68 | panic(err) 69 | } 70 | // end-create-index 71 | 72 | // start-create-tls 73 | tlsConfig := make(map[string]*tls.Config) 74 | tlsOpts := map[string]interface{}{ 75 | "tlsCertificateKeyFile": credentials["KMIP_TLS_CERT_FILE"], 76 | "tlsCAFile": credentials["KMIP_TLS_CA_FILE"], 77 | } 78 | kmipConfig, err := options.BuildTLSConfig(tlsOpts) 79 | tlsConfig["kmip"] = kmipConfig 80 | // end-create-tls 81 | 82 | // start-create-dek 83 | clientEncryptionOpts := options.ClientEncryption().SetKeyVaultNamespace(keyVaultNamespace). 84 | SetKmsProviders(kmsProviders).SetTLSConfig(tlsConfig) 85 | clientEnc, err := mongo.NewClientEncryption(keyVaultClient, clientEncryptionOpts) 86 | if err != nil { 87 | return fmt.Errorf("NewClientEncryption error %v", err) 88 | } 89 | defer func() { 90 | _ = clientEnc.Close(context.TODO()) 91 | }() 92 | dataKeyOpts := options.DataKey(). 93 | SetMasterKey(masterKey). 94 | SetKeyAltNames([]string{"demo-data-key"}) 95 | 96 | dataKeyID, err := clientEnc.CreateDataKey(context.TODO(), provider, dataKeyOpts) 97 | if err != nil { 98 | return fmt.Errorf("create data key error %v", err) 99 | } 100 | 101 | fmt.Printf("DataKeyId [base64]: %s\n", base64.StdEncoding.EncodeToString(dataKeyID.Data)) 102 | // end-create-dek 103 | return nil 104 | } 105 | -------------------------------------------------------------------------------- /csfle/go/local/reader/make-data-key.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/base64" 6 | "fmt" 7 | "log" 8 | 9 | "go.mongodb.org/mongo-driver/bson" 10 | "go.mongodb.org/mongo-driver/mongo" 11 | "go.mongodb.org/mongo-driver/mongo/options" 12 | ) 13 | 14 | import ( 15 | "crypto/rand" 16 | "io/ioutil" 17 | ) 18 | 19 | // start-local-cmk 20 | func localMasterKey() []byte { 21 | key := make([]byte, 96) 22 | if _, err := rand.Read(key); err != nil { 23 | log.Fatalf("Unable to create a random 96 byte data key: %v", err) 24 | } 25 | if err := ioutil.WriteFile("master-key.txt", key, 0644); err != nil { 26 | log.Fatalf("Unable to write key to file: %v", err) 27 | } 28 | return key 29 | } 30 | 31 | // end-local-cmk 32 | 33 | func MakeKey() error { 34 | 35 | credentials := GetCredentials() 36 | 37 | localMasterKey() 38 | 39 | // start-kmsproviders 40 | key, err := ioutil.ReadFile("master-key.txt") 41 | if err != nil { 42 | log.Fatalf("Could not read the key from master-key.txt: %v", err) 43 | } 44 | provider := "local" 45 | kmsProviders := map[string]map[string]interface{}{"local": {"key": key}} 46 | // end-kmsproviders 47 | 48 | // start-datakeyopts 49 | // end-datakeyopts 50 | 51 | // start-create-index 52 | uri := credentials["MONGODB_URI"] 53 | keyVaultClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) 54 | if err != nil { 55 | return fmt.Errorf("Connect error for regular client: %v", err) 56 | } 57 | defer func() { 58 | _ = keyVaultClient.Disconnect(context.TODO()) 59 | }() 60 | 61 | keyVaultColl := "__keyVault" 62 | keyVaultDb := "encryption" 63 | keyVaultNamespace := keyVaultDb + "." + keyVaultColl 64 | keyVaultIndex := mongo.IndexModel{ 65 | Keys: bson.D{{"keyAltNames", 1}}, 66 | Options: options.Index(). 67 | SetUnique(true). 68 | SetPartialFilterExpression(bson.D{ 69 | {"keyAltNames", bson.D{ 70 | {"$exists", true}, 71 | }}, 72 | }), 73 | } 74 | // Drop the Key Vault Collection in case you created this collection 75 | // in a previous run of this application. 76 | if err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Drop(context.TODO()); err != nil { 77 | log.Fatalf("Collection.Drop error: %v", err) 78 | } 79 | // Drop the database storing your encrypted fields as all 80 | // the DEKs encrypting those fields were deleted in the preceding line. 81 | if err = keyVaultClient.Database("medicalRecords").Collection("patients").Drop(context.TODO()); err != nil { 82 | log.Fatalf("Collection.Drop error: %v", err) 83 | } 84 | _, err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Indexes().CreateOne(context.TODO(), keyVaultIndex) 85 | if err != nil { 86 | panic(err) 87 | } 88 | // end-create-index 89 | 90 | // start-create-dek 91 | clientEncryptionOpts := options.ClientEncryption().SetKeyVaultNamespace(keyVaultNamespace). 92 | SetKmsProviders(kmsProviders) 93 | clientEnc, err := mongo.NewClientEncryption(keyVaultClient, clientEncryptionOpts) 94 | if err != nil { 95 | return fmt.Errorf("NewClientEncryption error %v", err) 96 | } 97 | defer func() { 98 | _ = clientEnc.Close(context.TODO()) 99 | }() 100 | dataKeyOpts := options.DataKey(). 101 | SetKeyAltNames([]string{"demo-data-key"}) 102 | 103 | dataKeyID, err := clientEnc.CreateDataKey(context.TODO(), provider, dataKeyOpts) 104 | if err != nil { 105 | return fmt.Errorf("create data key error %v", err) 106 | } 107 | 108 | fmt.Printf("DataKeyId [base64]: %s\n", base64.StdEncoding.EncodeToString(dataKeyID.Data)) 109 | // end-create-dek 110 | return nil 111 | } 112 | -------------------------------------------------------------------------------- /csfle/python/gcp/reader/insert_encrypted_document.py: -------------------------------------------------------------------------------- 1 | from pymongo import MongoClient 2 | from pymongo.encryption_options import AutoEncryptionOpts 3 | from pymongo.encryption import ClientEncryption 4 | import base64 5 | import os 6 | from bson.codec_options import CodecOptions 7 | from bson.binary import STANDARD, UUID 8 | import pprint 9 | from your_credentials import get_credentials 10 | 11 | credentials = get_credentials() 12 | 13 | # start-key-vault 14 | key_vault_namespace = "encryption.__keyVault" 15 | # end-key-vault 16 | 17 | connection_string = credentials["MONGODB_URI"] 18 | 19 | # start-kmsproviders 20 | provider = "gcp" 21 | kms_providers = { 22 | "gcp": { 23 | "email": credentials["GCP_EMAIL"], 24 | "privateKey": credentials["GCP_PRIVATE_KEY"], 25 | } 26 | } 27 | # end-kmsproviders 28 | 29 | # start-schema 30 | # Make All fields random to use json pointer to reference key-id 31 | json_schema = { 32 | "bsonType": "object", 33 | "encryptMetadata": {"keyId": "/key-id"}, 34 | "properties": { 35 | "insurance": { 36 | "bsonType": "object", 37 | "properties": { 38 | "policyNumber": { 39 | "encrypt": { 40 | "bsonType": "int", 41 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 42 | } 43 | } 44 | }, 45 | }, 46 | "medicalRecords": { 47 | "encrypt": { 48 | "bsonType": "array", 49 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 50 | } 51 | }, 52 | "bloodType": { 53 | "encrypt": { 54 | "bsonType": "string", 55 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 56 | } 57 | }, 58 | "ssn": { 59 | "encrypt": { 60 | "bsonType": "int", 61 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 62 | } 63 | }, 64 | }, 65 | } 66 | 67 | patient_schema = {"medicalRecords.patients": json_schema} 68 | # end-schema 69 | 70 | 71 | # start-extra-options 72 | extra_options = {"crypt_shared_lib_path": credentials["SHARED_LIB_PATH"]} 73 | # end-extra-options 74 | 75 | # start-client 76 | fle_opts = AutoEncryptionOpts( 77 | kms_providers, key_vault_namespace, schema_map=patient_schema, **extra_options 78 | ) 79 | secureClient = MongoClient(connection_string, auto_encryption_opts=fle_opts) 80 | # end-client 81 | 82 | # start-insert 83 | def insert_patient( 84 | collection, name, ssn, blood_type, medical_records, policy_number, provider 85 | ): 86 | insurance = {"policyNumber": policy_number, "provider": provider} 87 | doc = { 88 | "name": name, 89 | "ssn": ssn, 90 | "bloodType": blood_type, 91 | "medicalRecords": medical_records, 92 | "insurance": insurance, 93 | "key-id": "demo-data-key", 94 | } 95 | collection.insert_one(doc) 96 | 97 | 98 | medical_record = [{"weight": 180, "bloodPressure": "120/80"}] 99 | insert_patient( 100 | secureClient.medicalRecords.patients, 101 | "Jon Doe", 102 | 241014209, 103 | "AB+", 104 | medical_record, 105 | 123142, 106 | "MaestCare", 107 | ) 108 | # end-insert 109 | regularClient = MongoClient(connection_string) 110 | # start-find 111 | print("Finding a document with regular (non-encrypted) client.") 112 | result = regularClient.medicalRecords.patients.find_one({"name": "Jon Doe"}) 113 | pprint.pprint(result) 114 | 115 | print("Finding a document with encrypted client, searching on an encrypted field") 116 | pprint.pprint(secureClient.medicalRecords.patients.find_one({"name": "Jon Doe"})) 117 | # end-find 118 | -------------------------------------------------------------------------------- /csfle/python/aws/reader/insert_encrypted_document.py: -------------------------------------------------------------------------------- 1 | from pymongo import MongoClient 2 | from pymongo.encryption_options import AutoEncryptionOpts 3 | from pymongo.encryption import ClientEncryption 4 | import base64 5 | import os 6 | from bson.codec_options import CodecOptions 7 | from bson.binary import STANDARD, UUID 8 | import pprint 9 | from your_credentials import get_credentials 10 | 11 | credentials = get_credentials() 12 | 13 | # start-key-vault 14 | key_vault_namespace = "encryption.__keyVault" 15 | # end-key-vault 16 | 17 | connection_string = credentials["MONGODB_URI"] 18 | 19 | # start-kmsproviders 20 | provider = "aws" 21 | kms_providers = { 22 | "aws": { 23 | "accessKeyId": credentials["AWS_ACCESS_KEY_ID"], 24 | "secretAccessKey": credentials["AWS_SECRET_ACCESS_KEY"], 25 | } 26 | } 27 | # end-kmsproviders 28 | 29 | # start-schema 30 | # Make All fields random to use json pointer to reference key-id 31 | json_schema = { 32 | "bsonType": "object", 33 | "encryptMetadata": {"keyId": "/key-id"}, 34 | "properties": { 35 | "insurance": { 36 | "bsonType": "object", 37 | "properties": { 38 | "policyNumber": { 39 | "encrypt": { 40 | "bsonType": "int", 41 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 42 | } 43 | } 44 | }, 45 | }, 46 | "medicalRecords": { 47 | "encrypt": { 48 | "bsonType": "array", 49 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 50 | } 51 | }, 52 | "bloodType": { 53 | "encrypt": { 54 | "bsonType": "string", 55 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 56 | } 57 | }, 58 | "ssn": { 59 | "encrypt": { 60 | "bsonType": "int", 61 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 62 | } 63 | }, 64 | }, 65 | } 66 | 67 | patient_schema = {"medicalRecords.patients": json_schema} 68 | # end-schema 69 | 70 | 71 | # start-extra-options 72 | extra_options = {"crypt_shared_lib_path": credentials["SHARED_LIB_PATH"]} 73 | # end-extra-options 74 | 75 | # start-client 76 | fle_opts = AutoEncryptionOpts( 77 | kms_providers, key_vault_namespace, schema_map=patient_schema, **extra_options 78 | ) 79 | secureClient = MongoClient(connection_string, auto_encryption_opts=fle_opts) 80 | # end-client 81 | 82 | # start-insert 83 | def insert_patient( 84 | collection, name, ssn, blood_type, medical_records, policy_number, provider 85 | ): 86 | insurance = {"policyNumber": policy_number, "provider": provider} 87 | doc = { 88 | "name": name, 89 | "ssn": ssn, 90 | "bloodType": blood_type, 91 | "medicalRecords": medical_records, 92 | "insurance": insurance, 93 | "key-id": "demo-data-key", 94 | } 95 | collection.insert_one(doc) 96 | 97 | 98 | medical_record = [{"weight": 180, "bloodPressure": "120/80"}] 99 | insert_patient( 100 | secureClient.medicalRecords.patients, 101 | "Jon Doe", 102 | 241014209, 103 | "AB+", 104 | medical_record, 105 | 123142, 106 | "MaestCare", 107 | ) 108 | # end-insert 109 | regularClient = MongoClient(connection_string) 110 | # start-find 111 | print("Finding a document with regular (non-encrypted) client.") 112 | result = regularClient.medicalRecords.patients.find_one({"name": "Jon Doe"}) 113 | pprint.pprint(result) 114 | 115 | print("Finding a document with encrypted client, searching on an encrypted field") 116 | pprint.pprint(secureClient.medicalRecords.patients.find_one({"name": "Jon Doe"})) 117 | # end-find 118 | -------------------------------------------------------------------------------- /csfle/python/local/reader/insert_encrypted_document.py: -------------------------------------------------------------------------------- 1 | from pymongo import MongoClient 2 | from pymongo.encryption_options import AutoEncryptionOpts 3 | from pymongo.encryption import ClientEncryption 4 | import base64 5 | import os 6 | from bson.codec_options import CodecOptions 7 | from bson.binary import STANDARD, UUID 8 | import pprint 9 | from your_credentials import get_credentials 10 | 11 | credentials = get_credentials() 12 | 13 | # start-key-vault 14 | key_vault_namespace = "encryption.__keyVault" 15 | # end-key-vault 16 | 17 | connection_string = credentials["MONGODB_URI"] 18 | 19 | # start-kmsproviders 20 | path = "./master-key.txt" 21 | with open(path, "rb") as f: 22 | local_master_key = f.read() 23 | kms_providers = { 24 | "local": { 25 | "key": local_master_key # local_master_key variable from the previous step 26 | }, 27 | } 28 | # end-kmsproviders 29 | 30 | # start-schema 31 | # Make All fields random to use json pointer to reference key-id 32 | json_schema = { 33 | "bsonType": "object", 34 | "encryptMetadata": {"keyId": "/key-id"}, 35 | "properties": { 36 | "insurance": { 37 | "bsonType": "object", 38 | "properties": { 39 | "policyNumber": { 40 | "encrypt": { 41 | "bsonType": "int", 42 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 43 | } 44 | } 45 | }, 46 | }, 47 | "medicalRecords": { 48 | "encrypt": { 49 | "bsonType": "array", 50 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 51 | } 52 | }, 53 | "bloodType": { 54 | "encrypt": { 55 | "bsonType": "string", 56 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 57 | } 58 | }, 59 | "ssn": { 60 | "encrypt": { 61 | "bsonType": "int", 62 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 63 | } 64 | }, 65 | }, 66 | } 67 | 68 | patient_schema = {"medicalRecords.patients": json_schema} 69 | # end-schema 70 | 71 | 72 | # start-extra-options 73 | extra_options = {"crypt_shared_lib_path": credentials["SHARED_LIB_PATH"]} 74 | # end-extra-options 75 | 76 | # start-client 77 | fle_opts = AutoEncryptionOpts( 78 | kms_providers, key_vault_namespace, schema_map=patient_schema, **extra_options 79 | ) 80 | secureClient = MongoClient(connection_string, auto_encryption_opts=fle_opts) 81 | # end-client 82 | 83 | # start-insert 84 | def insert_patient( 85 | collection, name, ssn, blood_type, medical_records, policy_number, provider 86 | ): 87 | insurance = {"policyNumber": policy_number, "provider": provider} 88 | doc = { 89 | "name": name, 90 | "ssn": ssn, 91 | "bloodType": blood_type, 92 | "medicalRecords": medical_records, 93 | "insurance": insurance, 94 | "key-id": "demo-data-key", 95 | } 96 | collection.insert_one(doc) 97 | 98 | 99 | medical_record = [{"weight": 180, "bloodPressure": "120/80"}] 100 | insert_patient( 101 | secureClient.medicalRecords.patients, 102 | "Jon Doe", 103 | 241014209, 104 | "AB+", 105 | medical_record, 106 | 123142, 107 | "MaestCare", 108 | ) 109 | # end-insert 110 | regularClient = MongoClient(connection_string) 111 | # start-find 112 | print("Finding a document with regular (non-encrypted) client.") 113 | result = regularClient.medicalRecords.patients.find_one({"name": "Jon Doe"}) 114 | pprint.pprint(result) 115 | 116 | print("Finding a document with encrypted client, searching on an encrypted field") 117 | pprint.pprint(secureClient.medicalRecords.patients.find_one({"name": "Jon Doe"})) 118 | # end-find 119 | -------------------------------------------------------------------------------- /csfle/python/azure/reader/insert_encrypted_document.py: -------------------------------------------------------------------------------- 1 | from pymongo import MongoClient 2 | from pymongo.encryption_options import AutoEncryptionOpts 3 | from pymongo.encryption import ClientEncryption 4 | import base64 5 | import os 6 | from bson.codec_options import CodecOptions 7 | from bson.binary import STANDARD, UUID 8 | import pprint 9 | from your_credentials import get_credentials 10 | 11 | credentials = get_credentials() 12 | 13 | # start-key-vault 14 | key_vault_namespace = "encryption.__keyVault" 15 | # end-key-vault 16 | 17 | connection_string = credentials["MONGODB_URI"] 18 | 19 | # start-kmsproviders 20 | provider = "azure" 21 | kms_providers = { 22 | "azure": { 23 | "tenantId": credentials["AZURE_TENANT_ID"], 24 | "clientId": credentials["AZURE_CLIENT_ID"], 25 | "clientSecret": credentials["AZURE_CLIENT_SECRET"], 26 | } 27 | } 28 | # end-kmsproviders 29 | 30 | # start-schema 31 | # Make All fields random to use json pointer to reference key-id 32 | json_schema = { 33 | "bsonType": "object", 34 | "encryptMetadata": {"keyId": "/key-id"}, 35 | "properties": { 36 | "insurance": { 37 | "bsonType": "object", 38 | "properties": { 39 | "policyNumber": { 40 | "encrypt": { 41 | "bsonType": "int", 42 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 43 | } 44 | } 45 | }, 46 | }, 47 | "medicalRecords": { 48 | "encrypt": { 49 | "bsonType": "array", 50 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 51 | } 52 | }, 53 | "bloodType": { 54 | "encrypt": { 55 | "bsonType": "string", 56 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 57 | } 58 | }, 59 | "ssn": { 60 | "encrypt": { 61 | "bsonType": "int", 62 | "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 63 | } 64 | }, 65 | }, 66 | } 67 | 68 | patient_schema = {"medicalRecords.patients": json_schema} 69 | # end-schema 70 | 71 | 72 | # start-extra-options 73 | extra_options = {"crypt_shared_lib_path": credentials["SHARED_LIB_PATH"]} 74 | # end-extra-options 75 | 76 | # start-client 77 | fle_opts = AutoEncryptionOpts( 78 | kms_providers, key_vault_namespace, schema_map=patient_schema, **extra_options 79 | ) 80 | secureClient = MongoClient(connection_string, auto_encryption_opts=fle_opts) 81 | # end-client 82 | 83 | # start-insert 84 | def insert_patient( 85 | collection, name, ssn, blood_type, medical_records, policy_number, provider 86 | ): 87 | insurance = {"policyNumber": policy_number, "provider": provider} 88 | doc = { 89 | "name": name, 90 | "ssn": ssn, 91 | "bloodType": blood_type, 92 | "medicalRecords": medical_records, 93 | "insurance": insurance, 94 | "key-id": "demo-data-key", 95 | } 96 | collection.insert_one(doc) 97 | 98 | 99 | medical_record = [{"weight": 180, "bloodPressure": "120/80"}] 100 | insert_patient( 101 | secureClient.medicalRecords.patients, 102 | "Jon Doe", 103 | 241014209, 104 | "AB+", 105 | medical_record, 106 | 123142, 107 | "MaestCare", 108 | ) 109 | # end-insert 110 | regularClient = MongoClient(connection_string) 111 | # start-find 112 | print("Finding a document with regular (non-encrypted) client.") 113 | result = regularClient.medicalRecords.patients.find_one({"name": "Jon Doe"}) 114 | pprint.pprint(result) 115 | 116 | print("Finding a document with encrypted client, searching on an encrypted field") 117 | pprint.pprint(secureClient.medicalRecords.patients.find_one({"name": "Jon Doe"})) 118 | # end-find 119 | -------------------------------------------------------------------------------- /csfle/node/gcp/reader/insert_encrypted_document.js: -------------------------------------------------------------------------------- 1 | const mongodb = require("mongodb"); 2 | const { MongoClient, Binary } = mongodb; 3 | 4 | const { getCredentials } = require("./your_credentials"); 5 | credentials = getCredentials(); 6 | 7 | var db = "medicalRecords"; 8 | var coll = "patients"; 9 | var namespace = `${db}.${coll}`; 10 | // start-kmsproviders 11 | const kmsProviders = { 12 | gcp: { 13 | email: credentials["GCP_EMAIL"], 14 | privateKey: credentials["GCP_PRIVATE_KEY"], 15 | }, 16 | }; 17 | // end-kmsproviders 18 | 19 | const connectionString = credentials.MONGODB_URI; 20 | 21 | // start-key-vault 22 | const keyVaultNamespace = "encryption.__keyVault"; 23 | // end-key-vault 24 | 25 | // start-schema 26 | const schema = { 27 | bsonType: "object", 28 | encryptMetadata: { 29 | keyId: "/key-id", 30 | }, 31 | properties: { 32 | insurance: { 33 | bsonType: "object", 34 | properties: { 35 | policyNumber: { 36 | encrypt: { 37 | bsonType: "int", 38 | algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 39 | }, 40 | }, 41 | }, 42 | }, 43 | medicalRecords: { 44 | encrypt: { 45 | bsonType: "array", 46 | algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 47 | }, 48 | }, 49 | bloodType: { 50 | encrypt: { 51 | bsonType: "string", 52 | algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 53 | }, 54 | }, 55 | ssn: { 56 | encrypt: { 57 | bsonType: "int", 58 | algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 59 | }, 60 | }, 61 | }, 62 | }; 63 | 64 | var patientSchema = {}; 65 | patientSchema[namespace] = schema; 66 | // end-schema 67 | 68 | // start-extra-options 69 | const extraOptions = { 70 | cryptSharedLibPath: credentials["SHARED_LIB_PATH"], 71 | }; 72 | // end-extra-options 73 | 74 | // start-client 75 | const secureClient = new MongoClient(connectionString, { 76 | useNewUrlParser: true, 77 | useUnifiedTopology: true, 78 | autoEncryption: { 79 | keyVaultNamespace, 80 | kmsProviders, 81 | schemaMap: patientSchema, 82 | extraOptions: extraOptions, 83 | }, 84 | }); 85 | // end-client 86 | const regularClient = new MongoClient(connectionString, { 87 | useNewUrlParser: true, 88 | useUnifiedTopology: true, 89 | }); 90 | 91 | async function main() { 92 | try { 93 | await regularClient.connect(); 94 | try { 95 | await secureClient.connect(); 96 | // start-insert 97 | try { 98 | const writeResult = await secureClient 99 | .db(db) 100 | .collection(coll) 101 | .insertOne({ 102 | name: "Jon Doe", 103 | ssn: 241014209, 104 | bloodType: "AB+", 105 | "key-id": "demo-data-key", 106 | medicalRecords: [{ weight: 180, bloodPressure: "120/80" }], 107 | insurance: { 108 | policyNumber: 123142, 109 | provider: "MaestCare", 110 | }, 111 | }); 112 | } catch (writeError) { 113 | console.error("writeError occurred:", writeError); 114 | } 115 | // end-insert 116 | // start-find 117 | console.log("Finding a document with regular (non-encrypted) client."); 118 | console.log( 119 | await regularClient.db(db).collection(coll).findOne({ name: /Jon/ }) 120 | ); 121 | 122 | console.log( 123 | "Finding a document with encrypted client, searching on an encrypted field" 124 | ); 125 | console.log( 126 | await secureClient.db(db).collection(coll).findOne({ name: /Jon/ }) 127 | ); 128 | // end-find 129 | } finally { 130 | await secureClient.close(); 131 | } 132 | } finally { 133 | await regularClient.close(); 134 | } 135 | } 136 | main(); 137 | -------------------------------------------------------------------------------- /csfle/node/aws/reader/insert_encrypted_document.js: -------------------------------------------------------------------------------- 1 | const mongodb = require("mongodb"); 2 | const { MongoClient, Binary } = mongodb; 3 | 4 | const { getCredentials } = require("./your_credentials"); 5 | credentials = getCredentials(); 6 | 7 | var db = "medicalRecords"; 8 | var coll = "patients"; 9 | var namespace = `${db}.${coll}`; 10 | // start-kmsproviders 11 | const kmsProviders = { 12 | aws: { 13 | accessKeyId: credentials["AWS_ACCESS_KEY_ID"], 14 | secretAccessKey: credentials["AWS_SECRET_ACCESS_KEY"], 15 | }, 16 | }; 17 | // end-kmsproviders 18 | 19 | const connectionString = credentials.MONGODB_URI; 20 | 21 | // start-key-vault 22 | const keyVaultNamespace = "encryption.__keyVault"; 23 | // end-key-vault 24 | 25 | // start-schema 26 | const schema = { 27 | bsonType: "object", 28 | encryptMetadata: { 29 | keyId: "/key-id", 30 | }, 31 | properties: { 32 | insurance: { 33 | bsonType: "object", 34 | properties: { 35 | policyNumber: { 36 | encrypt: { 37 | bsonType: "int", 38 | algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 39 | }, 40 | }, 41 | }, 42 | }, 43 | medicalRecords: { 44 | encrypt: { 45 | bsonType: "array", 46 | algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 47 | }, 48 | }, 49 | bloodType: { 50 | encrypt: { 51 | bsonType: "string", 52 | algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 53 | }, 54 | }, 55 | ssn: { 56 | encrypt: { 57 | bsonType: "int", 58 | algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Random", 59 | }, 60 | }, 61 | }, 62 | }; 63 | 64 | var patientSchema = {}; 65 | patientSchema[namespace] = schema; 66 | // end-schema 67 | 68 | // start-extra-options 69 | const extraOptions = { 70 | cryptSharedLibPath: credentials["SHARED_LIB_PATH"], 71 | }; 72 | // end-extra-options 73 | 74 | // start-client 75 | const secureClient = new MongoClient(connectionString, { 76 | useNewUrlParser: true, 77 | useUnifiedTopology: true, 78 | autoEncryption: { 79 | keyVaultNamespace, 80 | kmsProviders, 81 | schemaMap: patientSchema, 82 | extraOptions: extraOptions, 83 | }, 84 | }); 85 | // end-client 86 | const regularClient = new MongoClient(connectionString, { 87 | useNewUrlParser: true, 88 | useUnifiedTopology: true, 89 | }); 90 | 91 | async function main() { 92 | try { 93 | await regularClient.connect(); 94 | try { 95 | await secureClient.connect(); 96 | // start-insert 97 | try { 98 | const writeResult = await secureClient 99 | .db(db) 100 | .collection(coll) 101 | .insertOne({ 102 | name: "Jon Doe", 103 | ssn: 241014209, 104 | bloodType: "AB+", 105 | "key-id": "demo-data-key", 106 | medicalRecords: [{ weight: 180, bloodPressure: "120/80" }], 107 | insurance: { 108 | policyNumber: 123142, 109 | provider: "MaestCare", 110 | }, 111 | }); 112 | } catch (writeError) { 113 | console.error("writeError occurred:", writeError); 114 | } 115 | // end-insert 116 | // start-find 117 | console.log("Finding a document with regular (non-encrypted) client."); 118 | console.log( 119 | await regularClient.db(db).collection(coll).findOne({ name: /Jon/ }) 120 | ); 121 | 122 | console.log( 123 | "Finding a document with encrypted client, searching on an encrypted field" 124 | ); 125 | console.log( 126 | await secureClient.db(db).collection(coll).findOne({ name: /Jon/ }) 127 | ); 128 | // end-find 129 | } finally { 130 | await secureClient.close(); 131 | } 132 | } finally { 133 | await regularClient.close(); 134 | } 135 | } 136 | main(); 137 | --------------------------------------------------------------------------------