Fix various issues found when testing

This commit is contained in:
kayos@tcp.direct 2022-11-10 12:05:48 -08:00
parent 48f15ef93b
commit 7e7bec5310
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
11 changed files with 170 additions and 143 deletions

2
.gitignore vendored
View File

@ -25,3 +25,5 @@ build/*
dist/*
.vscode/*
.idea/

View File

@ -346,12 +346,14 @@ func runBytesReadLimitTrial(t *testing.T, connector timeoutConnector, idx int, m
expectedSize = cfg.limit
}
defer func() {
if err = conn.Close(); err != nil {
t.Errorf("Error closing connection: %v", err)
}
if conn.BytesRead != expectedSize {
result = fmt.Errorf("BytesRead(%d) != expected(%d)", conn.BytesRead, expectedSize)
t.Error(result)
}
}()
defer conn.Close()
return method(cfg, t, conn, idx)
}

View File

@ -3,6 +3,7 @@ package zgrab2
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net"
@ -111,7 +112,7 @@ func _write(writer io.Writer, data []byte) error {
// Run the configured server. As soon as it returns, it is listening.
// Returns a channel that receives a timeoutTestError on error, or is closed on successful completion.
func (cfg *connTimeoutTestConfig) runServer(t *testing.T) (chan *timeoutTestError) {
func (cfg *connTimeoutTestConfig) runServer(t *testing.T) chan *timeoutTestError {
errorChan := make(chan *timeoutTestError)
if cfg.endpoint != "" {
// Only listen on localhost
@ -122,7 +123,11 @@ func (cfg *connTimeoutTestConfig) runServer(t *testing.T) (chan *timeoutTestErro
logrus.Fatalf("Error listening: %v", err)
}
go func() {
defer listener.Close()
defer func() {
if err = listener.Close(); err != nil {
t.Errorf("%s: error closing connection: %v", cfg.name, err)
}
}()
defer close(errorChan)
time.Sleep(cfg.acceptDelay)
sock, err := listener.Accept()
@ -130,7 +135,11 @@ func (cfg *connTimeoutTestConfig) runServer(t *testing.T) (chan *timeoutTestErro
errorChan <- serverError(testStepConnect, err)
return
}
defer sock.Close()
defer func() {
if err = sock.Close(); err != nil {
t.Errorf("%s: error closing connection: %v", cfg.name, err)
}
}()
time.Sleep(cfg.writeDelay)
if err := _write(sock, cfg.serverToClientPayload); err != nil {
errorChan <- serverError(testStepWrite, err)
@ -208,7 +217,11 @@ func (cfg *connTimeoutTestConfig) runClient(t *testing.T) (testStep, error) {
if err != nil {
return testStepConnect, err
}
defer conn.Close()
defer func() {
if err = conn.Close(); err != nil {
t.Errorf("%s: error closing connection: %v", cfg.name, err)
}
}()
buf := make([]byte, len(cfg.serverToClientPayload))
_, err = io.ReadFull(conn, buf)
if err != nil {
@ -244,7 +257,10 @@ func (cfg *connTimeoutTestConfig) run(t *testing.T) {
var ret *timeoutTestError
select {
case err := <-serverError:
t.Fatalf("%s: Server error: %v", cfg.name, err)
if !errors.Is(err.cause, io.EOF) {
t.Fatalf("%s: Server error: %v", cfg.name, err)
}
ret = <-done
case ret = <-done:
if ret == nil {
t.Fatalf("Channel unexpectedly closed")
@ -307,7 +323,7 @@ var connTestConfigs = []connTimeoutTestConfig{
serverToClientPayload: []byte("abc"),
clientToServerPayload: []byte("defghi"),
failStep: testStepConnect,
failStep: testStepConnect,
failError: "i/o timeout",
},
// short session timeout, medium connect timeout, with connect to nonexistent endpoint.
@ -326,7 +342,7 @@ var connTestConfigs = []connTimeoutTestConfig{
serverToClientPayload: []byte("abc"),
clientToServerPayload: []byte("defghi"),
failStep: testStepConnect,
failStep: testStepConnect,
failError: "i/o timeout",
},
// Get an IO timeout on the read.

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/zmap/zgrab2
go 1.12
require (
github.com/RumbleDiscovery/jarm-go v0.0.6 // indirect
github.com/RumbleDiscovery/jarm-go v0.0.6
github.com/golang/protobuf v1.5.2 // indirect
github.com/prometheus/client_golang v1.10.0
github.com/prometheus/common v0.20.0 // indirect

31
go.sum
View File

@ -78,7 +78,6 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4er
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
@ -98,6 +97,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
@ -146,9 +146,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@ -219,15 +217,12 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8=
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.10.0 h1:/o0BDeWzLWXNZ+4q5gXltUvaMpJqckTa+jTNoB+z4cg=
github.com/prometheus/client_golang v1.10.0/go.mod h1:WJM3cc3yu7XKBKa/I8WeZm+V3eltZnBwfENSU7mdogU=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@ -235,8 +230,6 @@ github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo=
github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc=
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
@ -245,8 +238,6 @@ github.com/prometheus/common v0.20.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE=
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
@ -261,7 +252,6 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
@ -279,28 +269,21 @@ github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5J
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/weppos/publicsuffix-go v0.4.0 h1:YSnfg3V65LcCFKtIGKGoBhkyKolEd0hlipcXaOjdnQw=
github.com/weppos/publicsuffix-go v0.4.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k=
github.com/weppos/publicsuffix-go v0.13.1-0.20210331065111-e81257c67567 h1:FLYs2zckqHm2ZGYVgDZlrTG8HjJuNDddIRy0jKIzU1E=
github.com/weppos/publicsuffix-go v0.13.1-0.20210331065111-e81257c67567/go.mod h1:HYux0V0Zi04bHNwOHy4cXJVz/TQjYonnF6aoYhj+3QE=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/zmap/rc2 v0.0.0-20131011165748-24b9757f5521 h1:kKCF7VX/wTmdg2ZjEaqlq99Bjsoiz7vH6sFniF/vI4M=
github.com/zmap/rc2 v0.0.0-20131011165748-24b9757f5521/go.mod h1:3YZ9o3WnatTIZhuOtot4IcUfzoKVjUHqu6WALIyI0nE=
github.com/zmap/rc2 v0.0.0-20190804163417-abaa70531248 h1:Nzukz5fNOBIHOsnP+6I79kPx3QhLv8nBy2mfFhBRq30=
github.com/zmap/rc2 v0.0.0-20190804163417-abaa70531248/go.mod h1:3YZ9o3WnatTIZhuOtot4IcUfzoKVjUHqu6WALIyI0nE=
github.com/zmap/zcertificate v0.0.0-20180516150559-0e3d58b1bac4/go.mod h1:5iU54tB79AMBcySS0R2XIyZBAVmeHranShAFELYx7is=
github.com/zmap/zcrypto v0.0.0-20200508204656-27de22294d44 h1:Nj6ai45vjEtu1gvYig3lm8BAWbVgp4hnJ5qSsAc1Nps=
github.com/zmap/zcrypto v0.0.0-20200508204656-27de22294d44/go.mod h1:TxpejqcVKQjQaVVmMGfzx5HnmFMdIU+vLtaCyPBfGI4=
github.com/zmap/zcrypto v0.0.0-20210331113710-23c79953ef34 h1:UPOTdCVa20EU0wZmm3uy/nVfiNinshKrOnras2qTtjo=
github.com/zmap/zcrypto v0.0.0-20210331113710-23c79953ef34/go.mod h1:J/LL3Pv9cqgWsRZ5xsZSxj5O4nVKL63ASHm4k6KTc/Y=
github.com/zmap/zflags v1.4.0-beta.1 h1:jzZ+wKTCksS/ltf9q19gYJ6zJuqRULuRdSWBPueEiZ8=
github.com/zmap/zflags v1.4.0-beta.1/go.mod h1:HXDUD+uue8yeLHr0eXx1lvY6CvMiHbTKw5nGmA9OUoo=
github.com/zmap/zflags v1.4.0-beta.1.0.20200204220219-9d95409821b6 h1:XYA+NN2AS4mRmIDVu2nCtrjU17zKlRihO3MnlcmueUw=
github.com/zmap/zflags v1.4.0-beta.1.0.20200204220219-9d95409821b6/go.mod h1:HXDUD+uue8yeLHr0eXx1lvY6CvMiHbTKw5nGmA9OUoo=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
@ -320,8 +303,6 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7 h1:0hQKqeLdqlt5iIwVOBErRisrHJAN57yOiPRQItI20fU=
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@ -352,8 +333,6 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190912160710-24e19bdeb0f2 h1:4dVFTC832rPn4pomLSz1vA+are2+dU19w1H8OngV7nc=
golang.org/x/net v0.0.0-20190912160710-24e19bdeb0f2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200528225125-3c3fba18258b/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
@ -385,10 +364,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190913121621-c3b328c6e5a7 h1:wYqz/tQaWUgGKyx+B/rssSE6wkIKdY5Ee6ryOmzarIg=
golang.org/x/sys v0.0.0-20190913121621-c3b328c6e5a7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -407,7 +383,6 @@ golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
@ -430,6 +405,7 @@ golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapK
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
@ -474,7 +450,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -1,29 +1,31 @@
// Package mysql is a very basic MySQL connection library.
// Usage:
// var sql *mysql.Connection := mysql.NewConnection(&mysql.Config{
// Host: targetHost,
// Port: targetPort,
// })
// err := sql.Connect()
// defer sql.Disconnect()
//
// var sql *mysql.Connection := mysql.NewConnection(&mysql.Config{
// Host: targetHost,
// Port: targetPort,
// })
// err := sql.Connect()
// defer sql.Disconnect()
//
// The Connection exports the connection details via the ConnectionLog.
package mysql
import (
"bufio"
"encoding/base64"
"encoding/binary"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net"
"strings"
"time"
log "github.com/sirupsen/logrus"
"github.com/zmap/zgrab2"
"time"
"io"
)
const (
@ -429,7 +431,7 @@ func (c *Connection) readOKPacket(body []byte) (*OKPacket, error) {
ret.StatusFlags = binary.LittleEndian.Uint16(rest[0:2])
rest = rest[2:]
if flags&CLIENT_PROTOCOL_41 != 0 {
log.Debugf("readOKPacket: CapabilityFlags = 0x%x, so reading Warnings")
log.Debugf("readOKPacket: CapabilityFlags = 0x%x, so reading Warnings", flags&CLIENT_PROTOCOL_41)
ret.Warnings = binary.LittleEndian.Uint16(rest[0:2])
rest = rest[2:]
}
@ -512,7 +514,7 @@ func (e *ERRPacket) GetErrorID() string {
func (e *ERRPacket) GetScanError() *zgrab2.ScanError {
return &zgrab2.ScanError{
Status: zgrab2.SCAN_APPLICATION_ERROR,
Err: e,
Err: e,
}
}
@ -639,7 +641,7 @@ func trunc(body []byte, n int) (result string) {
// 16 bytes = 32 bytes hex * 2 + ellipses = 3 * 2 + len("[%d bytes]") = 8 + log10(len - 32)
// max len = 24 bits ~= 16 million = 8 digits
// = 64 + 6 + 8 + 8 <= 96
return fmt.Sprintf("%x...[%d bytes]...%x", body[:16], n - 32, body[n-16:])
return fmt.Sprintf("%x...[%d bytes]...%x", body[:16], n-32, body[n-16:])
}
// Read a packet and sequence identifier off of the given connection
@ -663,7 +665,7 @@ func (c *Connection) readPacket() (*ConnectionLogEntry, error) {
if packetSize > 0x00080000 {
var temp [32]byte
// try to read up to 32 bytes, or whatever we can in 5ms, to give context for the error.
c.Connection.SetReadDeadline(time.Now().Add(5 * time.Millisecond))
_ = c.Connection.SetReadDeadline(time.Now().Add(5 * time.Millisecond))
n, _ := reader.Read(temp[:])
err := fmt.Errorf("packet too large (0x%08x bytes): header=%x, next %d bytes=%x", packetSize, header, n, temp[:n])
log.Debugf("Received suspiciously large packet: %s", err.Error())
@ -802,8 +804,8 @@ func readLenInt(body []byte) (uint64, []byte, error) {
return uint64(v), body[1:], nil
}
size := int(v - 0xfa)
if bodyLen - 1 < size {
return 0, nil, fmt.Errorf("invalid data: first byte=0x%02x, required size=%d, got %d", v, size, bodyLen - 1)
if bodyLen-1 < size {
return 0, nil, fmt.Errorf("invalid data: first byte=0x%02x, required size=%d, got %d", v, size, bodyLen-1)
}
switch v {
case 0xfb:
@ -817,7 +819,7 @@ func readLenInt(body []byte) (uint64, []byte, error) {
return uint64(binary.LittleEndian.Uint32(body[1:5]) & 0x00ffffff), body[4:], nil
case 0xfe:
if bodyLen < 9 {
return 0, nil, fmt.Errorf("invalid data: first byte=0xfe, required size=8, got %d", bodyLen - 1)
return 0, nil, fmt.Errorf("invalid data: first byte=0xfe, required size=8, got %d", bodyLen-1)
}
// eight little-endian bytes
return binary.LittleEndian.Uint64(body[1:9]), body[9:], nil

View File

@ -151,10 +151,10 @@ type kexAlgorithm interface {
// responsible for verifying the host key signature.
Client(p packetConn, rand io.Reader, magics *handshakeMagics, c *Config) (*kexResult, error)
// Create a JSON object for the kexAlgorithm group
// MarshalJSON creates a JSON object for the kexAlgorithm group
MarshalJSON() ([]byte, error)
// Get a new instance of this interface
// GetNew acquires a new instance of this interface
// Because the base x/crypto package passes the same object to each connection
GetNew(keyType string) kexAlgorithm
}
@ -683,7 +683,14 @@ func (kex *curve25519sha256) Client(c packetConn, rand io.Reader, magics *handsh
var servPub, secret [32]byte
copy(servPub[:], reply.EphemeralPubKey)
curve25519.ScalarMult(&secret, &kp.priv, &servPub)
secretBulk, err := curve25519.X25519(kp.priv[:32], servPub[:32])
if err != nil {
return nil, err
}
if len(secretBulk) != 32 {
return nil, errors.New("ssh: curve25519 secret has wrong length")
}
copy(secret[:], secretBulk)
if subtle.ConstantTimeCompare(secret[:], curve25519Zeros[:]) == 1 {
return nil, errors.New("ssh: peer's curve25519 public value has wrong order")
}

View File

@ -25,13 +25,17 @@ func TestKexes(t *testing.T) {
c := make(chan kexResultErr, 1)
var magics handshakeMagics
go func() {
r, e := kex.Client(a, rand.Reader, &magics)
a.Close()
r, e := kex.Client(a, rand.Reader, &magics, &Config{})
if err := a.Close(); err != nil {
t.Error(err)
}
c <- kexResultErr{r, e}
}()
go func() {
r, e := kex.Server(b, rand.Reader, &magics, testSigners["ecdsa"])
b.Close()
r, e := kex.Server(b, rand.Reader, &magics, testSigners["ecdsa"], &Config{})
if err := b.Close(); err != nil {
t.Errorf("%s: %v", name, err)
}
s <- kexResultErr{r, e}
}()

View File

@ -29,6 +29,7 @@ import (
"golang.org/x/crypto/ed25519"
ztoolsX509 "github.com/zmap/zcrypto/x509"
ztoolsKeys "github.com/zmap/zgrab2/tools/keys"
)
@ -377,12 +378,12 @@ func (r *rsaPublicKey) CryptoPublicKey() crypto.PublicKey {
type dsaPublicKey dsa.PublicKey
func (r *dsaPublicKey) Type() string {
func (dpk *dsaPublicKey) Type() string {
return "ssh-dss"
}
func (r *dsaPublicKey) MarshalJSON() ([]byte, error) {
temp := ztoolsX509.GetDSAPublicKeyJSON((*dsa.PublicKey)(r))
func (dpk *dsaPublicKey) MarshalJSON() ([]byte, error) {
temp := ztoolsX509.GetDSAPublicKeyJSON((*dsa.PublicKey)(dpk))
return json.Marshal(temp)
}
@ -407,26 +408,26 @@ func parseDSA(in []byte) (out PublicKey, rest []byte, err error) {
return key, w.Rest, nil
}
func (k *dsaPublicKey) Marshal() []byte {
func (dpk *dsaPublicKey) Marshal() []byte {
// DSA publickey struct layout should match the struct used by
// parseDSACert in the x/github.com/zmap/zgrab2/lib/agent package.
w := struct {
Name string
P, Q, G, Y *big.Int
}{
k.Type(),
k.P,
k.Q,
k.G,
k.Y,
dpk.Type(),
dpk.P,
dpk.Q,
dpk.G,
dpk.Y,
}
return Marshal(&w)
}
func (k *dsaPublicKey) Verify(data []byte, sig *Signature) error {
if sig.Format != k.Type() {
return fmt.Errorf("ssh: signature type %s for key type %s", sig.Format, k.Type())
func (dpk *dsaPublicKey) Verify(data []byte, sig *Signature) error {
if sig.Format != dpk.Type() {
return fmt.Errorf("ssh: signature type %s for key type %s", sig.Format, dpk.Type())
}
h := crypto.SHA1.New()
h.Write(data)
@ -442,14 +443,14 @@ func (k *dsaPublicKey) Verify(data []byte, sig *Signature) error {
}
r := new(big.Int).SetBytes(sig.Blob[:20])
s := new(big.Int).SetBytes(sig.Blob[20:])
if dsa.Verify((*dsa.PublicKey)(k), digest, r, s) {
if dsa.Verify((*dsa.PublicKey)(dpk), digest, r, s) {
return nil
}
return errors.New("ssh: signature did not verify")
}
func (k *dsaPublicKey) CryptoPublicKey() crypto.PublicKey {
return (*dsa.PublicKey)(k)
func (dpk *dsaPublicKey) CryptoPublicKey() crypto.PublicKey {
return (*dsa.PublicKey)(dpk)
}
type dsaPrivateKey struct {

View File

@ -6,7 +6,6 @@ package ssh
import (
"bytes"
"crypto/dsa"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
@ -17,8 +16,9 @@ import (
"strings"
"testing"
"github.com/zmap/zgrab2/lib/ssh/testdata"
"golang.org/x/crypto/ed25519"
"github.com/zmap/zgrab2/lib/ssh/testdata"
)
func rawKey(pub PublicKey) interface{} {
@ -26,7 +26,7 @@ func rawKey(pub PublicKey) interface{} {
case *rsaPublicKey:
return (*rsa.PublicKey)(k)
case *dsaPublicKey:
return (*dsa.PublicKey)(k)
return k
case *ecdsaPublicKey:
return (*ecdsa.PublicKey)(k)
case ed25519PublicKey:
@ -115,12 +115,12 @@ func TestKeySignVerify(t *testing.T) {
func TestParseRSAPrivateKey(t *testing.T) {
key := testPrivateKeys["rsa"]
rsa, ok := key.(*rsa.PrivateKey)
rsaKey, ok := key.(*rsa.PrivateKey)
if !ok {
t.Fatalf("got %T, want *rsa.PrivateKey", rsa)
t.Fatalf("got %T, want *rsa.PrivateKey", rsaKey)
}
if err := rsa.Validate(); err != nil {
if err := rsaKey.Validate(); err != nil {
t.Errorf("Validate: %v", err)
}
}
@ -177,19 +177,23 @@ func TestParseDSA(t *testing.T) {
// Tests for authorized_keys parsing.
// getTestKey returns a public key, and its base64 encoding.
func getTestKey() (PublicKey, string) {
func getTestKey(t *testing.T) (PublicKey, string) {
k := testPublicKeys["rsa"]
b := &bytes.Buffer{}
e := base64.NewEncoder(base64.StdEncoding, b)
e.Write(k.Marshal())
e.Close()
if _, err := e.Write(k.Marshal()); err != nil {
t.Fatalf("base64 encode: %v", err)
}
if err := e.Close(); err != nil {
t.Fatalf("base64 encode: %v", err)
}
return k, b.String()
}
func TestMarshalParsePublicKey(t *testing.T) {
pub, pubSerialized := getTestKey()
pub, pubSerialized := getTestKey(t)
line := fmt.Sprintf("%s %s user@host", pub.Type(), pubSerialized)
authKeys := MarshalAuthorizedKey(pub)
@ -229,7 +233,7 @@ func testAuthorizedKeys(t *testing.T, authKeys []byte, expected []authResult) {
var r authResult
var err error
r.pubKey, r.comments, r.options, rest, err = ParseAuthorizedKey(rest)
r.ok = (err == nil)
r.ok = err == nil
t.Log(err)
r.rest = string(rest)
values = append(values, r)
@ -241,7 +245,7 @@ func testAuthorizedKeys(t *testing.T, authKeys []byte, expected []authResult) {
}
func TestAuthorizedKeyBasic(t *testing.T) {
pub, pubSerialized := getTestKey()
pub, pubSerialized := getTestKey(t)
line := "ssh-rsa " + pubSerialized + " user@host"
testAuthorizedKeys(t, []byte(line),
[]authResult{
@ -250,7 +254,7 @@ func TestAuthorizedKeyBasic(t *testing.T) {
}
func TestAuth(t *testing.T) {
pub, pubSerialized := getTestKey()
pub, pubSerialized := getTestKey(t)
authWithOptions := []string{
`# comments to ignore before any keys...`,
``,
@ -275,49 +279,49 @@ func TestAuth(t *testing.T) {
}
func TestAuthWithQuotedSpaceInEnv(t *testing.T) {
pub, pubSerialized := getTestKey()
pub, pubSerialized := getTestKey(t)
authWithQuotedSpaceInEnv := []byte(`env="HOME=/home/root dir",no-port-forwarding ssh-rsa ` + pubSerialized + ` user@host`)
testAuthorizedKeys(t, []byte(authWithQuotedSpaceInEnv), []authResult{
testAuthorizedKeys(t, authWithQuotedSpaceInEnv, []authResult{
{pub, []string{`env="HOME=/home/root dir"`, "no-port-forwarding"}, "user@host", "", true},
})
}
func TestAuthWithQuotedCommaInEnv(t *testing.T) {
pub, pubSerialized := getTestKey()
pub, pubSerialized := getTestKey(t)
authWithQuotedCommaInEnv := []byte(`env="HOME=/home/root,dir",no-port-forwarding ssh-rsa ` + pubSerialized + ` user@host`)
testAuthorizedKeys(t, []byte(authWithQuotedCommaInEnv), []authResult{
testAuthorizedKeys(t, authWithQuotedCommaInEnv, []authResult{
{pub, []string{`env="HOME=/home/root,dir"`, "no-port-forwarding"}, "user@host", "", true},
})
}
func TestAuthWithQuotedQuoteInEnv(t *testing.T) {
pub, pubSerialized := getTestKey()
pub, pubSerialized := getTestKey(t)
authWithQuotedQuoteInEnv := []byte(`env="HOME=/home/\"root dir",no-port-forwarding` + "\t" + `ssh-rsa` + "\t" + pubSerialized + ` user@host`)
authWithDoubleQuotedQuote := []byte(`no-port-forwarding,env="HOME=/home/ \"root dir\"" ssh-rsa ` + pubSerialized + "\t" + `user@host`)
testAuthorizedKeys(t, []byte(authWithQuotedQuoteInEnv), []authResult{
testAuthorizedKeys(t, authWithQuotedQuoteInEnv, []authResult{
{pub, []string{`env="HOME=/home/\"root dir"`, "no-port-forwarding"}, "user@host", "", true},
})
testAuthorizedKeys(t, []byte(authWithDoubleQuotedQuote), []authResult{
testAuthorizedKeys(t, authWithDoubleQuotedQuote, []authResult{
{pub, []string{"no-port-forwarding", `env="HOME=/home/ \"root dir\""`}, "user@host", "", true},
})
}
func TestAuthWithInvalidSpace(t *testing.T) {
_, pubSerialized := getTestKey()
_, pubSerialized := getTestKey(t)
authWithInvalidSpace := []byte(`env="HOME=/home/root dir", no-port-forwarding ssh-rsa ` + pubSerialized + ` user@host
#more to follow but still no valid keys`)
testAuthorizedKeys(t, []byte(authWithInvalidSpace), []authResult{
testAuthorizedKeys(t, authWithInvalidSpace, []authResult{
{nil, nil, "", "", false},
})
}
func TestAuthWithMissingQuote(t *testing.T) {
pub, pubSerialized := getTestKey()
pub, pubSerialized := getTestKey(t)
authWithMissingQuote := []byte(`env="HOME=/home/root,no-port-forwarding ssh-rsa ` + pubSerialized + ` user@host
env="HOME=/home/root",shared-control ssh-rsa ` + pubSerialized + ` user@host`)
testAuthorizedKeys(t, []byte(authWithMissingQuote), []authResult{
testAuthorizedKeys(t, authWithMissingQuote, []authResult{
{pub, []string{`env="HOME=/home/root"`, `shared-control`}, "user@host", "", true},
})
}
@ -414,7 +418,7 @@ var knownHostsParseTests = []struct {
}
func TestKnownHostsParsing(t *testing.T) {
rsaPub, rsaPubSerialized := getTestKey()
rsaPub, rsaPubSerialized := getTestKey(t)
for i, test := range knownHostsParseTests {
var expectedKey PublicKey
@ -462,7 +466,7 @@ func TestKnownHostsParsing(t *testing.T) {
}
func TestFingerprintLegacyMD5(t *testing.T) {
pub, _ := getTestKey()
pub, _ := getTestKey(t)
fingerprint := FingerprintLegacyMD5(pub)
want := "fb:61:6d:1a:e3:f0:95:45:3c:a0:79:be:4a:93:63:66" // ssh-keygen -lf -E md5 rsa
if fingerprint != want {
@ -471,7 +475,7 @@ func TestFingerprintLegacyMD5(t *testing.T) {
}
func TestFingerprintSHA256(t *testing.T) {
pub, _ := getTestKey()
pub, _ := getTestKey(t)
fingerprint := FingerprintSHA256(pub)
want := "SHA256:Anr3LjZK8YVpjrxu79myrW9Hrb/wpcMNpVvTq/RcBm8" // ssh-keygen -lf rsa
if fingerprint != want {

View File

@ -1,12 +1,13 @@
package fox
import (
"bytes"
"encoding/hex"
"errors"
"io"
"net"
"strconv"
"strings"
"io"
"github.com/zmap/zgrab2"
)
@ -63,57 +64,70 @@ func GetFoxBanner(logStruct *FoxLog, connection net.Conn) error {
}
responseString := string(data)
output := strings.Split(responseString, string(0x0a))
output := bytes.Split([]byte(responseString), []byte{0x0a})
var (
colon = []byte(":")
semi = []byte(";")
)
b := func(s string) []byte {
return []byte(s)
}
s := func(b []byte) string {
return string(b)
}
if strings.HasPrefix(responseString, RESPONSE_PREFIX) {
logStruct.IsFox = true
for _, value := range output {
if strings.HasPrefix(value, "fox.version") && strings.Contains(value, ":") {
logStruct.Version = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "id") && strings.Contains(value, ":") {
id, err := strconv.ParseUint(strings.Split(value, ":")[1], 10, 32)
if bytes.HasPrefix(value, []byte("fox.version")) && bytes.Contains(value, colon) {
logStruct.Version = string(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("id")) && bytes.Contains(value, colon) {
id, err := strconv.ParseUint(string(bytes.Split(value, colon)[1]), 10, 32)
if err != nil {
return err
}
logStruct.Id = uint32(id)
} else if strings.HasPrefix(value, "hostAddress") && strings.Contains(value, ":") {
} else if bytes.HasPrefix(value, b("hostAddress")) && bytes.Contains(value, colon) {
// TODO: What if this is IPv6? Or, more generally, what if any of these contain a colon?
logStruct.HostAddress = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "hostName") && strings.Contains(value, ":") {
logStruct.Hostname = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "app.name") && strings.Contains(value, ":") {
logStruct.AppName = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "app.version") && strings.Contains(value, ":") {
logStruct.AppVersion = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "vm.name") && strings.Contains(value, ":") {
logStruct.VMName = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "vm.version") && strings.Contains(value, ":") {
logStruct.VMVersion = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "os.name") && strings.Contains(value, ":") {
logStruct.OSName = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "os.version") && strings.Contains(value, ":") {
logStruct.OSVersion = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "station.name") && strings.Contains(value, ":") {
logStruct.StationName = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "lang") && strings.Contains(value, ":") {
logStruct.Language = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "timeZone") && strings.Contains(value, ":") {
timeZone := strings.Split(value, ":")[1]
if strings.Contains(timeZone, ";") {
timeZone = strings.Split(timeZone, ";")[0]
logStruct.HostAddress = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("hostName")) && bytes.Contains(value, colon) {
logStruct.Hostname = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("app.name")) && bytes.Contains(value, colon) {
logStruct.AppName = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("app.version")) && bytes.Contains(value, colon) {
logStruct.AppVersion = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("vm.name")) && bytes.Contains(value, colon) {
logStruct.VMName = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("vm.version")) && bytes.Contains(value, colon) {
logStruct.VMVersion = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("os.name")) && bytes.Contains(value, colon) {
logStruct.OSName = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("os.version")) && bytes.Contains(value, colon) {
logStruct.OSVersion = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("station.name")) && bytes.Contains(value, colon) {
logStruct.StationName = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("lang")) && bytes.Contains(value, colon) {
logStruct.Language = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("timeZone")) && bytes.Contains(value, colon) {
timeZone := bytes.Split(value, colon)[1]
if bytes.Contains(timeZone, semi) {
timeZone = bytes.Split(timeZone, semi)[0]
}
logStruct.TimeZone = timeZone
} else if strings.HasPrefix(value, "hostId") && strings.Contains(value, ":") {
logStruct.HostId = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "vmUuid") && strings.Contains(value, ":") {
logStruct.VMUuid = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "brandId") && strings.Contains(value, ":") {
logStruct.BrandId = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "sysInfo") && strings.Contains(value, ":") {
logStruct.SysInfo = strings.Split(value, ":")[1]
} else if strings.HasPrefix(value, "authAgentTypeSpecs") && strings.Contains(value, ":") {
logStruct.AuthAgentType = strings.Split(value, ":")[1]
logStruct.TimeZone = s(timeZone)
} else if bytes.HasPrefix(value, b("hostId")) && bytes.Contains(value, colon) {
logStruct.HostId = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("vmUuid")) && bytes.Contains(value, colon) {
logStruct.VMUuid = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("brandId")) && bytes.Contains(value, colon) {
logStruct.BrandId = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("sysInfo")) && bytes.Contains(value, colon) {
logStruct.SysInfo = s(bytes.Split(value, colon)[1])
} else if bytes.HasPrefix(value, b("authAgentTypeSpecs")) && bytes.Contains(value, colon) {
logStruct.AuthAgentType = s(bytes.Split(value, colon)[1])
}
}
}