Skip to content
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

Fix for ipv6 link local with scope #9326

Merged
merged 6 commits into from
Jul 7, 2022
Merged

Fix for ipv6 link local with scope #9326

merged 6 commits into from
Jul 7, 2022

Conversation

jader-eero
Copy link
Contributor

Fix for ipv6 link local with scope. If you try to connect passing address like "ipv6%wlan0" it will use

public SNIHostName(String hostname) {
        super(0, (hostname = IDN.toASCII((String)Objects.requireNonNull(hostname, "Server name value of host_name cannot be null"), 2)).getBytes(StandardCharsets.US_ASCII));
        this.hostname = hostname;
        this.checkHostName();
    }

Which raises hostname is not valid because this method doesn't accept non ASCII characters. With the change it will use

public SNIHostName(byte[] encoded) {
        super(0, encoded);

        try {
            CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
            this.hostname = IDN.toASCII(decoder.decode(ByteBuffer.wrap(encoded)).toString());
        } catch (CharacterCodingException | RuntimeException var3) {
            throw new IllegalArgumentException("The encoded server name value is invalid", var3);
        }

        this.checkHostName();
    }

Now scoped ipv6 link is supported. 😄

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 30, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: jader-eero / name: Jader Alcântara (1b08fdc)

@sanjaypujare sanjaypujare requested a review from ejona86 June 30, 2022 15:44
@sanjaypujare sanjaypujare added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jun 30, 2022
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jun 30, 2022
@ejona86
Copy link
Member

ejona86 commented Jun 30, 2022

"ipv6%wlan0" is all-ASCII. What is the non-ASCII character?

SNI should not be used with IP addresses. It is domain names only. It sounds like instead we may need logic to detect IP addresses and ignore them.

@jader-eero
Copy link
Contributor Author

Using SNI_HOST_NAME.newInstance(string) raises The input does not conform to the STD 3 ASCII rules.. I'm not familiar with the grpc library to do what you are suggesting, but the current proposal solves the issue.

@ejona86
Copy link
Member

ejona86 commented Jun 30, 2022

Looks like that's talking about https://unicode.org/reports/tr46/#STD3_Rules or similar. So it is the % sign causing the error. It looks like you are forcing it to go through punycoding processing instead. I honestly don't know at what level punycode should be applied, but it is still the inappropriate behavior in your case. In your case SNI should not be used at all.

Easiest immediate fix I see is to skip the invoke() if InetAddresses.isInetAddress() returns true.

@jader-eero
Copy link
Contributor Author

jader-eero commented Jun 30, 2022

Using InetAddresses.isInetAddress returns false in my case, the hostname value is fe80::2ab:48ff:fe1f:402d.

@ejona86
Copy link
Member

ejona86 commented Jun 30, 2022

I added this to a test and it passed:

assertEquals(true, com.google.common.net.InetAddresses.isInetAddress("fe80::2ab:48ff:fe1f:402d%wlan0"));

It works without the %wlan0 as well.

@jader-eero
Copy link
Contributor Author

jader-eero commented Jun 30, 2022

Sorry the hostname value has brackets it's [fe80::2ab:48ff:fe1f:402d] that's why is returning false.

@jader-eero
Copy link
Contributor Author

jader-eero commented Jun 30, 2022

The brackets are needed due this issue, I think. #4278

@ejona86
Copy link
Member

ejona86 commented Jun 30, 2022

We could just throw https://guava.dev/releases/snapshot/api/docs/com/google/common/net/HostAndPort.html at this.

Although that seems a bit out-of-place. I think we might should use HostAndPort here instead of URI:

String getOverridenHost() {
URI uri = GrpcUtil.authorityToUri(defaultAuthority);
if (uri.getHost() != null) {
return uri.getHost();
}
return defaultAuthority;
}

@ejona86
Copy link
Member

ejona86 commented Jun 30, 2022

Ugh, no. That would break the hostname verifier. It looks like we should be passing host+port to hostname verifier or something. I'm fine with just throwing HostAndPort in the TLS code and we kick the can down the road.

@jader-eero
Copy link
Contributor Author

I didn't get the suggestion.

@ejona86
Copy link
Member

ejona86 commented Jun 30, 2022

Combine both methods: InetAddresses.isInetAddress(HostAndPort.fromString(host).getHost())

@jader-eero
Copy link
Contributor Author

I'll do more test and let you know if everything went well soon.

@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jun 30, 2022
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jun 30, 2022
@jader-eero
Copy link
Contributor Author

It worked well. Thank you for the suggestion. About the checking failing, what do I need to do?

Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not all that confident that we understand how the SET_HOSTNAME path works, but this works and the SET_HOSTNAME code path may just become a noop.

@ejona86
Copy link
Member

ejona86 commented Jun 30, 2022

I think we'll ignore the lack of test that the codecov/patch status is complaining about. We could add a test to Http2OkHttpTest, but it might break in some environments. Last time we tried (many years ago) it was a pain, and I think I recall more recent cases where even IPv6 loopback is not available. It is possible to cook up an Assumes to skip the test when IPv6 is unavailable, but seems annoying. (Maybe try to bind to [::1]:0 and if we can't then skip the test?)

@ejona86 ejona86 requested a review from YifeiZhuang June 30, 2022 22:42
@jader-eero
Copy link
Contributor Author

How long does it take to merge and have a new release with the fix?

@ejona86 ejona86 added the TODO:backport PR needs to be backported. Removed after backport complete label Jul 6, 2022
@ejona86 ejona86 merged commit c1abc7f into grpc:master Jul 7, 2022
@ejona86
Copy link
Member

ejona86 commented Jul 7, 2022

This will be backported to the release scheduled for next week.

ejona86 pushed a commit to ejona86/grpc-java that referenced this pull request Jul 7, 2022
ejona86 pushed a commit that referenced this pull request Jul 7, 2022
@ejona86 ejona86 removed the TODO:backport PR needs to be backported. Removed after backport complete label Jul 7, 2022
@ejona86 ejona86 linked an issue Jul 8, 2022 that may be closed by this pull request
ejona86 added a commit to ejona86/grpc-java that referenced this pull request Jul 14, 2022
This reverts commit c1abc7f. It
produced compilation issues inside Google. I strongly suspect it isn't
this commit or gRPC's fault, but it prevents further testing until it is
resolved.
ejona86 added a commit that referenced this pull request Jul 14, 2022
This reverts commit c1abc7f. It
produced compilation issues inside Google. I strongly suspect it isn't
this commit or gRPC's fault, but it prevents further testing until it is
resolved.
ejona86 added a commit to ejona86/grpc-java that referenced this pull request Jul 14, 2022
This reverts commit c1abc7f. It
produced compilation issues inside Google. I strongly suspect it isn't
this commit or gRPC's fault, but it prevents further testing until it is
resolved.
larry-safran pushed a commit to larry-safran/grpc-java that referenced this pull request Jul 14, 2022
This reverts commit c1abc7f. It
produced compilation issues inside Google. I strongly suspect it isn't
this commit or gRPC's fault, but it prevents further testing until it is
resolved.
ejona86 added a commit that referenced this pull request Jul 15, 2022
This reverts commit c1abc7f. It
produced compilation issues inside Google. I strongly suspect it isn't
this commit or gRPC's fault, but it prevents further testing until it is
resolved.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gRPC-okhttp ipv6 link local scope
5 participants