fix(sftp-server): postgre cannot store control characters (#8188 close #8186)

This commit is contained in:
KirCute 2025-03-27 23:14:36 +08:00 committed by GitHub
parent 32890da29f
commit 6e13923225
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View File

@ -17,7 +17,6 @@ func CreateSSHPublicKey(k *model.SSHPublicKey) (error, bool) {
if err != nil {
return err, false
}
k.KeyStr = string(pubKey.Marshal())
k.Fingerprint = ssh.FingerprintSHA256(pubKey)
k.AddedTime = time.Now()
k.LastUsedTime = k.AddedTime

View File

@ -6,6 +6,7 @@ import (
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
"strconv"
"strings"
)
type SSHKeyAddReq struct {
@ -30,7 +31,7 @@ func AddMyPublicKey(c *gin.Context) {
}
key := &model.SSHPublicKey{
Title: req.Title,
KeyStr: req.Key,
KeyStr: strings.TrimSpace(req.Key),
UserId: userObj.ID,
}
err, parsed := op.CreateSSHPublicKey(key)

View File

@ -113,11 +113,15 @@ func (d *SftpDriver) PublicKeyAuth(conn ssh.ConnMetadata, key ssh.PublicKey) (*s
}
marshal := string(key.Marshal())
for _, sk := range keys {
if marshal == sk.KeyStr {
sk.LastUsedTime = time.Now()
_ = op.UpdateSSHPublicKey(&sk)
return nil, nil
if marshal != sk.KeyStr {
pubKey, _, _, _, e := ssh.ParseAuthorizedKey([]byte(sk.KeyStr))
if e != nil || marshal != string(pubKey.Marshal()) {
continue
}
}
sk.LastUsedTime = time.Now()
_ = op.UpdateSSHPublicKey(&sk)
return nil, nil
}
return nil, errors.New("public key refused")
}