From f13f68242cd3293ef111d3809f783d7a22691c87 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Tue, 15 Jan 2019 08:29:13 +0100 Subject: [PATCH 1/2] chg: [doc] updated to clarify installation for golang --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 133a1db..d1c2fa9 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,39 @@ # Installation + Fetch d4-goclient code and dependencies + ```bash -go get github.com/D4-project/d4-goclient go get github.com/satori/go.uuid +go get github.com/D4-project/d4-goclient ``` + Use make to build binaries: + ```bash make arm5l # for raspberry pi / linux make amd64l # for amd64 / linux ``` + +## Dependencies + + - golang 1.10 (tested) + - go.uuid + # Use -## Launch a d4-server + +## Launch a d4-server (if you don't have a server) + See https://github.com/D4-project/d4-core/tree/master/server $IP_SRV being the d4-server's address, $PORT its listening port + ## Pipe data into the client + ### Some file ```bash cat /proc/cpuinfo | ./d4-goclient -c conf.sample/ | socat - OPENSSL-CONNECT:$IP_SRV:$PORT,verify=0 ``` -### Tcpdump output, discarding our own traffic + +### tcpdump (libpcap) output, discarding our own traffic $IP being the monitoring computer ip ```bash tcpdump not dst $IP and not src $IP -w - | ./d4-goclient -c conf.sample/ | socat - OPENSSL-CONNECT:$IP_SRV:$PORT,verify=0 From 85b78aa6a48ff038d4f28b49cced5844e15d9466 Mon Sep 17 00:00:00 2001 From: Jean-Louis Huynen Date: Tue, 15 Jan 2019 10:23:52 +0100 Subject: [PATCH 2/2] store UUID as canonical representation, unmarshal uuid on input --- d4-goclient.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/d4-goclient.go b/d4-goclient.go index 2b13eed..ce2002a 100644 --- a/d4-goclient.go +++ b/d4-goclient.go @@ -144,7 +144,7 @@ func readConfFile(d4 *d4S, fileName string) []byte { log.Fatal(err) } // removes 1 for \n - return data[:count-1] + return bytes.TrimSuffix(data[:count], []byte("\n")) } func d4loadConfig(d4 *d4S) bool { @@ -152,7 +152,21 @@ func d4loadConfig(d4 *d4S) bool { (*d4).conf = d4params{} (*d4).conf.source = string(readConfFile(d4, "source")) (*d4).conf.destination = string(readConfFile(d4, "destination")) - (*d4).conf.uuid = readConfFile(d4, "uuid") + tmpu, err := uuid.FromBytes(readConfFile(d4, "uuid")) + if err != nil { + // generate new uuid + (*d4).conf.uuid = generateUUIDv4() + // And push it into the conf file + f, err := os.OpenFile((*d4).confdir+"/uuid", os.O_WRONLY|os.O_CREATE, 0666) + if err != nil { + log.Fatal(err) + } + // store as canonical representation + f.WriteString(fmt.Sprintf("%s", uuid.FromBytesOrNil((*d4).conf.uuid)) + "\n") + f.Close() + } else { + (*d4).conf.uuid = tmpu.Bytes() + } // parse snaplen to uint32 tmp, _ := strconv.ParseUint(string(readConfFile(d4, "snaplen")), 10, 32) (*d4).conf.snaplen = uint32(tmp) @@ -190,18 +204,6 @@ func d4checkConfig(d4 *d4S) bool { (*d4).dst = newD4Writer(f, (*d4).conf.key) } - if len((*d4).conf.uuid) == 0 { - // UUID not set, generate a new one - (*d4).conf.uuid = generateUUIDv4() - // And push it into the conf file - f, err := os.OpenFile((*d4).confdir+"/uuid", os.O_WRONLY|os.O_CREATE, 0666) - if err != nil { - log.Fatal(err) - } - f.WriteString(string((*d4).conf.uuid) + "\n") - f.Close() - } - // Create the copy buffer (*d4).dst.fb = make([]byte, HDR_SIZE+(*d4).conf.snaplen) (*d4).dst.pb = make([]byte, (*d4).conf.snaplen) @@ -215,7 +217,7 @@ func generateUUIDv4() []byte { log.Fatal(err) } infof(fmt.Sprintf("UUIDv4: %s\n", uuid)) - return []byte(uuid[:]) + return uuid.Bytes() } func (d4w *d4Writer) Write(bs []byte) (int, error) {