Пример #1
0
BIO *BIO_new_accept(const char *str)
{
    BIO *ret;

    ret = BIO_new(BIO_s_accept());
    if (ret == NULL)
        return (NULL);
    if (BIO_set_accept_port(ret, str))
        return (ret);
    else {
        BIO_free(ret);
        return (NULL);
    }
}
Пример #2
0
int main(int argc, char *argv[])
{
    SSL_library_init();
    SSL_load_error_strings();
    
    SSL * new_ssl;
    SSL_CTX * new_ctx;
    
    new_ctx = dh_setup_ctx();
    
    BIO * acc, * client;
    char port[sizeof(argv[1])] = "";  
    int check = 0;
    long port_num;
    parse_port(argc,argv,port);
    acc = BIO_new_accept("1300");
    port_num = BIO_set_accept_port(acc,port);
    if ( !acc )
    { 
	printf("%s \n", "Error in new bio accept");
	return -1;
    }
    if ( BIO_do_accept(acc) <= 0)
    {
	printf("%s \n", "Error in do accept" );
	return -1;
    }
    int get = 0;
    while ( 1 )
    {
	if( BIO_do_accept(acc) <= 0 )
	{
	    printf("%s \n", "Error in accepting connections");
	    return -1;
	}
	client = BIO_pop(acc);
	if ( !(new_ssl = SSL_new(new_ctx)))
	{
	    printf("%s \n", "Error in creating new SSL");
	    return -1;
	}
	SSL_set_bio(new_ssl,client,client);
	if( SSL_accept(new_ssl) <= 0 )
	{
	    get = SSL_get_error(new_ssl,get);
	    printf("%s \n", "Error in accepting SSL connection");
	    printf("%d \n", get);
	    printf("%s \n",ERR_error_string(get,NULL)); 
	    return -1;
	}
	int buf[256] = { 0 };
	int count = 0;
	if ( SSL_read(new_ssl,buf,sizeof(buf)) > 0)
	{
	    /*get = SSL_get_error(new_ssl,get);
	    printf("%d \n", get);
	    printf("%s \n",ERR_error_string(get,NULL)); 
*/
	    while( (char)buf[count] != EOF )
	    {
		printf("%c" , (char)buf[count]);
		count++;
	    }
	}
	SSL_shutdown(new_ssl);
	SSL_free(new_ssl);
    }
    SSL_CTX_free(new_ctx);
    BIO_free(acc);
    return 0;
}