mysql

package
v2.2.0-alpha18 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

README

MySQL Package Documentation

The mysqlparser package encompasses the parser and mapping logic required to read MySql binary messages and capture and test the outputs. Utilized by the hooks package, it assists in redirecting outgoing calls for the purpose of recording or testing the outputs.

SSL Support

Please note that SSL is currently not supported in the MySQL package. To use the package without SSL, you can include the following parameters in your database URL like the following example:

jdbc:mysql://localhost:3306/db_name?useSSL=false&allowPublicKeyRetrieval=true

The following MySQL packet types are handled in the parser:

COM_PING: A ping command sent to the server to check if it's alive and responsive.

COM_STMT_EXECUTE: Executes a prepared statement that was prepared using the COM_STMT_PREPARE command.

COM_STMT_FETCH: Fetches rows from a statement which produced a result set. Used with cursors in server-side prepared statements.

COM_STMT_PREPARE: Prepares a SQL statement for execution.

COM_STMT_CLOSE: Closes a prepared statement, freeing up server resources associated with it.

COM_CHANGE_USER: Changes the user of the current connection and resets the connection state.

MySQLOK: A packet indicating a successful operation. It is usually received after commands like INSERT, UPDATE, DELETE, etc.

MySQLErr: An error packet sent from the server to the client, indicating an error occurred with the last command sent.

RESULT_SET_PACKET: Contains the actual result set data returned by a query. It's a series of packets containing rows and columns of data.

MySQLHandshakeV10: The initial handshake packet sent from the server to the client when a connection is established, containing authentication and connection details.

HANDSHAKE_RESPONSE: The response packet sent by the client in reply to MySQLHandshakeV10, containing client authentication data.

MySQLQuery: Contains a SQL query that is to be executed on the server.

AUTH_SWITCH_REQUEST: Sent by the server to request an authentication method switch during the connection process.

AUTH_SWITCH_RESPONSE: Sent by the client to respond to the AUTH_SWITCH_REQUEST, containing authentication data.

MySQLEOF: An EOF (End Of File) packet that marks the end of a result set or the end of the fields list.

AUTH_MORE_DATA: Sent by the server if it needs more data for authentication (used in plugins).

COM_STMT_SEND_LONG_DATA: Sends data for a column in a row to be inserted/updated in a table using a prepared statement.

COM_STMT_RESET: Resets the data of a prepared statement which was accumulated with COM_STMT_SEND_LONG_DATA commands.

COM_QUIT: Sent by the client to close the connection to the server gracefully.

Documentation

Overview

Package mysql provides integration with MySQL outgoing.

Index

Constants

View Source
const (
	// CLIENT_PLUGIN_AUTH indicates that the client supports plugin authentication.
	CLIENT_PLUGIN_AUTH = 0x00080000
	// CLIENT_CONNECT_WITH_DB indicates that client is connecting to server with database name.
	CLIENT_CONNECT_WITH_DB = 0x00000008
	// CLIENT_CONNECT_ATTRS indicates that the client supports connection attributes.
	CLIENT_CONNECT_ATTRS = 0x00100000
	// CLIENT_ZSTD_COMPRESSION_ALGORITHM indicates support for Zstandard compression algorithm
	CLIENT_ZSTD_COMPRESSION_ALGORITHM = 0x00010000
)

Variables

This section is empty.

Functions

func NewMySQL

func NewMySQL(logger *zap.Logger) integrations.Integrations

func Uint24

func Uint24(data []byte) uint32

Types

type AuthSwitchRequestPacket

type AuthSwitchRequestPacket struct {
	StatusTag      byte   `yaml:"status_tag"`
	PluginName     string `yaml:"plugin_name"`
	PluginAuthData string `yaml:"plugin_authdata"`
}

type AuthSwitchResponsePacket

type AuthSwitchResponsePacket struct {
	AuthResponseData string `yaml:"auth_response_data"`
}

type BoundParameter

type BoundParameter struct {
	Type     byte   `yaml:"type"`
	Unsigned byte   `yaml:"unsigned"`
	Value    []byte `yaml:"value,omitempty,flow"`
}

