forked from wolfSSL/wolfssl
fix Freescale MQX gmtime, cert generation
This commit is contained in:
@ -89,7 +89,7 @@
|
||||
#ifdef HAVE_RTP_SYS
|
||||
/* uses parital <time.h> 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 <time.h>
|
||||
#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))
|
||||
@ -189,7 +189,7 @@
|
||||
/* uses complete <time.h> facility */
|
||||
#include <time.h>
|
||||
#define XTIME(tl) time((tl))
|
||||
#define XGMTIME(c) gmtime((c))
|
||||
#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;
|
||||
@ -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;
|
||||
|
Reference in New Issue
Block a user