pairing

package
v0.125.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: MPL-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionPairingAccount = iota + 1
	ActionSyncDevice
	ActionConnect
)

Variables

This section is empty.

Functions

func GenerateCertFromKey

func GenerateCertFromKey(pk *ecdsa.PrivateKey, from time.Time, hostname string) (tls.Certificate, []byte, error)

func GenerateX509Cert

func GenerateX509Cert(sn *big.Int, from, to time.Time, hostname string) *x509.Certificate

func GenerateX509PEMs

func GenerateX509PEMs(cert *x509.Certificate, key *ecdsa.PrivateKey) (certPem, keyPem []byte, err error)

func StartUpPairingClient

func StartUpPairingClient(backend *api.GethStatusBackend, cs, configJSON string) error

func StartUpPairingServer

func StartUpPairingServer(backend *api.GethStatusBackend, mode Mode, configJSON string) (string, error)

StartUpPairingServer generates a Server, starts the pairing server in the correct mode and returns the ConnectionParams string to allow a Client to make a successful connection.

Types

type AccountPayload

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

AccountPayload represents the payload structure a Server handles

func (*AccountPayload) ResetPayload

func (ap *AccountPayload) ResetPayload()

type AccountPayloadManager

type AccountPayloadManager struct {
	*PayloadEncryptionManager
	// contains filtered or unexported fields
}

AccountPayloadManager is responsible for the whole lifecycle of a AccountPayload

func NewAccountPayloadManager

func NewAccountPayloadManager(aesKey []byte, config *AccountPayloadManagerConfig, logger *zap.Logger) (*AccountPayloadManager, error)

NewAccountPayloadManager generates a new and initialised AccountPayloadManager

func (*AccountPayloadManager) Mount

func (apm *AccountPayloadManager) Mount() error

Mount loads and prepares the payload to be stored in the AccountPayloadManager's state ready for later access

func (*AccountPayloadManager) Receive

func (apm *AccountPayloadManager) Receive(data []byte) error

Receive takes a []byte representing raw data, parses and stores the data

func (*AccountPayloadManager) ResetPayload

func (apm *AccountPayloadManager) ResetPayload()

ResetPayload resets all payload state managed by the AccountPayloadManager

type AccountPayloadManagerConfig

type AccountPayloadManagerConfig struct {
	DB *multiaccounts.Database
	*PayloadSourceConfig
}

AccountPayloadManagerConfig represents the initialisation parameters required for a AccountPayloadManager

type AccountPayloadMarshaller

type AccountPayloadMarshaller struct {
	*AccountPayload
	// contains filtered or unexported fields
}

AccountPayloadMarshaller is responsible for marshalling and unmarshalling Server payload data

func NewPairingPayloadMarshaller

func NewPairingPayloadMarshaller(ap *AccountPayload, logger *zap.Logger) *AccountPayloadMarshaller

func (*AccountPayloadMarshaller) MarshalToProtobuf

func (ppm *AccountPayloadMarshaller) MarshalToProtobuf() ([]byte, error)

func (*AccountPayloadMarshaller) UnmarshalProtobuf

func (ppm *AccountPayloadMarshaller) UnmarshalProtobuf(data []byte) error

type AccountPayloadRepository

type AccountPayloadRepository struct {
	*AccountPayload
	// contains filtered or unexported fields
}

AccountPayloadRepository is responsible for loading, parsing, validating and storing Server payload data

func (*AccountPayloadRepository) LoadFromSource

func (apr *AccountPayloadRepository) LoadFromSource() error

func (*AccountPayloadRepository) StoreToSource

func (apr *AccountPayloadRepository) StoreToSource() error

type Action

type Action int

type Client

type Client struct {
	*http.Client
	PayloadManager
	// contains filtered or unexported fields
}

func NewPairingClient

func NewPairingClient(backend *api.GethStatusBackend, c *ConnectionParams, config *AccountPayloadManagerConfig) (*Client, error)

func (*Client) PairAccount

func (c *Client) PairAccount() error

func (*Client) PairSyncDevice

func (c *Client) PairSyncDevice() error

type Config

type Config struct {
	// Connection fields
	PK       *ecdsa.PublicKey
	EK       []byte
	Cert     *tls.Certificate
	Hostname string
	Mode     Mode

	// AccountPayload management fields
	*AccountPayloadManagerConfig
}

type ConnectionParamVersion

type ConnectionParamVersion int
const (
	Version1 ConnectionParamVersion = iota + 1
)

type ConnectionParams

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

func NewConnectionParams

func NewConnectionParams(netIP net.IP, port int, publicKey *ecdsa.PublicKey, aesKey []byte, mode Mode) *ConnectionParams

func (*ConnectionParams) FromString

func (cp *ConnectionParams) FromString(s string) error

FromString parses a connection params string required for to securely connect to another Status device. This function parses a connection string generated by ToString

func (*ConnectionParams) ToString

func (cp *ConnectionParams) ToString() string

ToString generates a string required for generating a secure connection to another Status device.

The returned string will look like below:

  • "cs2:4FHRnp:H6G:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6:2"

Format bytes encoded into a base58 string, delimited by ":"

  • string type identifier
  • version
  • net.IP
  • port
  • ecdsa CompressedPublicKey
  • AES encryption key
  • server mode

func (*ConnectionParams) URL

func (cp *ConnectionParams) URL() (*url.URL, error)

type EncryptionPayload

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

EncryptionPayload represents the plain text and encrypted text of payload data

type Event

type Event struct {
	Type   EventType `json:"type"`
	Error  string    `json:"error,omitempty"`
	Action Action    `json:"action"`
}

Event is a type for transfer events.

type EventType

type EventType string

EventType type for event types.

const (
	EventConnectionError EventType = "connection-error"

	EventConnectionSuccess EventType = "connection-success"

	EventTransferError EventType = "transfer-error"

	EventTransferSuccess EventType = "transfer-success"

	EventProcessSuccess EventType = "process-success"

	EventProcessError EventType = "process-error"
)

type Mode

type Mode int
const (
	Receiving Mode = iota + 1
	Sending
)

type PayloadEncryptionManager

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

PayloadEncryptionManager is responsible for encrypting and decrypting payload data

func NewPayloadEncryptionManager

func NewPayloadEncryptionManager(aesKey []byte, logger *zap.Logger) (*PayloadEncryptionManager, error)

func (*PayloadEncryptionManager) Decrypt

func (pem *PayloadEncryptionManager) Decrypt(data []byte) error

func (*PayloadEncryptionManager) Encrypt

func (pem *PayloadEncryptionManager) Encrypt(data []byte) error

func (*PayloadEncryptionManager) EncryptPlain

func (pem *PayloadEncryptionManager) EncryptPlain(plaintext []byte) ([]byte, error)

EncryptPlain encrypts any given plain text using the internal AES key and returns the encrypted value This function is different to Encrypt as the internal EncryptionPayload.encrypted value is not set

func (*PayloadEncryptionManager) LockPayload

func (pem *PayloadEncryptionManager) LockPayload()

func (*PayloadEncryptionManager) Received

func (pem *PayloadEncryptionManager) Received() []byte

func (*PayloadEncryptionManager) ResetPayload

func (pem *PayloadEncryptionManager) ResetPayload()

func (*PayloadEncryptionManager) ToSend

func (pem *PayloadEncryptionManager) ToSend() []byte

type PayloadManager

type PayloadManager interface {
	// Mount Loads the payload into the PayloadManager's state
	Mount() error

	// Receive stores data from an inbound source into the PayloadManager's state
	Receive(data []byte) error

	// ToSend returns an outbound safe (encrypted) payload
	ToSend() []byte

	// Received returns a decrypted and parsed payload from an inbound source
	Received() []byte

	// ResetPayload resets all payloads the PayloadManager has in its state
	ResetPayload()

	// EncryptPlain encrypts the given plaintext using internal key(s)
	EncryptPlain(plaintext []byte) ([]byte, error)

	// LockPayload prevents future excess to outbound safe and received data
	LockPayload()
}

PayloadManager is the interface for PayloadManagers and wraps the basic functions for fulfilling payload management

type PayloadRepository

type PayloadRepository interface {
	LoadFromSource() error
	StoreToSource() error
}

type PayloadSourceConfig

type PayloadSourceConfig struct {
	// required
	KeystorePath string `json:"keystorePath"`
	// following 2 fields r optional.
	// optional cases:
	// 1. server mode is Receiving and server side doesn't contain this info
	// 2. server mode is Sending and client side doesn't contain this info
	// they are required in other cases
	KeyUID   string `json:"keyUID"`
	Password string `json:"password"`
}

PayloadSourceConfig represents location and access data of the pairing payload ONLY available from the application client

type RawMessageCollector

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

type RawMessagePayloadManager

type RawMessagePayloadManager struct {
	*PayloadEncryptionManager
	// contains filtered or unexported fields
}

func NewRawMessagePayloadManager

func NewRawMessagePayloadManager(logger *zap.Logger, accountPayload *AccountPayload, aesKey []byte, backend *api.GethStatusBackend, keystorePath string) (*RawMessagePayloadManager, error)

func (*RawMessagePayloadManager) Mount

func (r *RawMessagePayloadManager) Mount() error

func (*RawMessagePayloadManager) Receive

func (r *RawMessagePayloadManager) Receive(data []byte) error

func (*RawMessagePayloadManager) ResetPayload

func (r *RawMessagePayloadManager) ResetPayload()

type RawMessageRepository

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

func NewRawMessageRepository

func NewRawMessageRepository(backend *api.GethStatusBackend, keystorePath string, accountPayload *AccountPayload) *RawMessageRepository

func (*RawMessageRepository) LoadFromSource

func (r *RawMessageRepository) LoadFromSource() error

func (*RawMessageRepository) StoreToSource

func (r *RawMessageRepository) StoreToSource() error

type Server

type Server struct {
	server.Server
	PayloadManager
	// contains filtered or unexported fields
}

func MakeFullPairingServer

func MakeFullPairingServer(backend *api.GethStatusBackend, mode Mode, storeConfig *PayloadSourceConfig) (*Server, error)

MakeFullPairingServer generates a fully configured and randomly seeded Server

func NewPairingServer

func NewPairingServer(backend *api.GethStatusBackend, config *Config) (*Server, error)

NewPairingServer returns a *Server init from the given *Config

func (*Server) MakeConnectionParams

func (s *Server) MakeConnectionParams() (*ConnectionParams, error)

MakeConnectionParams generates a *ConnectionParams based on the Server's current state

func (*Server) StartPairing

func (s *Server) StartPairing() error

type SyncRawMessageHandler

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

func NewSyncRawMessageHandler

func NewSyncRawMessageHandler(backend *api.GethStatusBackend) *SyncRawMessageHandler

func (*SyncRawMessageHandler) HandleRawMessage

func (s *SyncRawMessageHandler) HandleRawMessage(account *multiaccounts.Account, password, keystorePath string, payload []byte) error

func (*SyncRawMessageHandler) PrepareRawMessage

func (s *SyncRawMessageHandler) PrepareRawMessage(keyUID string) ([]byte, error)

Jump to

Keyboard shortcuts

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