def test_join_request_uuid_deserializer_keystring(): token = "TOKEN12345" seq_id = 0x1234567890ABCDEF send_id = 0x5F5F5F5F5F5F5F5F uid = uuid.uuid4().hex x = pySRUPLib.SRUP_Human_Join_Response() y = pySRUPLib.SRUP_Human_Join_Response() x.token = token x.sequence_id = seq_id x.sender_id = send_id x.encrypt_keystring(uid, pub_keystring) assert x.sign_keystring(priv_keystring) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify_keystring(pub_keystring) is True assert y.token == token assert y.sender_id == send_id assert y.sequence_id == seq_id new_data = y.decrypt_keystring(priv_keystring) assert new_data == uid
def test_real_world_encrypt_decrypt(): token = 'fb47ce0f-aa3f-43f6-a3ac-c05e6d7ca0dc' seq_id = 189 send_id = 13389333505314606326 data = "636dd7ad8c004d09b2c391d0cc3aa2b0" assert len(data) == 32 x = pySRUPLib.SRUP_Human_Join_Response() y = pySRUPLib.SRUP_Human_Join_Response() x.token = token x.sequence_id = seq_id x.sender_id = send_id x.encrypt_keystring(data, pub_keystring) r_data = x.decrypt(keyfile) assert r_data == data assert len(r_data) == 32 assert x.sign(keyfile) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify(pubkeyfile) is True r_data_y = y.decrypt(keyfile) assert r_data_y == data assert len(r_data_y) == 32
def test_join_request_deserializer(): token = "TOKEN12345" seq_id = 0x1234567890ABCDEF send_id = 0x5F5F5F5F5F5F5F5F data = "0123456789ABCDEF0123456789ABCDEF" x = pySRUPLib.SRUP_Human_Join_Response() y = pySRUPLib.SRUP_Human_Join_Response() x.token = token x.sequence_id = seq_id x.sender_id = send_id x.encrypt(data, pubkeyfile) assert x.sign(keyfile) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify(pubkeyfile) is True assert y.token == token assert y.sender_id == send_id assert y.sequence_id == seq_id new_data = y.decrypt(keyfile) assert new_data == data
def test_empty_object_keystring(): x = pySRUPLib.SRUP_Human_Join_Response() assert x.token is None assert x.sequence_id is None assert x.sender_id is None assert x.sign("") is False assert x.decrypt_keystring(priv_keystring) is None
def test_empty_object(): x = pySRUPLib.SRUP_Human_Join_Response() assert x.token is None assert x.sequence_id is None assert x.sender_id is None assert x.sign("") is False assert x.decrypt(keyfile) is None
def test_join_request_signing_keystring(): blank = "" x = pySRUPLib.SRUP_Human_Join_Response() assert x.sign_keystring(blank) is False assert x.sign_keystring(priv_keystring) is False x.token = "TOKEN12345" assert x.sign_keystring(priv_keystring) is False x.sequence_id = 0x1234567890ABCDEF assert x.sign_keystring(priv_keystring) is False x.sender_id = 0x5F5F5F5F5F5F5F5F assert x.sign_keystring(priv_keystring) is False x.encrypt_keystring("0123456789ABCDEF", pub_keystring) assert x.sign_keystring(blank) is False assert x.sign_keystring(priv_keystring) is True assert x.verify_keystring(pub_keystring) is True # Transpose a digit in the digest... x.sequence_id = 0x5F5F5F5F5F5F5F5F - 1 assert x.verify_keystring(pub_keystring) is False
def test_join_request_serializer_keystring(): x = pySRUPLib.SRUP_Human_Join_Response() x.token = "TOKEN12345" x.sequence_id = 0x1234567890ABCDEF x.sender_id = 0x5F5F5F5F5F5F5F5F x.encrypt_keystring("0123456789ABCDEF", pub_keystring) assert x.sign_keystring(priv_keystring) is True z = x.serialize() assert z is not None
def test_join_request_generic_deserializer_keystring(): token = "TOKEN12345" seq_id = 0x1234567890ABCDEF send_id = 0x5F5F5F5F5F5F5F5F data = "0123456789ABCDEF" x = pySRUPLib.SRUP_Human_Join_Response() i = pySRUPLib.SRUP_Generic() x.token = token x.sequence_id = seq_id x.sender_id = send_id x.encrypt_keystring(data, pub_keystring) assert x.sign_keystring(priv_keystring) is True z = x.serialize() assert i.deserialize(z) is True assert i.msg_type == pySRUPLib.__human_join_response_message_type()
def test_join_request_sender(): MAX_SENDER = 0xFFFFFFFFFFFFFFFF ZERO_SENDER = 0x00 VALID_SENDER = 0x7FFFFFFFFFFFFFE7 x = pySRUPLib.SRUP_Human_Join_Response() x.sender_id = MAX_SENDER assert x.sender_id == MAX_SENDER x.sender_id = VALID_SENDER assert x.sender_id == VALID_SENDER x.sender_id = ZERO_SENDER assert x.sender_id == ZERO_SENDER with pytest.raises(OverflowError): x.sender_id = MAX_SENDER + 1 with pytest.raises(OverflowError): x.sender_id = ZERO_SENDER - 1
def test_join_request_seqid(): MAX_SEQID = 0xFFFFFFFFFFFFFFFF ZERO_SEQID = 0x00 VALID_SEQID = 0x7FFFFFFFFFFFFFE7 x = pySRUPLib.SRUP_Human_Join_Response() x.sequence_id = MAX_SEQID assert x.sequence_id == MAX_SEQID x.sequence_id = VALID_SEQID assert x.sequence_id == VALID_SEQID x.sequence_id = ZERO_SEQID assert x.sequence_id == ZERO_SEQID with pytest.raises(OverflowError): x.sequence_id = MAX_SEQID + 1 with pytest.raises(OverflowError): x.sequence_id = ZERO_SEQID - 1
def test_join_request_uuid_signing_keystring(): blank = "" uid = uuid.uuid4().bytes x = pySRUPLib.SRUP_Human_Join_Response() assert x.sign_keystring(blank) is False assert x.sign_keystring(priv_keystring) is False x.token = "TOKEN12345" assert x.sign_keystring(priv_keystring) is False x.sequence_id = 0x1234567890ABCDEF assert x.sign_keystring(priv_keystring) is False x.sender_id = 0x5F5F5F5F5F5F5F5F assert x.sign_keystring(priv_keystring) is False x.encrypt_keystring(uid, pub_keystring) assert x.sign_keystring(blank) is False assert x.sign_keystring(priv_keystring) is True assert x.verify_keystring(pub_keystring) is True
def test_join_request_type(): x = pySRUPLib.SRUP_Human_Join_Response() assert x.msg_type == pySRUPLib.__human_join_response_message_type()
def test_encrypt_decrypt_keystring(): token = "TOKEN12345" seq_id = 0x1234567890ABCDEF send_id = 0x5F5F5F5F5F5F5F5F data = "0123456789ABCDEF0123456789ABCDEF" long_data = "1234567890123456789012345678901234567890" short_data = "123" very_long_data = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890-=!@#$%^&*()_+[]{};':,./<>?\\|" x = pySRUPLib.SRUP_Human_Join_Response() y = pySRUPLib.SRUP_Human_Join_Response() x.token = token x.sequence_id = seq_id x.sender_id = send_id # The encrypted data is expected to be 32-bytes... # So assigning longer sequences will result in truncation... # (See elsewhere in the tests for notes). x.encrypt_keystring(long_data, pub_keystring) assert x.decrypt_keystring(priv_keystring) == long_data[:32] assert x.sign_keystring(priv_keystring) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify_keystring(pub_keystring) is True assert y.decrypt_keystring(priv_keystring) == long_data[:32] x.encrypt_keystring(very_long_data, pub_keystring) assert x.decrypt_keystring(priv_keystring) == very_long_data[:32] assert x.sign_keystring(priv_keystring) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify_keystring(pub_keystring) is True assert y.decrypt_keystring(priv_keystring) == very_long_data[:32] # ... whilst shorter sequences will be padded with 0x00's x.encrypt_keystring(short_data, pub_keystring) padded_short_data = short_data.ljust(32, chr(0x00)) assert x.decrypt_keystring(priv_keystring) == padded_short_data assert x.sign_keystring(priv_keystring) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify_keystring(pub_keystring) is True assert y.decrypt_keystring(priv_keystring) == padded_short_data # We can use strings for short-hand – but the real data will be raw bytes... # So let's test that too. byte_data = chr(0x00) byte_data += chr(0x01) byte_data += chr(0x02) byte_data += chr(0x03) byte_data += chr(0x04) byte_data += chr(0x05) byte_data += chr(0x06) byte_data += chr(0x07) byte_data += chr(0x08) byte_data += chr(0x09) byte_data += chr(0x0A) byte_data += chr(0x0B) byte_data += chr(0x0C) byte_data += chr(0x0D) byte_data += chr(0x0E) byte_data += chr(0x0F) byte_data += chr(0x00) byte_data += chr(0x01) byte_data += chr(0x02) byte_data += chr(0x03) byte_data += chr(0x04) byte_data += chr(0x05) byte_data += chr(0x06) byte_data += chr(0x07) byte_data += chr(0x08) byte_data += chr(0x09) byte_data += chr(0x0A) byte_data += chr(0x0B) byte_data += chr(0x0C) byte_data += chr(0x0D) byte_data += chr(0x0E) byte_data += chr(0x0F) x.encrypt_keystring(byte_data, pub_keystring) assert x.decrypt_keystring(priv_keystring) == byte_data assert x.sign_keystring(priv_keystring) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify_keystring(pub_keystring) is True assert y.decrypt_keystring(priv_keystring) == byte_data # Lastly we'll test with a "regular" 32-character string. x.encrypt_keystring(data, pub_keystring) assert x.decrypt_keystring(priv_keystring) == data assert x.sign_keystring(priv_keystring) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify_keystring(pub_keystring) is True assert y.decrypt_keystring(priv_keystring) == data
def test_encrypt_decrypt(): token = "TOKEN12345" seq_id = 0x1234567890ABCDEF send_id = 0x5F5F5F5F5F5F5F5F data = "0123456789ABCDEF0123456789ABCDEF" long_data = "1234567890123456789012345678901234567890" short_data = "123" very_long_data = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890-=!@#$%^&*()_+[]{};':,./<>?\\|" x = pySRUPLib.SRUP_Human_Join_Response() y = pySRUPLib.SRUP_Human_Join_Response() x.token = token x.sequence_id = seq_id x.sender_id = send_id # The encrypted data is expected to be 16-bytes... # Typically this will be stored as a 32-character string # So assigning longer sequences will result in truncation... x.encrypt(long_data, pubkeyfile) assert x.decrypt(keyfile) == long_data[:32] assert x.sign(keyfile) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify(pubkeyfile) is True assert y.decrypt(keyfile) == long_data[:32] x.encrypt(very_long_data, pubkeyfile) assert x.decrypt(keyfile) == very_long_data[:32] assert x.sign(keyfile) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify(pubkeyfile) is True assert y.decrypt(keyfile) == very_long_data[:32] # ... whilst shorter sequences will be padded with 0x00's x.encrypt(short_data, pubkeyfile) padded_short_data = short_data.ljust(32, chr(0x00)) assert x.decrypt(keyfile) == padded_short_data assert x.sign(keyfile) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify(pubkeyfile) is True assert y.decrypt(keyfile) == padded_short_data # We might want to use raw-bytes... # So let's test that too. byte_data = chr(0x00) byte_data += chr(0x01) byte_data += chr(0x02) byte_data += chr(0x03) byte_data += chr(0x04) byte_data += chr(0x05) byte_data += chr(0x06) byte_data += chr(0x07) byte_data += chr(0x08) byte_data += chr(0x09) byte_data += chr(0x0A) byte_data += chr(0x0B) byte_data += chr(0x0C) byte_data += chr(0x0D) byte_data += chr(0x0E) byte_data += chr(0x0F) byte_data += chr(0x00) byte_data += chr(0x01) byte_data += chr(0x02) byte_data += chr(0x03) byte_data += chr(0x04) byte_data += chr(0x05) byte_data += chr(0x06) byte_data += chr(0x07) byte_data += chr(0x08) byte_data += chr(0x09) byte_data += chr(0x0A) byte_data += chr(0x0B) byte_data += chr(0x0C) byte_data += chr(0x0D) byte_data += chr(0x0E) byte_data += chr(0x0F) x.encrypt(byte_data, pubkeyfile) assert x.decrypt(keyfile) == byte_data assert x.sign(keyfile) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify(pubkeyfile) is True assert y.decrypt(keyfile) == byte_data # Lastly we'll test with a "regular" 32-character string. x.encrypt(data, pubkeyfile) assert x.decrypt(keyfile) == data assert x.sign(keyfile) is True z = x.serialize() assert y.deserialize(z) is True assert y.verify(pubkeyfile) is True assert y.decrypt(keyfile) == data
def test_join_request_token(): x = pySRUPLib.SRUP_Human_Join_Response() assert x.token is None x.token = "TEST_TOKEN" assert x.token == "TEST_TOKEN"