Skip to content

Commit 24b3aff

Browse files
authored
Add kmip tests, use mongoCrypt snapshot (mongodb#1406)
JAVA-5300
1 parent 3c8b44e commit 24b3aff

File tree

7 files changed

+670
-13
lines changed

7 files changed

+670
-13
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ext {
5555
zstdVersion = '1.5.5-3'
5656
awsSdkV2Version = '2.18.9'
5757
awsSdkV1Version = '1.12.337'
58-
mongoCryptVersion = '1.8.0'
58+
mongoCryptVersion = '1.10.0-SNAPSHOT'
5959
projectReactorVersion = '2022.0.0'
6060
junitBomVersion = '5.8.2'
6161
logbackVersion = '1.3.14'

driver-core/src/main/com/mongodb/client/model/vault/DataKeyOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ public List<String> getKeyAltNames() {
128128
* omitted, the driver creates a random 96 byte KMIP Secret Data managed object.</li>
129129
* <li>endpoint: a String, the endpoint as a host with required port. e.g. "example.com:443". If endpoint is not provided, it
130130
* defaults to the required endpoint from the KMS providers map.</li>
131+
* <li>delegated: If true (recommended), the KMIP server will perform
132+
* encryption and decryption. If delegated is not provided, defaults
133+
* to false.</li>
131134
* </ul>
132135
* <p>
133136
* If the kmsProvider is "local" the masterKey is not applicable.

driver-core/src/test/resources/client-side-encryption/legacy/azureKMS.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@
7878
"bsonType": "string",
7979
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
8080
}
81+
},
82+
"encrypted_string_kmip_delegated": {
83+
"encrypt": {
84+
"keyId": [
85+
{
86+
"$uuid": "7411e9af-c688-4df7-8143-5e60ae96cba6"
87+
}
88+
],
89+
"bsonType": "string",
90+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
91+
}
8192
}
8293
},
8394
"bsonType": "object"

driver-core/src/test/resources/client-side-encryption/legacy/gcpKMS.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@
7878
"bsonType": "string",
7979
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
8080
}
81+
},
82+
"encrypted_string_kmip_delegated": {
83+
"encrypt": {
84+
"keyId": [
85+
{
86+
"$uuid": "7411e9af-c688-4df7-8143-5e60ae96cba6"
87+
}
88+
],
89+
"bsonType": "string",
90+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
91+
}
8192
}
8293
},
8394
"bsonType": "object"

