mirror of
https://github.com/coalaura/up.git
synced 2025-07-17 21:44:35 +00:00
initial commit
This commit is contained in:
33
internal/challenge.go
Normal file
33
internal/challenge.go
Normal 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
38
internal/types.go
Normal 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"`
|
||||
}
|
Reference in New Issue
Block a user