|
| 1 | +title: Configure Your KMIP KMS |
| 2 | +ref: configure-kmip-kms |
| 3 | +content: | |
| 4 | +
|
| 5 | + To connect a MongoDB driver client to your KMIP KMS, you must configure your KMS |
| 6 | + such that it accepts your client's TLS certificate. |
| 7 | +
|
| 8 | + Consult the documentation for your KMIP KMS for information on how |
| 9 | + to accept your client certificate with your specific KMS. |
| 10 | +
|
| 11 | +--- |
| 12 | +title: Specify your Certificates |
| 13 | +ref: specify-certificates |
| 14 | +content: | |
| 15 | +
|
| 16 | + Your client must connect to your KMIP KMS through TLS and present |
| 17 | + a client certificate accepted by your KMS server. |
| 18 | +
|
| 19 | + .. tabs-drivers:: |
| 20 | +
|
| 21 | + .. tab:: |
| 22 | + :tabid: java-sync |
| 23 | +
|
| 24 | + Specify the following Java system properties to configure your client's |
| 25 | + TLS connection: |
| 26 | +
|
| 27 | + .. code-block:: shell |
| 28 | + |
| 29 | + -Djavax.net.ssl.keyStoreType=pkcs12 |
| 30 | + -Djavax.net.ssl.keyStore=<path to pkcs12 KeyStore containing your client certificate> |
| 31 | + -Djavax.net.ssl.keyStorePassword=<KeyStore password> |
| 32 | +
|
| 33 | + .. note:: Configure Client With SSLContext |
| 34 | +
|
| 35 | + If you would rather configure your KMIP client using an SSL context, use the |
| 36 | + `kmsProviderSslContextMap <{+java-api+}/apidocs/mongodb-driver-core/com/mongodb/ClientEncryptionSettings.Builder.html#kmsProviderSslContextMap(java.util.Map)>`__ |
| 37 | + method. |
| 38 | +
|
| 39 | +--- |
| 40 | +title: Create a New Data Encryption Key |
| 41 | +ref: create-a-new-data-key |
| 42 | +content: | |
| 43 | + To encrypt your data, you need a data encryption key generated from your |
| 44 | + KMS-hosted **master key**. The following diagram shows the requests you need |
| 45 | + to make from the client application to create and store a new **data |
| 46 | + encryption key**: |
| 47 | +
|
| 48 | + .. image:: /figures/CSFLE_Data_Key_KMS.png |
| 49 | + :alt: Diagram that describes creating a data encryption key when using a KMS provider |
| 50 | +
|
| 51 | + 1. First, specify the following information to access the master key: |
| 52 | +
|
| 53 | + .. list-table:: |
| 54 | + :header-rows: 1 |
| 55 | + :stub-columns: 1 |
| 56 | + :widths: 30 15 45 |
| 57 | +
|
| 58 | + * - Field |
| 59 | + - Required |
| 60 | + - Description |
| 61 | +
|
| 62 | + * - keyId |
| 63 | + - No |
| 64 | + - The ``keyId`` field of a 96 byte |
| 65 | + `Secret Data managed object <http://docs.oasis-open.org/kmip/spec/v1.4/os/kmip-spec-v1.4-os.html#_Toc490660780>`__ |
| 66 | + stored in your KMIP KMS. |
| 67 | +
|
| 68 | + .. note:: Create a New Master Key |
| 69 | +
|
| 70 | + If you do not specify the ``keyId`` field in the ``masterKey`` document |
| 71 | + you send to your KMIP KMS, the driver creates a new |
| 72 | + 96 Byte Secret Data managed object in your KMS to act as your |
| 73 | + master key. |
| 74 | +
|
| 75 | + * - endpoint |
| 76 | + - Yes |
| 77 | + - The URI of your KMIP KMS. |
| 78 | +
|
| 79 | + 2. Once you have the required information, update and run the following code |
| 80 | + to generate the new data encryption key: |
| 81 | + |
| 82 | + .. include:: /includes/substitute-placeholders.rst |
| 83 | +
|
| 84 | + .. tabs-drivers:: |
| 85 | +
|
| 86 | + .. tab:: |
| 87 | + :tabid: java-sync |
| 88 | +
|
| 89 | + .. code-block:: java |
| 90 | +
|
| 91 | + Map<String, Map<String, Object>> kmsProviderProperties = new HashMap<>(); |
| 92 | + Map<String, Object> providerDetails = new HashMap<>(); |
| 93 | + providerDetails.put("endpoint", "<KMIP KMS URI>"); |
| 94 | + kmsProviderProperties.put(kmsProvider, providerDetails); |
| 95 | + String keyVaultCollection = "<MongoDB namespace where you store your keys>" |
| 96 | +
|
| 97 | + ClientEncryption clientEncryption = ClientEncryptions.create(ClientEncryptionSettings.builder() |
| 98 | + .keyVaultMongoClientSettings(MongoClientSettings.builder() |
| 99 | + .applyConnectionString(new ConnectionString("<MongoDB connection string>")) |
| 100 | + .build()) |
| 101 | + .keyVaultNamespace(keyVaultNamespace) |
| 102 | + .kmsProviders(kmsProviders) |
| 103 | + .build()); |
| 104 | +
|
| 105 | + DataKeyOptions dataKeyOptions = new DataKeyOptions().masterKey( |
| 106 | + new BsonDocument() |
| 107 | + .append("keyId", "<your KeyId>")); |
| 108 | +
|
| 109 | + BsonBinary dataKeyId = clientEncryption.createDataKey("kmip", dataKeyOptions); |
| 110 | +
|
| 111 | + System.out.println("DataKeyId [UUID]: " + dataKeyId.asUuid().toString()); |
| 112 | +
|
| 113 | + .. note:: |
| 114 | +
|
| 115 | + To use a KMIP KMS, you must use `mongodb-crypt <https://mvnrepository.com/artifact/org.mongodb/mongodb-crypt>`__ |
| 116 | + version 1.3 or later in your application's environment. |
| 117 | +
|
| 118 | +--- |
| 119 | +title: Update the Automatic Encryption JSON Schema |
| 120 | +ref: update-the-json-schema |
| 121 | +content: | |
| 122 | + If you previously embedded the key ID of your data encryption key in your |
| 123 | + automatic encryption rules, update the :ref:`JSON Schema <fle-define-a-json-schema>` |
| 124 | + with your new data encryption key ID. |
| 125 | +
|
| 126 | + Your client application is now ready to automatically encrypt your data |
| 127 | + using the master key on your KMS provider. |
0 commit comments