I have the following block in a java file (GcpEncrypt.java) that runs fine ( unit tests ).
However when I jar it up and call it from within a logstash Jruby input plugin
, it hangs at the client create portion.
public byte[] decryptWrappedKey(String wrappedKey, String cid)
throws IOException {
if (this.testMode) { logger.log(Level.INFO, "Decrypting wrapped key");}
byte[] wrappedKeyBytes = Base64.decodeBase64(wrappedKey);
// Create the KeyManagementServiceClient using try-with-resources to manage client cleanup.
if (this.testMode) { logger.log(Level.INFO, "Creating KMS Client ...");}
try {
KeyManagementServiceClient client = KeyManagementServiceClient.create();
logger.log(Level.INFO, "ENTERED KEY CREATION");
String keyResourceName = CryptoKeyName.format(
this.projectId,
this.locationId,
this.keyRingId,
cid);
// Decrypt the ciphertext with Cloud KMS.
if (this.testMode) { logger.log(Level.INFO, "Decrypting KMS response"); }
DecryptResponse response = client.decrypt(keyResourceName, ByteString.copyFrom(wrappedKeyBytes));
if (this.testMode) { logger.log(Level.INFO, "Returning decrypted wraped key"); }
client.close();
logger.log(Level.INFO, "**************CLOSING KMS CLIENT ***********");
return response.getPlaintext().toByteArray();
}catch (Exception e) {
throw new RuntimeException(e);
}
}
I can see the ENTERED KEY CREATION
log and then it just hangs, how can I go debugging this?
EDIT
I was able to find the relevant by instantiating the KeyManagementServiceClient
as an instance variable. It seems the 'com.google.cloud', 'google-cloud-kms', '0.81.0-beta'
jar is missing the com/google/cloud/kms/v1/ListKeyRingsRequest
class.
java.lang.NoClassDefFoundError: com/google/cloud/kms/v1/ListKeyRingsRequest
at com.google.cloud.kms.v1.stub.GrpcKeyManagementServiceStub.<clinit>(com/google/cloud/kms/v1/stub/GrpcKeyManagementServiceStub.java:88)
at com.google.cloud.kms.v1.stub.KeyManagementServiceStubSettings.createStub(com/google/cloud/kms/v1/stub/KeyManagementServiceStubSetting
s.java:292)
at com.google.cloud.kms.v1.KeyManagementServiceClient.<init>(com/google/cloud/kms/v1/KeyManagementServiceClient.java:154)
at com.google.cloud.kms.v1.KeyManagementServiceClient.create(com/google/cloud/kms/v1/KeyManagementServiceClient.java:135)
at com.google.cloud.kms.v1.KeyManagementServiceClient.create(com/google/cloud/kms/v1/KeyManagementServiceClient.java:126)