com

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: GPL-3.0 Imports: 14 Imported by: 1

Documentation

Overview

Package com contains many helper functions for network communications. This package includes some constant types that can be used with the "c2" package.

Index

Constants

View Source
const (
	// FlagFrag is a flag used to indicate that the packet is part of a
	// fragment group and the server should re-assemble the packet before
	// preforming actions on it.
	FlagFrag = 1 << iota
	// FlagMulti is a flag used to indicate that the packet is a container
	// for multiple packets, auto added by a processing agent. This Flag also
	// carries the 'FlagFrag' flag.
	FlagMulti
	// FlagProxy is a flag used to indicate that the packet was sent from another
	// client acting as a forwarding proxy.
	FlagProxy
	// FlagError is a flag used to indicate that the packet indicates that an error
	// condition has occurred. The contents of the Packet can be used to
	// understand the error cause.
	FlagError
	// FlagChannel is a flag used to signify that the connection should be converted
	// into/from a single channel connection. This means that the connection is
	// kept alive and the client will not poll the server.
	//
	// This flag will be present on the top level multi-packet if included in a
	// single packet inside. This flag will take effect on each hop that it goes
	// through.
	//
	// Incompatible with 'FlagOneshot'. Can only be used once per single connection.
	FlagChannel
	// FlagChannelEnd is a flag used to signify that a Channel connection should
	// be terminated. Unlike the 'FlagChannel' option, this will only affect the
	// targeted hop.
	//
	// Incompatible with 'FlagOneshot'. Can only be used once per single connection.
	FlagChannelEnd
	// FlagOneshot is used to signal that the Packet contains information and
	// should not be used to create or re-establish a session.
	FlagOneshot
	// FlagMultiDevice is used to determine if the Multi packet contains Packets
	// with separate device IDs. This is used to speed up processing and allows
	// packets that are all destined for the same host to be batch processed.
	FlagMultiDevice
	// FlagCrypt is used to indicate that the Packet is carrying Crypt related
	// information or a side of the conversation is asking for a re-key.
	FlagCrypt
)
View Source
const (
	// PacketMaxTags is the max amount of tags that are allowed on a specific
	// Packet. If the amount of tags exceed this limit, an error will occur
	// doing writing.
	PacketMaxTags = 2 << 14
	// PacketHeaderSize is the length of the Packet header in bytes.
	PacketHeaderSize = 46
)
View Source
const (
	NameIP   = "ip"
	NameTCP  = "tcp"
	NameUDP  = "udp"
	NamePipe = "pipe"
	NameUnix = "unix"
	NameHTTP = "http"
)

Named Network Constants

View Source
const DefaultTimeout = time.Second * 15 // 30

DefaultTimeout is the default timeout used for the default connectors. The default is 15 seconds.

Variables

View Source
var (
	// TCP is the TCP Raw connector. This connector uses raw TCP connections for
	// communication.
	TCP = NewTCP(DefaultTimeout)

	// UDP is the UDP Raw connector. This connector uses raw UDP connections for
	// communication.
	UDP = NewUDP(DefaultTimeout)

	// ICMP is the ICMP Raw connector. This connector uses raw ICMP connections
	// for communication.
	//
	// TODO(dij): I think ICMP is bugged ATM, "NewIP(<anything greater than 1>, DefaultTimeout)" works, weird.
	ICMP = NewIP(DefaultTimeout, 1)

	// TLS is the TCP over TLS connector client. This client uses TCP wrapped in
	// TLS encryption using certificates.
	//
	// This client is only valid for clients that connect to servers with properly
	// signed and trusted certificates.
	TLS = tcpClient{/* contains filtered or unexported fields */}

	// TLSInsecure is the TCP over TLS connector profile. This client uses TCP
	// wrapped in TLS encryption using certificates.
	//
	// This instance DOES NOT check the server certificate for validity.
	TLSInsecure = tcpClient{/* contains filtered or unexported fields */}
)
View Source
var ErrInvalidTLSConfig = xerr.Sub("invalid or missing TLS certificates", 0x2D)

ErrInvalidTLSConfig is returned when attempting to use the default TLS Connector as a listener. This error is also returned when attempting to use a TLS configuration that does not have a valid server certificates.

View Source
var ErrMalformedTag = xerr.Sub("malformed Tag", 0x2A)

ErrMalformedTag is an error returned when a read on a Packet Tag returns an empty (zero) tag value.

View Source
var ListenConfig = newListenConfig(DefaultTimeout)

ListenConfig is the default listener config that is used to generate the Listeners. This can be used to specify the listen 'KeepAlive' timeout.

Functions

func DialTCP added in v0.1.0

func DialTCP(x context.Context, s string) (net.Conn, error)

DialTCP is a quick utility function that can be used to quickly create a TCP connection to the provided address.

This function uses the 'com.TCP' var.

func DialTLS added in v0.1.0

func DialTLS(x context.Context, s string, c *tls.Config) (net.Conn, error)

DialTLS is a quick utility function that can be used to quickly create a TLS connection to the provided address.

func ListenTCP added in v0.1.0

func ListenTCP(x context.Context, s string) (net.Listener, error)

ListenTCP is a quick utility function that can be used to quickly create a TCP listener using the 'TCP' Acceptor.

func ListenTLS added in v0.1.0

func ListenTLS(x context.Context, s string, c *tls.Config) (net.Listener, error)

ListenTLS is a quick utility function that can be used to quickly create a TLS listener using the provided TLS config.

func NewTLSConfig added in v0.1.0

func NewTLSConfig(mu bool, ver uint16, ca, pem, key []byte) (*tls.Config, error)

NewTLSConfig generates a new 'tls.Config' struct from the provided TLS details. This can be used to generate mTLS or just simple CA-based TLS server/clients Connectors.

