mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
Contribute a Wireshark plugin for decrypting and dissecting hashicorp/memberlist messages. And contribue a plugin for dissecting the NetworkDB messages transported as memberlist User messages. Add a feature to NetworkDB to log the encryption keys to a file for the Wireshark memberlist plugin to consume, configured using an environment variable. Signed-off-by: Cory Snider <csnider@mirantis.com>
46 lines
785 B
Go
46 lines
785 B
Go
package networkdb
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"os"
|
|
|
|
"github.com/containerd/log"
|
|
)
|
|
|
|
func logEncKeys(ctx context.Context, keys ...[]byte) {
|
|
klpath := os.Getenv("NETWORKDBKEYLOGFILE")
|
|
if klpath == "" {
|
|
return
|
|
}
|
|
|
|
die := func(err error) {
|
|
log.G(ctx).WithFields(log.Fields{
|
|
"error": err,
|
|
"path": klpath,
|
|
}).Error("could not write to NetworkDB encryption-key log")
|
|
}
|
|
f, err := os.OpenFile(klpath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
|
|
if err != nil {
|
|
die(err)
|
|
return
|
|
}
|
|
defer func() {
|
|
if err := f.Close(); err != nil {
|
|
die(err)
|
|
}
|
|
}()
|
|
|
|
tohex := hex.NewEncoder(f)
|
|
for _, key := range keys {
|
|
if _, err := tohex.Write(key); err != nil {
|
|
die(err)
|
|
return
|
|
}
|
|
if _, err := f.WriteString("\n"); err != nil {
|
|
die(err)
|
|
return
|
|
}
|
|
}
|
|
}
|