boxstream

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: MIT Imports: 9 Imported by: 3

Documentation

Overview

Package boxstream implements the Secret Handshake and the box stream protocol.

See https://ssbc.github.io/scuttlebutt-protocol-guide/#handshake as well as https://ssbc.github.io/scuttlebutt-protocol-guide/#box-stream.

Index

Constants

View Source
const NetworkKeyLength = 32

NetworkKeyLength is implied to be constant due to an assumption that this key is used as an HMAC key when calling libsodium's crypto_auth during handshakes.

See https://ssbc.github.io/scuttlebutt-protocol-guide/#handshake. See https://doc.libsodium.org/secret-key_cryptography/secret-key_authentication.

Variables

This section is empty.

Functions

This section is empty.

Types

type CurrentTimeProvider

type CurrentTimeProvider interface {
	Get() time.Time
}

type HandshakeResult

type HandshakeResult struct {
	Remote identity.Public

	WriteSecret Key
	WriteNonce  Nonce

	ReadSecret Key
	ReadNonce  Nonce
}

HandshakeResult is created internally by the Handshaker and passed to NewStream.

type Handshaker

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

Handshaker performs the Secret Handshake using the provided ReadWriteCloser.

func NewHandshaker

func NewHandshaker(
	local identity.Private,
	networkKey NetworkKey,
	currentTimeProvider CurrentTimeProvider,
) (Handshaker, error)

NewHandshaker creates a new handshaker which uses the provided local private identity when performing secret handshakes.

func (Handshaker) OpenClientStream

func (h Handshaker) OpenClientStream(rw io.ReadWriteCloser, remote identity.Public) (*Stream, error)

OpenClientStream opens a client stream using the provided identity of the remote peer and the provided ReadWriteCloser. This should be used when initiating a connection with a remote peer.

func (Handshaker) OpenServerStream

func (h Handshaker) OpenServerStream(rw io.ReadWriteCloser) (*Stream, error)

OpenServerStream opens a server stream using the provided ReadWriteCloser. This should be used when handling incoming connections which were initiated by the other party.

type Key

type Key [32]byte

type NetworkKey

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

NetworkKey is used for verifying that two peers are a part of the same Secure Scuttlebutt network in the initial stages of the handshake. Peers using two different network keys will not be able to establish a connection with each other. If you want to use the main Secure Scuttlebutt network then use NewDefaultNetworkKey. Setting a different network key using NewNetworkKey is mainly useful for test networks.

See https://ssbc.github.io/scuttlebutt-protocol-guide/#handshake.

func MustNewNetworkKey

func MustNewNetworkKey(b []byte) NetworkKey

func NewDefaultNetworkKey

func NewDefaultNetworkKey() NetworkKey

NewDefaultNetworkKey creates a key initialized with an arbitrarily chosen value used in the default Secure Scuttlebutt network.

func NewNetworkKey

func NewNetworkKey(b []byte) (NetworkKey, error)

NewNetworkKey creates a network key from the provided slice of bytes. The slice must have a length of NetworkKeyLength.

func (NetworkKey) Bytes

func (k NetworkKey) Bytes() []byte

func (NetworkKey) IsZero

func (k NetworkKey) IsZero() bool

type Nonce

type Nonce [24]byte

type SetDeadliner

type SetDeadliner interface {
	SetDeadline(t time.Time) error
}

type Stream

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

Stream implements the box stream protocol.

func NewStream

func NewStream(rw io.ReadWriteCloser, handshakeResult HandshakeResult) (*Stream, error)

func (Stream) Close

func (s Stream) Close() error

Close writes the goodbye box stream message to the reader and then closes the underlying ReadWriteCloser.

func (*Stream) Read

func (s *Stream) Read(p []byte) (n int, err error)

Read reads the data arriving in the box stream format from the underlying ReadWriteCloser.

func (Stream) Remote

func (s Stream) Remote() identity.Public

Remote returns the identity of the other side of the connection.

func (*Stream) Write

func (s *Stream) Write(p []byte) (int, error)

Write writes the box stream data to the underlying ReadWriteCloser. It will always return 0 as the number of bytes written due to limitations of the underlying implementation.

Jump to

Keyboard shortcuts

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