The provided ca bytes (in PEM format) can be used to validate client certificates while the pem and key bytes (in PEM format) are used for the listening socket.

The 'ver' integer represents the TLS-min version requirement. Setting it to zero will default to TLSv1. SSLv3 is NOT SUPPORTED!

This function returns an error if the ca, pem and/or key are empty. The 'mu' bool will determine if mTLS should be enforced.

mTLS insights sourced from: https://kofo.dev/how-to-mtls-in-golang

func SetListenerDeadline added in v0.1.0

func SetListenerDeadline(l net.Listener, t time.Time) error

SetListenerDeadline attempts to set a deadline on the 'Accept; function of a Listener if applicable. This function will return any errors if they occur and always returns 'nil' if the Listener does not support deadlines.

Types

type Connector

type Connector interface {
	Connect(context.Context, string) (net.Conn, error)
	Listen(context.Context, string) (net.Listener, error)
}

Connector is an interface that represents an object that can create and establish connections on various protocols.

func NewIP

func NewIP(t time.Duration, p byte) Connector

NewIP creates a new simple IP based connector with the supplied timeout and protocol number.

func NewTCP

func NewTCP(t time.Duration) Connector

NewTCP creates a new simple TCP based connector with the supplied timeout.

func NewTLS added in v0.1.0

func NewTLS(t time.Duration, c *tls.Config) Connector

NewTLS creates a new simple TLS wrapped TCP based connector with the supplied timeout.

func NewUDP

func NewUDP(t time.Duration) Connector

NewUDP creates a new simple UDP based connector with the supplied timeout.

type Flag

type Flag uint64

Flag is a bitwise integer that represents important information about the packet that it's assigned to.

Mapping

| 64     56        48        40        32        24        16         8       0 |
| ----------------- | ----------------- | ----------------- | ----------------- |
| 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 |
|    Frag Total     |   Frag Position   |   Frag Group ID   |       Flags       |
|                         Frag Data                         |                   |

func (*Flag) Clear

func (f *Flag) Clear()

Clear clears all Frag and Multi related data values.

func (Flag) Group

func (f Flag) Group() uint16

Group returns the fragment group ID that this packet is part of.

func (Flag) Len

func (f Flag) Len() uint16

Len returns the count of fragmented packets that make up this fragment group.

func (Flag) MarshalStream

func (f Flag) MarshalStream(w data.Writer) error

MarshalStream writes the data of this Flag to the supplied Writer.

func (Flag) Position

func (f Flag) Position() uint16

Position represents position of this packet in a fragment group.

func (*Flag) Set

func (f *Flag) Set(n Flag)

Set appends the Flag value to this current Flag value.

func (*Flag) SetGroup

func (f *Flag) SetGroup(n uint16)

SetGroup sets the group ID of the fragment group this packet is part of.

func (*Flag) SetLen

func (f *Flag) SetLen(n uint16)

SetLen sets the total count of packets in the fragment group.

func (*Flag) SetPosition

func (f *Flag) SetPosition(n uint16)

SetPosition sets the position this packet is located in the fragment group.

func (Flag) String

func (f Flag) String() string

String returns a character representation of this Flag.

func (*Flag) UnmarshalStream

func (f *Flag) UnmarshalStream(r data.Reader) error

UnmarshalStream reads the data of this Flag from the supplied Reader.

func (*Flag) Unset

func (f *Flag) Unset(n Flag)

Unset removes the Flag value to this current Flag value.

type Packet

type Packet struct {
	Tags []uint32
	data.Chunk

	Flags Flag
	Job   uint16

	Device device.ID
	ID     uint8
	// contains filtered or unexported fields
}

Packet is a struct that is a Reader and Writer that can be generated to be sent, or received from a Connection.

Acts as a data buffer and 'parent' of 'data.Chunk'.

func (*Packet) Add

func (p *Packet) Add(n *Packet) error

Add attempts to combine the data and properties the supplied Packet with the existing Packet. This function will return an error if the ID's have a mismatch or there was an error during the write operation.

func (*Packet) Belongs

func (p *Packet) Belongs(n *Packet) bool

Belongs returns true if the specified Packet is a Frag that was a part of the split Chunks of this as the original packet.

func (*Packet) Marshal added in v0.1.0

func (p *Packet) Marshal(w io.Writer) error

Marshal will attempt to write this Packet's data and headers to the specified Writer. This function will return any errors that have occurred during writing.

func (*Packet) MarshalStream

func (p *Packet) MarshalStream(w data.Writer) error

MarshalStream writes the data of this Packet to the supplied Writer.

func (*Packet) Size

func (p *Packet) Size() int

Size returns the amount of bytes written or contained in this Packet with the header size added.

func (Packet) String

func (p Packet) String() string

String returns a string descriptor of the Packet struct.

func (*Packet) Unmarshal added in v0.1.0

func (p *Packet) Unmarshal(r io.Reader) error

Unmarshal will attempt to read Packet data and headers from the specified Reader. This function will return any errors that have occurred during reading.

func (*Packet) UnmarshalStream

func (p *Packet) UnmarshalStream(r data.Reader) error

UnmarshalStream reads the data of this Packet from the supplied Reader.

Directories

Path Synopsis
Package limits contains many options for setting Global limits on how the overall application behaves.
Package limits contains many options for setting Global limits on how the overall application behaves.
Package pipe contains a cross-device compatable Pipes/NamedPipes connection interface.
Package pipe contains a cross-device compatable Pipes/NamedPipes connection interface.
Package wc2 contains a HTTP/Web based communication channel, which follows the Golang 'net.Conn' interface and is very configurable.
Package wc2 contains a HTTP/Web based communication channel, which follows the Golang 'net.Conn' interface and is very configurable.

Jump to

Keyboard shortcuts

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