TEST_F(CmWSHandleRFC6455Test, Decode1Msg1PktMaskTest)
{
    UINT8  uFirstByte = 0x81;
    UINT8  uDataLen = SZ_DATA_TEST1_LEN;
    UINT8  uSecondByte = 0x80 | uDataLen;

    CCmMessageBlock aHead(6);
    CCmMessageBlock aData(SZ_DATA_TEST1_LEN);

    aHead.Write(&uFirstByte, sizeof(UINT8));
    aHead.Write(&uSecondByte, sizeof(UINT8));
    aHead.Write(m_mask_key, 4);

    aData.Write(m_pMaskData1, SZ_DATA_TEST1_LEN);
    aHead.Append(&aData);

    CCmMessageBlock* aDataIn = aHead.DuplicateChained();
    CCmMessageBlock* aDataOut = NULL;

    m_RFC6455.SetDataType(E_WS_DTYPE_TEXT);

    EXPECT_EQ(CM_OK, m_RFC6455.Decode(*aDataIn, aDataOut));

    CCmMessageBlock aExpect(SZ_DATA_TEST1_LEN, SZ_DATA_TEST1, CCmMessageBlock::DONT_DELETE, SZ_DATA_TEST1_LEN);
    EXPECT_TRUE(IsMessageEqual(aExpect, *aDataOut));

    SAFE_DELETE(aDataIn);
    SAFE_DELETE(aDataOut);
}
TEST_F(CmWSHandleRFC6455Test, Decode1Msg1PktTest)
{
    UINT8  uFirstByte = 0x81;
    UINT8  uSecondByte = SZ_DATA_TEST1_LEN;

    CCmMessageBlock aHead(2);
    CCmMessageBlock aData(SZ_DATA_TEST1_LEN);

    aHead.Write(&uFirstByte, sizeof(UINT8));
    aHead.Write(&uSecondByte, sizeof(UINT8));

    aData.Write(SZ_DATA_TEST1, SZ_DATA_TEST1_LEN);
    aHead.Append(&aData);

    CCmMessageBlock* aDataIn = aHead.DuplicateChained();
    CCmMessageBlock* aDataOut = NULL;

    m_RFC6455.SetDataType(E_WS_DTYPE_TEXT);

    EXPECT_EQ(CM_OK, m_RFC6455.Decode(*aDataIn, aDataOut));
    EXPECT_TRUE(IsMessageEqual(aData, *aDataOut));

    SAFE_DELETE(aDataIn);
    SAFE_DELETE(aDataOut);
}
TEST_F(CmWSHandleRFC6455Test, Decode126ErrorTest)
{
    char szBuf[500] = {0};
    memset(szBuf, 'e', 500);
    szBuf[499] = '\0';

    UINT8  uFirstByte = 0x81;
    UINT8  uSecondByte = 126;

    CCmMessageBlock aHead(2);
    CCmMessageBlock aData(strlen(szBuf));
    aData.Write(szBuf, strlen(szBuf));

    CCmByteStreamNetwork networkStream(aHead);
    networkStream << uFirstByte;
    networkStream << uSecondByte;

    aHead.Append(&aData);

    CCmMessageBlock* aDataIn = aHead.DuplicateChained();
    CCmMessageBlock* aDataOut = NULL;

    m_RFC6455.SetDataType(E_WS_DTYPE_TEXT);

    EXPECT_EQ(CM_OK, m_RFC6455.Decode(*aDataIn, aDataOut));

    SAFE_DELETE(aDataIn);
    SAFE_DELETE(aDataOut);
}
TEST_F(CmWSHandleRFC6455Test, Decode127Test)
{
    char szBuf[0x10000] = {0};
    memset(szBuf, 'f', 0x10000);
    szBuf[0x10000 - 1] = '\0';

    UINT8  uFirstByte = 0x81;
    UINT8  uSecondByte = 127;

    CCmMessageBlock aHead(10);
    CCmMessageBlock aData(strlen(szBuf));
    aData.Write(szBuf, strlen(szBuf));

    unsigned long long uDataLen = aData.GetChainedLength();

    CCmByteStreamNetwork networkStream(aHead);

    networkStream << uFirstByte;
    networkStream << uSecondByte;
    networkStream << uDataLen;

    aHead.Append(aData.DuplicateChained());

    CCmMessageBlock* aDataOut = NULL;

    m_RFC6455.SetDataType(E_WS_DTYPE_TEXT);

    EXPECT_EQ(CM_OK, m_RFC6455.Decode(aHead, aDataOut));

    EXPECT_TRUE(IsMessageEqual(aData, *aDataOut));

    ASSERT_TRUE(NULL != aDataOut);
    aDataOut->DestroyChained();
}
TEST_F(CmWSHandleRFC6455Test, Decode126Test)
{
    char szBuf[500] = {0};
    memset(szBuf, 'e', 500);
    szBuf[499] = '\0';

    UINT8  uFirstByte = 0x81;
    UINT8  uSecondByte = 126;

    CCmMessageBlock aHead(4);
    CCmMessageBlock aData(strlen(szBuf));
    aData.Write(szBuf, strlen(szBuf));

    UINT16 uDataLen = (UINT16)aData.GetChainedLength();

    CCmByteStreamNetwork networkStream(aHead);

    networkStream << uFirstByte;
    networkStream << uSecondByte;
    networkStream << uDataLen;

    aHead.Append(aData.DuplicateChained());

    CCmMessageBlock* aDataOut = NULL;

    m_RFC6455.SetDataType(E_WS_DTYPE_TEXT);

    EXPECT_EQ(CM_OK, m_RFC6455.Decode(aHead, aDataOut));
    EXPECT_TRUE(IsMessageEqual(aData, *aDataOut));

    aDataOut->DestroyChained();
    aDataOut = NULL;
}
CSSM_HANDLE
AppleX509CLSession::CrlGetFirstFieldValue(
	const CssmData &Crl,
	const CssmData &CrlField,
	uint32 &NumberOfMatchedFields,
	CSSM_DATA_PTR &Value)
{
	NumberOfMatchedFields = 0;
	Value = NULL;
	CssmAutoData aData(*this);
	
	DecodedCrl *decodedCrl = new DecodedCrl(*this, Crl);
	uint32 numMatches;
	
	/* this returns false if field not there, throws on bad OID */
	bool brtn;
	try {
		brtn = decodedCrl->getCrlFieldData(CrlField, 
			0, 				// index
			numMatches, 
			aData);
	}
	catch (...) {
		delete decodedCrl;
		throw;
	}
	if(!brtn) {
		delete decodedCrl;
		return CSSM_INVALID_HANDLE;
	}

	/* cook up a CLCachedCRL, stash it in cache */
	CLCachedCRL *cachedCrl = new CLCachedCRL(*decodedCrl);
	cacheMap.addEntry(*cachedCrl, cachedCrl->handle());
	
	/* cook up a CLQuery, stash it */
	CLQuery *query = new CLQuery(
		CLQ_CRL, 
		CrlField, 
		numMatches,
		false,				// isFromCache
		cachedCrl->handle());
	queryMap.addEntry(*query, query->handle());
	
	/* success - copy field data to outgoing Value */
	Value = (CSSM_DATA_PTR)malloc(sizeof(CSSM_DATA));
	*Value = aData.release();
	NumberOfMatchedFields = numMatches;
	return query->handle();
}
TEST_F(CmWSHandleRFC6455Test, Decode127TestMask)
{
    char* pBuf = new char[565633];
    memset(pBuf, 'f', 565633);
    pBuf[565632] = '\0';

    UINT8  uFirstByte = 0x81;
    UINT8  uSecondByte = 0xff;

    DWORD dwSize = 565632;
    char* pMask = Mask(pBuf, dwSize);

    CCmMessageBlock aHead(14);
    CCmMessageBlock aData(dwSize);
    aData.Write(pBuf, dwSize);

    CCmMessageBlock aDataMask(dwSize);
    aDataMask.Write(pMask, dwSize);

    unsigned long long uDataLen = aDataMask.GetChainedLength();

    CCmByteStreamNetwork networkStream(aHead);

    networkStream << uFirstByte;
    networkStream << uSecondByte;
    networkStream << uDataLen;

    networkStream << m_mask_key[0];
    networkStream << m_mask_key[1];
    networkStream << m_mask_key[2];
    networkStream << m_mask_key[3];

    aHead.Append(&aDataMask);

    CCmMessageBlock* aDataOut = NULL;

    m_RFC6455.SetDataType(E_WS_DTYPE_TEXT);

    EXPECT_EQ(CM_OK, m_RFC6455.Decode(aHead, aDataOut));
    EXPECT_TRUE(IsMessageEqual(aData, *aDataOut));

    delete [] pMask;
    pMask = NULL;
    delete [] pBuf;
    pBuf = NULL;

    ASSERT_TRUE(NULL != aDataOut);
    aDataOut->DestroyChained();
}
/* 
 * FIXME - CrlRecordIndex not supported, it'll require mods to 
 * the DecodedCrl::getCrlFieldData mechanism
 */
