Documentation ¶
Index ¶
- Constants
- Variables
- func IsHello(x []byte) bool
- func IsInitHello(x []byte) bool
- func IsPostHandshake(x []byte) bool
- func IsRespHello(x []byte) bool
- func PrettyPrint(msg Message) string
- type Channel
- func (c *Channel) Close() error
- func (c *Channel) Deliver(out, x []byte) ([]byte, error)
- func (c *Channel) LastReceived() time.Time
- func (c *Channel) LastSent() time.Time
- func (c *Channel) LocalKey() x509.PublicKey
- func (c *Channel) RemoteKey() x509.PublicKey
- func (c *Channel) Send(ctx context.Context, x p2p.IOVec) error
- func (c *Channel) WaitReady(ctx context.Context) error
- type ChannelConfig
- type Direction
- type ErrDecryptionFailure
- type ErrEarlyData
- type ErrSessionExpired
- type InitDone
- type InitHello
- func (*InitHello) Descriptor() ([]byte, []int)deprecated
- func (x *InitHello) GetKeyX509() []byte
- func (x *InitHello) GetSig() []byte
- func (x *InitHello) GetTimestampTai64N() []byte
- func (x *InitHello) GetVersion() uint32
- func (*InitHello) ProtoMessage()
- func (x *InitHello) ProtoReflect() protoreflect.Message
- func (x *InitHello) Reset()
- func (x *InitHello) String() string
- type Message
- type RespHello
- type SendFunc
- type Session
- func (s *Session) Deliver(out []byte, incoming []byte, now time.Time) (bool, []byte, error)
- func (s *Session) ExpiresAt() time.Time
- func (s *Session) Handshake(out []byte) []byte
- func (s *Session) InitHelloTime() tai64.TAI64N
- func (s *Session) IsInit() bool
- func (s *Session) IsReady() bool
- func (s *Session) LocalKey() x509.PublicKey
- func (s *Session) RemoteKey() x509.PublicKey
- func (s *Session) Send(out, ptext []byte, now time.Time) ([]byte, error)
- func (s *Session) String() string
- type SessionConfig
- type Timer
Constants ¶
const ( // Overhead is the per message overhead taken up by P2PKE. Overhead = 4 + 16 // MaxMessageLen is the maximum message size that applications can send through the channel. MaxMessageLen = noise.MaxMsgLen - Overhead // MaxNonce is the maxmium number of messages that can be sent through a channel. MaxNonce = math.MaxUint32 - 1 // RekeyAfterTime is the default. RekeyAfterTime = 120 * time.Second // RejectAfterTime is the default. RejectAfterTime = 180 * time.Second // RekeyAfterMessages is the number of messages that can be sent over a session before a rekey is triggered. RekeyAfterMessages = MaxNonce / 2 // KeepAliveTimeout is the default. KeepAliveTimeout = 15 * time.Second // HandshakeBackoff is the default. HandshakeBackoff = 250 * time.Millisecond )
const ( InitToResp = Direction(iota) RespToInit )
Variables ¶
var File_p2pke_proto protoreflect.FileDescriptor
Functions ¶
func IsInitHello ¶
IsInitHello returns true if x contains an InitHello message
func IsPostHandshake ¶
func IsRespHello ¶
IsRespHello returns true if x contains a RespHello message
func PrettyPrint ¶
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
func NewChannel ¶
func NewChannel(params ChannelConfig) *Channel
func (*Channel) Close ¶
Close releases all resources associated with the channel. send will not be called after Close completes.
func (*Channel) Deliver ¶
Deliver decrypts the payload in x if it contains application data, and appends it to out. if err != nil, then an error occured. The Channel is capable of recovering. if out != nil, then it is application data. if out == nil, then the message was either invalid or contained a handshake message and there is nothing more for the caller to do.
e.g. out, err := c.Deliver(nil, input)
if err != nil { // handle the error } else if out != nil { // deliver application data } else { // nothing to do }
func (*Channel) LastReceived ¶
LastReceived returns the time that a message was received
func (*Channel) LocalKey ¶
LocalKey returns the public key used by the local party to authenticate. It will correspond to the private key passed to NewChannel.
func (*Channel) RemoteKey ¶
RemoteKey returns the public key used by the remote party to authenticate. It can be nil, if there has been no successful handshake.
type ChannelConfig ¶
type ChannelConfig struct { Registry x509.Registry // PrivateKey is the signing key used to prove identity to the other party in the channel. // *REQUIRED* PrivateKey x509.PrivateKey // Send is used to send p2pke protocol messages including ciphertexts and handshake messages. // *REQUIRED* Send SendFunc // AcceptKey is used to check if a key is allowed before connecting // *REQUIRED*. AcceptKey func(*x509.PublicKey) bool // Logger is used for logging, nil disables logs. Logger *zap.Logger // KeepAliveTimeout is the amount of time to consider a session alive wihtout receiving a message // through it. KeepAliveTimeout time.Duration // HandshakeBackoff is the amount of time to wait between sending handshake messages. HandshakeBackoff time.Duration // RekeyAfterTime is the amount of time between rekeying a session. RekeyAfterTime time.Duration // RejectAfterTime is the duration after session creation when the session will send and // received messages. RejectAfterTime time.Duration }
type ErrDecryptionFailure ¶
ErrDecryptionFailure is returned by a Session when a message failed to decrypt.
func (ErrDecryptionFailure) Error ¶
func (e ErrDecryptionFailure) Error() string
type ErrEarlyData ¶
ErrEarlyData is returned by the session when application data arrives early. There is no way to verify this data without a
func (ErrEarlyData) Error ¶
func (e ErrEarlyData) Error() string
type ErrSessionExpired ¶
ErrSessionExpired is returned when the session is too old to be used anymore and needs to be put down.
func (ErrSessionExpired) Error ¶
func (e ErrSessionExpired) Error() string
type InitDone ¶
type InitDone struct { Sig []byte `protobuf:"bytes,1,opt,name=sig,proto3" json:"sig,omitempty"` // contains filtered or unexported fields }
func (*InitDone) Descriptor
deprecated
func (*InitDone) ProtoMessage ¶
func (*InitDone) ProtoMessage()
func (*InitDone) ProtoReflect ¶
func (x *InitDone) ProtoReflect() protoreflect.Message
type InitHello ¶
type InitHello struct { Version uint32 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` TimestampTai64N []byte `protobuf:"bytes,2,opt,name=timestamp_tai64n,json=timestampTai64n,proto3" json:"timestamp_tai64n,omitempty"` KeyX509 []byte `protobuf:"bytes,3,opt,name=key_x509,json=keyX509,proto3" json:"key_x509,omitempty"` Sig []byte `protobuf:"bytes,4,opt,name=sig,proto3" json:"sig,omitempty"` // contains filtered or unexported fields }
func (*InitHello) Descriptor
deprecated
func (*InitHello) GetKeyX509 ¶
func (*InitHello) GetTimestampTai64N ¶
func (*InitHello) GetVersion ¶
func (*InitHello) ProtoMessage ¶
func (*InitHello) ProtoMessage()
func (*InitHello) ProtoReflect ¶
func (x *InitHello) ProtoReflect() protoreflect.Message
type RespHello ¶
type RespHello struct { KeyX509 []byte `protobuf:"bytes,1,opt,name=key_x509,json=keyX509,proto3" json:"key_x509,omitempty"` Sig []byte `protobuf:"bytes,2,opt,name=sig,proto3" json:"sig,omitempty"` // contains filtered or unexported fields }
func (*RespHello) Descriptor
deprecated
func (*RespHello) GetKeyX509 ¶
func (*RespHello) ProtoMessage ¶
func (*RespHello) ProtoMessage()
func (*RespHello) ProtoReflect ¶
func (x *RespHello) ProtoReflect() protoreflect.Message
type SendFunc ¶
type SendFunc func([]byte)
SendFunc is the type of functions called to send messages by the channel.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
func NewSession(params SessionConfig) *Session
func (*Session) Deliver ¶
Deliver gives the session a message. If there is data in the message it will be returned as a non nil slice, appended to out. If there is not data, then a nil slice, and nil error will be returned.
isApp, out, err := s.Deliver(out, incoming, now)
if err != nil { // handle err }
if !isApp && len(out) > 0 {
} else if isApp {
}
func (*Session) Handshake ¶
Handshake appends the current handshake message to out. Handshake returns nil if there is no handshake message to send.