Refactored Protocol.Name -> Protocol.Type; added Encapsulation field Refactored TLS parsing; added support for ALPN
96 lines
2.0 KiB
Go
96 lines
2.0 KiB
Go
package protocol
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Protocols supported by this package.
|
|
const (
|
|
TypeACME = "ACME"
|
|
TypeCoAP = "CoAP"
|
|
TypeDNS = "DNS"
|
|
TypeFTP = "FTP"
|
|
TypeHTTP = "HTTP"
|
|
TypeIRC = "IRC"
|
|
TypeIMAP = "IMAP"
|
|
TypeJabber = TypeXMPP
|
|
TypeManageSieve = "ManageSieve"
|
|
TypeMosquitto = TypeMQTT
|
|
TypeMQTT = "MQTT"
|
|
TypeMySQL = "MySQL"
|
|
TypeNNTP = "NNTP"
|
|
TypePOP3 = "POP3"
|
|
TypePgSQL = TypePostgreSQL
|
|
TypePostgreSQL = "PostgreSQL"
|
|
TypeRADIUS = "RADIUS"
|
|
TypeSamba = TypeSMB
|
|
TypeSIP = "SIP"
|
|
TypeSMB = "SMB"
|
|
TypeSSH = "SSH"
|
|
TypeSSL = "SSL"
|
|
TypeSTUN = "STUN"
|
|
TypeSunRPC = "SunRPC"
|
|
TypeTLS = "TLS"
|
|
TypeWebRTC = "WebRTC"
|
|
TypeXMPP = "XMPP"
|
|
)
|
|
|
|
// Protocol description.
|
|
type Protocol struct {
|
|
// Type of protocol, usually one of the constants defined in this package.
|
|
Type string
|
|
|
|
// Encapsulation type, usually one of the constants defined in this package.
|
|
//
|
|
// Empty if there is no encapsulation.
|
|
Encapsulation string
|
|
|
|
// Version of the protocol. Unknown versions are marked with [UnknownVersion].
|
|
Version Version
|
|
}
|
|
|
|
func (proto Protocol) String() string {
|
|
var s string
|
|
if proto.Encapsulation != "" {
|
|
s = proto.Type + " (over " + proto.Encapsulation + ")"
|
|
} else {
|
|
s = proto.Type
|
|
}
|
|
if proto.Version == UnknownVersion {
|
|
return s
|
|
}
|
|
return s + " version " + proto.Version.String()
|
|
}
|
|
|
|
// Version of a protocol.
|
|
type Version struct {
|
|
Major int
|
|
Minor int
|
|
Patch int
|
|
Extra string
|
|
}
|
|
|
|
// UnknownVersion
|
|
var UnknownVersion Version
|
|
|
|
func (v Version) String() string {
|
|
if v == UnknownVersion {
|
|
return "unknown"
|
|
}
|
|
|
|
p := make([]string, 0, 3)
|
|
p = append(p, strconv.Itoa(v.Major))
|
|
if v.Minor >= 0 {
|
|
p = append(p, strconv.Itoa(v.Minor))
|
|
if v.Patch >= 0 {
|
|
p = append(p, strconv.Itoa(v.Patch))
|
|
}
|
|
}
|
|
s := strings.Join(p, ".")
|
|
if v.Extra != "" {
|
|
return s + "-" + v.Extra
|
|
}
|
|
return s
|
|
}
|