s2s

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PacketType_name = map[int32]string{
	0: "PacketType_INIT",
	1: "PacketType_INIT_ACK",
	2: "PacketType_COMPLETE",
}
View Source
var PacketType_value = map[string]int32{
	"PacketType_INIT":     0,
	"PacketType_INIT_ACK": 1,
	"PacketType_COMPLETE": 2,
}

Functions

This section is empty.

Types

type Handshaker

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

Handshaker implements the Station to Station handshake protocol.

func NewHandshaker

func NewHandshaker(
	privKey crypto.PrivKey,
	expectedRemotePub crypto.PubKey,
	writePacket func(data []byte) error,
	lookupPubKey func(pid peer.ID) crypto.PubKey,
	initiator bool,
	extraData []byte,
) (*Handshaker, error)

NewHandshaker builds a new handshaker. ExpectedRemotePub speeds up the handshake by indicating an expected remote public key. It can be nil.

func (*Handshaker) Close

func (h *Handshaker) Close()

Close cleans up any resources allocated by the handshake.

func (*Handshaker) Execute

func (h *Handshaker) Execute(ctx context.Context) (*identity.Result, error)

Execute executes the handshake with a context. Initiator indicates the handshaker is the initiator of the handshake. Returning an error cancels the attempt.

func (*Handshaker) Handle

func (h *Handshaker) Handle(data []byte) bool

Handle handles an incoming packet. The buffer is re-used upon return. Returns if another packet is expected.

type Packet

type Packet struct {
	// PacketType is the packet type.
	PacketType PacketType `protobuf:"varint,1,opt,name=packet_type,json=packetType,proto3,enum=s2s.PacketType" json:"packet_type,omitempty"`
	// InitPkt is the init packet.
	InitPkt *Packet_Init `protobuf:"bytes,2,opt,name=init_pkt,json=initPkt,proto3" json:"init_pkt,omitempty"`
	// InitAck is the init-ack packet.
	InitAckPkt *Packet_InitAck `protobuf:"bytes,3,opt,name=init_ack_pkt,json=initAckPkt,proto3" json:"init_ack_pkt,omitempty"`
	// Complete is the complete packet.
	CompletePkt          *Packet_Complete `protobuf:"bytes,4,opt,name=complete_pkt,json=completePkt,proto3" json:"complete_pkt,omitempty"`
	XXX_NoUnkeyedLiteral struct{}         `json:"-"`
	XXX_unrecognized     []byte           `json:"-"`
	XXX_sizecache        int32            `json:"-"`
}

Packet is a handshake packet.

func (*Packet) Descriptor

func (*Packet) Descriptor() ([]byte, []int)

func (*Packet) GetCompletePkt

func (m *Packet) GetCompletePkt() *Packet_Complete

func (*Packet) GetInitAckPkt

func (m *Packet) GetInitAckPkt() *Packet_InitAck

func (*Packet) GetInitPkt

func (m *Packet) GetInitPkt() *Packet_Init

func (*Packet) GetPacketType

func (m *Packet) GetPacketType() PacketType

func (*Packet) ProtoMessage

func (*Packet) ProtoMessage()

func (*Packet) Reset

func (m *Packet) Reset()

func (*Packet) String

func (m *Packet) String() string

func (*Packet) XXX_DiscardUnknown

func (m *Packet) XXX_DiscardUnknown()

func (*Packet) XXX_Marshal

func (m *Packet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Packet) XXX_Merge

func (m *Packet) XXX_Merge(src proto.Message)

func (*Packet) XXX_Size

func (m *Packet) XXX_Size() int

func (*Packet) XXX_Unmarshal

func (m *Packet) XXX_Unmarshal(b []byte) error

type PacketType

type PacketType int32
const (
	// INIT initializes the handshake.
	PacketType_PacketType_INIT PacketType = 0
	// INIT_ACK is the reply to the init.
	PacketType_PacketType_INIT_ACK PacketType = 1
	// COMPLETE is the completion of the handshake.
	PacketType_PacketType_COMPLETE PacketType = 2
)

