Ejemplo n.º 1
0
 def to_csv(self, sep="|", path=None, ip_anonymization=False):
     if path is None:
         output_path = str(self._source) + '.csv'
     else:
         output_path = path
     if os.path.exists(output_path):
         sys.exit("Output file exists: {}. Please specify a valid file path.".format(output_path))
     else:
         total_flows = 0
         crypto_key = secrets.token_bytes(16)
         with open(output_path, 'ab') as f:
             for flow in self:
                 try:
                     if total_flows == 0:  # header creation
                         header = sep.join([str(i) for i in flow.keys()]) + "\n"
                         src_ip_index = flow.keys().index("src_ip")
                         dst_ip_index = flow.keys().index("dst_ip")
                         f.write(header.encode('utf-8'))
                     values = flow.values()
                     if ip_anonymization:
                         values[src_ip_index] = int.from_bytes(siphash_64(crypto_key, values[src_ip_index].encode()),
                                                               sys.byteorder)
                         values[dst_ip_index] = int.from_bytes(siphash_64(crypto_key, values[dst_ip_index].encode()),
                                                               sys.byteorder)
                     to_export = sep.join([str(i) for i in values]) + "\n"
                     f.write(to_export.encode('utf-8'))
                     total_flows = total_flows + 1
                 except KeyboardInterup:
                     if not self._stopped:
                         self._stopped = True
                         self.cache.stopped = True
             return total_flows
Ejemplo n.º 2
0
def test_64(case_key, case_data, cases_siphash24_64):
    for i, case in enumerate(cases_siphash24_64):
        output = siphash.siphash_64(case_key, case_data[:i], 2, 4)
        hex_output = binascii.hexlify(output).decode("utf8")

        assert case == hex_output
Ejemplo n.º 3
0
def test_invalid_data_type(case_key):
    with pytest.raises(TypeError):
        siphash.siphash_64(case_key, "")
Ejemplo n.º 4
0
def test_invalid_d_rounds_value_high(case_key, case_data):
    with pytest.raises(ValueError):
        siphash.siphash_64(case_key, case_data, d_rounds=256)
Ejemplo n.º 5
0
def test_invalid_key_type(case_data):
    with pytest.raises(TypeError):
        siphash.siphash_64("", case_data)
Ejemplo n.º 6
0
def test_invalid_c_rounds_value_low(case_key, case_data):
    with pytest.raises(ValueError):
        siphash.siphash_64(case_key, case_data, c_rounds=-256)
Ejemplo n.º 7
0
def test_invalid_d_rounds_type(case_key, case_data):
    with pytest.raises(TypeError):
        siphash.siphash_64(case_key, case_data, d_rounds=1.00)
Ejemplo n.º 8
0
def test_invalid_key_length(case_key, case_data):
    with pytest.raises(ValueError):
        siphash.siphash_64(case_key + b"\0", case_data)
__license__ = 'MIT'
import base64
import toml
import json
from urllib.parse import quote as urlquote
from urllib.parse import urlparse, ParseResult
import sys
import argparse
import logging


key = b'\x00' * 16
try:
    # this is siphash-cffi
    from siphash import siphash_64
    siphasher = lambda b: base64.b16encode(siphash_64(key, b))

except ImportError:
    # this is siphash
    from siphash import SipHash_2_4
    siphasher = lambda b: SipHash_2_4(key, b).hexdigest()



CRATES_IO = 'https://static.crates.io/crates'
CARGO_HOME = 'cargo'
CARGO_CRATES = f'{CARGO_HOME}/vendor'


def rust_digest(b):
    # The 0xff suffix matches Rust's behaviour
Ejemplo n.º 10
0
def test_00_64(key_size, case_key, case_data):
    siphash.siphash_64(case_key[:key_size], case_data, 0, 0)
Ejemplo n.º 11
0
def test_255255_64(key_size, case_key, case_data):
    siphash.siphash_64(case_key[:key_size], case_data, 255, 255)
Ejemplo n.º 12
0
def test_255255_64(case_key, case_data):
    siphash.siphash_64(case_key, case_data, 255, 255)
Ejemplo n.º 13
0
def test_00_64(case_key, case_data):
    siphash.siphash_64(case_key, case_data, 0, 0)