| 1234567891011121314151617181920212223242526272829303132333435363738 |
- package aerotun
- import (
- "encoding/base64"
- "encoding/hex"
- "errors"
- "github.com/flynn/noise"
- )
- func decodeKey(s string) ([]byte, error) {
- if len(s) == 64 {
- if b, err := hex.DecodeString(s); err == nil {
- return b, nil
- }
- }
- b, err := base64.StdEncoding.DecodeString(s)
- if err != nil || len(b) != 32 {
- return nil, errors.New("key must encode exactly 32 bytes (64 hex characters or base64)")
- }
- return b, nil
- }
- func GenerateIdentity() (private, public string, err error) {
- k, err := noise.DH25519.GenerateKeypair(nil)
- if err != nil {
- return "", "", err
- }
- return base64.StdEncoding.EncodeToString(k.Private), base64.StdEncoding.EncodeToString(k.Public), nil
- }
- // PublicView is the only configuration representation sent to API clients.
- // Secret fields remain available solely for private configuration persistence.
- func (c TunnelInstance) PublicView() TunnelInstance {
- c.HasPSK = c.PSK != ""
- c.PSK = ""
- c.HasPrivateKey = c.PrivateKey != ""
- c.PrivateKey = ""
- return c
- }
|