feat(sftp-server): public key login (#7668)

This commit is contained in:
KirCute_ECT
2024-12-25 21:15:06 +08:00
committed by GitHub
parent db5c601cfe
commit 77d0c78bfd
7 changed files with 289 additions and 2 deletions

28
internal/model/sshkey.go Normal file
View File

@ -0,0 +1,28 @@
package model
import (
"golang.org/x/crypto/ssh"
"time"
)
type SSHPublicKey struct {
ID uint `json:"id" gorm:"primaryKey"`
UserId uint `json:"-"`
Title string `json:"title"`
Fingerprint string `json:"fingerprint"`
KeyStr string `gorm:"type:text" json:"-"`
AddedTime time.Time `json:"added_time"`
LastUsedTime time.Time `json:"last_used_time"`
}
func (k *SSHPublicKey) GetKey() (ssh.PublicKey, error) {
pubKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(k.KeyStr))
if err != nil {
return nil, err
}
return pubKey, nil
}
func (k *SSHPublicKey) UpdateLastUsedTime() {
k.LastUsedTime = time.Now()
}