44package setting
55
66import (
7+ "os"
78 "path/filepath"
89 "strings"
910 "text/template"
@@ -60,6 +61,7 @@ var SSH = struct {
6061 MinimumKeySizeCheck : true ,
6162 MinimumKeySizes : map [string ]int {"ed25519" : 256 , "ed25519-sk" : 256 , "ecdsa" : 256 , "ecdsa-sk" : 256 , "rsa" : 3071 },
6263 ServerHostKeys : []string {"ssh/gitea.rsa" , "ssh/gogs.rsa" },
64+ KeyTestPath : "ssh_key_test" ,
6365 AuthorizedKeysCommandTemplate : "{{.AppPath}} --config={{.CustomConf}} serv key-{{.Key.ID}}" ,
6466 PerWriteTimeout : PerWriteTimeout ,
6567 PerWritePerKbTimeout : PerWritePerKbTimeout ,
@@ -122,10 +124,6 @@ func loadSSHFrom(rootCfg ConfigProvider) {
122124 if len (serverMACs ) > 0 {
123125 SSH .ServerMACs = serverMACs
124126 }
125- SSH .KeyTestPath = sec .Key ("SSH_KEY_TEST_PATH" ).MustString ("ssh_key_test" )
126- if ! filepath .IsAbs (SSH .KeyTestPath ) {
127- SSH .KeyTestPath = filepath .Join (TempPath , SSH .KeyTestPath )
128- }
129127 if err = sec .MapTo (& SSH ); err != nil {
130128 log .Fatal ("Failed to map SSH settings: %v" , err )
131129 }
@@ -135,6 +133,15 @@ func loadSSHFrom(rootCfg ConfigProvider) {
135133 }
136134 }
137135
136+ SSH .KeyTestPath = sec .Key ("SSH_KEY_TEST_PATH" ).MustString ("ssh_key_test" )
137+ if ! filepath .IsAbs (SSH .KeyTestPath ) {
138+ SSH .KeyTestPath = filepath .Join (TempPath , SSH .KeyTestPath )
139+ }
140+ // FIXME: why 0o644 for a directory .....
141+ if err := os .MkdirAll (SSH .KeyTestPath , 0o644 ); err != nil {
142+ log .Fatal ("failed to create directory %q for ssh key test: %w" , SSH .KeyTestPath , err )
143+ }
144+
138145 SSH .KeygenPath = sec .Key ("SSH_KEYGEN_PATH" ).String ()
139146 SSH .Port = sec .Key ("SSH_PORT" ).MustInt (22 )
140147 SSH .ListenPort = sec .Key ("SSH_LISTEN_PORT" ).MustInt (SSH .Port )
0 commit comments