From 8e43db07ace346e2fc4b9644e9c17a6e0739d670 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 11 May 2017 01:40:11 +0200 Subject: fix previous commit --- src/hub/src/spreadspace.org/sfive/s5srvAnon.go | 100 +++++++++++++++++++++++++ src/hub/test-srv-anon | 19 +++++ 2 files changed, 119 insertions(+) create mode 100644 src/hub/src/spreadspace.org/sfive/s5srvAnon.go create mode 100755 src/hub/test-srv-anon (limited to 'src') 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 +// Markus Grüneis +// +// 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 . +// + +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 [ ]" + 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 -- cgit v1.2.3