Documentation
¶
Index ¶
- Constants
- Variables
- func DecryptApplicationData(encryptedText []byte, keyBlock *KeyBlock, clientSequence int) []byte
- func DecryptChacha20(header []byte, chipertext []byte, tlsConn *TLSv12Connection) []byte
- func EncryptChacha20(message []byte, tlsConn *TLSv12Connection) []byte
- func EncryptClientMessageForAlert(keyblock *KeyBlock, clientSequence int, plaintext []byte) ([]byte, int)
- func EstablishConnectionAndSendPayload(nwInterface string, dstIPAddr []byte, dstPort uint16, payload []byte) error
- func EstablishConnectionAndSendPayloadXxx(ctx context.Context, nwInterface string, fEthrh *EthernetHeader, fIpv4 *IPv4, ...) error
- func EstablishConnectionAndSendPayloadXxxForIPv6(ctx context.Context, nwInterface string, fEthrh *EthernetHeader, fIpv6 *IPv6, ...) error
- func EstablishTCPTLSv1_2AndSendPayload(ctx context.Context, nwInterface string, fEthrh *EthernetHeader, fIpv4 *IPv4, ...) error
- func EstablishTCPTLSv1_2AndSendPayloadForIPv6(ctx context.Context, nwInterface string, fEthrh *EthernetHeader, fIpv6 *IPv6, ...) error
- func EstablishTCPTLSv1_3AndSendPayload(ctx context.Context, nwInterface string, fEthrh *EthernetHeader, fIpv4 *IPv4, ...) error
- func ExecCommand(command string, args ...string) (string, error)
- func ExecIP(args ...string) (string, error)
- func ExecIPNeigh(args ...string) (string, error)
- func ExecIPRoute(args ...string) (string, error)
- func GetDefaultRouteIP() (string, error)
- func GetDefaultRouteMAC() (string, error)
- func IsDNSRequest(flags uint16) bool
- func IsDNSResponse(flags uint16) bool
- func NewTLSApplicationData(data []byte, keyblock *KeyBlock, clientSequence int) []byte
- func NewTLSClientKeyExchangeAndChangeCipherSpecAndFinished(clientHello *TLSClientHello, serverHello *TLSServerHello) (*TLSClientKeyExchange, *KeyBlock, int, []byte, []byte)
- func Options() []byte
- func OptionsOfAck() []byte
- func OptionsOfhttp() []byte
- func ParsedTLSToPassive(tcp *TCP, p *Passive)
- func SendEncryptedApplicationData(upperLayerData []byte, prevTCP *TCP, srcIPAddr uint32, dstIPAddr uint32, ...) error
- func SendTLSClientHello(nw *NetworkInterface, clientHello *TLSClientHello, srcPort, dstPort uint16, ...) error
- func SendTLSClientHelloForIPv6(nw *NetworkInterface, clientHello *TLSClientHello, srcPort, dstPort uint16, ...) error
- func StrHexToBytes(s string) ([]byte, error)
- func StrHexToBytes2(s string) ([]byte, error)
- func StrHexToBytes3(s string) (byte, error)
- func StrIPToBytes(s string) ([]byte, error)
- func StrIntToUint16(s string) (uint16, error)
- func UintTo2byte(data uint16) []byte
- func WriteHash(message []byte) []byte
- func WriteUint16(buf *bytes.Buffer, target uint16)
- func WriteUint32(buf *bytes.Buffer, target uint32)
- type ARP
- type Answer
- type Certificate
- type CertificateVerify
- type ChangeCipherSpecAndFinished
- type ChangeCipherSpecProtocol
- type ClientKeyExchange
- type DNS
- type ECDHEKeys
- type EncryptedHandshakeMessage
- type EthernetFrame
- type EthernetHeader
- type Finished
- type FinishedMessage
- type ForVerifing
- type HTTP
- type HTTPResponse
- type HTTPResponseHeader
- type HardwareAddr
- type ICMP
- type IPv4
- type IPv6
- type KeyBlock
- type KeyBlockForTLSv13
- type Mss
- type NetworkInterface
- type NetworkInterfaceForTCP
- type NoOperation
- type Passive
- type Queries
- type RSAEncryptedPreMasterSecret
- type SackPermitted
- type ServerHello
- type ServerHelloDone
- type TCP
- func NewTCPAck(srcPort, dstPort uint16, prevSequence uint32, prevAcknowledgment uint32) *TCP
- func NewTCPAckForPassiveData(srcPort, dstPort uint16, prevSequence uint32, prevAcknowledgment uint32, ...) *TCP
- func NewTCPFinAck(srcPort, dstPort uint16, prevSequence uint32, prevAcknowledgment uint32) *TCP
- func NewTCPSyn(srcPort, dstPort uint16) *TCP
- func NewTCPWithData(srcPort, dstPort uint16, data []byte, prevSequence uint32, ...) *TCP
- func ParsedTCP(payload []byte) *TCP
- type TCPConnection
- func (conn *TCPConnection) Close()
- func (conn *TCPConnection) EstablishedConnection()
- func (conn *TCPConnection) IsPassiveAck(tcp *TCP) bool
- func (conn *TCPConnection) IsPassiveFinAck(tcp *TCP) bool
- func (conn *TCPConnection) IsPassivePshAck(tcp *TCP) bool
- func (conn *TCPConnection) IsPassiveSynAckForHandshake(tcp *TCP) bool
- func (conn *TCPConnection) SetState(state TCPState)
- type TCPState
- type TLSApplicationData
- type TLSChangeCipherSpecAndEncryptedHandshakeMessage
- type TLSClientHello
- type TLSClientKeyExchange
- type TLSEncryptedAlert
- type TLSExtension
- type TLSExtensions
- type TLSHandshakeProtocol
- type TLSRecordLayer
- type TLSServerHello
- type TLSServerHelloFor1_3
- type TLSv12Connection
- func (t *TLSv12Connection) Close()
- func (t *TLSv12Connection) EstablishedConnection()
- func (t *TLSv12Connection) IsEstablished() bool
- func (t *TLSv12Connection) IsPassiveChangeCipherSpecAndFinished(tcp *TCP) bool
- func (t *TLSv12Connection) IsPassiveServerHello(tcp *TCP) bool
- func (t *TLSv12Connection) IsSendApplicationData() bool
- func (t *TLSv12Connection) KeyscheduleToAppTraffic()
- func (t *TLSv12Connection) KeyscheduleToMasterSecret(sharedkey []byte)
- func (t *TLSv12Connection) SetState(s TLSv12State)
- func (t *TLSv12Connection) VerifingData() *ForVerifing
- type TLSv12State
- type Timestamps
- type UDP
- type WindowScale
Constants ¶
const ( ARP_OPERATION_CODE_REQUEST = 0x0001 ARP_OPERATION_CODE_REPLY = 0x0002 )
const ( DNS_QR_REQUEST = 0 << 15 // 0 DNS_QR_RESPONSE = 1 << 15 // 1000 0000 0000 0000 )
https://datatracker.ietf.org/doc/html/rfc1035#section-4.1.1 の「QR」 関連: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-5 の「Opcode」の逆引きは廃止(IQuery (Inverse Query, OBSOLETE))
const ( DNS_QUERY_TYPE_A = 0x0001 DNS_QUERY_TYPE_AAAA = 0x001c )
const ( PORT_HTTP = 0x0050 PORT_HTTPS = 0x01bb // 443 )
const ( IPv4_PROTO_ICMP uint8 = 0x01 IPv4_PROTO_TCP uint8 = 0x06 IPv4_PROTO_UDP uint8 = 0x11 )
const ( IPv6_NEXT_HEADER_TCP = IPv4_PROTO_TCP IPv6_NEXT_HEADER_UDP = IPv4_PROTO_UDP IPv6_NEXT_HEADER_ICMPv6 = 0x3a )
TODO: IPv4 と同じものは、IPv4_PROTO_HOGE 使っていいかも
const ( TCP_FLAGS_SYN = 0x02 TCP_FLAGS_SYN_ACK = 0x12 TCP_FLAGS_ACK = 0x10 TCP_FLAGS_FIN_ACK = 0x11 TCP_FLAGS_PSH_ACK = 0x18 // データを上位層へ渡してという信号 TCP_FLAGS_FIN_PSH_ACK = 0x19 )
const ARP_HARDWARE_TYPE_THERNET = 0x0001
const ARP_PROTO_TYPE_IPv4 = 0x0800
const COMMAND_IP = "ip"
const COMPRESSION_METHOD_NULL = 0x00
const (
DNS_QUERY_CLASS_IN = 0x0001
)
const ETHER_TYPE_ARP uint16 = 0x0806
const ETHER_TYPE_IPv4 uint16 = 0x0800
const ETHER_TYPE_IPv6 uint16 = 0x86dd
const (
ICMP_TYPE_REQUEST = 0x08
)
const IP_PAYLOAD_MAX_LENGTH = 1500 - 14 // =1486byte(IPヘッダ含む。14byteはEthernetヘッダ分)
const PORT_DNS = 0x0035 // 53
const TLS_CONTENT_TYPE_ALERT = 0x15
const TLS_CONTENT_TYPE_APPLICATION_DATA = 0x17
const TLS_CONTENT_TYPE_CHANGE_CIPHER_SPEC = 0x14
const TLS_CONTENT_TYPE_HANDSHAKE = 0x16
const TLS_HANDSHAKE_TYPE_CHANGE_CIPHER_SPEC = 0x14
const TLS_HANDSHAKE_TYPE_CLIENT_HELLO = 0x01
const TLS_HANDSHAKE_TYPE_CLIENT_KEY_EXCHANGE = 0x10
const TLS_HANDSHAKE_TYPE_FINISHED = 0x14
const TLS_HANDSHAKE_TYPE_SERVER_HELLO = 0x02
Variables ¶
var IPv4Protocols = map[uint8]string{ IPv4_PROTO_ICMP: "ICMP", IPv4_PROTO_TCP: "TCP", IPv4_PROTO_UDP: "UDP", }
var KeyLable = []byte("key expansion")
var MasterSecretLable = []byte("master secret")
var TLS_EXTENSION_SUPPORTED_VERSIONS = []byte{0x00, 0x2b}
var TLS_EXTENSION_TYPE_KEY_SHARE = []byte{0x0, 0x33}
var TLS_VERSION_1_0 = []byte{0x03, 0x01}
var TLS_VERSION_1_1 = []byte{0x03, 0x02}
var TLS_VERSION_1_2 = []byte{0x03, 0x03}
var TLS_VERSION_1_3 = []byte{0x03, 0x04}
var TLSv13_ClientapTraffic = []byte(`c ap traffic`)
var TLSv13_ClienthsTraffic = []byte(`c hs traffic`)
var TLSv13_DerivedLabel = []byte(`derived`)
var TLSv13_FinishedLabel = []byte(`finished`)
var TLSv13_ServerapTraffic = []byte(`s ap traffic`)
var TLSv13_ServerhsTraffic = []byte(`s hs traffic`)
Functions ¶
func DecryptApplicationData ¶ added in v1.3.2
func DecryptChacha20 ¶ added in v1.4.0
func DecryptChacha20(header []byte, chipertext []byte, tlsConn *TLSv12Connection) []byte
こちらも拝借させてもらってる ref: https://github.com/sat0ken/go-tcpip/blob/7dd5085f8aa25747a6098cc7d8d8e336ec5fcadd/tls1_3.go#L88
func EncryptChacha20 ¶ added in v1.4.0
func EncryptChacha20(message []byte, tlsConn *TLSv12Connection) []byte
func EncryptClientMessageForAlert ¶ added in v1.3.2
func EncryptClientMessageForAlert(keyblock *KeyBlock, clientSequence int, plaintext []byte) ([]byte, int)
TODO: 上の encryptClientMessage と共通化を
func EstablishConnectionAndSendPayload ¶
func EstablishConnectionAndSendPayload(nwInterface string, dstIPAddr []byte, dstPort uint16, payload []byte) error
with tcp 3 way handshake
func EstablishConnectionAndSendPayloadXxx ¶ added in v0.0.3
func EstablishConnectionAndSendPayloadXxx(ctx context.Context, nwInterface string, fEthrh *EthernetHeader, fIpv4 *IPv4, fTcp *TCP, upperLayerData []byte) error
このなかで、ログ出力などしないこと。Monitor の下に出てくる 挙動を詳細に確認する場合は、internal内の SendTCP3wayhandshake 関数でやること TODO: 対向からRST,RST/ACKが来た時にreturnするようにする
func EstablishConnectionAndSendPayloadXxxForIPv6 ¶ added in v1.1.0
func EstablishTCPTLSv1_2AndSendPayload ¶ added in v1.3.0
func EstablishTCPTLSv1_2AndSendPayload(ctx context.Context, nwInterface string, fEthrh *EthernetHeader, fIpv4 *IPv4, fTcp *TCP, upperLayerData []byte) error
TCP 3way handshake と TLSv1.2 の handshake 後にリクエストする関数
func EstablishTCPTLSv1_2AndSendPayloadForIPv6 ¶ added in v1.3.2
func EstablishTCPTLSv1_2AndSendPayloadForIPv6(ctx context.Context, nwInterface string, fEthrh *EthernetHeader, fIpv6 *IPv6, fTcp *TCP, upperLayerData []byte) error
TCP 3way handshake と TLSv1.2 の handshake 後にリクエストする関数(IPv6用)
func EstablishTCPTLSv1_3AndSendPayload ¶ added in v1.4.0
func EstablishTCPTLSv1_3AndSendPayload(ctx context.Context, nwInterface string, fEthrh *EthernetHeader, fIpv4 *IPv4, fTcp *TCP, upperLayerData []byte) error
TCP 3way handshake と TLSv1.3 の handshake 後にリクエストする関数
func ExecIPNeigh ¶
func ExecIPRoute ¶
func GetDefaultRouteIP ¶
func GetDefaultRouteMAC ¶
func IsDNSRequest ¶ added in v1.0.8
func IsDNSResponse ¶ added in v1.0.8
func NewTLSApplicationData ¶ added in v1.0.3
func NewTLSClientKeyExchangeAndChangeCipherSpecAndFinished ¶ added in v1.0.3
func NewTLSClientKeyExchangeAndChangeCipherSpecAndFinished(clientHello *TLSClientHello, serverHello *TLSServerHello) (*TLSClientKeyExchange, *KeyBlock, int, []byte, []byte)
func OptionsOfhttp ¶
func OptionsOfhttp() []byte
http getリクエスト時のtcp optionを覗いて https://atmarkit.itmedia.co.jp/ait/articles/0401/29/news080_2.html 「オプション」フィールド:32bit単位で可変長
func ParsedTLSToPassive ¶ added in v1.3.0
func SendEncryptedApplicationData ¶ added in v1.4.0
func SendEncryptedApplicationData(upperLayerData []byte, prevTCP *TCP, srcIPAddr uint32, dstIPAddr uint32, dstMACAddr HardwareAddr, srcMACAddr HardwareAddr, fEthrh *EthernetHeader, nw *NetworkInterface, tlsConn *TLSv12Connection, tcpConn *TCPConnection) error
func SendTLSClientHello ¶ added in v1.3.0
func SendTLSClientHello(nw *NetworkInterface, clientHello *TLSClientHello, srcPort, dstPort uint16, srcIPAddr uint32, dstIPAddr uint32, firsthopMACAddr [6]byte, prevSequence uint32, prevAcknowledgment uint32) error
func SendTLSClientHelloForIPv6 ¶ added in v1.3.2
func SendTLSClientHelloForIPv6(nw *NetworkInterface, clientHello *TLSClientHello, srcPort, dstPort uint16, srcIPAddr []uint8, dstIPAddr []uint8, firsthopMACAddr [6]byte, prevSequence uint32, prevAcknowledgment uint32) error
func StrHexToBytes ¶ added in v1.0.0
TODO: rename or refactor
func StrHexToBytes2 ¶ added in v1.0.0
TODO: rename or refactor
func StrHexToBytes3 ¶ added in v1.0.0
TODO: rename or refactor
func StrIPToBytes ¶ added in v1.0.0
stringのIPv4アドレスをbytesに変換
func StrIntToUint16 ¶ added in v1.0.0
func UintTo2byte ¶ added in v1.4.0
func WriteUint16 ¶
func WriteUint32 ¶
Types ¶
type ARP ¶
type ARP struct { HardwareType uint16 ProtocolType uint16 HardwareAddrLength uint8 ProtocolLength uint8 Operation uint16 SenderHardwareAddr HardwareAddr SenderIPAddr uint32 TargetHardwareAddr HardwareAddr TargetIPAddr uint32 }
https://ja.wikipedia.org/wiki/Address_Resolution_Protocol#%E3%83%91%E3%82%B1%E3%83%83%E3%83%88%E6%A7%8B%E9%80%A0 https://beginners-network.com/supplement/arp_packet_format.html
func NewARPReply ¶ added in v1.0.0
func NewARPReply(sMACAdder HardwareAddr, sIPAddr uint32, tMACAddr HardwareAddr, tIPAddr uint32) *ARP
func NewARPRequest ¶ added in v1.0.0
func NewARPRequest(sMACAdder HardwareAddr, sIPAddr uint32, tMACAddr HardwareAddr, tIPAddr uint32) *ARP
type Certificate ¶ added in v1.0.3
type Certificate struct { RecordLayer *TLSRecordLayer HandshakeProtocol *TLSHandshakeProtocol CertificatesLength []byte Certificates []byte // TODO: ここ更にフィールドあった // contains filtered or unexported fields }
func (*Certificate) Bytes ¶ added in v1.0.3
func (c *Certificate) Bytes() []byte
func (*Certificate) ServerPublicKey ¶ added in v1.0.3
func (c *Certificate) ServerPublicKey() *rsa.PublicKey
func (*Certificate) Validate ¶ added in v1.0.3
func (c *Certificate) Validate() error
ref: https://zenn.dev/satoken/articles/golang-tls1_2#serverhello%2C-certificate%2C-serverhellodone
type CertificateVerify ¶ added in v1.4.0
type CertificateVerify struct { HandshakeType byte Length []byte SignatureHashAlgorithms []byte SignatureLength []byte Signature []byte }
func (*CertificateVerify) VerifyServerCertificate ¶ added in v1.4.0
func (c *CertificateVerify) VerifyServerCertificate(pubkey *rsa.PublicKey, handshake_messages []byte) error
ref: https://github.com/sat0ken/go-tcpip/blob/7dd5085f8aa25747a6098cc7d8d8e336ec5fcadd/tls1_3.go#L285
type ChangeCipherSpecAndFinished ¶ added in v1.0.3
type ChangeCipherSpecAndFinished struct { ChangeCipherSpecProtocol *ChangeCipherSpecProtocol Finished *Finished }
func ParsedTLSChangeCipherSpecAndFinished ¶ added in v1.0.3
func ParsedTLSChangeCipherSpecAndFinished(b []byte, keyblock *KeyBlock, clientSequenceNum int, verifyingData *ForVerifing) *ChangeCipherSpecAndFinished
これは、自作 tls handshake 用で、Monitor に表示するためのものではない
type ChangeCipherSpecProtocol ¶ added in v1.0.3
type ChangeCipherSpecProtocol struct { RecordLayer *TLSRecordLayer ChangeCipherSpecMessage []byte }
func ParsedChangeCipherSpec ¶ added in v1.4.0
func ParsedChangeCipherSpec(b []byte) (*ChangeCipherSpecProtocol, int)
func (*ChangeCipherSpecProtocol) Bytes ¶ added in v1.0.3
func (cc *ChangeCipherSpecProtocol) Bytes() []byte
type ClientKeyExchange ¶ added in v1.0.3
type ClientKeyExchange struct { RecordLayer *TLSRecordLayer HandshakeProtocol *TLSHandshakeProtocol RSAEncryptedPreMasterSecret *RSAEncryptedPreMasterSecret }
func (*ClientKeyExchange) Bytes ¶ added in v1.0.3
func (c *ClientKeyExchange) Bytes() []byte
type DNS ¶
type DNS struct { TransactionID uint16 Flags uint16 // TODO: ここにビット単位で意味があるから、structにして管理したい Questions uint16 AnswerRRs uint16 AuthorityRRs uint16 AdditionalRRs uint16 Queries *Queries Answers []*Answer }
https://atmarkit.itmedia.co.jp/ait/articles/1601/29/news014.html 上記とパケットキャプチャ見てイメージがつく、domain
func ParsedDNSRequest ¶
func ParsedDNSResponse ¶
type EncryptedHandshakeMessage ¶ added in v1.0.3
type EncryptedHandshakeMessage struct { RecordLayer *TLSRecordLayer EncryptedHandshakeMessage_ []byte }
func (*EncryptedHandshakeMessage) Bytes ¶ added in v1.0.3
func (e *EncryptedHandshakeMessage) Bytes() []byte
type EthernetFrame ¶
type EthernetFrame struct { Header *EthernetHeader Data []byte }
func NewEthernetFrame ¶
func NewEthernetFrame(dst HardwareAddr, src HardwareAddr, typ uint16, payload []byte) *EthernetFrame
func ParsedEthernetFrame ¶
func ParsedEthernetFrame(b []byte) *EthernetFrame
func (*EthernetFrame) Bytes ¶
func (ef *EthernetFrame) Bytes() []byte
type EthernetHeader ¶
type EthernetHeader struct { Dst HardwareAddr Src HardwareAddr Typ uint16 }
type Finished ¶ added in v1.0.3
type Finished struct { RecordLayer *TLSRecordLayer RawEncrypted []byte }
type FinishedMessage ¶ added in v1.4.0
func (*FinishedMessage) Bytes ¶ added in v1.4.0
func (f *FinishedMessage) Bytes() []byte
type ForVerifing ¶ added in v1.0.3
type ForVerifing struct { Master []byte ClientHello *TLSClientHello ServerHello *TLSServerHello ClientKeyExchange *ClientKeyExchange ClientFinished []byte // 暗号化前の }
type HTTP ¶
type HTTP struct { Method string Uri string Version string Host string UserAgent string Accept string ContentLength string Body string }
func ParsedHTTPRequest ¶
type HTTPResponse ¶
type HTTPResponse struct { StatusLine string Header *HTTPResponseHeader Body []byte // contains filtered or unexported fields }
func ParsedHTTPResponse ¶
func ParsedHTTPResponse(payload []byte) *HTTPResponse
TODO: 多分このあたりバグってる。Monitor の http response の hexadecimal dump と Wireshark で異なる TODO: panic になることある
func (*HTTPResponse) Bytes ¶ added in v1.0.7
func (hr *HTTPResponse) Bytes() []byte
func (*HTTPResponse) Len ¶ added in v0.0.3
func (h *HTTPResponse) Len() int
type HTTPResponseHeader ¶ added in v0.0.3
func (*HTTPResponseHeader) Bytes ¶ added in v1.0.7
func (hrh *HTTPResponseHeader) Bytes() []byte
type HardwareAddr ¶
type HardwareAddr [6]uint8
func (*HardwareAddr) String ¶ added in v1.0.0
func (h *HardwareAddr) String() string
type ICMP ¶
type ICMP struct { Typ uint8 Code uint8 Checksum uint16 Identifier uint16 Sequence uint16 Data []byte }
https://www.infraexpert.com/study/tcpip4.html https://inc0x0.com/icmp-ip-packets-ping-manually-create-and-send-icmp-ip-packets/
func ParsedICMP ¶
func (*ICMP) CalculateChecksum ¶
copy from https://cs.opensource.google/go/x/net/+/master:icmp/message.go
type IPv4 ¶
type IPv4 struct { Version uint8 // 4bit Ihl uint8 // 4bit. hearder length Tos uint8 // 8bit. type of service TotalLength uint16 // 16bit. total length Identification uint16 // 16bit Flags uint8 // 3bit FragmentOffset uint16 // 13bit Ttl uint8 // 8bit Protocol uint8 // 8bit HeaderChecksum uint16 // 16bit SrcAddr uint32 // 32bit DstAddr uint32 // 32bit Options []uint8 Padding []uint8 Data []byte }
https://www.infraexpert.com/study/tcpip1.html
func ParsedIPv4 ¶
func (*IPv4) CalculateTotalLength ¶
func (i *IPv4) CalculateTotalLength()
func (*IPv4) StrDstIPAddr ¶ added in v1.0.0
func (*IPv4) StrSrcIPAddr ¶ added in v1.0.0
type IPv6 ¶ added in v0.0.2
type IPv6 struct { Version uint8 // 4bit TrafficClass uint8 FlowLabel uint32 // 20bit PayloadLength uint16 NextHeader uint8 HopLimit uint8 SrcAddr []uint8 DstAddr []uint8 Option []uint8 Data []byte }
rfc: https://datatracker.ietf.org/doc/html/rfc8200#page-6 https://atmarkit.itmedia.co.jp/ait/articles/1201/05/news113.html ↑ によると、「TrafficClass」の前半4bitに拡張ヘッダ(Option)までの長さ入ってるっぽいけど https://datatracker.ietf.org/doc/html/rfc8200#section-4 によると、「NextHeader」の種類ごとに、拡張ヘッダー(Option)があるかどうかみたいなのがわかるっぽい? ちなみに、NextHeader は、IPv4 の Protocol と同じ値みたい
func ParsedIPv6 ¶ added in v0.0.2
func (*IPv6) PseudoHeader ¶ added in v1.1.0
上位レイヤのチェックサムを求めるための ref: https://datatracker.ietf.org/doc/html/rfc8200#section-8.1
func (*IPv6) StrDstIPAddr ¶ added in v1.0.0
func (*IPv6) StrSrcIPAddr ¶ added in v1.0.0
type KeyBlockForTLSv13 ¶ added in v1.4.0
type NetworkInterface ¶
type NetworkInterface struct { Intf *net.Interface Socket int // file discripter SocketAddr unix.SockaddrLinklayer IPAdder uint32 PassiveCh chan *Passive }
func NewNetworkInterface ¶
func NewNetworkInterface(nwInterface string) (*NetworkInterface, error)
func (*NetworkInterface) Close ¶
func (nw *NetworkInterface) Close() error
func (*NetworkInterface) Send ¶
func (nw *NetworkInterface) Send(ethernetFrame *EthernetFrame) error
type NetworkInterfaceForTCP ¶
type NetworkInterfaceForTCP struct {
Socket int
}
func NewNetworkInterfaceForTCP ¶
func NewNetworkInterfaceForTCP(nwInterface string) (*NetworkInterfaceForTCP, error)
func (*NetworkInterfaceForTCP) Close ¶
func (nwt *NetworkInterfaceForTCP) Close() error
func (*NetworkInterfaceForTCP) Connect ¶
func (nwt *NetworkInterfaceForTCP) Connect(dstIPAddr []byte, dstPort uint16) error
type NoOperation ¶
type NoOperation struct {
Kind uint8
}
type Passive ¶
type Passive struct { HTTPRes *HTTPResponse HTTP *HTTP TLSClientHello *TLSClientHello TLSServerHello *TLSServerHello TLSServerHelloFor1_3 *TLSServerHelloFor1_3 // TODO: まとめたい TLSClientKeyExchange *TLSClientKeyExchange TLSChangeCipherSpecAndEncryptedHandshakeMessage *TLSChangeCipherSpecAndEncryptedHandshakeMessage TLSApplicationData *TLSApplicationData TLSEncryptedAlert *TLSEncryptedAlert DNS *DNS TCP *TCP UDP *UDP ICMP *ICMP IPv4 *IPv4 IPv6 *IPv6 ARP *ARP EthernetFrame *EthernetFrame }
func ParsedPacket ¶
func (*Passive) HighLayerProto ¶
type RSAEncryptedPreMasterSecret ¶ added in v1.0.3
type RSAEncryptedPreMasterSecret struct { EncryptedPreMasterLength []byte EncryptedPreMaster []byte }
func (*RSAEncryptedPreMasterSecret) Bytes ¶ added in v1.0.3
func (r *RSAEncryptedPreMasterSecret) Bytes() []byte
type SackPermitted ¶
type ServerHello ¶ added in v1.0.3
type ServerHello struct { RecordLayer *TLSRecordLayer HandshakeProtocol *TLSHandshakeProtocol }
func ParsedTLSServerHelloOnly ¶ added in v1.4.0
func ParsedTLSServerHelloOnly(b []byte) (*ServerHello, int)
TLS1.2/1.3 共通
func (*ServerHello) Bytes ¶ added in v1.0.3
func (s *ServerHello) Bytes() []byte
type ServerHelloDone ¶ added in v1.0.3
type ServerHelloDone struct { RecordLayer *TLSRecordLayer HandshakeProtocol *TLSHandshakeProtocol }
func (*ServerHelloDone) Bytes ¶ added in v1.0.3
func (sd *ServerHelloDone) Bytes() []byte
type TCP ¶
type TCP struct { SrcPort uint16 DstPort uint16 Sequence uint32 Acknowledgment uint32 // Data Offset (DOffset)(4bit. TCPヘッダ長. 32bit整数倍) と Reserved (Rsrvd)(4bit. すべて0) // ref: https://www.rfc-editor.org/rfc/rfc9293.html#section-3.1 HeaderLength uint8 // Control bits(8bit) // ref: https://www.rfc-editor.org/rfc/rfc9293.html#section-3.1-6.14.1 Flags uint8 Window uint16 Checksum uint16 UrgentPointer uint16 Options []byte // optionsをセットする用の関数あった方がいいかも? Data []byte }
func NewTCPAckForPassiveData ¶ added in v0.0.3
func NewTCPAckForPassiveData(srcPort, dstPort uint16, prevSequence uint32, prevAcknowledgment uint32, tcpPayloadLength int) *TCP
tcpパケット連続で送るときは port 変えること
func NewTCPFinAck ¶ added in v0.0.3
tcpパケット連続で送るときは port 変えること
func NewTCPWithData ¶
func NewTCPWithData(srcPort, dstPort uint16, data []byte, prevSequence uint32, prevAcknowledgment uint32) *TCP
tcpパケット連続で送るときは port 変えること
func (*TCP) CalculateChecksum ¶ added in v0.0.3
https://atmarkit.itmedia.co.jp/ait/articles/0401/29/news080_2.html 「「チェックサム」フィールド:16bit幅」
func (*TCP) CalculateChecksumForIPv6 ¶ added in v1.1.0
type TCPConnection ¶ added in v1.3.2
type TCPConnection struct { SrcPort uint16 DstPort uint16 // contains filtered or unexported fields }
func NewTCPConnection ¶ added in v1.3.2
func NewTCPConnection(SrcPort uint16, DstPort uint16) *TCPConnection
func (*TCPConnection) Close ¶ added in v1.3.2
func (conn *TCPConnection) Close()
func (*TCPConnection) EstablishedConnection ¶ added in v1.3.2
func (conn *TCPConnection) EstablishedConnection()
func (*TCPConnection) IsPassiveAck ¶ added in v1.3.2
func (conn *TCPConnection) IsPassiveAck(tcp *TCP) bool
func (*TCPConnection) IsPassiveFinAck ¶ added in v1.3.2
func (conn *TCPConnection) IsPassiveFinAck(tcp *TCP) bool
func (*TCPConnection) IsPassivePshAck ¶ added in v1.3.2
func (conn *TCPConnection) IsPassivePshAck(tcp *TCP) bool
func (*TCPConnection) IsPassiveSynAckForHandshake ¶ added in v1.3.2
func (conn *TCPConnection) IsPassiveSynAckForHandshake(tcp *TCP) bool
func (*TCPConnection) SetState ¶ added in v1.3.2
func (conn *TCPConnection) SetState(state TCPState)
type TCPState ¶ added in v1.3.2
type TCPState int
const ( TCP_STATE_INIT TCPState = iota TCP_STATE_3WAY_HANDSHAKE_SEND_SYN TCP_STATE_3WAY_HANDSHAKE_PASSIVE_SYNACK TCP_STATE_3WAY_HANDSHAKE_SEND_ACK // = established tcp connection TCP_STATE_PASSIVE_PSHACK // = データ受信 TCP_STATE_SEND_FINACK // = tcp connection を終えたい TCP_STATE_PASSIVE_FINACK TCP_STATE_SEND_ACK )
type TLSApplicationData ¶ added in v1.0.3
type TLSApplicationData struct { RecordLayer *TLSRecordLayer EncryptedApplicationData []byte }
func ParsedTLSApplicationData ¶ added in v1.3.0
func ParsedTLSApplicationData(b []byte) *TLSApplicationData
func (*TLSApplicationData) Bytes ¶ added in v1.0.3
func (a *TLSApplicationData) Bytes() []byte
type TLSChangeCipherSpecAndEncryptedHandshakeMessage ¶ added in v1.3.0
type TLSChangeCipherSpecAndEncryptedHandshakeMessage struct { ChangeCipherSpecProtocol *ChangeCipherSpecProtocol EncryptedHandshakeMessage *EncryptedHandshakeMessage }
サーバから来る
func ParsedTLSChangeCipherSpecAndEncryptedHandshakeMessage ¶ added in v1.3.0
func ParsedTLSChangeCipherSpecAndEncryptedHandshakeMessage(b []byte) *TLSChangeCipherSpecAndEncryptedHandshakeMessage
これは、Monitor 表示用に、受信したものをただパースする関数
func (*TLSChangeCipherSpecAndEncryptedHandshakeMessage) Bytes ¶ added in v1.3.0
func (t *TLSChangeCipherSpecAndEncryptedHandshakeMessage) Bytes() []byte
type TLSClientHello ¶ added in v1.0.3
type TLSClientHello struct { RecordLayer *TLSRecordLayer HandshakeProtocol *TLSHandshakeProtocol // TODO: これがこのstruct内にあるのはおかしく、一旦実装を簡単にするため置いてるだけ。要リファクタ ECDHEKeys *ECDHEKeys }
func NewTLSClientHello ¶ added in v1.0.3
func NewTLSClientHello(tlsVersion []byte, cipherSuites ...uint16) *TLSClientHello
TODO: tls1.3 用のと汎用的に
func ParsedTLSClientHello ¶ added in v1.3.0
func ParsedTLSClientHello(b []byte) *TLSClientHello
func (*TLSClientHello) Bytes ¶ added in v1.0.3
func (tch *TLSClientHello) Bytes() []byte
type TLSClientKeyExchange ¶ added in v1.0.3
type TLSClientKeyExchange struct { ClientKeyExchange *ClientKeyExchange ChangeCipherSpecProtocol *ChangeCipherSpecProtocol EncryptedHandshakeMessage []byte }
func ParsedTLSClientKeyexchange ¶ added in v1.3.0
func ParsedTLSClientKeyexchange(b []byte) *TLSClientKeyExchange
func (*TLSClientKeyExchange) Bytes ¶ added in v1.0.3
func (tlsclientkeyexchange *TLSClientKeyExchange) Bytes() []byte
type TLSEncryptedAlert ¶ added in v1.3.0
type TLSEncryptedAlert struct { RecordLayer *TLSRecordLayer AlertMessage []byte }
func ParsedTLSEncryptedAlert ¶ added in v1.3.0
func ParsedTLSEncryptedAlert(b []byte) *TLSEncryptedAlert
func (*TLSEncryptedAlert) Bytes ¶ added in v1.3.0
func (t *TLSEncryptedAlert) Bytes() []byte
type TLSExtension ¶ added in v1.4.0
func (*TLSExtension) Bytes ¶ added in v1.4.0
func (e *TLSExtension) Bytes() []byte
func (*TLSExtension) IsTLS13 ¶ added in v1.4.0
func (e *TLSExtension) IsTLS13() bool
type TLSExtensions ¶ added in v1.4.0
type TLSExtensions []*TLSExtension
func ParsedTLSExtensions ¶ added in v1.4.0
func ParsedTLSExtensions(extensionsLength int, b []byte) TLSExtensions
func (TLSExtensions) Bytes ¶ added in v1.4.0
func (es TLSExtensions) Bytes() []byte
type TLSHandshakeProtocol ¶ added in v1.0.3
type TLSHandshakeProtocol struct { HandshakeType []byte Length []byte Version []byte Random []byte SessionIDLength []byte SessionID []byte CipherSuitesLength []byte CipherSuites []uint16 // ref: https://tls12.xargs.org/#client-hello/annotated [Ciper Suites] CompressionMethodsLength []byte CompressionMethods []byte ExtensionsLength []byte Extentions TLSExtensions }
func (*TLSHandshakeProtocol) Bytes ¶ added in v1.0.3
func (p *TLSHandshakeProtocol) Bytes(isFromServer bool) []byte
type TLSRecordLayer ¶ added in v1.0.3
ref: https://tls12.xargs.org/#client-hello/annotated 以降のstructのフィールドはWiresharkを見つつ補完
func (*TLSRecordLayer) Bytes ¶ added in v1.0.3
func (l *TLSRecordLayer) Bytes() []byte
type TLSServerHello ¶ added in v1.0.3
type TLSServerHello struct { ServerHello *ServerHello Certificate *Certificate ServerHelloDone *ServerHelloDone }
func ParsedTLSServerHello ¶ added in v1.0.3
func ParsedTLSServerHello(b []byte) *TLSServerHello
tls1.2用
func (*TLSServerHello) Bytes ¶ added in v1.0.3
func (tlsserverhello *TLSServerHello) Bytes() []byte
type TLSServerHelloFor1_3 ¶ added in v1.4.0
type TLSServerHelloFor1_3 struct { ServerHello *ServerHello ChangeCipherSpecProtocol *ChangeCipherSpecProtocol ApplicationDataProtocols []*TLSApplicationData }
func ParsedTLSServerHelloFor1_3 ¶ added in v1.4.0
func ParsedTLSServerHelloFor1_3(b []byte) *TLSServerHelloFor1_3
tls1.3用
func (*TLSServerHelloFor1_3) Bytes ¶ added in v1.4.0
func (t *TLSServerHelloFor1_3) Bytes() []byte
func (*TLSServerHelloFor1_3) GetServerKeyShare ¶ added in v1.4.0
func (t *TLSServerHelloFor1_3) GetServerKeyShare() []byte
type TLSv12Connection ¶ added in v1.3.2
type TLSv12Connection struct { TLSClientHello *TLSClientHello TLSServerHello *TLSServerHello TLSClientKeyExchange *TLSClientKeyExchange TLSClientFinished []byte KeyBlock *KeyBlock ClientSequence int Master []byte // 以降、tlsv1.3実装で追加したものたち ECDHEKeys *ECDHEKeys KeyBlockForTLSv13 *KeyBlockForTLSv13 TLSServerHelloFor1_3 *TLSServerHelloFor1_3 ServerHandshakeSeq int ServerAppSeq int ClientHandshakeSeq int ClientAppSeq int // contains filtered or unexported fields }
func NewTLSv12Connection ¶ added in v1.3.2
func NewTLSv12Connection() *TLSv12Connection
func NewTLSv13Connection ¶ added in v1.4.0
func NewTLSv13Connection() *TLSv12Connection
TODO: 1.3用のstructを?
func (*TLSv12Connection) Close ¶ added in v1.3.2
func (t *TLSv12Connection) Close()
func (*TLSv12Connection) EstablishedConnection ¶ added in v1.3.2
func (t *TLSv12Connection) EstablishedConnection()
func (*TLSv12Connection) IsEstablished ¶ added in v1.3.2
func (t *TLSv12Connection) IsEstablished() bool
func (*TLSv12Connection) IsPassiveChangeCipherSpecAndFinished ¶ added in v1.3.2
func (t *TLSv12Connection) IsPassiveChangeCipherSpecAndFinished(tcp *TCP) bool
func (*TLSv12Connection) IsPassiveServerHello ¶ added in v1.3.2
func (t *TLSv12Connection) IsPassiveServerHello(tcp *TCP) bool
TODO: ServerHello 以外も拾っちゃってるからちゃんと判定したい
func (*TLSv12Connection) IsSendApplicationData ¶ added in v1.3.2
func (t *TLSv12Connection) IsSendApplicationData() bool
func (*TLSv12Connection) KeyscheduleToAppTraffic ¶ added in v1.4.0
func (t *TLSv12Connection) KeyscheduleToAppTraffic()
こちらも
func (*TLSv12Connection) KeyscheduleToMasterSecret ¶ added in v1.4.0
func (t *TLSv12Connection) KeyscheduleToMasterSecret(sharedkey []byte)
丸っと拝借させて頂いた コード: https://github.com/sat0ken/go-tcpip/blob/7dd5085f8aa25747a6098cc7d8d8e336ec5fcadd/tls1_3.go#L192 記事:https://zenn.dev/satoken/articles/golang-tls1_3#tls1.3%E3%81%AE%E9%8D%B5%E7%94%9F%E6%88%90%E3%81%AE%E6%B5%81%E3%82%8C TODO: やっぱりレシーバがTLSv1.2用のはおかしいから、v1.3用の作るか、共用に命名変更するかする
func (*TLSv12Connection) SetState ¶ added in v1.3.2
func (t *TLSv12Connection) SetState(s TLSv12State)
func (*TLSv12Connection) VerifingData ¶ added in v1.3.2
func (t *TLSv12Connection) VerifingData() *ForVerifing
type TLSv12State ¶ added in v1.3.2
type TLSv12State int
const ( TLSv12_STATE_INIT TLSv12State = iota TLSv12_STATE_PASSIVE_SERVER_HELLO TLSv12_STATE_SEND_APPLICATION_DATA )
type UDP ¶
type UDP struct { SrcPort uint16 DstPort uint16 Length uint16 Checksum uint16 // TODO: 後で計算用メソッドを。そもそも他のヘッダのchecksumと同じ計算っぽいから、独立させるかも Data []byte }
func (*UDP) CalculateChecksumForIPv6 ¶ added in v1.1.0
IPv6 ではチェックサムがないため、上のレイヤでチェックサムが必要なため