From 1d4cc928c6628724996e3d04b555a432249bcd4f Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Wed, 18 Mar 2015 16:15:56 -0600 Subject: [PATCH 01/13] fix Freescale MQX gmtime, cert generation --- wolfcrypt/src/asn.c | 64 +++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 0f12f6402..500b39ebb 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -89,7 +89,7 @@ #ifdef HAVE_RTP_SYS /* uses parital structures */ #define XTIME(tl) (0) - #define XGMTIME(c) my_gmtime((c)) + #define XGMTIME(c, t) my_gmtime((c)) #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t)) #elif defined(MICRIUM) #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) @@ -102,11 +102,11 @@ #elif defined(MICROCHIP_TCPIP_V5) || defined(MICROCHIP_TCPIP) #include #define XTIME(t1) pic32_time((t1)) - #define XGMTIME(c) gmtime((c)) + #define XGMTIME(c, t) gmtime((c)) #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t)) #elif defined(FREESCALE_MQX) #define XTIME(t1) mqx_time((t1)) - #define XGMTIME(c) mqx_gmtime((c)) + #define XGMTIME(c, t) mqx_gmtime((c), (t)) #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t)) #elif defined(WOLFSSL_MDK_ARM) #if defined(WOLFSSL_MDK5) @@ -119,7 +119,7 @@ #undef RNG #define RNG wolfSSL_RNG /*for avoiding name conflict in "stm32f2xx.h" */ #define XTIME(tl) (0) - #define XGMTIME(c) wolfssl_MDK_gmtime((c)) + #define XGMTIME(c, t) wolfssl_MDK_gmtime((c)) #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t)) #elif defined(USER_TIME) /* user time, and gmtime compatible functions, there is a gmtime @@ -146,7 +146,7 @@ struct tm* gmtime(const time_t* timer); extern time_t XTIME(time_t * timer); - #define XGMTIME(c) gmtime((c)) + #define XGMTIME(c, t) gmtime((c)) #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t)) #ifdef STACK_TRAP @@ -179,7 +179,7 @@ char *tm_zone; /* timezone abbreviation */ }; #endif - extern struct tm* XGMTIME(const time_t* timer); + extern struct tm* XGMTIME(const time_t* timer, struct tm* tmp); #ifndef HAVE_VALIDATE_DATE #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t)) @@ -188,8 +188,8 @@ /* default */ /* uses complete facility */ #include - #define XTIME(tl) time((tl)) - #define XGMTIME(c) gmtime((c)) + #define XTIME(tl) time((tl)) + #define XGMTIME(c, t) gmtime((c)) #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t)) #endif @@ -350,11 +350,9 @@ time_t mqx_time(time_t* timer) } /* CodeWarrior GCC toolchain only has gmtime_r(), no gmtime() */ -struct tm* mqx_gmtime(const time_t* clock) +struct tm* mqx_gmtime(const time_t* clock, struct tm* tmpTime) { - struct tm tmpTime; - - return gmtime_r(clock, &tmpTime); + return gmtime_r(clock, tmpTime); } #endif /* FREESCALE_MQX */ @@ -2399,8 +2397,16 @@ int ValidateDate(const byte* date, byte format, int dateType) time_t ltime; struct tm certTime; struct tm* localTime; + struct tm* tmpTime; int i = 0; +#ifdef FREESCALE_MQX + struct tm mqxTime; + tmpTime = &mqxTime; +#else + (void)tmpTime; +#endif + ltime = XTIME(0); XMEMSET(&certTime, 0, sizeof(certTime)); @@ -2428,7 +2434,7 @@ int ValidateDate(const byte* date, byte format, int dateType) return 0; } - localTime = XGMTIME(<ime); + localTime = XGMTIME(<ime, tmpTime); if (dateType == BEFORE) { if (DateLessThan(localTime, &certTime)) @@ -5220,6 +5226,18 @@ static int CopyValidity(byte* output, Cert* cert) #endif +/* for systems where mktime() doesn't normalize fully */ +static void RebuildTime(time_t* in, struct tm* out) +{ + #ifdef FREESCALE_MQX + out = localtime_r(in, out); + #else + (void)in; + (void)out; + #endif +} + + /* Set Date validity from now until now + daysValid */ static int SetValidity(byte* output, int daysValid) { @@ -5231,11 +5249,21 @@ static int SetValidity(byte* output, int daysValid) int seqSz; time_t ticks; + time_t normalTime; struct tm* now; + struct tm* tmpTime; struct tm local; +#ifdef FREESCALE_MQX + /* for use with MQX gmtime_r */ + struct tm mqxTime; + tmpTime = &mqxTime; +#else + (void)tmpTime; +#endif + ticks = XTIME(0); - now = XGMTIME(&ticks); + now = XGMTIME(&ticks, tmpTime); /* before now */ local = *now; @@ -5244,7 +5272,8 @@ static int SetValidity(byte* output, int daysValid) /* subtract 1 day for more compliance */ local.tm_mday -= 1; - mktime(&local); + normalTime = mktime(&local); + RebuildTime(&normalTime, &local); /* adjust */ local.tm_year += 1900; @@ -5252,7 +5281,7 @@ static int SetValidity(byte* output, int daysValid) SetTime(&local, before + beforeSz); beforeSz += ASN_GEN_TIME_SZ; - + /* after now + daysValid */ local = *now; after[0] = ASN_GENERALIZED_TIME; @@ -5260,7 +5289,8 @@ static int SetValidity(byte* output, int daysValid) /* add daysValid */ local.tm_mday += daysValid; - mktime(&local); + normalTime = mktime(&local); + RebuildTime(&normalTime, &local); /* adjust */ local.tm_year += 1900; From 555eb662923ae8af0c373b394c9ac6ef6b4107ad Mon Sep 17 00:00:00 2001 From: toddouska Date: Wed, 18 Mar 2015 15:47:19 -0700 Subject: [PATCH 02/13] fix github issue #40, export Base64_Decode, allow user to export Base64_Encode w/o other options --- wolfcrypt/src/coding.c | 4 ++-- wolfssl/wolfcrypt/coding.h | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/src/coding.c b/wolfcrypt/src/coding.c index 1834c2da3..6ead79caf 100644 --- a/wolfcrypt/src/coding.c +++ b/wolfcrypt/src/coding.c @@ -133,7 +133,7 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen) } -#if defined(OPENSSL_EXTRA) || defined (SESSION_CERTS) || defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN) || defined(HAVE_WEBSERVER) +#if defined(WOLFSSL_BASE64_ENCODE) static const byte base64Encode[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', @@ -324,7 +324,7 @@ int Base64_EncodeEsc(const byte* in, word32 inLen, byte* out, word32* outLen) } -#endif /* defined(OPENSSL_EXTRA) || defined (SESSION_CERTS) || defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN) || defined(HAVE_WEBSERVER) */ +#endif /* defined(WOLFSSL_BASE64_ENCODE) */ #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(HAVE_FIPS) diff --git a/wolfssl/wolfcrypt/coding.h b/wolfssl/wolfcrypt/coding.h index b5a0ce345..296bc3ca7 100644 --- a/wolfssl/wolfcrypt/coding.h +++ b/wolfssl/wolfcrypt/coding.h @@ -30,11 +30,17 @@ #endif -/* decode needed by wolfSSL */ -WOLFSSL_LOCAL int Base64_Decode(const byte* in, word32 inLen, byte* out, +WOLFSSL_API int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen); -#if defined(OPENSSL_EXTRA) || defined(SESSION_CERTS) || defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN) || defined(HAVE_WEBSERVER) +#if defined(OPENSSL_EXTRA) || defined(SESSION_CERTS) || defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN) || defined(HAVE_WEBSERVER) + #ifndef WOLFSSL_BASE64_ENCODE + #define WOLFSSL_BASE64_ENCODE + #endif +#endif + + +#ifdef WOLFSSL_BASE64_ENCODE /* encode isn't */ WOLFSSL_API int Base64_Encode(const byte* in, word32 inLen, byte* out, From 605ca8eaf6ce3098bbd37aac0132a33ee07de1ab Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Wed, 18 Mar 2015 18:18:09 -0600 Subject: [PATCH 03/13] update Freescale CodeWarrior project files to wolfSSL --- Makefile.am | 8 +-- mqx/README | 20 +++--- mqx/cyassl_client/Sources/include.am | 22 ------ mqx/wolfcrypt_benchmark/.cproject | 18 ++--- mqx/wolfcrypt_benchmark/.project | 6 +- .../ReferencedRSESystems.xml | 26 +++---- mqx/wolfcrypt_benchmark/Sources/include.am | 28 ++++---- mqx/wolfcrypt_benchmark/Sources/main.c | 2 +- ...lash_DDRData_Debug_PnE_U-MultiLink.launch} | 0 ...sh_DDRData_Release_PnE_U-MultiLink.launch} | 0 ...ash_SramData_Debug_PnE_U-MultiLink.launch} | 0 ...h_SramData_Release_PnE_U-MultiLink.launch} | 0 mqx/wolfcrypt_test/.cproject | 18 ++--- mqx/wolfcrypt_test/.project | 6 +- mqx/wolfcrypt_test/ReferencedRSESystems.xml | 26 +++---- mqx/wolfcrypt_test/Sources/include.am | 8 +-- mqx/wolfcrypt_test/Sources/main.c | 4 +- mqx/wolfcrypt_test/Sources/main.h | 2 +- ...lash_DDRData_Debug_PnE_U-MultiLink.launch} | 0 ...sh_DDRData_Release_PnE_U-MultiLink.launch} | 0 ...ash_SramData_Debug_PnE_U-MultiLink.launch} | 0 ...h_SramData_Release_PnE_U-MultiLink.launch} | 0 mqx/{cyassl => wolfssl}/.cproject | 20 +++--- mqx/{cyassl => wolfssl}/.project | 10 +-- mqx/{cyassl => wolfssl}/include.am | 4 +- .../.cproject | 42 ++++++------ .../.project | 6 +- .../Debugger/K70FN1M0.mem | 0 .../Debugger/init_kinetis.tcl | 0 .../Debugger/mass_erase_kinetis.tcl | 0 .../ReferencedRSESystems.xml | 28 ++++---- mqx/wolfssl_client/Sources/include.am | 22 ++++++ .../Sources/main.c | 68 +++++++++---------- .../Sources/main.h | 4 +- ...lash_DDRData_Debug_PnE_U-MultiLink.launch} | 6 +- ...sh_DDRData_Release_PnE_U-MultiLink.launch} | 6 +- ...20m_Int_Flash_SramData_Debug_JTrace.jlink} | 0 ...0m_Int_Flash_SramData_Debug_JTrace.launch} | 6 +- ...ash_SramData_Debug_PnE_U-MultiLink.launch} | 6 +- ...h_SramData_Release_PnE_U-MultiLink.launch} | 6 +- 40 files changed, 215 insertions(+), 213 deletions(-) delete mode 100644 mqx/cyassl_client/Sources/include.am rename mqx/wolfcrypt_benchmark/{wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Debug_PnE U-MultiLink.launch => wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch} (100%) rename mqx/wolfcrypt_benchmark/{wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Release_PnE U-MultiLink.launch => wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch} (100%) rename mqx/wolfcrypt_benchmark/{wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_PnE U-MultiLink.launch => wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch} (100%) rename mqx/wolfcrypt_benchmark/{wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Release_PnE U-MultiLink.launch => wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch} (100%) rename mqx/wolfcrypt_test/{wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Debug_PnE U-MultiLink.launch => wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch} (100%) rename mqx/wolfcrypt_test/{wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Release_PnE U-MultiLink.launch => wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch} (100%) rename mqx/wolfcrypt_test/{wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_PnE U-MultiLink.launch => wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch} (100%) rename mqx/wolfcrypt_test/{wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Release_PnE U-MultiLink.launch => wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch} (100%) rename mqx/{cyassl => wolfssl}/.cproject (95%) rename mqx/{cyassl => wolfssl}/.project (74%) rename mqx/{cyassl => wolfssl}/include.am (66%) rename mqx/{cyassl_client => wolfssl_client}/.cproject (94%) rename mqx/{cyassl_client => wolfssl_client}/.project (89%) rename mqx/{cyassl_client => wolfssl_client}/Debugger/K70FN1M0.mem (100%) rename mqx/{cyassl_client => wolfssl_client}/Debugger/init_kinetis.tcl (100%) rename mqx/{cyassl_client => wolfssl_client}/Debugger/mass_erase_kinetis.tcl (100%) rename mqx/{cyassl_client => wolfssl_client}/ReferencedRSESystems.xml (92%) create mode 100644 mqx/wolfssl_client/Sources/include.am rename mqx/{cyassl_client => wolfssl_client}/Sources/main.c (81%) rename mqx/{cyassl_client => wolfssl_client}/Sources/main.h (94%) rename mqx/{cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE U-MultiLink.launch => wolfssl_client/wolfssl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch} (99%) rename mqx/{cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE U-MultiLink.launch => wolfssl_client/wolfssl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch} (98%) rename mqx/{cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink => wolfssl_client/wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink} (100%) rename mqx/{cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch => wolfssl_client/wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch} (99%) rename mqx/{cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE U-MultiLink.launch => wolfssl_client/wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch} (99%) rename mqx/{cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE U-MultiLink.launch => wolfssl_client/wolfssl_client_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch} (99%) diff --git a/Makefile.am b/Makefile.am index 5def2496f..2cbb27616 100644 --- a/Makefile.am +++ b/Makefile.am @@ -79,11 +79,11 @@ include testsuite/include.am include tests/include.am include sslSniffer/sslSnifferTest/include.am include rpm/include.am -# TODO: fix, this commented out mqx ones have spaces in file names -#include mqx/wolfcrypt_test/Sources/include.am -include mqx/cyassl/include.am -#include mqx/cyassl_client/Sources/include.am include mqx/util_lib/Sources/include.am +include mqx/wolfcrypt_benchmark/Sources/include.am +include mqx/wolfcrypt_test/Sources/include.am +include mqx/wolfssl/include.am +include mqx/wolfssl_client/Sources/include.am include mplabx/include.am include mplabx/wolfcrypt_benchmark.X/nbproject/include.am include mplabx/wolfcrypt_test.X/nbproject/include.am diff --git a/mqx/README b/mqx/README index d99785373..55c13c671 100644 --- a/mqx/README +++ b/mqx/README @@ -1,4 +1,4 @@ -CyaSSL Freescale CodeWarrior Project Files +wolfSSL Freescale CodeWarrior Project Files This directory contains project files for Freescale CodeWarrior 10.6 with the Freescale GCC compiler. These project have been created to use MQX, RTCS, @@ -7,20 +7,22 @@ and MFS on the Freescale Kinetis K70 Tower System (TWRK70F120M). Included Project Files ----------------------- -1. CyaSSL library (/cyassl) +1. wolfSSL library (/wolfssl) - Prior to building this project, uncomment the FREESCALE_MQX define + Prior to building this project, uncomment the FREESCALE_MQX define located in: - /cyassl/ctaocrypt/settings.h + /wolfssl/wolfcrypt/settings.h 2. wolfCrypt Test App (/wolfcrypt_test) -3. Example CyaSSL Client (/cyassl_client) +3. wolfCrypt Benchmark App (/wolfcrypt_benchmark) + +3. Example wolfSSL Client (/wolfssl_client) 4. Utility library (/util_lib) - This library is used by the CyaSSL example client project and wolfCrypt + This library is used by the wolfSSL example client project and wolfCrypt test app project for opening/closing the SD card, etc. Importing into CodeWarrior Workspace @@ -32,10 +34,10 @@ these steps: 1. File -> Import 2. General -> Existing Projects into Workspace -3. Select Root Directory (browse to this "/mqx" directory) +3. Select Root Directory (browse to this "/mqx" directory) 4. Select desired projects -> Finish -Keep in mind that the projects above reference CyaSSL source files and header +Keep in mind that the projects above reference wolfSSL source files and header files with relative paths to the projects' current location in the -/mqx directory. +/mqx directory. diff --git a/mqx/cyassl_client/Sources/include.am b/mqx/cyassl_client/Sources/include.am deleted file mode 100644 index de5221e49..000000000 --- a/mqx/cyassl_client/Sources/include.am +++ /dev/null @@ -1,22 +0,0 @@ -# vim:ft=automake -# All paths should be given relative to the root -# - -EXTRA_DIST += \ - mqx/cyassl_client/.cproject \ - mqx/cyassl_client/.project \ - mqx/cyassl_client/K70FN1M0.mem \ - mqx/cyassl_client/init_kinetis.tcl \ - mqx/cyassl_client/mass_erase_kinetis.tcl \ - mqx/cyassl_client/ReferencedRSESystems.xml \ - mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE U-MultiLink.launch \ - mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE U-MultiLink.launch \ - mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink \ - mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch \ - mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE U-MultiLink.launch \ - mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE U-MultiLink.launch - -EXTRA_DIST += \ - mqx/cyassl_client/Sources/main.c \ - mqx/cyassl_client/Sources/main.h - diff --git a/mqx/wolfcrypt_benchmark/.cproject b/mqx/wolfcrypt_benchmark/.cproject index 8c43e3c7e..d110e10ea 100755 --- a/mqx/wolfcrypt_benchmark/.cproject +++ b/mqx/wolfcrypt_benchmark/.cproject @@ -90,7 +90,7 @@ - +