Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ services:
- "1337:1337"
working_dir: /app
volumes:
- ./.ssh:/app/.ssh/
- ./.ssh:/app/.ssh/
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
}

func migrateDb() {
m, err := migrate.New("file://./migrations/", "sqlite:///app/db.sqlite")
m, err := migrate.New("file://./migrations/", "sqlite://db.sqlite")
if err != nil {
log.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions src/sshwordle/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package sshwordle
import (
"database/sql"
"fmt"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/ssh"
"log"
_ "modernc.org/sqlite"
"strings"
"time"

"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/ssh"
_ "modernc.org/sqlite"

"github.com/charmbracelet/bubbles/stopwatch"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
Expand Down
5 changes: 3 additions & 2 deletions src/sshwordle/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package sshwordle

import (
"database/sql"
tea "github.com/charmbracelet/bubbletea"
"log"
"time"

tea "github.com/charmbracelet/bubbletea"
)

func openDb() *sql.DB {
db, err := sql.Open("sqlite", "file:///app/db.sqlite")
db, err := sql.Open("sqlite", "file:db.sqlite")
if err != nil {
log.Panic(err)
}
Expand Down
5 changes: 5 additions & 0 deletions src/sshwordle/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func StartServer(host string, port int, useApi bool) {
s, err := wish.NewServer(
wish.WithAddress(fmt.Sprintf("%s:%d", host, port)),
wish.WithPublicKeyAuth(publicKeyHandler),
wish.WithPasswordAuth(passwordHandler),
wish.WithHostKeyPath(".ssh/term_info_ed25519"),
wish.WithMiddleware(
teaMiddleware.Middleware(sshwordleTeaHandler(useApi)),
Expand Down Expand Up @@ -55,6 +56,10 @@ func publicKeyHandler(_ctx ssh.Context, _key ssh.PublicKey) bool {
return true
}

func passwordHandler(_ ssh.Context, _ string) bool {
return true
}

func sshwordleTeaHandler(useApi bool) teaMiddleware.Handler {
return func(session ssh.Session) (tea.Model, []tea.ProgramOption) {
pty, _, active := session.Pty()
Expand Down
11 changes: 9 additions & 2 deletions src/sshwordle/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package sshwordle
import (
"crypto/sha256"
"fmt"
"github.com/charmbracelet/ssh"
"regexp"

"github.com/charmbracelet/ssh"
)

var keys = []string{
Expand Down Expand Up @@ -39,7 +40,13 @@ func makeGuessesSlice() [][]*Guess {

func makeIdentifier(session ssh.Session) string {
h := sha256.New()
h.Write(session.PublicKey().Marshal())

if key := session.PublicKey(); key != nil {
h.Write(key.Marshal())
} else {
h.Write([]byte(session.User()))
}

return fmt.Sprintf("%x", h.Sum(nil))
}

Expand Down