Beispiel #1
0
    def testKeyPair(self):
        kpA = utils.genKeyPair("alice")
        kpAp = utils.genKeyPair("alice")
        kpB = utils.genKeyPair("bob")

        assert kpA != kpB
        assert kpA != kpAp
        assert kpA == kpA
        assert kpB == kpB
    def testKeyPair(self):
        params = DefaultParams

        kpA1 = utils.genKeyPair('alice')
        kpB1 = utils.genKeyPair('bob')

        kpA2 = KeyPair.unserialize(params, kpA1.serialize(), 'alice')
        kpB2 = KeyPair.unserialize(params, kpB1.serialize(), 'bob')

        with self.assertRaises(ValueError):
            KeyPair.unserialize(params, kpA1.serialize(), 'bad name here')

        assert kpA1 != kpB1
        assert kpA2 != kpB2
        assert kpA1 == kpA2
        assert kpB1 == kpB2
    def _testKeyAgreement(self, kgcA, kgcB):
        keyType = "aead"
        alice = "*****@*****.**"
        bob = "*****@*****.**"
        charlie = "*****@*****.**"

        keypairA = utils.genKeyPair(alice, kgcA, DefaultParams)
        keypairB = utils.genKeyPair(bob, kgcB, DefaultParams)
        keypairC = utils.genKeyPair(charlie, kgcA, DefaultParams)

        symkeyAB = keypairA.deriveKey(keypairB.getPublicKey(), bob, keyType)
        symkeyBA = keypairB.deriveKey(keypairA.getPublicKey(), alice, keyType)
        symkeyAC = keypairA.deriveKey(keypairC.getPublicKey(), charlie, keyType)
        symkeyBC = keypairB.deriveKey(keypairC.getPublicKey(), charlie, keyType)

        assert symkeyAB == symkeyBA
        assert symkeyAC != symkeyAB
        assert symkeyBC != symkeyAB
        assert symkeyAC != symkeyBC