Пример #1
0
    def test_fake_client(self):
        c = session()
        s = session()
        alicefakek = array.array('B', [0x78,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d,0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45,0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a,0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a]).tostring()
        alicesk    = array.array('B', [0x77,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d,0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45,0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a,0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a]).tostring()
        alicepk    = array.array('B', [0x85,0x20,0xf0,0x09,0x89,0x30,0xa7,0x54,0x74,0x8b,0x7d,0xdc,0xb4,0x3e,0xf7,0x5a,0x0d,0xbf,0x3a,0x0d,0x26,0x38,0x1a,0xf4,0xeb,0xa4,0xa9,0x8e,0xaa,0x9b,0x4e,0x6a]).tostring()

        c.init_as_client(aliceskakek,alicepk)
        s.init_as_server(alicesk)

        packet1 = c.client_say_hello_first()
        print array.array('c', packet1)
        packet2 = s.server_say_hello_second(packet1)
        c.client_get_hello_third(packet2)
Пример #2
0
    def test_replay_attack(self):
        c = session()
        s = session()
        alicesk = array.array('B', [0x77,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d,0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45,0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a,0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a]).tostring()
        alicepk = array.array('B', [0x85,0x20,0xf0,0x09,0x89,0x30,0xa7,0x54,0x74,0x8b,0x7d,0xdc,0xb4,0x3e,0xf7,0x5a,0x0d,0xbf,0x3a,0x0d,0x26,0x38,0x1a,0xf4,0xeb,0xa4,0xa9,0x8e,0xaa,0x9b,0x4e,0x6a]).tostring()

        c.init_as_client(alicesk,alicepk)
        s.init_as_server(alicesk)

        packet1 = c.client_say_hello_first()
        print array.array('c', packet1)
        packet2 = s.server_say_hello_second(packet1)
        c.client_get_hello_third(packet2)

        msg = "Test this message."
        encrypted = c.session_send(msg)
        plain = s.session_receive(encrypted)
        self.assertEquals(plain, msg)
        try:
            plain2 = s.session_receive(encrypted)
            self.assertNotEquals(plain2, msg)
            self.assertTrue(False)
        except:
            pass

        #now test replays in a new session
        c = session()
        s = session()
        alicesk = array.array('B', [0x77,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d,0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45,0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a,0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a]).tostring()
        alicepk = array.array('B', [0x85,0x20,0xf0,0x09,0x89,0x30,0xa7,0x54,0x74,0x8b,0x7d,0xdc,0xb4,0x3e,0xf7,0x5a,0x0d,0xbf,0x3a,0x0d,0x26,0x38,0x1a,0xf4,0xeb,0xa4,0xa9,0x8e,0xaa,0x9b,0x4e,0x6a]).tostring()

        c.init_as_client(alicesk,alicepk)
        s.init_as_server(alicesk)

        packet1 = c.client_say_hello_first()
        print array.array('c', packet1)
        packet2 = s.server_say_hello_second(packet1)
        c.client_get_hello_third(packet2)

        msg = "Test this message."
        encrypted = c.session_send(msg)
        plain = s.session_receive(encrypted)
        self.assertEquals(plain, msg)
        try:
            self.assertNotEquals(plain2, msg)
            self.assertTrue(False)
        except:
            pass
Пример #3
0
 def test_internaltests(self):
     from caffeinecrypto import session
     session().tests()