diff options
Diffstat (limited to 'apps/ping/src/ping_server.cc')
-rw-r--r-- | apps/ping/src/ping_server.cc | 162 |
1 files changed, 104 insertions, 58 deletions
diff --git a/apps/ping/src/ping_server.cc b/apps/ping/src/ping_server.cc index 3ffbc7325..dd7d23b5e 100644 --- a/apps/ping/src/ping_server.cc +++ b/apps/ping/src/ping_server.cc @@ -22,6 +22,7 @@ #endif #include <hicn/transport/auth/signer.h> +#include <hicn/transport/auth/verifier.h> #include <hicn/transport/core/content_object.h> #include <hicn/transport/core/interest.h> #include <hicn/transport/interfaces/global_conf_interface.h> @@ -42,7 +43,8 @@ class CallbackContainer { public: CallbackContainer(const Name &prefix, uint32_t object_size, bool verbose, bool dump, bool quite, bool flags, bool reset, uint8_t ttl, - auth::Signer *signer, bool sign, uint32_t lifetime) + auth::Signer *signer, bool sign, std::string passphrase, + uint32_t lifetime) : buffer_(object_size, 'X'), content_objects_((std::uint32_t)(1 << log2_content_object_buffer_size)), mask_((std::uint16_t)(1 << log2_content_object_buffer_size) - 1), @@ -55,8 +57,11 @@ class CallbackContainer { ttl_(ttl), signer_(signer), sign_(sign) { - core::Packet::Format format; + // Verifier for interest manifests + if (!passphrase.empty()) + verifier_ = std::make_unique<auth::SymmetricVerifier>(passphrase); + core::Packet::Format format; if (prefix.getAddressFamily() == AF_INET) { format = core::Packet::Format::HF_INET_TCP; if (sign_) { @@ -76,14 +81,28 @@ class CallbackContainer { } } - void processInterest(ProducerSocket &p, const Interest &interest, + void processInterest(ProducerSocket &p, Interest &interest, uint32_t lifetime) { + if (verifier_ && interest.hasManifest()) { + auto t0 = utils::SteadyTime::now(); + if (verifier_->verifyPacket(&interest)) { + auto t1 = utils::SteadyTime::now(); + auto dt = utils::SteadyTime::getDurationUs(t0, t1); + std::cout << "Verification time: " << dt.count() << std::endl; + std::cout << "<<< Signature Ok." << std::endl; + } else { + std::cout << "<<< Signature verification failed!" << std::endl; + } + } + if (verbose_) { std::cout << "<<< received interest " << interest.getName() << " src port: " << interest.getSrcPort() << " dst port: " << interest.getDstPort() << " flags: " << interest.printFlags() - << "TTL: " << (int)interest.getTTL() << std::endl; + << "TTL: " << (int)interest.getTTL() + << " suffixes in manifest: " << interest.numberOfSuffixes() + << std::endl; } else if (!quite_) { std::cout << "<<< received interest " << interest.getName() << std::endl; } @@ -97,54 +116,74 @@ class CallbackContainer { if (interest.testRst()) { std::cout << "!!!got a reset, I don't reply" << std::endl; } else { - auto &content_object = content_objects_[content_objects_index_++ & mask_]; - - content_object->setName(interest.getName()); - content_object->setLifetime(lifetime); - content_object->setLocator(interest.getLocator()); - content_object->setSrcPort(interest.getDstPort()); - content_object->setDstPort(interest.getSrcPort()); - content_object->setTTL(ttl_); - - if (!sign_) { - content_object->resetFlags(); - } - - if (flags_) { - if (interest.testSyn()) { - content_object->setSyn(); - content_object->setAck(); - } else if (interest.testAck()) { - content_object->setAck(); - } // here I may need to handle the FIN flag; - } else if (reset_) { - content_object->setRst(); - } - - if (verbose_) { - std::cout << ">>> send object " << content_object->getName() - << " src port: " << content_object->getSrcPort() - << " dst port: " << content_object->getDstPort() - << " flags: " << content_object->printFlags() - << " TTL: " << (int)content_object->getTTL() << std::endl; - } else if (!quite_) { - std::cout << ">>> send object " << content_object->getName() - << std::endl; - } - - if (dump_) { - std::cout << "----- object dump -----" << std::endl; - content_object->dump(); - std::cout << "-----------------------" << std::endl; - } + uint32_t *suffix = interest.firstSuffix(); + uint32_t n_suffixes_in_manifest = interest.numberOfSuffixes(); + uint32_t *request_bitmap = interest.getRequestBitmap(); + if (!interest.isValid()) throw std::runtime_error("Bad interest format"); + + Name name = interest.getName(); + uint32_t pos = 0; // Position of current suffix in manifest + do { + // If suffix can be processed, i.e. no manifest with bitmap excluding it + if (!interest.hasManifest() || is_bit_set(request_bitmap, pos)) { + auto &content_object = + content_objects_[content_objects_index_++ & mask_]; + + content_object->setName(interest.getName()); + content_object->setLifetime(lifetime); + content_object->setLocator(interest.getLocator()); + content_object->setSrcPort(interest.getDstPort()); + content_object->setDstPort(interest.getSrcPort()); + content_object->setTTL(ttl_); + + if (!sign_) { + content_object->resetFlags(); + } + + if (flags_) { + if (interest.testSyn()) { + content_object->setSyn(); + content_object->setAck(); + } else if (interest.testAck()) { + content_object->setAck(); + } // here I may need to handle the FIN flag; + } else if (reset_) { + content_object->setRst(); + } + + if (verbose_) { + std::cout << ">>> send object " << content_object->getName() + << " src port: " << content_object->getSrcPort() + << " dst port: " << content_object->getDstPort() + << " flags: " << content_object->printFlags() + << " TTL: " << (int)content_object->getTTL() << std::endl; + } else if (!quite_) { + std::cout << ">>> send object " << content_object->getName() + << std::endl; + } + + if (dump_) { + std::cout << "----- object dump -----" << std::endl; + content_object->dump(); + std::cout << "-----------------------" << std::endl; + } + + if (sign_ && signer_) { + signer_->signPacket(content_object.get()); + } + + p.produce(*content_object); + } + + if (interest.hasManifest()) { + uint32_t seq = *suffix; + suffix++; + + interest.setName(name.setSuffix(seq)); + } + } while (pos++ < n_suffixes_in_manifest); if (!quite_) std::cout << std::endl; - - if (sign_ && signer_) { - signer_->signPacket(content_object.get()); - } - - p.produce(*content_object); } } @@ -161,6 +200,7 @@ class CallbackContainer { uint8_t ttl_; auth::Signer *signer_; bool sign_; + std::unique_ptr<auth::Verifier> verifier_; }; void help() { @@ -199,6 +239,7 @@ void help() { } int main(int argc, char **argv) { + transport::interface::global_config::GlobalConfigInterface global_conf; #ifdef _WIN32 WSADATA wsaData = {0}; WSAStartup(MAKEWORD(2, 2), &wsaData); @@ -216,6 +257,7 @@ int main(int argc, char **argv) { uint8_t ttl = 64; std::string keystore_path = "./rsa_crypto_material.p12"; std::string keystore_password = "cisco"; + std::string passphrase = ""; bool sign = false; uint32_t data_lifetime = default_values::content_object_expiry_time; @@ -225,11 +267,14 @@ int main(int argc, char **argv) { int opt; #ifndef _WIN32 - while ((opt = getopt(argc, argv, "s:n:t:l:qfrVDdHk:p:z:F:")) != -1) { + while ((opt = getopt(argc, argv, "a:s:n:t:l:qfrVDdHk:p:z:F:")) != -1) { #else while ((opt = getopt(argc, argv, "s:n:t:l:qfrVDHk:p:z:F:")) != -1) { #endif switch (opt) { + case 'a': + passphrase = optarg; + break; case 's': object_size = std::stoi(optarg); break; @@ -298,7 +343,7 @@ int main(int argc, char **argv) { /** * Parse config file */ - transport::interface::global_config::parseConfigurationFile(conf_file); + global_conf.parseConfigurationFile(conf_file); core::Prefix producer_namespace(name_prefix); @@ -309,24 +354,25 @@ int main(int argc, char **argv) { if (object_size > 1350) object_size = 1350; CallbackContainer *stubs; - std::unique_ptr<auth::AsymmetricSigner> signer; + std::unique_ptr<auth::Signer> signer; if (sign) { signer = std::make_unique<auth::AsymmetricSigner>(keystore_path, keystore_password); - stubs = - new CallbackContainer(n, object_size, verbose, dump, quite, flags, - reset, ttl, signer.get(), sign, data_lifetime); + stubs = new CallbackContainer(n, object_size, verbose, dump, quite, flags, + reset, ttl, signer.get(), sign, passphrase, + data_lifetime); } else { auth::Signer *signer = nullptr; stubs = new CallbackContainer(n, object_size, verbose, dump, quite, flags, - reset, ttl, signer, sign, data_lifetime); + reset, ttl, signer, sign, passphrase, + data_lifetime); } ProducerSocket p; p.registerPrefix(producer_namespace); - p.setSocketOption(GeneralTransportOptions::MAKE_MANIFEST, false); + p.setSocketOption(GeneralTransportOptions::MANIFEST_MAX_CAPACITY, 0U); p.setSocketOption(GeneralTransportOptions::OUTPUT_BUFFER_SIZE, 0U); p.setSocketOption( ProducerCallbacksOptions::CACHE_MISS, |