Example #1
0
    def test_all(self):
        dao_factory = factory(DAOMongoFactory)
        server = KSIServer(Identifier('server'), dao_factory.get_server())
        keys = Keys(l=256, seed=b'SEED')
        client = KSIClient(server, dao_factory.get_client(), keys=keys)
        ref_cert = client.certificate

        mongo_cert = server.dao.get_user_certificate(client.certificate.id_client)
        self.assertTrue(ref_cert == mongo_cert)

        ref_msg = hash_factory(data=b'DATA').digest()
        sig = client.sign(ref_msg)
        client.verify(sig, client.certificate, ref_msg)
Example #2
0
    def test_all(self):
        dao_factory = factory(DAOMongoFactory)
        server = KSIServer(Identifier('server'), dao_factory.get_server())
        keys = Keys(l=256, seed=b'SEED')
        client = KSIClient(server, dao_factory.get_client(), keys=keys)
        ref_cert = client.certificate

        mongo_cert = server.dao.get_user_certificate(
            client.certificate.id_client)
        self.assertTrue(ref_cert == mongo_cert)

        ref_msg = hash_factory(data=b'DATA').digest()
        sig = client.sign(ref_msg)
        client.verify(sig, client.certificate, ref_msg)
Example #3
0
    def test_verify(self):
        dao_factory = factory(DAOMemoryFactory)
        l = 512
        keys = Keys(l=l, seed=b"SEED")
        client = KSIClient(
            KSIServer(Identifier("server"), dao_factory.get_server()), dao_factory.get_client(), keys=keys
        )
        message = b"DDDD"
        sig = client.sign(message)

        self.assertTrue(client.verify(sig, client.certificate, sig.message))

        # Tampering with the hash chain
        sig.c_i.right_child.hash = b"1234567890"  # This is an arbitrary value, any other than the original one would do
        self.assertFalse(client.verify(sig, client.certificate, sig.message))
Example #4
0
    def test_verify(self):
        dao_factory = factory(DAOMemoryFactory)
        l = 512
        keys = Keys(l=l, seed=b'SEED')
        client = KSIClient(KSIServer(Identifier("server"),
                                     dao_factory.get_server()),
                           dao_factory.get_client(),
                           keys=keys)
        message = b'DDDD'
        sig = client.sign(message)

        self.assertTrue(client.verify(sig, client.certificate, sig.message))

        # Tampering with the hash chain
        sig.c_i.right_child.hash = b'1234567890'  # This is an arbitrary value, any other than the original one would do
        self.assertFalse(client.verify(sig, client.certificate, sig.message))
Example #5
0
from ksi.dao_mongo import DAOMongoFactory, DAOMongoClient
from ksi.dao import factory
from ksi import API_HOST_PORT, API_ROUTE_BASE, SIGN_KEY_FORMAT

#
# REST API client example.
# This file is executable as a "standalone" script.
#

logging.basicConfig(level=logging.DEBUG)

# Filter messages to come only from the client's logger
for handler in logging.root.handlers:
    handler.addFilter(logging.Filter("ksi.ksi_client.KSIClient"))


if __name__ == "__main__":

    dao_factory = factory(DAOMongoFactory)
    client = KSIClient(None, dao_factory.get_client(), keys=Keys(l=8, seed=b'SEED2'), ID_C_str="client2",
                       api_user="******", api_password="******", api_ID_S="server",
                       public_key_filename="/tmp/public_key." + SIGN_KEY_FORMAT)

    sig = client.sign(b'EFGH', use_rest_api=True)

    dao_client = dao_factory.get_client()  # type: DAOMongoClient
    r = requests.get(API_HOST_PORT + API_ROUTE_BASE + 'signed')
    assert str(client.certificate.id_client) in r.json()['signed_timestamps']

    assert client.verify(sig, client.certificate, sig.message) is True
Example #6
0
# REST API client example.
# This file is executable as a "standalone" script.
#

logging.basicConfig(level=logging.DEBUG)

# Filter messages to come only from the client's logger
for handler in logging.root.handlers:
    handler.addFilter(logging.Filter("ksi.ksi_client.KSIClient"))

if __name__ == "__main__":

    dao_factory = factory(DAOMongoFactory)
    client = KSIClient(None,
                       dao_factory.get_client(),
                       keys=Keys(l=8, seed=b'SEED2'),
                       ID_C_str="client2",
                       api_user="******",
                       api_password="******",
                       api_ID_S="server",
                       public_key_filename="/tmp/public_key." +
                       SIGN_KEY_FORMAT)

    sig = client.sign(b'EFGH', use_rest_api=True)

    dao_client = dao_factory.get_client()  # type: DAOMongoClient
    r = requests.get(API_HOST_PORT + API_ROUTE_BASE + 'signed')
    assert str(client.certificate.id_client) in r.json()['signed_timestamps']

    assert client.verify(sig, client.certificate, sig.message) is True