pairing

package
v0.138.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

Variables

View Source
var (
	ErrKeyFileAlreadyExists       = errors.New("key file already exists")
	ErrKeyUIDEmptyAsSender        = errors.New("keyUID must be provided as sender")
	ErrNodeConfigNilAsReceiver    = errors.New("node config must be provided as receiver")
	ErrPayloadSourceConfigBothSet = errors.New("payloadSourceSenderConfig and payloadSourceReceiverConfig cannot be both set")
	ErrLoggedInKeyUIDConflict     = errors.New("logged in keyUID not same as keyUID in payload")
)

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.

func ValidateConnectionString added in v0.131.7

func ValidateConnectionString(cs string) error

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
	// only used for the receiver side
	LoggedInKeyUID string
}

AccountPayloadManagerConfig represents the initialisation parameters required for a AccountPayloadManager

func (*AccountPayloadManagerConfig) GetDeviceType added in v0.134.0

func (a *AccountPayloadManagerConfig) GetDeviceType() string

func (*AccountPayloadManagerConfig) GetKeystorePath added in v0.131.10

func (a *AccountPayloadManagerConfig) GetKeystorePath() string

func (*AccountPayloadManagerConfig) GetNodeConfig added in v0.131.10

func (a *AccountPayloadManagerConfig) GetNodeConfig() *params.NodeConfig

func (*AccountPayloadManagerConfig) GetPayloadSourceReceiverConfig added in v0.131.10

func (a *AccountPayloadManagerConfig) GetPayloadSourceReceiverConfig() *PayloadSourceReceiverConfig

func (*AccountPayloadManagerConfig) GetPayloadSourceSenderConfig added in v0.131.10

func (a *AccountPayloadManagerConfig) GetPayloadSourceSenderConfig() *PayloadSourceSenderConfig

func (*AccountPayloadManagerConfig) GetSettingCurrentNetwork added in v0.131.10

func (a *AccountPayloadManagerConfig) GetSettingCurrentNetwork() string

func (*AccountPayloadManagerConfig) GetTimeout added in v0.131.10

func (a *AccountPayloadManagerConfig) GetTimeout() uint

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) PairInstallation added in v0.134.0

func (c *Client) PairInstallation() error

PairInstallation transfer installation data from receiver to sender. installation data from sender to receiver already processed within PairSyncDevice method on the receiver side.

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"`
	Data   any       `json:"data,omitempty"`
}

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"

	EventReceivedAccount EventType = "received-account"
	EventProcessSuccess  EventType = "process-success"
	EventProcessError    EventType = "process-error"
)

type InstallationPayloadManager added in v0.134.0

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

func NewInstallationPayloadManager added in v0.134.0

func NewInstallationPayloadManager(logger *zap.Logger, aesKey []byte, backend *api.GethStatusBackend, deviceType string) (*InstallationPayloadManager, error)

func (*InstallationPayloadManager) Mount added in v0.134.0

func (i *InstallationPayloadManager) Mount() error

func (*InstallationPayloadManager) Receive added in v0.134.0

func (i *InstallationPayloadManager) Receive(data []byte) error

func (*InstallationPayloadManager) ResetPayload added in v0.134.0

func (i *InstallationPayloadManager) ResetPayload()

type InstallationPayloadRepository added in v0.134.0

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

func NewInstallationPayloadRepository added in v0.134.0

func NewInstallationPayloadRepository(backend *api.GethStatusBackend, deviceType string) *InstallationPayloadRepository

func (*InstallationPayloadRepository) LoadFromSource added in v0.134.0

func (r *InstallationPayloadRepository) LoadFromSource() error

func (*InstallationPayloadRepository) StoreToSource added in v0.134.0

func (r *InstallationPayloadRepository) StoreToSource() 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 for sender and receiver, there are some different cases:
	// 1. for sender, KeystorePath must end with keyUID
	// 2. for receiver, KeystorePath must not end with keyUID (because keyUID is not known yet)
	KeystorePath string `json:"keystorePath"`
	// required for sender and receiver, SendPairInstallation need this information
	DeviceType string `json:"deviceType"`
	*PayloadSourceSenderConfig
	*PayloadSourceReceiverConfig
	// Timeout the number of milliseconds after which the pairing server will automatically terminate
	Timeout uint `json:"timeout"`
}

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

func NewPayloadSourceForClient added in v0.131.10

func NewPayloadSourceForClient(configJSON string, mode Mode) (*PayloadSourceConfig, error)

func NewPayloadSourceForServer added in v0.131.10

func NewPayloadSourceForServer(configJSON string, mode Mode) (*PayloadSourceConfig, error)

type PayloadSourceReceiverConfig added in v0.131.10

type PayloadSourceReceiverConfig struct {
	KDFIterations int `json:"kdfIterations"`
	NodeConfig    *params.NodeConfig
	// this field already exists within params.NodeConfig, but it doesn't support json marshalling, so we need to duplicate it here
	RootDataDir string
	// corresponding to field current_network from table settings, so that we can override current network from sender
	SettingCurrentNetwork string
}

type PayloadSourceSenderConfig added in v0.131.10

type PayloadSourceSenderConfig struct {
	KeyUID   string `json:"keyUID"`
	Password string `json:"password"`
}

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, nodeConfig *params.NodeConfig, settingCurrentNetwork, deviceType 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, accountPayload *AccountPayload, config *params.NodeConfig, settingCurrentNetwork, deviceType string) *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) CollectInstallationData added in v0.134.0

func (s *SyncRawMessageHandler) CollectInstallationData(rawMessageCollector *RawMessageCollector, deviceType string) error

func (*SyncRawMessageHandler) HandleRawMessage

func (s *SyncRawMessageHandler) HandleRawMessage(accountPayload *AccountPayload, nodeConfig *params.NodeConfig, settingCurrentNetwork, deviceType string, rawMessagePayload []byte) error

func (*SyncRawMessageHandler) PrepareRawMessage

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

Jump to

Keyboard shortcuts

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