MCPcopy Create free account
hub / github.com/Fahrj/reverse-ssh / createPublicKeyHandler

Function createPublicKeyHandler

core.go:91–110  ·  view source on GitHub ↗
(authorizedKey string)

Source from the content-addressed store, hash-verified

89}
90
91func createPublicKeyHandler(authorizedKey string) ssh.PublicKeyHandler {
92 if authorizedKey == "" {
93 return nil
94 }
95
96 return func(ctx ssh.Context, key ssh.PublicKey) bool {
97 master, _, _, _, err := ssh.ParseAuthorizedKey([]byte(authorizedKey))
98 if err != nil {
99 log.Println("Encountered error while parsing public key:", err)
100 return false
101 }
102 passed := bytes.Equal(key.Marshal(), master.Marshal())
103 if passed {
104 log.Printf("Successful authentication with ssh key from %s@%s", ctx.User(), ctx.RemoteAddr().String())
105 } else {
106 log.Printf("Invalid ssh key from %s@%s", ctx.User(), ctx.RemoteAddr().String())
107 }
108 return passed
109 }
110}
111
112func createSFTPHandler() ssh.SubsystemHandler {
113 return func(s ssh.Session) {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected