コード例 #1
0
def test_syndication_init_real_world_encrypt_decrypt():
    token = 'fb47ce0f-aa3f-43f6-a3ac-c05e6d7ca0dc'
    seq_id = 189
    send_id = 13389333505314606326
    url = "http://www.really-long-url.example.com/longpath/to/the/files/we_might/need.py"
    data = "636dd7ad8c004d09b2c391d0cc3aa2b0"

    assert len(data) == 32

    x = pySRUPLib.SRUP_Syndication_Init()
    y = pySRUPLib.SRUP_Syndication_Init()

    x.token = token
    x.sequence_id = seq_id
    x.sender_id = send_id
    x.url = url

    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
    assert y.url == url
コード例 #2
0
def test_syndication_init_uuid_deserializer_keystring():
    token = "TOKEN12345"
    seq_id = 0x1234567890ABCDEF
    send_id = 0x5F5F5F5F5F5F5F5F
    url = "http://www.really-long-url.example.com/longpath/to/the/files/we_might/need.py"
    uid = uuid.uuid4().hex

    x = pySRUPLib.SRUP_Syndication_Init()
    y = pySRUPLib.SRUP_Syndication_Init()

    x.token = token
    x.sequence_id = seq_id
    x.sender_id = send_id
    x.url = url

    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
    assert y.url == url

    new_data = y.decrypt_keystring(priv_keystring)
    assert new_data == uid
コード例 #3
0
def test_syndication_init_deserializer():
    token = "TOKEN12345"
    seq_id = 0x1234567890ABCDEF
    send_id = 0x5F5F5F5F5F5F5F5F
    data = "0123456789ABCDEF0123456789ABCDEF"
    url = "http://www.really-long-url.example.com/longpath/to/the/files/we_might/need.py"

    x = pySRUPLib.SRUP_Syndication_Init()
    y = pySRUPLib.SRUP_Syndication_Init()

    x.token = token
    x.sequence_id = seq_id
    x.sender_id = send_id
    x.url = url

    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
    assert y.url == url

    new_data = y.decrypt(keyfile)
    assert new_data == data
コード例 #4
0
def test_syndication_init_uuid_signing_keystring():
    blank = ""
    uid = uuid.uuid4().bytes

    x = pySRUPLib.SRUP_Syndication_Init()
    assert x.sign_keystring(blank) is False
    assert x.sign_keystring(priv_keystring) is False

    x.url = "http://www.really-long-url.example.com/longpath/to/the/files/we_might/need.py"
    assert x.sign_keystring(priv_keystring) is False

    x.token = "TOKEN12345"
    assert x.sign_keystring(priv_keystring) is False

    x.encrypt_keystring(uid, pub_keystring)
    assert x.sign(keyfile) is False

    x.sequence_id = 0x1234567890ABCDEF
    assert x.sign_keystring(priv_keystring) is False

    x.sender_id = 0x5F5F5F5F5F5F5F5F
    assert x.sign_keystring(blank) is False
    assert x.sign_keystring(priv_keystring) is True

    assert x.verify_keystring(pub_keystring) is True
コード例 #5
0
def test_syndication_init_signing():
    blank = ""

    x = pySRUPLib.SRUP_Syndication_Init()
    assert x.sign(blank) is False
    assert x.sign(keyfile) is False

    x.token = "TOKEN12345"
    assert x.sign(keyfile) is False

    x.encrypt("0123456789ABCDEF", pubkeyfile)
    assert x.sign(keyfile) is False

    x.sequence_id = 0x1234567890ABCDEF
    assert x.sign(keyfile) is False

    x.url = "http://www.really-long-url.example.com/longpath/to/the/files/we_might/need.py"
    assert x.sign(keyfile) is False

    x.sender_id = 0x5F5F5F5F5F5F5F5F
    assert x.sign(blank) is False
    assert x.sign(keyfile) is True

    assert x.verify(pubkeyfile) is True

    # Transpose a digit in the digest...
    x.sequence_id = 0x5F5F5F5F5F5F5F5F - 1
    assert x.verify(pubkeyfile) is False
