-
Notifications
You must be signed in to change notification settings - Fork 1k
Truncate a hostname longer than 64 characters for self-signed certificates #6900
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
Changes from all commits
f75df0a
935411c
0ef56e6
64cd331
a0644fc
52cf5f9
394ea1c
865a056
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,9 @@ | |||||||||||
| import java.util.Random; | ||||||||||||
| import java.util.concurrent.ThreadLocalRandom; | ||||||||||||
|
|
||||||||||||
| import org.slf4j.Logger; | ||||||||||||
| import org.slf4j.LoggerFactory; | ||||||||||||
|
|
||||||||||||
| import com.google.common.collect.ImmutableList; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
|
|
@@ -53,6 +56,10 @@ | |||||||||||
| */ | ||||||||||||
| public final class SelfSignedCertificate extends SignedCertificate { | ||||||||||||
|
|
||||||||||||
| private static final Logger logger = LoggerFactory.getLogger(SelfSignedCertificate.class); | ||||||||||||
|
|
||||||||||||
| private static final int MAX_COMMON_NAME_LENGTH = 64; | ||||||||||||
|
|
||||||||||||
| // Forked from: | ||||||||||||
| // https://github.com/netty/netty/blob/11e6a77fba9ec7184a558d869373d0ce506d7236/handler/src/main/java/io/netty/handler/ssl/util/SelfSignedCertificate.java | ||||||||||||
| // https://github.com/netty/netty/blob/11e6a77fba9ec7184a558d869373d0ce506d7236/handler/src/main/java/io/netty/handler/ssl/util/BouncyCastleSelfSignedCertGenerator.java | ||||||||||||
|
|
@@ -235,7 +242,17 @@ public SelfSignedCertificate(String fqdn, Random random, int bits, Date notBefor | |||||||||||
| public SelfSignedCertificate(String fqdn, Random random, int bits, Date notBefore, Date notAfter, | ||||||||||||
| String algorithm, Iterable<String> subjectAlternativeNames, boolean isCA) | ||||||||||||
| throws CertificateException { | ||||||||||||
| super(new CertificateParams(fqdn, random, bits, notBefore, notAfter, algorithm, | ||||||||||||
| subjectAlternativeNames, isCA)); | ||||||||||||
| super(new CertificateParams(truncateToCommonNameLength(fqdn), random, bits, notBefore, notAfter, | ||||||||||||
| algorithm, subjectAlternativeNames, isCA)); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private static String truncateToCommonNameLength(String fqdn) { | ||||||||||||
| if (fqdn.length() <= MAX_COMMON_NAME_LENGTH) { | ||||||||||||
|
Comment on lines
+249
to
+250
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Validate
As per path instructions, validation must use meaningful validation and exception messages. Proposed fix private static String truncateToCommonNameLength(String fqdn) {
+ requireNonNull(fqdn, "fqdn");
if (fqdn.length() <= MAX_COMMON_NAME_LENGTH) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Path instructions |
||||||||||||
| return fqdn; | ||||||||||||
| } | ||||||||||||
| final String truncated = fqdn.substring(0, MAX_COMMON_NAME_LENGTH); | ||||||||||||
| logger.debug("Truncating the fqdn '{}' to '{}' to satisfy " + | ||||||||||||
| "the RFC 5280 common name length limit (64).", fqdn, truncated); | ||||||||||||
| return truncated; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: line/armeria
Length of output: 25781
🏁 Script executed:
Repository: line/armeria
Length of output: 18420
Preserve the original FQDN in the DNS SAN.
truncationToCommonNameLength(fqdn)is passed toCertificateParams, andSignedCertificate.generate()usesparams.fqdn()as the automatic DNS SAN. A FQDN over 64 characters therefore produces a SAN that is also truncated, so hostname validation against the requested FQDN can fail. Store the original FQDN separately or pass it to SAN generation, and add a test that asserts the full FQDN in the SAN when the common name is truncated.🤖 Prompt for AI Agents