Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1 | // Copyright 2018 The GoPacket Authors. All rights reserved. |
| 2 | // |
| 3 | // Use of this source code is governed by a BSD-style license |
| 4 | // that can be found in the LICENSE file in the root of the source |
| 5 | // tree. |
| 6 | |
| 7 | package layers |
| 8 | |
| 9 | import ( |
| 10 | "errors" |
| 11 | |
| 12 | "github.com/google/gopacket" |
| 13 | ) |
| 14 | |
| 15 | // TLSchangeCipherSpec defines the message value inside ChangeCipherSpec Record |
| 16 | type TLSchangeCipherSpec uint8 |
| 17 | |
| 18 | const ( |
| 19 | TLSChangecipherspecMessage TLSchangeCipherSpec = 1 |
| 20 | TLSChangecipherspecUnknown TLSchangeCipherSpec = 255 |
| 21 | ) |
| 22 | |
| 23 | // TLS Change Cipher Spec |
| 24 | // 0 1 2 3 4 5 6 7 8 |
| 25 | // +--+--+--+--+--+--+--+--+ |
| 26 | // | Message | |
| 27 | // +--+--+--+--+--+--+--+--+ |
| 28 | |
| 29 | // TLSChangeCipherSpecRecord defines the type of data inside ChangeCipherSpec Record |
| 30 | type TLSChangeCipherSpecRecord struct { |
| 31 | TLSRecordHeader |
| 32 | |
| 33 | Message TLSchangeCipherSpec |
| 34 | } |
| 35 | |
| 36 | // DecodeFromBytes decodes the slice into the TLS struct. |
| 37 | func (t *TLSChangeCipherSpecRecord) decodeFromBytes(h TLSRecordHeader, data []byte, df gopacket.DecodeFeedback) error { |
| 38 | // TLS Record Header |
| 39 | t.ContentType = h.ContentType |
| 40 | t.Version = h.Version |
| 41 | t.Length = h.Length |
| 42 | |
| 43 | if len(data) != 1 { |
| 44 | df.SetTruncated() |
| 45 | return errors.New("TLS Change Cipher Spec record incorrect length") |
| 46 | } |
| 47 | |
| 48 | t.Message = TLSchangeCipherSpec(data[0]) |
| 49 | if t.Message != TLSChangecipherspecMessage { |
| 50 | t.Message = TLSChangecipherspecUnknown |
| 51 | } |
| 52 | |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | // String shows the message value nicely formatted |
| 57 | func (ccs TLSchangeCipherSpec) String() string { |
| 58 | switch ccs { |
| 59 | default: |
| 60 | return "Unknown" |
| 61 | case TLSChangecipherspecMessage: |
| 62 | return "Change Cipher Spec Message" |
| 63 | } |
| 64 | } |