type COM_STMT_RESET

type COM_STMT_RESET struct {
	StatementID uint32 `yaml:"statement_id"`
}

type COM_STMT_SEND_LONG_DATA

type COM_STMT_SEND_LONG_DATA struct {
	StatementID uint32 `yaml:"statement_id"`
	ParameterID uint16 `yaml:"parameter_id"`
	Data        []byte `yaml:"data,omitempty,flow"`
}

type CapabilityFlags

type CapabilityFlags uint32

type ComChangeUserPacket

type ComChangeUserPacket struct {
	User         string `yaml:"user"`
	Auth         []byte `yaml:"auth,omitempty,flow"`
	Db           string `yaml:"db"`
	CharacterSet uint8  `yaml:"character_set"`
	AuthPlugin   string `yaml:"auth_plugin"`
}

type ComInitDbPacket

type ComInitDbPacket struct {
	Status byte
	DbName string
}

type ComPingPacket

type ComPingPacket struct {
}

type ComStmtCloseAndPrepare

type ComStmtCloseAndPrepare struct {
	StmtClose   ComStmtClosePacket
	StmtPrepare ComStmtPreparePacket1
}

type ComStmtClosePacket

type ComStmtClosePacket struct {
	Status      byte
	StatementID uint32
}

type ComStmtExecute

type ComStmtExecute struct {
	StatementID    uint32           `yaml:"statement_id"`
	Flags          byte             `yaml:"flags"`
	IterationCount uint32           `yaml:"iteration_count"`
	NullBitmap     []byte           `yaml:"null_bitmap,omitempty,flow"`
	ParamCount     uint16           `yaml:"param_count"`
	Parameters     []BoundParameter `yaml:"parameters,omitempty,flow"`
}

type ComStmtFetchPacket

type ComStmtFetchPacket struct {
	StatementID uint32 `yaml:"statement_id"`
	RowCount    uint32 `yaml:"row_count"`
	Info        string `yaml:"info"`
}

type ComStmtPreparePacket

type ComStmtPreparePacket struct {
	Query string
}

type ComStmtPreparePacket1

type ComStmtPreparePacket1 struct {
	Header []byte
	Query  string
}

type EOFPacket

type EOFPacket struct {
	Header      byte   `yaml:"header"`
	Warnings    uint16 `yaml:"warnings"`
	StatusFlags uint16 `yaml:"status_flags"`
}

type ERRPacket

type ERRPacket struct {
	Header         byte   `yaml:"header"`
	ErrorCode      uint16 `yaml:"error_code"`
	SQLStateMarker string `yaml:"sql_state_marker"`
	SQLState       string `yaml:"sql_state"`
	ErrorMessage   string `yaml:"error_message"`
}

type HandshakeResponse

type HandshakeResponse struct {
	CapabilityFlags      uint32            `yaml:"capability_flags"`
	MaxPacketSize        uint32            `yaml:"max_packet_size"`
	CharacterSet         uint8             `yaml:"character_set"`
	Reserved             [23]byte          `yaml:"reserved,omitempty,flow"`
	Username             string            `yaml:"username"`
	AuthData             []byte            `yaml:"auth_data,omitempty,flow"`
	Database             string            `yaml:"database"`
	AuthPluginName       string            `yaml:"auth_plugin_name"`
	ConnectAttributes    map[string]string `yaml:"connect_attributes"`
	ZstdCompressionLevel byte              `yaml:"zstdcompressionlevel"`
}

type HandshakeResponseOk

type HandshakeResponseOk struct {
	PacketIndicator string        `yaml:"packet_indicator"`
	PluginDetails   PluginDetails `yaml:"plugin_details"`
	RemainingBytes  []byte        `yaml:"remaining_bytes,omitempty,flow"`
}

type HandshakeV10Packet