コード例 #6
0
def test_empty_object_keystring():
    x = pySRUPLib.SRUP_Syndication_Init()
    assert x.token is None
    assert x.sequence_id is None
    assert x.sender_id is None
    assert x.url is None
    assert x.sign("") is False
    assert x.decrypt_keystring(priv_keystring) is None
コード例 #7
0
def test_syndication_init_serializer_keystring():
    x = pySRUPLib.SRUP_Syndication_Init()
    x.token = "TOKEN12345"
    x.sequence_id = 0x1234567890ABCDEF
    x.sender_id = 0x5F5F5F5F5F5F5F5F
    x.encrypt_keystring("0123456789ABCDEF", pub_keystring)
    x.url = "http://www.really-long-url.example.com/longpath/to/the/files/we_might/need.py"
    assert x.sign_keystring(priv_keystring) is True
    z = x.serialize()
    assert z is not None
コード例 #8
0
def test_syndication_init_sender():
    MAX_SENDER = 0xFFFFFFFFFFFFFFFF
    ZERO_SENDER = 0x00
    VALID_SENDER = 0x7FFFFFFFFFFFFFE7

    x = pySRUPLib.SRUP_Syndication_Init()

    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
コード例 #9
0
def test_syndication_init_seqid():
    MAX_SEQID = 0xFFFFFFFFFFFFFFFF
    ZERO_SEQID = 0x00
    VALID_SEQID = 0x7FFFFFFFFFFFFFE7

    x = pySRUPLib.SRUP_Syndication_Init()

    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
コード例 #10
0
def test_syndication_init_generic_deserializer_keystring():
    token = "TOKEN12345"
    seq_id = 0x1234567890ABCDEF
    send_id = 0x5F5F5F5F5F5F5F5F
    data = "0123456789ABCDEF"
    url = "http://www.really-long-url.example.com/longpath/to/the/files/we_might/need.py"

    x = pySRUPLib.SRUP_Syndication_Init()
    i = pySRUPLib.SRUP_Generic()

    x.token = token
    x.sequence_id = seq_id
    x.sender_id = send_id
    x.url = url

    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.__syndication_init_message_type()
コード例 #11
0
def test_syndication_init_url():
    x = pySRUPLib.SRUP_Syndication_Init()
    url = "http://www.really-long-url.example.com/longpath/to/the/files/we_might/need.py"
    assert x.url is None
    x.url = url
    assert x.url == url
コード例 #12
0
def test_syndication_init_type():
    x = pySRUPLib.SRUP_Syndication_Init()
    assert x.msg_type == pySRUPLib.__syndication_init_message_type()
コード例 #13
0
def test_syndication_init_encrypt_decrypt_keystring():
    token = "TOKEN12345"
    seq_id = 0x1234567890ABCDEF
    send_id = 0x5F5F5F5F5F5F5F5F

    data = "0123456789ABCDEF0123456789ABCDEF"

    long_data = "1234567890123456789012345678901234567890"
    short_data = "123"
    very_long_data = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890-=!@#$%^&*()_+[]{};':,./<>?\\|"
    url = "http://www.really-long-url.example.com/longpath/to/the/files/we_might/need.py"

    x = pySRUPLib.SRUP_Syndication_Init()
    y = pySRUPLib.SRUP_Syndication_Init()

    x.token = token
    x.sequence_id = seq_id
    x.sender_id = send_id
    x.url = url

    # 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]
    assert y.url == url

    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
    assert y.url == url
コード例 #14
0
def test_syndication_init_token():
    x = pySRUPLib.SRUP_Syndication_Init()
    assert x.token is None
    x.token = "TEST_TOKEN"
    assert x.token == "TEST_TOKEN"