forked from KolibriOS/kolibrios
mbedtls:
- is now a native dynamic library (ms coff) - removed unnecessary files. - updated ssl_client1 example git-svn-id: svn://kolibrios.org@9076 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
qemu-system-i386 -m 256 -fda ../../test_kos_images/kolibri.img -boot a -vga vmware -net nic,model=rtl8139 -net user -soundhw ac97 -usb -usbdevice tablet -drive file=fat:rw:.
|
||||
@@ -1,24 +1,12 @@
|
||||
NEWLIB_INCLUDES=D:\KOSSDK\newlib\libc\include
|
||||
APP_DYNAMIC_LDS=D:\KOSSDK\newlib/app-dynamic.lds
|
||||
LIBDIR=D:\KOSSDK\kos32-msys-5.4.0\win32\lib
|
||||
MAIN_TARGET=ssl_client1
|
||||
FASM = fasm
|
||||
TCC_DIR = /home/max/kolibri-svn/programs/develop/ktcc/trunk
|
||||
TCC= $(TCC_DIR)/bin/kos32-tcc
|
||||
|
||||
CC=kos32-gcc
|
||||
LD=kos32-ld
|
||||
OBJCOPY=kos32-objcopy
|
||||
CFLAGS= -I../../include -I$(TCC_DIR)/libc.obj/include -stack=10000
|
||||
|
||||
CCFLAGS=-c -fomit-frame-pointer -I $(NEWLIB_INCLUDES) -I../../include -I../../kosnet/include -Wall -Wextra
|
||||
LDFLAGS=-call_shared -nostdlib --subsystem console -T $(APP_DYNAMIC_LDS) --image-base 0 -L $(LIBDIR) -L ../../kosnet -L ../../library -lmbedtls -lmbedx509 -lmbedcrypto -lkosnet -lgcc -lapp -lc.dll
|
||||
|
||||
all: ssl_client1
|
||||
|
||||
ssl_client1: ssl_client1.o
|
||||
$(LD) ssl_client1.o -o $(MAIN_TARGET) $(LDFLAGS)
|
||||
$(OBJCOPY) $(MAIN_TARGET) -O binary
|
||||
|
||||
ssl_client1.o: ssl_client1.c
|
||||
$(CC) $(CCFLAGS) ssl_client1.c -o ssl_client1.o
|
||||
all:
|
||||
$(FASM) load_mbedtls.asm
|
||||
$(TCC) $(CFLAGS) ssl_client1.c load_mbedtls.o -o ssl_client1 -ltcc -lc.obj
|
||||
|
||||
clean:
|
||||
del *.o
|
||||
del $(MAIN_TARGET)
|
||||
rm -f *.o ssl_client1
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
format elf
|
||||
use32
|
||||
|
||||
section '.text' executable
|
||||
|
||||
include '../../../../../proc32.inc'
|
||||
include '../../../../../macros.inc'
|
||||
purge section,mov,add,sub
|
||||
|
||||
include '../../../../../dll.inc'
|
||||
|
||||
public mbedtls_load
|
||||
public mbedtls_ctr_drbg_free
|
||||
public mbedtls_ctr_drbg_init
|
||||
public mbedtls_ctr_drbg_random
|
||||
public mbedtls_ctr_drbg_seed
|
||||
public mbedtls_debug_set_threshold
|
||||
public mbedtls_entropy_free
|
||||
public mbedtls_entropy_func
|
||||
public mbedtls_entropy_init
|
||||
public mbedtls_net_connect
|
||||
public mbedtls_net_free
|
||||
public mbedtls_net_init
|
||||
public mbedtls_net_recv
|
||||
public mbedtls_net_send
|
||||
public mbedtls_ssl_close_notify
|
||||
public mbedtls_ssl_conf_authmode
|
||||
public mbedtls_ssl_conf_ca_chain
|
||||
public mbedtls_ssl_conf_dbg
|
||||
public mbedtls_ssl_config_defaults
|
||||
public mbedtls_ssl_config_free
|
||||
public mbedtls_ssl_config_init
|
||||
public mbedtls_ssl_conf_rng
|
||||
public mbedtls_ssl_free
|
||||
public mbedtls_ssl_get_verify_result
|
||||
public mbedtls_ssl_handshake
|
||||
public mbedtls_ssl_init
|
||||
public mbedtls_ssl_read
|
||||
public mbedtls_ssl_set_bio
|
||||
public mbedtls_ssl_set_hostname
|
||||
public mbedtls_ssl_setup
|
||||
public mbedtls_ssl_write
|
||||
public mbedtls_strerror
|
||||
public _mbedtls_test_cas_pem
|
||||
public _mbedtls_test_cas_pem_len
|
||||
public mbedtls_x509_crt_free
|
||||
public mbedtls_x509_crt_init
|
||||
public mbedtls_x509_crt_parse
|
||||
public mbedtls_x509_crt_verify_info
|
||||
public mbedtls_init
|
||||
public __snprintf_test
|
||||
|
||||
__snprintf_test:
|
||||
ret
|
||||
|
||||
;;; Returns 0 on success. -1 on failure.
|
||||
|
||||
proc mbedtls_load
|
||||
stdcall dll.Load, @IMPORT
|
||||
test eax, eax
|
||||
jnz error
|
||||
|
||||
mov eax, 0
|
||||
ret
|
||||
|
||||
error:
|
||||
mov eax, -1
|
||||
ret
|
||||
endp
|
||||
|
||||
mbedtls_ctr_drbg_free: jmp [_mbedtls_ctr_drbg_free ]
|
||||
mbedtls_ctr_drbg_init: jmp [_mbedtls_ctr_drbg_init ]
|
||||
mbedtls_ctr_drbg_random: jmp [_mbedtls_ctr_drbg_random ]
|
||||
mbedtls_ctr_drbg_seed: jmp [_mbedtls_ctr_drbg_seed ]
|
||||
mbedtls_debug_set_threshold: jmp [_mbedtls_debug_set_threshold ]
|
||||
mbedtls_entropy_free: jmp [_mbedtls_entropy_free ]
|
||||
mbedtls_entropy_func: jmp [_mbedtls_entropy_func ]
|
||||
mbedtls_entropy_init: jmp [_mbedtls_entropy_init ]
|
||||
mbedtls_net_connect: jmp [_mbedtls_net_connect ]
|
||||
mbedtls_net_free: jmp [_mbedtls_net_free ]
|
||||
mbedtls_net_init: jmp [_mbedtls_net_init ]
|
||||
mbedtls_net_recv: jmp [_mbedtls_net_recv ]
|
||||
mbedtls_net_send: jmp [_mbedtls_net_send ]
|
||||
mbedtls_ssl_close_notify: jmp [_mbedtls_ssl_close_notify ]
|
||||
mbedtls_ssl_conf_authmode: jmp [_mbedtls_ssl_conf_authmode ]
|
||||
mbedtls_ssl_conf_ca_chain: jmp [_mbedtls_ssl_conf_ca_chain ]
|
||||
mbedtls_ssl_conf_dbg: jmp [_mbedtls_ssl_conf_dbg ]
|
||||
mbedtls_ssl_config_defaults: jmp [_mbedtls_ssl_config_defaults ]
|
||||
mbedtls_ssl_config_free: jmp [_mbedtls_ssl_config_free ]
|
||||
mbedtls_ssl_config_init: jmp [_mbedtls_ssl_config_init ]
|
||||
mbedtls_ssl_conf_rng: jmp [_mbedtls_ssl_conf_rng ]
|
||||
mbedtls_ssl_free: jmp [_mbedtls_ssl_free ]
|
||||
mbedtls_ssl_get_verify_result: jmp [_mbedtls_ssl_get_verify_result ]
|
||||
mbedtls_ssl_handshake: jmp [_mbedtls_ssl_handshake ]
|
||||
mbedtls_ssl_init: jmp [_mbedtls_ssl_init ]
|
||||
mbedtls_ssl_read: jmp [_mbedtls_ssl_read ]
|
||||
mbedtls_ssl_set_bio: jmp [_mbedtls_ssl_set_bio ]
|
||||
mbedtls_ssl_set_hostname: jmp [_mbedtls_ssl_set_hostname ]
|
||||
mbedtls_ssl_setup: jmp [_mbedtls_ssl_setup ]
|
||||
mbedtls_ssl_write: jmp [_mbedtls_ssl_write ]
|
||||
mbedtls_strerror: jmp [_mbedtls_strerror]
|
||||
;mbedtls_test_cas_pem: jmp [_mbedtls_test_cas_pem ]
|
||||
;mbedtls_test_cas_pem_len: jmp [_mbedtls_test_cas_pem_len ]
|
||||
mbedtls_x509_crt_free: jmp [_mbedtls_x509_crt_free ]
|
||||
mbedtls_x509_crt_init: jmp [_mbedtls_x509_crt_init ]
|
||||
mbedtls_x509_crt_parse: jmp [_mbedtls_x509_crt_parse]
|
||||
mbedtls_x509_crt_verify_info: jmp [_mbedtls_x509_crt_verify_info ]
|
||||
mbedtls_init: jmp [_mbedtls_init]
|
||||
;__snprintf_test: jmp[___snprintf_test]
|
||||
|
||||
section '.data' writable
|
||||
@IMPORT:
|
||||
library mbedtls, 'mbedtls.obj'
|
||||
import mbedtls, \
|
||||
_mbedtls_init , 'mbedtls_init' ,\
|
||||
_mbedtls_strerror , 'mbedtls_strerror' ,\
|
||||
_mbedtls_test_cas_pem , 'mbedtls_test_cas_pem' ,\
|
||||
_mbedtls_test_cas_pem_len , 'mbedtls_test_cas_pem_len' ,\
|
||||
_mbedtls_x509_crt_free , 'mbedtls_x509_crt_free' ,\
|
||||
_mbedtls_x509_crt_init , 'mbedtls_x509_crt_init' ,\
|
||||
_mbedtls_x509_crt_parse , 'mbedtls_x509_crt_parse' ,\
|
||||
_mbedtls_x509_crt_verify_info , 'mbedtls_x509_crt_verify_info' ,\
|
||||
_mbedtls_ctr_drbg_free , 'mbedtls_ctr_drbg_free' ,\
|
||||
_mbedtls_ctr_drbg_init , 'mbedtls_ctr_drbg_init' ,\
|
||||
_mbedtls_ctr_drbg_random , 'mbedtls_ctr_drbg_random' ,\
|
||||
_mbedtls_ctr_drbg_seed , 'mbedtls_ctr_drbg_seed' ,\
|
||||
_mbedtls_debug_set_threshold , 'mbedtls_debug_set_threshold' ,\
|
||||
_mbedtls_entropy_free , 'mbedtls_entropy_free' ,\
|
||||
_mbedtls_entropy_func , 'mbedtls_entropy_func' ,\
|
||||
_mbedtls_entropy_init , 'mbedtls_entropy_init' ,\
|
||||
_mbedtls_net_connect , 'mbedtls_net_connect' ,\
|
||||
_mbedtls_net_free , 'mbedtls_net_free' ,\
|
||||
_mbedtls_net_init , 'mbedtls_net_init' ,\
|
||||
_mbedtls_net_recv , 'mbedtls_net_recv' ,\
|
||||
_mbedtls_net_send , 'mbedtls_net_send' ,\
|
||||
_mbedtls_ssl_close_notify , 'mbedtls_ssl_close_notify' ,\
|
||||
_mbedtls_ssl_conf_authmode , 'mbedtls_ssl_conf_authmode' ,\
|
||||
_mbedtls_ssl_conf_ca_chain , 'mbedtls_ssl_conf_ca_chain' ,\
|
||||
_mbedtls_ssl_conf_dbg , 'mbedtls_ssl_conf_dbg' ,\
|
||||
_mbedtls_ssl_config_defaults , 'mbedtls_ssl_config_defaults' ,\
|
||||
_mbedtls_ssl_config_free , 'mbedtls_ssl_config_free' ,\
|
||||
_mbedtls_ssl_config_init , 'mbedtls_ssl_config_init' ,\
|
||||
_mbedtls_ssl_conf_rng , 'mbedtls_ssl_conf_rng' ,\
|
||||
_mbedtls_ssl_free , 'mbedtls_ssl_free' ,\
|
||||
_mbedtls_ssl_get_verify_result , 'mbedtls_ssl_get_verify_result' ,\
|
||||
_mbedtls_ssl_handshake , 'mbedtls_ssl_handshake' ,\
|
||||
_mbedtls_ssl_init , 'mbedtls_ssl_init' ,\
|
||||
_mbedtls_ssl_read , 'mbedtls_ssl_read' ,\
|
||||
_mbedtls_ssl_set_bio , 'mbedtls_ssl_set_bio' ,\
|
||||
_mbedtls_ssl_set_hostname , 'mbedtls_ssl_set_hostname' ,\
|
||||
_mbedtls_ssl_setup , 'mbedtls_ssl_setup' ,\
|
||||
_mbedtls_ssl_write , 'mbedtls_ssl_write'
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
qemu-system-i386 -m 256 -fda ../../test_kos_images/kolibri.img -boot a -vga vmware -net nic,model=rtl8139 -net user -soundhw ac97 -usb -usbdevice tablet -drive file=fat:rw:.
|
||||
Binary file not shown.
@@ -20,16 +20,17 @@
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <sys/ksys.h>
|
||||
|
||||
//#if defined(MBEDTLS_PLATFORM_C)
|
||||
//#include "mbedtls/platform.h"
|
||||
//#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_time time
|
||||
@@ -37,16 +38,16 @@
|
||||
#define mbedtls_fprintf fprintf
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_exit exit
|
||||
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
|
||||
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#define MBEDTLS_EXIT_SUCCESS 0
|
||||
#define MBEDTLS_EXIT_FAILURE -1
|
||||
//#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
|
||||
//#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
|
||||
!defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \
|
||||
!defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || \
|
||||
!defined(MBEDTLS_CERTS_C) || !defined(MBEDTLS_PEM_PARSE_C) || \
|
||||
!defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
int main( void )
|
||||
/*int main( void )
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or "
|
||||
"MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or "
|
||||
@@ -55,7 +56,7 @@ int main( void )
|
||||
"not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
//#else*/
|
||||
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/debug.h"
|
||||
@@ -70,12 +71,21 @@ int main( void )
|
||||
//#define SERVER_PORT "443"
|
||||
//#define SERVER_NAME "wikipedia.org"
|
||||
//#define GET_REQUEST "GET / HTTP/1.0\r\n\r\n"
|
||||
char SERVER_PORT[16];
|
||||
char SERVER_NAME[128];
|
||||
char GET_REQUEST[512];
|
||||
static char SERVER_PORT[16];
|
||||
static char SERVER_NAME[128];
|
||||
static char GET_REQUEST[512];
|
||||
|
||||
#define DEBUG_LEVEL 1
|
||||
|
||||
extern int *_mbedtls_test_cas_pem_len;
|
||||
extern char* _mbedtls_test_cas_pem;
|
||||
|
||||
#define mbedtls_test_cas_pem_len *_mbedtls_test_cas_pem_len
|
||||
#define mbedtls_test_cas_pem _mbedtls_test_cas_pem
|
||||
|
||||
//gmtime(time_t t){puts("gmtime stub");};
|
||||
|
||||
//int load_network_obj(){return networklib_init();}
|
||||
|
||||
static void my_debug( void *ctx, int level,
|
||||
const char *file, int line,
|
||||
@@ -90,11 +100,21 @@ static void my_debug( void *ctx, int level,
|
||||
|
||||
int main( void )
|
||||
{
|
||||
if(mbedtls_load()){
|
||||
printf("mbedtls.obj not load!\n");
|
||||
return -1;
|
||||
}
|
||||
if(mbedtls_init()){
|
||||
puts("mbedtls.obj not init!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
puts("Enter SERVER_NAME : ");
|
||||
gets(SERVER_NAME);
|
||||
puts("Enter SERVER_PORT : ");
|
||||
gets(SERVER_PORT);
|
||||
sprintf(GET_REQUEST, "GET / HTTP/1.1\r\nHost: %s\r\n\r\n", SERVER_NAME);
|
||||
//puts(GET_REQUEST);
|
||||
|
||||
int ret = 1, len;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
@@ -102,7 +122,6 @@ int main( void )
|
||||
uint32_t flags;
|
||||
unsigned char buf[1024];
|
||||
const char *pers = "ssl_client1";
|
||||
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
mbedtls_ssl_context ssl;
|
||||
@@ -110,7 +129,7 @@ int main( void )
|
||||
mbedtls_x509_crt cacert;
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_debug_set_threshold( DEBUG_LEVEL );
|
||||
// mbedtls_debug_set_threshold( DEBUG_LEVEL );
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -121,10 +140,8 @@ int main( void )
|
||||
mbedtls_ssl_config_init( &conf );
|
||||
mbedtls_x509_crt_init( &cacert );
|
||||
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||
|
||||
mbedtls_printf( "\n . Seeding the random number generator..." );
|
||||
//fflush( stdout );
|
||||
|
||||
mbedtls_entropy_init( &entropy );
|
||||
if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
@@ -133,15 +150,15 @@ int main( void )
|
||||
mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
|
||||
/*
|
||||
* 0. Initialize certificates
|
||||
*/
|
||||
*/;
|
||||
mbedtls_printf( " . Loading the CA root certificate ..." );
|
||||
//fflush( stdout );
|
||||
|
||||
|
||||
ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_cas_pem,
|
||||
mbedtls_test_cas_pem_len );
|
||||
if( ret < 0 )
|
||||
@@ -151,7 +168,7 @@ int main( void )
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok (%d skipped)\n", ret );
|
||||
|
||||
|
||||
/*
|
||||
* 1. Start the connection
|
||||
*/
|
||||
@@ -204,7 +221,6 @@ int main( void )
|
||||
}
|
||||
|
||||
mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
|
||||
/*
|
||||
* 4. Handshake
|
||||
*/
|
||||
@@ -301,15 +317,14 @@ int main( void )
|
||||
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||
|
||||
exit:
|
||||
|
||||
#ifdef MBEDTLS_ERROR_C
|
||||
//#ifdef MBEDTLS_ERROR_C
|
||||
if( exit_code != MBEDTLS_EXIT_SUCCESS )
|
||||
{
|
||||
char error_buf[100];
|
||||
static char error_buf[100];
|
||||
mbedtls_strerror( ret, error_buf, 100 );
|
||||
mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
|
||||
}
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
mbedtls_net_free( &server_fd );
|
||||
|
||||
@@ -322,7 +337,7 @@ exit:
|
||||
|
||||
return( exit_code );
|
||||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
|
||||
/*#endif MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
|
||||
MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C &&
|
||||
MBEDTLS_CERTS_C && MBEDTLS_PEM_PARSE_C && MBEDTLS_CTR_DRBG_C &&
|
||||
MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
Reference in New Issue
Block a user