summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-05-11 01:40:11 +0200
committerChristian Pointner <equinox@spreadspace.org>2017-05-11 01:40:11 +0200
commit8e43db07ace346e2fc4b9644e9c17a6e0739d670 (patch)
treebb74f0701be3fcb9dd1796e501a84a676dc6fd60
parentadded support IP address anonymization (diff)
fix previous commit
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvAnon.go100
-rwxr-xr-xsrc/hub/test-srv-anon19
2 files changed, 119 insertions, 0 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvAnon.go b/src/hub/src/spreadspace.org/sfive/s5srvAnon.go
new file mode 100644
index 0000000..8626932
--- /dev/null
+++ b/src/hub/src/spreadspace.org/sfive/s5srvAnon.go
@@ -0,0 +1,100 @@
+//
+// sfive
+//
+// sfive - spreadspace streaming statistics suite is a generic
+// statistic collection tool for streaming server infrastuctures.
+// The system collects and stores meta data like number of views
+// and throughput from a number of streaming servers and stores
+// it in a global data store.
+// The data acquisition is designed to be generic and extensible in
+// order to support different streaming software.
+// sfive also contains tools and applications to filter and visualize
+// live and recorded data.
+//
+//
+// Copyright (C) 2014-2017 Christian Pointner <equinox@spreadspace.org>
+// Markus Grüneis <gimpf@gimpf.org>
+//
+// This file is part of sfive.
+//
+// sfive is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 3
+// as published by the Free Software Foundation.
+//
+// sfive is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with sfive. If not, see <http://www.gnu.org/licenses/>.
+//
+
+package sfive
+
+import (
+ "crypto/rand"
+ "errors"
+ "io/ioutil"
+ "net"
+ "os"
+
+ "github.com/Yawning/cryptopan"
+)
+
+type AnonymizationAlgo interface {
+ String() string
+ Anonymize(addr string) (string, error)
+}
+
+func readOrGenerateKey(keyFile string, size int) (key []byte, err error) {
+ if keyFile != "" {
+ var kf *os.File
+ if kf, err = os.Open(keyFile); err != nil {
+ return
+ }
+ defer kf.Close()
+ return ioutil.ReadAll(kf)
+ }
+
+ key = make([]byte, size)
+ _, err = rand.Read(key)
+ return
+}
+
+//
+// CryptoPan based anonymization
+//
+
+type CryptoPanAnonymization struct {
+ ctx *cryptopan.Cryptopan
+ keyFile string
+}
+
+func (cp *CryptoPanAnonymization) String() string {
+ if cp.keyFile == "" {
+ return "CryptoPan, with random key"
+ }
+ return "CryptoPan, with key from file: " + cp.keyFile
+}
+
+func (cp *CryptoPanAnonymization) Anonymize(addr string) (string, error) {
+ ip := net.ParseIP(addr)
+ if ip == nil {
+ return "", errors.New("address '" + addr + "' is not valid")
+ }
+ return cp.ctx.Anonymize(ip).String(), nil
+}
+
+func NewCryptopanAnonymization(keyFile string) (AnonymizationAlgo, error) {
+ key, err := readOrGenerateKey(keyFile, cryptopan.Size)
+ if err != nil {
+ return nil, err
+ }
+
+ cp := &CryptoPanAnonymization{keyFile: keyFile}
+ if cp.ctx, err = cryptopan.New(key); err != nil {
+ return nil, err
+ }
+ return cp, nil
+}
diff --git a/src/hub/test-srv-anon b/src/hub/test-srv-anon
new file mode 100755
index 0000000..93f41ab
--- /dev/null
+++ b/src/hub/test-srv-anon
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+if [ -z "$1" ]; then
+ echo "Usage: $0 <db-name> [ <key-file> ]"
+ exit 1
+fi
+
+TEST_D="./test"
+TEST_DB="$TEST_D/$1.bolt"
+EXTRA_OPTS=""
+
+
+if [ -n "$2" ]; then
+ EXTRA_OPTS="$EXTRA_OPTS -anonymization-key-file $2"
+fi
+
+mkdir -p "$TEST_D"
+rm -f "$TEST_D/pipe" "$TEST_D/pipegram"
+exec ./bin/sfive-hub -db "$TEST_DB" -start-pipe-server -pipe "$TEST_D/pipe" -start-pipegram-server -pipegram "$TEST_D/pipegram" -start-web-server -web ":8000" -anonymize $EXTRA_OPTS