From 03b571cde4869c121565aecfc8a2cbc5bc1b33ab Mon Sep 17 00:00:00 2001 From: Ludovic FLAMENT Date: Sat, 7 May 2016 21:12:08 +0200 Subject: [PATCH] fix some bugs, add Windows support --- src/ssl.c | 5 +++-- wolfcrypt/src/bio.c | 14 ++++++++++---- wolfcrypt/test/test.c | 24 ++++++++++++++++++++---- wolfssl-ntru.vcproj | 13 +++++++++++-- wolfssl.vcproj | 8 ++++++++ wolfssl.vcxproj | 2 ++ wolfssl/openssl/ripemd.h | 2 +- wolfssl/wolfcrypt/bio.h | 2 -- 8 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index e11c44ad3..2ca056176 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -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; diff --git a/wolfcrypt/src/bio.c b/wolfcrypt/src/bio.c index c92b708f9..035a3cb07 100644 --- a/wolfcrypt/src/bio.c +++ b/wolfcrypt/src/bio.c @@ -30,16 +30,18 @@ #include #include -#include #include -#include #include #ifdef USE_WINDOWS_API #include #include #include +#include +#define SHUT_RDWR SD_BOTH #else +#include +#include #include #include #include @@ -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); diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 6a9a1cb86..f52fbb10c 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -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); diff --git a/wolfssl-ntru.vcproj b/wolfssl-ntru.vcproj index 84a6feac8..bda665992 100755 --- a/wolfssl-ntru.vcproj +++ b/wolfssl-ntru.vcproj @@ -165,7 +165,11 @@ - + + + @@ -176,7 +180,12 @@ + > + + + diff --git a/wolfssl.vcproj b/wolfssl.vcproj index 7a509d75f..53f046e5a 100755 --- a/wolfssl.vcproj +++ b/wolfssl.vcproj @@ -162,6 +162,10 @@ + + + + + + diff --git a/wolfssl/openssl/ripemd.h b/wolfssl/openssl/ripemd.h index 585b6e651..62b1dc105 100644 --- a/wolfssl/openssl/ripemd.h +++ b/wolfssl/openssl/ripemd.h @@ -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 diff --git a/wolfssl/wolfcrypt/bio.h b/wolfssl/wolfcrypt/bio.h index 73ad9772e..62178152a 100644 --- a/wolfssl/wolfcrypt/bio.h +++ b/wolfssl/wolfcrypt/bio.h @@ -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()