Skip to content

Commit 7236e40

Browse files
committed
Add api names / user-agent to the KMS calls.
1 parent 8b2755a commit 7236e40

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package software.amazon.encryption.s3.internal;
2+
3+
import software.amazon.awssdk.core.ApiName;
4+
5+
/**
6+
* Provides the information for the ApiName APIs for the AWS SDK
7+
*/
8+
public class ApiNameVersion {
9+
public static final String API_NAME = "AwsS3Encrypt";
10+
11+
public static final String API_VERSION_UNKNOWN = "unknown";
12+
13+
public static ApiName apiNameWithVersion() {
14+
return ApiName.builder()
15+
.name(API_NAME)
16+
.version(apiVersion())
17+
.build();
18+
}
19+
20+
private static String apiVersion() {
21+
// TODO: Use a resources file akin to ESDK to populate this
22+
return API_VERSION_UNKNOWN;
23+
}
24+
}

src/main/java/software/amazon/encryption/s3/materials/KMSContextKeyring.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import java.util.List;
55
import java.util.TreeMap;
66
import javax.crypto.SecretKey;
7+
import software.amazon.awssdk.core.ApiName;
78
import software.amazon.awssdk.core.SdkBytes;
89
import software.amazon.awssdk.services.kms.KmsClient;
910
import software.amazon.awssdk.services.kms.model.DecryptRequest;
1011
import software.amazon.awssdk.services.kms.model.DecryptResponse;
1112
import software.amazon.awssdk.services.kms.model.EncryptRequest;
1213
import software.amazon.awssdk.services.kms.model.EncryptResponse;
1314
import software.amazon.encryption.s3.S3EncryptionClientException;
15+
import software.amazon.encryption.s3.internal.ApiNameVersion;
1416

1517
/**
1618
* AESKeyring will call to KMS to wrap the data key used to encrypt content.
@@ -21,6 +23,8 @@ public class KMSContextKeyring implements Keyring {
2123

2224
private static final String ENCRYPTION_CONTEXT_ALGORITHM_KEY = "aws:x-amz-cek-alg";
2325

26+
private static final ApiName API_NAME = ApiNameVersion.apiNameWithVersion();
27+
2428
private final KmsClient _kmsClient;
2529
private final String _wrappingKeyId;
2630
private final DataKeyGenerator _dataKeyGenerator;
@@ -56,6 +60,7 @@ public EncryptionMaterials onEncrypt(EncryptionMaterials materials) {
5660
.keyId(_wrappingKeyId)
5761
.encryptionContext(encryptionContext)
5862
.plaintext(SdkBytes.fromByteArray(materials.plaintextDataKey()))
63+
.overrideConfiguration(builder -> builder.addApiName(API_NAME))
5964
.build();
6065

6166
EncryptResponse response = _kmsClient.encrypt(request);
@@ -94,6 +99,7 @@ public DecryptionMaterials onDecrypt(final DecryptionMaterials materials, List<E
9499
.keyId(_wrappingKeyId)
95100
.encryptionContext(materials.encryptionContext())
96101
.ciphertextBlob(SdkBytes.fromByteArray(encryptedDataKey.ciphertext()))
102+
.overrideConfiguration(builder -> builder.addApiName(API_NAME))
97103
.build();
98104

99105
DecryptResponse response = _kmsClient.decrypt(request);

0 commit comments

Comments
 (0)