Skip to content

Commit 1020534

Browse files
authored
Add IoT SDK Metrics V2 (#994)
1 parent 1a5bf15 commit 1020534

25 files changed

Lines changed: 1319 additions & 122 deletions

.github/workflows/ci-android.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
env:
15-
BUILDER_VERSION: v0.9.92
15+
BUILDER_VERSION: v0.9.96
1616
BUILDER_SOURCE: releases
1717
BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net
1818
PACKAGE_NAME: aws-crt-java
@@ -140,4 +140,4 @@ jobs:
140140
--run_attempt ${{ github.run_attempt }} \
141141
--project_arn $(aws secretsmanager get-secret-value --region us-east-1 --secret-id "ci/DeviceFarm/ProjectArn" --query "SecretString" | cut -f5 -d\" | cut -f1 -d'\') \
142142
--device_pool_arn $(aws secretsmanager get-secret-value --region us-east-1 --secret-id "ci/DeviceFarm/DevicePoolArnAndroid8" --query "SecretString" | cut -f5 -d\" | cut -f1 -d'\') \
143-
--device_pool android_8
143+
--device_pool android_8

.github/workflows/ci-slow.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
env:
15-
BUILDER_VERSION: v0.9.92
15+
BUILDER_VERSION: v0.9.96
1616
BUILDER_SOURCE: releases
1717
BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net
1818
PACKAGE_NAME: aws-crt-java
@@ -63,4 +63,4 @@ jobs:
6363
- name: Build ${{ env.PACKAGE_NAME }}
6464
run: |
6565
aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh
66-
./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ matrix.image }} build -p ${{ env.PACKAGE_NAME }}
66+
./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ matrix.image }} build -p ${{ env.PACKAGE_NAME }}

src/main/java/software/amazon/awssdk/crt/internal/IoTDeviceSDKMetrics.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/software/amazon/awssdk/crt/io/TlsContext.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
*/
1414
public class TlsContext extends CrtResource {
1515

16+
private TlsCipherPreference cipherPreference;
17+
private TlsContextOptions.TlsVersions minimumTlsVersion;
18+
private TlsContextOptions.CertificateSource certificateSource;
19+
1620
/**
1721
* Creates a new Client TlsContext. There are significant native resources consumed to create a TlsContext, so most
1822
* applications will only need to create one and re-use it for all connections.
@@ -22,6 +26,9 @@ public class TlsContext extends CrtResource {
2226
*/
2327
public TlsContext(TlsContextOptions options) throws CrtRuntimeException {
2428
acquireNativeHandle(tlsContextNew(options.getNativeHandle()));
29+
this.cipherPreference = options.tlsCipherPreference;
30+
this.minimumTlsVersion = options.minTlsVersion;
31+
this.certificateSource = options.getCertificateSource();
2532
}
2633

2734
/**
@@ -31,6 +38,9 @@ public TlsContext(TlsContextOptions options) throws CrtRuntimeException {
3138
public TlsContext() throws CrtRuntimeException {
3239
try (TlsContextOptions options = TlsContextOptions.createDefaultClient()) {
3340
acquireNativeHandle(tlsContextNew(options.getNativeHandle()));
41+
this.cipherPreference = options.tlsCipherPreference;
42+
this.minimumTlsVersion = options.minTlsVersion;
43+
this.certificateSource = options.getCertificateSource();
3444
}
3545
}
3646

@@ -54,4 +64,26 @@ protected void releaseNativeHandle() {
5464
protected static native long tlsContextNew(long options) throws CrtRuntimeException;
5565

5666
private static native void tlsContextDestroy(long elg);
67+
68+
/**
69+
* Returns the {@link TlsCipherPreference} configured on this context.
70+
*
71+
* @return the cipher preference
72+
*/
73+
public TlsCipherPreference getCipherPreference() { return cipherPreference; }
74+
75+
/**
76+
* Returns the minimum {@link TlsContextOptions.TlsVersions TLS version} configured on this context.
77+
*
78+
* @return the minimum TLS version
79+
*/
80+
public TlsContextOptions.TlsVersions getMinimumTlsVersion() { return minimumTlsVersion; }
81+
82+
/**
83+
* Returns the {@link TlsContextOptions.CertificateSource} of the configured mTLS, or
84+
* {@code null} if no mTLS source has been set on the options used to create this context.
85+
*
86+
* @return the certificate source
87+
*/
88+
public TlsContextOptions.CertificateSource getCertificateSource() { return certificateSource; }
5789
};

src/main/java/software/amazon/awssdk/crt/io/TlsContextOptions.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@
2020
*/
2121
public final class TlsContextOptions extends CrtResource {
2222

23+
/**
24+
* Identifies the source of the mTLS certificate/private key configured on a
25+
* {@link TlsContextOptions}. Used internally by the IoT Device SDK metrics
26+
* layer to encode feature "I" of the SDK metrics string. Values are set
27+
* automatically by the {@code createWithMtls*} factory methods (and their
28+
* {@code withMtls*} equivalents).
29+
*/
30+
public enum CertificateSource {
31+
/** PEM cert + key files (in-memory or on-disk). */
32+
CERTIFICATE_FILES,
33+
/** Hardware security module via PKCS#11. */
34+
PKCS11,
35+
/** Windows certificate store. */
36+
WINDOWS_CERT_STORE,
37+
/** Java keystore. */
38+
JAVA_KEYSTORE,
39+
/** PKCS#12 (.p12 / .pfx) file. */
40+
PKCS12_FILE,
41+
}
42+
2343
public enum TlsVersions {
2444
/**
2545
* SSL v3. This should almost never be used.
@@ -90,7 +110,7 @@ public enum TlsVersions {
90110
* On Linux (s2n), this disables validation of OCSP stapled responses provided by the server.
91111
*
92112
* On Apple platforms, this is a no-op as revocation checking is not enabled by default.
93-
*
113+
*
94114
* Default is false (revocation checking enabled where available).
95115
*/
96116
public boolean noCertificateRevocation = false;
@@ -107,6 +127,7 @@ public enum TlsVersions {
107127
private TlsContextPkcs11Options pkcs11Options;
108128
private TlsContextCustomKeyOperationOptions customKeyOperations;
109129
private String windowsCertStorePath;
130+
private CertificateSource certificateSource;
110131

111132
/**
112133
* Creates a new set of options that can be used to create a {@link TlsContext}
@@ -187,6 +208,7 @@ public void setCipherPreference(TlsCipherPreference cipherPref) {
187208
public void initMtlsFromPath(String certificatePath, String privateKeyPath) {
188209
this.certificatePath = certificatePath;
189210
this.privateKeyPath = privateKeyPath;
211+
this.certificateSource = CertificateSource.CERTIFICATE_FILES;
190212
}
191213

192214
/**
@@ -203,6 +225,7 @@ public void initMtls(String certificate, String privateKey) throws IllegalArgume
203225

204226
this.privateKey = PemUtils.cleanUpPem(privateKey);
205227
PemUtils.sanityCheck(privateKey, 1, "PRIVATE KEY");
228+
this.certificateSource = CertificateSource.CERTIFICATE_FILES;
206229
}
207230

208231
/**
@@ -218,6 +241,7 @@ public void initMtlsPkcs12(String pkcs12Path, String pkcs12Password) {
218241
}
219242
this.pkcs12Path = pkcs12Path;
220243
this.pkcs12Password = pkcs12Password;
244+
this.certificateSource = CertificateSource.PKCS12_FILE;
221245
}
222246

223247
/**
@@ -414,6 +438,7 @@ public static TlsContextOptions createWithMtlsJavaKeystore(
414438
}
415439
options.initMtls(certificate, privateKey);
416440
options.verifyPeer = true;
441+
options.certificateSource = CertificateSource.JAVA_KEYSTORE;
417442
return options;
418443
}
419444

@@ -517,6 +542,7 @@ public TlsContextOptions withMtlsPkcs12(String pkcs12Path, String pkcs12Password
517542
public TlsContextOptions withMtlsPkcs11(TlsContextPkcs11Options pkcs11Options) {
518543
swapReferenceTo(this.pkcs11Options, pkcs11Options);
519544
this.pkcs11Options = pkcs11Options;
545+
this.certificateSource = CertificateSource.PKCS11;
520546
return this;
521547
}
522548

@@ -544,6 +570,7 @@ public TlsContextOptions withMtlsCustomKeyOperations(TlsContextCustomKeyOperatio
544570
*/
545571
public TlsContextOptions withMtlsWindowsCertStorePath(String certificatePath) {
546572
this.windowsCertStorePath = certificatePath;
573+
this.certificateSource = CertificateSource.WINDOWS_CERT_STORE;
547574
return this;
548575
}
549576

@@ -577,6 +604,14 @@ public TlsContextOptions withNoCertificateRevocation() {
577604
return this;
578605
}
579606

607+
/**
608+
* @return the {@link CertificateSource} of the configured mTLS, or {@code null}
609+
* if no mTLS source has been set (or the source has no defined metrics mapping).
610+
*/
611+
CertificateSource getCertificateSource() {
612+
return certificateSource;
613+
}
614+
580615
/*******************************************************************************
581616
* native methods
582617
******************************************************************************/

0 commit comments

Comments
 (0)