⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipmpx_code.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 5 页
字号:
	gf_bs_read_int(bs, 3);	if (requestNegotiation) {		count = gf_bs_read_int(bs, 8);		for (i=0; i<count; i++) {			GF_IPMPX_Authentication *auth;			e = GF_IPMPX_AUTH_Parse(bs, &auth);			if (e) return e;			gf_list_add(p->candidateAlgorithms, auth);		}	}	if (successNegotiation) {		count = gf_bs_read_int(bs, 8);		for (i=0; i<count; i++) {			GF_IPMPX_Authentication *auth;			e = GF_IPMPX_AUTH_Parse(bs, &auth);			if (e) return e;			gf_list_add(p->agreedAlgorithms, auth);		}	}	if (inclAuthenticationData) p->AuthenticationData = GF_IPMPX_GetByteArray(bs);	if (inclAuthCodes) {		/*unspecified in spec, IM1 uses 8 bits*/		u32 type = gf_bs_read_int(bs, 8);		switch (type) {		case 0x01:			count = gf_bs_read_int(bs, 8);			p->certType = gf_bs_read_int(bs, 32);			for (i=0; i<count; i++) {				GF_IPMPX_ByteArray *ipd = GF_IPMPX_GetByteArray(bs);				if (ipd) gf_list_add(p->certificates, ipd);			}			break;		case 0x02:			e = GF_IPMPX_AUTH_Parse(bs, (GF_IPMPX_Authentication**) &p->publicKey);			if (e) return e;			break;		case 0xFE:			p->opaque = GF_IPMPX_GetByteArray(bs);			break;		default:			break;		}		e = gf_ipmpx_data_parse(bs, (GF_IPMPX_Data **) &p->trustData);		if (e) return e;		p->authCodes = GF_IPMPX_GetByteArray(bs);	}	return GF_OK;}static u32 SizeGF_IPMPX_MutualAuthentication(GF_IPMPX_Data *_p){	u32 size, i, count;	GF_IPMPX_MutualAuthentication *p = (GF_IPMPX_MutualAuthentication *)_p;	size = 1;	count = gf_list_count(p->candidateAlgorithms);	if (count) {		size += 1;		for (i=0; i<count; i++) {			GF_IPMPX_Authentication *ip_auth = (GF_IPMPX_Authentication *)gf_list_get(p->candidateAlgorithms, i);			size += GF_IPMPX_AUTH_FullSize(ip_auth);		}	}	count = gf_list_count(p->agreedAlgorithms);	if (count) {		size += 1;		for (i=0; i<count; i++) {			GF_IPMPX_Authentication *ip_auth = (GF_IPMPX_Authentication *)gf_list_get(p->agreedAlgorithms, i);			size += GF_IPMPX_AUTH_FullSize(ip_auth);		}	}	if (p->AuthenticationData) size += GF_IPMPX_GetByteArraySize(p->AuthenticationData);		count = gf_list_count(p->certificates);	if (count || p->opaque || p->publicKey) {		size += 1;		/*type 1*/		if (count) {			size += 1+4;			for (i=0; i<count; i++) {				GF_IPMPX_ByteArray *ba = (GF_IPMPX_ByteArray *)gf_list_get(p->certificates, i);				size += GF_IPMPX_GetByteArraySize(ba);			}		}		/*type 2*/		else if (p->publicKey) {			size += GF_IPMPX_AUTH_FullSize((GF_IPMPX_Authentication*)p->publicKey);		}		/*type 0xFE*/		else if (p->opaque) {			size += GF_IPMPX_GetByteArraySize(p->opaque);		}		size += gf_ipmpx_data_full_size((GF_IPMPX_Data *)p->trustData);		size += GF_IPMPX_GetByteArraySize(p->authCodes);	}	return size;}static GF_Err WriteGF_IPMPX_MutualAuthentication(GF_BitStream *bs, GF_IPMPX_Data *_p){	u32 i, count;	GF_IPMPX_MutualAuthentication *p = (GF_IPMPX_MutualAuthentication *)_p;	gf_bs_write_int(bs, gf_list_count(p->candidateAlgorithms) ? 1 : 0, 1);	gf_bs_write_int(bs, gf_list_count(p->agreedAlgorithms) ? 1 : 0, 1);	gf_bs_write_int(bs, p->failedNegotiation ? 1 : 0, 1);	gf_bs_write_int(bs, p->AuthenticationData ? 1 : 0, 1);	if (gf_list_count(p->certificates) || p->opaque || p->publicKey) {		gf_bs_write_int(bs, 1, 1);	} else {		gf_bs_write_int(bs, 0, 1);	}	gf_bs_write_int(bs, 0, 3);	count = gf_list_count(p->candidateAlgorithms);	if (count) {		gf_bs_write_int(bs, count, 8);		for (i=0; i<count; i++) {			GF_IPMPX_Authentication *ip_auth = (GF_IPMPX_Authentication *)gf_list_get(p->candidateAlgorithms, i);			WriteGF_IPMPX_AUTH(bs, ip_auth);		}	}	count = gf_list_count(p->agreedAlgorithms);	if (count) {		gf_bs_write_int(bs, count, 8);		for (i=0; i<count; i++) {			GF_IPMPX_Authentication *ip_auth = (GF_IPMPX_Authentication *)gf_list_get(p->agreedAlgorithms, i);			WriteGF_IPMPX_AUTH(bs, ip_auth);		}	}	if (p->AuthenticationData) GF_IPMPX_WriteByteArray(bs, p->AuthenticationData);		count = gf_list_count(p->certificates);	if (count || p->opaque || p->publicKey) {		/*type 1*/		if (count) {			gf_bs_write_int(bs, 0x01, 8);			gf_bs_write_int(bs, count, 8);			gf_bs_write_int(bs, p->certType, 32);			for (i=0; i<count; i++) {				GF_IPMPX_ByteArray *ipd = (GF_IPMPX_ByteArray *)gf_list_get(p->certificates, i);				if (ipd) GF_IPMPX_WriteByteArray(bs, ipd);			}		}		/*type 2*/		else if (p->publicKey) {			gf_bs_write_int(bs, 0x02, 8);			WriteGF_IPMPX_AUTH(bs, (GF_IPMPX_Authentication *) p->publicKey);		}		/*type 0xFE*/		else if (p->opaque) {			gf_bs_write_int(bs, 0xFE, 8);			GF_IPMPX_WriteByteArray(bs, p->opaque);		}		gf_ipmpx_data_write(bs, (GF_IPMPX_Data *)p->trustData);		GF_IPMPX_WriteByteArray(bs, p->authCodes);	}	return GF_OK;}static GF_IPMPX_Data *NewGF_IPMPX_TrustSecurityMetadata(){	GF_IPMPX_TrustSecurityMetadata *ptr;	GF_IPMPX_DATA_ALLOC(ptr, GF_IPMPX_TrustSecurityMetadata, GF_IPMPX_TRUST_SECURITY_METADATA_TAG);	ptr->TrustedTools = gf_list_new();	return (GF_IPMPX_Data *) ptr;}static void DelGF_IPMPX_TrustSecurityMetadata(GF_IPMPX_Data *_p){	GF_IPMPX_TrustSecurityMetadata *p = (GF_IPMPX_TrustSecurityMetadata *)_p;	while (gf_list_count(p->TrustedTools)) {		GF_IPMPX_TrustedTool *tt = (GF_IPMPX_TrustedTool *)gf_list_get(p->TrustedTools, 0);		gf_list_rem(p->TrustedTools, 0);		while (gf_list_count(tt->trustSpecifications)) {			GF_IPMPX_TrustSpecification *tts = (GF_IPMPX_TrustSpecification *)gf_list_get(tt->trustSpecifications, 0);			gf_list_rem(tt->trustSpecifications, 0);			GF_IPMPX_DELETE_ARRAY(tts->CCTrustMetadata);			free(tts);		}		gf_list_del(tt->trustSpecifications);		free(tt);	}	gf_list_del(p->TrustedTools);	free(p);}static GF_Err ReadGF_IPMPX_TrustSecurityMetadata(GF_BitStream *bs, GF_IPMPX_Data *_p, u32 size){	u32 nbTools, nbSpec;	GF_IPMPX_TrustSecurityMetadata *p = (GF_IPMPX_TrustSecurityMetadata *)_p;	nbTools = gf_bs_read_int(bs, 16);	while (nbTools) {		GF_IPMPX_TrustedTool *tt = (GF_IPMPX_TrustedTool *)malloc(sizeof(GF_IPMPX_TrustedTool));		if (!tt) return GF_OUT_OF_MEM;		memset(tt, 0, sizeof(GF_IPMPX_TrustedTool));		tt->tag = GF_IPMPX_TRUSTED_TOOL_TAG;		nbTools--;		gf_list_add(p->TrustedTools, tt);		gf_bs_read_data(bs, (char*)tt->toolID, 16);		gf_bs_read_data(bs, tt->AuditDate, 5);		tt->trustSpecifications = gf_list_new();		nbSpec = gf_bs_read_int(bs, 16);		while (nbSpec) {			Bool has_cc;			GF_IPMPX_TrustSpecification *tts = (GF_IPMPX_TrustSpecification *)malloc(sizeof(GF_IPMPX_TrustSpecification));			if (!tts) return GF_OUT_OF_MEM;			memset(tts, 0, sizeof(GF_IPMPX_TrustSpecification));			tts->tag = GF_IPMPX_TRUST_SPECIFICATION_TAG;			nbSpec--;			gf_list_add(tt->trustSpecifications, tts);			has_cc = gf_bs_read_int(bs, 1);			gf_bs_read_int(bs, 7);			if (has_cc) {				tts->CCTrustMetadata = GF_IPMPX_GetByteArray(bs);			} else {				gf_bs_read_data(bs, tts->startDate, 5);				tts->attackerProfile = gf_bs_read_int(bs, 2);				gf_bs_read_int(bs, 6);				tts->trustedDuration = gf_bs_read_int(bs, 32);			}		}	}	return GF_OK;}static u32 SizeGF_IPMPX_TrustSecurityMetadata(GF_IPMPX_Data *_p){	u32 size, i, j;	GF_IPMPX_TrustSecurityMetadata *p = (GF_IPMPX_TrustSecurityMetadata *)_p;	size = 2;	for (i=0;i<gf_list_count(p->TrustedTools); i++) {		GF_IPMPX_TrustedTool *tt = (GF_IPMPX_TrustedTool *)gf_list_get(p->TrustedTools, i);		size += 23;		for (j=0; j<gf_list_count(tt->trustSpecifications); j++) {			GF_IPMPX_TrustSpecification *tts = (GF_IPMPX_TrustSpecification *)gf_list_get(tt->trustSpecifications, j);			size += 1;			if (tts->CCTrustMetadata) size += GF_IPMPX_GetByteArraySize(tts->CCTrustMetadata);			else size += 10;		}	}	return size;}static GF_Err WriteGF_IPMPX_TrustSecurityMetadata(GF_BitStream *bs, GF_IPMPX_Data *_p){	u32 i, j, c1, c2;	GF_IPMPX_TrustSecurityMetadata *p = (GF_IPMPX_TrustSecurityMetadata *)_p;	c1 = gf_list_count(p->TrustedTools);	gf_bs_write_int(bs, c1, 16);	for (i=0;i<c1; i++) {		GF_IPMPX_TrustedTool *tt = (GF_IPMPX_TrustedTool *)gf_list_get(p->TrustedTools, i);		gf_bs_write_data(bs, (char*)tt->toolID, 16);		gf_bs_write_data(bs, (char*)tt->AuditDate, 5);		c2 = gf_list_count(tt->trustSpecifications);		gf_bs_write_int(bs, c2, 16);		for (j=0; j<c2; j++) {			GF_IPMPX_TrustSpecification *tts = (GF_IPMPX_TrustSpecification *)gf_list_get(tt->trustSpecifications, j);			gf_bs_write_int(bs, tts->CCTrustMetadata ? 1 : 0, 1);			gf_bs_write_int(bs, 0, 7);			if (tts->CCTrustMetadata) GF_IPMPX_WriteByteArray(bs, tts->CCTrustMetadata);			else {				gf_bs_write_data(bs, tts->startDate, 5);				gf_bs_write_int(bs, tts->attackerProfile, 2);				gf_bs_write_int(bs, 0, 6);				gf_bs_write_int(bs, tts->trustedDuration, 32);			}		}	}	return GF_OK;}static GF_IPMPX_Data *NewGF_IPMPX_SecureContainer(){	GF_IPMPX_SecureContainer *ptr;	GF_IPMPX_DATA_ALLOC(ptr, GF_IPMPX_SecureContainer, GF_IPMPX_SECURE_CONTAINER_TAG);	return (GF_IPMPX_Data *) ptr;}static void DelGF_IPMPX_SecureContainer(GF_IPMPX_Data *_p){	GF_IPMPX_SecureContainer *p = (GF_IPMPX_SecureContainer *)_p;	GF_IPMPX_DELETE_ARRAY(p->encryptedData);	GF_IPMPX_DELETE_ARRAY(p->MAC);	gf_ipmpx_data_del(p->protectedMsg);	free(p);}static GF_Err ReadGF_IPMPX_SecureContainer(GF_BitStream *bs, GF_IPMPX_Data *_p, u32 size){	Bool has_enc, has_mac;	GF_IPMPX_SecureContainer *p = (GF_IPMPX_SecureContainer *)_p;	has_enc = gf_bs_read_int(bs, 1);	has_mac = gf_bs_read_int(bs, 1);	p->isMACEncrypted = gf_bs_read_int(bs, 1);	gf_bs_read_int(bs, 5);	if (has_enc) {		p->encryptedData = GF_IPMPX_GetByteArray(bs);		if (has_mac && !p->isMACEncrypted) p->MAC = GF_IPMPX_GetByteArray(bs);	} else {		GF_Err e = gf_ipmpx_data_parse(bs, &p->protectedMsg);		if (e) return e;		if (has_mac) p->MAC = GF_IPMPX_GetByteArray(bs);	}	return GF_OK;}static u32 SizeGF_IPMPX_SecureContainer(GF_IPMPX_Data *_p){	u32 size = 1;	GF_IPMPX_SecureContainer *p = (GF_IPMPX_SecureContainer *)_p;	if (p->MAC) p->isMACEncrypted = 0;	if (p->encryptedData) {		size += GF_IPMPX_GetByteArraySize(p->encryptedData);		if (p->MAC) size += GF_IPMPX_GetByteArraySize(p->MAC);	} else {		size += gf_ipmpx_data_full_size(p->protectedMsg);		if (p->MAC) size += GF_IPMPX_GetByteArraySize(p->MAC);	}	return size;}static GF_Err WriteGF_IPMPX_SecureContainer(GF_BitStream *bs, GF_IPMPX_Data *_p){	GF_IPMPX_SecureContainer *p = (GF_IPMPX_SecureContainer *)_p;	if (p->MAC) p->isMACEncrypted = 0;	gf_bs_write_int(bs, p->encryptedData ? 1 : 0, 1);	gf_bs_write_int(bs, (p->MAC || p->isMACEncrypted) ? 1 : 0, 1);	gf_bs_write_int(bs, p->isMACEncrypted, 1);	gf_bs_write_int(bs, 0, 5);	if (p->encryptedData) {		GF_IPMPX_WriteByteArray(bs, p->encryptedData);		if (p->MAC) GF_IPMPX_WriteByteArray(bs, p->MAC);	} else {		GF_Err e = gf_ipmpx_data_write(bs, p->protectedMsg);		if (e) return e;		if (p->MAC) GF_IPMPX_WriteByteArray(bs, p->MAC);	}	return GF_OK;}static GF_IPMPX_Data *NewGF_IPMPX_GetToolsResponse(){	GF_IPMPX_GetToolsResponse *ptr;	GF_IPMPX_DATA_ALLOC(ptr, GF_IPMPX_GetToolsResponse, GF_IPMPX_GET_TOOLS_RESPONSE_TAG);	ptr->ipmp_tools = gf_list_new();	return (GF_IPMPX_Data *) ptr;}static void DelGF_IPMPX_GetToolsResponse(GF_IPMPX_Data *_p){	GF_IPMPX_GetToolsResponse *p = (GF_IPMPX_GetToolsResponse *)_p;	while (gf_list_count(p->ipmp_tools)) {		/*IPMPTools are descriptors*/		GF_Descriptor *d = (GF_Descriptor *)gf_list_get(p->ipmp_tools, 0);		gf_list_rem(p->ipmp_tools, 0);		gf_odf_desc_del((GF_Descriptor*)d);	}	gf_list_del(p->ipmp_tools);	free(p);}static GF_Err ReadGF_IPMPX_GetToolsResponse(GF_BitStream *bs, GF_IPMPX_Data *_p, u32 size){	u32 NbBytes = 0;	GF_IPMPX_GetToolsResponse *p = (GF_IPMPX_GetToolsResponse *)_p;	while (size>NbBytes) {		u32 desc_size, start_o;		GF_Descriptor *desc;		GF_Err e;		start_o = (u32) gf_bs_get_position(bs);		e = gf_odf_parse_descriptor(bs, &desc, &desc_size);		if (e) return e;		gf_list_add(p->ipmp_tools, desc);		NbBytes += (u32) gf_bs_get_position(bs) - start_o;	}	if (size<NbBytes) return GF_NON_COMPLIANT_BITSTREAM;	return GF_OK;}static u32 SizeGF_IPMPX_GetToolsResponse(GF_IPMPX_Data *_p){	u32 size = 0;	GF_IPMPX_GetToolsResponse *p = (GF_IPMPX_GetToolsResponse *)_p;	gf_odf_size_descriptor_list(p->ipmp_tools, &size);	return size;}static GF_Err WriteGF_IPMPX_GetToolsResponse(GF_BitStream *bs, GF_IPMPX_Data *_p){	u32 i;	GF_IPMPX_GetToolsResponse *p = (GF_IPMPX_GetToolsResponse *)_p;	for (i=0; i<gf_list_count(p->ipmp_tools); i++) {		GF_Descriptor *desc = (GF_Descriptor *)gf_list_get(p->ipmp_tools, i);		gf_odf_write_descriptor(bs, desc);	}	return GF_OK;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -