func RemoveSSLFromHandshakeV10(packet []byte) ([]byte, error) {
	r := bytes.NewReader(packet)
	initialLen := r.Len()
	if _, err := GetPacketHeader(r); err != nil {
		return nil, err
	}
	r.ReadByte()
	ReadNullTerminatedString(r)
	connectionIDBuf := make([]byte, 4)
	if _, err := r.Read(connectionIDBuf); err != nil {
		return nil, err
	}
	var salt []byte
	salt8 := make([]byte, 8)
	if _, err := r.Read(salt8); err != nil {
		return nil, err
	}
	salt = append(salt, salt8...)
	if _, err := r.ReadByte(); err != nil {
		return nil, err
	}
	serverCapabilitiesIndex := initialLen - r.Len()
	serverCapabilitiesLowerBuf := make([]byte, 2)
	if _, err := r.Read(serverCapabilitiesLowerBuf); err != nil {
		return nil, err
	}
	if _, err := r.Seek(3, io.SeekCurrent); err != nil {
		return nil, err
	}
	exServerCapabilitiesIndex := initialLen - r.Len()
	serverCapabilitiesHigherBuf := make([]byte, 2)
	if _, err := r.Read(serverCapabilitiesHigherBuf); err != nil {
		return nil, err
	}
	newPacket := make([]byte, len(packet))
	copy(newPacket, packet)
	var serverCapabilitiesBuf []byte
	serverCapabilitiesBuf = append(serverCapabilitiesBuf, serverCapabilitiesLowerBuf...)
	serverCapabilitiesBuf = append(serverCapabilitiesBuf, serverCapabilitiesHigherBuf...)
	serverCapabilities := binary.LittleEndian.Uint32(serverCapabilitiesBuf)
	serverCapabilities = serverCapabilities ^ ClientSSL
	writeUint16(newPacket, serverCapabilitiesIndex, uint16(serverCapabilities))
	writeUint16(newPacket, exServerCapabilitiesIndex, uint16(serverCapabilities>>16))
	return newPacket, nil
}
RemoveSSLFromHandshakeV10 removes Client SSL Capability from Server
Handshake Packet.  Secretless needs to do this to force the client to
communicate with Secretless without using SSL.  That half of the connection
is insecure by design.  Secretless then (usually) adds SSL for the other
half of the communication -- between Secretless and the MySQL server.
package protocol
import (
	"bytes"
	"crypto/sha1"
	"encoding/binary"
	"errors"
	"io"
)
var ErrInvalidPacketLength = errors.New("Protocol: Invalid packet length")
var ErrInvalidPacketType = errors.New("Protocol: Invalid packet type")
var ErrFieldTypeNotImplementedYet = errors.New("Protocol: Required field type not implemented yet")
func UnpackErrResponse(data []byte) error {
	if err := CheckPacketLength(8, data); err != nil {
		return err
	}
	pos := 0
	pos = pos + 4
	pos++
	errno := binary.LittleEndian.Uint16(data[pos : pos+2])
	pos = pos + 2
	sqlstate := ""
	if data[pos] == '#' {
		pos++
		sqlstate = string(data[pos : pos+5])
		pos = pos + 5
	}
	return Error{
		Code:     errno,
		SQLState: sqlstate,
		Message:  string(data[pos:]),
	}
}
func GetPacketType(packet []byte) byte {
	return packet[4]
}
type OkResponse struct {
	PacketType   byte
	AffectedRows uint64
	LastInsertID uint64
	StatusFlags  uint16
	Warnings     uint16
}
func UnpackOkResponse(packet []byte) (*OkResponse, error) {
	if err := CheckPacketLength(5, packet); err != nil {
		return nil, err
	}
	r := bytes.NewReader(packet)
	if _, err := GetPacketHeader(r); err != nil {
		return nil, err
	}
	packetType, err := r.ReadByte()
	if err != nil {
		return nil, err
	}
	if packetType != responseOk {
		return nil, errors.New("Malformed packet")
	}
	affectedRows, err := ReadLenEncodedInteger(r)
	if err != nil {
		return nil, err
	}
	lastInsertID, err := ReadLenEncodedInteger(r)
	if err != nil {
		return nil, err
	}
	statusBuf := make([]byte, 2)
	if _, err := r.Read(statusBuf); err != nil {
		return nil, err
	}
	status := binary.LittleEndian.Uint16(statusBuf)
	warningsBuf := make([]byte, 2)
	if _, err := r.Read(warningsBuf); err != nil {
		return nil, err
	}
	warnings := binary.LittleEndian.Uint16(warningsBuf)
	return &OkResponse{
		PacketType:   packetType,
		AffectedRows: affectedRows,
		LastInsertID: lastInsertID,
		StatusFlags:  status,
		Warnings:     warnings}, nil
}
type HandshakeV10 struct {
	ProtocolVersion    byte
	ServerVersion      string
	ConnectionID       uint32
	ServerCapabilities uint32
	AuthPlugin         string
	Salt               []byte
}
func UnpackHandshakeV10(packet []byte) (*HandshakeV10, error) {
	r := bytes.NewReader(packet)
	if _, err := GetPacketHeader(r); err != nil {
		return nil, err
	}
	protoVersion, _ := r.ReadByte()
	serverVersion := ReadNullTerminatedString(r)
	connectionIDBuf := make([]byte, 4)
	if _, err := r.Read(connectionIDBuf); err != nil {
		return nil, err
	}
	connectionID := binary.LittleEndian.Uint32(connectionIDBuf)
	var salt []byte
	salt8 := make([]byte, 8)
	if _, err := r.Read(salt8); err != nil {
		return nil, err
	}
	salt = append(salt, salt8...)
	if _, err := r.ReadByte(); err != nil {
		return nil, err
	}
	serverCapabilitiesLowerBuf := make([]byte, 2)
	if _, err := r.Read(serverCapabilitiesLowerBuf); err != nil {
		return nil, err
	}
	if _, err := r.Seek(3, io.SeekCurrent); err != nil {
		return nil, err
	}
	serverCapabilitiesHigherBuf := make([]byte, 2)
	if _, err := r.Read(serverCapabilitiesHigherBuf); err != nil {
		return nil, err
	}
	var serverCapabilitiesBuf []byte
	serverCapabilitiesBuf = append(serverCapabilitiesBuf, serverCapabilitiesLowerBuf...)
	serverCapabilitiesBuf = append(serverCapabilitiesBuf, serverCapabilitiesHigherBuf...)
	serverCapabilities := binary.LittleEndian.Uint32(serverCapabilitiesBuf)
	var authPluginDataLength byte
	if serverCapabilities&ClientPluginAuth > 0 {
		var err error
		authPluginDataLength, err = r.ReadByte()
		if err != nil {
			return nil, err
		}
	} else {
		if _, err := r.ReadByte(); err != nil {
			return nil, err
		}
	}
	if _, err := r.Seek(10, io.SeekCurrent); err != nil {
		return nil, err
	}
	var numBytes int
	if serverCapabilities&ClientSecureConnection != 0 {
		numBytes = int(authPluginDataLength) - 8
		if numBytes < 0 || numBytes > 13 {
			numBytes = 13
		}
		salt2 := make([]byte, numBytes)
		if _, err := r.Read(salt2); err != nil {
			return nil, err
		}
		if salt2[numBytes-1] != 0 {
			return nil, errors.New("Malformed packet")
		}
		salt = append(salt, salt2[:numBytes-1]...)
	}
	var authPlugin string
	if serverCapabilities&ClientPluginAuth != 0 {
		authPlugin = ReadNullTerminatedString(r)
	}
	return &HandshakeV10{
		ProtocolVersion:    protoVersion,
		ServerVersion:      serverVersion,
		ConnectionID:       connectionID,
		ServerCapabilities: serverCapabilities,
		AuthPlugin:         authPlugin,
		Salt:               salt,
	}, nil
}