Example #1
0
int  main(int argc, char const *argv[])
{
	if(!argv[1])
	{
		printf("no file\n");
		return 0;
	}
	FILE *fp;
	if((fp=fopen(argv[1],"r"))==NULL)
	{
		printf("error in open file %s\n",argv[1]);
	}
	load_buffer(fp);
	int i=0;
	while(buffer[pointer]!=EOF)
	{
		printf("%d %c\n",i++,buffer[pointer]);
		pointer++;
		if (pointer==100)
		{
			load_buffer(fp);
			pointer=0;
		}
	}
	fclose(fp);
	return 0;
}
Example #2
0
void generate_ext4_image(struct image_data *image)
{
    int fd;
    struct stat st;

#ifdef USE_MINGW
    /* Ideally we should use tmpfile() here, the same as with unix version.
     * But unfortunately it is not portable as it is not clear whether this
     * function opens file in TEXT or BINARY mode.
     *
     * There are also some reports it is buggy:
     *    http://pdplab.it.uom.gr/teaching/gcc_manuals/gnulib.html#tmpfile
     *    http://www.mega-nerd.com/erikd/Blog/Windiots/tmpfile.html
     */
    char *filename = tempnam(getenv("TEMP"), "fastboot-format.img");
    fd = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0644);
    unlink(filename);
#else
    fd = fileno(tmpfile());
#endif
    make_ext4fs_sparse_fd(fd, image->partition_size, NULL, NULL);

    fstat(fd, &st);
    image->image_size = st.st_size;
    image->buffer = load_buffer(fd, st.st_size);

    close(fd);
}
variable flux_load_buffer(opts o,interpreter *i)
{
    variable v=init_variable();
    int buf=0;
    char *str;
    if (i->cast_int(&buf,o,0) && i->cast_string(&str,o,1))
	load_buffer(str,buf);
    return v;
}
void SSR::TCP_connection::read_message(int* wait_in_msec)
{
    bool load_buffer_successful = true;
    new_message_available = false;
    int tmp_index = buffer_index;

    /**
     * Clear the content of the string stream as described:
     * m.str(std::string()) -> is technically more efficient,
     * because you avoid invoking the "std::string" constructor that takes
     * "const char*"
     *
     * http://stackoverflow.com/questions/20731/in-c-how-do-you-clear-a-stringstream-variable
     **/
    ss->str(std::string());

    do {

        if (tmp_index == incoming_message_buffer.size()) {
            load_buffer_successful = load_buffer(wait_in_msec);
            tmp_index = 0x00;
        }

        if (load_buffer_successful) {

            while (tmp_index < incoming_message_buffer.size() && !new_message_available) {

                if (incoming_message_buffer[tmp_index] != end_of_message && incoming_message_buffer[tmp_index] != 0x04) {
                    (*ss) << incoming_message_buffer[tmp_index];
                    tmp_index++;
                } else {

                    if (incoming_message_buffer[tmp_index] == 0x04) {
                        tmp_index = incoming_message_buffer.size();
                        new_message_available = false;
                    } else {
                        new_message_available = true;
                        tmp_index++;
                    }


                }

            }

        }

    } while (load_buffer_successful && !new_message_available);

    if (!new_message_available) {
        tmp_index = incoming_message_buffer.size();
    }

    buffer_index = tmp_index;

}
Example #5
0
bool CScriptStorage::do_file	(LPCSTR caScriptName, LPCSTR caNameSpaceName)
{
	int				start = lua_gettop(lua());
	string_path		l_caLuaFileName;
	IReader			*l_tpFileReader = FS.r_open(caScriptName);
	if (!l_tpFileReader) {
		script_log	(eLuaMessageTypeError,"Cannot open file \"%s\"",caScriptName);
		return		(false);
	}
	strconcat		(sizeof(l_caLuaFileName),l_caLuaFileName,"@",caScriptName);
	
	if (!load_buffer(lua(),static_cast<LPCSTR>(l_tpFileReader->pointer()),(size_t)l_tpFileReader->length(),l_caLuaFileName,caNameSpaceName)) {
//		VERIFY		(lua_gettop(lua()) >= 4);
//		lua_pop		(lua(),4);
//		VERIFY		(lua_gettop(lua()) == start - 3);
		lua_settop	(lua(),start);
		FS.r_close	(l_tpFileReader);
		return		(false);
	}
	FS.r_close		(l_tpFileReader);

	int errFuncId = -1;
#ifdef USE_DEBUGGER
#	ifndef USE_LUA_STUDIO
		if( ai().script_engine().debugger() )
			errFuncId = ai().script_engine().debugger()->PrepareLua(lua());
#	endif // #ifndef USE_LUA_STUDIO
#endif // #ifdef USE_DEBUGGER
	if (0)	//.
	{
	    for (int i=0; lua_type(lua(), -i-1); i++)
            Msg	("%2d : %s",-i-1,lua_typename(lua(), lua_type(lua(), -i-1)));
	}

	// because that's the first and the only call of the main chunk - there is no point to compile it
//	luaJIT_setmode	(lua(),0,LUAJIT_MODE_ENGINE|LUAJIT_MODE_OFF);						// Oles
	int	l_iErrorCode = lua_pcall(lua(),0,0,(-1==errFuncId)?0:errFuncId);				// new_Andy
//	luaJIT_setmode	(lua(),0,LUAJIT_MODE_ENGINE|LUAJIT_MODE_ON);						// Oles

#ifdef USE_DEBUGGER
#	ifndef USE_LUA_STUDIO
		if( ai().script_engine().debugger() )
			ai().script_engine().debugger()->UnPrepareLua(lua(),errFuncId);
#	endif // #ifndef USE_LUA_STUDIO
#endif // #ifdef USE_DEBUGGER
	if (l_iErrorCode) {
#ifdef DEBUG
		print_output(lua(),caScriptName,l_iErrorCode);
#endif
		on_error	(lua());
		lua_settop	(lua(),start);
		return		(false);
	}

	return			(true);
}
Example #6
0
EASYRPG_SHARED_PTR<ALAudio::buffer> ALAudio::getSound(std::string const& file) {
	buffer_cache::iterator i = sound_pool_.find(file);
	if(i == sound_pool_.end() || i->second.expired()) {
		EASYRPG_SHARED_PTR<buffer> const ret = load_buffer(FileFinder::FindSound(file));
		sound_pool_[file] = ret;
		return ret;
	} else {
		return i->second.lock();
	}
}
Example #7
0
static GeglRectangle
get_bounding_box (GeglOperation *operation)
{
  GeglProperties   *o = GEGL_PROPERTIES (operation);
  GeglRectangle result = {0,0,0,0};

  load_buffer (o);

  result.width  = gegl_buffer_get_width (GEGL_BUFFER (o->user_data));
  result.height = gegl_buffer_get_height (GEGL_BUFFER (o->user_data));
  return result;
}
Example #8
0
void generate_ext4_image(struct image_data *image)
{
    int fd;
    struct stat st;

    fd = fileno(tmpfile());
    make_ext4fs_sparse_fd(fd, image->partition_size, NULL, NULL);

    fstat(fd, &st);
    image->image_size = st.st_size;
    image->buffer = load_buffer(fd, st.st_size);

    close(fd);
}
Example #9
0
static GeglRectangle
get_bounding_box (GeglOperation *operation)
{
  GeglRectangle result = {0,0,0,0};
  GeglChantO   *o = GEGL_CHANT_PROPERTIES (operation);

  load_buffer (o);

  if (o->chant_data)
    {
      result.width  = gegl_buffer_get_width  (GEGL_BUFFER (o->chant_data));
      result.height = gegl_buffer_get_height (GEGL_BUFFER (o->chant_data));
    }

  return result;
}
Example #10
0
int rpexpose_select(){
	g.status=S_STARTUP;
	g.x.display = XOpenDisplay(getenv("DISPLAY"));

	load_rcdefaults();
	load_rcfile();
	load_input();
	load_xwindow();
	load_buffer();

	atexit(clean_up);

	// And here is when the magic is supposed to happen...
	
	XMapWindow(g.x.display,g.x.window);

	g.status=S_RUNNING;

	XEvent e;
	for(;;){
		XNextEvent(g.x.display, &e);
		switch(e.type){
		case MapNotify:
			XGrabKeyboard(g.x.display,g.x.window,False,GrabModeSync,GrabModeAsync,CurrentTime);
			break;
		case KeyPress:{
			KeySym keysym=XKeycodeToKeysym(g.x.display,e.xkey.keycode,0);
			if( keysym<256 && isdigit(keysym) ){
				if( g.p.selected->children[keysym-'0'] ){
					g.p.selected=g.p.selected->children[keysym-'0'];
					event_move(g.p.selected->window);
				}
				break;
			}
			KeyCode keycode=XKeysymToKeycode(g.x.display,keysym);
			parse_command(g.rc.keybindings[keycode]);
			break;
		}
		case Expose:
			event_redraw(e.xexpose.x,e.xexpose.y,e.xexpose.width,e.xexpose.height);
			event_move(g.gui.selected);
		}
	}
	return 0;
}
Example #11
0
static gboolean
process (GeglOperation         *operation,
         GeglOperationContext  *context,
         const gchar           *output_pad,
         const GeglRectangle   *result,
         gint                   level)
{
  GeglProperties *o = GEGL_PROPERTIES (operation);
  GeglBuffer     *output;

  load_buffer (o);
  g_assert (o->user_data);
  g_assert (g_str_equal (output_pad, "output"));

  output = GEGL_BUFFER (o->user_data);
  g_object_ref (output);
  gegl_operation_context_take_object (context, "output", G_OBJECT (output));
  return TRUE;
}
Example #12
0
static EEL_object *eel_load_buffer_nc(EEL_vm *vm,
		const char *source, unsigned len, EEL_sflags flags)
{
	EEL_state *es = VMP->state;
	EEL_value v;
	EEL_object *m;
	EEL_xno x = eel_o_construct(es->vm, EEL_CMODULE, NULL, 0, &v);
	if(x)
		return NULL;
	m = v.objref.v;
	eel_try(es)
		load_buffer(vm, o2EEL_module(m), source, len);
	eel_except
	{
		eel_o_disown_nz(m);
		return NULL;
	}
	return m;
}
Example #13
0
int main(int argc, char **argv)
{


	if (argc <= 1) 
		cmdline_help();

	init_windows();
	init_buffers();

	for (argv++; *argv != NULL ; argv++) 
		current_buf = load_buffer(*argv);
		

	paint_buffer(current_buf);
	statusprintf("%s", current_buf->name);

	refresh();
	input_loop();

}
Example #14
0
BOOL				load_dir(char *path, t_elst **entries, BOOL all)
{
    DIR				*dirp;
    struct dirent	*dire;
    t_elst			*last;
    t_elst			*entry;

    last = NULL;
    load_buffer(path);
    if (!(dirp = opendir(path)))
    {
        print_error(path);
        return (FALSE);
    }
    while ((dire = readdir(dirp)))
        if (all || dire->d_name[0] != '.')
            if ((entry = new_entry(ft_strjoin(g_buffer, dire->d_name), FALSE)))
                last = elst_add(entries, last, entry);
    closedir(dirp);
    free(dire);
    return (TRUE);
}
Example #15
0
/****************************************************************
*																*
*					cherche une chaŒne 							*
*																*
****************************************************************/
void search_secteur(windowptr thewin, boolean diff_majmin, boolean start_to_end)
{
	char *buffer, *buffer_frontiere;
	OBJECT *search = Dialog[WAIT].tree;
	int taille, start;
	long secteur = thewin -> fonction.secteur.secteur, max = thewin -> fonction.secteur.max;
	int width, i;
	char *secteur_text;
	char pattern[SEARCH_PATTERN_SIZE];
	long offset;
	int size_buff_sect;
	int dummy;

#ifndef TEST_VERSION
	if (thewin -> fonction.secteur.dirty && write_secteur(thewin, MENU_DEPLACEMENT))
			return;
#endif

	thewin -> fonction.secteur.dirty = FALSE;

	/* attend la fin des redessins */
	Event_Timer(0, 0, TRUE);

	search[WAIT_MESSAGE].ob_spec.free_string = Messages(SEARCH_2);
	search[WAIT_INFO].ob_spec.tedinfo -> te_ptext = Messages(REORG_14);

	width = search[SLIDE_PERE].ob_width -3;
	search[SLIDE_FILS].ob_width = (int)((long)width * secteur / max) +3;

	secteur_text = search[INDICATEUR_WAIT].ob_spec.tedinfo -> te_ptext;
	sprintf(secteur_text, "%ld", secteur);
	sprintf(search[MAX_WAIT].ob_spec.free_string, "/%ld", max);

	my_open_dialog(&Dialog[WAIT], AUTO_DIAL|NO_ICONIFY|MODAL, FAIL);

	/* attend la fin des redessins */
	Event_Timer(0, 0, TRUE);

	/* allocation des buffers, on d‚passe un peu … cause de l'approximation de la taille dans and_buffer() */
	buffer = malloc(20L+ 512L * (thewin -> fonction.secteur.device < 2 ? SIZEBUFFLOP : SIZEBUFHARD));
	if (buffer == NULL)
	{
		error_msg(Z_NOT_ENOUGH_MEMORY);
		return;
	}

	if ((buffer_frontiere = malloc(20L+ SEARCH_PATTERN_SIZE*2L + 16L)) == NULL)
	{
		free(buffer);
		error_msg(Z_NOT_ENOUGH_MEMORY);
		return;
	}
	/* mise … z‚ro */
	memset(buffer_frontiere, 0, 20L+ SEARCH_PATTERN_SIZE*2L + 16L);

	/* pr‚pare le pattern */
	if (diff_majmin)
		for (i=0; i<SearchLength; i++)
			pattern[i] = SearchString[i];
	else
		for (i=0; i<SearchLength; i++)
			pattern[i] = SearchString[i] & ~('a'-'A');

	/* octet de d‚part */
	start = thewin -> fonction.secteur.curseur_x < 0 ? thewin -> fonction.secteur.page *512 : thewin -> fonction.secteur.page *512 + thewin -> fonction.secteur.curseur_y*32 + thewin -> fonction.secteur.curseur_x/2 +1;

	/* recherche d'abord dans le secteur en m‚moire */
	memcpy(buffer, thewin -> fonction.secteur.secteurBin, thewin -> fonction.secteur.sector_size*512L);
	if ((offset = search_pattern(buffer + start, thewin -> fonction.secteur.sector_size*512L - start, pattern, diff_majmin, start_to_end)) >= 0)
	{
		my_close_dialog(&Dialog[WAIT]);
		free(buffer_frontiere);
		free(buffer);
		search_found(thewin, secteur, offset + start);
		return;
	}

	/* remplis de n'importe quoi sauf du motif recherch‚ */
	memset(buffer_frontiere, SearchString[0] ^ 0xAA, (long)SEARCH_PATTERN_SIZE);

	/* nombre max de secteurs … lire */
	size_buff_sect = (thewin -> fonction.secteur.device < 2 ? SIZEBUFFLOP : SIZEBUFHARD) / thewin -> fonction.secteur.sector_size;

	/* taille du bloc … lire */
	if (max - secteur > (long)size_buff_sect)
		taille = size_buff_sect;
	else
		taille = (int)(max - secteur);

	while (taille > 0)
	{
		/* charge le buffer */
		if ((taille = load_buffer(thewin, buffer, secteur, taille, start_to_end)) < 0)
		{	/* erreur */
			my_close_dialog(&Dialog[WAIT]);
			free(buffer);
			return;
		}

		/* recherche sur la frontiŠre */
		memcpy(buffer_frontiere + SEARCH_PATTERN_SIZE, buffer, (long)SEARCH_PATTERN_SIZE);
		if ((offset = search_pattern(buffer_frontiere, SEARCH_PATTERN_SIZE, pattern, diff_majmin, start_to_end)) >= 0)
		{
			my_close_dialog(&Dialog[WAIT]);
			free(buffer_frontiere);
			free(buffer);
			search_found(thewin, secteur-taille, offset + (thewin -> fonction.secteur.device < 2 ? SIZEBUFFLOP*512L - SEARCH_PATTERN_SIZE : SIZEBUFHARD*512L - SEARCH_PATTERN_SIZE));
			return;
		}

		/* recherche en cours */
		if ((offset = search_pattern(buffer+start, taille * thewin -> fonction.secteur.sector_size * 512L - start, pattern, diff_majmin, start_to_end)) >= 0)
		{
			my_close_dialog(&Dialog[WAIT]);
			free(buffer_frontiere);
			free(buffer);
			search_found(thewin, secteur, offset+start);
			return;
		}

		/* on n'a un d‚calage que la premiŠre fois */
		start = 0;

		/* copie la fin du bloc pour la frontiŠre */
		memcpy(buffer_frontiere, buffer + (thewin -> fonction.secteur.device < 2 ? SIZEBUFFLOP*512L - SEARCH_PATTERN_SIZE : SIZEBUFHARD*512L - SEARCH_PATTERN_SIZE), (long)SEARCH_PATTERN_SIZE);

		/* on avance */
		secteur += taille;

		/* taille du bloc … lire */
		if (max - secteur > (long)size_buff_sect)
			taille = size_buff_sect;
		else
			taille = (int)(max - secteur);

		/* test les boutons */
		if (evnt_multi(MU_TIMER | MU_BUTTON,
		 256+1, 3, 0,	/* button */
		 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* mouse */
		 NULL,	/* message */
		 1, 0,	/* timer */
		 &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) == MU_BUTTON
		 && my_alert(1, 2, X_ICN_QUESTION, Messages(SEARCH_3), Messages(BOOT_32)) == 0)
		{	/* on n'a pas trouv‚ mais on s'arrˆte */
			my_close_dialog(&Dialog[WAIT]);
			free(buffer_frontiere);
			free(buffer);
			search_found(thewin, secteur, -1L);
			return;
		}

		/* met … jour la barre */
		search[SLIDE_FILS].ob_width = (int)((long)width * secteur / max) +3;
		ob_draw(Dialog[WAIT].info, SLIDE_FILS);

		/* met … jour le compteur */
		sprintf(secteur_text, "%ld", secteur);
		ob_draw(Dialog[WAIT].info, INDICATEUR_WAIT);

		/* attend la fin des redessins */
		Event_Timer(0, 0, TRUE);
	}

	free(buffer_frontiere);
	free(buffer);

	my_close_dialog(&Dialog[WAIT]);

	/* un petit bruit */
	if (Sound)
		Cconout(7);
} /* search_secteur */
Example #16
0
void client_test(void* args)
{
    SOCKET_T sockfd = 0;

    SSL_METHOD*  method  = 0;
    SSL_CTX*     ctx     = 0;
    SSL*         ssl     = 0;
    
#ifdef TEST_RESUME
    SSL*         sslResume = 0;
    SSL_SESSION* session = 0;
    char         resumeMsg[] = "resuming cyassl!";
    int          resumeSz    = sizeof(resumeMsg);
#endif

    char msg[64] = "hello cyassl!";
    char reply[1024];
    int  input;
    int  msgSz = strlen(msg);

    int     argc = ((func_args*)args)->argc;
    char**  argv = ((func_args*)args)->argv;

    ((func_args*)args)->return_code = -1; /* error state */

#if defined(CYASSL_DTLS)
    method  = DTLSv1_client_method();
#elif  !defined(NO_TLS)
    method  = SSLv23_client_method();
#else
    method  = SSLv3_client_method();
#endif
    ctx     = SSL_CTX_new(method);

#ifndef NO_PSK
    SSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
#endif

#ifdef OPENSSL_EXTRA
    SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
#endif

#ifdef CYASSL_SNIFFER
    /* don't use EDH, can't sniff tmp keys */
    SSL_CTX_set_cipher_list(ctx, "AES256-SHA");
#endif

#ifndef NO_FILESYSTEM
    if (SSL_CTX_load_verify_locations(ctx, caCert, 0) != SSL_SUCCESS)
        err_sys("can't load ca file");
    #ifdef HAVE_ECC
        if (SSL_CTX_load_verify_locations(ctx, eccCert, 0) != SSL_SUCCESS)
            err_sys("can't load ca file");
    #endif
#else
    load_buffer(ctx, caCert, CYASSL_CA);
#endif

#ifdef VERIFY_CALLBACK
    SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
#endif

    if (argc == 3) {
        /*  ./client server securePort  */
        SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);  /* TODO: add ca cert */
                    /* this is just to allow easy testing of other servers */
        tcp_connect(&sockfd, argv[1], (short)atoi(argv[2]));
    }
    else if (argc == 1) {
        /* ./client          // plain mode */
        /* for client cert authentication if server requests */
#ifndef NO_FILESYSTEM
        if (SSL_CTX_use_certificate_file(ctx, cliCert, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load client cert file");

        if (SSL_CTX_use_PrivateKey_file(ctx, cliKey, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load client key file");
#else
        load_buffer(ctx, cliCert, CYASSL_CERT);
        load_buffer(ctx, cliKey, CYASSL_KEY);
#endif

        tcp_connect(&sockfd, yasslIP, yasslPort);
    }
    else if (argc == 2) {
        /* time passed in number of connects give average */
        int times = atoi(argv[1]);
        int i = 0;

        double start = current_time(), avg;

        for (i = 0; i < times; i++) {
            tcp_connect(&sockfd, yasslIP, yasslPort);
            ssl = SSL_new(ctx);
            SSL_set_fd(ssl, sockfd);
            if (SSL_connect(ssl) != SSL_SUCCESS)
                err_sys("SSL_connect failed");

            SSL_shutdown(ssl);
            SSL_free(ssl);
            CloseSocket(sockfd);
        }
        avg = current_time() - start;
        avg /= times;
        avg *= 1000;    /* milliseconds */  
        printf("SSL_connect avg took:%6.3f milliseconds\n", avg);

        SSL_CTX_free(ctx);
        ((func_args*)args)->return_code = 0;
        return;
    }
    else
        err_sys("usage: ./client server securePort");

    ssl = SSL_new(ctx);
    SSL_set_fd(ssl, sockfd);
    if (argc != 3)
        CyaSSL_check_domain_name(ssl, "www.yassl.com");
#ifdef NON_BLOCKING
    tcp_set_nonblocking(&sockfd);
    NonBlockingSSL_Connect(ssl);
#else
    #ifndef CYASSL_CALLBACKS
        if (SSL_connect(ssl) != SSL_SUCCESS) { /* see note at top of README */
            int  err = SSL_get_error(ssl, 0);
            char buffer[80];
            printf("err = %d, %s\n", err, ERR_error_string(err, buffer));
            err_sys("SSL_connect failed");/* if you're getting an error here  */
        }
    #else
        timeout.tv_sec  = 2;
        timeout.tv_usec = 0;
        NonBlockingSSL_Connect(ssl);  /* will keep retrying on timeout */
    #endif
#endif
    showPeer(ssl);
    
    if (argc == 3) {
        printf("SSL connect ok, sending GET...\n");
        msgSz = 28;
        strncpy(msg, "GET /index.html HTTP/1.0\r\n\r\n", msgSz);
    }
    if (SSL_write(ssl, msg, msgSz) != msgSz)
        err_sys("SSL_write failed");

    input = SSL_read(ssl, reply, sizeof(reply));
    if (input > 0) {
        reply[input] = 0;
        printf("Server response: %s\n", reply);

        if (argc == 3) {  /* get html */
            while (1) {
                input = SSL_read(ssl, reply, sizeof(reply));
                if (input > 0) {
                    reply[input] = 0;
                    printf("%s\n", reply);
                }
                else
                    break;
            }
        }
    }
  
#ifdef TEST_RESUME
    #ifdef CYASSL_DTLS
        strncpy(msg, "break", 6);
        msgSz = (int)strlen(msg);
        /* try to send session close */
        SSL_write(ssl, msg, msgSz);
    #endif
    session   = SSL_get_session(ssl);
    sslResume = SSL_new(ctx);
#endif

    SSL_shutdown(ssl);
    SSL_free(ssl);
    CloseSocket(sockfd);

#ifdef TEST_RESUME
    #ifdef CYASSL_DTLS
        #ifdef USE_WINDOWS_API 
            Sleep(500);
        #else
            sleep(1);
        #endif
    #endif
    if (argc == 3)
        tcp_connect(&sockfd, argv[1], (short)atoi(argv[2]));
    else
        tcp_connect(&sockfd, yasslIP, yasslPort);
    SSL_set_fd(sslResume, sockfd);
    SSL_set_session(sslResume, session);
   
    showPeer(sslResume); 
    if (SSL_connect(sslResume) != SSL_SUCCESS) err_sys("SSL resume failed");

#ifdef OPENSSL_EXTRA
    if (SSL_session_reused(sslResume))
        printf("reused session id\n");
    else
        printf("didn't reuse session id!!!\n");
#endif
  
    if (SSL_write(sslResume, resumeMsg, resumeSz) != resumeSz)
        err_sys("SSL_write failed");

    input = SSL_read(sslResume, reply, sizeof(reply));
    if (input > 0) {
        reply[input] = 0;
        printf("Server resume response: %s\n", reply);
    }

    /* try to send session break */
    SSL_write(sslResume, msg, msgSz); 

    SSL_shutdown(sslResume);
    SSL_free(sslResume);
#endif /* TEST_RESUME */

    SSL_CTX_free(ctx);
    CloseSocket(sockfd);

    ((func_args*)args)->return_code = 0;
}
Example #17
0
THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
{
    SOCKET_T       sockfd = 0;
    CYASSL_METHOD* method = 0;
    CYASSL_CTX*    ctx    = 0;

    int    doDTLS = 0;
    int    doPSK = 0;
    int    outCreated = 0;
    int    shutDown = 0;
    int    useAnyAddr = 0;
    word16 port = yasslPort;
    int    argc = ((func_args*)args)->argc;
    char** argv = ((func_args*)args)->argv;

#ifdef ECHO_OUT
    FILE* fout = stdout;
    if (argc >= 2) {
        fout = fopen(argv[1], "w");
        outCreated = 1;
    }
    if (!fout) err_sys("can't open output file");
#endif
    (void)outCreated;
    (void)argc;
    (void)argv;

    ((func_args*)args)->return_code = -1; /* error state */

#ifdef CYASSL_DTLS
    doDTLS  = 1;
#endif

#ifdef CYASSL_LEANPSK
    doPSK = 1;
#endif

#if defined(NO_RSA) && !defined(HAVE_ECC)
    doPSK = 1;
#endif

    #if defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API) && \
                      !defined(CYASSL_SNIFFER) && !defined(CYASSL_MDK_ARM)
        port = 0;
    #endif
    #if defined(USE_ANY_ADDR)
        useAnyAddr = 1;
    #endif
    tcp_listen(&sockfd, &port, useAnyAddr, doDTLS);

#if defined(CYASSL_DTLS)
    method  = CyaDTLSv1_server_method();
#elif  !defined(NO_TLS)
    method = CyaSSLv23_server_method();
#else
    method = CyaSSLv3_server_method();
#endif
    ctx    = CyaSSL_CTX_new(method);
    /* CyaSSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF); */

#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
    CyaSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
#endif

#ifndef NO_FILESYSTEM
    if (doPSK == 0) {
    #ifdef HAVE_NTRU
        /* ntru */
        if (CyaSSL_CTX_use_certificate_file(ctx, ntruCert, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load ntru cert file, "
                    "Please run from CyaSSL home dir");

        if (CyaSSL_CTX_use_NTRUPrivateKey_file(ctx, ntruKey)
                != SSL_SUCCESS)
            err_sys("can't load ntru key file, "
                    "Please run from CyaSSL home dir");
    #elif defined(HAVE_ECC)
        /* ecc */
        if (CyaSSL_CTX_use_certificate_file(ctx, eccCert, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load server cert file, "
                    "Please run from CyaSSL home dir");

        if (CyaSSL_CTX_use_PrivateKey_file(ctx, eccKey, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load server key file, "
                    "Please run from CyaSSL home dir");
    #elif defined(NO_CERTS)
        /* do nothing, just don't load cert files */
    #else
        /* normal */
        if (CyaSSL_CTX_use_certificate_file(ctx, svrCert, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load server cert file, "
                    "Please run from CyaSSL home dir");

        if (CyaSSL_CTX_use_PrivateKey_file(ctx, svrKey, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load server key file, "
                    "Please run from CyaSSL home dir");
    #endif
    } /* doPSK */
#elif !defined(NO_CERTS)
    if (!doPSK) {
        load_buffer(ctx, svrCert, CYASSL_CERT);
        load_buffer(ctx, svrKey,  CYASSL_KEY);
    }
#endif

#if defined(CYASSL_SNIFFER) && !defined(HAVE_NTRU) && !defined(HAVE_ECC)
    /* don't use EDH, can't sniff tmp keys */
    CyaSSL_CTX_set_cipher_list(ctx, "AES256-SHA");
#endif

    if (doPSK) {
#ifndef NO_PSK
        const char *defaultCipherList;

        CyaSSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
        CyaSSL_CTX_use_psk_identity_hint(ctx, "cyassl server");
        #ifdef HAVE_NULL_CIPHER
            defaultCipherList = "PSK-NULL-SHA256";
        #else
            defaultCipherList = "PSK-AES128-CBC-SHA256";
        #endif
        if (CyaSSL_CTX_set_cipher_list(ctx, defaultCipherList) != SSL_SUCCESS)
            err_sys("server can't set cipher list 2");
#endif
    }

    SignalReady(args, port);

    while (!shutDown) {
        CYASSL* ssl = 0;
        char    command[SVR_COMMAND_SIZE+1];
        int     echoSz = 0;
        int     clientfd;
        int     firstRead = 1;
        int     gotFirstG = 0;
                
#ifndef CYASSL_DTLS 
        SOCKADDR_IN_T client;
        socklen_t     client_len = sizeof(client);
        clientfd = accept(sockfd, (struct sockaddr*)&client,
                         (ACCEPT_THIRD_T)&client_len);
#else
        clientfd = udp_read_connect(sockfd);
#endif
        if (clientfd == -1) err_sys("tcp accept failed");

        ssl = CyaSSL_new(ctx);
        if (ssl == NULL) err_sys("SSL_new failed");
        CyaSSL_set_fd(ssl, clientfd);
        #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
            CyaSSL_SetTmpDH_file(ssl, dhParam, SSL_FILETYPE_PEM);
        #elif !defined(NO_DH)
            SetDH(ssl);  /* will repick suites with DHE, higher than PSK */
        #endif
        if (CyaSSL_accept(ssl) != SSL_SUCCESS) {
            printf("SSL_accept failed\n");
            CyaSSL_free(ssl);
            CloseSocket(clientfd);
            continue;
        }
#if defined(PEER_INFO)
        showPeer(ssl);
#endif

        while ( (echoSz = CyaSSL_read(ssl, command, sizeof(command)-1)) > 0) {

            if (firstRead == 1) {
                firstRead = 0;  /* browser may send 1 byte 'G' to start */
                if (echoSz == 1 && command[0] == 'G') {
                    gotFirstG = 1;
                    continue;
                }
            }
            else if (gotFirstG == 1 && strncmp(command, "ET /", 4) == 0) {
                strncpy(command, "GET", 4);
                /* fall through to normal GET */
            }
           
            if ( strncmp(command, "quit", 4) == 0) {
                printf("client sent quit command: shutting down!\n");
                shutDown = 1;
                break;
            }
            if ( strncmp(command, "break", 5) == 0) {
                printf("client sent break command: closing session!\n");
                break;
            }
#ifdef SESSION_STATS
            if ( strncmp(command, "printstats", 10) == 0) {
                PrintSessionStats();
                break;
            }
#endif
            if ( strncmp(command, "GET", 3) == 0) {
                char type[]   = "HTTP/1.0 200 ok\r\nContent-type:"
                                " text/html\r\n\r\n";
                char header[] = "<html><body BGCOLOR=\"#ffffff\">\n<pre>\n";
                char body[]   = "greetings from CyaSSL\n";
                char footer[] = "</body></html>\r\n\r\n";
            
                strncpy(command, type, sizeof(type));
                echoSz = sizeof(type) - 1;

                strncpy(&command[echoSz], header, sizeof(header));
                echoSz += (int)sizeof(header) - 1;
                strncpy(&command[echoSz], body, sizeof(body));
                echoSz += (int)sizeof(body) - 1;
                strncpy(&command[echoSz], footer, sizeof(footer));
                echoSz += (int)sizeof(footer);

                if (CyaSSL_write(ssl, command, echoSz) != echoSz)
                    err_sys("SSL_write failed");
                break;
            }
            command[echoSz] = 0;

            #ifdef ECHO_OUT
                fputs(command, fout);
            #endif

            if (CyaSSL_write(ssl, command, echoSz) != echoSz)
                err_sys("SSL_write failed");
        }
#ifndef CYASSL_DTLS
        CyaSSL_shutdown(ssl);
#endif
        CyaSSL_free(ssl);
        CloseSocket(clientfd);
#ifdef CYASSL_DTLS
        tcp_listen(&sockfd, &port, useAnyAddr, doDTLS);
        SignalReady(args, port);
#endif
    }

    CloseSocket(sockfd);
    CyaSSL_CTX_free(ctx);

#ifdef ECHO_OUT
    if (outCreated)
        fclose(fout);
#endif

    ((func_args*)args)->return_code = 0;
    return 0;
}
Example #18
0
THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
{
    SOCKET_T       sockfd = 0;
    CYASSL_METHOD* method = 0;
    CYASSL_CTX*    ctx    = 0;

    int    ret = 0;
    int    doDTLS = 0;
    int    doPSK = 0;
    int    outCreated = 0;
    int    shutDown = 0;
    int    useAnyAddr = 0;
    word16 port;
    int    argc = ((func_args*)args)->argc;
    char** argv = ((func_args*)args)->argv;

#ifdef ECHO_OUT
    FILE* fout = stdout;
    if (argc >= 2) {
        fout = fopen(argv[1], "w");
        outCreated = 1;
    }
    if (!fout) err_sys("can't open output file");
#endif
    (void)outCreated;
    (void)argc;
    (void)argv;

    ((func_args*)args)->return_code = -1; /* error state */

#ifdef CYASSL_DTLS
    doDTLS  = 1;
#endif

#ifdef CYASSL_LEANPSK
    doPSK = 1;
#endif

#if defined(NO_RSA) && !defined(HAVE_ECC)
    doPSK = 1;
#endif

#if defined(NO_MAIN_DRIVER) && !defined(CYASSL_SNIFFER) && \
     !defined(WOLFSSL_MDK_SHELL) && !defined(CYASSL_TIRTOS) && \
     !defined(USE_WINDOWS_API)
    /* Let tcp_listen assign port */
    port = 0;
#else
    /* Use default port */
    port = wolfSSLPort;
#endif

#if defined(USE_ANY_ADDR)
    useAnyAddr = 1;
#endif

#ifdef CYASSL_TIRTOS
    fdOpenSession(Task_self());
#endif

    tcp_listen(&sockfd, &port, useAnyAddr, doDTLS, 0);

#if defined(CYASSL_DTLS)
    method  = CyaDTLSv1_2_server_method();
#elif  !defined(NO_TLS)
    method = CyaSSLv23_server_method();
#elif defined(WOLFSSL_ALLOW_SSLV3)
    method = CyaSSLv3_server_method();
#else
    #error "no valid server method built in"
#endif
    ctx    = CyaSSL_CTX_new(method);
    /* CyaSSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF); */

#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
    CyaSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
#endif

#if defined(HAVE_SESSION_TICKET) && defined(HAVE_CHACHA) && \
                                    defined(HAVE_POLY1305)
    if (TicketInit() != 0)
        err_sys("unable to setup Session Ticket Key context");
    wolfSSL_CTX_set_TicketEncCb(ctx, myTicketEncCb);
#endif

#ifndef NO_FILESYSTEM
    if (doPSK == 0) {
    #if defined(HAVE_NTRU) && defined(WOLFSSL_STATIC_RSA)
        /* ntru */
        if (CyaSSL_CTX_use_certificate_file(ctx, ntruCertFile, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load ntru cert file, "
                    "Please run from wolfSSL home dir");

        if (CyaSSL_CTX_use_NTRUPrivateKey_file(ctx, ntruKeyFile)
                != SSL_SUCCESS)
            err_sys("can't load ntru key file, "
                    "Please run from wolfSSL home dir");
    #elif defined(HAVE_ECC) && !defined(CYASSL_SNIFFER)
        /* ecc */
        if (CyaSSL_CTX_use_certificate_file(ctx, eccCertFile, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load server cert file, "
                    "Please run from wolfSSL home dir");

        if (CyaSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load server key file, "
                    "Please run from wolfSSL home dir");
    #elif defined(NO_CERTS)
        /* do nothing, just don't load cert files */
    #else
        /* normal */
        if (CyaSSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load server cert file, "
                    "Please run from wolfSSL home dir");

        if (CyaSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM)
                != SSL_SUCCESS)
            err_sys("can't load server key file, "
                    "Please run from wolfSSL home dir");
    #endif
    } /* doPSK */
#elif !defined(NO_CERTS)
    if (!doPSK) {
        load_buffer(ctx, svrCertFile, WOLFSSL_CERT);
        load_buffer(ctx, svrKeyFile,  WOLFSSL_KEY);
    }
#endif

#if defined(CYASSL_SNIFFER)
    /* don't use EDH, can't sniff tmp keys */
    CyaSSL_CTX_set_cipher_list(ctx, "AES256-SHA");
#endif

    if (doPSK) {
#ifndef NO_PSK
        const char *defaultCipherList;

        CyaSSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
        CyaSSL_CTX_use_psk_identity_hint(ctx, "cyassl server");
        #ifdef HAVE_NULL_CIPHER
            defaultCipherList = "PSK-NULL-SHA256";
        #elif defined(HAVE_AESGCM) && !defined(NO_DH)
            defaultCipherList = "DHE-PSK-AES128-GCM-SHA256";
        #else
            defaultCipherList = "PSK-AES128-CBC-SHA256";
        #endif
        if (CyaSSL_CTX_set_cipher_list(ctx, defaultCipherList) != SSL_SUCCESS)
            err_sys("server can't set cipher list 2");
#endif
    }

#ifdef WOLFSSL_ASYNC_CRYPT
    ret = wolfAsync_DevOpen(&devId);
    if (ret != 0) {
        err_sys("Async device open failed");
    }
    wolfSSL_CTX_UseAsync(ctx, devId);
#endif /* WOLFSSL_ASYNC_CRYPT */

    SignalReady(args, port);

    while (!shutDown) {
        CYASSL* ssl = NULL;
        CYASSL* write_ssl = NULL;   /* may have separate w/ HAVE_WRITE_DUP */
        char    command[SVR_COMMAND_SIZE+1];
        int     echoSz = 0;
        int     clientfd;
        int     firstRead = 1;
        int     gotFirstG = 0;
        int     err = 0;
        SOCKADDR_IN_T client;
        socklen_t     client_len = sizeof(client);
#ifndef CYASSL_DTLS
        clientfd = accept(sockfd, (struct sockaddr*)&client,
                         (ACCEPT_THIRD_T)&client_len);
#else
        clientfd = sockfd;
        {
            /* For DTLS, peek at the next datagram so we can get the client's
             * address and set it into the ssl object later to generate the
             * cookie. */
            int n;
            byte b[1500];
            n = (int)recvfrom(clientfd, (char*)b, sizeof(b), MSG_PEEK,
                              (struct sockaddr*)&client, &client_len);
            if (n <= 0)
                err_sys("recvfrom failed");
        }
#endif
        if (WOLFSSL_SOCKET_IS_INVALID(clientfd)) err_sys("tcp accept failed");

        ssl = CyaSSL_new(ctx);
        if (ssl == NULL) err_sys("SSL_new failed");
        CyaSSL_set_fd(ssl, clientfd);
        #ifdef CYASSL_DTLS
            wolfSSL_dtls_set_peer(ssl, &client, client_len);
        #endif
        #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && !defined(NO_ASN)
            CyaSSL_SetTmpDH_file(ssl, dhParamFile, SSL_FILETYPE_PEM);
        #elif !defined(NO_DH)
            SetDH(ssl);  /* will repick suites with DHE, higher than PSK */
        #endif

        do {
#ifdef WOLFSSL_ASYNC_CRYPT
            if (err == WC_PENDING_E) {
                ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
                if (ret < 0) { break; } else if (ret == 0) { continue; }
            }
#endif
            err = 0; /* Reset error */
            ret = CyaSSL_accept(ssl);
            if (ret != SSL_SUCCESS) {
                err = CyaSSL_get_error(ssl, 0);
            }
        } while (ret != SSL_SUCCESS && err == WC_PENDING_E);

        if (ret != SSL_SUCCESS) {
            char buffer[CYASSL_MAX_ERROR_SZ];
            err = CyaSSL_get_error(ssl, 0);
            printf("error = %d, %s\n", err, CyaSSL_ERR_error_string(err, buffer));
            printf("SSL_accept failed\n");
            CyaSSL_free(ssl);
            CloseSocket(clientfd);
            continue;
        }
#if defined(PEER_INFO)
        showPeer(ssl);
#endif

#ifdef HAVE_WRITE_DUP
        write_ssl = wolfSSL_write_dup(ssl);
        if (write_ssl == NULL) {
            printf("wolfSSL_write_dup failed\n");
            CyaSSL_free(ssl);
            CloseSocket(clientfd);
            continue;
        }
#else
        write_ssl = ssl;
#endif

        while ( (echoSz = CyaSSL_read(ssl, command, sizeof(command)-1)) > 0) {

            if (firstRead == 1) {
                firstRead = 0;  /* browser may send 1 byte 'G' to start */
                if (echoSz == 1 && command[0] == 'G') {
                    gotFirstG = 1;
                    continue;
                }
            }
            else if (gotFirstG == 1 && strncmp(command, "ET /", 4) == 0) {
                strncpy(command, "GET", 4);
                /* fall through to normal GET */
            }
           
            if ( strncmp(command, "quit", 4) == 0) {
                printf("client sent quit command: shutting down!\n");
                shutDown = 1;
                break;
            }
            if ( strncmp(command, "break", 5) == 0) {
                printf("client sent break command: closing session!\n");
                break;
            }
#ifdef PRINT_SESSION_STATS
            if ( strncmp(command, "printstats", 10) == 0) {
                CyaSSL_PrintSessionStats();
                break;
            }
#endif
            if ( strncmp(command, "GET", 3) == 0) {
                char type[]   = "HTTP/1.0 200 ok\r\nContent-type:"
                                " text/html\r\n\r\n";
                char header[] = "<html><body BGCOLOR=\"#ffffff\">\n<pre>\n";
                char body[]   = "greetings from wolfSSL\n";
                char footer[] = "</body></html>\r\n\r\n";
            
                strncpy(command, type, sizeof(type));
                echoSz = sizeof(type) - 1;

                strncpy(&command[echoSz], header, sizeof(header));
                echoSz += (int)sizeof(header) - 1;
                strncpy(&command[echoSz], body, sizeof(body));
                echoSz += (int)sizeof(body) - 1;
                strncpy(&command[echoSz], footer, sizeof(footer));
                echoSz += (int)sizeof(footer);

                if (CyaSSL_write(write_ssl, command, echoSz) != echoSz)
                    err_sys("SSL_write failed");
                break;
            }
            command[echoSz] = 0;

            #ifdef ECHO_OUT
                fputs(command, fout);
            #endif

            if (CyaSSL_write(write_ssl, command, echoSz) != echoSz)
                err_sys("SSL_write failed");
        }
#ifndef CYASSL_DTLS
        CyaSSL_shutdown(ssl);
#endif
#ifdef HAVE_WRITE_DUP
        CyaSSL_free(write_ssl);
#endif
        CyaSSL_free(ssl);
        CloseSocket(clientfd);
#ifdef CYASSL_DTLS
        tcp_listen(&sockfd, &port, useAnyAddr, doDTLS, 0);
        SignalReady(args, port);
#endif
    }

    CloseSocket(sockfd);
    CyaSSL_CTX_free(ctx);

#ifdef ECHO_OUT
    if (outCreated)
        fclose(fout);
#endif

    ((func_args*)args)->return_code = 0;

#if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
                            && defined(HAVE_THREAD_LS)
    ecc_fp_free();  /* free per thread cache */
#endif

#ifdef CYASSL_TIRTOS
    fdCloseSession(Task_self());
#endif

#if defined(HAVE_SESSION_TICKET) && defined(HAVE_CHACHA) && \
                                    defined(HAVE_POLY1305)
    TicketCleanup();
#endif

#ifdef WOLFSSL_ASYNC_CRYPT
    wolfAsync_DevClose(&devId);
#endif

#ifndef CYASSL_TIRTOS
    return 0;
#endif
}
Example #19
0
static bool load(RBinFile *bf) {
	r_return_val_if_fail (bf && bf->o, false);

	bf->o->bin_obj = load_buffer (bf, bf->buf, bf->o->loadaddr, bf->sdb);
	return bf->o->bin_obj != NULL;
}
void Kinect2Manager::LoadBuffers() {

    load_buffer("dump/depth_rgbx.bin", m_pDepthRGBX, sizeof(RGBQUAD), CAPTURE_SIZE_X_DEPTH * CAPTURE_SIZE_Y_DEPTH);
    load_buffer("dump/depth.bin", m_pDepth, sizeof(USHORT), CAPTURE_SIZE_X_DEPTH * CAPTURE_SIZE_Y_DEPTH);
    load_buffer("dump/color_rgbx.bin", m_pColorRGBX, sizeof(RGBQUAD), CAPTURE_SIZE_X_COLOR * CAPTURE_SIZE_Y_COLOR);
    load_buffer("dump/color_depth_map.bin", m_pColorDepthMap, sizeof(DepthSpacePoint), CAPTURE_SIZE_X_COLOR * CAPTURE_SIZE_Y_COLOR);
    load_buffer("dump/depth_color_map_rgbx.bin", m_pDepthColorMap, sizeof(ColorSpacePoint), CAPTURE_SIZE_X_DEPTH * CAPTURE_SIZE_Y_DEPTH);
    load_buffer("dump/depth_x_mapped_to_color.bin", m_pDepthXMappedToColor, sizeof(int), CAPTURE_SIZE_X_COLOR * CAPTURE_SIZE_Y_COLOR);
    load_buffer("dump/depth_y_mapped_to_color.bin", m_pDepthYMappedToColor, sizeof(int), CAPTURE_SIZE_X_COLOR * CAPTURE_SIZE_Y_COLOR);
    load_buffer("dump/depth_mapped_to_color.bin", m_pDepthMappedToColor, sizeof(USHORT), CAPTURE_SIZE_X_COLOR * CAPTURE_SIZE_Y_COLOR);
    load_buffer("dump/color_x_mapped_to_depth.bin", m_pColorXMappedToDepth, sizeof(int), CAPTURE_SIZE_X_DEPTH * CAPTURE_SIZE_Y_DEPTH);
    load_buffer("dump/color_y_mapped_to_depth.bin", m_pColorYMappedToDepth, sizeof(int), CAPTURE_SIZE_X_DEPTH * CAPTURE_SIZE_Y_DEPTH);
    load_buffer("dump/color_mapped_to_depth.bin", m_pColorMappedToDepth, sizeof(RGBQUAD), CAPTURE_SIZE_X_DEPTH * CAPTURE_SIZE_Y_DEPTH);
    load_buffer("dump/body_index.bin", m_pBodyIndex, sizeof(unsigned char), CAPTURE_SIZE_X_DEPTH * CAPTURE_SIZE_Y_DEPTH);
    load_buffer("dump/joints.bin", m_pJoints, sizeof(Joint), JointType_Count);
    load_buffer("dump/joint_orientations.bin", m_pJointOrientations, sizeof(JointOrientation), JointType_Count);
    load_buffer("dump/best_body_index.bin", &m_nBodyIndex, sizeof(UCHAR), 1);

}
Example #21
0
void echoclient_test(void* args)
{
    SOCKET_T sockfd = 0;

    FILE* fin   = stdin  ;
    FILE* fout = stdout;

    int inCreated  = 0;
    int outCreated = 0;

    char msg[1024];
    char reply[1024+1];

    SSL_METHOD* method = 0;
    SSL_CTX*    ctx    = 0;
    SSL*        ssl    = 0;

    int doDTLS = 0;
    int doPSK = 0;
    int sendSz;
    int argc    = 0;
    char** argv = 0;
    word16 port = yasslPort;

    ((func_args*)args)->return_code = -1; /* error state */
    
#ifndef WOLFSSL_MDK_SHELL
    argc = ((func_args*)args)->argc;
    argv = ((func_args*)args)->argv;
#endif

    if (argc >= 2) {
        fin  = fopen(argv[1], "r"); 
        inCreated = 1;
    }
    if (argc >= 3) {
        fout = fopen(argv[2], "w");
        outCreated = 1;
    }

    if (!fin)  err_sys("can't open input file");
    if (!fout) err_sys("can't open output file");

#ifdef CYASSL_DTLS
    doDTLS  = 1;
#endif

#ifdef CYASSL_LEANPSK 
    doPSK = 1;
#endif

#if defined(NO_RSA) && !defined(HAVE_ECC)
    doPSK = 1;
#endif

#if defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API) && !defined(WOLFSSL_MDK_SHELL)
    port = ((func_args*)args)->signal->port;
#endif

#if defined(CYASSL_DTLS)
    method  = DTLSv1_2_client_method();
#elif  !defined(NO_TLS)
    method = CyaSSLv23_client_method();
#elif defined(WOLFSSL_ALLOW_SSLV3)
    method = SSLv3_client_method();
#else
    #error "no valid client method type"
#endif
    ctx    = SSL_CTX_new(method);

#ifndef NO_FILESYSTEM
    #ifndef NO_RSA
    if (SSL_CTX_load_verify_locations(ctx, caCert, 0) != SSL_SUCCESS)
        err_sys("can't load ca file, Please run from wolfSSL home dir");
    #endif
    #ifdef HAVE_ECC
        if (SSL_CTX_load_verify_locations(ctx, eccCert, 0) != SSL_SUCCESS)
            err_sys("can't load ca file, Please run from wolfSSL home dir");
    #endif
#elif !defined(NO_CERTS)
    if (!doPSK)
        load_buffer(ctx, caCert, CYASSL_CA);
#endif

#if defined(CYASSL_SNIFFER)
    /* don't use EDH, can't sniff tmp keys */
    SSL_CTX_set_cipher_list(ctx, "AES256-SHA");
#endif
    if (doPSK) {
#ifndef NO_PSK
        const char *defaultCipherList;

        CyaSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
        #ifdef HAVE_NULL_CIPHER
            defaultCipherList = "PSK-NULL-SHA256";
        #elif defined(HAVE_AESGCM) && !defined(NO_DH)
            defaultCipherList = "DHE-PSK-AES128-GCM-SHA256";
        #else
            defaultCipherList = "PSK-AES128-CBC-SHA256";
        #endif
        if (CyaSSL_CTX_set_cipher_list(ctx,defaultCipherList) !=SSL_SUCCESS)
            err_sys("client can't set cipher list 2");
#endif
    }

#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
    SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
#endif

    #if defined(WOLFSSL_MDK_ARM)
    CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
    #endif

    ssl = SSL_new(ctx);
    tcp_connect(&sockfd, yasslIP, port, doDTLS, ssl);
        
    SSL_set_fd(ssl, sockfd);
#if defined(USE_WINDOWS_API) && defined(CYASSL_DTLS) && defined(NO_MAIN_DRIVER)
    /* let echoserver bind first, TODO: add Windows signal like pthreads does */
    Sleep(100);
#endif

    if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");

    while (fgets(msg, sizeof(msg), fin) != 0) {
     
        sendSz = (int)strlen(msg);

        if (SSL_write(ssl, msg, sendSz) != sendSz)
            err_sys("SSL_write failed");

        if (strncmp(msg, "quit", 4) == 0) {
            fputs("sending server shutdown command: quit!\n", fout);
            break;
        }

        if (strncmp(msg, "break", 5) == 0) {
            fputs("sending server session close: break!\n", fout);
            break;
        }

        #ifndef WOLFSSL_MDK_SHELL
        while (sendSz) {
            int got;
            if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
                reply[got] = 0;
                fputs(reply, fout);
                fflush(fout) ;
                sendSz -= got;
            }
            else
                break;
        }
        #else
        {
            int got;
            if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
                reply[got] = 0;
                fputs(reply, fout);
                fflush(fout) ;
                sendSz -= got;
            }
        }
        #endif
    }


#ifdef CYASSL_DTLS
    strncpy(msg, "break", 6);
    sendSz = (int)strlen(msg);
    /* try to tell server done */
    SSL_write(ssl, msg, sendSz);
#else
    SSL_shutdown(ssl);
#endif

    SSL_free(ssl);
    SSL_CTX_free(ctx);

    fflush(fout);
    if (inCreated)  fclose(fin);
    if (outCreated) fclose(fout);

    CloseSocket(sockfd);
    ((func_args*)args)->return_code = 0; 
}
Example #22
0
void echoclient_test(void* args)
{
    SOCKET_T sockfd = 0;

    FILE* fin  = stdin;
    FILE* fout = stdout;

    int inCreated  = 0;
    int outCreated = 0;

    char send[1024];
    char reply[1024];

    SSL_METHOD* method = 0;
    SSL_CTX*    ctx    = 0;
    SSL*        ssl    = 0;

    int sendSz;
    int argc    = 0;
    char** argv = 0;

    ((func_args*)args)->return_code = -1; /* error state */
    argc = ((func_args*)args)->argc;
    argv = ((func_args*)args)->argv;

    if (argc >= 2) {
        fin  = fopen(argv[1], "r"); 
        inCreated = 1;
    }
    if (argc >= 3) {
        fout = fopen(argv[2], "w");
        outCreated = 1;
    }

    if (!fin)  err_sys("can't open input file");
    if (!fout) err_sys("can't open output file");

    tcp_connect(&sockfd, yasslIP, yasslPort);

#if defined(CYASSL_DTLS)
    method  = DTLSv1_client_method();
#elif  !defined(NO_TLS)
    method = TLSv1_client_method();
#else
    method = SSLv3_client_method();
#endif
    ctx    = SSL_CTX_new(method);

#ifndef NO_FILESYSTEM
    if (SSL_CTX_load_verify_locations(ctx, caCert, 0) != SSL_SUCCESS)
        err_sys("can't load ca file");
    #ifdef HAVE_ECC
        if (SSL_CTX_load_verify_locations(ctx, eccCert, 0) != SSL_SUCCESS)
            err_sys("can't load ca file");
    #endif
#else
    load_buffer(ctx, caCert, CYASSL_CA);
#endif

#ifdef OPENSSL_EXTRA
    SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
#endif
    ssl = SSL_new(ctx);

    SSL_set_fd(ssl, sockfd);
#if defined(USE_WINDOWS_API) && defined(CYASSL_DTLS) && defined(NO_MAIN_DRIVER)
    /* let echoserver bind first, TODO: add Windows signal like pthreads does */
    Sleep(100);
#endif
    if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");

    while (fgets(send, sizeof(send), fin)) {

        sendSz = (int)strlen(send) + 1;

        if (SSL_write(ssl, send, sendSz) != sendSz)
            err_sys("SSL_write failed");

        if (strncmp(send, "quit", 4) == 0) {
            fputs("sending server shutdown command: quit!\n", fout);
            break;
        }

        if (strncmp(send, "break", 4) == 0) {
            fputs("sending server session close: break!\n", fout);
            break;
        }

        while (sendSz) {
            int got;
            if ( (got = SSL_read(ssl, reply, sizeof(reply))) > 0) {
                fputs(reply, fout);
                sendSz -= got;
            }
            else
                break;
        }
    }

#ifdef CYASSL_DTLS
    strncpy(send, "break", 6);
    sendSz = (int)strlen(send);
    /* try to tell server done */
    SSL_write(ssl, send, sendSz);
#else
    SSL_shutdown(ssl);
#endif

    SSL_free(ssl);
    SSL_CTX_free(ctx);

    fflush(fout);
    if (inCreated)  fclose(fin);
    if (outCreated) fclose(fout);

    CloseSocket(sockfd);
    ((func_args*)args)->return_code = 0; 
}
Example #23
0
void echoclient_test(void* args)
{
    SOCKET_T sockfd = 0;

    FILE* fin  = stdin;
    FILE* fout = stdout;

    int inCreated  = 0;
    int outCreated = 0;

    char msg[1024];
    char reply[1024];

    SSL_METHOD* method = 0;
    SSL_CTX*    ctx    = 0;
    SSL*        ssl    = 0;

    int doDTLS = 0;
    int doLeanPSK = 0;
    int sendSz;
    int argc    = 0;
    char** argv = 0;

    ((func_args*)args)->return_code = -1; /* error state */
    argc = ((func_args*)args)->argc;
    argv = ((func_args*)args)->argv;

    if (argc >= 2) {
        fin  = fopen(argv[1], "r"); 
        inCreated = 1;
    }
    if (argc >= 3) {
        fout = fopen(argv[2], "w");
        outCreated = 1;
    }

    if (!fin)  err_sys("can't open input file");
    if (!fout) err_sys("can't open output file");

#ifdef CYASSL_DTLS
    doDTLS  = 1;
#endif

#ifdef CYASSL_LEANPSK 
    doLeanPSK = 1;
#endif

#if defined(CYASSL_DTLS)
    method  = DTLSv1_client_method();
#elif  !defined(NO_TLS)
    method = CyaSSLv23_client_method();
#else
    method = SSLv3_client_method();
#endif
    ctx    = SSL_CTX_new(method);

#ifndef NO_FILESYSTEM
    if (SSL_CTX_load_verify_locations(ctx, caCert, 0) != SSL_SUCCESS)
        err_sys("can't load ca file, Please run from CyaSSL home dir");
    #ifdef HAVE_ECC
        if (SSL_CTX_load_verify_locations(ctx, eccCert, 0) != SSL_SUCCESS)
            err_sys("can't load ca file, Please run from CyaSSL home dir");
    #endif
#elif !defined(NO_CERTS)
    if (!doLeanPSK)
        load_buffer(ctx, caCert, CYASSL_CA);
#endif

#if defined(CYASSL_SNIFFER) && !defined(HAVE_NTRU) && !defined(HAVE_ECC)
    /* don't use EDH, can't sniff tmp keys */
    SSL_CTX_set_cipher_list(ctx, "AES256-SHA");
#endif
    if (doLeanPSK) {
#ifdef CYASSL_LEANPSK
        CyaSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
        SSL_CTX_set_cipher_list(ctx, "PSK-NULL-SHA");
#endif
    }

#ifdef OPENSSL_EXTRA
    SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
#endif
    ssl = SSL_new(ctx);

    if (doDTLS) {
        SOCKADDR_IN_T addr;
        build_addr(&addr, yasslIP, yasslPort);
        CyaSSL_dtls_set_peer(ssl, &addr, sizeof(addr));
        tcp_socket(&sockfd, 1);
    }
    else {
        tcp_connect(&sockfd, yasslIP, yasslPort, 0);
    }

    SSL_set_fd(ssl, sockfd);
#if defined(USE_WINDOWS_API) && defined(CYASSL_DTLS) && defined(NO_MAIN_DRIVER)
    /* let echoserver bind first, TODO: add Windows signal like pthreads does */
    Sleep(100);
#endif
    if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");

    while (fgets(msg, sizeof(msg), fin)) {

        sendSz = (int)strlen(msg);

        if (SSL_write(ssl, msg, sendSz) != sendSz)
            err_sys("SSL_write failed");

        if (strncmp(msg, "quit", 4) == 0) {
            fputs("sending server shutdown command: quit!\n", fout);
            break;
        }

        if (strncmp(msg, "break", 5) == 0) {
            fputs("sending server session close: break!\n", fout);
            break;
        }

        while (sendSz) {
            int got;
            if ( (got = SSL_read(ssl, reply, sizeof(reply))) > 0) {
                reply[got] = 0;
                fputs(reply, fout);
                sendSz -= got;
            }
            else
                break;
        }
    }

#ifdef CYASSL_DTLS
    strncpy(msg, "break", 6);
    sendSz = (int)strlen(msg);
    /* try to tell server done */
    SSL_write(ssl, msg, sendSz);
#else
    SSL_shutdown(ssl);
#endif

    SSL_free(ssl);
    SSL_CTX_free(ctx);

    fflush(fout);
    if (inCreated)  fclose(fin);
    if (outCreated) fclose(fout);

    CloseSocket(sockfd);
    ((func_args*)args)->return_code = 0; 
}
Example #24
0
int main(int argc , char *argv[])
{


    int r_bytes;
    char user_input[STDIN_BUFFER_SIZE];
    char* arg1 = NULL;
    char* arg2 = NULL;
	int cmd;

	
    init_client("127.0.0.1", 8888);

    maxfd = 0;
    client_connection_id = 0;
    
    while (run){

        FD_ZERO(&fds);

    	if (logged)
        	FD_SET(client_connection_id, &fds); //al establecer conexion tengo que hacerlo.
        
    
        FD_SET(0, &fds); //stdin
        select(maxfd+1, &fds, NULL, NULL, NULL);

        if (FD_ISSET(0, &fds)){
      
   			fgets(user_input, STDIN_BUFFER_SIZE, stdin);
   			
   			if (*user_input == '\n')
				continue;

   			
			cmd = parse_cmd(user_input, &arg1, &arg2);

            switch(cmd) {
				
				case CMD_CHAT:
					write_talk(user_input);
					break;
				case CMD_LOGIN:
					write_login(arg1, arg2, DEFAULT_COLOR);
					break;
				case CMD_REGISTER:
					write_register(arg1, arg2);
					break;
				case CMD_LOGOUT:
					write_disconnect();
					break;
				case CMD_CH_PW:
					write_change_pw(arg1);
					break;
				case CMD_CH_PRIVS:
					write_change_privileges(arg1, (unsigned char)(*arg2 - '0'));
					break;
				case CMD_CH_COLOR:
					write_change_color((unsigned char)(*arg1 - '0'));
					break;
				case CMD_DELETE_USER:
					write_delete();
					break;
				case CMD_KICK:
					write_kick(arg1, arg2);
					break;
				case CMD_BAN:
					write_ban(arg1, arg2);
					break;
				case CMD_GET_ONLINE_USERS:
					write_get_online_users();
					break;
				case CMD_HELP:
					show_help();
					break;
				case CMD_ERROR:
					fprintf(stderr, "Comando no reconocido. Escriba /help para ver la lista de comandos...\n");
					break;				
			}
			

			if (arg1 != NULL){
				free(arg1);
			}


			if (arg2 != NULL){
				free(arg2);
			}
			

			arg1 = arg2 = NULL;
        }
        

        
        if (logged && FD_ISSET(client_connection_id, &fds)){

  
            r_bytes = load_buffer(client_connection_id, client_recv_buffer);

            while (client_recv_buffer->pos + 1 < r_bytes){
                handle_tcp_packets();
                
                client_recv_buffer->pos+=1;
            }

            clean_buffer(client_recv_buffer);
        }
    }

    deinit_client();
     
    return 0;
}