Skip to content

Commit eec1c63

Browse files
author
Samin Rahman
committed
Switched to ubi 10 base image and set ACCP default for all crypto
1 parent 03b33f2 commit eec1c63

2 files changed

Lines changed: 15 additions & 25 deletions

File tree

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# sha from https://hub.docker.com/layers/library/eclipse-temurin/21-jre-alpine-3.23/images/sha256-693c22ea458d62395bac47a2da405d0d18c77b205211ceec4846a550a37684b6
2-
FROM eclipse-temurin:21-jdk-alpine
3-
4-
# For Amazon Corretto Crypto Provider
5-
RUN apk add --no-cache gcompat
2+
FROM eclipse-temurin:21-jdk-ubi10-minimal
63

74
WORKDIR /app
85
EXPOSE 8080

src/main/java/com/uid2/operator/service/CryptoProviderService.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,38 @@
77
import javax.crypto.KeyAgreement;
88
import java.security.NoSuchAlgorithmException;
99
import java.security.NoSuchProviderException;
10-
import java.security.Security;
1110

1211
public class CryptoProviderService {
1312
private static final Logger LOGGER = LoggerFactory.getLogger(CryptoProviderService.class);
1413

15-
// ECDH provider selection: tries ACCP first, falls back to default (SunEC)
16-
private static final String ECDH_PROVIDER_NAME = initEcdhProvider();
14+
// ACCP provider name when available (after install()); null otherwise
15+
private static final String ACCP_PROVIDER_NAME = initAccpAsDefault();
1716

18-
private static String initEcdhProvider() {
19-
// Try ACCP (Amazon Corretto Crypto Provider) first
17+
private static String initAccpAsDefault() {
2018
try {
21-
// Add ACCP at lowest priority so it doesn't become default for other algorithms
22-
Security.addProvider(AmazonCorrettoCryptoProvider.INSTANCE);
23-
24-
// Verify it works for ECDH
25-
KeyAgreement ka = KeyAgreement.getInstance("ECDH", AmazonCorrettoCryptoProvider.PROVIDER_NAME);
26-
LOGGER.info("ECDH using AmazonCorrettoCryptoProvider (added at lowest priority)");
27-
return AmazonCorrettoCryptoProvider.PROVIDER_NAME;
19+
AmazonCorrettoCryptoProvider.install();
20+
if (AmazonCorrettoCryptoProvider.INSTANCE.getLoadingError() == null) {
21+
LOGGER.info("AmazonCorrettoCryptoProvider installed as default for all crypto");
22+
return AmazonCorrettoCryptoProvider.PROVIDER_NAME;
23+
}
2824
} catch (Throwable e) {
29-
// ACCP not available
3025
LOGGER.info("AmazonCorrettoCryptoProvider is not available: {}", e.getMessage());
3126
}
32-
33-
// Fall back to default provider
34-
LOGGER.info("ECDH using default provider (SunEC)");
27+
LOGGER.info("Using platform default crypto provider");
3528
return null;
3629
}
3730

3831
/**
39-
* Create ECDH Key Agreement using ACCP if available, fall back to SunEC if not
32+
* Create ECDH Key Agreement. Uses ACCP when installed as default; otherwise platform default (e.g. SunEC).
4033
* @return ECDH KeyAgreement
4134
* @throws NoSuchAlgorithmException
4235
*/
43-
public static KeyAgreement createKeyAgreement() throws NoSuchAlgorithmException {
44-
if (ECDH_PROVIDER_NAME != null) {
36+
public static KeyAgreement createKeyAgreement() throws NoSuchAlgorithmException {
37+
if (ACCP_PROVIDER_NAME != null) {
4538
try {
46-
return KeyAgreement.getInstance("ECDH", ECDH_PROVIDER_NAME);
39+
return KeyAgreement.getInstance("ECDH", ACCP_PROVIDER_NAME);
4740
} catch (NoSuchProviderException e) {
48-
LOGGER.info("{} is not available: {}", ECDH_PROVIDER_NAME, e.getMessage());
41+
LOGGER.info("{} is not available: {}", ACCP_PROVIDER_NAME, e.getMessage());
4942
}
5043
}
5144
return KeyAgreement.getInstance("ECDH");

0 commit comments

Comments
 (0)