tls

package
v0.16.7 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 39 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientHelloDecoder = &decoder.AbstractDecoder{Name: "TLSClientHello", Type: types.Type_NC_TLSClientHello, Description: "Reassembled TLS client hellos"}
View Source
var Decoder = &decoder.StreamDecoder{
	Type:        types.Type_NC_TLSCertificate,
	Name:        serviceTLS,
	Description: "Transport Layer Security certificates extracted from TLS handshakes",
	PostInit: func(d *decoder.StreamDecoder) error {
		var err error
		tlsLog, _, err = logging.InitZapLogger(
			decoderconfig.Instance.Out,
			"tls",
			decoderconfig.Instance.Debug,
		)
		return err
	},

	Specificity: core.SpecificityStructural,

	CanDecode: func(client, server []byte) bool {
		for _, data := range [][]byte{client, server} {
			if sslv2HelloType(data) != 0 {
				return true
			}
			if len(data) >= 6 && data[0] == 22 && data[1] == 3 && data[2] <= 3 && (data[5] == 1 || data[5] == 2) {
				return true
			}
		}
		if RecordDecoder.Writer != nil {
			for _, data := range [][]byte{client, server} {
				if len(data) >= 3 && data[0] >= 20 && data[0] <= 24 && data[1] == 3 && data[2] <= 3 {
					return true
				}
			}
		}

		if len(client) >= 6 {

			if client[0] == recordTypeHandshake &&
				(client[1] == 0x03 && client[2] <= 0x04) {
				if len(client) >= 6 && client[5] == handshakeTypeClientHello {
					tlsLog.Info("TLS traffic detected - CanDecode matched (ClientHello)",
						zap.Int("clientLen", len(client)),
						zap.Int("serverLen", len(server)),
					)
					return true
				}
			}
		}

		if len(server) >= 6 {
			if server[0] == recordTypeHandshake &&
				(server[1] == 0x03 && server[2] <= 0x04) {
				if len(server) >= 6 && server[5] == handshakeTypeServerHello {
					tlsLog.Info("TLS traffic detected - CanDecode matched (ServerHello)",
						zap.Int("clientLen", len(client)),
						zap.Int("serverLen", len(server)),
					)
					return true
				}
			}
		}

		tlsLog.Debug("TLS CanDecode check failed",
			zap.Int("clientLen", len(client)),
			zap.Int("serverLen", len(server)),
		)
		return false
	},
	DeInit: func(sd *decoder.StreamDecoder) error {

		flushCertificates(sd)

		return tlsLog.Sync()
	},
	Factory: &tlsReader{},
	Typ:     core.TCP,
}

Decoder for protocol analysis and writing audit records to disk.

View Source
var RecordDecoder = &decoder.AbstractDecoder{
	Name: "TLSRecord", Type: types.Type_NC_TLSRecord,
	Description: "Stream-framed TLS record headers and known-plaintext alerts (no record payloads)",
}

A writer-only decoder: TLS retains its single stream reader and certificate path.

View Source
var ServerHelloDecoder = &decoder.AbstractDecoder{Name: "TLSServerHello", Type: types.Type_NC_TLSServerHello, Description: "Reassembled TLS server hellos"}

Functions

func AddOrUpdateCertificate

func AddOrUpdateCertificate(cert *types.TLSCertificate) bool

AddOrUpdateCertificate adds a new certificate or updates an existing one Returns true if this is a new certificate, false if it was updated Exported for testing

func GetCertificate

func GetCertificate(fingerprint string) *types.TLSCertificate

GetCertificate returns a certificate by its SHA256 fingerprint Exported for testing

func GetCertificateCount

func GetCertificateCount() int

GetCertificateCount returns the number of certificates in the cache Exported for testing

func ObserveUpgrade

func ObserveUpgrade(c *core.ConversationInfo, primary string)

ObserveUpgrade shares the TLS framer with validated cleartext protocol hand-offs.

func ResetCertificates

func ResetCertificates()

ResetCertificates clears all certificates from memory This should be called when resetting state between processing different files

Types

This section is empty.

Jump to

Keyboard shortcuts

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