Skip to content

Commit 7131c7d

Browse files
spacetouristlafriks
authored andcommitted
Configurable SSH cipher suite (#913)
* Configurable SSH cipher suite * Update configuration file comment * Add default in settings loading code * Fix fmt and log messsage * Remove default from code as this could probably might not be good idea
1 parent 985a395 commit 7131c7d

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

conf/app.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ SSH_PORT = 22
125125
SSH_LISTEN_PORT = %(SSH_PORT)s
126126
; Root path of SSH directory, default is '~/.ssh', but you have to use '/home/git/.ssh'.
127127
SSH_ROOT_PATH =
128+
; For built-in SSH server only, choose the ciphers to support for SSH connections,
129+
; for system SSH this setting has no effect
130+
SSH_SERVER_CIPHERS = aes128-ctr, aes192-ctr, aes256-ctr, [email protected], arcfour256, arcfour128
128131
; Directory to create temporary files when test public key using ssh-keygen,
129132
; default is system temporary directory.
130133
SSH_KEY_TEST_PATH =

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ var (
9696
ListenHost string `ini:"SSH_LISTEN_HOST"`
9797
ListenPort int `ini:"SSH_LISTEN_PORT"`
9898
RootPath string `ini:"SSH_ROOT_PATH"`
99+
ServerCiphers []string `ini:"SSH_SERVER_CIPHERS"`
99100
KeyTestPath string `ini:"SSH_KEY_TEST_PATH"`
100101
KeygenPath string `ini:"SSH_KEYGEN_PATH"`
101102
AuthorizedKeysBackup bool `ini:"SSH_AUTHORIZED_KEYS_BACKUP"`
@@ -708,6 +709,7 @@ func NewContext() {
708709
SSH.Domain = Domain
709710
}
710711
SSH.RootPath = path.Join(homeDir, ".ssh")
712+
SSH.ServerCiphers = sec.Key("SSH_SERVER_CIPHERS").Strings(",")
711713
SSH.KeyTestPath = os.TempDir()
712714
if err = Cfg.Section("server").MapTo(&SSH); err != nil {
713715
log.Fatal(4, "Failed to map SSH settings: %v", err)

modules/ssh/ssh.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ func listen(config *ssh.ServerConfig, host string, port int) {
151151
}
152152

153153
// Listen starts a SSH server listens on given port.
154-
func Listen(host string, port int) {
154+
func Listen(host string, port int, ciphers []string) {
155155
config := &ssh.ServerConfig{
156+
Config: ssh.Config{
157+
Ciphers: ciphers,
158+
},
156159
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
157160
pkey, err := models.SearchPublicKeyByContent(strings.TrimSpace(string(ssh.MarshalAuthorizedKey(key))))
158161
if err != nil {

routers/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func GlobalInit() {
7777
checkRunMode()
7878

7979
if setting.InstallLock && setting.SSH.StartBuiltinServer {
80-
ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort)
81-
log.Info("SSH server started on %s:%v", setting.SSH.ListenHost, setting.SSH.ListenPort)
80+
ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers)
81+
log.Info("SSH server started on %s:%d. Cipher list (%v)", setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers)
8282
}
8383
}

0 commit comments

Comments
 (0)