-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug where a tailing dot is not stripped for SNI
Motivation: A trailing dot specified in an hostname can be used to make DNS queries to avoid using search domains. However, the trailing dot should be removed for SNI. https://datatracker.ietf.org/doc/html/rfc6066#section-3 > The hostname is represented as a byte string using ASCII encoding > without a trailing dot. Modifications: - Add `Endpoint.withTrailingDot()` to remove a trailing dot if exists. - Use an `Endpoint` without a trailing dot create an remote address which is used for SNI. Result: - Fixed a bug where a trailing dot was included in the hostname used by SNI. - Closes #6044
- Loading branch information
Showing
4 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
core/src/test/java/com/linecorp/armeria/client/TrailingDotSniTest.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,76 @@ | ||
/* | ||
* Copyright 2024 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you 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: | ||
* | ||
* https://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 com.linecorp.armeria.client; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.linecorp.armeria.common.AggregatedHttpResponse; | ||
import com.linecorp.armeria.common.HttpResponse; | ||
import com.linecorp.armeria.common.HttpStatus; | ||
import com.linecorp.armeria.common.TlsProvider; | ||
import com.linecorp.armeria.internal.testing.MockAddressResolverGroup; | ||
import com.linecorp.armeria.server.ServerBuilder; | ||
import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; | ||
import com.linecorp.armeria.testing.junit5.server.ServerExtension; | ||
|
||
class TrailingDotSniTest { | ||
|
||
@Order(0) | ||
@RegisterExtension | ||
static SelfSignedCertificateExtension ssc = new SelfSignedCertificateExtension("example.com"); | ||
|
||
@Order(1) | ||
@RegisterExtension | ||
static ServerExtension server = new ServerExtension() { | ||
@Override | ||
protected void configure(ServerBuilder sb) { | ||
sb.https(0); | ||
sb.tlsProvider(TlsProvider.builder() | ||
.keyPair("example.com", ssc.tlsKeyPair()) | ||
.build()); | ||
sb.service("/", (ctx, req) -> { | ||
return HttpResponse.of(200); | ||
}); | ||
} | ||
}; | ||
|
||
@Test | ||
void shouldStripTrailingDotForSni() { | ||
try (ClientFactory factory = | ||
ClientFactory.builder() | ||
.addressResolverGroupFactory(unused -> { | ||
return MockAddressResolverGroup.localhost(); | ||
}) | ||
.tlsCustomizer(b -> { | ||
b.trustManager(ssc.certificate()); | ||
}) | ||
.build()) { | ||
|
||
final BlockingWebClient client = WebClient.builder("https://example.com.:" + server.httpsPort()) | ||
.factory(factory) | ||
.build() | ||
.blocking(); | ||
final AggregatedHttpResponse response = client.get("/"); | ||
assertThat(response.status()).isEqualTo(HttpStatus.OK); | ||
} | ||
} | ||
} |