networking

package module
v0.0.0-...-54883c6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2020 License: GPL-2.0 Imports: 20 Imported by: 0

README

Shine Engine Networking

TCP Networking and decoding and decrypting of packets from inbound or outbound connections. To be used in all the Shine Engine services or packet sniffers.


CircleCI Go Report Card

This project has dependencies on the modules:

If changes are needed on these modules, append to the file go.mod:

replace github.com/shine-o/shine.engine.structs => C:\Users\marbo\go\src\github.com\shine-o\shine.engine.structs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PacketBoundary

func PacketBoundary(offset int, data []byte) (int, string)

PacketBoundary of a packet in a data segment Shine packets can be small or big small packets specify the length in the first byte big packets ignore the first byte (that is, is 0 value), and set the length in the next 2 bytes the data segment is usually a local variable in a goroutine

func RandomXorKey

func RandomXorKey() uint16

RandomXorKey generate a random number between 0 and the defined xorLimit

func ReadBinary

func ReadBinary(data []byte, nc interface{}) error

ReadBinary data into a given struct if struct size is bigger than available data, fill with zeros

func WriteBinary

func WriteBinary(nc interface{}) ([]byte, error)

WriteBinary data into a given struct and return bytes

func WriteToClient

func WriteToClient(ctx context.Context, pc *Command)

WriteToClient data all shine service handlers will call this function to write data to the TCP client the TCP connection object is stored in the context

func XorCipher

func XorCipher(data []byte, xorPos *uint16)

XorCipher decrypt bytes using captured xorKey and xorTable

Types

type Command

type Command struct {
	Base CommandBase // common data in every command, like operation code and length
	//NcStruct interface{} // any kind of structure that is the representation in bytes of the network packet
	NcStruct structs.NC // any kind of structure that is the representation in bytes of the network packet
}

Command type used to unmarshal data from the protocol commands file

func DecodePacket

func DecodePacket(pType string, pLen int, data []byte) (Command, error)

DecodePacket data into a struct

func (*Command) Send

func (pc *Command) Send(ctx context.Context)

type CommandBase

type CommandBase struct {
	PacketType       string
	Length           int
	Department       uint16
	Command          uint16
	OperationCode    uint16
	ClientStructName string
	Data             []byte
}

CommandBase type used to store decoded data from a packet

func (*CommandBase) PacketLength

func (pcb *CommandBase) PacketLength() int

PacketLength of a packet, which includes de operation code bytes

func (*CommandBase) RawData

func (pcb *CommandBase) RawData() []byte

RawData of a packet that contains the length, operation code and packet data

func (*CommandBase) String

func (pcb *CommandBase) String() string

type ContextKey

type ContextKey int

ContextKey identifier for values of common use within the Context

const (
	// XorOffset indicates what offset in the xor hex table to use to start decrypting client data
	XorOffset ContextKey = iota
	// ShineSession if used, shine service can access session data within their handler's context
	ShineSession
	// ConnectionWriter is a utility struct which contains the tcp connection object and a mutex
	// it is used to write data to the client from any shine service handler
	ConnectionWriter
)

type Department

type Department struct {
	HexID             string `yaml:"hexId"`
	Name              string `yaml:"name"`
	RawCommands       string `yaml:"commands"`
	ProcessedCommands map[string]string
}

Department type used to unmarshal data from the protocol commands file

type HandleWarden

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

HandleWarden utility struct for triggering functions implemented by the calling shine service

func NewHandlerWarden

func NewHandlerWarden(customHandlers map[uint16]func(ctx context.Context, command *Command)) *HandleWarden

NewHandlerWarden handlers are callbacks to be called when an operationCode is detected in a packet.

type PCList

type PCList struct {
	Departments map[uint8]Department
	// contains filtered or unexported fields
}

PCList protocol command list friendly names for each Department and Commands within a Department

func InitCommandList

func InitCommandList(filePath string) (PCList, error)

InitCommandList from protocol commands file

type RawPCList

type RawPCList struct {
	Departments []Department `yaml:"departments,flow"`
}

RawPCList struct used to unmarshal the protocol commands file

type Session

type Session interface {
	Identifier() string
}

Session type for the shine service to implement if it needs session data

type SessionFactory

type SessionFactory interface {
	New() Session
}

SessionFactory type for the shine service to implement if it needs session data

type Settings

type Settings struct {
	// xor hex table used to encrypt data on the client side, we use it here to decrypt data sent by the client
	XorKey []byte
	// xor hex table has a limit, when that limit is reached, while decrypting, we start from offset 0 of the xor hex table
	XorLimit uint16
	// operation codes are the result of bit operation on the Department (category) and Command (category item) values on the client side
	// each Department has a DN and each Command has a a FQDN
	// the FQDN of a Command is used to give useful info about a detected packet
	CommandsFilePath string
}

Settings for decoding the packets detected by this library

func (*Settings) Set

func (s *Settings) Set()

Set Settings specified by the shine service

type ShineService

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

ShineService to be used by the calling shine service to:

  1. configure the settings for TCP socket
  2. assign the handlers for the operation codes handled by the shine service
  3. use session factory specific to the shine service to create a session object in the context of each TCP connection

func NewShineService

func NewShineService(s *Settings, hw *HandleWarden) *ShineService

NewShineService create new, the calling shine service must configure Settings and a HandlerWarden

func (*ShineService) Listen

func (ss *ShineService) Listen(ctx context.Context, port string)

Listen on TPC socket for connection on given port

func (*ShineService) UseSessionFactory

func (ss *ShineService) UseSessionFactory(sf SessionFactory)

UseSessionFactory given by the shine service

Directories

Path Synopsis
auxiliar structs and functions for Network Commands
auxiliar structs and functions for Network Commands

Jump to

Keyboard shortcuts

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