mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Fix ipv6 parsing for builtin ssh server (#17561)
This commit is contained in:
		| @@ -13,6 +13,7 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
|  | 	"strconv" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"testing" | 	"testing" | ||||||
| 	"time" | 	"time" | ||||||
| @@ -55,7 +56,7 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL { | |||||||
| 	u2 := *u | 	u2 := *u | ||||||
| 	u2.Scheme = "ssh" | 	u2.Scheme = "ssh" | ||||||
| 	u2.User = url.User("git") | 	u2.User = url.User("git") | ||||||
| 	u2.Host = fmt.Sprintf("%s:%d", setting.SSH.ListenHost, setting.SSH.ListenPort) | 	u2.Host = net.JoinHostPort(setting.SSH.ListenHost, strconv.Itoa(setting.SSH.ListenPort)) | ||||||
| 	u2.Path = gitPath | 	u2.Path = gitPath | ||||||
| 	return &u2 | 	return &u2 | ||||||
| } | } | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"os/exec" | 	"os/exec" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
|  | 	"strconv" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"sync" | 	"sync" | ||||||
| 	"syscall" | 	"syscall" | ||||||
| @@ -264,7 +265,7 @@ func sshConnectionFailed(conn net.Conn, err error) { | |||||||
| // Listen starts a SSH server listens on given port. | // Listen starts a SSH server listens on given port. | ||||||
| func Listen(host string, port int, ciphers []string, keyExchanges []string, macs []string) { | func Listen(host string, port int, ciphers []string, keyExchanges []string, macs []string) { | ||||||
| 	srv := ssh.Server{ | 	srv := ssh.Server{ | ||||||
| 		Addr:             fmt.Sprintf("%s:%d", host, port), | 		Addr:             net.JoinHostPort(host, strconv.Itoa(port)), | ||||||
| 		PublicKeyHandler: publicKeyHandler, | 		PublicKeyHandler: publicKeyHandler, | ||||||
| 		Handler:          sessionHandler, | 		Handler:          sessionHandler, | ||||||
| 		ServerConfigCallback: func(ctx ssh.Context) *gossh.ServerConfig { | 		ServerConfigCallback: func(ctx ssh.Context) *gossh.ServerConfig { | ||||||
|   | |||||||
| @@ -6,8 +6,10 @@ package routers | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"net" | ||||||
| 	"reflect" | 	"reflect" | ||||||
| 	"runtime" | 	"runtime" | ||||||
|  | 	"strconv" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	"code.gitea.io/gitea/models" | 	"code.gitea.io/gitea/models" | ||||||
| @@ -155,7 +157,9 @@ func GlobalInit(ctx context.Context) { | |||||||
|  |  | ||||||
| 	if setting.SSH.StartBuiltinServer { | 	if setting.SSH.StartBuiltinServer { | ||||||
| 		ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs) | 		ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs) | ||||||
| 		log.Info("SSH server started on %s:%d. Cipher list (%v), key exchange algorithms (%v), MACs (%v)", setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs) | 		log.Info("SSH server started on %s. Cipher list (%v), key exchange algorithms (%v), MACs (%v)", | ||||||
|  | 			net.JoinHostPort(setting.SSH.ListenHost, strconv.Itoa(setting.SSH.ListenPort)), | ||||||
|  | 			setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs) | ||||||
| 	} else { | 	} else { | ||||||
| 		ssh.Unused() | 		ssh.Unused() | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user