MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / PublicKeyAuth

Method PublicKeyAuth

server/sftp.go:124–149  ·  view source on GitHub ↗
(conn ssh.ConnMetadata, key ssh.PublicKey)

Source from the content-addressed store, hash-verified

122}
123
124func (d *SftpDriver) PublicKeyAuth(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
125 userObj, err := op.GetUserByName(conn.User())
126 if err != nil {
127 return nil, err
128 }
129 if userObj.Disabled || !userObj.CanFTPAccess() {
130 return nil, errors.New("user is not allowed to access via SFTP")
131 }
132 keys, _, err := op.GetSSHPublicKeyByUserId(userObj.ID, 1, -1)
133 if err != nil {
134 return nil, err
135 }
136 marshal := string(key.Marshal())
137 for _, sk := range keys {
138 if marshal != sk.KeyStr {
139 pubKey, _, _, _, e := ssh.ParseAuthorizedKey([]byte(sk.KeyStr))
140 if e != nil || marshal != string(pubKey.Marshal()) {
141 continue
142 }
143 }
144 sk.LastUsedTime = time.Now()
145 _ = op.UpdateSSHPublicKey(&sk)
146 return nil, nil
147 }
148 return nil, errors.New("public key refused")
149}
150
151func (d *SftpDriver) AuthLogCallback(conn ssh.ConnMetadata, method string, err error) {
152 ip := conn.RemoteAddr().String()

Callers

nothing calls this directly

Calls 6

GetUserByNameFunction · 0.92
GetSSHPublicKeyByUserIdFunction · 0.92
UpdateSSHPublicKeyFunction · 0.92
CanFTPAccessMethod · 0.80
UserMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected