remove crypto, bump version

This commit is contained in:
Kevin Froman 2020-12-27 03:30:13 +00:00
parent 6971a1bb0f
commit 0b509b4f1f
8 changed files with 36 additions and 74 deletions

View File

@ -2,6 +2,10 @@
This project uses Semantic Versioning
## 2.0.0
- Removed encryption and signature stuff since that should be up to protocols
## 1.0.0

View File

@ -10,12 +10,9 @@ hash authentication is dependending on the generator used.
Packed bytes structure:
0: type: str: 4bytesmax
1: enc-mode: int: 0, 1, 2 (0=plaintext, 1=asymmetic, 2=symmetric).
2. Timestamp: int
1. Timestamp: int
encrypted with specified mode:
3. signer: bytes (max 256bits)
4. signature: bytes (max 256bits)
5. app_metadata: arbitrary JSON
3. app_metadata: arbitrary JSON
\n
data: bytes
"""
@ -46,8 +43,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
def pack(data: bytes, data_type: str,
enc_mode: 'KastenEncryptionModeID',
signer: bytes = None, signature: bytes = None,
app_metadata: 'KastenSerializeableDict' = None,
timestamp: int = None
) -> KastenPacked:
@ -55,7 +50,7 @@ def pack(data: bytes, data_type: str,
# Final data will be:
# msgpack.packb([data_type, enc_mode, timestamp, (signer, signature), {app_metadata}]) \
# msgpack.packb([data_type, timestamp, {app_metadata}]) \
# + b'\n' + data
# Ensure data type does not exceed 4 characters
if not data_type or len(data_type) > 4:
@ -66,21 +61,6 @@ def pack(data: bytes, data_type: str,
except AttributeError:
pass
if signer:
if signature is None:
raise ValueError("Signer specified without signature")
else:
signer = b''
signature = b''
# Ensure encryption mode is in [0, 100)
try:
enc_mode = int(enc_mode)
except (TypeError, ValueError):
raise exceptions.InvalidEncryptionMode
if not enc_mode >= 0 or enc_mode >= 100:
raise exceptions.InvalidEncryptionMode
try:
data = data.encode('utf8')
except AttributeError:
@ -89,9 +69,7 @@ def pack(data: bytes, data_type: str,
timestamp = floor(time())
timestamp = int(timestamp)
kasten_header = [data_type, enc_mode, timestamp]
kasten_header.append((signer, signature))
kasten_header.append(app_metadata)
kasten_header = [data_type, timestamp, app_metadata]
kasten_header = packb(kasten_header) + b'\n'
return kasten_header + data

View File

@ -1,6 +1,4 @@
"""Main Kasten object, does nothing but provide access to packed Kasten bytes and call a specified generator function"""
import traceback
from msgpack import unpackb
import msgpack
@ -53,6 +51,7 @@ class Kasten:
self.data = data
self.additional_generator_args = list(additional_generator_args)
self.additional_generator_kwargs = dict(additional_generator_kwargs)
int(self.get_timestamp())
if auto_check_generator:
self.check_generator()
@ -60,7 +59,9 @@ class Kasten:
packed = self.get_packed()
if generator is None:
self.generator.validate_id(
self.id, packed, *self.additional_generator_args, **self.additional_generator_kwargs)
self.id, packed,
*self.additional_generator_args,
**self.additional_generator_kwargs)
else:
generator(self.id, packed)
@ -76,20 +77,11 @@ class Kasten:
return None
return ret
return pack.pack(self.data, self.get_data_type(),
self.get_encryption_mode(),
signer=_get_or_none(self.get_signer),
signature=_get_or_none(self.get_signature),
app_metadata=_get_or_none(self.get_metadata),
timestamp=self.get_timestamp())
def get_data_type(self) -> str: return self.header[0]
def get_encryption_mode(self): return self.header[1]
def get_timestamp(self): return self.header[1]
def get_timestamp(self): return self.header[2]
def get_signer(self): return self.header[3][0]
def get_signature(self): return self.header[3][1]
def get_metadata(self): return self.header[4]
def get_metadata(self): return self.header[2]

View File

@ -6,7 +6,7 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
setup(name='kasten',
version='1.0.1',
version='2.0.0',
description='Efficient, secure data serialization format with extensibility.',
author='Kevin Froman',
author_email='beardog@mailbox.org',

View File

@ -8,8 +8,8 @@ from kasten.generator import KastenBaseGenerator
class TestBaseGenerator(unittest.TestCase):
def test_base_generator(self):
k = b'\x95\xa3tst\x00\x00\xc0\xc0\ntest data'
invalid = b'\x95\xa3tst\x00\x00\xc0\xc0\ntest datb'
k = b'\x93\xa3tst\xce_\xe7\xfb\xfb\xc0\nTest'
invalid = b'\x93\xa3tst\xce_\xe7\xfb\xfb\xc0\nTes2'
correct_K = KastenBaseGenerator.generate(k)
hash_test = sha3_384(k).digest()

View File

@ -8,18 +8,18 @@ from kasten.generator import KastenBaseGenerator, pack
class TestKastenBaseGenerator(unittest.TestCase):
def test_kasten(self):
k = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest data'
k = b'\x93\xa3tst\xce_\xe7\xfb\xfb\xc0\nTest'
K = Kasten(sha3_384(k).digest(), k, KastenBaseGenerator)
def test_kasten_invalid(self):
k = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest data'
k = b'\x93\xa3tst\xce_\xe7\xfb\xfb\xc0\nTest'
self.assertRaises(
exceptions.InvalidID,
Kasten, sha3_384(k + b'invalid').digest(), k, KastenBaseGenerator)
def test_kasten_get_metadata(self):
metadata = {"name": "john", "raw": b"are we having fun yet?"}
packed = pack.pack(b"test msg", "tst", 0, app_metadata=metadata)
packed = pack.pack(b"test msg", "tst", app_metadata=metadata)
K = Kasten(sha3_384(packed).digest(), packed, KastenBaseGenerator)
self.assertEqual(K.get_metadata(), metadata)
@ -31,7 +31,7 @@ class TestKastenBaseGenerator(unittest.TestCase):
metadata = {
"name": "john", "raw": b"are we having fun yet?", "person": kevin}
try:
packed = pack.pack(b"test msg", "tst", 0, app_metadata=metadata)
packed = pack.pack(b"test msg", "tst", app_metadata=metadata)
K = Kasten(sha3_384(packed).digest(), packed, KastenBaseGenerator)
except TypeError:
pass

View File

@ -9,8 +9,8 @@ from kasten import Kasten
class TestMimcGenerator(unittest.TestCase):
def test_mimc_generator(self):
k = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest data'
invalid = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest dat2'
k = b'\x93\xa3tst\xce_\xe7\xfb\xfb\xc0\nTest'
invalid = b'\x93\xa3tst\xce_\xe7\xfb\xfb\xc0\nTes2'
K = KastenMimcGenerator.generate(k)
#h = sha3_384(k).digest()
h = mimcvdf.vdf_create(k, 5000, dec=True)
@ -20,8 +20,8 @@ class TestMimcGenerator(unittest.TestCase):
self.assertEqual(K.get_packed(), k)
def test_mimc_generator_wrong_rounds(self):
k = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest data'
invalid = b'\x95\xa3tst\x00\x00\xc0\xc0\ntest dat2'
k = b'\x93\xa3tst\xce_\xe7\xfb\xfb\xc0\nTest'
invalid = b'\x93\xa3tst\xce_\xe7\xfb\xfb\xc0\nTes2'
K = KastenMimcGenerator.generate(k)
#h = sha3_384(k).digest()
h = mimcvdf.vdf_create(k, 1000, dec=True)
@ -31,7 +31,7 @@ class TestMimcGenerator(unittest.TestCase):
self.assertEqual(K.get_packed(), k)
def test_mimc_generator_kasten_auto_validate(self):
k = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest data'
k = b'\x93\xa3tst\xce_\xe7\xfb\xfb\xc0\nTest'
K = KastenMimcGenerator.generate(k, 1000)
Kasten(int.from_bytes(K.id, byteorder="big"), K.get_packed(), KastenMimcGenerator, *[1000])

View File

@ -10,28 +10,26 @@ from kasten import exceptions
class TestPack(unittest.TestCase):
def test_unsigned_pack(self):
def test_pack(self):
data = os.urandom(10)
t = floor(time())
packed = pack.pack(data, 'bin', 0)
packed = pack.pack(data, 'bin', timestamp=t)
parts = packed.split(b'\n', 1)
unpacked = unpackb(parts[0])
self.assertEqual(unpacked[0], 'bin')
self.assertEqual(unpacked[1], 0)
self.assertAlmostEqual(unpacked[2], t)
self.assertEqual(len(unpacked), 5)
self.assertAlmostEqual(unpacked[1], t)
self.assertEqual(len(unpacked), 3)
def test_unsigned_with_meta(self):
def test_with_meta(self):
data = os.urandom(10)
t = floor(time())
packed = pack.pack(data, 'bin', 0, app_metadata={"meme": "doge"})
packed = pack.pack(data, 'bin', app_metadata={"meme": "doge"})
parts = packed.split(b'\n', 1)
unpacked = unpackb(parts[0])
self.assertEqual(unpacked[0], 'bin')
self.assertEqual(unpacked[1], 0)
self.assertAlmostEqual(unpacked[2], t)
self.assertEqual(unpacked[4], {"meme": "doge"})
self.assertEqual(len(unpacked), 5)
self.assertAlmostEqual(unpacked[1], t)
self.assertEqual(unpacked[2], {"meme": "doge"})
self.assertEqual(len(unpacked), 3)
def test_linebreak_data(self):
data = os.urandom(10) + b'\n'
@ -40,8 +38,7 @@ class TestPack(unittest.TestCase):
parts = packed.split(b'\n', 1)
unpacked = unpackb(parts[0])
self.assertEqual(unpacked[0], 'bin')
self.assertEqual(unpacked[1], 0)
self.assertAlmostEqual(unpacked[2], t)
self.assertAlmostEqual(unpacked[1], t)
self.assertEqual(len(unpacked[0]), 3)
def test_invalid_data_type(self):
@ -50,15 +47,6 @@ class TestPack(unittest.TestCase):
data = os.urandom(10)
self.assertRaises(exceptions.InvalidKastenTypeLength, pack.pack, data, 'aaaaa', 1)
def test_invalid_enc_mode(self):
data = os.urandom(10)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', None)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', "100")
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', 100)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', -1)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', -5)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', "test")
unittest.main()