func (PacketType) EnumDescriptor

func (PacketType) EnumDescriptor() ([]byte, []int)

func (PacketType) String

func (x PacketType) String() string

type Packet_Ciphertext

type Packet_Ciphertext struct {
	// TupleSignature is the signature of the two ephemeral pub keys.
	// The signature is made using the sender's public key.
	// The keys are concatinated as AB
	TupleSignature []byte `protobuf:"bytes,1,opt,name=tuple_signature,json=tupleSignature,proto3" json:"tuple_signature,omitempty"`
	// SenderPubKey contains B's public key if necessary.
	SenderPubKey []byte `protobuf:"bytes,2,opt,name=sender_pub_key,json=senderPubKey,proto3" json:"sender_pub_key,omitempty"`
	// ReceiverKeyKnown indicates that A's public key is known.
	ReceiverKeyKnown bool `protobuf:"varint,3,opt,name=receiver_key_known,json=receiverKeyKnown,proto3" json:"receiver_key_known,omitempty"`
	// ExtraInfo contains extra information supplied by the transport.
	// Example: in UDP this is information about what port to dial KCP on.
	ExtraInfo            []byte   `protobuf:"bytes,4,opt,name=extra_info,json=extraInfo,proto3" json:"extra_info,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Packet_Ciphertext) Descriptor

func (*Packet_Ciphertext) Descriptor() ([]byte, []int)

func (*Packet_Ciphertext) GetExtraInfo

func (m *Packet_Ciphertext) GetExtraInfo() []byte

func (*Packet_Ciphertext) GetReceiverKeyKnown

func (m *Packet_Ciphertext) GetReceiverKeyKnown() bool

func (*Packet_Ciphertext) GetSenderPubKey

func (m *Packet_Ciphertext) GetSenderPubKey() []byte

func (*Packet_Ciphertext) GetTupleSignature

func (m *Packet_Ciphertext) GetTupleSignature() []byte

func (*Packet_Ciphertext) ProtoMessage

func (*Packet_Ciphertext) ProtoMessage()

func (*Packet_Ciphertext) Reset

func (m *Packet_Ciphertext) Reset()

func (*Packet_Ciphertext) String

func (m *Packet_Ciphertext) String() string

func (*Packet_Ciphertext) XXX_DiscardUnknown

func (m *Packet_Ciphertext) XXX_DiscardUnknown()

func (*Packet_Ciphertext) XXX_Marshal

func (m *Packet_Ciphertext) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Packet_Ciphertext) XXX_Merge

func (m *Packet_Ciphertext) XXX_Merge(src proto.Message)

func (*Packet_Ciphertext) XXX_Size

func (m *Packet_Ciphertext) XXX_Size() int

func (*Packet_Ciphertext) XXX_Unmarshal

func (m *Packet_Ciphertext) XXX_Unmarshal(b []byte) error

type Packet_Complete

type Packet_Complete struct {
	// Ciphertext is a Ciphertext message encoded and encrypted with the shared key.
	Ciphertext           []byte   `protobuf:"bytes,1,opt,name=ciphertext,proto3" json:"ciphertext,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Packet_Complete) Descriptor

func (*Packet_Complete) Descriptor() ([]byte, []int)

func (*Packet_Complete) GetCiphertext

func (m *Packet_Complete) GetCiphertext() []byte

func (*Packet_Complete) ProtoMessage

func (*Packet_Complete) ProtoMessage()

func (*Packet_Complete) Reset

func (m *Packet_Complete) Reset()

func (*Packet_Complete) String

func (m *Packet_Complete) String() string

func (*Packet_Complete) XXX_DiscardUnknown

func (m *Packet_Complete) XXX_DiscardUnknown()

func (*Packet_Complete) XXX_Marshal

func (m *Packet_Complete) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Packet_Complete) XXX_Merge

func (m *Packet_Complete) XXX_Merge(src proto.Message)

func (*Packet_Complete) XXX_Size

func (m *Packet_Complete) XXX_Size() int

