1
0
mirror of https://github.com/coalaura/up.git synced 2025-07-17 21:44:35 +00:00

initial commit

This commit is contained in:
Laura
2025-06-20 03:27:36 +02:00
commit 2fcfebe25b
14 changed files with 787 additions and 0 deletions

33
internal/challenge.go Normal file
View File

@ -0,0 +1,33 @@
package internal
import (
"crypto/rand"
"encoding/base64"
)
func FreshChallenge() (*AuthChallenge, []byte, error) {
challenge, err := random(64)
if err != nil {
return nil, nil, err
}
token, err := random(64)
if err != nil {
return nil, nil, err
}
return &AuthChallenge{
Token: base64.StdEncoding.EncodeToString(token),
Challenge: base64.StdEncoding.EncodeToString(challenge),
}, challenge, nil
}
func random(n int) ([]byte, error) {
b := make([]byte, n)
if _, err := rand.Read(b); err != nil {
return nil, err
}
return b, nil
}

38
internal/types.go Normal file
View File

@ -0,0 +1,38 @@
package internal
import (
"time"
"golang.org/x/crypto/ssh"
)
type ChallengeEntry struct {
Challenge []byte
PublicKey ssh.PublicKey
Expires time.Time
}
type SessionEntry struct {
PublicKey ssh.PublicKey
Expires time.Time
}
type AuthRequest struct {
Public string `json:"public"`
}
type AuthChallenge struct {
Token string `json:"token"`
Challenge string `json:"challenge"`
}
type AuthResponse struct {
Token string `json:"token"`
Public string `json:"public"`
Format string `json:"format"`
Signature string `json:"signature"`
}
type AuthResult struct {
Token string `json:"token"`
}