shared

package
v0.7.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyIDLength       = 32
	NonceSize         = 12
	SignatureSize     = ed25519.SignatureSize // 64 bytes for Ed25519 signature
	PublicKeySize     = 32
	PrivateKeySize    = 32
	SharedKeySize     = 32
	FingerprintLength = 16
)
View Source
const (
	RoleOwner    = "owner"
	RoleAdmin    = "admin"
	RoleDeployer = "deployer"
	RoleReader   = "reader"
)
View Source
const Version = "v0.7.18"

Variables

View Source
var (
	ErrNilKey                = errors.New("crypto: nil key provided")
	ErrInvalidClientID       = errors.New("auth: invalid client ID")
	ErrInvalidSigningMethod  = errors.New("auth: invalid signing method")
	ErrKeyMismatch           = errors.New("auth: key ID mismatch")
	ErrInvalidAudience       = errors.New("auth: invalid audience")
	ErrInvalidToken          = errors.New("auth: invalid token")
	ErrAuthKeyNotInitialized = errors.New("auth: WebSocket auth key not initialized")
	ErrEmptyClientID         = errors.New("auth: empty client ID")
)
View Source
var (
	SharedLogger = PackageLogger("shared", "🔗 SHARED")
)

Functions

func CreateZip added in v0.1.60

func CreateZip(srcDir, targetZip string) error

func DecodeFromBase64

func DecodeFromBase64(encoded string) ([]byte, error)

func DecodeFromHex

func DecodeFromHex(encoded string) ([]byte, error)

func Decrypt

func Decrypt(cipherText []byte, key []byte, nonce []byte) ([]byte, error)

func DecryptMessage

func DecryptMessage(key []byte, data []byte) ([]byte, uint64, error)

func DeriveSharedKey

func DeriveSharedKey(privateKey *ecdh.PrivateKey, publicKey *ecdh.PublicKey) ([]byte, error)

func DeserializeFromJSON

func DeserializeFromJSON(jsonStr string, data interface{}) error

func EncodeToBase64

func EncodeToBase64(data []byte) string

func EncodeToHex

func EncodeToHex(data []byte) string

func Encrypt

func Encrypt(data []byte, key []byte) ([]byte, []byte, error)

func EncryptMessage

func EncryptMessage(key []byte, sequence uint64, payload interface{}) ([]byte, error)

func ExtractTarGz added in v0.1.60

func ExtractTarGz(src, dest string) error

func GenerateCommandID

func GenerateCommandID() string

func GenerateFingerprint

func GenerateFingerprint(publicKey ed25519.PublicKey) (string, error)

func GetCurrentTimestamp

func GetCurrentTimestamp() int64

func HasRequiredRole

func HasRequiredRole(role Identity, Role string) bool

func LoadKeyFromFile

func LoadKeyFromFile(filename string) ([]byte, error)

func RunCryptoHealthChecks

func RunCryptoHealthChecks() error

func SecureKeyMemory

func SecureKeyMemory(key []byte)

func SerializeToJSON

func SerializeToJSON(data interface{}) (string, error)

func Sign

func Sign(data []byte, privateKey ed25519.PrivateKey) ([]byte, error)

func ValidateKeyID

func ValidateKeyID(keyID string) error

validate key id

func Verify

func Verify(data []byte, signature []byte, publicKey ed25519.PublicKey) (bool, error)

func VerifyMessageSignature

func VerifyMessageSignature(msg AgentMessage) bool

func ZeroKey

func ZeroKey(key []byte)

Types

type AgentMessage

type AgentMessage struct {
	Source    AgentType         `json:"source"`
	Target    AgentType         `json:"target"`
	Type      MessageType       `json:"type"`
	Payload   json.RawMessage   `json:"payload"`
	Timestamp int64             `json:"timestamp"`
	AgentID   string            `json:"agent_id"`
	Signature string            `json:"signature,omitempty"`
	Context   map[string]string `json:"context,omitempty"`
}

func NewCommandMessage

func NewCommandMessage(agentID string, command CommandPayload) (AgentMessage, error)

func NewStatusMessage

func NewStatusMessage(agentID string, status StatusPayload) (AgentMessage, error)

func SignMessage

func SignMessage(msg AgentMessage, privateKey *ecdsa.PrivateKey) (AgentMessage, error)

type AgentType

type AgentType string
const (
	AgentDaemon    AgentType = "daemon"
	AgentCLI       AgentType = "cli"
	AgentDashboard AgentType = "dashboard"
)

type AuditLogEntry

type AuditLogEntry struct {
	Action    string    `json:"action"`
	Actor     string    `json:"actor"`
	Target    string    `json:"target"`
	Timestamp time.Time `json:"timestamp"`
	Signature string    `json:"signature"`
	IP        string    `json:"ip,omitempty"`
	Message   string    `json:"message"`
	Client    string    `json:"client_id"`
}

type AuthPayload

type AuthPayload struct {
	Token    string `json:"token"`
	Version  string `json:"version"`
	Hostname string `json:"hostname,omitempty"`
}

type CommandPayload

type CommandPayload struct {
	Name string      `json:"name"`
	Args []string    `json:"args,omitempty"`
	ID   string      `json:"id"`
	Meta interface{} `json:"meta,omitempty"`
}

type ECCSignature

type ECCSignature struct {
	R *big.Int
	S *big.Int
}

type EncryptedEnv

type EncryptedEnv struct {
	KeyID        string            `json:"key_id"`
	EnvBlob      string            `json:"env_blob"`
	Variables    map[string]string `json:"variables"`
	Nonce        string            `json:"nonce"`
	Timestamp    time.Time         `json:"timestamp"`
	CLIPublicKey string            `json:"cli_public_key"`
}

