Skip to content

Commit

Permalink
feat: support ssh authorized_keys authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
jon4hz committed Jul 29, 2022
1 parent 9073d16 commit dac69c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ $ fztea server -l 127.0.0.1:2222
# connect to the server (from the same machine)
$ ssh localhost -p 2222
```
Currently the ssh server supports no authentiaction methods so use it with caution.
By default, `fztea` doesn't require any authentication but you can specify an `authorized_keys` file if you want to.

```bash
# use authorized_keys for authentication
$ fztea server -l 127.0.0.1:2222 -k ~/.ssh/authorized_keys
```

## 🎬 Demo

Expand Down
16 changes: 13 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
)

var serverFlags struct {
port string
listen string
port string
listen string
authorizedKeys string
}

var serverCmd = &coral.Command{
Expand All @@ -31,6 +32,7 @@ var serverCmd = &coral.Command{
func init() {
serverCmd.Flags().StringVarP(&serverFlags.port, "port", "p", "", "port to connect to")
serverCmd.Flags().StringVarP(&serverFlags.listen, "listen", "l", "127.0.0.1:2222", "address to listen on")
serverCmd.Flags().StringVarP(&serverFlags.authorizedKeys, "authorized-keys", "k", "", "authorized_keys file for public key authentication")
}

func server(cmd *coral.Command, args []string) {
Expand All @@ -41,7 +43,7 @@ func server(cmd *coral.Command, args []string) {

cl := newConnLimiter(1)

s, err := wish.NewServer(
sshOpts := []ssh.Option{
wish.WithAddress(serverFlags.listen),
wish.WithHostKeyPath(".ssh/flipperzero_tea_ed25519"),
wish.WithMiddleware(
Expand All @@ -59,6 +61,14 @@ func server(cmd *coral.Command, args []string) {
lm.Middleware(),
connLimit(cl),
),
}

if serverFlags.authorizedKeys != "" {
sshOpts = append(sshOpts, wish.WithAuthorizedKeys(serverFlags.authorizedKeys))
}

s, err := wish.NewServer(
sshOpts...,
)
if err != nil {
log.Fatalln(err)
Expand Down

0 comments on commit dac69c6

Please sign in to comment.