void CertificateCacheTtl::remove(const Name& certificateName) { Name name = certificateName.getPrefix(-1); Cache::iterator it = m_cache.find(name); if (it != m_cache.end()) m_cache.erase(it); }
// Interface of different hash functions size_t computeHash(const Name& prefix) { prefix.wireEncode(); // guarantees prefix's wire buffer is not empty size_t hashValue = 0; size_t hashUpdate = 0; for (Name::const_iterator it = prefix.begin(); it != prefix.end(); it++) { const char* wireFormat = reinterpret_cast<const char*>( it->wire() ); hashUpdate = CityHash::compute(wireFormat, it->size()); hashValue ^= hashUpdate; } return hashValue; }
bool Helium::AssetIdentifier::Identify( Reflect::Object* object, Name& identity ) { Asset *pAsset = Reflect::SafeCast<Asset>(object); if ( pAsset ) { identity.Set(pAsset->GetPath().ToString()); HELIUM_TRACE( TraceLevels::Info, TXT( "Identifying object [%s]\n" ), identity.Get() ); return true; } else if ( object ) { HELIUM_TRACE( TraceLevels::Info, TXT( "Deferring identification of object of type [%s]\n" ), object->GetMetaClass()->m_Name ); } return false; }
void FilePrivateKeyStorage::deleteKeyPair(const Name& keyName) { string keyUri = keyName.toUri(); remove(nameTransform(keyUri, ".pub").c_str()); remove(nameTransform(keyUri, ".pri").c_str()); }
void producerDeniedRequest( const Name& producer_name, const Name& request_name, const string& why ) { if( logging_enabled ) { lock.lock(); log_file << "Producer:Denied" << endl << "{" << endl << " time = " << time::system_clock::now() << endl << " producer = " << producer_name.toUri() << endl << " request = " << request_name.toUri() << endl << " why = " << why << endl << "}" << endl; lock.unlock(); } }
ActionItemPtr ActionLog::AddRemoteAction(shared_ptr<Data> actionData) { Name name = actionData->getName(); // action name: /<device_name>/<appname>/action/<shared-folder>/<action-seq> uint64_t seqno = name.get(-1).toNumber(); std::string sharedFolder = name.get(-2).toUri(); if (sharedFolder != m_sharedFolderName) { _LOG_ERROR("Action doesn't belong to this shared folder"); return ActionItemPtr(); } if (name.get(-3).toUri() != "action") { _LOG_ERROR("not an action"); return ActionItemPtr(); } if (name.get(-4) != m_appName) { _LOG_ERROR("Action doesn't belong to this application"); return ActionItemPtr(); } Name deviceName = name.getSubName(0, name.size() - 4); _LOG_DEBUG("From [" << name << "] extracted deviceName: " << deviceName << ", sharedFolder: " << sharedFolder << ", seqno: " << seqno); return AddRemoteAction(deviceName, seqno, actionData); }
SceneTypeId SceneRegistry::type_id_of(Name type_name) { auto it = _type_name_to_id.find(type_name); if (it == _type_name_to_id.end()) { throw InvalidOperation(format("Unknown scene type '%s'", type_name.data())); } return it->second; }
void Tracer::onReceive(const Name& name) { if (m_options.shouldPrintTimestamp) { std::cout << time::toIsoString(time::system_clock::now()) << " - "; } std::cout << "interest received: seq=" << name.at(-1).toUri() << std::endl; }
void MemoryIdentityStorage::addIdentity(const Name& identityName) { string identityUri = identityName.toUri(); if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end()) return; identityStore_.push_back(identityUri); }
void SecPublicInfoMemory::addIdentity(const Name& identityName) { string identityUri = identityName.toUri(); if (find(m_identityStore.begin(), m_identityStore.end(), identityUri) != m_identityStore.end()) return; m_identityStore.push_back(identityUri); }
void handleBreakTarget(Name& name) { if (name.is()) { if (branchesSeen.find(name) == branchesSeen.end()) { name = Name(); } else { branchesSeen.erase(name); } } }
void SecPublicInfoMemory::addIdentity(const Name& identityName) { string identityUri = identityName.toUri(); if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end()) throw Error("Identity already exists: " + identityUri); identityStore_.push_back(identityUri); }
ConstBufferPtr SecTpmFile::exportPrivateKeyPkcs8FromTpm(const Name& keyName) { OBufferStream privateKeyOs; CryptoPP::FileSource(m_impl->transformName(keyName.toUri(), ".pri").string().c_str(), true, new CryptoPP::Base64Decoder(new CryptoPP::FileSink(privateKeyOs))); return privateKeyOs.buf(); }
void xl_enter_prefix(Context *context, text name, native_fn fn, Tree *rtype, TreeList ¶meters, text symbol, text doc) // ---------------------------------------------------------------------------- // Enter a prefix into the context (called from .tbl files) // ---------------------------------------------------------------------------- { if (parameters.size()) { Tree *parmtree = xl_parameters_tree(parameters); Prefix *from = new Prefix(new Name(symbol), parmtree); Name *to = new Name(symbol); Rewrite *rw = context->Define(from, to); rw->native = fn; rw->type = rtype; Symbols *s = MAIN->globals; Rewrite *rw2 = s->EnterRewrite(from, to); rw2->type = rtype; to->code = fn; to->SetSymbols(s); xl_enter_builtin(MAIN, name, to, rw2->parameters, fn); xl_set_documentation(from, doc); } else { Name *n = new Name(symbol); n->SetInfo<PrefixDefinitionsInfo>(new PrefixDefinitionsInfo()); Rewrite *rw = context->Define(n, n); rw->native = fn; rw->type = rtype; Symbols *s = MAIN->globals; Rewrite *rw2 = s->EnterName(symbol, n, Rewrite::GLOBAL); rw2->type = rtype; n->code = fn; n->SetSymbols(s); TreeList noparms; xl_enter_builtin(MAIN, name, n, noparms, fn); xl_set_documentation(n, doc); } }
NdnServer(std::string fileName, size_t segSize, size_t contentsize, int signORnot){ using namespace std; isSign = signORnot; ifstream fin(fileName.c_str(), fstream::binary); fin.seekg(0, fin.end); m_FileSize = fin.tellg(); fin.seekg(0, fin.beg); fin.read(fileBuffer, m_FileSize); fin.close(); m_SegmentSize = segSize * 1024; m_ContentSize = contentsize * 1024; m_TotalPacketNum = m_FileSize / m_ContentSize + 1; cout << "Finish reading file\n"; std::cout << "Total file size:\t" << m_FileSize << std::endl ; std::cout << "m_SegmentSize is:\t" << m_SegmentSize << std::endl ; std::cout << "m_TotalSegNum is:\t" << m_FileSize / m_SegmentSize + 1 << std::endl ; std::cout << "m_ContentSize is:\t" << m_ContentSize << std::endl ; std::cout << "Total packet num is:\t" << m_FileSize / m_ContentSize + 1 << std::endl ; timeval start, end; gettimeofday(&start, 0); for(int id = 0;id < m_TotalPacketNum; id++){ Name fileName = Name("askfile"); fileName.appendNumber(xxx); fileName.appendSegment(1024); fileName.appendSegmentOffset(id); shared_ptr<Data> data = make_shared<Data>(fileName); if(isSign == 1) m_keyChain.sign(*data); else m_keyChain.signWithSha256(*data); m_store.push_back(data); if(id == m_TotalPacketNum - 1) std::cout <<"Finish signing last datapacket\n"; } gettimeofday(&end, 0); double totalTime =(1000000.0 * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec ) / 1000000; std::cout << "Signing cost is:\t" << totalTime <<" s" << std::endl; };
void Sqlite3ConsumerDb::deleteKey(const Name& keyName) { sqlite3_stmt *statement; sqlite3_prepare_v2 (database_, "DELETE FROM decryptionkeys WHERE key_name=?", -1, &statement, 0); sqlite3_bind_blob(statement, 1, keyName.wireEncode(), SQLITE_TRANSIENT); sqlite3_step(statement); sqlite3_finalize(statement); }
inline Name SecPublicInfo::getNewKeyName (const Name& identityName, bool useKsk) { std::ostringstream oss; if (useKsk) oss << "ksk-"; else oss << "dsk-"; oss << time::toUnixTimestamp(time::system_clock::now()).count(); Name keyName = Name(identityName).append(oss.str()); if (doesPublicKeyExist(keyName)) throw Error("Key name already exists: " + keyName.toUri()); return keyName; }
ptr_lib::shared_ptr<PublicKey> SecPublicInfoMemory::getPublicKey(const Name& keyName) { KeyStore::iterator record = keyStore_.find(keyName.toUri()); if (record == keyStore_.end()) // Not found. Silently return null. return ptr_lib::shared_ptr<PublicKey>(); return ptr_lib::make_shared<PublicKey> (record->second->getKey()); }
void Logic::addUserNode(const Name& userPrefix, const Name& signingId) { if (userPrefix == EMPTY_NAME) return; if (m_defaultUserPrefix == EMPTY_NAME) { m_defaultUserPrefix = userPrefix; m_defaultSigningId = signingId; } if (m_nodeList.find(userPrefix) == m_nodeList.end()) { m_nodeList[userPrefix].userPrefix = userPrefix; m_nodeList[userPrefix].signingId = signingId; Name sessionName = userPrefix; sessionName.appendNumber(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()); m_nodeList[userPrefix].sessionName = sessionName; m_nodeList[userPrefix].seqNo = 0; reset(false); } }
void SecPublicInfoMemory::setDefaultIdentityInternal(const Name& identityName) { string identityUri = identityName.toUri(); if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end()) defaultIdentity_ = identityUri; else // The identity doesn't exist, so clear the default. defaultIdentity_.clear(); }
ptr_lib::shared_ptr<IdentityCertificate> SecPublicInfoMemory::getCertificate(const Name& certificateName) { CertificateStore::iterator record = certificateStore_.find(certificateName.toUri()); if (record == certificateStore_.end()) // Not found. Silently return null. return ptr_lib::shared_ptr<IdentityCertificate>(); return record->second; }
void MemoryIdentityStorage::setDefaultIdentity(const Name& identityName) { string identityUri = identityName.toUri(); if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end()) defaultIdentity_ = identityUri; else // The identity doesn't exist, so clear the default. defaultIdentity_.clear(); }
BOOST_FIXTURE_TEST_CASE(EcdsaSigningByIdentityNoCert, IdentityManagementFixture) { Data data("/test/data"); Name nonExistingIdentity = Name("/non-existing/identity").appendVersion(); BOOST_CHECK_NO_THROW(m_keyChain.sign(data, signingByIdentity(nonExistingIdentity))); BOOST_CHECK_EQUAL(data.getSignature().getType(), KeyChain::getSignatureType(KeyChain::DEFAULT_KEY_PARAMS.getKeyType(), DigestAlgorithm::SHA256)); BOOST_CHECK(nonExistingIdentity.isPrefixOf(data.getSignature().getKeyLocator().getName())); Name ecdsaIdentity = Name("/ndn/test/ecdsa").appendVersion(); Name ecdsaKeyName = m_keyChain.generateEcdsaKeyPairAsDefault(ecdsaIdentity, false, 256); BOOST_CHECK_NO_THROW(m_keyChain.sign(data, signingByIdentity(ecdsaIdentity))); BOOST_CHECK_EQUAL(data.getSignature().getType(), KeyChain::getSignatureType(EcdsaKeyParams().getKeyType(), DigestAlgorithm::SHA256)); BOOST_CHECK(ecdsaIdentity.isPrefixOf(data.getSignature().getKeyLocator().getName())); }
bool matchesFilter(const Name& name) { if (nameFilter.empty()) return true; /// \todo Switch to NDN regular expressions return boost::regex_match(name.toUri(), nameFilter); }
void Socket::fetchData(const Name& sessionName, const SeqNo& seqNo, const ndn::OnDataValidated& dataCallback, int nRetries) { Name interestName; interestName.append(sessionName).appendNumber(seqNo); Interest interest(interestName); interest.setMustBeFresh(true); ndn::OnDataValidationFailed failureCallback = bind(&Socket::onDataValidationFailed, this, _1, _2); m_face.expressInterest(interest, bind(&Socket::onData, this, _1, _2, dataCallback, failureCallback), bind(&Socket::onDataTimeout, this, _1, nRetries, dataCallback, failureCallback)); }
Blob MemoryIdentityStorage::getKey(const Name& keyName) { map<string, ptr_lib::shared_ptr<KeyRecord> >::iterator record = keyStore_.find(keyName.toUri()); if (record == keyStore_.end()) // Not found. Silently return null. return Blob(); return record->second->getKeyDer(); }
shared_ptr<RegexTopMatcher> RegexTopMatcher::fromName(const Name& name, bool hasAnchor) { std::string regexStr("^"); for (Name::const_iterator it = name.begin(); it != name.end(); it++) { regexStr.append("<"); regexStr.append(convertSpecialChar(it->toUri())); regexStr.append(">"); } if (hasAnchor) regexStr.append("$"); // On OSX 10.9, boost, and C++03 the following doesn't work without ndn:: // because the argument-dependent lookup prefers STL to boost return ndn::make_shared<RegexTopMatcher>(regexStr); }
void sendNextInterest() { if (this->shouldStop()) return; BOOST_ASSERT(m_lastSequenceNo != std::numeric_limits<uint64_t>::max());// overflow or missing initial reply Name nextName = m_prefix; nextName.appendSequenceNumber(m_lastSequenceNo + 1); shared_ptr<Interest> interest = make_shared<Interest>(nextName); interest->setInterestLifetime(getInterestLifetime()); m_lastInterestId = m_face.expressInterest(*interest, bind(&NotificationSubscriber<Notification>::afterReceiveData, this, _2), bind(&NotificationSubscriber<Notification>::afterReceiveNack, this, _2), bind(&NotificationSubscriber<Notification>::afterTimeout, this)); }
static security::SigningInfo makeSigningInfoFromIdentityCertificate(const Name& certificateName) { // A valid IdentityCertificate has at least 4 name components, // as it follows `<...>/KEY/<...>/<key-id>/ID-CERT/<version>` naming model. if (certificateName.size() < 4) { BOOST_THROW_EXCEPTION(std::invalid_argument("Certificate is invalid")); } return security::signingByCertificate(certificateName); }
void PibDb::setDefaultCertNameOfKey(const Name& certificateName) { sqlite3_stmt* statement; sqlite3_prepare_v2(m_database, "UPDATE certificates SET is_default=1 WHERE certificate_name=?", -1, &statement, nullptr); sqlite3_bind_block(statement, 1, certificateName.wireEncode(), SQLITE_TRANSIENT); sqlite3_step(statement); sqlite3_finalize(statement); }