2019-02-01 11:28:20 +01:00
|
|
|
// Copyright 2018 The GoPacket Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the LICENSE file in the root of the source
|
|
|
|
// tree.
|
|
|
|
|
|
|
|
package etls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/google/gopacket"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ETLSHandshakeRecord defines the structure of a Handskake Record
|
|
|
|
type ETLSHandshakeRecord struct {
|
|
|
|
ETLSRecordHeader
|
|
|
|
ETLSHandshakeMsgType uint8
|
2019-02-04 16:26:34 +01:00
|
|
|
ETLSHandshakeServerHello *ServerHelloMsg
|
|
|
|
ETLSHandshakeClientHello *ClientHelloMsg
|
|
|
|
ETLSHandshakeCertificate *CertificateMsg
|
2019-02-01 11:28:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeFromBytes decodes the slice into the ETLS struct.
|
|
|
|
func (t *ETLSHandshakeRecord) decodeFromBytes(h ETLSRecordHeader, data []byte, df gopacket.DecodeFeedback) error {
|
|
|
|
// ETLS Record Header
|
|
|
|
t.ContentType = h.ContentType
|
|
|
|
t.Version = h.Version
|
|
|
|
t.Length = h.Length
|
|
|
|
|
|
|
|
// Switch on Handshake message type
|
|
|
|
switch uint8(data[0]) {
|
|
|
|
case typeClientHello:
|
|
|
|
t.ETLSHandshakeMsgType = typeClientHello
|
2019-02-04 16:26:34 +01:00
|
|
|
t.ETLSHandshakeClientHello = new(ClientHelloMsg)
|
2019-02-01 11:28:20 +01:00
|
|
|
t.ETLSHandshakeClientHello.unmarshal(data)
|
|
|
|
case typeServerHello:
|
|
|
|
t.ETLSHandshakeMsgType = typeServerHello
|
2019-02-04 16:26:34 +01:00
|
|
|
t.ETLSHandshakeServerHello = new(ServerHelloMsg)
|
2019-02-01 11:28:20 +01:00
|
|
|
t.ETLSHandshakeServerHello.unmarshal(data)
|
|
|
|
case typeCertificate:
|
|
|
|
t.ETLSHandshakeMsgType = typeCertificate
|
2019-02-04 16:26:34 +01:00
|
|
|
t.ETLSHandshakeCertificate = new(CertificateMsg)
|
2019-02-01 11:28:20 +01:00
|
|
|
t.ETLSHandshakeCertificate.unmarshal(data)
|
|
|
|
}
|
|
|
|
// Please see the following url if you are interested into implementing the rest:
|
|
|
|
// https://golang.org/src/crypto/tls/conn.go?h=readHandshake#L950
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|