otherData = new HashMap<>();
otherData.put("field1", "gumby");
otherData.put("field2", "gumby");
- EventMetadata metadata1 = new EventMetadata(TENANT_ID, "userId1", "PII", otherData, "Rq8675309", "127.0.0.1",
- "userId1", System.currentTimeMillis());
+ EventMetadata metadata1 = new EventMetadata(TENANT_ID, "userId1", "PII", otherData, "Rq8675309",
+ "127.0.0.1", "userId1", System.currentTimeMillis());
try {
client.logSecurityEvent(UserEvent.LOGIN, metadata1).get();
System.out.println("Successfully logged user login event.");
diff --git a/examples/rekey-example/pom.xml b/examples/rekey-example/pom.xml
index b4402d1..54d45e4 100644
--- a/examples/rekey-example/pom.xml
+++ b/examples/rekey-example/pom.xml
@@ -28,7 +28,7 @@
com.ironcorelabs
tenant-security-java
- 4.1.0
+ 8.0.1
@@ -80,4 +80,4 @@
-
\ No newline at end of file
+
diff --git a/examples/rekey-example/src/main/java/com/ironcorelabs/rekey/RekeyExample.java b/examples/rekey-example/src/main/java/com/ironcorelabs/rekey/RekeyExample.java
index 747d4c7..43f7e0e 100644
--- a/examples/rekey-example/src/main/java/com/ironcorelabs/rekey/RekeyExample.java
+++ b/examples/rekey-example/src/main/java/com/ironcorelabs/rekey/RekeyExample.java
@@ -2,6 +2,7 @@
import com.ironcorelabs.tenantsecurity.kms.v1.*;
import com.ironcorelabs.tenantsecurity.kms.v1.exception.TenantSecurityException;
+import com.ironcorelabs.tenantsecurity.utils.CompletableFutures;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
@@ -12,11 +13,14 @@
/**
* Three parts:
*
- * Encrypt a customer record
+ *
+ * Encrypt a customer record
*
- *
Rekey the encrypted record to a new tenant
+ *
+ * Rekey the encrypted record to a new tenant
*
- *
Decrypt the encrypted record using the new tenant
+ *
+ * Decrypt the encrypted record using the new tenant
*/
public class RekeyExample {
@@ -44,77 +48,69 @@ public static void main(String[] args) throws Exception {
// Initialize the client with a Tenant Security Proxy domain and API key.
// Typically this would be done once when the application or service initializes.
- CompletableFuture rekeyedRoundtrip =
- TenantSecurityClient.create(TSP_ADDR, API_KEY)
- .thenCompose(
- client -> {
- try {
- //
- // Part 1: Encrypting a customer record
- //
-
- // Create metadata used to associate this document to the first tenant, name the
- // document, and identify the service or user making the call
- DocumentMetadata metadata =
- new DocumentMetadata(TENANT_ID, "serviceOrUserId", "PII");
-
- // Create a map containing your data
- Map custRecord = new HashMap<>();
- custRecord.put("ssn", "000-12-2345".getBytes("UTF-8"));
- custRecord.put(
- "address", "2825-519 Stone Creek Rd, Bozeman, MT 59715".getBytes("UTF-8"));
- custRecord.put("name", "Jim Bridger".getBytes("UTF-8"));
-
- System.out.println("Encrypting using tenant " + TENANT_ID);
- // Request a key from the KMS and use it to encrypt the document
- CompletableFuture encryptedDocument =
- client.encrypt(custRecord, metadata);
-
- //
- // Part 2: Rekey the encrypted record to a new tenant
- //
-
- final String NEW_TENANT_ID = "tenant-aws";
-
- System.out.println("Rekeying to tenant " + NEW_TENANT_ID);
-
- CompletableFuture rekeyedDocument =
- encryptedDocument.thenCompose(
- // Rekey the document to `tenant-aws` using their primary config. The
- // metadata's name and identifying information could also be changed at
- // this time.
- encrypted ->
- client.rekeyEdek(encrypted.getEdek(), metadata, NEW_TENANT_ID)
- .thenApply(
- newDoc ->
- new EncryptedDocument(encrypted.getEncryptedFields(),
- newDoc)
- ));
-
-
-
- //
- // Part 3: Decrypt the encrypted record using the new tenant
- //
-
- // Create new metadata for this document indicating that it was
- // rekeyed to the second tenant. The name and identifying information
- // could also be changed at this time.
- DocumentMetadata newMetadata =
- new DocumentMetadata(NEW_TENANT_ID, "serviceOrUserId", "PII");
-
- System.out.println("Decrypting with tenant " + NEW_TENANT_ID);
-
- CompletableFuture decryptedDocument =
- rekeyedDocument.thenCompose(
- // Decrypt the document encrypted to `tenant-aws`
- rekeyed -> client.decrypt(rekeyed, newMetadata));
-
- return decryptedDocument;
- } catch (Exception e) {
- throw new CompletionException(e);
- }
- });
+ CompletableFuture rekeyedRoundtrip = CompletableFutures.tryCatchNonFatal(
+ () -> new TenantSecurityClient.Builder(TSP_ADDR, API_KEY).allowInsecureHttp(true).build())
+ .thenCompose(client -> {
+ try {
+ //
+ // Part 1: Encrypting a customer record
+ //
+
+ // Create metadata used to associate this document to the first tenant, name the
+ // document, and identify the service or user making the call
+ DocumentMetadata metadata = new DocumentMetadata(TENANT_ID, "serviceOrUserId", "PII");
+
+ // Create a map containing your data
+ Map custRecord = new HashMap<>();
+ custRecord.put("ssn", "000-12-2345".getBytes("UTF-8"));
+ custRecord.put("address",
+ "2825-519 Stone Creek Rd, Bozeman, MT 59715".getBytes("UTF-8"));
+ custRecord.put("name", "Jim Bridger".getBytes("UTF-8"));
+
+ System.out.println("Encrypting using tenant " + TENANT_ID);
+ // Request a key from the KMS and use it to encrypt the document
+ CompletableFuture encryptedDocument =
+ client.encrypt(custRecord, metadata);
+
+ //
+ // Part 2: Rekey the encrypted record to a new tenant
+ //
+
+ final String NEW_TENANT_ID = "tenant-aws";
+
+ System.out.println("Rekeying to tenant " + NEW_TENANT_ID);
+
+ CompletableFuture rekeyedDocument = encryptedDocument.thenCompose(
+ // Rekey the document to `tenant-aws` using their primary config. The
+ // metadata's name and identifying information could also be changed at
+ // this time.
+ encrypted -> client.rekeyEdek(encrypted.getEdek(), metadata, NEW_TENANT_ID)
+ .thenApply(
+ newDoc -> new EncryptedDocument(encrypted.getEncryptedFields(), newDoc)));
+
+
+
+ //
+ // Part 3: Decrypt the encrypted record using the new tenant
+ //
+
+ // Create new metadata for this document indicating that it was
+ // rekeyed to the second tenant. The name and identifying information
+ // could also be changed at this time.
+ DocumentMetadata newMetadata =
+ new DocumentMetadata(NEW_TENANT_ID, "serviceOrUserId", "PII");
+
+ System.out.println("Decrypting with tenant " + NEW_TENANT_ID);
+
+ CompletableFuture decryptedDocument = rekeyedDocument.thenCompose(
+ // Decrypt the document encrypted to `tenant-aws`
+ rekeyed -> client.decrypt(rekeyed, newMetadata));
+
+ return decryptedDocument;
+ } catch (Exception e) {
+ throw new CompletionException(e);
+ }
+ });
try {
// access decrypted fields
@@ -122,9 +118,8 @@ public static void main(String[] args) throws Exception {
System.out.println(
"Decrypted SSN: " + new String(decryptedValuesMap.get("ssn"), StandardCharsets.UTF_8));
- System.out.println(
- "Decrypted address: "
- + new String(decryptedValuesMap.get("address"), StandardCharsets.UTF_8));
+ System.out.println("Decrypted address: "
+ + new String(decryptedValuesMap.get("address"), StandardCharsets.UTF_8));
System.out.println(
"Decrypted name: " + new String(decryptedValuesMap.get("name"), StandardCharsets.UTF_8));
} catch (ExecutionException e) {
diff --git a/examples/simple-roundtrip/pom.xml b/examples/simple-roundtrip/pom.xml
index 778d2db..634d535 100644
--- a/examples/simple-roundtrip/pom.xml
+++ b/examples/simple-roundtrip/pom.xml
@@ -29,7 +29,7 @@
com.ironcorelabs
tenant-security-java
- 4.0.0
+ 8.0.1
@@ -82,4 +82,4 @@
-
\ No newline at end of file
+
diff --git a/examples/simple-roundtrip/src/main/java/com/ironcorelabs/simple/SimpleRoundtrip.java b/examples/simple-roundtrip/src/main/java/com/ironcorelabs/simple/SimpleRoundtrip.java
index 6a741c9..bfbdab6 100644
--- a/examples/simple-roundtrip/src/main/java/com/ironcorelabs/simple/SimpleRoundtrip.java
+++ b/examples/simple-roundtrip/src/main/java/com/ironcorelabs/simple/SimpleRoundtrip.java
@@ -2,7 +2,7 @@
import com.ironcorelabs.tenantsecurity.kms.v1.*;
import com.ironcorelabs.tenantsecurity.kms.v1.exception.TenantSecurityException;
-
+import com.ironcorelabs.tenantsecurity.utils.CompletableFutures;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -63,39 +63,55 @@ public static void main(String[] args) throws Exception {
CompletableFuture roundtrip =
// Initialize the client with a Tenant Security Proxy domain and API key.
// Typically this would be done once when the application or service initializes
- TenantSecurityClient.create(TSP_ADDR, API_KEY).thenCompose(client -> {
-
- try {
- return client.encrypt(custRecord, metadata)
- .thenCompose(encryptedResults -> {
- // persist the EDEK and encryptedDocument to your persistence layer
- String edek = encryptedResults.getEdek();
- Map encryptedDocument = encryptedResults.getEncryptedFields();
-
- // un-comment if you want to print out the encrypted data
- //System.out.println("Encrypted SSN: " + new String(encryptedDocument.get("ssn"), StandardCharsets.UTF_8));
- //System.out.println("Encrypted address: " + new String(encryptedDocument.get("address"), StandardCharsets.UTF_8));
- //System.out.println("Encrypted name: " + new String(encryptedDocument.get("name"), StandardCharsets.UTF_8));
-
-
- // retrieve the EDEK and encryptedDocument from your persistence layer
- EncryptedDocument retrievedEncryptedDocument = new EncryptedDocument(encryptedDocument, edek);
-
- // decrypt back into plaintext
- return client.decrypt(encryptedResults, metadata);
- });
- } catch (Exception e) {
- throw new CompletionException(e);
- }
- });
+ CompletableFutures
+ .tryCatchNonFatal(() -> new TenantSecurityClient.Builder(TSP_ADDR, API_KEY)
+ .allowInsecureHttp(true).build())
+ .thenCompose(client -> {
+ try {
+ return client.encrypt(custRecord, metadata)
+ .thenCompose(encryptedResults -> {
+ // persist the EDEK and encryptedDocument to your
+ // persistence layer
+ String edek = encryptedResults.getEdek();
+ Map encryptedDocument =
+ encryptedResults.getEncryptedFields();
+
+ // un-comment if you want to print out the encrypted
+ // data
+ // System.out.println("Encrypted SSN: " + new
+ // String(encryptedDocument.get("ssn"),
+ // StandardCharsets.UTF_8));
+ // System.out.println("Encrypted address: " + new
+ // String(encryptedDocument.get("address"),
+ // StandardCharsets.UTF_8));
+ // System.out.println("Encrypted name: " + new
+ // String(encryptedDocument.get("name"),
+ // StandardCharsets.UTF_8));
+
+
+ // retrieve the EDEK and encryptedDocument from your
+ // persistence layer
+ EncryptedDocument retrievedEncryptedDocument =
+ new EncryptedDocument(encryptedDocument, edek);
+
+ // decrypt back into plaintext
+ return client.decrypt(encryptedResults, metadata);
+ });
+ } catch (Exception e) {
+ throw new CompletionException(e);
+ }
+ });
try {
- // access decrypted fields
+ // access decrypted fields
Map decryptedValuesMap = roundtrip.get().getDecryptedFields();
- System.out.println("Decrypted SSN: " + new String(decryptedValuesMap.get("ssn"), StandardCharsets.UTF_8));
- System.out.println("Decrypted address: " + new String(decryptedValuesMap.get("address"), StandardCharsets.UTF_8));
- System.out.println("Decrypted name: " + new String(decryptedValuesMap.get("name"), StandardCharsets.UTF_8));
+ System.out.println("Decrypted SSN: "
+ + new String(decryptedValuesMap.get("ssn"), StandardCharsets.UTF_8));
+ System.out.println("Decrypted address: "
+ + new String(decryptedValuesMap.get("address"), StandardCharsets.UTF_8));
+ System.out.println("Decrypted name: "
+ + new String(decryptedValuesMap.get("name"), StandardCharsets.UTF_8));
} catch (ExecutionException e) {
if (e.getCause() instanceof TenantSecurityException) {
TenantSecurityException kmsError = (TenantSecurityException) e.getCause();
@@ -121,41 +137,57 @@ public static void main(String[] args) throws Exception {
CompletableFuture roundtripFile =
// Initialize the client with a Tenant Security Proxy domain and API key.
// Typically this would be done once when the application or service initializes
- TenantSecurityClient.create(TSP_ADDR, API_KEY).thenCompose(client -> {
-
- try {
- return client.encrypt(toEncrypt, metadata)
- .thenCompose(encryptedResults -> {
- // write the encrypted file and the encrypted key to the filesystem
- try {
- Files.write(Paths.get(sourceFile + ".enc"), encryptedResults.getEncryptedFields().get("file"));
- Files.write(Paths.get(sourceFile + ".edek"), encryptedResults.getEdek().getBytes(StandardCharsets.UTF_8));
- } catch (IOException e) {
- throw new CompletionException(e);
- }
-
- // some time later... read the file from the disk
- try {
- byte[] encryptedBytes = Files.readAllBytes(Paths.get(sourceFile + ".enc"));
- byte[] encryptedDek = Files.readAllBytes(Paths.get(sourceFile + ".edek"));
-
- EncryptedDocument fileAndEdek = new EncryptedDocument(Collections.singletonMap("file", encryptedBytes), new String(encryptedDek, StandardCharsets.UTF_8));
-
- // decrypt
- return client.decrypt(fileAndEdek, metadata);
-
- } catch (IOException e) {
- throw new CompletionException(e);
- }
- });
- } catch (Exception e) {
- throw new CompletionException(e);
- }
- });
+ CompletableFutures
+ .tryCatchNonFatal(() -> new TenantSecurityClient.Builder(TSP_ADDR, API_KEY)
+ .allowInsecureHttp(true).build())
+ .thenCompose(client -> {
+
+ try {
+ return client.encrypt(toEncrypt, metadata)
+ .thenCompose(encryptedResults -> {
+ // write the encrypted file and the encrypted key to the
+ // filesystem
+ try {
+ Files.write(Paths.get(sourceFile + ".enc"),
+ encryptedResults.getEncryptedFields()
+ .get("file"));
+ Files.write(Paths.get(sourceFile + ".edek"),
+ encryptedResults.getEdek()
+ .getBytes(StandardCharsets.UTF_8));
+ } catch (IOException e) {
+ throw new CompletionException(e);
+ }
+
+ // some time later... read the file from the disk
+ try {
+ byte[] encryptedBytes = Files.readAllBytes(
+ Paths.get(sourceFile + ".enc"));
+ byte[] encryptedDek = Files.readAllBytes(
+ Paths.get(sourceFile + ".edek"));
+
+ EncryptedDocument fileAndEdek =
+ new EncryptedDocument(
+ Collections.singletonMap("file",
+ encryptedBytes),
+ new String(encryptedDek,
+ StandardCharsets.UTF_8));
+
+ // decrypt
+ return client.decrypt(fileAndEdek, metadata);
+
+ } catch (IOException e) {
+ throw new CompletionException(e);
+ }
+ });
+ } catch (Exception e) {
+ throw new CompletionException(e);
+ }
+ });
try {
// write the decrypted file back to the filesystem
- Files.write(Paths.get("decrypted.jpg"), roundtripFile.get().getDecryptedFields().get("file"));
+ Files.write(Paths.get("decrypted.jpg"),
+ roundtripFile.get().getDecryptedFields().get("file"));
} catch (ExecutionException e) {
if (e.getCause() instanceof TenantSecurityException) {
TenantSecurityException kmsError = (TenantSecurityException) e.getCause();
diff --git a/pom.xml b/pom.xml
index 14442d1..2b997f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
com.ironcorelabs
tenant-security-java
jar
- 7.2.3
+ 8.0.1
tenant-security-java
https://ironcorelabs.com/docs
Java client library for the IronCore Labs Tenant Security Proxy.
@@ -63,7 +63,7 @@