static inline std::map< Identity,std::vector<InetAddress> > _mkSupernodeMap() throw(std::runtime_error) { std::map< Identity,std::vector<InetAddress> > sn; Identity id; std::vector<InetAddress> addrs; // Nothing special about a supernode... except that they are // designated as such. // cthulhu.zerotier.com - New York, New York, USA addrs.clear(); if (!id.fromString("271ee006a0:1:AgGXs3I+9CWrEmGMxc50x3E+trwtaa2ZMXDU6ezz92fFJXzlhRKGUY/uAToHDdH9XiLxtcA+kUQAZdC4Dy2xtqXxjw==:QgH5Nlx4oWEGVrwhNocqem+3VNd4qzt7RLrmuvqZvKPRS9R70LJYJQLlKZj0ri55Pzg+Mlwy4a4nAgfnRAWA+TW6R0EjSmq72MG585XGNfWBVk3LxMvxlNWErnVNFr2BQS9yzVp4pRjPLdCW4RB3dwEHBUgJ78rwMxQ6IghVCl8CjkDapg==")) throw std::runtime_error("invalid identity in Defaults"); addrs.push_back(InetAddress("198.199.73.93",ZT_DEFAULT_UDP_PORT)); sn[id] = addrs; // nyarlathotep.zerotier.com - San Francisco, California, USA addrs.clear(); if (!id.fromString("fa9be4008b:1:AwCHXEi/PJuhtOPUZxnBSMiuGvj6XeRMWu9R9aLR3JD1qluADLQzUPSP2+81Dqvgi2wkQ2cqEpOlDPeUCvtlZwdXEA==:QgH4usG/wzsoUCtO2LL3qkwugtoXEz1PUJbmUzY8vbwzc5bckmVPjMqb4q2CF71+QVPV1K6shIV2EKkBMRSS/D/44EGEwC6tjFGZqmmogaC0P1uQeukTAF4qta46YgC4YQx54/Vd/Yfl8n1Bwmgm0gBB4W1ZQir3p+wp37MGlEN0rlXxqA==")) throw std::runtime_error("invalid identity in Defaults"); addrs.push_back(InetAddress("198.199.97.220",ZT_DEFAULT_UDP_PORT)); sn[id] = addrs; // shub-niggurath.zerotier.com - Amsterdam, Netherlands addrs.clear(); if (!id.fromString("48099ecd05:1:AwHO7o1FdDj1nEArfchTDa6EG7Eh2GLdiH86BhcoNv0BHJN4tmrf0Y7/2SZiQFpTTwJf93iph84Dci5+k52u/qkHTQ==:QgGbir8CNxBFFPPj8Eo3Bnp2UmbnZxu/pOq3Ke0WaLBBhHzVuwM+88g7CaDxbZ0AY2VkFc9hmE3VG+xi7g0H86yfVUIBHZnb7N+DCtf8/mphZIHNgmasakRi4hU11kGyLi1nTVTnrmCfAb7w+8SCp64Q5RNvBC/Pvz7pxSwSdjIHkVqRaeo=")) throw std::runtime_error("invalid identity in Defaults"); addrs.push_back(InetAddress("198.211.127.172",ZT_DEFAULT_UDP_PORT)); sn[id] = addrs; return sn; }
void FaceManagement::Recognizer::trainRecognitionDatabase(QPair<QString, QString> &tagData, const QImage &image) { #ifdef HAVE_KFACE // Assemble an ID string for this tag QString fullNameString = identityString(tagData); // Check if we have an identity for this tag Identity identity = m_recognitionDatabase.findIdentity( QString::fromLatin1("fullName"), fullNameString ); if (identity.isNull()) { // Add a new identity for this tag QMap<QString, QString> attributes; attributes[QString::fromLatin1("fullName")] = fullNameString; identity = m_recognitionDatabase.addIdentity(attributes); } // Train the database m_recognitionDatabase.train(identity, image, QString::fromLatin1("KPhotoAlbum")); #else Q_UNUSED(tagData); Q_UNUSED(image); #endif }
static inline std::map< Identity,std::vector<InetAddress> > _mkSupernodeMap() { std::map< Identity,std::vector<InetAddress> > sn; Identity id; std::vector<InetAddress> addrs; // Nothing special about a supernode... except that they are // designated as such and trusted to provide WHOIS lookup. // cthulhu.zerotier.com - New York, New York, USA addrs.clear(); if (!id.fromString("8acf059fe3:0:482f6ee5dfe902319b419de5bdc765209c0ecda38c4d6e4fcf0d33658398b4527dcd22f93112fb9befd02fd78bf7261b333fc105d192a623ca9e50fc60b374a5")) throw std::runtime_error("invalid identity in Defaults"); addrs.push_back(InetAddress("162.243.77.111",ZT_DEFAULT_UDP_PORT)); sn[id] = addrs; // nyarlathotep.zerotier.com - San Francisco, California, USA addrs.clear(); if (!id.fromString("7e19876aba:0:2a6e2b2318930f60eb097f70d0f4b028b2cd6d3d0c63c014b9039ff35390e41181f216fb2e6fa8d95c1ee9667156411905c3dccfea78d8c6dfafba688170b3fa")) throw std::runtime_error("invalid identity in Defaults"); addrs.push_back(InetAddress("198.199.97.220",ZT_DEFAULT_UDP_PORT)); sn[id] = addrs; // shub-niggurath.zerotier.com - Amsterdam, Netherlands addrs.clear(); if (!id.fromString("36f63d6574:0:67a776487a1a99b32f413329f2b67c43fbf6152e42c6b66e89043e69d93e48314c7d709b58a83016bd2612dd89400b856e18c553da94892f7d3ca16bf2c92c24")) throw std::runtime_error("invalid identity in Defaults"); addrs.push_back(InetAddress("198.211.127.172",ZT_DEFAULT_UDP_PORT)); sn[id] = addrs; return sn; }
// // Find and store database objects (primitive layer) // bool CodeSignatures::find(Identity &id, uid_t user) { if (id.mState != Identity::untried) return id.mState == Identity::valid; try { DbKey userKey('H', id.getHash(), true, user); CssmData linkValue; if (mDb.get(userKey, linkValue)) { id.mName = string(linkValue.interpretedAs<const char>(), linkValue.length()); IFDUMPING("equiv", id.debugDump("found/user")); id.mState = Identity::valid; return true; } DbKey sysKey('H', id.getHash()); if (mDb.get(sysKey, linkValue)) { id.mName = string(linkValue.interpretedAs<const char>(), linkValue.length()); IFDUMPING("equiv", id.debugDump("found/system")); id.mState = Identity::valid; return true; } } catch (...) { secdebug("codesign", "exception validating identity for %s - marking failed", id.path().c_str()); id.mState = Identity::invalid; } return id.mState == Identity::valid; }
void FaceManagement::Recognizer::changeIdentityName(QString category, QString oldTagName, QString newTagName) { #ifdef HAVE_KFACE // Assemble the old ID string for this tag QString fullNameString = identityString(category, oldTagName); // Check if we have an identity for this tag Identity identity = m_recognitionDatabase.findIdentity( QString::fromLatin1("fullName"), fullNameString ); if (identity.isNull()) { // We don't have this tag in the recognition database, so nothing has to be done return; } // Assemble the new ID string for this tag fullNameString = identityString(category, newTagName); QMap<QString, QString> attributes; attributes[QString::fromLatin1("fullName")] = fullNameString; // Update the recognition database m_recognitionDatabase.setIdentityAttributes(identity.id(), attributes); #else Q_UNUSED(category); Q_UNUSED(oldTagName); Q_UNUSED(newTagName); #endif }
void processSubscriptionDataEvent(const Event &event) { MessageIterator msgIter(event); while (msgIter.next()) { Message msg = msgIter.message(); Service service = msg.service(); int index = (int)msg.correlationId().asInteger(); std::string &topic = d_securities[index]; if (!msg.hasElement(d_fieldName)) { continue; } std::cout << "\t" << topic << std::endl; Element field = msg.getElement(d_fieldName); if (!field.isValid()) { continue; } bool needsEntitlement = msg.hasElement(EID); for (size_t i = 0; i < d_identities.size(); ++i) { Identity *handle = &d_identities[i]; if (!needsEntitlement || handle->hasEntitlements(service, msg.getElement(EID), 0, 0)) { std::cout << "User #" << (i+1) << " is entitled" << " for " << field << std::endl; } else { std::cout << "User #" << (i+1) << " is NOT entitled" << " for " << d_fieldName << std::endl; } } } }
void AuthWidget::oAuthDone(OAuthProcess *oauth, const Identity& identity) { /* * FIXME: perhaps consider moving this to the model with signals or * by passing the Login object ? */ if (identity.isValid()) { LOG_SECURE(oauth->service().name() << ": identified: as " << identity.id() << ", " << identity.name() << ", " << identity.email()); std::auto_ptr<AbstractUserDatabase::Transaction> t(model_->users().startTransaction()); User user = model_->baseAuth()->identifyUser(identity, model_->users()); if (user.isValid()) login_.login(user); else registerNewUser(identity); if (t.get()) t->commit(); } else { LOG_SECURE(oauth->service().name() << ": error: " << oauth->error()); displayError(oauth->error()); } }
TEST_F(RotationDeathTest, SerializationError) { Identity<World, World> id; EXPECT_DEATH({ serialization::LinearMap message; id.WriteToMessage(&message); Rot const r = Rot::ReadFromMessage(message); }, "HasExtension.*Rotation");
void AccountShared::load() { if (!isValidStorage()) return; Shared::load(); Identity identity = IdentityManager::instance()->byUuid(loadValue<QString>("Identity")); if (identity.isNull() && !IdentityManager::instance()->items().isEmpty()) identity = IdentityManager::instance()->items().at(0); setAccountIdentity(identity); ProtocolName = loadValue<QString>("Protocol"); setId(loadValue<QString>("Id")); RememberPassword = loadValue<bool>("RememberPassword", true); HasPassword = RememberPassword; if (RememberPassword) Password = pwHash(loadValue<QString>("Password")); ProxySettings.setEnabled(loadValue<bool>("UseProxy")); ProxySettings.setAddress(loadValue<QString>("ProxyHost")); ProxySettings.setPort(loadValue<int>("ProxyPort")); ProxySettings.setRequiresAuthentication(loadValue<bool>("ProxyRequiresAuthentication")); ProxySettings.setUser(loadValue<QString>("ProxyUser")); ProxySettings.setPassword(loadValue<QString>("ProxyPassword")); PrivateStatus = loadValue<bool>("PrivateStatus", true); triggerAllProtocolsRegistered(); }
QList<Identity> TrainingDB::identities() const { QList<QVariant> ids; QList<Identity> results; d->db->execSql("SELECT id FROM Identities", &ids); foreach (const QVariant& v, ids) { QList<QVariant> values; Identity p; p.setId(v.toInt()); d->db->execSql("SELECT attribute, value FROM IdentityAttributes WHERE id=?", p.id(), &values); for (QList<QVariant>::const_iterator it = values.constBegin(); it != values.constEnd();) { QString attribute = it->toString(); ++it; QString value = it->toString(); ++it; p.setAttribute(attribute, value); } results << p; }
Packet::Packet(Identity& id) : _type(Packet::Id) { unsigned char *instr; unsigned char *port; char* _username; char* _ip; unsigned int _instruction; unsigned int _port; _instruction = id.getInstruct(); _port = id.getPort(); _username = id.getUsername(); _ip = id.getIp(); instr = reinterpret_cast<unsigned char *>(&_instruction); port = reinterpret_cast<unsigned char *>(&_port); for (unsigned int i = 0; i < 8; ++i) if (i < 4) _data.push_back(instr[i]); else _data.push_back(port[i - sizeof(int)]); for (unsigned int i = 0; i < 64; ++i) _data.push_back(_username[i]); for (unsigned int i = 0; i < 32; ++i) _data.push_back(_ip[i]); this->_encrypted = false; }
TEST_F(PermutationDeathTest, SerializationError) { Identity<World1, World2> id; EXPECT_DEATH({ serialization::LinearMap message; id.WriteToMessage(&message); Perm const p = Perm::ReadFromMessage(message); }, "HasExtension.*Permutation");
void IdentityWidget::loadFromIdentity( const Identity &identity ) { mName->setText( identity.fullName() ); mOrganisation->setText( identity.organization() ); mEmail->setText( identity.primaryEmailAddress() ); mReplyto->setText( identity.replyToAddr() ); mMailcopiesto->setText( identity.property( "Mail-Copies-To" ).toString() ); }
void Topology::_saveIdentity(const Identity &id) { if (id) { char p[128]; Utils::snprintf(p,sizeof(p),"iddb.d/%.10llx",(unsigned long long)id.address().toInt()); RR->node->dataStorePut(p,id.toString(false),false); } }
IcmProxy::Object* ProxyFactory::streamToProxy(InputStream* s) const { Identity ident; ident.read(s); Reference* ref = mCommunicator->referenceFactory()->create(ident, s); return referenceToProxy(ref); }
QPair<QString, QString> FaceManagement::Recognizer::recognizeFace(const QImage& image) { if (! m_recognitionDatabase.isNull() && ! m_recognitionDatabase.allIdentities().isEmpty()) { Identity identity = m_recognitionDatabase.recognizeFace(image); if (! identity.isNull()) { return parseIdentity(identity); } } return QPair<QString, QString>(); }
void TrainingDB::updateIdentity(const Identity& p) { d->db->execSql("DELETE FROM IdentityAttributes WHERE id=?", p.id()); const QMap<QString, QString> map = p.attributesMap(); QMap<QString, QString>::const_iterator it; for (it = map.begin(); it != map.end(); ++it) { d->db->execSql("INSERT INTO IdentityAttributes (id, attribute, value) VALUES (?, ?,?)", p.id(), it.key(), it.value()); } }
int main(int argc,char **argv) { std::string buf; // Read root-topology-authority.secret signing authority, must be symlinked and online Identity topologyAuthority; if (OSUtils::readFile("root-topology-authority.secret",buf)) topologyAuthority.fromString(buf); else std::cerr << "Warning: root-topology-authority.secret not found, creating unsigned topology." << std::endl; Dictionary topology; // Read template.dict to populate default fields in root topology // if this file exists. Otherwise we just start empty. buf.clear(); if (OSUtils::readFile("template.dict",buf)) topology.fromString(buf); // Read all entries in supernodes/ that correspond to supernode entry dictionaries // and add them to topology under supernodes/ subkey. Dictionary supernodes; std::vector<std::string> supernodeDictionaries(OSUtils::listDirectory("supernodes")); for(std::vector<std::string>::const_iterator sn(supernodeDictionaries.begin());sn!=supernodeDictionaries.end();++sn) { if (sn->length() == 10) { buf.clear(); if (!OSUtils::readFile((std::string("supernodes/")+(*sn)).c_str(),buf)) { std::cerr << "Cannot read supernodes/" << *sn << std::endl; return 1; } supernodes[*sn] = buf; } } topology["supernodes"] = supernodes.toString(); if ((topologyAuthority)&&(topologyAuthority.hasPrivate())) { // Sign topology with root-topology-authority.secret if (!topology.sign(topologyAuthority,OSUtils::now())) { std::cerr << "Unable to sign!" << std::endl; return 1; } // Test signature to make sure signing worked Dictionary test(topology.toString()); if (!test.verify(topologyAuthority)) { std::cerr << "Test verification of signed dictionary failed!" << std::endl; return 1; } } // Output to stdout std::cout << topology.toString(); return 0; }
/** * Sign this tag * * @param signer Signing identity, must have private key * @return True if signature was successful */ inline bool sign(const Identity &signer) { if (signer.hasPrivate()) { Buffer<sizeof(Tag) + 64> tmp; _signedBy = signer.address(); this->serialize(tmp,true); _signature = signer.sign(tmp.data(),tmp.size()); return true; } return false; }
void ProxyFactory::proxyToStream(IcmProxy::Object* proxy, OutputStream* s) const { if(proxy) { proxy->getReference()->identity().write(s); proxy->getReference()->write(s); } else { Identity ident; ident.write(s); } }
void FaceDb::updateIdentity(const Identity& p) { d->db->execSql(QString::fromLatin1("DELETE FROM IdentityAttributes WHERE id=?;"), p.id()); const QMap<QString, QString> map = p.attributesMap(); QMap<QString, QString>::const_iterator it; for (it = map.constBegin(); it != map.constEnd(); ++it) { d->db->execSql(QString::fromLatin1("INSERT INTO IdentityAttributes (id, attribute, value) VALUES (?, ?,?);"), p.id(), it.key(), it.value()); } }
// replace placeholders void KNode::StringFilter::expand( KNGroup *g ) { Identity *id = (g) ? g->identity() : 0; if (!id) { id = (g) ? g->account()->identity() : 0; if (!id) id = knGlobals.configManager()->identity(); } expanded = data; expanded.replace(QRegExp("%MYNAME"), id->name()); expanded.replace(QRegExp("%MYEMAIL"), id->email()); }
QPair<QString, QString> FaceManagement::Recognizer::recognizeFace(const QImage &image) { #ifdef HAVE_KFACE if (! m_recognitionDatabase.isNull() && ! m_recognitionDatabase.allIdentities().isEmpty()) { Identity identity = m_recognitionDatabase.recognizeFace(image); if (! identity.isNull()) { return parseIdentity(identity); } } #else Q_UNUSED(image); #endif return QPair<QString, QString>(); }
void BabelClient::waitingForAnswer(ISocket *client) { Packet *packet; Instruct *instruct; Identity *id; BabelClient *_this = BabelClient::getInstance(); std::cout << "Waiting for answer" << std::endl; if ((packet = client->readPacket()) != NULL) { if (packet->getType() == Packet::Inst && (instruct = packet->unpack<Instruct>()) != NULL) { if (*instruct == KO) { std::cout << "No such user or whatever" << std::endl; client->attachOnReceive(BabelClient::onReceiveLogged); } delete instruct; } else if (packet->getType() == Packet::Id) { if ((id = packet->unpack<Identity>()) != NULL) { if (id->getInstruct() == OK) { std::cout << "Creating server" << std::endl; IMutex *mutex = (*MutexVault::getMutexVault())["peer"]; mutex->lock(true); _this->_peer = ISocket::getServer(5555); _this->_peer->attachOnReceive(BabelClient::receiveSound); _this->getSound(); _this->_peer->start(); #ifdef _WIN_32 _this->_peerthread = new WinThread<void, ISocket *>(BabelClient::sendSound); #else _this->_peerthread = new LinuxThread<void, ISocket *>(BabelClient::sendSound); #endif (*_this->_peerthread)(_this->_peer); client->attachOnReceive(BabelClient::onReceiveLogged); mutex->unlock(); } delete id; } } delete packet; } }
void Explanation_Based_Chunker::join_identities(Identity* lFromJoinSet, Identity* lToJoinSet) { lFromJoinSet = lFromJoinSet->joined_identity; lToJoinSet = lToJoinSet->joined_identity; if (lFromJoinSet == lToJoinSet) return; thisAgent->explanationMemory->increment_stat_identities_joined(); lFromJoinSet->touch(); lToJoinSet->touch(); /* Check size and swap if necessary to favor growing the bigger join set */ uint64_t lFromSize = lFromJoinSet->merged_identities ? lFromJoinSet->merged_identities->size() : 0; uint64_t lToSize = lToJoinSet->merged_identities ? lToJoinSet->merged_identities->size() : 0; if (lFromSize > lToSize) { Identity* tempJoin = lFromJoinSet; lFromJoinSet = lToJoinSet; lToJoinSet = tempJoin; } if (!lToJoinSet->merged_identities) { lToJoinSet->merged_identities = new identity_list(); } /* Iterate through identity sets in lFromJoinSet and set their super join set point to lToJoinSet */ Identity* lPreviouslyJoinedIdentity; if (lFromJoinSet->merged_identities) { for (auto it = lFromJoinSet->merged_identities->begin(); it != lFromJoinSet->merged_identities->end(); it++) { lPreviouslyJoinedIdentity = *it; lPreviouslyJoinedIdentity->joined_identity = lToJoinSet; if (lPreviouslyJoinedIdentity->literalized()) lToJoinSet->literalize(); } lToJoinSet->merged_identities->splice(lToJoinSet->merged_identities->begin(), (*lFromJoinSet->merged_identities)); delete lFromJoinSet->merged_identities; lFromJoinSet->merged_identities = NULL; } /* The identity set being joined is not on its child identity_sets list, so we add it to other identity set here*/ lToJoinSet->merged_identities->push_back(lFromJoinSet); /* Propagate literalization and constraint info */ if (lFromJoinSet->literalized()) lToJoinSet->literalize(); /* Point super_join to joined identity set */ lFromJoinSet->joined_identity = lToJoinSet; }
static Identity getIdFromArg(char *arg) { Identity id; if ((strlen(arg) > 32)&&(arg[10] == ':')) { // identity is a literal on the command line if (id.fromString(arg)) return id; } else { // identity is to be read from a file std::string idser; if (Utils::readFile(arg,idser)) { if (id.fromString(idser)) return id; } } return Identity(); }
void RegistrationWidget::oAuthDone(OAuthProcess *oauth, const Identity& identity) { if (identity.isValid()) { LOG_SECURE(oauth->service().name() << ": identified: as " << identity.id() << ", " << identity.name() << ", " << identity.email()); if (!model_->registerIdentified(identity)) update(); } else { if (authWidget_) authWidget_->displayError(oauth->error()); LOG_SECURE(oauth->service().name() << ": error: " << oauth->error()); } }
int CertificateOfOwnership::verify(const RuntimeEnvironment *RR,void *tPtr) const { if ((!_signedBy)||(_signedBy != Network::controllerFor(_networkId))) return -1; const Identity id(RR->topology->getIdentity(tPtr,_signedBy)); if (!id) { RR->sw->requestWhois(tPtr,_signedBy); return 1; } try { Buffer<(sizeof(CertificateOfOwnership) + 64)> tmp; this->serialize(tmp,true); return (id.verify(tmp.data(),tmp.size(),_signature) ? 0 : -1); } catch ( ... ) { return -1; } }
void main(int argc, char** argv) { // Need at least three parameters if (argc < 4) { Usage(); return; } const char* server_address = argv[1]; unsigned long server_port = atoi(argv[2]); string category_name = argv[3]; IPSocket::Address server_address_object(server_address, server_port); IPSocket::Address auth_server_address_object("master1.west.won.net", 15200); CompletionContainer<const UserSearchServerCountResult&> result_object; Identity identity = Identity("neeraj", "Admin", PW, "", auth_server_address_object); Error aError = identity.Authenticate(false , false, 20000); if (aError == StatusCommon_Success) { cout << "\n\n\nResult is: " << UserSearchGetNumberOfUsers(/*&identity*/ NULL, &server_address_object, 1, WONCommon::StringToWString(category_name), 20000, false, result_object).m_result << ".\n\n"; } }
void AddressBook::LoadHosts () { std::ifstream f (i2p::util::filesystem::GetFullPath ("hosts.txt").c_str (), std::ofstream::in); // in text mode if (!f.is_open ()) { LogPrint ("hosts.txt not found. Try to load..."); if (!m_IsDowloading) { m_IsDowloading = true; std::thread load_hosts(&AddressBook::LoadHostsFromI2P, this); load_hosts.detach(); } return; } int numAddresses = 0; std::string s; while (!f.eof ()) { getline(f, s); if (!s.length()) continue; // skip empty line size_t pos = s.find('='); if (pos != std::string::npos) { std::string name = s.substr(0, pos++); std::string addr = s.substr(pos); Identity ident; if (!ident.FromBase64(addr)) { LogPrint ("hosts.txt: ignore ", name); continue; } m_Addresses[name] = ident.Hash(); numAddresses++; } } LogPrint (numAddresses, " addresses loaded"); m_IsLoaded = true; }