Skip to content

Commit 5153e02

Browse files
authored
Merge branch 'main' into graalvm-support
2 parents c720d1b + 7126375 commit 5153e02

File tree

16 files changed

+289
-157
lines changed

16 files changed

+289
-157
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- 'docs'
88

99
env:
10-
BUILDER_VERSION: v0.9.46
10+
BUILDER_VERSION: v0.9.54
1111
BUILDER_SOURCE: releases
1212
BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net
1313
PACKAGE_NAME: aws-crt-java
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
package software.amazon.awssdk.crt.io;
6+
7+
import java.security.PrivateKey;
8+
import java.security.Signature;
9+
import java.io.ByteArrayOutputStream;
10+
11+
/*
12+
* TlsKeyOperationHandler implementation for using an Android PrivateKey on TlsKeyOperations
13+
*/
14+
public class TlsAndroidPrivateKeyOperationHandler implements TlsKeyOperationHandler {
15+
private PrivateKey privateKey;
16+
17+
/*
18+
* DER encoded DigestInfo value to be prefixed to the hash, used for RSA signing
19+
* See https://tools.ietf.org/html/rfc3447#page-43
20+
*/
21+
static byte[] sha1PrefixToRsaSig = { (byte)0x30, (byte)0x21, (byte)0x30, (byte)0x09, (byte)0x06, (byte)0x05, (byte)0x2b, (byte)0x0e, (byte)0x03, (byte)0x02, (byte)0x1a, (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x14 };
22+
static byte[] sha224PrefixToRsaSig = { (byte)0x30, (byte)0x2d, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x60, (byte)0x86, (byte)0x48, (byte)0x01, (byte)0x65, (byte)0x03, (byte)0x04, (byte)0x02, (byte)0x04, (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x1c };
23+
static byte[] sha256PrefixToRsaSig = { (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x60, (byte)0x86, (byte)0x48, (byte)0x01, (byte)0x65, (byte)0x03, (byte)0x04, (byte)0x02, (byte)0x01, (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x20 };
24+
static byte[] sha384PrefixToRsaSig = { (byte)0x30, (byte)0x41, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x60, (byte)0x86, (byte)0x48, (byte)0x01, (byte)0x65, (byte)0x03, (byte)0x04, (byte)0x02, (byte)0x02, (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x30 };
25+
static byte[] sha512PrefixToRsaSig = { (byte)0x30, (byte)0x51, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x60, (byte)0x86, (byte)0x48, (byte)0x01, (byte)0x65, (byte)0x03, (byte)0x04, (byte)0x02, (byte)0x03, (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x40 };
26+
27+
public TlsAndroidPrivateKeyOperationHandler(PrivateKey privateKey) {
28+
this.privateKey = privateKey;
29+
}
30+
31+
public void performOperation(TlsKeyOperation operation){
32+
try{
33+
if (operation.getType() != TlsKeyOperation.Type.SIGN) {
34+
operation.completeExceptionally(new Throwable("Android KeyChain PrivateKey only handles SIGN operations."));
35+
return;
36+
}
37+
38+
// A SIGN operation's inputData is the 32bytes of the SHA-256 digest.
39+
// Before doing the RSA signature, we need to construct a PKCS1 v1.5 DigestInfo.
40+
// See https://datatracker.ietf.org/doc/html/rfc3447#section-9.2
41+
byte[] dataToSign = operation.getInput();
42+
43+
Signature signature = Signature.getInstance("NONEwith" + operation.getSignatureAlgorithm().name());;
44+
45+
switch(operation.getSignatureAlgorithm()){
46+
case RSA:
47+
/*
48+
* DER encoded DigestInfo value to be prefixed to the hash, used for RSA signing
49+
* See https://tools.ietf.org/html/rfc3447#page-43
50+
*/
51+
byte[] digestAlgorithm;
52+
switch(operation.getDigestAlgorithm()){
53+
case SHA1:
54+
digestAlgorithm = sha1PrefixToRsaSig;
55+
break;
56+
case SHA224:
57+
digestAlgorithm = sha224PrefixToRsaSig;
58+
break;
59+
case SHA256:
60+
digestAlgorithm = sha256PrefixToRsaSig;
61+
break;
62+
case SHA384:
63+
digestAlgorithm = sha384PrefixToRsaSig;
64+
break;
65+
case SHA512:
66+
digestAlgorithm = sha512PrefixToRsaSig;
67+
break;
68+
case UNKNOWN:
69+
default:
70+
operation.completeExceptionally(new Throwable("An UNKNOWN digest algorithm was encountered during a SIGN operation against an Android KeyChain PrivateKey."));
71+
return;
72+
}
73+
74+
ByteArrayOutputStream digestInfoStream = new ByteArrayOutputStream();
75+
digestInfoStream.write(digestAlgorithm);
76+
digestInfoStream.write(dataToSign);
77+
byte[] digestInfo = digestInfoStream.toByteArray();
78+
79+
signature.initSign(privateKey);
80+
signature.update(digestInfo);
81+
byte[] signatureBytesRSA = signature.sign();
82+
83+
operation.complete(signatureBytesRSA);
84+
return;
85+
86+
case ECDSA:
87+
88+
signature.initSign(privateKey);
89+
signature.update(dataToSign);
90+
byte[] signatureBytesECC = signature.sign();
91+
92+
operation.complete(signatureBytesECC);
93+
return;
94+
95+
case UNKNOWN:
96+
default:
97+
98+
operation.completeExceptionally(new Throwable("An UNKNOWN signature algorithm was encountered during a SIGN operation against an Android KeyChain PrivateKey."));
99+
return;
100+
}
101+
} catch (Exception ex){
102+
operation.completeExceptionally(new Throwable("Exception caught during Android KeyChain PrivateKey operation.", ex));
103+
}
104+
}
105+
}

crt/aws-c-io

crt/s2n

Submodule s2n updated from 54fbc3c to c74f442

src/main/java/software/amazon/awssdk/crt/Log.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public enum LogSubject {
103103
// aws-crt-java, we're authoritative
104104
JavaCrtGeneral(0x2400),
105105
JavaCrtResource(0x2401),
106-
JavaCrtS3(0x2402)
106+
JavaCrtS3(0x2402),
107+
JavaAndroidKeychain(0x2403)
107108
;
108109

109110
LogSubject(int value) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public TlsContextCustomKeyOperationOptions withCertificateFileContents(String co
5151
}
5252

5353
/**
54-
* Returns the path to the X.509 certificate file on desk if it has been set.
54+
* Returns the path to the X.509 certificate file on disk if it has been set.
5555
*
5656
* @return The path to the certificate file
5757
*/

src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,6 @@ private void onConnectionComplete(int errorCode, boolean sessionPresent) {
226226
}
227227
connectAck = null;
228228
}
229-
230-
MqttClientConnectionEvents callbacks = config.getConnectionCallbacks();
231-
if (callbacks != null) {
232-
if (errorCode == 0) {
233-
OnConnectionSuccessReturn returnData = new OnConnectionSuccessReturn(sessionPresent);
234-
callbacks.onConnectionSuccess(returnData);
235-
} else {
236-
OnConnectionFailureReturn returnData = new OnConnectionFailureReturn(errorCode);
237-
callbacks.onConnectionFailure(returnData);
238-
}
239-
}
240229
}
241230

242231
// Called when the connection drops or is disconnected. If errorCode == 0, the

src/native/crt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ static struct aws_log_subject_info s_crt_log_subject_infos[] = {
484484
AWS_LS_JAVA_CRT_RESOURCE, "JavaCrtResource", "Subject for CrtResource"),
485485
DEFINE_LOG_SUBJECT_INFO(
486486
AWS_LS_JAVA_CRT_S3, "JavaCrtS3", "Subject for the layer binding aws-c-s3 to Java"),
487+
DEFINE_LOG_SUBJECT_INFO(
488+
AWS_LS_JAVA_ANDROID_KEYCHAIN, "android-keychain", "Subject for Android KeyChain"),
487489
/* clang-format on */
488490
};
489491

src/native/crt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum aws_java_crt_log_subject {
1919
AWS_LS_JAVA_CRT_GENERAL = AWS_LOG_SUBJECT_BEGIN_RANGE(AWS_CRT_JAVA_PACKAGE_ID),
2020
AWS_LS_JAVA_CRT_RESOURCE,
2121
AWS_LS_JAVA_CRT_S3,
22+
AWS_LS_JAVA_ANDROID_KEYCHAIN,
2223

2324
AWS_LS_JAVA_CRT_LAST = AWS_LOG_SUBJECT_END_RANGE(AWS_CRT_JAVA_PACKAGE_ID),
2425
};

0 commit comments

Comments
 (0)