bool	CACFDictionary::AddCFTypeWithCStringKey(const char* inKey, const CFTypeRef inValue)
{
	bool theAnswer = false;
	
	if(mMutable && (mCFDictionary != NULL))
	{
		CACFString theKey(inKey);
		if(theKey.IsValid())
		{
			theAnswer = AddCFType(theKey.GetCFString(), inValue);
		}
	}
	
	return theAnswer;
}
bool	CACFDictionary::GetCFTypeWithCStringKey(const char* inKey, CFTypeRef& outValue) const
{
	bool theAnswer = false;
	
	if(mCFDictionary != NULL)
	{
		CACFString theKey(inKey);
		if(theKey.IsValid())
		{
			theAnswer = GetCFType(theKey.GetCFString(), outValue);
		}
	}
	
	return theAnswer;
}
/**
 * Called when we receive a message from the game servers.  Save it in the
 * map, in case the object it refers to is loaded before the message is
 * persisted.
 */
void MessageToManager::handleMessageTo(const MessageToPayload &data)
{
	IndexKey theKey(data.getNetworkId(), data.getMessageId());
	
	MessagesByObjectType::iterator i=m_messagesByObject.find(theKey);
	if (i!=m_messagesByObject.end())
	{
		DEBUG_WARNING(true,("Received message %s twice.",data.getMessageId().getValueString().c_str()));
		delete i->second;
		i->second = NULL;
	}
	
	m_messagesByObject[theKey]=new MessageToPayload(data);
	m_messageToObjectMap[data.getMessageId()]=data.getNetworkId();
}
示例#4
0
QMap< KEntryKey, KEntry >::ConstIterator KEntryMap::findEntry(const QByteArray& group, const QByteArray& key, KEntryMap::SearchFlags flags) const
{
    KEntryKey theKey(group, key, false, bool(flags&SearchDefaults));

    // try the localized key first
    if (flags&SearchLocalized) {
        theKey.bLocal = true;

        ConstIterator it = find(theKey);
        if (it != constEnd())
            return it;

        theKey.bLocal = false;
    }
    return find(theKey);
}
示例#5
0
// Encrypt the supplied data
bool SecureDataManager::encrypt(const ByteString& plaintext, ByteString& encrypted)
{
	// Check the object logged in state
	if ((!userLoggedIn && !soLoggedIn) || (maskedKey.size() != 32))
	{
		return false;
	}

	AESKey theKey(256);
	ByteString unmaskedKey;

	{
		MutexLocker lock(dataMgrMutex);

		unmask(unmaskedKey);

		theKey.setKeyBits(unmaskedKey);

		remask(unmaskedKey);
	}

	// Wipe encrypted data block
	encrypted.wipe();

	// Generate random IV
	ByteString IV;

	if (!rng->generateRandom(IV, aes->getBlockSize())) return false;

	ByteString finalBlock;

	if (!aes->encryptInit(&theKey, SymMode::CBC, IV) ||
	    !aes->encryptUpdate(plaintext, encrypted) ||
	    !aes->encryptFinal(finalBlock))
	{
		return false;
	}

	encrypted += finalBlock;

	// Add IV to output data
	encrypted = IV + encrypted;

	return true;
}
QTSS_Error SessionClosing(QTSS_RTSPSession_Params* inParams)
{
    UInt32* theIPAddr = NULL;
    Bool16* isFirstRequest = NULL;
    UInt32 theLen = 0;
    
    // Only remove this session from the map if it has been added in the first place
    (void)QTSS_GetValuePtr(inParams->inRTSPSession, sIsFirstRequestAttr, 0, (void**)&isFirstRequest, &theLen);
    if (isFirstRequest == NULL)
        return QTSS_NoErr;
        
    // Get the IP address of this client.
    (void)QTSS_GetValuePtr(inParams->inRTSPSession, qtssRTSPSesRemoteAddr, 0, (void**)&theIPAddr, &theLen);
    if ((theIPAddr == NULL) || (theLen != sizeof(UInt32)))
    {
        Assert(0);
        return QTSS_NoErr;
    }

    IPAddrTableKey theKey(*theIPAddr);
    
    // This must be atomic
    OSMutexLocker locker(sMutex);

    // Check to see if this client currently has a connection open.
    IPAddrTableElem* theElem = sHashTable->Map(&theKey);
    if (theElem == NULL)
        return QTSS_NoErr; //this may happen if there is another module denying connections
        
    // Decrement the refcount
    if (theElem->GetRefCount() > 0)
        theElem->DecrementRefCount();
    
    // If the refcount is 0, remove this from the map, and delete it.
    if (theElem->GetRefCount() == 0)
    {
        sHashTable->Remove(theElem);
        delete theElem;
    }
    
    return QTSS_NoErr;      
}
bool LegacySymmetric::CreateNewKey(
    const api::Crypto& crypto,
    String& strOutput,
    const String& pstrDisplay,
    const OTPassword* pAlreadyHavePW)
{
    std::unique_ptr<OTPassword> pPassUserInput;

    if (nullptr == pAlreadyHavePW) {
        const char* szDisplay = "Creating new symmetric key.";
        const auto strDisplay = String::Factory(
            (!pstrDisplay.Exists()) ? szDisplay : pstrDisplay.Get());

        pPassUserInput.reset(GetPassphraseFromUser(
            strDisplay, true));  // bAskTwice=false by default.
    } else
        pPassUserInput.reset(new OTPassword(*pAlreadyHavePW));

    bool bSuccess = false;

    if (pPassUserInput)  // Success retrieving the passphrase from the
                         // user. (Now let's generate the key...)
    {
        LogDebug(OT_METHOD)(__FUNCTION__)(
            ": Calling LegacySymmetric theKey.GenerateKey()...")
            .Flush();
        implementation::LegacySymmetric theKey(crypto, *pPassUserInput);
        const bool bGenerated = theKey.IsGenerated();

        if (bGenerated && theKey.SerializeTo(strOutput))
            bSuccess = true;
        else
            LogDetail(OT_METHOD)(__FUNCTION__)(
                ": Sorry, unable to generate key. (Failure).")
                .Flush();
    } else
        LogDetail(OT_METHOD)(__FUNCTION__)(
            ": Sorry, unable to retrieve password from user. (Failure).")
            .Flush();

    return bSuccess;
}
// static
bool LegacySymmetric::Encrypt(
    const api::Crypto& crypto,
    const String& strKey,
    const String& strPlaintext,
    String& strOutput,
    const String& pstrDisplay,
    bool bBookends,
    const OTPassword* pAlreadyHavePW)
{
    if (!strKey.Exists() || !strPlaintext.Exists()) {
        LogDetail(OT_METHOD)(__FUNCTION__)(
            ": Nonexistent: either the key or the "
            "plaintext. Please supply. (Failure).")
            .Flush();
        return false;
    }

    implementation::LegacySymmetric theKey(crypto);

    if (!theKey.SerializeFrom(strKey)) {
        LogDetail(OT_METHOD)(__FUNCTION__)(
            ": Failed trying to load symmetric key from "
            "string. (Returning false).")
            .Flush();
        return false;
    }

    // By this point, we know we have a plaintext and a symmetric Key.
    //
    return Encrypt(
        theKey,
        strPlaintext,
        strOutput,
        pstrDisplay,
        bBookends,
        pAlreadyHavePW);
}
示例#9
0
bool KEntryMap::setEntry(const QByteArray& group, const QByteArray& key, const QByteArray& value, KEntryMap::EntryOptions options)
{
    KEntryKey k;
    KEntry e;
    bool newKey = false;

    const Iterator it = findExactEntry(group, key, SearchFlags(options>>16));

    if (key.isEmpty()) { // inserting a group marker
        k.mGroup = group;
        e.bImmutable = (options&EntryImmutable);
        if (options&EntryDeleted) {
            qWarning("Internal KConfig error: cannot mark groups as deleted");
        }
        if(it == end()) {
            insert(k, e);
            return true;
        } else if(it.value() == e) {
            return false;
        }

        it.value() = e;
        return true;
    }


    if (it != end()) {
        if (it->bImmutable)
            return false; // we cannot change this entry. Inherits group immutability.
        k = it.key();
        e = *it;
        //qDebug() << "found existing entry for key" << k;
    } else {
        // make sure the group marker is in the map
        KEntryMap const *that = this;
        ConstIterator cit = that->findEntry(group);
        if (cit == constEnd())
            insert(KEntryKey(group), KEntry());
        else if (cit->bImmutable)
            return false; // this group is immutable, so we cannot change this entry.

        k = KEntryKey(group, key);
        newKey = true;
    }

    // set these here, since we may be changing the type of key from the one we found
    k.bLocal = (options&EntryLocalized);
    k.bDefault = (options&EntryDefault);
    k.bRaw = (options&EntryRawKey);

    e.mValue = value;
    e.bDirty = e.bDirty || (options&EntryDirty);
    e.bGlobal = (options&EntryGlobal);  //we can't use || here, because changes to entries in
    //kdeglobals would be written to kdeglobals instead
    //of the local config file, regardless of the globals flag
    e.bImmutable = e.bImmutable || (options&EntryImmutable);
    if (value.isNull())
        e.bDeleted = e.bDeleted || (options&EntryDeleted);
    else
        e.bDeleted = false; // setting a value to a previously deleted entry
    e.bExpand = (options&EntryExpansion);
    e.bReverted = false;

    if(newKey)
    {
        //qDebug() << "inserting" << k << "=" << value;
        insert(k, e);
        if(k.bDefault)
        {
            k.bDefault = false;
            //qDebug() << "also inserting" << k << "=" << value;
            insert(k, e);
        }
        // TODO check for presence of unlocalized key
        return true;
    } else {
//                KEntry e2 = it.value();
        if(it.value() != e)
        {
            //qDebug() << "changing" << k << "from" << e.mValue << "to" << value;
            it.value() = e;
            if(k.bDefault)
            {
                KEntryKey nonDefaultKey(k);
                nonDefaultKey.bDefault = false;
                insert(nonDefaultKey, e);
            }
            if (!(options & EntryLocalized)) {
                KEntryKey theKey(group, key, true, false);
                //qDebug() << "non-localized entry, remove localized one:" << theKey;
                remove(theKey);
                if (k.bDefault) {
                    theKey.bDefault = true;
                    remove(theKey);
                }
            }
            return true;
        } else {
            //qDebug() << k << "was already set to" << e.mValue;
            if (!(options & EntryLocalized)) {
                //qDebug() << "unchanged non-localized entry, remove localized one.";
                KEntryKey theKey(group, key, true, false);
                bool ret = false;
                Iterator cit = find(theKey);
                if (cit != end()) {
                    erase(cit);
                    ret = true;
                }
                if (k.bDefault) {
                    theKey.bDefault = true;
                    Iterator cit = find(theKey);
                    if (cit != end()) {
                        erase(cit);
                        return true;
                    }
                }
                return ret;
            }
            //qDebug() << "localized entry, unchanged, return false";
            // When we are writing a default, we know that the non-
            // default is the same as the default, so we can simply
            // use the same branch.
            return false;
        }
    }
}
示例#10
0
QMap< KEntryKey, KEntry >::Iterator KEntryMap::findExactEntry(const QByteArray& group, const QByteArray& key, KEntryMap::SearchFlags flags)
{
    KEntryKey theKey(group, key, bool(flags&SearchLocalized), bool(flags&SearchDefaults));
    return find(theKey);
}