| 89 | } |
| 90 | |
| 91 | func 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 | |
| 112 | func createSFTPHandler() ssh.SubsystemHandler { |
| 113 | return func(s ssh.Session) { |