Ejemplo n.º 1
0
Archivo: sms.c Proyecto: AndriusA/ofono
static DBusMessage *sms_get_messages(DBusConnection *conn, DBusMessage *msg,
					void *data)
{
	struct ofono_sms *sms = data;
	DBusMessage *reply;
	DBusMessageIter iter;
	DBusMessageIter array;
	DBusMessageIter entry, dict;
	const char *path;
	GHashTableIter hashiter;
	gpointer key, value;
	struct message *m;
	const struct ofono_uuid *uuid;

	reply = dbus_message_new_method_return(msg);
	if (reply == NULL)
		return NULL;

	dbus_message_iter_init_append(reply, &iter);

	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
					DBUS_STRUCT_BEGIN_CHAR_AS_STRING
					DBUS_TYPE_OBJECT_PATH_AS_STRING
					DBUS_TYPE_ARRAY_AS_STRING
					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
					DBUS_TYPE_STRING_AS_STRING
					DBUS_TYPE_VARIANT_AS_STRING
					DBUS_DICT_ENTRY_END_CHAR_AS_STRING
					DBUS_STRUCT_END_CHAR_AS_STRING,
					&array);

	g_hash_table_iter_init(&hashiter, sms->messages);

	while (g_hash_table_iter_next(&hashiter, &key, &value)) {
		m = value;
		uuid = message_get_uuid(m);

		path = __ofono_sms_message_path_from_uuid(sms, uuid);

		dbus_message_iter_open_container(&array, DBUS_TYPE_STRUCT,
							NULL, &entry);
		dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
						&path);
		dbus_message_iter_open_container(&entry, DBUS_TYPE_ARRAY,
					OFONO_PROPERTIES_ARRAY_SIGNATURE,
					&dict);

		message_append_properties(m, &dict);
		dbus_message_iter_close_container(&entry, &dict);
		dbus_message_iter_close_container(&array, &entry);
	}

	dbus_message_iter_close_container(&iter, &array);

	return reply;
}
Ejemplo n.º 2
0
int key_manage2_start(void * sub_proc,void * para)
{
	int ret;
	int retval;
	void * recv_msg;
	void * send_msg;
	void * context;
	int i;
	int type;
	int subtype;
	void * sock;	
	BYTE uuid[DIGEST_SIZE];

	char local_uuid[DIGEST_SIZE];
	char proc_name[DIGEST_SIZE];
	
	ret=proc_share_data_getvalue("uuid",local_uuid);
	ret=proc_share_data_getvalue("proc_name",proc_name);

	// build a  slot for key request info
	void * slot_port=slot_port_init("key_request",2);
	slot_port_addrecordpin(slot_port,DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO);
	slot_port_addmessagepin(slot_port,DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY);
	slot_port_addmessagepin(slot_port,DTYPE_TESI_KEY_STRUCT,SUBTYPE_PUBLIC_KEY);
	ex_module_addslot(sub_proc,slot_port);


	printf("begin tpm key manage1 start!\n");

	for(i=0;i<300*1000;i++)
	{
		usleep(time_val.tv_usec);
		ret=ex_module_recvmsg(sub_proc,&recv_msg);
		if(ret<0)
			continue;
		if(recv_msg==NULL)
			continue;

 		type=message_get_type(recv_msg);
		subtype=message_get_subtype(recv_msg);
		
		if((type==DTYPE_TRUST_DEMO)&&(subtype==SUBTYPE_KEY_INFO))
		{
			proc_key_check(sub_proc,recv_msg);
		}
		else if(((type==DTYPE_TESI_KEY_STRUCT)&&(subtype==SUBTYPE_WRAPPED_KEY))
			||((type==DTYPE_TESI_KEY_STRUCT)&&(subtype==SUBTYPE_PUBLIC_KEY)))
		{
			ret=message_get_uuid(recv_msg,uuid);						
			if(ret<0)
				continue;
			sock=ex_module_findsock(sub_proc,uuid);
			if(sock==NULL)
				continue;	
			ret=slot_sock_addmsg(sock,recv_msg);
	
			if(ret>0)	
				proc_key_store(sub_proc,sock);
		}
		else if((type==DTYPE_TRUST_DEMO)&&(subtype==SUBTYPE_FILECRYPT_INFO))
		{
			proc_key_recover(sub_proc,recv_msg);	
		}
	}

	return 0;
};
Ejemplo n.º 3
0
int proc_key_check(void * sub_proc,void * recv_msg)
{
	int ret=0;
	int i=0;
	struct trust_demo_keyinfo * keyinfo;
	struct trust_demo_keyinfo * comp_keyinfo;
	struct vTPM_wrappedkey    * key_struct;	
	void * send_msg;
	BYTE uuid[DIGEST_SIZE];
	DB_RECORD * keyinfo_record;
	DB_RECORD * key_record;

	// build a slot_port
	void * slot_port=ex_module_findport(sub_proc,"key_request");
	if(slot_port==NULL)
		return -EINVAL;
	ret=message_get_uuid(recv_msg,uuid);						
	if(ret<0)
		return ret;
	// build a sock
	void * sock=slot_create_sock(slot_port,uuid);

	// get message
	ret=message_get_record(recv_msg,&keyinfo,0);
	if(keyinfo!=NULL)
	{
		keyinfo_record=find_key_info(keyinfo);
		if(keyinfo_record!=NULL)
		{
			comp_keyinfo=keyinfo_record->record;
			key_record=memdb_find_first(DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY,"uuid",comp_keyinfo->uuid);
			if(key_record!=NULL)
				key_struct=key_record->record;		
			ret=slot_sock_addrecorddata(sock,DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO,comp_keyinfo);
			if(ret<0)
				return ret;
			ex_module_addsock(sub_proc,sock);		
		}
		
		else
		{
			// build a slot sock to store the (DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO) keyinfo record and wait for the
			// (DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY) message
			// build (DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY) message and send it
			key_struct=Talloc0(sizeof(*key_struct));
			if(key_struct==NULL)
				return -ENOMEM;
			Memcpy(key_struct->vtpm_uuid,keyinfo->vtpm_uuid,DIGEST_SIZE); 
			key_struct->key_type=keyinfo->key_type; 
			key_struct->key_size=1024;
			key_struct->keypass=dup_str(keyinfo->passwd,DIGEST_SIZE);
			ret=slot_sock_addrecorddata(sock,DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO,keyinfo);
			if(ret<0)
				return ret;
			ex_module_addsock(sub_proc,sock);		
		}

		send_msg=message_create(DTYPE_TESI_KEY_STRUCT,SUBTYPE_WRAPPED_KEY,recv_msg);
		if(send_msg==NULL)
			return -EINVAL;
		message_add_record(send_msg,key_struct);
		ex_module_sendmsg(sub_proc,send_msg);	
	}	

	return ret;
}