vau

package
v0.20.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: EUPL-1.2 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version        = byte(0x02)
	HeaderRequest  = byte(0x01)
	HeaderResponse = byte(0x02)
)

Variables

This section is empty.

Functions

func AEADDecrypt

func AEADDecrypt(key []byte, ciphertext []byte) ([]byte, error)

func AEADEncrypt

func AEADEncrypt(key, plaintext []byte) ([]byte, error)

func KemKDF1

func KemKDF1(ss_e_ecdh, ss_e_kyber768 []byte) (k1_c2s []byte, k1_s2c []byte, err error)

func KemKDF2

func KemKDF2(ecdhSS1, kemSS1, ecdhSS2, kemSS2 []byte) (k2_c2s_key_confirmation, k2_c2s_app_data, k2_s2c_key_confirmation, k2_s2c_app_data, key_id []byte, err error)

func PostMessage

func PostMessage[M any](httpClient *http.Client, url string, requestMessage any) ([]byte, *http.Response, []byte, *M, error)

Types

type CertData

type CertData struct {
	Cert     *x509.Certificate
	CACert   *x509.Certificate
	RCAChain []*x509.Certificate
}

func (*CertData) UnmarshalCBOR

func (c *CertData) UnmarshalCBOR(data []byte) error

type Channel

type Channel struct {
	Env                 Env
	ID                  string
	ChannelURL          *url.URL
	SignedPublicVAUKeys *SignedPublicVAUKeys
	// contains filtered or unexported fields
}

func OpenChannel

func OpenChannel(baseURLString string, env Env, httpClient *http.Client) (*Channel, error)

func RestoreChannel

func RestoreChannel(state ChannelSnapshot, httpClient *http.Client) (*Channel, error)

RestoreChannel reconstructs a Channel from a previously captured state. The HTTP client is provided by the caller (typically wired with the same cert pool used at handshake time). Subsequent Encrypts will resume from the counters in the state.

func (*Channel) Decrypt

func (c *Channel) Decrypt(data []byte, req *http.Request) (*http.Response, error)

func (*Channel) DecryptResponse

func (c *Channel) DecryptResponse(resp *http.Response, req *http.Request) (*http.Response, error)

func (*Channel) Do

func (c *Channel) Do(req *http.Request) (*http.Response, error)

func (*Channel) Encrypt

func (c *Channel) Encrypt(data []byte) (*EncryptedRequest, error)

func (*Channel) EncryptRequest

func (c *Channel) EncryptRequest(r *http.Request) (*EncryptedRequest, error)

func (*Channel) PostEncryptedRequest

func (c *Channel) PostEncryptedRequest(data []byte) (*http.Response, error)

PostEncryptedRequest sends previously encrypted data to the server, returning the raw "outer" response.

func (*Channel) Snapshot

func (c *Channel) Snapshot() ChannelSnapshot

Snapshot returns the current state of the channel suitable for persistence. Counters are read under their respective locks so concurrent senders don't race the snapshotter.

type ChannelSnapshot

type ChannelSnapshot struct {
	Env                 Env    `json:"env"`
	ID                  string `json:"id"`
	ChannelURL          string `json:"channel_url"`
	KeyID               []byte `json:"key_id"`
	K2C2SAppData        []byte `json:"k2_c2s_app_data"`
	K2C2SAppDataCounter uint64 `json:"k2_c2s_app_data_counter"`
	K2S2CAppData        []byte `json:"k2_s2c_app_data"`
	RequestCounter      uint64 `json:"request_counter"`
}

ChannelSnapshot captures everything needed to resume an open VAU channel from a different process. AEAD keys, the channel ID/URL, and both monotonic counters are included; the HTTP client and SignedPublicVAUKeys are intentionally excluded (the client is process-local, the server keys are only used during the initial handshake and are not consulted on subsequent Encrypt/Decrypt).

The receiver of a ChannelSnapshot MUST persist counters at least as often as it sends VAU requests — counter reuse breaks AES-GCM nonce uniqueness AND will be rejected by the server. The simplest correct pattern: snapshot after each successful request, drop the snapshot on any failure, fall back to a fresh handshake.

type ChannelState

type ChannelState struct {
	ID                      string
	Message1Raw             []byte
	Message2Raw             []byte
	K1_ss_ecdh              []byte
	K1_ss_kem               []byte
	K1_c2s                  []byte
	K1_s2c                  []byte
	KeyID                   []byte
	K2_c2s_app_data         []byte
	K2_s2c_app_data         []byte
	K2_s2c_app_data_counter Counter
}

type Counter

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

type ECDHData

type ECDHData struct {
	Crv string `cbor:"crv"`
	X   []byte `cbor:"x"`
	Y   []byte `cbor:"y"`
}

func (*ECDHData) Encapsulate

func (ed *ECDHData) Encapsulate() (ss []byte, ct *ECDHData, err error)

func (*ECDHData) PublicKey

func (ed *ECDHData) PublicKey() (*ecdh.PublicKey, error)

type ECKeyPair

type ECKeyPair struct {
	PublicKey  *ecdh.PublicKey
	PublicData ECDHData
	// contains filtered or unexported fields
}

