Documentation
¶
Overview ¶
Package gomat implements matter protocol to allow talking to matter enabled devices.
Index ¶
- func Commission(fabric *Fabric, device_ip net.IP, pin int, controller_id, device_id uint64) error
- func CreateRandomBytes(n int) []byte
- func EncodeIMInvokeRequest(endpoint uint16, cluster uint32, command uint32, payload []byte, timed bool, ...) []byte
- func EncodeIMReadRequest(endpoint uint16, cluster uint32, attr uint32) []byte
- func EncodeIMStatusResponse(exchange_id uint16, iflag byte) []byte
- func EncodeIMSubscribeRequest(endpoint uint16, cluster uint32, event uint32) []byte
- func EncodeIMTimedRequest(exchange uint16, timeout uint16) []byte
- func EncodeStatusReport(code StatusReportElements) []byte
- func ParseImInvokeResponse(resp *mattertlv.TlvItem) int
- func SerializeCertificateIntoMatter(fabric *Fabric, in *x509.Certificate) []byte
- type CertificateManager
- type DecodedGeneric
- type Fabric
- type FileCertManager
- func (cm *FileCertManager) BootstrapCa() error
- func (cm *FileCertManager) CreateUser(node_id uint64) error
- func (cm *FileCertManager) GetCaCertificate() *x509.Certificate
- func (cm *FileCertManager) GetCaPublicKey() ecdsa.PublicKey
- func (cm *FileCertManager) GetCertificate(id uint64) (*x509.Certificate, error)
- func (cm *FileCertManager) GetPrivkey(id uint64) (*ecdsa.PrivateKey, error)
- func (cm *FileCertManager) Load() error
- func (cm *FileCertManager) SignCertificate(user_pubkey *ecdsa.PublicKey, node_id uint64) (*x509.Certificate, error)
- type MessageHeader
- type Opcode
- type ProtocolId
- type ProtocolMessageHeader
- type SecureChannel
- func ConnectDevice(device_ip net.IP, port int, fabric *Fabric, device_id, admin_id uint64) (SecureChannel, error)
- func SigmaExchange(fabric *Fabric, controller_id uint64, device_id uint64, ...) (SecureChannel, error)
- func Spake2pExchange(pin int, udp *udpChannel) (SecureChannel, error)
- func StartSecureChannel(remote_ip net.IP, remote_port, local_port int) (SecureChannel, error)
- type SpakeCtx
- type StatusReportElements
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Commission ¶
Commission performs commissioning procedure on device with device_ip ip address
- fabric is fabric object with approriate certificate authority
- pin is passcode used for device pairing
- controller_id is identifier of node whioch will be owner/admin of this device
- device_id_id is identifier of "new" device
func CreateRandomBytes ¶
func EncodeIMInvokeRequest ¶
func EncodeIMInvokeRequest(endpoint uint16, cluster uint32, command uint32, payload []byte, timed bool, exchange uint16) []byte
EncodeIMInvokeRequest encodes Interaction Model Invoke Request message
func EncodeIMReadRequest ¶
EncodeIMInvokeRequest encodes Interaction Model Read Request message
func EncodeIMStatusResponse ¶
EncodeIMStatusResponse encodes success Interaction Model Invoke Response
func EncodeIMSubscribeRequest ¶
EncodeIMInvokeRequest encodes Interaction Model Read Request message
func EncodeIMTimedRequest ¶
EncodeIMInvokeRequest encodes Interaction Model Timed Request message
func EncodeStatusReport ¶
func EncodeStatusReport(code StatusReportElements) []byte
func ParseImInvokeResponse ¶
ParseImInvokeResponse parses IM InvokeResponse TLV
- returns 0 when success
- returns -1 when parsing did fail
- returned number > 0 is ClusterStatus code
func SerializeCertificateIntoMatter ¶
func SerializeCertificateIntoMatter(fabric *Fabric, in *x509.Certificate) []byte
SerializeCertificateIntoMatter serializes x509 certificate into matter certificate format. Matter certificate format is way how to make matter even more weird and complicated. Signature of matter vertificate must match signature of certificate reencoded to DER encoding. This requires to handle very carefully order and presence of all elements in original x509.
Types ¶
type CertificateManager ¶
type CertificateManager interface { GetCaPublicKey() ecdsa.PublicKey GetCaCertificate() *x509.Certificate // CreateUser creates keys and certificate for node with specific id // it must be possible to later retrieve node keys using GetPrivkey and certificate using GetCertificate CreateUser(node_id uint64) error // retrieve certificate of specified node (previously created by CreateUser) GetCertificate(id uint64) (*x509.Certificate, error) // retrieve key of specified node (previously created by CreateUser) GetPrivkey(id uint64) (*ecdsa.PrivateKey, error) // create and sign certificate using local CA keys SignCertificate(user_pubkey *ecdsa.PublicKey, node_id uint64) (*x509.Certificate, error) }
matter certificate manager interface all generated certificates must be compatible with matter
- this means that after they are reencoded to matter format and back their signature must match
type DecodedGeneric ¶
type DecodedGeneric struct { MessageHeader MessageHeader ProtocolHeader ProtocolMessageHeader Tlv mattertlv.TlvItem Payload []byte StatusReport StatusReportElements }
type Fabric ¶
type Fabric struct { CertificateManager CertificateManager // contains filtered or unexported fields }
Fabric structure represents matter Fabric. Its main parameters are Id of fabric and certificate manager.
func NewFabric ¶
func NewFabric(id uint64, certman CertificateManager) *Fabric
NewFabric constructs new Fabric object.
func (Fabric) CompressedFabric ¶
CompressedFabric returns Compressed Fabric Identifier which is used to identify fabric in matter protocol.
func (Fabric) GetOperationalDeviceId ¶
type FileCertManager ¶
type FileCertManager struct {
// contains filtered or unexported fields
}
PEM file backed certiticate manager
func NewFileCertManager ¶
func NewFileCertManager(fabric uint64) *FileCertManager
func (*FileCertManager) BootstrapCa ¶
func (cm *FileCertManager) BootstrapCa() error
BootstrapCa initializes CA - creates CA keys and certificate
func (*FileCertManager) CreateUser ¶
func (cm *FileCertManager) CreateUser(node_id uint64) error
func (*FileCertManager) GetCaCertificate ¶
func (cm *FileCertManager) GetCaCertificate() *x509.Certificate
func (*FileCertManager) GetCaPublicKey ¶
func (cm *FileCertManager) GetCaPublicKey() ecdsa.PublicKey
func (*FileCertManager) GetCertificate ¶
func (cm *FileCertManager) GetCertificate(id uint64) (*x509.Certificate, error)
func (*FileCertManager) GetPrivkey ¶
func (cm *FileCertManager) GetPrivkey(id uint64) (*ecdsa.PrivateKey, error)
func (*FileCertManager) Load ¶
func (cm *FileCertManager) Load() error
Load initializes CA. It loads required state from files.
func (*FileCertManager) SignCertificate ¶
func (cm *FileCertManager) SignCertificate(user_pubkey *ecdsa.PublicKey, node_id uint64) (*x509.Certificate, error)
type MessageHeader ¶
type MessageHeader struct {
// contains filtered or unexported fields
}
func (*MessageHeader) Dump ¶
func (m *MessageHeader) Dump()
func (*MessageHeader) Encode ¶
func (m *MessageHeader) Encode(data *bytes.Buffer)
type Opcode ¶
type Opcode byte
const INTERACTION_OPCODE_INVOKE_REQ Opcode = 0x8
const INTERACTION_OPCODE_INVOKE_RSP Opcode = 0x9
const INTERACTION_OPCODE_READ_REQ Opcode = 0x2
const INTERACTION_OPCODE_REPORT_DATA Opcode = 0x5
const INTERACTION_OPCODE_STATUS_RSP Opcode = 0x1
const INTERACTION_OPCODE_SUBSC_REQ Opcode = 0x3
const INTERACTION_OPCODE_SUBSC_RSP Opcode = 0x4
const INTERACTION_OPCODE_TIMED_REQ Opcode = 0xa
const SEC_CHAN_OPCODE_ACK Opcode = 0x10
const SEC_CHAN_OPCODE_PAKE1 Opcode = 0x22
const SEC_CHAN_OPCODE_PAKE2 Opcode = 0x23
const SEC_CHAN_OPCODE_PAKE3 Opcode = 0x24
const SEC_CHAN_OPCODE_PBKDF_REQ Opcode = 0x20
const SEC_CHAN_OPCODE_PBKDF_RESP Opcode = 0x21
const SEC_CHAN_OPCODE_STATUS_REP Opcode = 0x40
type ProtocolId ¶
type ProtocolId uint16
const ProtocolIdInteraction ProtocolId = 1
const ProtocolIdSecureChannel ProtocolId = 0
type ProtocolMessageHeader ¶
type ProtocolMessageHeader struct { Opcode Opcode ExchangeId uint16 ProtocolId ProtocolId // contains filtered or unexported fields }
func (*ProtocolMessageHeader) Decode ¶
func (m *ProtocolMessageHeader) Decode(data *bytes.Buffer)
func (*ProtocolMessageHeader) Dump ¶
func (m *ProtocolMessageHeader) Dump()
func (*ProtocolMessageHeader) Encode ¶
func (m *ProtocolMessageHeader) Encode(data *bytes.Buffer)
type SecureChannel ¶
type SecureChannel struct { Udp *udpChannel Counter uint32 // contains filtered or unexported fields }
func ConnectDevice ¶
func SigmaExchange ¶
func SigmaExchange(fabric *Fabric, controller_id uint64, device_id uint64, secure_channel SecureChannel) (SecureChannel, error)
SigmaExhange establishes secure session using CASE (Certificate Authenticated Session Establishment)
func Spake2pExchange ¶
func Spake2pExchange(pin int, udp *udpChannel) (SecureChannel, error)
Spake2pExchange establishes secure session using PASE (Passcode-Authenticated Session Establishment). This uses SPAKE2+ protocol
func StartSecureChannel ¶
func StartSecureChannel(remote_ip net.IP, remote_port, local_port int) (SecureChannel, error)
StartSecureChannel initializes secure channel for plain unencrypted communication. It initializes UDP interface and blocks local udp port. Secure channel becomes encrypted after encryption keys are supplied.
func (*SecureChannel) Close ¶
func (sc *SecureChannel) Close()
Close secure channel. Send close session message to remote end and relase UDP port.
func (*SecureChannel) Receive ¶
func (sc *SecureChannel) Receive() (DecodedGeneric, error)
func (*SecureChannel) Send ¶
func (sc *SecureChannel) Send(data []byte) error
Send sends Protocol Message via secure channel. It creates Matter Message by adding Message Header. Protocol Message is aes-ccm encrypted when channel does have encryption keys. When encryption keys are empty plain Message is sent.
type SpakeCtx ¶
type SpakeCtx struct { W0 []byte W1 []byte X point Y point Z point V point L point Ke []byte Ka []byte // contains filtered or unexported fields }
func NewSpaceCtx ¶
func NewSpaceCtx() SpakeCtx
func (*SpakeCtx) Gen_random_X ¶
func (ctx *SpakeCtx) Gen_random_X()
func (*SpakeCtx) Gen_random_Y ¶
func (ctx *SpakeCtx) Gen_random_Y()
type StatusReportElements ¶
func (StatusReportElements) Dump ¶
func (sr StatusReportElements) Dump()
func (StatusReportElements) IsOk ¶
func (sr StatusReportElements) IsOk() bool