Exemplo n.º 1
0
    def test_setter_getter(self):
        content = EncryptedContent()
        self.assertEqual(content.getAlgorithmType(), None)
        self.assertTrue(content.getPayload().isNull())
        self.assertTrue(content.getInitialVector().isNull())
        self.assertEqual(content.getKeyLocator().getType(), None)

        content.setAlgorithmType(EncryptAlgorithmType.RsaOaep)
        self.assertEqual(content.getAlgorithmType(),
                         EncryptAlgorithmType.RsaOaep)
        self.assertTrue(content.getPayload().isNull())
        self.assertTrue(content.getInitialVector().isNull())
        self.assertEqual(content.getKeyLocator().getType(), None)

        keyLocator = KeyLocator()
        keyLocator.setType(KeyLocatorType.KEYNAME)
        keyLocator.getKeyName().set("/test/key/locator")
        content.setKeyLocator(keyLocator)
        self.assertTrue(content.getKeyLocator().getType() != None)
        self.assertTrue(content.getKeyLocator().getKeyName().equals(
            Name("/test/key/locator")))
        self.assertTrue(content.getPayload().isNull())
        self.assertTrue(content.getInitialVector().isNull())

        content.setPayload(Blob(message, False))
        self.assertTrue(content.getPayload().equals(Blob(message, False)))

        content.setInitialVector(Blob(iv, False))
        self.assertTrue(content.getInitialVector().equals(Blob(iv, False)))

        encoded = content.wireEncode()
        contentBlob = Blob(encrypted, False)
        self.assertTrue(contentBlob.equals(encoded))
Exemplo n.º 2
0
    def test_setter_getter(self):
        content = EncryptedContent()
        self.assertEqual(content.getAlgorithmType(), None)
        self.assertTrue(content.getPayload().isNull())
        self.assertTrue(content.getInitialVector().isNull())
        self.assertEqual(content.getKeyLocator().getType(), None)

        content.setAlgorithmType(EncryptAlgorithmType.RsaOaep)
        self.assertEqual(content.getAlgorithmType(), EncryptAlgorithmType.RsaOaep)
        self.assertTrue(content.getPayload().isNull())
        self.assertTrue(content.getInitialVector().isNull())
        self.assertEqual(content.getKeyLocator().getType(), None)

        keyLocator = KeyLocator()
        keyLocator.setType(KeyLocatorType.KEYNAME)
        keyLocator.getKeyName().set("/test/key/locator")
        content.setKeyLocator(keyLocator)
        self.assertTrue(content.getKeyLocator().getType() != None)
        self.assertTrue(content.getKeyLocator().getKeyName().equals(
          Name("/test/key/locator")))
        self.assertTrue(content.getPayload().isNull())
        self.assertTrue(content.getInitialVector().isNull())

        content.setPayload(Blob(message, False))
        self.assertTrue(content.getPayload().equals(Blob(message, False)))

        content.setInitialVector(Blob(iv, False))
        self.assertTrue(content.getInitialVector().equals(Blob(iv, False)))

        encoded = content.wireEncode()
        contentBlob = Blob(encrypted, False)
        self.assertTrue(contentBlob.equals(encoded))
    def test_bad_certificate_name(self):
        interest1 = self._fixture.makeCommandInterest(self._fixture._identity)
        keyLocator = KeyLocator()
        keyLocator.setType(KeyLocatorType.KEYNAME)
        keyLocator.setKeyName(Name("/bad/cert/name"))
        signatureInfo = Sha256WithRsaSignature()
        signatureInfo.setKeyLocator(keyLocator)

        setNameComponent(
          interest1, CommandInterestSigner.POS_SIGNATURE_INFO,
          TlvWireFormat.get().encodeSignatureInfo(signatureInfo))
        self.validateExpectFailure(interest1, "Should fail (bad certificate name)")
    def test_bad_key_locator_type(self):
        interest1 = self._fixture.makeCommandInterest(self._fixture._identity)
        keyLocator = KeyLocator()
        keyLocator.setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
        keyLocator.setKeyData(Blob
          ([ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd ]))
        signatureInfo = Sha256WithRsaSignature()
        signatureInfo.setKeyLocator(keyLocator)

        setNameComponent(
          interest1, CommandInterestSigner.POS_SIGNATURE_INFO,
          TlvWireFormat.get().encodeSignatureInfo(signatureInfo))
        self.validateExpectFailure(interest1, "Should fail (bad KeyLocator type)")
    def test_bad_certificate_name(self):
        interest1 = self._fixture.makeCommandInterest(self._fixture._identity)
        keyLocator = KeyLocator()
        keyLocator.setType(KeyLocatorType.KEYNAME)
        keyLocator.setKeyName(Name("/bad/cert/name"))
        signatureInfo = Sha256WithRsaSignature()
        signatureInfo.setKeyLocator(keyLocator)

        setNameComponent(
            interest1, CommandInterestSigner.POS_SIGNATURE_INFO,
            TlvWireFormat.get().encodeSignatureInfo(signatureInfo))
        self.validateExpectFailure(interest1,
                                   "Should fail (bad certificate name)")
    def test_bad_key_locator_type(self):
        interest1 = self._fixture.makeCommandInterest(self._fixture._identity)
        keyLocator = KeyLocator()
        keyLocator.setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
        keyLocator.setKeyData(
            Blob([0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd]))
        signatureInfo = Sha256WithRsaSignature()
        signatureInfo.setKeyLocator(keyLocator)

        setNameComponent(
            interest1, CommandInterestSigner.POS_SIGNATURE_INFO,
            TlvWireFormat.get().encodeSignatureInfo(signatureInfo))
        self.validateExpectFailure(interest1,
                                   "Should fail (bad KeyLocator type)")
Exemplo n.º 7
0
    def generateFakeSignature():
        signatureInfo = Sha256WithRsaSignature()

        keyLocatorName = Name("/ndn/site1/KEY/ksk-2516425377094")
        keyLocator = KeyLocator()
        keyLocator.setType(KeyLocatorType.KEYNAME)
        keyLocator.setKeyName(keyLocatorName)
        signatureInfo.setKeyLocator(keyLocator)

        period = ValidityPeriod()
        period.setPeriod(fromIsoString("20141111T050000"),
                         fromIsoString("20141111T060000"))
        signatureInfo.setValidityPeriod(period)

        block2 = Blob(SIG_VALUE, False)
        signatureInfo.setSignature(block2)

        return signatureInfo
Exemplo n.º 8
0
    def test_constructor(self):
        # Check default settings.
        content = EncryptedContent()
        self.assertEqual(content.getAlgorithmType(), None)
        self.assertTrue(content.getPayload().isNull())
        self.assertTrue(content.getInitialVector().isNull())
        self.assertEqual(content.getKeyLocator().getType(), None)

        # Check an encrypted content with IV.
        keyLocator = KeyLocator()
        keyLocator.setType(KeyLocatorType.KEYNAME)
        keyLocator.getKeyName().set("/test/key/locator")
        rsaOaepContent = EncryptedContent()
        rsaOaepContent.setAlgorithmType(
            EncryptAlgorithmType.RsaOaep).setKeyLocator(keyLocator).setPayload(
                Blob(message, False)).setInitialVector(Blob(iv, False))

        self.assertEqual(rsaOaepContent.getAlgorithmType(),
                         EncryptAlgorithmType.RsaOaep)
        self.assertTrue(rsaOaepContent.getPayload().equals(Blob(
            message, False)))
        self.assertTrue(rsaOaepContent.getInitialVector().equals(
            Blob(iv, False)))
        self.assertTrue(rsaOaepContent.getKeyLocator().getType() != None)
        self.assertTrue(rsaOaepContent.getKeyLocator().getKeyName().equals(
            Name("/test/key/locator")))

        # Encoding.
        encryptedBlob = Blob(encrypted, False)
        encoded = rsaOaepContent.wireEncode()

        self.assertTrue(encryptedBlob.equals(encoded))

        # Decoding.
        rsaOaepContent2 = EncryptedContent()
        rsaOaepContent2.wireDecode(encryptedBlob)
        self.assertEqual(rsaOaepContent2.getAlgorithmType(),
                         EncryptAlgorithmType.RsaOaep)
        self.assertTrue(rsaOaepContent2.getPayload().equals(
            Blob(message, False)))
        self.assertTrue(rsaOaepContent2.getInitialVector().equals(
            Blob(iv, False)))
        self.assertTrue(rsaOaepContent2.getKeyLocator().getType() != None)
        self.assertTrue(rsaOaepContent2.getKeyLocator().getKeyName().equals(
            Name("/test/key/locator")))

        # Check the no IV case.
        rsaOaepContentNoIv = EncryptedContent()
        rsaOaepContentNoIv.setAlgorithmType(
            EncryptAlgorithmType.RsaOaep).setKeyLocator(keyLocator).setPayload(
                Blob(message, False))
        self.assertEqual(rsaOaepContentNoIv.getAlgorithmType(),
                         EncryptAlgorithmType.RsaOaep)
        self.assertTrue(rsaOaepContentNoIv.getPayload().equals(
            Blob(message, False)))
        self.assertTrue(rsaOaepContentNoIv.getInitialVector().isNull())
        self.assertTrue(rsaOaepContentNoIv.getKeyLocator().getType() != None)
        self.assertTrue(rsaOaepContentNoIv.getKeyLocator().getKeyName().equals(
            Name("/test/key/locator")))

        # Encoding.
        encryptedBlob2 = Blob(encryptedNoIv, False)
        encodedNoIv = rsaOaepContentNoIv.wireEncode()
        self.assertTrue(encryptedBlob2.equals(encodedNoIv))

        # Decoding.
        rsaOaepContentNoIv2 = EncryptedContent()
        rsaOaepContentNoIv2.wireDecode(encryptedBlob2)
        self.assertEqual(rsaOaepContentNoIv2.getAlgorithmType(),
                         EncryptAlgorithmType.RsaOaep)
        self.assertTrue(rsaOaepContentNoIv2.getPayload().equals(
            Blob(message, False)))
        self.assertTrue(rsaOaepContentNoIv2.getInitialVector().isNull())
        self.assertTrue(rsaOaepContentNoIv2.getKeyLocator().getType() != None)
        self.assertTrue(
            rsaOaepContentNoIv2.getKeyLocator().getKeyName().equals(
                Name("/test/key/locator")))
Exemplo n.º 9
0
    def test_constructor(self):
        # Check default settings.
        content = EncryptedContent()
        self.assertEqual(content.getAlgorithmType(), None)
        self.assertTrue(content.getPayload().isNull())
        self.assertTrue(content.getInitialVector().isNull())
        self.assertEqual(content.getKeyLocator().getType(), None)

        # Check an encrypted content with IV.
        keyLocator = KeyLocator()
        keyLocator.setType(KeyLocatorType.KEYNAME)
        keyLocator.getKeyName().set("/test/key/locator")
        rsaOaepContent = EncryptedContent()
        rsaOaepContent.setAlgorithmType(EncryptAlgorithmType.RsaOaep).setKeyLocator(
          keyLocator).setPayload(Blob(message, False)).setInitialVector(Blob(iv, False))

        self.assertEqual(rsaOaepContent.getAlgorithmType(), EncryptAlgorithmType.RsaOaep)
        self.assertTrue(rsaOaepContent.getPayload().equals(Blob(message, False)))
        self.assertTrue(rsaOaepContent.getInitialVector().equals(Blob(iv, False)))
        self.assertTrue(rsaOaepContent.getKeyLocator().getType() != None)
        self.assertTrue(rsaOaepContent.getKeyLocator().getKeyName().equals(
          Name("/test/key/locator")))

        # Encoding.
        encryptedBlob = Blob(encrypted, False)
        encoded = rsaOaepContent.wireEncode()

        self.assertTrue(encryptedBlob.equals(encoded))

        # Decoding.
        rsaOaepContent2 = EncryptedContent()
        rsaOaepContent2.wireDecode(encryptedBlob)
        self.assertEqual(rsaOaepContent2.getAlgorithmType(), EncryptAlgorithmType.RsaOaep)
        self.assertTrue(rsaOaepContent2.getPayload().equals(Blob(message, False)))
        self.assertTrue(rsaOaepContent2.getInitialVector().equals(Blob(iv, False)))
        self.assertTrue(rsaOaepContent2.getKeyLocator().getType() != None)
        self.assertTrue(rsaOaepContent2.getKeyLocator().getKeyName().equals(
          Name("/test/key/locator")))

        # Check the no IV case.
        rsaOaepContentNoIv = EncryptedContent()
        rsaOaepContentNoIv.setAlgorithmType(EncryptAlgorithmType.RsaOaep).setKeyLocator(
          keyLocator).setPayload(Blob(message, False))
        self.assertEqual(rsaOaepContentNoIv.getAlgorithmType(), EncryptAlgorithmType.RsaOaep)
        self.assertTrue(rsaOaepContentNoIv.getPayload().equals(Blob(message, False)))
        self.assertTrue(rsaOaepContentNoIv.getInitialVector().isNull())
        self.assertTrue(rsaOaepContentNoIv.getKeyLocator().getType() != None)
        self.assertTrue(rsaOaepContentNoIv.getKeyLocator().getKeyName().equals(
          Name("/test/key/locator")))

        # Encoding.
        encryptedBlob2 = Blob(encryptedNoIv, False)
        encodedNoIv = rsaOaepContentNoIv.wireEncode()
        self.assertTrue(encryptedBlob2.equals(encodedNoIv))

        # Decoding.
        rsaOaepContentNoIv2 = EncryptedContent()
        rsaOaepContentNoIv2.wireDecode(encryptedBlob2)
        self.assertEqual(rsaOaepContentNoIv2.getAlgorithmType(), EncryptAlgorithmType.RsaOaep)
        self.assertTrue(rsaOaepContentNoIv2.getPayload().equals(Blob(message, False)))
        self.assertTrue(rsaOaepContentNoIv2.getInitialVector().isNull())
        self.assertTrue(rsaOaepContentNoIv2.getKeyLocator().getType() != None)
        self.assertTrue(rsaOaepContentNoIv2.getKeyLocator().getKeyName().equals(
          Name("/test/key/locator")))