func GenerateRandomECKeyPair

func GenerateRandomECKeyPair(curve elliptic.Curve) (*ECKeyPair, error)

GenerateRandomECKeyPair generates a random EC key pair

func (*ECKeyPair) Decapsulate

func (kp *ECKeyPair) Decapsulate(ecdhData *ECDHData) (ss []byte, err error)

Decapsulate computes the shared secret between the private key and the public key of the sender

type EncryptedRequest

type EncryptedRequest struct {
	RequestCounter uint64
	Ciphertext     []byte
}

type Env

type Env byte
const EnvNonPU Env = 0
const EnvPU Env = 1

type KEMData

type KEMData []byte

func (KEMData) Encapsulate

func (kd KEMData) Encapsulate() (ss []byte, ct []byte, err error)

Encapsulate generates a shared secret and a ciphertext

func (KEMData) PublicKey

func (kd KEMData) PublicKey() (kem.PublicKey, error)

type KEMKeyPair

type KEMKeyPair struct {
	PublicData KEMData
	// contains filtered or unexported fields
}

func GenerateKEMKeyPair

func GenerateKEMKeyPair(scheme kem.Scheme) (*KEMKeyPair, error)

func (*KEMKeyPair) Decapsulate

func (kp *KEMKeyPair) Decapsulate(ciphertext []byte) ([]byte, error)

type KeyPairs

type KeyPairs struct {
	ECKeyPair  *ECKeyPair
	KEMKeyPair *KEMKeyPair
}

func GenerateKeyPairs

func GenerateKeyPairs() (*KeyPairs, error)

type Message1

type Message1 struct {
	MessageType string
	ECDH_PK     ECDHData
	Kyber768_PK KEMData
}

type Message2

type Message2 struct {
	MessageType string
	ECDH_ct     ECDHData
	Kyber768_ct []byte
	AEAD_ct     []byte
}

type Message3

type Message3 struct {
	MessageType              string
	AEAD_ct                  []byte
	AEAD_ct_key_confirmation []byte
}

type Message3Inner

type Message3Inner struct {
	ECDH_ct     ECDHData
	Kyber768_ct []byte
	ERP         bool
	ESO         bool
}

type Message4

type Message4 struct {
	MessageType              string
	AEAD_ct_key_confirmation []byte
}

type MessageError

type MessageError struct {
	MessageType  string `cbor:"MessageType"`
	ErrorCode    uint64 `cbor:"ErrorCode"`
	ErrorMessage string `cbor:"ErrorMessage"`
}

MessageError is a CBOR encoded error message

func (*MessageError) Error

func (m *MessageError) Error() string

type PublicVAUKeys

type PublicVAUKeys struct {
	ECDH_PK     ECDHData
	Kyber768_PK KEMData
	IssuedAt    int64  `cbor:"iat"`
	ExpiresAt   int64  `cbor:"exp"`
	Commment    string `cbor:"comment"`
}

type Server

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

func NewServer

func NewServer() (s *Server, err error)

func (*Server) Decapsulate

func (s *Server) Decapsulate(ecdh_ss1, kem_ss1 []byte, ecdh_ct *ECDHData, kem_ct []byte) (k2_c2s_key_confirmation, k2_c2s_app_data, k2_s2c_key_confirmation, k2_s2c_app_data, key_id []byte, err error)

func (*Server) DecryptNestedRequestData

func (s *Server) DecryptNestedRequestData(channelState *ChannelState, r *http.Request) ([]byte, error)

func (*Server) EncryptNestedResponseData

func (s *Server) EncryptNestedResponseData(channelState *ChannelState, data []byte) ([]byte, error)

func (*Server) HandleByContentType

func (s *Server) HandleByContentType(w http.ResponseWriter, r *http.Request)

func (*Server) HandleCertData

func (s *Server) HandleCertData(w http.ResponseWriter, r *http.Request)

func (*Server) HandleMessage1

func (s *Server) HandleMessage1(w http.ResponseWriter, r *http.Request)

func (*Server) HandleMessage3

func (s *Server) HandleMessage3(w http.ResponseWriter, r *http.Request)

func (*Server) HandleNestedRequest

func (s *Server) HandleNestedRequest(w http.ResponseWriter, r *http.Request)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SignedPublicVAUKeys

type SignedPublicVAUKeys struct {
	SignedPubKeys    *PublicVAUKeys `cbor:"-"`
	SignedPubKeysRaw []byte         `cbor:"signed_pub_keys"`
	Signature        []byte         `cbor:"signature-ES256"`
	CertHash         []byte         `cbor:"cert_hash"`
	Cdv              int            `cbor:"cdv"`
	OcspResponse     []byte         `cbor:"ocsp_response"`
}

type Status

type Status struct {
	VAUType            string `json:"VAU-Type"`
	VAUVersion         string `json:"VAU-Version"`
	UserAuthentication string `json:"User-Authentication"`
	KeyID              string `json:"KeyID"`
	ConnectionStart    string `json:"Connection-Start"`
}

Jump to

Keyboard shortcuts

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