driver-core/src/test/resources/client-side-encryption/legacy/kmipKMS.json

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@
7878
"bsonType": "string",
7979
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
8080
}
81+
},
82+
"encrypted_string_kmip_delegated": {
83+
"encrypt": {
84+
"keyId": [
85+
{
86+
"$uuid": "7411e9af-c688-4df7-8143-5e60ae96cba6"
87+
}
88+
],
89+
"bsonType": "string",
90+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
91+
}
8192
}
8293
},
8394
"bsonType": "object"
@@ -117,6 +128,38 @@
117128
"altname",
118129
"kmip_altname"
119130
]
131+
},
132+
{
133+
"_id": {
134+
"$uuid": "7411e9af-c688-4df7-8143-5e60ae96cba6"
135+
},
136+
"keyMaterial": {
137+
"$binary": {
138+
"base64": "5TLMFWlguBWe5GUESTvOVtkdBsCrynhnV72XRyZ66/nk+EP9/1oEp1t1sg0+vwCTqULHjBiUE6DRx2mYD/Eup1+u2Jgz9/+1sV1drXeOPALNPkSgiZiDbIb67zRi+wTABEcKcegJH+FhmSGxwUoQAiHCsCbcvia5P8tN1lt98YQ=",
139+
"subType": "00"
140+
}
141+
},
142+
"creationDate": {
143+
"$date": {
144+
"$numberLong": "1634220190041"
145+
}
146+
},
147+
"updateDate": {
148+
"$date": {
149+
"$numberLong": "1634220190041"
150+
}
151+
},
152+
"status": {
153+
"$numberInt": "0"
154+
},
155+
"masterKey": {
156+
"provider": "kmip",
157+
"delegated": true,
158+
"keyId": "11"
159+
},
160+
"keyAltNames": [
161+
"delegated"
162+
]
120163
}
121164
],
122165
"tests": [
@@ -218,6 +261,102 @@
218261
]
219262
}
220263
}
264+
},
265+
{
266+
"description": "Insert a document with auto encryption using KMIP delegated KMS provider",
267+
"clientOptions": {
268+
"autoEncryptOpts": {
269+
"kmsProviders": {
270+
"kmip": {}
271+
}
272+
}
273+
},
274+
"operations": [
275+
{
276+
"name": "insertOne",
277+
"arguments": {
278+
"document": {
279+
"_id": 1,
280+
"encrypted_string_kmip_delegated": "string0"
281+
}
282+
}
283+
}
284+
],
285+
"expectations": [
286+
{
287+
"command_started_event": {
288+
"command": {
289+
"listCollections": 1,
290+
"filter": {
291+
"name": "default"
292+
}
293+
},
294+
"command_name": "listCollections"
295+
}
296+
},
297+
{
298+
"command_started_event": {
299+
"command": {
300+
"find": "datakeys",
301+
"filter": {
302+
"$or": [
303+
{
304+
"_id": {
305+
"$in": [
306+
{
307+
"$uuid": "7411e9af-c688-4df7-8143-5e60ae96cba6"
308+
}
309+
]
310+
}
311+
},
312+
{
313+
"keyAltNames": {
314+
"$in": []
315+
}
316+
}
317+
]
318+
},
319+
"$db": "keyvault"
320+
},
321+
"command_name": "find"
322+
}
323+
},
324+
{
325+
"command_started_event": {
326+
"command": {
327+
"insert": "default",
328+
"documents": [
329+
{
330+
"_id": 1,
331+
"encrypted_string_kmip_delegated": {
332+
"$binary": {
333+
"base64": "AXQR6a/GiE33gUNeYK6Wy6YCkB+8NVfAAjIbvLqyXIg6g1a8tXrym92DPoqmxpcdQyH0vQM3aFNMz7tZwQBimKs29ztZV/LWjM633HhO5ACl9A==",
334+
"subType": "06"
335+
}
336+
}
337+
}
338+
],
339+
"ordered": true
340+
},
341+
"command_name": "insert"
342+
}
343+
}
344+
],
345+
"outcome": {
346+
"collection": {
347+
"data": [
348+
{
349+
"_id": 1,
350+
"encrypted_string_kmip_delegated": {
351+
"$binary": {
352+
"base64": "AXQR6a/GiE33gUNeYK6Wy6YCkB+8NVfAAjIbvLqyXIg6g1a8tXrym92DPoqmxpcdQyH0vQM3aFNMz7tZwQBimKs29ztZV/LWjM633HhO5ACl9A==",
353+
"subType": "06"
354+
}
355+
}
356+
}
357+
]
358+
}
359+
}
221360
}
222361
]
223362
}

driver-core/src/test/resources/unified-test-format/client-side-encryption/createDataKey.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,70 @@
337337
}
338338
]
339339
},
340+
{
341+
"description": "create datakey with KMIP delegated KMS provider",
342+
"operations": [
343+
{
344+
"name": "createDataKey",
345+
"object": "clientEncryption0",
346+
"arguments": {
347+
"kmsProvider": "kmip",
348+
"opts": {
349+
"masterKey": {
350+
"delegated": true
351+
}
352+
}
353+
},
354+
"expectResult": {
355+
"$$type": "binData"
356+
}
357+
}
358+
],
359+
"expectEvents": [
360+
{
361+
"client": "client0",
362+
"events": [
363+
{
364+
"commandStartedEvent": {
365+
"databaseName": "keyvault",
366+
"command": {
367+
"insert": "datakeys",
368+
"documents": [
369+
{
370+
"_id": {
371+
"$$type": "binData"
372+
},
373+
"keyMaterial": {
374+
"$$type": "binData"
375+
},
376+
"creationDate": {
377+
"$$type": "date"
378+
},
379+
"updateDate": {
380+
"$$type": "date"
381+
},
382+
"status": {
383+
"$$exists": true
384+
},
385+
"masterKey": {
386+
"provider": "kmip",
387+
"keyId": {
388+
"$$type": "string"
389+
},
390+
"delegated": true
391+
}
392+
}
393+
],
394+
"writeConcern": {
395+
"w": "majority"
396+
}
397+
}
398+
}
399+
}
400+
]
401+
}
402+
]
403+
},
340404
{
341405
"description": "create datakey with local KMS provider",
342406
"operations": [

0 commit comments

Comments
 (0)