Esempio n. 1
0
    def test_database_functions(self):
        # Test construction.
        database = Sqlite3ProducerDb(self.databaseFilePath)

        # Create member.
        params = AesKeyParams(128)
        keyBlob1 = AesAlgorithm.generateKey(params).getKeyBits()
        keyBlob2 = AesAlgorithm.generateKey(params).getKeyBits()

        point1 = Schedule.fromIsoString("20150101T100000")
        point2 = Schedule.fromIsoString("20150102T100000")
        point3 = Schedule.fromIsoString("20150103T100000")
        point4 = Schedule.fromIsoString("20150104T100000")

        # Add keys into the database.
        database.addContentKey(point1, keyBlob1)
        database.addContentKey(point2, keyBlob1)
        database.addContentKey(point3, keyBlob2)

        # Throw an exception when adding a key to an existing time slot.
        with self.assertRaises(ProducerDb.Error):
            database.addContentKey(point1, keyBlob1)

        # Check has functions.
        self.assertEqual(True, database.hasContentKey(point1))
        self.assertEqual(True, database.hasContentKey(point2))
        self.assertEqual(True, database.hasContentKey(point3))
        self.assertEqual(False, database.hasContentKey(point4))

        # Get content keys.
        keyResult = database.getContentKey(point1)
        self.assertTrue(keyResult.equals(keyBlob1))

        keyResult = database.getContentKey(point3)
        self.assertTrue(keyResult.equals(keyBlob2))

        # Throw exception when there is no such time slot in the database.
        with self.assertRaises(ProducerDb.Error):
            database.getContentKey(point4)

        # Delete content keys.
        self.assertEqual(True, database.hasContentKey(point1))
        database.deleteContentKey(point1)
        self.assertEqual(False, database.hasContentKey(point1))

        # Delete at a non-existing time slot.
        try:
            database.deleteContentKey(point4)
        except Exception as ex:
            self.fail(
                "Unexpected error deleting a non-existing content key: " +
                repr(ex))
Esempio n. 2
0
    def test_database_functions(self):
        # Test construction.
        database = Sqlite3ProducerDb(self.databaseFilePath)

        # Create member.
        params = AesKeyParams(128)
        keyBlob1 = AesAlgorithm.generateKey(params).getKeyBits()
        keyBlob2 = AesAlgorithm.generateKey(params).getKeyBits()

        point1 = Schedule.fromIsoString("20150101T100000")
        point2 = Schedule.fromIsoString("20150102T100000")
        point3 = Schedule.fromIsoString("20150103T100000")
        point4 = Schedule.fromIsoString("20150104T100000")

        # Add keys into the database.
        database.addContentKey(point1, keyBlob1)
        database.addContentKey(point2, keyBlob1)
        database.addContentKey(point3, keyBlob2)

        # Throw an exception when adding a key to an existing time slot.
        with self.assertRaises(ProducerDb.Error):
            database.addContentKey(point1, keyBlob1)

        # Check has functions.
        self.assertEqual(True, database.hasContentKey(point1))
        self.assertEqual(True, database.hasContentKey(point2))
        self.assertEqual(True, database.hasContentKey(point3))
        self.assertEqual(False, database.hasContentKey(point4))

        # Get content keys.
        keyResult = database.getContentKey(point1)
        self.assertTrue(keyResult.equals(keyBlob1))

        keyResult = database.getContentKey(point3)
        self.assertTrue(keyResult.equals(keyBlob2))

        # Throw exception when there is no such time slot in the database.
        with self.assertRaises(ProducerDb.Error):
            database.getContentKey(point4)

        # Delete content keys.
        self.assertEqual(True, database.hasContentKey(point1))
        database.deleteContentKey(point1)
        self.assertEqual(False, database.hasContentKey(point1))

        # Delete at a non-existing time slot.
        try:
            database.deleteContentKey(point4)
        except Exception as ex:
            self.fail("Unexpected error deleting a non-existing content key: " + repr(ex))
Esempio n. 3
0
def generateAesKeys():
    params = AesKeyParams()
    memberDecryptKey = AesAlgorithm.generateKey(params)
    decryptionKeyBlob = memberDecryptKey.getKeyBits()
    memberEncryptKey = AesAlgorithm.deriveEncryptKey(decryptionKeyBlob)
    encryptionKeyBlob = memberEncryptKey.getKeyBits()

    return (encryptionKeyBlob, decryptionKeyBlob)
Esempio n. 4
0
def generateAesKeys():
    params = AesKeyParams()
    memberDecryptKey = AesAlgorithm.generateKey(params)
    decryptionKeyBlob = memberDecryptKey.getKeyBits()
    memberEncryptKey = AesAlgorithm.deriveEncryptKey(decryptionKeyBlob)
    encryptionKeyBlob = memberEncryptKey.getKeyBits()

    return (encryptionKeyBlob, decryptionKeyBlob)
Esempio n. 5
0
    def test_key_generation(self):
        keyParams = AesKeyParams(128)
        decryptKey = AesAlgorithm.generateKey(keyParams)
        encryptKey = AesAlgorithm.deriveEncryptKey(decryptKey.getKeyBits())

        plainBlob = Blob(PLAINTEXT, False)

        # Encrypt/decrypt data in AES_CBC with auto-generated IV.
        encryptParams = EncryptParams(EncryptAlgorithmType.AesCbc, 16)
        cipherBlob = AesAlgorithm.encrypt(encryptKey.getKeyBits(), plainBlob,
                                          encryptParams)
        receivedBlob = AesAlgorithm.decrypt(decryptKey.getKeyBits(),
                                            cipherBlob, encryptParams)
        self.assertTrue(receivedBlob.equals(plainBlob))
Esempio n. 6
0
    def test_key_generation(self):
        keyParams = AesKeyParams(128)
        decryptKey = AesAlgorithm.generateKey(keyParams)
        encryptKey = AesAlgorithm.deriveEncryptKey(decryptKey.getKeyBits())

        plainBlob = Blob(PLAINTEXT, False)

        # Encrypt/decrypt data in AES_CBC with auto-generated IV.
        encryptParams = EncryptParams(EncryptAlgorithmType.AesCbc, 16)
        cipherBlob = AesAlgorithm.encrypt(
          encryptKey.getKeyBits(), plainBlob, encryptParams)
        receivedBlob = AesAlgorithm.decrypt(
          decryptKey.getKeyBits(), cipherBlob, encryptParams)
        self.assertTrue(receivedBlob.equals(plainBlob))