CSSM_HANDLE
AppleX509CLSession::CrlGetFirstCachedFieldValue(
	CSSM_HANDLE CrlHandle,
	const CssmData *CrlRecordIndex,
	const CssmData &CrlField,
	uint32 &NumberOfMatchedFields,
	CSSM_DATA_PTR &Value)
{
	if(CrlRecordIndex != NULL) {
		/* not yet */
		CssmError::throwMe(CSSMERR_CL_INVALID_CRL_INDEX);
	}
	
	/* fetch the associated cached CRL */
	CLCachedCRL *cachedCrl = lookupCachedCRL(CrlHandle);
	if(cachedCrl == NULL) {
		CssmError::throwMe(CSSMERR_CL_INVALID_CACHE_HANDLE);
	}
	
	CssmAutoData aData(*this);
	uint32 numMatches;

	/* this returns false if field not there, throws on bad OID */
	if(!cachedCrl->crl().getCrlFieldData(CrlField, 
			0, 				// index
			numMatches, 
			aData)) {
		return CSSM_INVALID_HANDLE;
	}

	/* cook up a CLQuery, stash it */
	CLQuery *query = new CLQuery(
		CLQ_CRL, 
		CrlField, 
		numMatches,
		true,				// isFromCache
		cachedCrl->handle());
	queryMap.addEntry(*query, query->handle());
	
	/* success - copy field data to outgoing Value */
	Value = (CSSM_DATA_PTR)malloc(sizeof(CSSM_DATA));
	*Value = aData.release();
	NumberOfMatchedFields = numMatches;
	return query->handle();
}
示例#9
0
/// Reads FLV from stdin and outputs human-readable information to stderr.
int main(int argc, char ** argv){
  Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
  conf.parseArgs(argc, argv);
  FLV::Tag FLV_in; // Temporary storage for incoming FLV data.
  std::ofstream vData("vData");
  std::ofstream aData("aData");
  while ( !feof(stdin)){
    if (FLV_in.FileLoader(stdin)){
      std::cout << "Tag: " << FLV_in.tagType() << "\n\tTime: " << FLV_in.tagTime() << std::endl;
      if (FLV_in.data[0] == 0x08){ //Audio
        aData.write(FLV_in.data + 13, FLV_in.len - 17);
      }
      if (FLV_in.data[0] == 0x09){ //Video
        vData.write(FLV_in.data + 16, FLV_in.len - 20);
      }
    }
  }
  vData.close();
  aData.close();
  return 0;
}
示例#10
0
bool
AppleX509CLSession::CrlGetNextFieldValue(
	CSSM_HANDLE ResultsHandle,
	CSSM_DATA_PTR &Value)
{
	/* fetch & validate the query */
	CLQuery *query = queryMap.lookupEntry(ResultsHandle);
	if(query == NULL) {
		CssmError::throwMe(CSSMERR_CL_INVALID_RESULTS_HANDLE);
	}
	if(query->queryType() != CLQ_CRL) {
		clErrorLog("CrlGetNextFieldValue: bad queryType (%d)", 
			(int)query->queryType());
		CssmError::throwMe(CSSMERR_CL_INVALID_RESULTS_HANDLE);
	}
	if(query->nextIndex() >= query->numFields()) {
		return false;
	}

	/* fetch the associated cached CRL */
	CLCachedCRL *cachedCrl = lookupCachedCRL(query->cachedObject());
	uint32 dummy;
	CssmAutoData aData(*this);
	if(!cachedCrl->crl().getCrlFieldData(query->fieldId(), 
		query->nextIndex(), 
		dummy,
		aData))  {
		return false;
	}
		
	/* success - copy field data to outgoing Value */
	Value = (CSSM_DATA_PTR)malloc(sizeof(CSSM_DATA));
	*Value = aData.release();
	query->incrementIndex();
	return true;
}
/*
 * Common means to get all fields from a decoded cert. Used in
 * CertGetAllTemplateFields and CertGetAllFields.
 */
