-
Notifications
You must be signed in to change notification settings - Fork 364
Facilitate FIPS-compliant store resolution #6059
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
cwperks
merged 9 commits into
opensearch-project:main
from
sternadsoftware:create_bcfks_test_stores
Apr 13, 2026
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c9cc526
facilitate FIPS-compliant store resolution
iigonin 90b4564
spotlessApply
iigonin fb024c2
Replace `FileHelper.getAbsoluteFilePathFromClassPath` with `ClassLoad…
iigonin b625e85
Enable automatic detection of keystore type and support for FIPS-comp…
iigonin 1cf3309
add tests
iigonin 8bc673c
extract SanParser to extra class
iigonin 050d79c
Replace `resolveStorePath` with `resolveStore` which returns both typ…
iigonin bb984ae
Introducing `FileHelper.classpathResourceExists` to replace repetitiv…
iigonin efac29d
Clarify error message for unsupported keystore types in FIPS mode.
iigonin 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
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
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
78 changes: 78 additions & 0 deletions
78
src/main/java/org/opensearch/security/ssl/config/SanParser.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,78 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| * Modifications Copyright OpenSearch Contributors. See | ||
| * GitHub history for details. | ||
| */ | ||
|
|
||
| package org.opensearch.security.ssl.config; | ||
|
|
||
| import java.net.InetAddress; | ||
| import java.net.UnknownHostException; | ||
| import java.security.cert.CertificateEncodingException; | ||
| import java.security.cert.X509Certificate; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.bouncycastle.asn1.ASN1Encodable; | ||
| import org.bouncycastle.asn1.ASN1OctetString; | ||
| import org.bouncycastle.asn1.ASN1String; | ||
| import org.bouncycastle.asn1.x509.Extension; | ||
| import org.bouncycastle.asn1.x509.GeneralName; | ||
| import org.bouncycastle.asn1.x509.GeneralNames; | ||
| import org.bouncycastle.asn1.x509.OtherName; | ||
| import org.bouncycastle.cert.X509CertificateHolder; | ||
| import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder; | ||
| import org.bouncycastle.crypto.CryptoServicesRegistrar; | ||
|
|
||
| public class SanParser { | ||
|
|
||
| private static final Logger LOGGER = LogManager.getLogger(SanParser.class); | ||
|
|
||
| private SanParser() {} | ||
|
|
||
| public static String parse(X509Certificate certificate) { | ||
| try { | ||
| X509CertificateHolder holder = new JcaX509CertificateHolder(certificate); | ||
| GeneralNames generalNames = GeneralNames.fromExtensions(holder.getExtensions(), Extension.subjectAlternativeName); | ||
| if (generalNames == null) return ""; | ||
|
|
||
| Comparator<List<?>> comparator = Comparator.comparing((List<?> n) -> (Integer) n.get(0)) | ||
| .thenComparing((List<?> n) -> n.get(1).toString()); | ||
| Set<List<?>> sans = new TreeSet<>(comparator); | ||
|
|
||
| for (GeneralName gn : generalNames.getNames()) { | ||
| int type = gn.getTagNo(); | ||
| if (type == GeneralName.otherName) { | ||
| OtherName on = OtherName.getInstance(gn.getName()); | ||
| ASN1Encodable value = on.getValue(); | ||
| if (value instanceof ASN1String) { | ||
| sans.add(List.of(type, List.of(on.getTypeID().getId(), value.toString()))); | ||
| } else { | ||
| LOGGER.warn("Couldn't parse OtherName SAN value"); | ||
| } | ||
| } else if (type == GeneralName.iPAddress) { | ||
| byte[] octets = ASN1OctetString.getInstance(gn.getName()).getOctets(); | ||
| sans.add(List.of(type, InetAddress.getByAddress(octets).getHostAddress())); | ||
| } else { | ||
| sans.add(List.of(type, gn.getName().toString())); | ||
| } | ||
| } | ||
| return sans.isEmpty() ? "" : sans.toString(); | ||
| } catch (final CertificateEncodingException | UnknownHostException e) { | ||
| LOGGER.error("Couldn't parse subject alternative names", e); | ||
| if (CryptoServicesRegistrar.isInApprovedOnlyMode()) { | ||
| throw new RuntimeException("Couldn't parse subject alternative names", e); | ||
| } | ||
| return ""; | ||
| } | ||
| } | ||
| } | ||
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.