mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-31 00:04:43 +00:00
Introduce Version
field to Protocol
struct for dynamically switching the HTTP protocol to HTTP/2
This commit is contained in:
parent
5900d59567
commit
820dc09976
@ -237,9 +237,9 @@ func GetEntry(c *gin.Context) {
|
||||
// })
|
||||
// }
|
||||
extension := extensionsMap[entryData.ProtocolName]
|
||||
representation, _ := extension.Dissector.Represent(entryData.Entry)
|
||||
protocol, representation, _ := extension.Dissector.Represent(&entryData)
|
||||
c.JSON(http.StatusOK, tapApi.MizuEntryWrapper{
|
||||
Protocol: extension.Protocol,
|
||||
Protocol: protocol,
|
||||
Representation: string(representation),
|
||||
Data: entryData,
|
||||
})
|
||||
|
@ -10,11 +10,12 @@ type Protocol struct {
|
||||
Name string `json:"name"`
|
||||
LongName string `json:"long_name"`
|
||||
Abbreviation string `json:"abbreviation"`
|
||||
Version string `json:"version"`
|
||||
BackgroundColor string `json:"background_color"`
|
||||
ForegroundColor string `json:"foreground_color"`
|
||||
FontSize int8 `json:"font_size"`
|
||||
ReferenceLink string `json:"reference_link"`
|
||||
Ports []string `json:"outbound_ports"`
|
||||
Ports []string `json:"ports"`
|
||||
}
|
||||
|
||||
type Extension struct {
|
||||
@ -64,7 +65,7 @@ type Dissector interface {
|
||||
Dissect(b *bufio.Reader, isClient bool, tcpID *TcpID, emitter Emitter)
|
||||
Analyze(item *OutputChannelItem, entryId string, resolvedSource string, resolvedDestination string) *MizuEntry
|
||||
Summarize(entry *MizuEntry) *BaseEntryDetails
|
||||
Represent(entry string) ([]byte, error)
|
||||
Represent(entry *MizuEntry) (Protocol, []byte, error)
|
||||
}
|
||||
|
||||
type Emitting struct {
|
||||
@ -84,6 +85,7 @@ type MizuEntry struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
ProtocolName string `json:"protocol_key" gorm:"column:protocolKey"`
|
||||
ProtocolVersion string `json:"protocol_version" gorm:"column:protocolVersion"`
|
||||
Entry string `json:"entry,omitempty" gorm:"column:entry"`
|
||||
EntryId string `json:"entryId" gorm:"column:entryId"`
|
||||
Url string `json:"url" gorm:"column:url"`
|
||||
|
@ -15,6 +15,7 @@ var protocol api.Protocol = api.Protocol{
|
||||
Name: "amqp",
|
||||
LongName: "Advanced Message Queuing Protocol 0-9-1",
|
||||
Abbreviation: "AMQP",
|
||||
Version: "0-9-1",
|
||||
BackgroundColor: "#ff6600",
|
||||
ForegroundColor: "#ffffff",
|
||||
FontSize: 12,
|
||||
@ -246,6 +247,7 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, entryId string, resolve
|
||||
entryBytes, _ := json.Marshal(item.Pair)
|
||||
return &api.MizuEntry{
|
||||
ProtocolName: protocol.Name,
|
||||
ProtocolVersion: protocol.Version,
|
||||
EntryId: entryId,
|
||||
Entry: string(entryBytes),
|
||||
Url: fmt.Sprintf("%s%s", service, summary),
|
||||
@ -290,9 +292,9 @@ func (d dissecting) Summarize(entry *api.MizuEntry) *api.BaseEntryDetails {
|
||||
}
|
||||
}
|
||||
|
||||
func (d dissecting) Represent(entry string) ([]byte, error) {
|
||||
func (d dissecting) Represent(entry *api.MizuEntry) (api.Protocol, []byte, error) {
|
||||
var root map[string]interface{}
|
||||
json.Unmarshal([]byte(entry), &root)
|
||||
json.Unmarshal([]byte(entry.Entry), &root)
|
||||
representation := make(map[string]interface{}, 0)
|
||||
request := root["request"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||
var repRequest []interface{}
|
||||
@ -323,12 +325,9 @@ func (d dissecting) Represent(entry string) ([]byte, error) {
|
||||
repRequest = representBasicConsume(details)
|
||||
break
|
||||
}
|
||||
// response := root["response"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||
// repRequest := representRequest(request)
|
||||
// repResponse := representResponse(response)
|
||||
representation["request"] = repRequest
|
||||
// representation["response"] = repResponse
|
||||
return json.Marshal(representation)
|
||||
object, err := json.Marshal(representation)
|
||||
return protocol, object, err
|
||||
}
|
||||
|
||||
var Dissector dissecting
|
||||
|
@ -19,20 +19,22 @@ var protocol api.Protocol = api.Protocol{
|
||||
Name: "http",
|
||||
LongName: "Hypertext Transfer Protocol -- HTTP/1.1",
|
||||
Abbreviation: "HTTP",
|
||||
Version: "1.1",
|
||||
BackgroundColor: "#205cf5",
|
||||
ForegroundColor: "#ffffff",
|
||||
FontSize: 12,
|
||||
ReferenceLink: "https://datatracker.ietf.org/doc/html/rfc2616",
|
||||
Ports: []string{"80", "8080"},
|
||||
Ports: []string{"80", "8080", "50051"},
|
||||
}
|
||||
|
||||
var http2Protocol api.Protocol = api.Protocol{
|
||||
Name: "http",
|
||||
LongName: "Hypertext Transfer Protocol Version 2 (HTTP/2) (gRPC)",
|
||||
Abbreviation: "HTTP/2",
|
||||
Version: "2.0",
|
||||
BackgroundColor: "#244c5a",
|
||||
ForegroundColor: "#ffffff",
|
||||
FontSize: 12,
|
||||
FontSize: 11,
|
||||
ReferenceLink: "https://datatracker.ietf.org/doc/html/rfc7540",
|
||||
Ports: []string{"80", "8080"},
|
||||
}
|
||||
@ -113,6 +115,7 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, entryId string, resolve
|
||||
service := fmt.Sprintf("http://%s", host)
|
||||
return &api.MizuEntry{
|
||||
ProtocolName: protocol.Name,
|
||||
ProtocolVersion: item.Protocol.Version,
|
||||
EntryId: entryId,
|
||||
Entry: string(entryBytes),
|
||||
Url: fmt.Sprintf("%s%s", service, request["url"].(string)),
|
||||
@ -133,9 +136,15 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, entryId string, resolve
|
||||
}
|
||||
|
||||
func (d dissecting) Summarize(entry *api.MizuEntry) *api.BaseEntryDetails {
|
||||
var p api.Protocol
|
||||
if entry.ProtocolVersion == "2.0" {
|
||||
p = http2Protocol
|
||||
} else {
|
||||
p = protocol
|
||||
}
|
||||
return &api.BaseEntryDetails{
|
||||
Id: entry.EntryId,
|
||||
Protocol: protocol,
|
||||
Protocol: p,
|
||||
Url: entry.Url,
|
||||
RequestSenderIp: entry.RequestSenderIp,
|
||||
Service: entry.Service,
|
||||
@ -273,9 +282,15 @@ func representResponse(response map[string]interface{}) []interface{} {
|
||||
return repResponse
|
||||
}
|
||||
|
||||
func (d dissecting) Represent(entry string) ([]byte, error) {
|
||||
func (d dissecting) Represent(entry *api.MizuEntry) (api.Protocol, []byte, error) {
|
||||
var p api.Protocol
|
||||
if entry.ProtocolVersion == "2.0" {
|
||||
p = http2Protocol
|
||||
} else {
|
||||
p = protocol
|
||||
}
|
||||
var root map[string]interface{}
|
||||
json.Unmarshal([]byte(entry), &root)
|
||||
json.Unmarshal([]byte(entry.Entry), &root)
|
||||
representation := make(map[string]interface{}, 0)
|
||||
request := root["request"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||
response := root["response"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||
@ -283,7 +298,8 @@ func (d dissecting) Represent(entry string) ([]byte, error) {
|
||||
repResponse := representResponse(response)
|
||||
representation["request"] = repRequest
|
||||
representation["response"] = repResponse
|
||||
return json.Marshal(representation)
|
||||
object, err := json.Marshal(representation)
|
||||
return p, object, err
|
||||
}
|
||||
|
||||
var Dissector dissecting
|
||||
|
@ -13,6 +13,7 @@ var _protocol api.Protocol = api.Protocol{
|
||||
Name: "kafka",
|
||||
LongName: "Apache Kafka Protocol",
|
||||
Abbreviation: "KAFKA",
|
||||
Version: "12",
|
||||
BackgroundColor: "#000000",
|
||||
ForegroundColor: "#ffffff",
|
||||
FontSize: 11,
|
||||
@ -116,6 +117,7 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, entryId string, resolve
|
||||
entryBytes, _ := json.Marshal(item.Pair)
|
||||
return &api.MizuEntry{
|
||||
ProtocolName: _protocol.Name,
|
||||
ProtocolVersion: _protocol.Version,
|
||||
EntryId: entryId,
|
||||
Entry: string(entryBytes),
|
||||
Url: fmt.Sprintf("%s%s", service, summary),
|
||||
@ -159,9 +161,9 @@ func (d dissecting) Summarize(entry *api.MizuEntry) *api.BaseEntryDetails {
|
||||
}
|
||||
}
|
||||
|
||||
func (d dissecting) Represent(entry string) ([]byte, error) {
|
||||
func (d dissecting) Represent(entry *api.MizuEntry) (api.Protocol, []byte, error) {
|
||||
var root map[string]interface{}
|
||||
json.Unmarshal([]byte(entry), &root)
|
||||
json.Unmarshal([]byte(entry.Entry), &root)
|
||||
representation := make(map[string]interface{}, 0)
|
||||
request := root["request"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||
response := root["response"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||
@ -205,7 +207,8 @@ func (d dissecting) Represent(entry string) ([]byte, error) {
|
||||
|
||||
representation["request"] = repRequest
|
||||
representation["response"] = repResponse
|
||||
return json.Marshal(representation)
|
||||
object, err := json.Marshal(representation)
|
||||
return _protocol, object, err
|
||||
}
|
||||
|
||||
var Dissector dissecting
|
||||
|
@ -9,7 +9,7 @@ export interface ProtocolInterface {
|
||||
foreground_color: string
|
||||
font_size: number
|
||||
reference_link: string
|
||||
outbound_ports: string[]
|
||||
ports: string[]
|
||||
inbound_ports: string
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ const Protocol: React.FC<ProtocolProps> = ({protocol, horizontal}) => {
|
||||
style={{
|
||||
backgroundColor: protocol.background_color,
|
||||
color: protocol.foreground_color,
|
||||
fontSize: protocol.font_size * 1.1,
|
||||
fontSize: 13,
|
||||
}}
|
||||
title={protocol.abbreviation}
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user