void DecodedCert::getAllParsedCertFields(
	uint32 				&NumberOfFields,		// RETURNED
	CSSM_FIELD_PTR 		&CertFields)			// RETURNED
{
	/* this is the max - some might be missing */
	uint32 maxFields = NUM_STD_CERT_FIELDS + mDecodedExtensions.numExtensions();
	CSSM_FIELD_PTR outFields = (CSSM_FIELD_PTR)mAlloc.malloc(maxFields * sizeof(CSSM_FIELD));

	/*
	 * We'll be copying oids and values for fields we find into
	 * outFields; current number of valid fields found in numOutFields.
	 */
	memset(outFields, 0, maxFields * sizeof(CSSM_FIELD));
	uint32 			numOutFields = 0;
	CSSM_FIELD_PTR 	currOutField;
	uint32 			currOidDex;
	const CSSM_OID 	*currOid;
	CssmAutoData 	aData(mAlloc);		// for malloc/copy of outgoing data

	/* query for each OID we know about */
	for(currOidDex=0; currOidDex<NUM_KNOWN_FIELDS; currOidDex++) {
		const oidToFieldFuncs *fieldFuncs = &fieldFuncTable[currOidDex];
		currOid = fieldFuncs->fieldId;
		uint32 numFields;				// for THIS oid

		/*
		 * Return false if field not there, which is not an error here.
		 * Actual exceptions are fatal.
		 */
		if(!fieldFuncs->getFcn(*this,
				0, 				// index - looking for first one
				numFields,
				aData)) {
			continue;
		}

		/* got some data for this oid - copy it and oid to outgoing CertFields */
		assert(numOutFields < maxFields);
		currOutField = &outFields[numOutFields];
		currOutField->FieldValue = aData.release();
		aData.copy(*currOid);
		currOutField->FieldOid = aData.release();
		numOutFields++;

		/* if more fields are available for this OID, snag them too */
		for(uint32 fieldDex=1; fieldDex<numFields; fieldDex++) {
			/* note this should always succeed */
			bool brtn = fieldFuncs->getFcn(*this,
				fieldDex,
				numFields, 			// shouldn't change
				aData);
			if(!brtn) {
				clErrorLog("getAllParsedCertFields: index screwup");
				CssmError::throwMe(CSSMERR_CL_INTERNAL_ERROR);
			}
			assert(numOutFields < maxFields);
			currOutField = &outFields[numOutFields];
			currOutField->FieldValue = aData.release();
			aData.copy(*currOid);
			currOutField->FieldOid = aData.release();
			numOutFields++;
		}	/* multiple fields for currOid */
	}		/* for each known OID */

	NumberOfFields = numOutFields;
	CertFields = outFields;
}