Skip to content

Commit aca5333

Browse files
authored
Fix JCA certificate refresh interval configuration (#50785)
* Fix JCA certificate refresh interval configuration * Update changelog
1 parent 0d4e547 commit aca5333

9 files changed

Lines changed: 179 additions & 39 deletions

File tree

‎sdk/keyvault/azure-security-keyvault-jca/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
## 2.13.0 (2026-10-13)
44

55
### Features Added
6+
- Added ISO-8601 duration support (e.g., `PT30S`) for `azure.keyvault.jca.certificates-refresh-interval`, while retaining support for millisecond values. ([#50785](https://github.com/Azure/azure-sdk-for-java/pull/50785))
67
- Added lazy loading for Key Vault certificate details in the JCA keystore. Certificate details are now loaded by alias when requested, avoiding unnecessary reads for unconfigured certificates. ([#49774](https://github.com/Azure/azure-sdk-for-java/pull/49774))
78
- Added support for `azure.keyvault.jca.certificate-alias-filter-pattern` to filter Key Vault certificate aliases with inclusion/exclusion regex patterns. Inclusion patterns are configured directly and exclusion patterns are prefixed with `!`. Configure more than one filter by appending a suffix to the property name, such as `azure.keyvault.jca.certificate-alias-filter-pattern.1`. A pattern can contain any character as long as the regex is correct. If no filter property is configured, alias filtering is disabled and all discovered Key Vault aliases remain eligible for lazy loading. ([#39487](https://github.com/Azure/azure-sdk-for-java/issues/39487))
89

10+
### Breaking Changes
11+
- Removed support for `azure.keyvault.jca.certificates-refresh-interval-in-ms`. ([#50785](https://github.com/Azure/azure-sdk-for-java/pull/50785))
12+
913
### Bugs Fixed
1014
- Preserved configured TLS endpoint identification and connection-specific validation when delegating certificate checks, including checks of certificates trusted through the Key Vault keystore. ([#50667](https://github.com/Azure/azure-sdk-for-java/pull/50667))
1115
- Stopped recording sensitive data in `FINER` level logs. Review any logs captured at the `FINER` level or lower in previous library versions and rotate any sensitive data contained there.
1216
- Fixed bug: `jarsigner` reports invalid certificate chain (`PKIX path building failed: unable to find valid certification path to requested target`) when using a non-exportable Azure Key Vault certificate. When the certificate chain returned by Azure Key Vault does not end in a self-signed root, the missing issuer certificates are now resolved at runtime using the CA Issuers URL in the AIA (Authority Information Access) extension of each certificate. Responses are cached by URL so subsequent loads can reuse them without another network request. ([#44267](https://github.com/Azure/azure-sdk-for-java/issues/44267))
1317
- Fixed an issue where `KeyStore.load(KeyVaultLoadStoreParameter)` could combine explicit client settings with certificate cache and path settings captured earlier from system properties. The parameter now carries the complete key store configuration. ([#50163](https://github.com/Azure/azure-sdk-for-java/pull/50163))
1418

1519
### Other Changes
20+
- Changed the certificate refresh interval in `KeyVaultLoadStoreParameter` from `long` milliseconds to `Duration`. ([#50785](https://github.com/Azure/azure-sdk-for-java/pull/50785))
1621
- Added system property `azure.keyvault.jca.disable-aia-download` to disable automatic AIA chain completion. AIA chain completion downloads certificates from URLs embedded in certificate extensions, so this allows locked-down environments to prevent those outbound HTTP(S) requests, mitigating potential SSRF-like attack vectors when loading untrusted certificates. The value is captured when each Key Vault client is initialized and retained for lazy certificate-chain loading, so multiple keystores can use different settings without overwriting one another. Set to `true` to disable (defaults to `false`).
1722
- Added `KeyVaultJcaPropertyNames` as the central source for the system property names supported by the Azure Key Vault JCA provider. ([#50163](https://github.com/Azure/azure-sdk-for-java/pull/50163))
1823
- Replaced Apache HttpClient 5 with the JDK `HttpURLConnection`, removing the Apache HttpClient and SLF4J runtime dependencies while preserving strict HTTPS hostname verification, non-fatal AIA download failures, fail-closed TLS trust initialization, and automatic gzip and deflate response decompression. VM managed identity requests to IMDS use `Proxy.NO_PROXY` to bypass HTTP proxy routing. Other requests, including App Service and Container Apps managed identity requests, retain JDK proxy selection.

‎sdk/keyvault/azure-security-keyvault-jca/README.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ The JCA library supports configuring the following options:
139139
* `azure.cert-path.well-known`: The path where the well-known certificate is stored.
140140
* `azure.cert-path.custom`: The path where the custom certificate is stored.
141141
* `azure.keyvault.jca.refresh-certificates-when-have-un-trust-certificate`: Indicates whether to refresh certificates when have untrusted certificate.
142-
* `azure.keyvault.jca.certificates-refresh-interval`: The refresh interval time.
143-
* `azure.keyvault.jca.certificates-refresh-interval-in-ms`: The refresh interval time.
142+
* `azure.keyvault.jca.certificates-refresh-interval`: The certificate refresh interval as an ISO-8601 duration, for example `-Dazure.keyvault.jca.certificates-refresh-interval=PT30S` for 30 seconds. Millisecond values such as `-Dazure.keyvault.jca.certificates-refresh-interval=30000` remain supported for backward compatibility. Defaults to zero; zero or negative values disable periodic refresh.
144143
* `azure.keyvault.jca.certificate-alias-filter-pattern`: A regex that filters which Key Vault certificate aliases are eligible for lazy loading. Append a suffix to the property name to configure more than one filter, for example `azure.keyvault.jca.certificate-alias-filter-pattern.1` or `azure.keyvault.jca.certificate-alias-filter-pattern.prod`. If no such property is configured, all discovered Key Vault aliases are eligible for lazy loading. See "Filtering Key Vault certificate aliases" below.
145144
* `azure.keyvault.disable-challenge-resource-verification`: Indicates whether to disable verification that the authentication challenge resource matches the Key Vault or Managed HSM domain.
146145
* `azure.keyvault.jca.disable-aia-download`: Set to `true` to disable automatic AIA (Authority Information Access) certificate chain completion. Chain completion is only attempted when the chain returned by Azure Key Vault is incomplete, meaning it holds a single certificate or is missing an intermediate CA. When disabled, the provider will return certificate chains as provided by Azure Key Vault without downloading missing intermediate CA certificates. Use this in locked-down environments or when processing untrusted certificates to prevent outbound HTTP(S) requests to URLs embedded in certificate extensions. Defaults to `false` for backward compatibility. The value is captured when a Key Vault keystore and its client are initialized.
@@ -154,6 +153,10 @@ or as a JVM argument:
154153
-Dazure.keyvault.uri=<your-azure-keyvault-uri>
155154
```
156155

156+
The system property `azure.keyvault.jca.certificates-refresh-interval-in-ms` has been removed and is ignored. If it is
157+
configured, the provider logs a warning. Use `azure.keyvault.jca.certificates-refresh-interval` instead, with an ISO-8601
158+
duration such as `PT30S` or the existing millisecond value.
159+
157160
#### Programmatic configuration
158161

159162
Use `KeyVaultLoadStoreParameter` when each key store needs an explicit configuration instead of global system
@@ -165,7 +168,7 @@ KeyVaultLoadStoreParameter parameter = new KeyVaultLoadStoreParameter(
165168
"<your-tenant-id>",
166169
"<your-client-id>",
167170
"<your-client-secret>")
168-
.setCertificatesRefreshIntervalInMs(60_000)
171+
.setCertificatesRefreshInterval(Duration.ofSeconds(60))
169172
.setCertificateAliasFilterPatterns(Collections.singleton("^prod-.*"));
170173
parameter.disableAiaDownload();
171174

‎sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/KeyVaultJcaPropertyNames.java‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,12 @@ private KeyVaultJcaPropertyNames() {
5858
public static final String CERT_PATH_CUSTOM = "azure.cert-path.custom";
5959

6060
/**
61-
* The certificate refresh interval property name.
61+
* The certificate refresh interval property name. Accepts an ISO-8601 duration, such as {@code PT30S}, or a
62+
* millisecond value, such as {@code 30000}.
6263
*/
6364
public static final String KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL
6465
= "azure.keyvault.jca.certificates-refresh-interval";
6566

66-
/**
67-
* The certificate refresh interval in milliseconds property name.
68-
*/
69-
public static final String KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL_IN_MS
70-
= "azure.keyvault.jca.certificates-refresh-interval-in-ms";
71-
7267
/**
7368
* The property name used to refresh certificates when an untrusted certificate is encountered.
7469
*/

‎sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/KeyVaultKeyStore.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public final class KeyVaultKeyStore extends KeyStoreSpi {
5353
*/
5454
private static final Logger LOGGER = Logger.getLogger(KeyVaultKeyStore.class.getName());
5555

56+
private static final String REMOVED_CERTIFICATES_REFRESH_INTERVAL_IN_MS
57+
= "azure.keyvault.jca.certificates-refresh-interval-in-ms";
58+
5659
/**
5760
* Stores the Jre key store certificates.
5861
*/
@@ -123,6 +126,17 @@ public KeyVaultKeyStore() {
123126
updateKeyStoreConfiguration(parameter);
124127
}
125128

129+
static void warnIfRemovedCertificatesRefreshIntervalIsConfigured() {
130+
if (System.getProperty(REMOVED_CERTIFICATES_REFRESH_INTERVAL_IN_MS) != null) {
131+
LOGGER.log(WARNING,
132+
"System property {0} has been removed and is ignored. Use {1} instead with an ISO-8601 duration"
133+
+ " (for example, PT30S). Millisecond values (for example, 30000) are also supported.",
134+
new Object[] {
135+
REMOVED_CERTIFICATES_REFRESH_INTERVAL_IN_MS,
136+
KeyVaultJcaPropertyNames.KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL });
137+
}
138+
}
139+
126140
private void updateKeyStoreConfiguration(KeyVaultLoadStoreParameter parameter) {
127141
refreshCertificatesWhenHaveUnTrustCertificate = parameter.isRefreshCertificatesWhenHaveUnTrustCertificate();
128142
certPathWellKnown = parameter.getCertPathWellKnown();

‎sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/KeyVaultLoadStoreParameter.java‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package com.azure.security.keyvault.jca;
55

66
import java.security.KeyStore;
7+
import java.time.Duration;
78
import java.util.Collections;
89
import java.util.HashSet;
910
import java.util.Objects;
@@ -60,9 +61,9 @@ public final class KeyVaultLoadStoreParameter implements KeyStore.LoadStoreParam
6061
private boolean disableChallengeResourceVerification = false;
6162

6263
/**
63-
* Stores the certificate refresh interval in milliseconds.
64+
* Stores the certificate refresh interval.
6465
*/
65-
private long certificatesRefreshIntervalInMs;
66+
private Duration certificatesRefreshInterval = Duration.ZERO;
6667

6768
/**
6869
* Stores a flag indicating whether AIA certificate downloads are disabled.
@@ -108,13 +109,17 @@ public static KeyVaultLoadStoreParameter fromSystemProperties() {
108109
parameter.disableChallengeResourceVerification();
109110
}
110111

112+
KeyVaultKeyStore.warnIfRemovedCertificatesRefreshIntervalIsConfigured();
111113
String refreshInterval
112-
= System.getProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL_IN_MS);
113-
if (refreshInterval == null) {
114-
refreshInterval = System.getProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL);
115-
}
114+
= System.getProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL);
116115
if (refreshInterval != null) {
117-
parameter.setCertificatesRefreshIntervalInMs(Long.parseLong(refreshInterval));
116+
Duration interval;
117+
try {
118+
interval = Duration.ofMillis(Long.parseLong(refreshInterval));
119+
} catch (NumberFormatException exception) {
120+
interval = Duration.parse(refreshInterval);
121+
}
122+
parameter.setCertificatesRefreshInterval(interval);
118123
}
119124

120125
if (Boolean.parseBoolean(System.getProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_DISABLE_AIA_DOWNLOAD))) {
@@ -300,22 +305,24 @@ public void disableChallengeResourceVerification() {
300305
}
301306

302307
/**
303-
* Gets the certificate refresh interval in milliseconds.
308+
* Gets the certificate refresh interval.
304309
*
305-
* @return The certificate refresh interval in milliseconds.
310+
* @return The certificate refresh interval. Defaults to {@link Duration#ZERO}, which disables periodic refresh.
306311
*/
307-
public long getCertificatesRefreshIntervalInMs() {
308-
return certificatesRefreshIntervalInMs;
312+
public Duration getCertificatesRefreshInterval() {
313+
return certificatesRefreshInterval;
309314
}
310315

311316
/**
312-
* Sets the certificate refresh interval in milliseconds.
317+
* Sets the certificate refresh interval. Zero or negative intervals disable periodic refresh.
313318
*
314-
* @param certificatesRefreshIntervalInMs The certificate refresh interval in milliseconds.
319+
* @param certificatesRefreshInterval The certificate refresh interval, for example {@code Duration.parse("PT30S")}.
315320
* @return The KeyVaultLoadStoreParameter.
321+
* @throws NullPointerException if {@code certificatesRefreshInterval} is {@code null}.
316322
*/
317-
public KeyVaultLoadStoreParameter setCertificatesRefreshIntervalInMs(long certificatesRefreshIntervalInMs) {
318-
this.certificatesRefreshIntervalInMs = certificatesRefreshIntervalInMs;
323+
public KeyVaultLoadStoreParameter setCertificatesRefreshInterval(Duration certificatesRefreshInterval) {
324+
this.certificatesRefreshInterval
325+
= Objects.requireNonNull(certificatesRefreshInterval, "'certificatesRefreshInterval' cannot be null.");
319326
return this;
320327
}
321328

‎sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/implementation/certificates/KeyVaultCertificates.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private void updateCertificateConfiguration(KeyVaultLoadStoreParameter parameter
131131
List<Pattern> updatedIncludeAliasPatterns = getAliasPatterns(normalizedFilterPatterns, false);
132132
List<Pattern> updatedExcludeAliasPatterns = getAliasPatterns(normalizedFilterPatterns, true);
133133

134-
certificatesRefreshIntervalInMs = parameter.getCertificatesRefreshIntervalInMs();
134+
certificatesRefreshIntervalInMs = parameter.getCertificatesRefreshInterval().toMillis();
135135
includeAliasPatterns = updatedIncludeAliasPatterns;
136136
excludeAliasPatterns = updatedExcludeAliasPatterns;
137137
}

‎sdk/keyvault/azure-security-keyvault-jca/src/test/java/com/azure/security/keyvault/jca/KeyVaultCertificatesTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private X509Certificate getTestCertificate() {
8383

8484
@Test
8585
public void testCertificatesRefreshInterval() throws Exception {
86-
System.setProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL_IN_MS, "1000");
86+
System.setProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL, "PT1S");
8787
KeyStore keyStore = PropertyConvertorUtils.getKeyVaultKeyStore();
8888
assertNotNull(keyStore.getCertificate(certificateName));
8989
keyStore.deleteEntry(certificateName);

0 commit comments

Comments
 (0)