Пример #1
0
    def setManager(self, manager):
        # Set up the first schedule.
        schedule1 = Schedule()
        interval11 = RepetitiveInterval(
            Schedule.fromIsoString("20150825T000000"),
            Schedule.fromIsoString("20150827T000000"), 5, 10, 2,
            RepetitiveInterval.RepeatUnit.DAY)
        interval12 = RepetitiveInterval(
            Schedule.fromIsoString("20150825T000000"),
            Schedule.fromIsoString("20150827T000000"), 6, 8, 1,
            RepetitiveInterval.RepeatUnit.DAY)
        interval13 = RepetitiveInterval(
            Schedule.fromIsoString("20150827T000000"),
            Schedule.fromIsoString("20150827T000000"), 7, 8)
        schedule1.addWhiteInterval(interval11)
        schedule1.addWhiteInterval(interval12)
        schedule1.addBlackInterval(interval13)

        # Set up the second schedule.
        schedule2 = Schedule()
        interval21 = RepetitiveInterval(
            Schedule.fromIsoString("20150825T000000"),
            Schedule.fromIsoString("20150827T000000"), 9, 12, 1,
            RepetitiveInterval.RepeatUnit.DAY)
        interval22 = RepetitiveInterval(
            Schedule.fromIsoString("20150827T000000"),
            Schedule.fromIsoString("20150827T000000"), 6, 8)
        interval23 = RepetitiveInterval(
            Schedule.fromIsoString("20150827T000000"),
            Schedule.fromIsoString("20150827T000000"), 2, 4)
        schedule2.addWhiteInterval(interval21)
        schedule2.addWhiteInterval(interval22)
        schedule2.addBlackInterval(interval23)

        # Add them to the group manager database.
        manager.addSchedule("schedule1", schedule1)
        manager.addSchedule("schedule2", schedule2)

        # Make some adaptions to certificate.
        dataBlob = self.certificate.wireEncode()

        memberA = Data()
        memberA.wireDecode(dataBlob, TlvWireFormat.get())
        memberA.setName(Name("/ndn/memberA/KEY/ksk-123/ID-CERT/123"))
        memberB = Data()
        memberB.wireDecode(dataBlob, TlvWireFormat.get())
        memberB.setName(Name("/ndn/memberB/KEY/ksk-123/ID-CERT/123"))
        memberC = Data()
        memberC.wireDecode(dataBlob, TlvWireFormat.get())
        memberC.setName(Name("/ndn/memberC/KEY/ksk-123/ID-CERT/123"))

        # Add the members to the database.
        manager.addMember("schedule1", memberA)
        manager.addMember("schedule1", memberB)
        manager.addMember("schedule2", memberC)
Пример #2
0
    def setManager(self, manager):
        # Set up the first schedule.
        schedule1 = Schedule()
        interval11 = RepetitiveInterval(
          Schedule.fromIsoString("20150825T000000"),
          Schedule.fromIsoString("20150827T000000"), 5, 10, 2,
          RepetitiveInterval.RepeatUnit.DAY)
        interval12 = RepetitiveInterval(
          Schedule.fromIsoString("20150825T000000"),
          Schedule.fromIsoString("20150827T000000"), 6, 8, 1,
          RepetitiveInterval.RepeatUnit.DAY)
        interval13 = RepetitiveInterval(
          Schedule.fromIsoString("20150827T000000"),
          Schedule.fromIsoString("20150827T000000"), 7, 8)
        schedule1.addWhiteInterval(interval11)
        schedule1.addWhiteInterval(interval12)
        schedule1.addBlackInterval(interval13)

        # Set up the second schedule.
        schedule2 = Schedule()
        interval21 = RepetitiveInterval(
          Schedule.fromIsoString("20150825T000000"),
          Schedule.fromIsoString("20150827T000000"), 9, 12, 1,
          RepetitiveInterval.RepeatUnit.DAY)
        interval22 = RepetitiveInterval(
          Schedule.fromIsoString("20150827T000000"),
          Schedule.fromIsoString("20150827T000000"), 6, 8)
        interval23 = RepetitiveInterval(
          Schedule.fromIsoString("20150827T000000"),
          Schedule.fromIsoString("20150827T000000"), 2, 4)
        schedule2.addWhiteInterval(interval21)
        schedule2.addWhiteInterval(interval22)
        schedule2.addBlackInterval(interval23)

        # Add them to the group manager database.
        manager.addSchedule("schedule1", schedule1)
        manager.addSchedule("schedule2", schedule2)

        # Make some adaptions to certificate.
        dataBlob = self.certificate.wireEncode()

        memberA = Data()
        memberA.wireDecode(dataBlob, TlvWireFormat.get())
        memberA.setName(Name("/ndn/memberA/KEY/ksk-123/ID-CERT/123"))
        memberB = Data()
        memberB.wireDecode(dataBlob, TlvWireFormat.get())
        memberB.setName(Name("/ndn/memberB/KEY/ksk-123/ID-CERT/123"))
        memberC = Data()
        memberC.wireDecode(dataBlob, TlvWireFormat.get())
        memberC.setName(Name("/ndn/memberC/KEY/ksk-123/ID-CERT/123"))

        # Add the members to the database.
        manager.addMember("schedule1", memberA)
        manager.addMember("schedule1", memberB)
        manager.addMember("schedule2", memberC)
Пример #3
0
    def test_congestion_mark(self):
        # Imitate onReceivedElement.
        lpPacket = LpPacket()
        # Set copy False so that the fragment is a slice which will be
        # copied below. The header fields are all integers and don't need to
        # be copied.
        TlvWireFormat.get().decodeLpPacket(lpPacket, CONGESTION_MARK_PACKET.buf(), False)
        element = lpPacket.getFragmentWireEncoding().buf()

        data = Data()
        data.wireDecode(element, TlvWireFormat.get())
        data.setLpPacket(lpPacket)

        self.assertEqual(1, data.getCongestionMark())
Пример #4
0
    def test_congestion_mark(self):
        # Imitate onReceivedElement.
        lpPacket = LpPacket()
        # Set copy False so that the fragment is a slice which will be
        # copied below. The header fields are all integers and don't need to
        # be copied.
        TlvWireFormat.get().decodeLpPacket(lpPacket, CONGESTION_MARK_PACKET.buf(), False)
        element = lpPacket.getFragmentWireEncoding().buf()

        data = Data()
        data.wireDecode(element, TlvWireFormat.get())
        data.setLpPacket(lpPacket)

        self.assertEqual(1, data.getCongestionMark())
 def test_missing_key_locator(self):
     interest1 = self._fixture.makeCommandInterest(self._fixture._identity)
     signatureInfo = Sha256WithRsaSignature()
     setNameComponent(
       interest1, CommandInterestSigner.POS_SIGNATURE_INFO,
       TlvWireFormat.get().encodeSignatureInfo(signatureInfo))
     self.validateExpectFailure(interest1, "Should fail (missing KeyLocator)")
 def test_missing_key_locator(self):
     interest1 = self._fixture.makeCommandInterest(self._fixture._identity)
     signatureInfo = Sha256WithRsaSignature()
     setNameComponent(
         interest1, CommandInterestSigner.POS_SIGNATURE_INFO,
         TlvWireFormat.get().encodeSignatureInfo(signatureInfo))
     self.validateExpectFailure(interest1,
                                "Should fail (missing KeyLocator)")
    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)")
Пример #8
0
    def test_encode_decode(self):
        name = Name("/local/ndn/prefix")

        encoding = name.wireEncode(TlvWireFormat.get())
        self.assertTrue(encoding.equals(Blob(TEST_NAME)))

        decodedName = Name()
        decodedName.wireDecode(Blob(TEST_NAME), TlvWireFormat.get())
        self.assertEqual(decodedName, name)

        # Test ImplicitSha256Digest.
        name2 = Name(
          "/local/ndn/prefix/sha256digest=" +
          "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")

        encoding2 = name2.wireEncode(TlvWireFormat.get())
        self.assertTrue(encoding2.equals(Blob(TEST_NAME_IMPLICIT_DIGEST)))

        decodedName2 = Name()
        decodedName2.wireDecode(Blob(TEST_NAME_IMPLICIT_DIGEST), TlvWireFormat.get())
        self.assertEqual(decodedName2, name2)
Пример #9
0
    def test_encode_decode(self):
        name = Name("/local/ndn/prefix")

        encoding = name.wireEncode(TlvWireFormat.get())
        self.assertTrue(encoding.equals(Blob(TEST_NAME)))

        decodedName = Name()
        decodedName.wireDecode(Blob(TEST_NAME), TlvWireFormat.get())
        self.assertEqual(decodedName, name)

        # Test ImplicitSha256Digest.
        name2 = Name(
          "/local/ndn/prefix/sha256digest=" +
          "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")

        encoding2 = name2.wireEncode(TlvWireFormat.get())
        self.assertTrue(encoding2.equals(Blob(TEST_NAME_IMPLICIT_DIGEST)))

        decodedName2 = Name()
        decodedName2.wireDecode(Blob(TEST_NAME_IMPLICIT_DIGEST), TlvWireFormat.get())
        self.assertEqual(decodedName2, name2)
    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)")
Пример #13
0
    def setUp(self):
        # Reuse the policy_config subdirectory for the temporary SQLite files.
        self.dKeyDatabaseFilePath = "policy_config/manager-d-key-test.db"
        try:
            os.remove(self.dKeyDatabaseFilePath)
        except OSError:
            # no such file
            pass

        self.eKeyDatabaseFilePath = "policy_config/manager-e-key-test.db"
        try:
            os.remove(self.eKeyDatabaseFilePath)
        except OSError:
            # no such file
            pass

        self.intervalDatabaseFilePath = "policy_config/manager-interval-test.db"
        try:
            os.remove(self.intervalDatabaseFilePath)
        except OSError:
            # no such file
            pass

        self.groupKeyDatabaseFilePath = "policy_config/manager-group-key-test.db"
        try:
            os.remove(self.groupKeyDatabaseFilePath)
        except OSError:
            # no such file
            pass

        params = RsaKeyParams()
        memberDecryptKey = RsaAlgorithm.generateKey(params)
        self.decryptKeyBlob = memberDecryptKey.getKeyBits()
        memberEncryptKey = RsaAlgorithm.deriveEncryptKey(self.decryptKeyBlob)
        self.encryptKeyBlob = memberEncryptKey.getKeyBits()

        # Generate the certificate.
        self.certificate = IdentityCertificate()
        self.certificate.setName(Name("/ndn/memberA/KEY/ksk-123/ID-CERT/123"))
        contentPublicKey = PublicKey(self.encryptKeyBlob)
        self.certificate.setPublicKeyInfo(contentPublicKey)
        self.certificate.setNotBefore(0)
        self.certificate.setNotAfter(0)
        self.certificate.encode()

        signatureInfoBlob = Blob(SIG_INFO, False)
        signatureValueBlob = Blob(SIG_VALUE, False)

        signature = TlvWireFormat.get().decodeSignatureInfoAndValue(
            signatureInfoBlob.buf(), signatureValueBlob.buf())
        self.certificate.setSignature(signature)

        self.certificate.wireEncode()

        # Set up the keyChain.
        identityStorage = MemoryIdentityStorage()
        privateKeyStorage = MemoryPrivateKeyStorage()
        self.keyChain = KeyChain(
            IdentityManager(identityStorage, privateKeyStorage),
            NoVerifyPolicyManager())
        identityName = Name("TestGroupManager")
        self.keyChain.createIdentityAndCertificate(identityName)
        self.keyChain.getIdentityManager().setDefaultIdentity(identityName)
Пример #14
0
    def setUp(self):
        # Reuse the policy_config subdirectory for the temporary SQLite files.
        self.dKeyDatabaseFilePath = "policy_config/manager-d-key-test.db"
        try:
            os.remove(self.dKeyDatabaseFilePath)
        except OSError:
            # no such file
            pass

        self.eKeyDatabaseFilePath = "policy_config/manager-e-key-test.db"
        try:
            os.remove(self.eKeyDatabaseFilePath)
        except OSError:
            # no such file
            pass

        self.intervalDatabaseFilePath = "policy_config/manager-interval-test.db"
        try:
            os.remove(self.intervalDatabaseFilePath)
        except OSError:
            # no such file
            pass

        self.groupKeyDatabaseFilePath = "policy_config/manager-group-key-test.db"
        try:
            os.remove(self.groupKeyDatabaseFilePath)
        except OSError:
            # no such file
            pass

        params = RsaKeyParams()
        memberDecryptKey = RsaAlgorithm.generateKey(params)
        self.decryptKeyBlob = memberDecryptKey.getKeyBits()
        memberEncryptKey = RsaAlgorithm.deriveEncryptKey(self.decryptKeyBlob)
        self.encryptKeyBlob = memberEncryptKey.getKeyBits()

        # Generate the certificate.
        self.certificate = IdentityCertificate()
        self.certificate.setName(Name("/ndn/memberA/KEY/ksk-123/ID-CERT/123"))
        contentPublicKey = PublicKey(self.encryptKeyBlob)
        self.certificate.setPublicKeyInfo(contentPublicKey)
        self.certificate.setNotBefore(0)
        self.certificate.setNotAfter(0)
        self.certificate.encode()

        signatureInfoBlob = Blob(SIG_INFO, False)
        signatureValueBlob = Blob(SIG_VALUE, False)

        signature = TlvWireFormat.get().decodeSignatureInfoAndValue(
          signatureInfoBlob.buf(), signatureValueBlob.buf())
        self.certificate.setSignature(signature)

        self.certificate.wireEncode()

        # Set up the keyChain.
        identityStorage = MemoryIdentityStorage()
        privateKeyStorage = MemoryPrivateKeyStorage()
        self.keyChain = KeyChain(
          IdentityManager(identityStorage, privateKeyStorage),
          NoVerifyPolicyManager())
        identityName = Name("TestGroupManager")
        self.keyChain.createIdentityAndCertificate(identityName)
        self.keyChain.getIdentityManager().setDefaultIdentity(identityName)