pairing package

import "code.pfad.fr/gohmekit/pairing"

Index

Examples

Constants

func NewEncryptableDialer

NewEncryptableDialer should be used for homekit client, to wrap a (&net.Dialer{...}).DialContext (see Example).

Example
package main

import (
	"net"
	"net/http"
	"time"

	"code.pfad.fr/gohmekit/pairing"
)

func main() {
	dial, encrypt := pairing.NewEncryptableDialer((&net.Dialer{
		Timeout:   5 * time.Second,
		KeepAlive: 5 * time.Second,
	}).DialContext)
	httpClient := http.Client{
		Transport: &http.Transport{
			Proxy:                 http.ProxyFromEnvironment,
			DialContext:           dial,
			ForceAttemptHTTP2:     false,
			MaxIdleConns:          1,
			IdleConnTimeout:       5 * time.Second,
			TLSHandshakeTimeout:   5 * time.Second,
			ExpectContinueTimeout: 5 * time.Second,
		},
	}
	// do whatever you need with the httpClient
	// call encrypt(sharedKey) to encrypt further communications.
	_ = encrypt
	_ = httpClient
}

func NewRandomPairingID

NewRandomPin generates a random 48-bits pairingID.

func NewRandomPin

NewRandomPin generates a random pin (XXX-XX-XXX).

func WithIdentify

WithIdentify allows to specify a function to call when the device should physically identify itself (before pairing).

func WithLogger

WithLogger adds structured logging to the pairing server.

type AccessoryDevice

AccessoryDevice interface must be implemented by the accessory to support pairing.

func NewDeviceWithPin

NewDeviceWithPin creates a new AccessoryDevice with the given id, pin and private key.

type AccessorySRPSession

type Controller

Controller is used to store the devices in the Database.

type Database

Database interface for the accessory to store its state.

type Device

Device interface must be implemented by the controller to support pairing.

type HTTPServer

HTTPServer must be created with NewServer and can be adjusted afterwards.

func NewServer

NewServer creates a new pairing server. Once the accessory is paired, it will forward all decrypted communications to the given server.

func (*HTTPServer) ListenAndServe

ListenAndServe listens on the TCP network address of the underlying http.Server (server.Addr) and then calls Serve to handle requests on incoming connections.

If the address is blank, ":http" is used.

ListenAndServe always returns a non-nil error. After Shutdown or Close, the returned error is ErrServerClosed.

func (*HTTPServer) Listener

Listener returns a new listener on the TCP network address of the underlying http.Server (server.Addr).

If the address is blank, ":http" is used.

func (*HTTPServer) Serve

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each.

Serve always returns a non-nil error and closes l. After Shutdown or Close, the returned error is ErrServerClosed.

func (*HTTPServer) Shutdown

Shutdown gracefully shuts down the underlying http.Server.

type VerifyClientController

VerifyClientController implements the client logic for the pairing-verify step.

func NewVerifyClientController

NewVerifyClientController implements the client logic for the pairing-verify step.

func (VerifyClientController) FinishRequest

FinishRequest checks the accessory initial response and generate the finish request.

func (VerifyClientController) FinishResponse

FinishResponse checks the response of the accessory. From now on, the connection must be encrypted using the sharedSecret computed in the FinishRequest step.

func (VerifyClientController) StartRequest

StartRequest is the initial pairing-verify request.

Source Files

conn.go database.go device.go dial.go kltv.go listener.go pair_setup.go pair_verify.go pairings.go server.go verify_client_controller.go

Directories

Path Synopsis
crypto