mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Update x/crypto package and make builtin SSH use default parameters (#34667)
This commit is contained in:
@@ -51,9 +51,6 @@ var SSH = struct {
|
||||
StartBuiltinServer: false,
|
||||
Domain: "",
|
||||
Port: 22,
|
||||
ServerCiphers: []string{"chacha20-poly1305@openssh.com", "aes128-ctr", "aes192-ctr", "aes256-ctr", "aes128-gcm@openssh.com", "aes256-gcm@openssh.com"},
|
||||
ServerKeyExchanges: []string{"curve25519-sha256", "ecdh-sha2-nistp256", "ecdh-sha2-nistp384", "ecdh-sha2-nistp521", "diffie-hellman-group14-sha256", "diffie-hellman-group14-sha1"},
|
||||
ServerMACs: []string{"hmac-sha2-256-etm@openssh.com", "hmac-sha2-256", "hmac-sha1"},
|
||||
MinimumKeySizeCheck: true,
|
||||
MinimumKeySizes: map[string]int{"ed25519": 256, "ed25519-sk": 256, "ecdsa": 256, "ecdsa-sk": 256, "rsa": 3071},
|
||||
ServerHostKeys: []string{"ssh/gitea.rsa", "ssh/gogs.rsa"},
|
||||
@@ -107,21 +104,20 @@ func loadSSHFrom(rootCfg ConfigProvider) {
|
||||
homeDir = strings.ReplaceAll(homeDir, "\\", "/")
|
||||
|
||||
SSH.RootPath = filepath.Join(homeDir, ".ssh")
|
||||
serverCiphers := sec.Key("SSH_SERVER_CIPHERS").Strings(",")
|
||||
if len(serverCiphers) > 0 {
|
||||
SSH.ServerCiphers = serverCiphers
|
||||
}
|
||||
serverKeyExchanges := sec.Key("SSH_SERVER_KEY_EXCHANGES").Strings(",")
|
||||
if len(serverKeyExchanges) > 0 {
|
||||
SSH.ServerKeyExchanges = serverKeyExchanges
|
||||
}
|
||||
serverMACs := sec.Key("SSH_SERVER_MACS").Strings(",")
|
||||
if len(serverMACs) > 0 {
|
||||
SSH.ServerMACs = serverMACs
|
||||
}
|
||||
|
||||
if err = sec.MapTo(&SSH); err != nil {
|
||||
log.Fatal("Failed to map SSH settings: %v", err)
|
||||
}
|
||||
|
||||
serverCiphers := sec.Key("SSH_SERVER_CIPHERS").Strings(",")
|
||||
SSH.ServerCiphers = util.Iif(len(serverCiphers) > 0, serverCiphers, nil)
|
||||
|
||||
serverKeyExchanges := sec.Key("SSH_SERVER_KEY_EXCHANGES").Strings(",")
|
||||
SSH.ServerKeyExchanges = util.Iif(len(serverKeyExchanges) > 0, serverKeyExchanges, nil)
|
||||
|
||||
serverMACs := sec.Key("SSH_SERVER_MACS").Strings(",")
|
||||
SSH.ServerMACs = util.Iif(len(serverMACs) > 0, serverMACs, nil)
|
||||
|
||||
for i, key := range SSH.ServerHostKeys {
|
||||
if !filepath.IsAbs(key) {
|
||||
SSH.ServerHostKeys[i] = filepath.Join(AppDataPath, key)
|
||||
|
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
func Init() error {
|
||||
@@ -23,9 +24,11 @@ func Init() error {
|
||||
|
||||
if setting.SSH.StartBuiltinServer {
|
||||
Listen(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)",
|
||||
log.Info("SSH server started on %q. Ciphers: %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,
|
||||
util.Iif[any](setting.SSH.ServerCiphers == nil, "default", setting.SSH.ServerCiphers),
|
||||
util.Iif[any](setting.SSH.ServerKeyExchanges == nil, "default", setting.SSH.ServerKeyExchanges),
|
||||
util.Iif[any](setting.SSH.ServerMACs == nil, "default", setting.SSH.ServerMACs),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
@@ -333,7 +333,7 @@ func sshConnectionFailed(conn net.Conn, err error) {
|
||||
log.Warn("Failed authentication attempt from %s", conn.RemoteAddr())
|
||||
}
|
||||
|
||||
// Listen starts a SSH server listens on given port.
|
||||
// Listen starts an SSH server listening on given port.
|
||||
func Listen(host string, port int, ciphers, keyExchanges, macs []string) {
|
||||
srv := ssh.Server{
|
||||
Addr: net.JoinHostPort(host, strconv.Itoa(port)),
|
||||
|
Reference in New Issue
Block a user