-
Notifications
You must be signed in to change notification settings - Fork 4
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
Omit the IPv6 zone ID if it contains spaces #4
Conversation
Thank you for the issue report + fix PR! I must confess I'm not too familiar with IPv6 zone IDs. Does the rest of golang.org/x/crypto/ssh/knownhosts work properly with them? In particular: if we strip the zone ID (if it contained a space) when writing the knownhosts entry, will that knownhosts line properly match for future host lookups on the same ipv6 address that have the zone ID present? From quick scan of golang.org/x/crypto/ssh/knownhosts I'm not sure. Some of the logic uses net.SplitHostPort, which keeps the zone ID in the host. I haven't tested or looked in depth though. To fully test I think there would need to be no hostname present on the lookup attempt, only an ipv6 address with zone id. (If a hostname is supplied on the lookup, it is used preferentially instead of the ip address, if I understand correctly.) |
one other question -- in common |
My test with openssh:
My test with trzsz-ssh written in go:
|
I want to fix the case |
Thanks, that helps clarify the situation. I definitely agree we must avoid writing the known_hosts line with the extra space. But I want to be fully confident that stripping the zone ID entirely is safe, and won't cause any other problems down the line in other use-cases. Here's a situation I'm concerned about, regarding whether the knownhosts lookup path will work correctly after the zone is stripped:
Instead of stripping the zone, could this approach work?
|
72c9964 works like this:
|
I may be misremembering how So if I'm reading 72c9964 correctly, I would expect that case 4 would actually write Anyway yes I think it would be better to just return an error in that specific situation of case 4 (remote contains a zone ID with a space, and we don't have a separate hostname). We disagree on case 1 though (remote contains a zone ID with a space, but we also have a separate hostname that isn't just an IP address). I think it might be better to just write |
You are right. Let's keep it simple, we return an error if the hostname contains spaces, and we align it with openssh if the remote address contains spaces. |
That approach sounds good to me, thanks! |
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.
This looks great! Thanks again for finding and fixing the issue, and also for your patience in the discussion. I'll merge momentarily, and will plan to tag a new version on Monday.
if strings.ContainsAny(hostnameNormalized, "\t ") { | ||
return fmt.Errorf("knownhosts: hostname '%s' contains spaces", hostnameNormalized) | ||
} | ||
addresses := []string{hostnameNormalized} |
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.
Just noting for background: previously, addresses
had the non-normalized versions of the strings, because Line
already also calls Normalize
on these. But I suppose it's harmless to change here, because both functions need to normalize the input (since they're exported functions and Line
may be used independently) and there's no harm in calling it redundantly.
@evanelias Thanks for your help. |
Closes #3