@@ -185,24 +185,29 @@ func knownHostsCallback(host string, knownHosts []byte) git2go.CertificateCheckC
185
185
186
186
// First, attempt to split the configured host and port to validate
187
187
// the port-less hostname given to the callback.
188
- h , _ , err := net .SplitHostPort (host )
188
+ hostWithoutPort , _ , err := net .SplitHostPort (host )
189
189
if err != nil {
190
190
// SplitHostPort returns an error if the host is missing
191
191
// a port, assume the host has no port.
192
- h = host
192
+ hostWithoutPort = host
193
193
}
194
194
195
- // Check if the configured host matches the hostname given to
196
- // the callback.
197
- if h != hostname {
195
+ // Different versions of libgit handle this differently.
196
+ // This fixes the case in which ports may be sent back.
197
+ hostnameWithoutPort , _ , err := net .SplitHostPort (hostname )
198
+ if err != nil {
199
+ hostnameWithoutPort = hostname
200
+ }
201
+
202
+ if hostnameWithoutPort != hostWithoutPort {
198
203
return git2go .ErrorCodeUser
199
204
}
200
205
201
206
// We are now certain that the configured host and the hostname
202
207
// given to the callback match. Use the configured host (that
203
208
// includes the port), and normalize it, so we can check if there
204
209
// is an entry for the hostname _and_ port.
205
- h = knownhosts .Normalize (host )
210
+ h : = knownhosts .Normalize (host )
206
211
for _ , k := range kh {
207
212
if k .matches (h , cert .Hostkey ) {
208
213
return git2go .ErrorCodeOK
0 commit comments