fix some bugs, add Windows support

This commit is contained in:
Ludovic FLAMENT 2016-05-07 21:12:08 +02:00
parent 5d1de3bb33
commit 03b571cde4
8 changed files with 55 additions and 15 deletions

View File

@ -263,11 +263,12 @@ WOLFSSL* wolfSSL_dup(WOLFSSL* s)
CHACHA20_IMP_IV_SZ);
XMEMCPY(ret->keys.client_write_IV, s->keys.client_write_IV,
CHACHA20_IMP_IV_SZ);
#ifdef HAVE_AEAD
XMEMCPY(ret->keys.aead_enc_imp_IV, ret->keys.server_write_IV,
CHACHA20_IMP_IV_SZ);
XMEMCPY(ret->keys.aead_dec_imp_IV, ret->keys.client_write_IV,
CHACHA20_IMP_IV_SZ);
#endif
/* setup biord, and biowr */
if (s->biord != NULL) {
@ -16673,7 +16674,7 @@ WOLFCRYPT_BIO *wolfSSL_BioNewSSLConnect(WOLFSSL_CTX *ctx)
if (con == NULL)
return NULL;
ssl = wolfSSL_BioNewSSL(ctx, 1);
ssl = wolfSSL_BioNewSSL(ctx, BIO_CLOSE);
if (ssl == NULL)
goto err;

View File

@ -30,16 +30,18 @@
#include <stdarg.h>
#include <stdio.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#ifdef USE_WINDOWS_API
#include <winsock2.h>
#include <process.h>
#include <io.h>
#include <fcntl.h>
#define SHUT_RDWR SD_BOTH
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <fcntl.h>
#include <netdb.h>
@ -753,7 +755,9 @@ unsigned long wc_BioNumberWritten(WOLFCRYPT_BIO *bio)
}
#ifndef USE_WINDOWS_API
__attribute__((format(printf, 2, 3)))
#endif
int wc_BioPrintf(WOLFCRYPT_BIO *bio, const char *format, ...)
{
int size, ret;
@ -1954,7 +1958,6 @@ static int wc_BioBuffer_gets(WOLFCRYPT_BIO *bio, char *buf, int size)
for (;;) {
if (ctx->inLen > 0) {
// p = &(ctx->in[ctx->inIdx]);
flag = 0;
for (i = 0; (i < ctx->inLen) && (i < size); i++) {
@ -3071,6 +3074,9 @@ int wc_BioSetTcpNsigpipe(int s, int on)
signal(SIGPIPE, SIG_IGN);
#endif /* S_NOSIGPIPE */
#else /* USE_WINDOWS_API */
(void) s;
(void) on;
#endif /* USE_WINDOWS_API */
return (ret == 0);
@ -5462,7 +5468,7 @@ static int wolfCrypt_BufMem_grow(WOLFCRYPT_BUF_MEM *buf, size_t len)
static int wolfCrypt_BufMem_grow_clean(WOLFCRYPT_BUF_MEM *buf, size_t len)
{
int ret, idx = -1;
size_t size;
size_t size = 0;
if (buf == NULL) {
WOLFSSL_ERROR(BAD_FUNC_ARG);

View File

@ -6736,7 +6736,11 @@ int bio_connect_ssl_test(void)
i = wc_BioWrite(out, request+idx, len);
if (i <= 0) {
if (wc_BioShouldRetry(out)) {
#ifdef USE_WINDOWS_API
Sleep(1000);
#else
sleep(1);
#endif
continue;
} else {
ret = -3005;
@ -6755,7 +6759,11 @@ int bio_connect_ssl_test(void)
break;
if (i < 0) {
if (wc_BioShouldRetry(out)) {
#ifdef USE_WINDOWS_API
Sleep(1000);
#else
sleep(1);
#endif
continue;
}
ret = -3006;
@ -6817,7 +6825,7 @@ int bio_accept_ssl_test(void)
#define KEY_F "./certs/ecc-key.pem"
#endif
ssl_ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method());
ssl_ctx = wolfSSL_CTX_new(wolfTLSv1_server_method());
if (ssl_ctx == NULL)
return -3000;
@ -6844,7 +6852,7 @@ int bio_accept_ssl_test(void)
#endif /* NO_DH */
/* Setup server side SSL bio */
ssl_bio = wolfSSL_BioNewSSL(ssl_ctx, 0);
ssl_bio = wolfSSL_BioNewSSL(ssl_ctx, BIO_NOCLOSE);
if (ssl_bio == NULL) {
ret = -3005;
goto end;
@ -6882,7 +6890,7 @@ int bio_accept_ssl_test(void)
* will be freed when the accept BIO is freed.
*/
if (wc_BioSetAcceptBios(in, ssl_bio) <= 0) {
ret = -3006;
ret = -3009;
goto end;
}
@ -6904,7 +6912,8 @@ int bio_accept_ssl_test(void)
b_rw = wc_BioPop(in);
if (b_rw == NULL) {
printf("BIO error -> close\n");
break;
ret = -3012;
goto end;
}
for(;;) {
@ -6922,6 +6931,8 @@ int bio_accept_ssl_test(void)
if (wc_BioShouldRetry(b_rw))
continue;
printf("Read error -> close\n");
ret = -3014;
goto end;
break;
}
@ -7004,8 +7015,13 @@ int bio_test(void)
return -1006;
ret = wc_BioTell(bio);
#ifdef USE_WINDOWS_API
if (ret != 0)
return -1007;
#else
if (ret != (int)strlen(buf)+1)
return -1007;
#endif
/* write */
ret = wc_BioPrintf(bio, "%s\n", buf);

View File

@ -165,7 +165,11 @@
<File
RelativePath=".\wolfcrypt\src\asn.c"
>
</File>
</File>
<File
RelativePath=".\wolfcrypt\src\bio.c"
>
</File>
<File
RelativePath=".\wolfcrypt\src\blake2b.c"
>
@ -176,7 +180,12 @@
</File>
<File
RelativePath=".\wolfcrypt\src\coding.c"
>
>
</File>
<File
RelativePath=".\wolfcrypt\src\compat-wolfssl.c"
>
</File>
<File
RelativePath=".\wolfcrypt\src\chacha.c"
>

View File

@ -162,6 +162,10 @@
<File
RelativePath=".\wolfcrypt\src\asn.c"
>
</File>
<File
RelativePath=".\wolfcrypt\src\bio.c"
>
</File>
<File
RelativePath=".\wolfcrypt\src\blake2b.c"
@ -174,6 +178,10 @@
<File
RelativePath=".\wolfcrypt\src\coding.c"
>
</File>
<File
RelativePath=".\wolfcrypt\src\compat-wolfssl.c"
>
</File>
<File
RelativePath=".\wolfcrypt\src\chacha.c"

View File

@ -286,11 +286,13 @@
<ClCompile Include="wolfcrypt\src\aes.c" />
<ClCompile Include="wolfcrypt\src\arc4.c" />
<ClCompile Include="wolfcrypt\src\asn.c" />
<ClCompile Include="wolfcrypt\src\bio.c" />
<ClCompile Include="wolfcrypt\src\blake2b.c" />
<ClCompile Include="wolfcrypt\src\camellia.c" />
<ClCompile Include="wolfcrypt\src\chacha.c" />
<ClCompile Include="wolfcrypt\src\chacha20_poly1305.c" />
<ClCompile Include="wolfcrypt\src\coding.c" />
<ClCompile Include="wolfcrypt\src\compat-wolfssl.c" />
<ClCompile Include="wolfcrypt\src\des3.c" />
<ClCompile Include="wolfcrypt\src\dh.c" />
<ClCompile Include="wolfcrypt\src\dsa.c" />

View File

@ -12,7 +12,7 @@
#ifdef WOLFSSL_RIPEMD
typedef WOLCRYPT_RIPEMD_CTX RIPEMD_CTX;
typedef WOLFCRYPT_RIPEMD_CTX RIPEMD_CTX;
#define RIPEMD_Init wc_RIPEMD_Init
#define RIPEMD_Update wc_RIPEMD_Update

View File

@ -50,10 +50,8 @@ enum WS_BIO_TYPE {
* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
* BIO_set_fp(in,stdin,BIO_NOCLOSE);
*/
#if !defined(BIO_CLOSE) || !defined(BIO_NOCLOSE)
#define BIO_CLOSE 1
#define BIO_NOCLOSE 0
#endif
/*
* These are used in the following macros and are passed to BIO_ctrl()