protocol

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package protocol reaches the point where a TLS ClientHello can be sent: directly for TLS-wrapped services, or after a plaintext STARTTLS-style negotiation (SMTP, IMAP, POP3, FTP, LDAP, XMPP, PostgreSQL, MySQL). New protocols are added by implementing Adapter and registering it.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("server does not support TLS upgrade")

ErrNotSupported means the server does not offer TLS for this protocol.

Functions

func ByPort

func ByPort(port int) (string, bool)

ByPort returns the conventional protocol for port, if any.

func DefaultPort

func DefaultPort(name string) int

DefaultPort returns the usual port for a protocol (443 for unknown).

func Names

func Names() []string

Names lists registered protocol names.

func Printable

func Printable(b []byte) string

Printable renders a banner for display.

func SniffBanner

func SniffBanner(ctx context.Context, conn net.Conn, wait time.Duration) (string, []byte)

SniffBanner reads what a server sends without prompting. Servers that speak first (SMTP, FTP, IMAP, POP3, MySQL) identify themselves this way; silence suggests a TLS-first service.

Types

type Adapter

type Adapter interface {
	// Name is the --protocol value, e.g. "smtp".
	Name() string
	// STARTTLS reports whether a plaintext negotiation precedes TLS.
	STARTTLS() bool
	// Upgrade negotiates TLS on s. On return the next bytes written must be
	// the ClientHello. Direct-TLS adapters do nothing.
	Upgrade(ctx context.Context, s *Session, host string) error
}

Adapter performs a protocol-specific TLS upgrade on a fresh connection.

func Lookup

func Lookup(name string) (Adapter, error)

Lookup returns the adapter for a --protocol value.

type Detection

type Detection struct {
	Protocol string `json:"protocol"`
	Method   string `json:"method"`      // direct or starttls
	Via      string `json:"detected_by"` // flag, port, banner, default
	Banner   string `json:"banner,omitempty"`
}

Detection records how the protocol was chosen.

type Session

type Session struct {
	Conn net.Conn

	Log []string
	// contains filtered or unexported fields
}

Session wraps a connection during negotiation and keeps a transcript.

func NewSession

func NewSession(conn net.Conn) *Session

NewSession wraps conn.

func (*Session) ReadFull

func (s *Session) ReadFull(n int) ([]byte, error)

ReadFull reads exactly n bytes.

func (*Session) ReadLine

func (s *Session) ReadLine() (string, error)

ReadLine reads one CRLF-terminated line (max 4 KiB).

func (*Session) ReadUntil

func (s *Session) ReadUntil(markers []string, max int) (string, error)

ReadUntil reads until marker appears (max bytes).

func (*Session) Ready

func (s *Session) Ready() error

Ready verifies that no plaintext bytes are pending before TLS starts.

func (*Session) Send

func (s *Session) Send(line string) error

Send writes a command line.

func (*Session) Write

func (s *Session) Write(b []byte, desc string) error

Write writes raw bytes (binary protocols).

Jump to

Keyboard shortcuts

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