Skip to content

Commit

Permalink
Fix ipv6 parsing for builtin ssh server (#17561)
Browse files Browse the repository at this point in the history
  • Loading branch information
42wim authored Nov 6, 2021
1 parent 5e0cf4b commit bd613c7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion integrations/git_helper_for_declarative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -55,7 +56,7 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL {
u2 := *u
u2.Scheme = "ssh"
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
return &u2
}
Expand Down
3 changes: 2 additions & 1 deletion modules/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -264,7 +265,7 @@ func sshConnectionFailed(conn net.Conn, err error) {
// Listen starts a SSH server listens on given port.
func Listen(host string, port int, ciphers []string, keyExchanges []string, macs []string) {
srv := ssh.Server{
Addr: fmt.Sprintf("%s:%d", host, port),
Addr: net.JoinHostPort(host, strconv.Itoa(port)),
PublicKeyHandler: publicKeyHandler,
Handler: sessionHandler,
ServerConfigCallback: func(ctx ssh.Context) *gossh.ServerConfig {
Expand Down
6 changes: 5 additions & 1 deletion routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package routers

import (
"context"
"net"
"reflect"
"runtime"
"strconv"
"strings"

"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -155,7 +157,9 @@ func GlobalInit(ctx context.Context) {

if setting.SSH.StartBuiltinServer {
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 {
ssh.Unused()
}
Expand Down

0 comments on commit bd613c7

Please sign in to comment.