コード例 #1
0
void
DirEntity::PackDataObjects(BaseMessage& theMsgR, const DataObjectTypeSet& theSetR,
                           unsigned long theFlags)
{
	WTRACE("DirEntity::PackDataObjects");
	WDBG_LL("DirEntity::PackDataObject Packing data objects, size=" << theSetR.size());
	theMsgR.AppendShort(theSetR.size());

	bool packType = ((theFlags & WONMsg::GF_ADDDOTYPE) != 0);
	bool packData = ((theFlags & WONMsg::GF_ADDDODATA) != 0);
	DataObjectTypeSet::const_iterator anItr(theSetR.begin());
	for (; anItr != theSetR.end(); anItr++)
	{
		if (packType)
		{
			unsigned char aTypeLen = anItr->GetDataType().size();
			theMsgR.AppendByte(aTypeLen);
			theMsgR.AppendBytes(aTypeLen, anItr->GetDataType().data());
		}

		if (packData)
		{
			unsigned short aDataLen = anItr->GetData().size();
			theMsgR.AppendShort(aDataLen);
			theMsgR.AppendBytes(aDataLen, anItr->GetData().data());
		}
	}
}
コード例 #2
0
// SMsgDirG2ExplicitSetDataObjects::Pack
// Virtual method from SmallMessage.  Packs data into message buffer.
void*
SMsgDirG2ExplicitSetDataObjects::Pack(void)
{
	WTRACE("SMsgDirG2ExplicitSetDataObjects::Pack");
	SetServiceType(WONMsg::SmallDirServerG2);
	SetMessageType(mKeyType == KT_SERVICE ? WONMsg::DirG2ServiceExplicitSetDataObjects : WONMsg::DirG2DirectoryExplicitSetDataObjects);
	SMsgDirG2UpdateBase::Pack();

	PackKey(*this);

	AppendShort(mObjects.size());
	ExplicitDOInfoList::iterator anItr(mObjects.begin());
	for (; anItr != mObjects.end(); anItr++)
	{
		AppendByte(static_cast<unsigned char>(anItr->mSetMode));

		unsigned char aTypeLen = anItr->mData.GetDataType().size();
		AppendByte(aTypeLen);
		if (aTypeLen > 0)
			AppendBytes(aTypeLen, anItr->mData.GetDataType().data());

		unsigned short aDataLen = anItr->mData.GetData().size();
		AppendShort(aDataLen);
		if (aDataLen > 0)
			AppendBytes(aDataLen, anItr->mData.GetData().data());
	}

	PackPeerData();
	return GetDataPtr();
}
コード例 #3
0
// TMsgAuth1Complete::Pack
// Virtual method from TMessage.  Packs data into message buffer and
// sets the new message length.
void*
TMsgAuth1Complete::Pack(void)
{
	WTRACE("TMsgAuth1Complete::Pack");
	SetServiceType(WONMsg::Auth1PeerToPeer);
	SetMessageType(WONMsg::Auth1Complete);
	TMsgAuthRawBufferBase::Pack();

	WDBG_LL("TMsgAuth1Complete::Pack Appending message data");
	AppendShort(static_cast<short>(mStatus));

	// Append error info if status implies failure
	if (mStatus < 0)
	{
		WDBG_LL("TMsgAuth1Complete::Pack Failure status, append error info");
		AppendShort(mErrList.size());
		ErrorList::iterator anItr(mErrList.begin());
		for (; anItr != mErrList.end(); anItr++)
			Append_PA_STRING(*anItr);
	}

	// Otherwise append success info
	else
	{
		WDBG_LL("TMsgAuth1Complete::Pack Success status, append secret and optional session");
		PackRawBuf();
		if (mSessionId != 0) AppendShort(mSessionId);
	}

	return GetDataPtr();
}
コード例 #4
0
ファイル: Auth1PublicKeyBlock.cpp プロジェクト: vgck/opendr2
// Auth1PublicKeyBlock::PackData
// Packs member data into raw buffer in base class.  Returns true on success and
// false on failure.  Makes sure keyList is not empty.  Appends number of keys
// in key list.  For each key, appends key length and the key.
bool
Auth1PublicKeyBlock::PackData()
{
	WTRACE("Auth1PublicKeyBlock::PackData");
	if (! AuthPublicKeyBlockBase::PackData()) return false;

	// KeyList cannot be empty.
	WDBG_LL("Auth1PublicKeyBlock::PackData Validating...");
	if (mKeyList.empty())
	{
		WDBG_LH("Auth1PublicKeyBlock::PackData KeySet is empty, pack fails.");
		return false;
	}

	// Append fixed length data
	WDBG_LL("Auth1PublicKeyBlock::PackData Packing...");
	unsigned short aNumKeys = mKeyList.size();
	makeLittleEndian(aNumKeys);
	mRawBuf.append(reinterpret_cast<unsigned char*>(&aNumKeys), sizeof(aNumKeys));

	// Append each key (length and binary data)
	WDBG_LL("Auth1PublicKeyBlock::PackData Packing keys (" << mKeyList.size() << ')');
	PublicKeyList::iterator anItr(mKeyList.begin());
	for (; anItr != mKeyList.end(); anItr++)
	{
		unsigned short aKeyLen = anItr->GetKeyLen();
		unsigned short tmpKeyLen = getLittleEndian(aKeyLen);
		mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpKeyLen), sizeof(tmpKeyLen));
		mRawBuf.append(anItr->GetKey(), aKeyLen);
	}

	return true;
}
コード例 #5
0
ファイル: Auth1PrivateKeyBlock.cpp プロジェクト: vgck/opendr2
// Auth1PrivateKeyBlock::PackData
// Packs member data into raw buffer in base class.  Returns true on success and
// false on failure.  Makes sure keyList is not empty.  Appends number of keys
// in key list.  For each key, appends key length and the key.
bool
Auth1PrivateKeyBlock::PackData()
{
	WTRACE("Auth1PrivateKeyBlock::PackData");
	if (! AuthPublicKeyBlockBase::PackData()) return false;

	// KeyList cannot be empty.
	WDBG_LL("Auth1PrivateKeyBlock::PackData Validating...");
	if (mKeyList.empty())
	{
		WDBG_LH("Auth1PrivateKeyBlock::PackData KeySet is empty, pack fails.");
		return false;
	}

	// Append fixed length data
	WDBG_LL("Auth1PrivateKeyBlock::PackData Packing...");
	unsigned short aNumKeys = mKeyList.size();
	unsigned short tmpNumKeys = getLittleEndian(aNumKeys);
	mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpNumKeys), sizeof(tmpNumKeys));

	// Append each key (length and binary data)
	WDBG_LL("Auth1PrivateKeyBlock::PackData Packing keys (" << mKeyList.size() << ')');
	PrivateKeyList::iterator anItr(mKeyList.begin());
	for (; anItr != mKeyList.end(); anItr++)
	{
		unsigned short aKeyLen = (*anItr)->GetKeyLen();
		unsigned short tmpKeyLen = getLittleEndian(tmpKeyLen);
		mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpKeyLen), sizeof(tmpKeyLen));
		mRawBuf.append((*anItr)->GetKey(), aKeyLen);

        // count and record which BlockId's map to this key.
	    PrivateKeyMap::iterator aMapIter(mKeyMap.begin());
		unsigned short aBlockIDCount=0;
        std::list<unsigned short> aBlockIdList;
        for(; aMapIter != mKeyMap.end(); aMapIter++)
        {
            if( aMapIter->second == *anItr )
            {
                aBlockIDCount++;
                aBlockIdList.push_back( aMapIter->first );
            }
        }

		unsigned short tmpBlockIDCount = getLittleEndian(aBlockIDCount);
		
        // pack BlockId count and BlockIds
		mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpBlockIDCount), sizeof(tmpBlockIDCount));
        while( aBlockIdList.size() )
        {
            unsigned short aBlockId = aBlockIdList.front();
            makeLittleEndian(aBlockId);
		    mRawBuf.append(reinterpret_cast<unsigned char*>(& aBlockId), sizeof(unsigned short));
            aBlockIdList.pop_front();
        }
	}

	return true;
}
コード例 #6
0
ファイル: Auth1PrivateKeyBlock.cpp プロジェクト: vgck/opendr2
// Auth1PrivateKeyBlock::Dump
// Streaming method.  Outputs base class info and all keys.
void
Auth1PrivateKeyBlock::Dump(std::ostream& os) const
{
	// Output buf and data length
	os << "(AuthPrivKeyBlk1 RawLen=" << mRawBuf.size() << " DataLen=" << mDataLen << endl;
	os << "  Family=" << GetFamily() << endl;
	os << "  IssueTime=" << ctime(&mIssueTime);
	os << "  ExpireTime=" << ctime(&mExpireTime);
	os << "  BlockId=" << mBlockId << " NumKeys=" << mKeyList.size() << endl;

	PrivateKeyList::const_iterator anItr(mKeyList.begin());
	for (int i=1; anItr != mKeyList.end(); i++,anItr++)
		os << "    Key" << i << '=' << *anItr << endl;
}
コード例 #7
0
ファイル: Auth1PublicKeyBlock.cpp プロジェクト: vgck/opendr2
// Auth1PublicKeyBlock::ComputeBufSize
// Determines number of bytes required in buffer for PACK and UNPACK operations.
// For PACK, returns base class total + fixed size + length of public keys.  For
// UNPACK, returns base class total + fixed size.
RawBuffer::size_type
Auth1PublicKeyBlock::ComputeBufSize(SizeComputeMode theMode) const
{
	WTRACE("Auth1PublicKeyBlock::ComputeBufSize");
	RawBuffer::size_type aRet = AuthPublicKeyBlockBase::ComputeBufSize(theMode) + BLOCK_MINLEN;
	if (theMode == PACK)
	{
		WDBG_LL("Auth1PublicKeyBlock::ComputeBufSize Add size of each key (" << mKeyList.size() << ')');
		PublicKeyList::const_iterator anItr(mKeyList.begin());
		for (; anItr != mKeyList.end(); anItr++)
			aRet += sizeof(unsigned short) + anItr->GetKeyLen();
	}

	return aRet;
}
コード例 #8
0
void
SMsgDirG2QueryExtendBase::PackExtended(void)
{
	WTRACE("SMsgDirG2QueryExtendBase::PackExtended");
	WDBG_LL("SMsgDirG2QueryExtendBase::PackExtended Extended=" << mExtended << " GetTypes size=" << mGetTypes.size());
	if (! mExtended) return;

	AppendShort(mGetTypes.size());
	DataObjectTypeSet::iterator anItr(mGetTypes.begin());
	for (; anItr != mGetTypes.end(); anItr++)
	{
		unsigned char aLen = anItr->GetDataType().size();
		AppendByte(aLen);
		if (aLen > 0)
			AppendBytes(aLen, anItr->GetDataType().data());
	}
}
コード例 #9
0
ファイル: Auth1PublicKeyBlock.cpp プロジェクト: vgck/opendr2
bool
Auth1PublicKeyBlock::VerifyFamilyBuffer(const AuthFamilyBuffer& theBufR) const
{
	WTRACE("Auth1PublicKeyBlock::VerifyFamilyBuffer");
	WDBG_LM("Auth1PublicKeyBlock::VerifyFamilyBuffer Verify Buffer: " << theBufR);
	if ((! IsValid()) || (! theBufR.IsValid())) return false;

	PublicKeyList::const_iterator anItr(mKeyList.begin());
	for (; anItr != mKeyList.end(); anItr++)
	{
		WDBG_LL("Auth1PublicKeyBlock::VerifyFamilyBuffer Verify with key=" << *anItr);
		if (theBufR.Verify(*anItr)) break;
	}

	WDBG_LM("Auth1PublicKeyBlock::VerifyFamilyBuffer Verify Result=" << (anItr != mKeyList.end()));
	return (anItr != mKeyList.end());
}
コード例 #10
0
void
SMsgDirG2UpdateExtendBase::PackExtended(void)
{
	WTRACE("SMsgDirG2UpdateExtendBase::PackExtended");
	WDBG_LL("SMsgDirG2UpdateExtendBase::PackExtended enableDataObjects=" << mEnableDataObjects << " enableACLs=" << mEnableACLs);

	if (mEnableDataObjects)
	{
		WDBG_LL("SMsgDirG2UpdateExtendBase::PackExtended Writing " << mDataObjects.size() << " data objects.");
		AppendShort(mDataObjects.size());
		DataObjectTypeSet::iterator anItr(mDataObjects.begin());
		for (; anItr != mDataObjects.end(); anItr++)
		{
			unsigned char aTypeLen = anItr->GetDataType().size();
			AppendByte(aTypeLen);
			if (aTypeLen > 0)
				AppendBytes(aTypeLen, anItr->GetDataType().data());

			unsigned short aDataLen = anItr->GetData().size();
			AppendShort(aDataLen);
			if (aDataLen > 0)
				AppendBytes(aDataLen, anItr->GetData().data());
		}
	}

	if (mEnableACLs)
	{
		WDBG_LL("SMsgDirG2UpdateExtendBase::PackExtended Writing " << mACLs.size() << " ACLs.");
		AppendShort(mACLs.size());

		DirACLList::const_iterator anACLItr(mACLs.begin());
		for (; anACLItr != mACLs.end(); anACLItr++)
		{
			AppendByte(anACLItr->mType);
			AppendShort(anACLItr->mACL.size());
			PermissionACL::const_iterator aPermItr(anACLItr->mACL.begin());
			for (; aPermItr != anACLItr->mACL.end(); aPermItr++)
			{
				AppendLong(aPermItr->mUserId);
				AppendLong(aPermItr->mCommunityId);
				AppendShort(aPermItr->mTrustLevel);
			}
		}
	}
}
コード例 #11
0
ファイル: Auth1PublicKeyBlock.cpp プロジェクト: vgck/opendr2
bool
Auth1PublicKeyBlock::VerifyRawBuffer(const unsigned char* theSigP, unsigned long theSigLen,
                                     const unsigned char* theMsgP, unsigned long theMsgLen) const
{
	WTRACE("Auth1PublicKeyBlock::VerifyRawBuffer");
	WDBG_LM("Auth1PublicKeyBlock::VerifyRawBuffer Verify Buffer, SigLen=" << theSigLen << " Msglen=" << theMsgLen);
	if (! IsValid()) return false;

	PublicKeyList::const_iterator anItr(mKeyList.begin());
	for (; anItr != mKeyList.end(); anItr++)
	{
		WDBG_LL("Auth1PublicKeyBlock::VerifyFamilyBuffer Verify with key=" << *anItr);
		if (anItr->Verify(theSigP, theSigLen, theMsgP, theMsgLen)) break;
	}

	WDBG_LM("Auth1PublicKeyBlock::VerifyRawBuffer Verify Result=" << (anItr != mKeyList.end()));
	return (anItr != mKeyList.end());
}
コード例 #12
0
// SMsgDirG2GetNumEntities::Pack
// Virtual method from SmallMessage.  Packs data into message buffer.
void*
SMsgDirG2GetNumEntities::Pack(void)
{
	WTRACE("SMsgDirG2GetNumEntities::Pack");
	SetServiceType(WONMsg::SmallDirServerG2);
	SetMessageType(WONMsg::DirG2GetNumEntities);
	SmallMessage::Pack();

	WDBG_LL("SMsgDirG2GetNumEntities::Pack Appending message data");
	AppendShort(mPaths.size());

	WDBG_LL("SMsgDirG2GetNumEntities::Pack Writing " << mPaths.size() << " entries.");
	DirPathList::iterator anItr(mPaths.begin());
	for (; anItr != mPaths.end(); anItr++)
	{
		Append_PW_STRING(anItr->mPath);
		AppendShort(static_cast<short>(anItr->mMode));
	}

	return GetDataPtr();
}
コード例 #13
0
// SMsgDirG2ClearDataObjects::Pack
// Virtual method from SmallMessage.  Packs data into message buffer.
void*
SMsgDirG2ClearDataObjects::Pack(void)
{
	WTRACE("SMsgDirG2ClearDataObjects::Pack");
	SetServiceType(WONMsg::SmallDirServerG2);
	SetMessageType(mKeyType == KT_SERVICE ? WONMsg::DirG2ServiceClearDataObjects : WONMsg::DirG2DirectoryClearDataObjects);
	SMsgDirG2UpdateBase::Pack();

	PackKey(*this);

	AppendShort(mClearTypes.size());
	DataObjectTypeSet::iterator anItr(mClearTypes.begin());
	for (; anItr != mClearTypes.end(); anItr++)
	{
		unsigned char aLen = anItr->GetDataType().size();
		AppendByte(aLen);
		if (aLen > 0)
			AppendBytes(aLen, anItr->GetDataType().data());
	}

	PackPeerData();
	return GetDataPtr();
}
コード例 #14
0
unsigned long
DirEntity::ComputeSize(unsigned long theGetFlags, const DataObjectTypeSet& theSetR) const
{
	unsigned long aSize = 0;

	// Add type if needed
	if (theGetFlags & WONMsg::GF_ADDTYPE)
		aSize += sizeof(mType);

	// Entity specific fields
	switch (mType)
	{
	case DirEntity::ET_DIRECTORY:
		// Add dir path if needed
		if (theGetFlags & WONMsg::GF_DIRADDPATH)
			aSize += TRawMsg::ComputeWStringPackSize(mPath);
		// Add dir name if needed
		if (theGetFlags & WONMsg::GF_DIRADDNAME)
			aSize += TRawMsg::ComputeWStringPackSize(mName);
		// Add dir visibility if needed
		if (theGetFlags & WONMsg::GF_DIRADDVISIBLE)
			aSize += sizeof(mVisible);
		break;
	case DirEntity::ET_SERVICE:
		// Add serv path if needed
		if (theGetFlags & WONMsg::GF_SERVADDPATH)
			aSize += TRawMsg::ComputeWStringPackSize(mPath);
		// Add serv name if needed
		if (theGetFlags & WONMsg::GF_SERVADDNAME)
			aSize += TRawMsg::ComputeWStringPackSize(mName);
		// Add serv netaddress if needed
		if (theGetFlags & WONMsg::GF_SERVADDNETADDR)
			aSize += sizeof(unsigned char) + mNetAddress.size();
		break;
	}

	// Add displayName if needed
	if (theGetFlags & WONMsg::GF_ADDDISPLAYNAME)
		aSize += TRawMsg::ComputeWStringPackSize(mDisplayName);

	// Add lifespan if needed
	if (theGetFlags & WONMsg::GF_ADDLIFESPAN)
		aSize += sizeof(mLifespan);

	// Add create date if needed
	if (theGetFlags & WONMsg::GF_ADDCREATED)
		aSize += sizeof(mCreated);

	// Add touched date if needed
	if (theGetFlags & WONMsg::GF_ADDTOUCHED)
		aSize += sizeof(mTouched);

	// Add CRC if needed
	if (theGetFlags & WONMsg::GF_ADDCRC)
		aSize += sizeof(mCRC);

	// Add UserIds if needed
	if (theGetFlags & WONMsg::GF_ADDUIDS)
		aSize += sizeof(mCreateId) + sizeof(mTouchId);

	// Data Objects
	bool packAllObjs = ((theGetFlags & WONMsg::GF_ADDDATAOBJECTS) != 0);
	if ((packAllObjs) || (! theSetR.empty()))
	{
		aSize += sizeof(unsigned short);  // data object count
		bool packType = ((theGetFlags & WONMsg::GF_ADDDOTYPE) != 0);
		bool packData = ((theGetFlags & WONMsg::GF_ADDDODATA) != 0);
		DataObjectTypeSet::const_iterator anItr(mDataObjects.begin());
		for (; anItr != mDataObjects.end(); ++anItr)
		{
			if ((packAllObjs) || (theSetR.find(*anItr) != theSetR.end()))
			{
				if (packType)
					aSize += sizeof(unsigned char)  + anItr->GetDataType().size();
				if (packData)
					aSize += sizeof(unsigned short) + anItr->GetData().size();
			}
		}
	}

	// Add ACLs if needed
	if (theGetFlags & WONMsg::GF_ADDACLS)
	{
		aSize += sizeof(unsigned short);  // ACL count
		DirACLList::const_iterator anItr(mACLs.begin());
		for (; anItr != mACLs.end(); ++anItr)
			aSize += sizeof(unsigned char) + sizeof(unsigned short) + (anItr->mACL.size() * sizeof(Permission));
	}

	return aSize;
}
コード例 #15
0
void
DirEntity::Pack(BaseMessage& theMsgR, unsigned long theGetFlags,
                const DataObjectTypeSet& theSetR) const
{
	WTRACE("DirEntity::Pack");
	WDBG_LL("DirEntity::Pack Packing entity, type=" << mType);

	// Add type if needed
	if (theGetFlags & WONMsg::GF_ADDTYPE)
		theMsgR.AppendByte(mType);

	// Entity specific fields
	switch (mType)
	{
	case DirEntity::ET_DIRECTORY:
		// Add dir path if needed
		if (theGetFlags & WONMsg::GF_DIRADDPATH)
			theMsgR.Append_PW_STRING(mPath);
		// Add dir name if needed
		if (theGetFlags & WONMsg::GF_DIRADDNAME)
			theMsgR.Append_PW_STRING(mName);
		// Add dir visibility if needed
		if (theGetFlags & WONMsg::GF_DIRADDVISIBLE)
			theMsgR.AppendByte(mVisible);
		break;
	case DirEntity::ET_SERVICE:
		// Add serv path if needed
		if (theGetFlags & WONMsg::GF_SERVADDPATH)
			theMsgR.Append_PW_STRING(mPath);
		// Add serv name if needed
		if (theGetFlags & WONMsg::GF_SERVADDNAME)
			theMsgR.Append_PW_STRING(mName);
		// Add serv netaddress if needed
		if (theGetFlags & WONMsg::GF_SERVADDNETADDR)
		{
			theMsgR.AppendByte(mNetAddress.size());
			theMsgR.AppendBytes(mNetAddress.size(), mNetAddress.data());
		}
		break;
	}

	// Add displayName if needed
	if (theGetFlags & WONMsg::GF_ADDDISPLAYNAME)
		theMsgR.Append_PW_STRING(mDisplayName);

	// Add lifespan if needed
	if (theGetFlags & WONMsg::GF_ADDLIFESPAN)
		theMsgR.AppendLong(mLifespan);

	// Add create date if needed
	if (theGetFlags & WONMsg::GF_ADDCREATED)
		theMsgR.AppendLong(mCreated);

	// Add touched date if needed
	if (theGetFlags & WONMsg::GF_ADDTOUCHED)
		theMsgR.AppendLong(mTouched);

	// Add CRC if needed
	if (theGetFlags & WONMsg::GF_ADDCRC)
		theMsgR.AppendLong(mCRC);

	// Add UserIds if needed
	if (theGetFlags & WONMsg::GF_ADDUIDS)
	{
		theMsgR.AppendLong(mCreateId);
		theMsgR.AppendLong(mTouchId);
	}

	// Add all data objects if needed
	if (theGetFlags & WONMsg::GF_ADDDATAOBJECTS)
		PackDataObjects(theMsgR, mDataObjects, theGetFlags);

	// Otherwise, add requested data objects (if any)
	else if (theSetR.size() > 0)
	{
		DataObjectTypeSet aPackSet;
		DataObjectTypeSet::const_iterator anItr(theSetR.begin());
		for (; anItr != theSetR.end(); anItr++)
		{
			DataObjectTypeSet::const_iterator aSrch(mDataObjects.find(*anItr));
			if (aSrch != mDataObjects.end())
				aPackSet.insert(*aSrch);
		}
		PackDataObjects(theMsgR, aPackSet, theGetFlags);
	}

	// Add ACLs if needed (deferred)
	if (theGetFlags & WONMsg::GF_ADDACLS)
		PackACLs(theMsgR);
}