func (*Packet_Complete) XXX_Unmarshal

func (m *Packet_Complete) XXX_Unmarshal(b []byte) error

type Packet_Init

type Packet_Init struct {
	// SenderPeerID is the peer ID of the sender.
	SenderPeerId []byte `protobuf:"bytes,1,opt,name=sender_peer_id,json=senderPeerId,proto3" json:"sender_peer_id,omitempty"`
	// ReceiverPeerID is the receiver peer ID, if known.
	// If this does not match, the public key is included in the next message.
	ReceiverPeerId []byte `protobuf:"bytes,2,opt,name=receiver_peer_id,json=receiverPeerId,proto3" json:"receiver_peer_id,omitempty"`
	// SenderEphPub is the ephemeral public key of the sender.
	SenderEphPub         []byte   `protobuf:"bytes,3,opt,name=sender_eph_pub,json=senderEphPub,proto3" json:"sender_eph_pub,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Packet_Init) Descriptor

func (*Packet_Init) Descriptor() ([]byte, []int)

func (*Packet_Init) GetReceiverPeerId

func (m *Packet_Init) GetReceiverPeerId() []byte

func (*Packet_Init) GetSenderEphPub

func (m *Packet_Init) GetSenderEphPub() []byte

func (*Packet_Init) GetSenderPeerId

func (m *Packet_Init) GetSenderPeerId() []byte

func (*Packet_Init) ProtoMessage

func (*Packet_Init) ProtoMessage()

func (*Packet_Init) Reset

func (m *Packet_Init) Reset()

func (*Packet_Init) String

func (m *Packet_Init) String() string

func (*Packet_Init) Validate

func (m *Packet_Init) Validate() error

Validate validates the message.

func (*Packet_Init) XXX_DiscardUnknown

func (m *Packet_Init) XXX_DiscardUnknown()

func (*Packet_Init) XXX_Marshal

func (m *Packet_Init) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Packet_Init) XXX_Merge

func (m *Packet_Init) XXX_Merge(src proto.Message)

func (*Packet_Init) XXX_Size

func (m *Packet_Init) XXX_Size() int

func (*Packet_Init) XXX_Unmarshal

func (m *Packet_Init) XXX_Unmarshal(b []byte) error

type Packet_InitAck

type Packet_InitAck struct {
	// SenderEphPub is the ephemeral public key of the sender.
	// This is used to compute the shared secret and decode AckInner.
	SenderEphPub []byte `protobuf:"bytes,1,opt,name=sender_eph_pub,json=senderEphPub,proto3" json:"sender_eph_pub,omitempty"`
	// Ciphertext is a Ciphertext message encoded and encrypted with the shared key.
	Ciphertext           []byte   `protobuf:"bytes,2,opt,name=ciphertext,proto3" json:"ciphertext,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Packet_InitAck) Descriptor

func (*Packet_InitAck) Descriptor() ([]byte, []int)

func (*Packet_InitAck) GetCiphertext

func (m *Packet_InitAck) GetCiphertext() []byte

func (*Packet_InitAck) GetSenderEphPub

func (m *Packet_InitAck) GetSenderEphPub() []byte

func (*Packet_InitAck) ProtoMessage

func (*Packet_InitAck) ProtoMessage()

func (*Packet_InitAck) Reset

func (m *Packet_InitAck) Reset()

func (*Packet_InitAck) String

func (m *Packet_InitAck) String() string

func (*Packet_InitAck) Validate

func (m *Packet_InitAck) Validate() error

Validate validates the init ack packet.

func (*Packet_InitAck) XXX_DiscardUnknown

func (m *Packet_InitAck) XXX_DiscardUnknown()

func (*Packet_InitAck) XXX_Marshal

func (m *Packet_InitAck) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Packet_InitAck) XXX_Merge

func (m *Packet_InitAck) XXX_Merge(src proto.Message)

func (*Packet_InitAck) XXX_Size

func (m *Packet_InitAck) XXX_Size() int

func (*Packet_InitAck) XXX_Unmarshal

func (m *Packet_InitAck) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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