-
Notifications
You must be signed in to change notification settings - Fork 71
fix: Log ignored certificates during client authentication #4415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hrishikesh-nalawade
merged 19 commits into
v3.x.x
from
hrishikesh-nalawade/GH4164/log-ignored-client-certificate-ino
Feb 2, 2026
Merged
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
970bf43
Logs for Ignored Client Certificates
hrishikesh-nalawade 9d14b4c
Optimizing Code and adding Tests
hrishikesh-nalawade cf8e372
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
hrishikesh-nalawade 9258c5e
Implemented CertificateLoggingUtils utility class so that logging cou…
hrishikesh-nalawade 5dd882c
Removing Comments
hrishikesh-nalawade c8bda34
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
hrishikesh-nalawade 7ee33f4
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
hrishikesh-nalawade b006e54
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
hrishikesh-nalawade d7cfaa8
Restructured the CertificateLoggingUtils class and enhanced Categoriz…
hrishikesh-nalawade 6d5b5d0
removing unused Imports
hrishikesh-nalawade 6e5656f
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
pablocarle 7571743
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
pablocarle b69e310
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
pablocarle 1fb9a6d
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
pablocarle 7963cad
updates
hrishikesh-nalawade 21da760
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
hrishikesh-nalawade a1a1254
test corrections
hrishikesh-nalawade 1b7bca2
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
hrishikesh-nalawade 14b9a2d
Merge branch 'v3.x.x' into hrishikesh-nalawade/GH4164/log-ignored-cli…
pablocarle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...ity-common/src/main/java/org/zowe/apiml/security/common/util/CertificateLoggingUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.security.common.util; | ||
|
|
||
| import lombok.experimental.UtilityClass; | ||
| import org.slf4j.Logger; | ||
|
|
||
| import java.security.cert.X509Certificate; | ||
| import java.util.*; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * Utility class for logging certificate-related operations, particularly for logging | ||
| * certificates that were ignored/filtered during client authentication. | ||
| */ | ||
| @UtilityClass | ||
hrishikesh-nalawade marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public class CertificateLoggingUtils { | ||
|
|
||
| /** | ||
| * Logs information about certificates that were ignored during authentication. | ||
| * Compares the original set of certificates with the filtered set to identify ignored certificates. | ||
| * Uses Base64-encoded public keys for reliable comparison instead of X509Certificate object equality. | ||
| * | ||
| * @param originalCerts The original array of certificates before filtering | ||
| * @param filteredCerts The array of certificates after filtering for authentication | ||
| * @param publicKeyCertificatesBase64 Set of Base64-encoded public keys of known APIML certificates | ||
| * @param logger The logger to use for output | ||
| * @param base64Encoder Function to encode certificate public key to Base64 | ||
| */ | ||
| public static void logIgnoredCertificates( | ||
hrishikesh-nalawade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| X509Certificate[] originalCerts, | ||
| X509Certificate[] filteredCerts, | ||
| Set<String> publicKeyCertificatesBase64, | ||
| Logger logger, | ||
| Function<X509Certificate, String> base64Encoder | ||
| ) { | ||
| if (originalCerts == null || originalCerts.length == 0) return; | ||
|
|
||
| Set<String> originalKeys = Arrays.stream(originalCerts) | ||
| .map(base64Encoder) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| Set<String> filteredKeys = filteredCerts != null | ||
| ? Arrays.stream(filteredCerts) | ||
| .map(base64Encoder) | ||
| .collect(Collectors.toSet()) | ||
| : new HashSet<>(); | ||
|
|
||
| Set<String> ignoredKeys = new HashSet<>(originalKeys); | ||
| ignoredKeys.removeAll(filteredKeys); | ||
hrishikesh-nalawade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!ignoredKeys.isEmpty()) { | ||
| List<X509Certificate> ignoredCerts = Arrays.stream(originalCerts) | ||
hrishikesh-nalawade marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .filter(cert -> ignoredKeys.contains(base64Encoder.apply(cert))) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| logger.debug("Certificates ignored/not used for authentication: {}", | ||
| ignoredCerts.stream() | ||
| .map(cert -> { | ||
| String subjectDN = cert.getSubjectX500Principal() != null | ||
| ? cert.getSubjectX500Principal().getName() | ||
| : "Unknown"; | ||
| String issuerDN = cert.getIssuerX500Principal() != null | ||
| ? cert.getIssuerX500Principal().getName() | ||
| : "Unknown"; | ||
| String publicKeyBase64 = base64Encoder.apply(cert); | ||
| return String.format("[Subject: %s, Issuer: %s, Public Key (first 20 chars): %s...]", | ||
| subjectDN, issuerDN, publicKeyBase64.substring(0, Math.min(20, publicKeyBase64.length()))); | ||
| }) | ||
| .collect(Collectors.joining(", "))); | ||
hrishikesh-nalawade marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ignoredCerts.forEach(cert -> { | ||
| String publicKeyBase64 = base64Encoder.apply(cert); | ||
| boolean isApimlCert = publicKeyCertificatesBase64.contains(publicKeyBase64); | ||
| String subjectDN = cert.getSubjectX500Principal() != null | ||
| ? cert.getSubjectX500Principal().getName() | ||
| : "Unknown"; | ||
| if (isApimlCert) { | ||
| logger.debug("Certificate with subject '{}' was ignored because it is an APIML Gateway certificate (not used for client authentication)", | ||
| subjectDN); | ||
| } else { | ||
| logger.debug("Certificate with subject '{}' was ignored for unknown reason (not in APIML cert set, but filtered by predicate)", | ||
| subjectDN); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.