Browse Source

Implemented canonical uuid in the meantime

nosocat
Jean-Louis Huynen 3 years ago
parent
commit
480c54e81e
  1. 21
      README.md
  2. 32
      d4-goclient.go

21
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

32
d4-goclient.go

@ -146,7 +146,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 {
@ -154,7 +154,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)
@ -192,18 +206,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)
@ -228,7 +230,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) {

Loading…
Cancel
Save