type EnvFile

type EnvFile struct {
	Variables map[string]string
	Raw       []byte
}

func ParseEnvFile

func ParseEnvFile(content []byte) (*EnvFile, error)

type Envelope

type Envelope struct {
	Payload   []byte `json:"payload"`
	Signature string `json:"signature"`
}

type ErrorPayload

type ErrorPayload struct {
	Message string `json:"message"`
	Code    int    `json:"code,omitempty"`
	Details string `json:"details,omitempty"`
}

type EventPayload

type EventPayload struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

type Identity

type Identity struct {
	Fingerprint string    `json:"fingerprint"`
	PublicKey   string    `json:"public_key"`
	SignPublic  string    `json:"sign_public"`
	Role        string    `json:"role"`
	Email       string    `json:"email"`
	AddedBy     string    `json:"added_by"`
	CreatedAt   time.Time `json:"created_at"`
}

type KeyPair

type KeyPair struct {
	ECDHPrivate *ecdh.PrivateKey
	ECDHPublic  *ecdh.PublicKey
	SignPrivate ed25519.PrivateKey
	SignPublic  ed25519.PublicKey
	ECDSAKey    *ecdsa.PrivateKey
	KeyID       string
}

func GenerateKeyPair

func GenerateKeyPair() (*KeyPair, error)

type LogLevel

type LogLevel int
const (
	LevelTrace LogLevel = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelSuccess
	LevelError
	LevelFatal
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func DefaultLogger

func DefaultLogger() *Logger

func New

func New(out io.Writer, prefix string, flag int, minLevel LogLevel) *Logger

func PackageLogger

func PackageLogger(pkgName string, displayName string) *Logger

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...interface{})

func (*Logger) EnableBanner

func (l *Logger) EnableBanner(enable bool)

func (*Logger) EnableCallerInfo

func (l *Logger) EnableCallerInfo(enable bool)

func (*Logger) EnableColor

func (l *Logger) EnableColor(enable bool)

func (*Logger) EnableTimestamp

func (l *Logger) EnableTimestamp(enable bool)

func (*Logger) Error

func (l *Logger) Error(msg string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, args ...interface{})

func (*Logger) Indent

func (l *Logger) Indent() *Logger

func (*Logger) Info

func (l *Logger) Info(msg string, args ...interface{})

func (*Logger) JSON

func (l *Logger) JSON(level LogLevel, data interface{})

func (*Logger) Log

func (l *Logger) Log(level LogLevel, msg string, args ...interface{})

func (*Logger) Progress

func (l *Logger) Progress(level LogLevel, current, total int, label string)

func (*Logger) RegisterPackage

func (l *Logger) RegisterPackage(pkg string, displayName string)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel)

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

func (*Logger) SetTimeFormat

func (l *Logger) SetTimeFormat(format string)

func (*Logger) Success

func (l *Logger) Success(msg string, args ...interface{})

func (*Logger) Table

func (l *Logger) Table(level LogLevel, headers []string, rows [][]string)

func (*Logger) Timed

func (l *Logger) Timed(label string, fn func())

func (*Logger) Trace

func (l *Logger) Trace(msg string, args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...interface{})

func (*Logger) WithPrefix

func (l *Logger) WithPrefix(prefix string) *Logger

type MessageHeader

type MessageHeader struct {
	Type      string `json:"type"`
	SessionID string `json:"session_id"`
}

type MessageType

type MessageType string
const (
	TypeCommand         MessageType = "command"
	TypeCommandResponse MessageType = "command_response"
	TypeStatus          MessageType = "status"
	TypeResponse        MessageType = "response"
	TypeEvent           MessageType = "event"
	TypeLog             MessageType = "log"
	TypeError           MessageType = "error"
	TypeAuth            MessageType = "auth"
	TypeStatusAck       MessageType = "status_ack"
	TypeAuthResponse    MessageType = "auth_response"
)

type PublicKeyResponse

type PublicKeyResponse struct {
	KeyID      string `json:"key_id"`
	PublicKey  string `json:"public_key"`
	SignPublic string `json:"sign_public"`
}

type SecureMessage

type SecureMessage struct {
	IV         []byte `json:"iv"`
	Ciphertext []byte `json:"ciphertext"`
	Tag        []byte `json:"tag"`
	Sequence   uint64 `json:"sequence"`
	Timestamp  int64  `json:"timestamp"`
}

type StatusPayload

type StatusPayload struct {
	Status  string                 `json:"status"`
	Metrics map[string]interface{} `json:"metrics,omitempty"`
	Load    SystemLoad             `json:"load,omitempty"`
}

type SystemLoad

type SystemLoad struct {
	CPU    float64 `json:"cpu"`
	Memory float64 `json:"memory"`
	Disk   float64 `json:"disk"`
}

type TrustStore

type TrustStore struct {
	Keys       []TrustedKey `json:"keys"`
	Identities []Identity   `json:"identities"`
}

type TrustedKey

type TrustedKey struct {
	KeyID       string          `json:"key_id"`
	PublicKey   *ecdh.PublicKey `json:"public_key"`
	SignPublic  string          `json:"sign_public"`
	Fingerprint string          `json:"fingerprint"`
}

Directories

Path Synopsis
Package sanitizer provides security-focused sanitization functions to prevent common vulnerabilities like command injection, path traversal, and other security issues.
Package sanitizer provides security-focused sanitization functions to prevent common vulnerabilities like command injection, path traversal, and other security issues.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL