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)")
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 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
def signData(self, data): data.setSignature(Sha256WithRsaSignature())
def test_matches_data(self): interest = Interest(Name("/A")) interest.setMinSuffixComponents(2) interest.setMaxSuffixComponents(2) interest.getKeyLocator().setType(KeyLocatorType.KEYNAME) interest.getKeyLocator().setKeyName(Name("/B")) interest.getExclude().appendComponent(Name.Component("J")) interest.getExclude().appendAny() data = Data(Name("/A/D")) signature = Sha256WithRsaSignature() signature.getKeyLocator().setType(KeyLocatorType.KEYNAME) signature.getKeyLocator().setKeyName(Name("/B")) data.setSignature(signature) self.assertEqual(interest.matchesData(data), True) # Check violating MinSuffixComponents. data1 = Data(data) data1.setName(Name("/A")) self.assertEqual(interest.matchesData(data1), False) interest1 = Interest(interest) interest1.setMinSuffixComponents(1) self.assertEqual(interest1.matchesData(data1), True) # Check violating MaxSuffixComponents. data2 = Data(data) data2.setName(Name("/A/E/F")) self.assertEqual(interest.matchesData(data2), False) interest2 = Interest(interest) interest2.setMaxSuffixComponents(3) self.assertEqual(interest2.matchesData(data2), True) # Check violating PublisherPublicKeyLocator. data3 = Data(data) signature3 = Sha256WithRsaSignature() signature3.getKeyLocator().setType(KeyLocatorType.KEYNAME) signature3.getKeyLocator().setKeyName(Name("/G")) data3.setSignature(signature3) self.assertEqual(interest.matchesData(data3), False) interest3 = Interest(interest) interest3.getKeyLocator().setType(KeyLocatorType.KEYNAME) interest3.getKeyLocator().setKeyName(Name("/G")) self.assertEqual(interest3.matchesData(data3), True) data4 = Data(data) data4.setSignature(DigestSha256Signature()) self.assertEqual(interest.matchesData(data4), False) interest4 = Interest(interest) interest4.setKeyLocator(KeyLocator()) self.assertEqual(interest4.matchesData(data4), True) # Check violating Exclude. data5 = Data(data) data5.setName(Name("/A/J")) self.assertEqual(interest.matchesData(data5), False) interest5 = Interest(interest) interest5.getExclude().clear() interest5.getExclude().appendComponent(Name.Component("K")) interest5.getExclude().appendAny() self.assertEqual(interest5.matchesData(data5), True) # Check violating Name. data6 = Data(data) data6.setName(Name("/H/I")) self.assertEqual(interest.matchesData(data6), False) data7 = Data(data) data7.setName(Name("/A/B")) interest7 = Interest( Name("/A/B/sha256digest=" + "54008e240a7eea2714a161dfddf0dd6ced223b3856e9da96792151e180f3b128")) self.assertEqual(interest7.matchesData(data7), True) # Check violating the implicit digest. interest7b = Interest( Name("/A/B/%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00" + "%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00")) self.assertEqual(interest7b.matchesData(data7), False) # Check excluding the implicit digest. interest8 = Interest(Name("/A/B")) interest8.getExclude().appendComponent(interest7.getName().get(2)) self.assertEqual(interest8.matchesData(data7), False)
def test_matches_data(self): interest = Interest(Name("/A")) interest.setCanBePrefix(False) # Check violating CanBePrefix. data = Data(Name("/A/D")) self.assertEqual(interest.matchesData(data), False) # Check violating PublisherPublicKeyLocator. data3 = Data(data) signature3 = Sha256WithRsaSignature() signature3.getKeyLocator().setType(KeyLocatorType.KEYNAME) signature3.getKeyLocator().setKeyName(Name("/G")) data3.setSignature(signature3) self.assertEqual(interest.matchesData(data3), False) # Do not test keylocator in interest packet #interest3 = Interest(interest) #interest3.getKeyLocator().setType(KeyLocatorType.KEYNAME) #interest3.getKeyLocator().setKeyName(Name("/G")) #self.assertEqual(interest3.matchesData(data3), True) data4 = Data(data) data4.setSignature(DigestSha256Signature()) self.assertEqual(interest.matchesData(data4), False) # Do not test keylocator in interest packet #interest4 = Interest(interest) #interest4.setKeyLocator(KeyLocator()) #self.assertEqual(interest4.matchesData(data4), True) # Check violating Exclude. data5 = Data(data) data5.setName(Name("/A/J")) self.assertEqual(interest.matchesData(data5), False) # Check violating Name. data6 = Data(data) data6.setName(Name("/H/I")) self.assertEqual(interest.matchesData(data6), False) data7 = Data(data) data7.setName(Name("/A/B")) interest7 = Interest( Name( "/A/B/sha256digest=" + "54008e240a7eea2714a161dfddf0dd6ced223b3856e9da96792151e180f3b128" )) self.assertEqual(interest7.matchesData(data7), True) # Check violating the implicit digest. interest7b = Interest( Name("/A/B/%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00" + "%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00")) self.assertEqual(interest7b.matchesData(data7), False) # Check excluding the implicit digest. interest8 = Interest(Name("/A/B")) interest8.getExclude().appendComponent(interest7.getName().get(2)) self.assertEqual(interest8.matchesData(data7), False)