BOOST_FIXTURE_TEST_CASE(GeneralSigningInterface, IdentityManagementFixture) { Name id("/id"); Name certName = m_keyChain.createIdentity(id); shared_ptr<v1::IdentityCertificate> idCert = m_keyChain.getCertificate(certName); Name keyName = idCert->getPublicKeyName(); m_keyChain.setDefaultIdentity(id); Name id2("/id2"); Name cert2Name = m_keyChain.createIdentity(id2); shared_ptr<v1::IdentityCertificate> id2Cert = m_keyChain.getCertificate(cert2Name); // SigningInfo is set to default Data data1("/data1"); m_keyChain.sign(data1); BOOST_CHECK(Validator::verifySignature(data1, idCert->getPublicKeyInfo())); BOOST_CHECK_EQUAL(data1.getSignature().getKeyLocator().getName(), certName.getPrefix(-1)); Interest interest1("/interest1"); m_keyChain.sign(interest1); BOOST_CHECK(Validator::verifySignature(interest1, idCert->getPublicKeyInfo())); SignatureInfo sigInfo1(interest1.getName()[-2].blockFromValue()); BOOST_CHECK_EQUAL(sigInfo1.getKeyLocator().getName(), certName.getPrefix(-1)); // SigningInfo is set to Identity Data data2("/data2"); m_keyChain.sign(data2, SigningInfo(SigningInfo::SIGNER_TYPE_ID, id2)); BOOST_CHECK(Validator::verifySignature(data2, id2Cert->getPublicKeyInfo())); BOOST_CHECK_EQUAL(data2.getSignature().getKeyLocator().getName(), cert2Name.getPrefix(-1)); Interest interest2("/interest2"); m_keyChain.sign(interest2, SigningInfo(SigningInfo::SIGNER_TYPE_ID, id2)); BOOST_CHECK(Validator::verifySignature(interest2, id2Cert->getPublicKeyInfo())); SignatureInfo sigInfo2(interest2.getName()[-2].blockFromValue()); BOOST_CHECK_EQUAL(sigInfo2.getKeyLocator().getName(), cert2Name.getPrefix(-1)); // SigningInfo is set to Key Data data3("/data3"); m_keyChain.sign(data3, SigningInfo(SigningInfo::SIGNER_TYPE_KEY, keyName)); BOOST_CHECK(Validator::verifySignature(data3, idCert->getPublicKeyInfo())); BOOST_CHECK_EQUAL(data3.getSignature().getKeyLocator().getName(), certName.getPrefix(-1)); Interest interest3("/interest3"); m_keyChain.sign(interest3); BOOST_CHECK(Validator::verifySignature(interest3, idCert->getPublicKeyInfo())); SignatureInfo sigInfo3(interest1.getName()[-2].blockFromValue()); BOOST_CHECK_EQUAL(sigInfo3.getKeyLocator().getName(), certName.getPrefix(-1)); // SigningInfo is set to Cert Data data4("/data4"); m_keyChain.sign(data4, SigningInfo(SigningInfo::SIGNER_TYPE_CERT, certName)); BOOST_CHECK(Validator::verifySignature(data4, idCert->getPublicKeyInfo())); BOOST_CHECK_EQUAL(data4.getSignature().getKeyLocator().getName(), certName.getPrefix(-1)); Interest interest4("/interest4"); m_keyChain.sign(interest4, SigningInfo(SigningInfo::SIGNER_TYPE_CERT, certName)); BOOST_CHECK(Validator::verifySignature(interest4, idCert->getPublicKeyInfo())); SignatureInfo sigInfo4(interest4.getName()[-2].blockFromValue()); BOOST_CHECK_EQUAL(sigInfo4.getKeyLocator().getName(), certName.getPrefix(-1)); // SigningInfo is set to DigestSha256 Data data5("/data5"); m_keyChain.sign(data5, SigningInfo(SigningInfo::SIGNER_TYPE_SHA256)); BOOST_CHECK(Validator::verifySignature(data5, DigestSha256(data5.getSignature()))); Interest interest5("/interest4"); m_keyChain.sign(interest5, SigningInfo(SigningInfo::SIGNER_TYPE_SHA256)); BOOST_CHECK(Validator::verifySignature(interest5, DigestSha256(Signature(interest5.getName()[-2].blockFromValue(), interest5.getName()[-1].blockFromValue())))); }
BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture) { UdpFactory factory; factory.createChannel("::1", "20071"); factory.createFace(FaceUri("udp://[::1]:20070"), bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, "UdpChannel error: cannot connect or cannot accept connection"); BOOST_REQUIRE(static_cast<bool>(face2)); BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "udp6://[::1]:20070"); BOOST_CHECK_EQUAL(face2->getLocalUri().toString(), "udp6://[::1]:20071"); BOOST_CHECK_EQUAL(face2->isLocal(), false); // face1 is not created yet shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); Interest interest1("ndn:/TpnzGvW9R"); Data data1 ("ndn:/KfczhUqVix"); data1.setContent(0, 0); Interest interest2("ndn:/QWiIMfj5sL"); Data data2 ("ndn:/XNBV796f"); data2.setContent(0, 0); Interest interest3("ndn:/QWiIhjgkj5sL"); Data data3 ("ndn:/XNBV794f"); data3.setContent(0, 0); ndn::SignatureSha256WithRsa fakeSignature; fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0)); // set fake signature on data1 and data2 data1.setSignature(fakeSignature); data2.setSignature(fakeSignature); data3.setSignature(fakeSignature); face2->sendInterest(interest2); face2->sendData (data2 ); BOOST_CHECK_MESSAGE(limitedIo.run(3,//2 send + 1 listen return time::seconds(1)) == LimitedIo::EXCEED_OPS, "UdpChannel error: cannot send or receive Interest/Data packets"); BOOST_REQUIRE(static_cast<bool>(face1)); BOOST_CHECK_EQUAL(face1->getRemoteUri().toString(), "udp6://[::1]:20071"); BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "udp6://[::1]:20070"); BOOST_CHECK_EQUAL(face1->isLocal(), false); face1->sendInterest(interest1); face1->sendData (data1 ); BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "UdpChannel error: cannot send or receive Interest/Data packets"); BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); //checking if the connection accepting mechanism works properly. face2->sendData (data3 ); face2->sendInterest(interest3); BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "UdpChannel error: cannot send or receive Interest/Data packets"); BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 2); BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); BOOST_CHECK_EQUAL(face1_receivedDatas [1].getName(), data3.getName()); }