type HandshakeV10Packet struct {
	ProtocolVersion uint8  `yaml:"protocol_version"`
	ServerVersion   string `yaml:"server_version"`
	ConnectionID    uint32 `yaml:"connection_id"`
	AuthPluginData  []byte `yaml:"auth_plugin_data,omitempty,flow"`
	CapabilityFlags uint32 `yaml:"capability_flags"`
	CharacterSet    uint8  `yaml:"character_set"`
	StatusFlags     uint16 `yaml:"status_flags"`
	AuthPluginName  string `yaml:"auth_plugin_name"`
}

func (*HandshakeV10Packet) GetAuthMethod

func (packet *HandshakeV10Packet) GetAuthMethod() string

func (*HandshakeV10Packet) ShouldUseSSL

func (packet *HandshakeV10Packet) ShouldUseSSL() bool

type MySQL

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

func (*MySQL) MatchType

func (m *MySQL) MatchType(_ context.Context, _ []byte) bool

func (*MySQL) MockOutgoing

func (m *MySQL) MockOutgoing(ctx context.Context, src net.Conn, dstCfg *integrations.ConditionalDstCfg, mockDb integrations.MockMemDb, opts models.OutgoingOptions) error

func (*MySQL) RecordOutgoing

func (m *MySQL) RecordOutgoing(ctx context.Context, src net.Conn, dst net.Conn, mocks chan<- *models.Mock, opts models.OutgoingOptions) error

type NextAuthPacket

type NextAuthPacket struct {
	PluginData byte `yaml:"plugin_data"`
}

type Packet

type Packet struct {
	Header  SQLPacketHeader `yaml:"header"`
	Payload []byte          `yaml:"payload"`
}

func (*Packet) Encode

func (p *Packet) Encode() ([]byte, error)

type PacketHeader

type PacketHeader struct {
	PacketLength     uint8 `yaml:"packet_length"`
	PacketSequenceID uint8 `yaml:"packet_sequence_id"`
}

type PacketType2

type PacketType2 struct {
	Field1 byte `yaml:"field1"`
	Field2 byte `yaml:"field2"`
	Field3 byte `yaml:"field3"`
}

type PasswordData

type PasswordData struct {
	PayloadLength uint32 `yaml:"payload_length"`
	SequenceID    byte   `yaml:"sequence_id"`
	Payload       []byte `yaml:"payload,omitempty,flow"`
}

type PluginDetails

type PluginDetails struct {
	Type    string `yaml:"type"`
	Message string `yaml:"message"`
}

type QueryPacket

type QueryPacket struct {
	Command byte   `yaml:"command"`
	Query   string `yaml:"query"`
}

type RowColumnDefinition

type RowColumnDefinition struct {
	Type  models.FieldType `yaml:"type"`
	Name  string           `yaml:"name"`
	Value interface{}      `yaml:"value"`
}

type RowDataPacket

type RowDataPacket struct {
	Data []byte `yaml:"data,omitempty,flow"`
}

type RowHeader

type RowHeader struct {
	PacketLength int   `yaml:"packet_length"`
	SequenceID   uint8 `yaml:"sequence_id"`
}

type SQLPacketHeader

type SQLPacketHeader struct {
	PayloadLength uint32 `yaml:"payload_length"` // MySQL packet payload length
	SequenceID    uint8  `yaml:"sequence_id"`    // MySQL packet sequence ID
}

func DecodeMySQLPacket

func DecodeMySQLPacket(logger *zap.Logger, packet Packet, clientConn net.Conn, mode models.Mode, lastCommand *lastCommandMap) (string, SQLPacketHeader, interface{}, error)

type StmtPrepareOk

type StmtPrepareOk struct {
	Status       byte                      `yaml:"status"`
	StatementID  uint32                    `yaml:"statement_id"`
	NumColumns   uint16                    `yaml:"num_columns"`
	NumParams    uint16                    `yaml:"num_params"`
	WarningCount uint16                    `yaml:"warning_count"`
	ColumnDefs   []models.ColumnDefinition `yaml:"column_definitions,omitempty,flow"`
	ParamDefs    []models.ColumnDefinition `yaml:"param_definitions,omitempty,flow"`
}

Jump to

Keyboard shortcuts

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