forked from helidon-io/helidon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.x: Support Http.Header.X_HELIDON_CN (helidon-io#7345)
* Support X_HELIDON_CN (rebase) Signed-off-by: tvallin <[email protected]>
- Loading branch information
1 parent
f9f0191
commit 7c7dfc4
Showing
8 changed files
with
102 additions
and
97 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
common/tls/src/main/java/io/helidon/common/tls/TlsUtils.java
This file contains 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,54 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.helidon.common.tls; | ||
|
||
import java.security.Principal; | ||
import java.security.cert.Certificate; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Utility class for TLS. | ||
*/ | ||
public class TlsUtils { | ||
|
||
private TlsUtils() { | ||
} | ||
|
||
/** | ||
* Parse the Common Name (CN) from the first certificate if present. | ||
* | ||
* @param certificates certificates | ||
* @return Common Name value | ||
*/ | ||
public static Optional<String> parseCn(Certificate[] certificates) { | ||
if (certificates.length >= 1) { | ||
Certificate certificate = certificates[0]; | ||
X509Certificate cert = (X509Certificate) certificate; | ||
Principal principal = cert.getSubjectX500Principal(); | ||
int i = 0; | ||
String[] segments = principal.getName().split("=|,"); | ||
while (i + 1 < segments.length) { | ||
if ("CN".equals(segments[i])) { | ||
return Optional.of(segments[i + 1]); | ||
} | ||
i += 2; | ||
} | ||
return Optional.of("Unknown CN"); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
...server/mutual-tls/src/main/java/io/helidon/examples/webserver/mtls/CertificateHelper.java
This file was deleted.
Oops, something went wrong.
This file contains 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 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
39 changes: 0 additions & 39 deletions
39
webclient/tests/webclient/src/test/java/io/helidon/webclient/tests/CertificateHelper.java
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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