From f18ff8bfa4108c2edfdd69bb39427906472f18d1 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Mon, 27 Jun 2016 15:44:52 -0600 Subject: [PATCH] update mysql patch --- src/internal.c | 13 +++++++++++ src/ssl.c | 39 ++++---------------------------- wolfcrypt/src/asn.c | 44 ++++++++++++++++++++++++++++++++++++ wolfssl/wolfcrypt/asn.h | 4 +++- wolfssl/wolfcrypt/settings.h | 5 ++++ wolfssl/wolfcrypt/wc_port.h | 4 ++-- 6 files changed, 71 insertions(+), 38 deletions(-) diff --git a/src/internal.c b/src/internal.c index 7b9d2317a..ac9ad5c51 100755 --- a/src/internal.c +++ b/src/internal.c @@ -1955,6 +1955,16 @@ void InitSuites(Suites* suites, ProtocolVersion pv, word16 haveRSA, } #endif +/* Place as higher priority for MYSQL */ +#if defined(WOLFSSL_MYSQL_COMPATIBLE) +#ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA + if (tls && haveDH && haveRSA) { + suites->suites[idx++] = 0; + suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_256_CBC_SHA; + } +#endif +#endif + #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 if (tls1_2 && haveRSAsig) { suites->suites[idx++] = ECC_BYTE; @@ -2179,12 +2189,15 @@ void InitSuites(Suites* suites, ProtocolVersion pv, word16 haveRSA, } #endif +/* Place as higher priority for MYSQL testing */ +#if !defined(WOLFSSL_MYSQL_COMPATIBLE) #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA if (tls && haveDH && haveRSA) { suites->suites[idx++] = 0; suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_256_CBC_SHA; } #endif +#endif #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA if (tls && haveDH && haveRSA) { diff --git a/src/ssl.c b/src/ssl.c index 82295ef6c..ae04f9083 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -12507,8 +12507,6 @@ int wolfSSL_ASN1_TIME_print(WOLFSSL_BIO* bio, const WOLFSSL_ASN1_TIME* asnTime) #if defined(WOLFSSL_MYSQL_COMPATIBLE) char* wolfSSL_ASN1_TIME_to_string(WOLFSSL_ASN1_TIME* time, char* buf, int len) { - struct tm t; - int idx = 0; int format; int dateLen; byte* date = (byte*)time; @@ -12523,43 +12521,14 @@ char* wolfSSL_ASN1_TIME_to_string(WOLFSSL_ASN1_TIME* time, char* buf, int len) format = *date; date++; dateLen = *date; date++; if (dateLen > len) { - return "error"; + WOLFSSL_MSG("Length of date is longer then buffer"); + return NULL; } - if (!ExtractDate(date, format, &t, &idx)) { - return "error"; + if (!GetTimeString(date, format, buf, len)) { + return NULL; } - if (date[idx] != 'Z') { - WOLFSSL_MSG("UTCtime, not Zulu") ; - return "Not Zulu"; - } - - /* place month in buffer */ - buf[0] = '\0'; - switch(t.tm_mon) { - case 0: XSTRNCAT(buf, "Jan ", 4); break; - case 1: XSTRNCAT(buf, "Feb ", 4); break; - case 2: XSTRNCAT(buf, "Mar ", 4); break; - case 3: XSTRNCAT(buf, "Apr ", 4); break; - case 4: XSTRNCAT(buf, "May ", 4); break; - case 5: XSTRNCAT(buf, "Jun ", 4); break; - case 6: XSTRNCAT(buf, "Jul ", 4); break; - case 7: XSTRNCAT(buf, "Aug ", 4); break; - case 8: XSTRNCAT(buf, "Sep ", 4); break; - case 9: XSTRNCAT(buf, "Oct ", 4); break; - case 10: XSTRNCAT(buf, "Nov ", 4); break; - case 11: XSTRNCAT(buf, "Dec ", 4); break; - default: - return "error"; - - } - idx = 4; /* use idx now for char buffer */ - buf[idx] = ' '; - - XSNPRINTF(buf + idx, len - idx, "%2d %02d:%02d:%02d %d GMT", - t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, t.tm_year + 1900); - return buf; } #endif /* WOLFSSL_MYSQL_COMPATIBLE */ diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 5c5c9e54b..3cdab5c95 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -3005,6 +3005,50 @@ static INLINE int DateLessThan(const struct tm* a, const struct tm* b) } +#if defined(WOLFSSL_MYSQL_COMPATIBLE) +int GetTimeString(byte* date, int format, char* buf, int len) +{ + struct tm t; + int idx = 0; + + if (!ExtractDate(date, format, &t, &idx)) { + return 0; + } + + if (date[idx] != 'Z') { + WOLFSSL_MSG("UTCtime, not Zulu") ; + return 0; + } + + /* place month in buffer */ + buf[0] = '\0'; + switch(t.tm_mon) { + case 0: XSTRNCAT(buf, "Jan ", 4); break; + case 1: XSTRNCAT(buf, "Feb ", 4); break; + case 2: XSTRNCAT(buf, "Mar ", 4); break; + case 3: XSTRNCAT(buf, "Apr ", 4); break; + case 4: XSTRNCAT(buf, "May ", 4); break; + case 5: XSTRNCAT(buf, "Jun ", 4); break; + case 6: XSTRNCAT(buf, "Jul ", 4); break; + case 7: XSTRNCAT(buf, "Aug ", 4); break; + case 8: XSTRNCAT(buf, "Sep ", 4); break; + case 9: XSTRNCAT(buf, "Oct ", 4); break; + case 10: XSTRNCAT(buf, "Nov ", 4); break; + case 11: XSTRNCAT(buf, "Dec ", 4); break; + default: + return 0; + + } + idx = 4; /* use idx now for char buffer */ + buf[idx] = ' '; + + XSNPRINTF(buf + idx, len - idx, "%2d %02d:%02d:%02d %d GMT", + t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, t.tm_year + 1900); + + return 1; +} +#endif /* MYSQL compatibility */ + int ExtractDate(const unsigned char* date, unsigned char format, struct tm* certTime, int* idx) { diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index 8dda43cab..ff6253d9c 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -610,7 +610,9 @@ WOLFSSL_LOCAL int ToTraditional(byte* buffer, word32 length); WOLFSSL_LOCAL int ToTraditionalEnc(byte* buffer, word32 length,const char*,int); typedef struct tm wolfssl_tm; - +#if defined(WOLFSSL_MYSQL_COMPATIBLE) +WOLFSSL_LOCAL int GetTimeString(byte* date, int format, char* buf, int len); +#endif WOLFSSL_LOCAL int ExtractDate(const unsigned char* date, unsigned char format, wolfssl_tm* certTime, int* idx); WOLFSSL_LOCAL int ValidateDate(const byte* date, byte format, int dateType); diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index ac93ca19a..c2130f6a2 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -1257,6 +1257,11 @@ static char *fgets(char *buff, int sz, FILE *fp) #endif /* WOLFSSL_STATIC_MEMORY */ /* Place any other flags or defines here */ +#if defined(WOLFSSL_MYSQL_COMPATIBLE) && defined(_WIN32) \ + && defined(HAVE_GMTIME_R) + #undef HAVE_GMTIME_R /* don't trust macro with windows */ +#endif /* WOLFSSL_MYSQL_COMPATIBLE */ + #ifdef __cplusplus } /* extern "C" */ diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 136a6be5f..29e557b62 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -247,10 +247,10 @@ WOLFSSL_API int wolfCrypt_Init(void); /* Windows API defines its own min() macro. */ #if defined(USE_WINDOWS_API) - #ifdef min + #if defined(min) || defined(WOLFSSL_MYSQL_COMPATIBLE) #define WOLFSSL_HAVE_MIN #endif /* min */ - #ifdef max + #if defined(max) || defined(WOLFSSL_MYSQL_COMPATIBLE) #define WOLFSSL_HAVE_MAX #endif /* max */ #endif /* USE_WINDOWS_API */