forked from wolfSSL/wolfssl
fix Freescale MQX gmtime, cert generation
This commit is contained in:
@ -89,7 +89,7 @@
|
|||||||
#ifdef HAVE_RTP_SYS
|
#ifdef HAVE_RTP_SYS
|
||||||
/* uses parital <time.h> structures */
|
/* uses parital <time.h> structures */
|
||||||
#define XTIME(tl) (0)
|
#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))
|
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
|
||||||
#elif defined(MICRIUM)
|
#elif defined(MICRIUM)
|
||||||
#if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
|
#if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
|
||||||
@ -102,11 +102,11 @@
|
|||||||
#elif defined(MICROCHIP_TCPIP_V5) || defined(MICROCHIP_TCPIP)
|
#elif defined(MICROCHIP_TCPIP_V5) || defined(MICROCHIP_TCPIP)
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#define XTIME(t1) pic32_time((t1))
|
#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))
|
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
|
||||||
#elif defined(FREESCALE_MQX)
|
#elif defined(FREESCALE_MQX)
|
||||||
#define XTIME(t1) mqx_time((t1))
|
#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))
|
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
|
||||||
#elif defined(WOLFSSL_MDK_ARM)
|
#elif defined(WOLFSSL_MDK_ARM)
|
||||||
#if defined(WOLFSSL_MDK5)
|
#if defined(WOLFSSL_MDK5)
|
||||||
@ -119,7 +119,7 @@
|
|||||||
#undef RNG
|
#undef RNG
|
||||||
#define RNG wolfSSL_RNG /*for avoiding name conflict in "stm32f2xx.h" */
|
#define RNG wolfSSL_RNG /*for avoiding name conflict in "stm32f2xx.h" */
|
||||||
#define XTIME(tl) (0)
|
#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))
|
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
|
||||||
#elif defined(USER_TIME)
|
#elif defined(USER_TIME)
|
||||||
/* user time, and gmtime compatible functions, there is a gmtime
|
/* user time, and gmtime compatible functions, there is a gmtime
|
||||||
@ -146,7 +146,7 @@
|
|||||||
struct tm* gmtime(const time_t* timer);
|
struct tm* gmtime(const time_t* timer);
|
||||||
extern time_t XTIME(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))
|
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
|
||||||
|
|
||||||
#ifdef STACK_TRAP
|
#ifdef STACK_TRAP
|
||||||
@ -179,7 +179,7 @@
|
|||||||
char *tm_zone; /* timezone abbreviation */
|
char *tm_zone; /* timezone abbreviation */
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
extern struct tm* XGMTIME(const time_t* timer);
|
extern struct tm* XGMTIME(const time_t* timer, struct tm* tmp);
|
||||||
|
|
||||||
#ifndef HAVE_VALIDATE_DATE
|
#ifndef HAVE_VALIDATE_DATE
|
||||||
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
|
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
|
||||||
@ -188,8 +188,8 @@
|
|||||||
/* default */
|
/* default */
|
||||||
/* uses complete <time.h> facility */
|
/* uses complete <time.h> facility */
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#define XTIME(tl) time((tl))
|
#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))
|
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -350,11 +350,9 @@ time_t mqx_time(time_t* timer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* CodeWarrior GCC toolchain only has gmtime_r(), no gmtime() */
|
/* 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 */
|
#endif /* FREESCALE_MQX */
|
||||||
@ -2399,8 +2397,16 @@ int ValidateDate(const byte* date, byte format, int dateType)
|
|||||||
time_t ltime;
|
time_t ltime;
|
||||||
struct tm certTime;
|
struct tm certTime;
|
||||||
struct tm* localTime;
|
struct tm* localTime;
|
||||||
|
struct tm* tmpTime;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
#ifdef FREESCALE_MQX
|
||||||
|
struct tm mqxTime;
|
||||||
|
tmpTime = &mqxTime;
|
||||||
|
#else
|
||||||
|
(void)tmpTime;
|
||||||
|
#endif
|
||||||
|
|
||||||
ltime = XTIME(0);
|
ltime = XTIME(0);
|
||||||
XMEMSET(&certTime, 0, sizeof(certTime));
|
XMEMSET(&certTime, 0, sizeof(certTime));
|
||||||
|
|
||||||
@ -2428,7 +2434,7 @@ int ValidateDate(const byte* date, byte format, int dateType)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
localTime = XGMTIME(<ime);
|
localTime = XGMTIME(<ime, tmpTime);
|
||||||
|
|
||||||
if (dateType == BEFORE) {
|
if (dateType == BEFORE) {
|
||||||
if (DateLessThan(localTime, &certTime))
|
if (DateLessThan(localTime, &certTime))
|
||||||
@ -5220,6 +5226,18 @@ static int CopyValidity(byte* output, Cert* cert)
|
|||||||
#endif
|
#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 */
|
/* Set Date validity from now until now + daysValid */
|
||||||
static int SetValidity(byte* output, int daysValid)
|
static int SetValidity(byte* output, int daysValid)
|
||||||
{
|
{
|
||||||
@ -5231,11 +5249,21 @@ static int SetValidity(byte* output, int daysValid)
|
|||||||
int seqSz;
|
int seqSz;
|
||||||
|
|
||||||
time_t ticks;
|
time_t ticks;
|
||||||
|
time_t normalTime;
|
||||||
struct tm* now;
|
struct tm* now;
|
||||||
|
struct tm* tmpTime;
|
||||||
struct tm local;
|
struct tm local;
|
||||||
|
|
||||||
|
#ifdef FREESCALE_MQX
|
||||||
|
/* for use with MQX gmtime_r */
|
||||||
|
struct tm mqxTime;
|
||||||
|
tmpTime = &mqxTime;
|
||||||
|
#else
|
||||||
|
(void)tmpTime;
|
||||||
|
#endif
|
||||||
|
|
||||||
ticks = XTIME(0);
|
ticks = XTIME(0);
|
||||||
now = XGMTIME(&ticks);
|
now = XGMTIME(&ticks, tmpTime);
|
||||||
|
|
||||||
/* before now */
|
/* before now */
|
||||||
local = *now;
|
local = *now;
|
||||||
@ -5244,7 +5272,8 @@ static int SetValidity(byte* output, int daysValid)
|
|||||||
|
|
||||||
/* subtract 1 day for more compliance */
|
/* subtract 1 day for more compliance */
|
||||||
local.tm_mday -= 1;
|
local.tm_mday -= 1;
|
||||||
mktime(&local);
|
normalTime = mktime(&local);
|
||||||
|
RebuildTime(&normalTime, &local);
|
||||||
|
|
||||||
/* adjust */
|
/* adjust */
|
||||||
local.tm_year += 1900;
|
local.tm_year += 1900;
|
||||||
@ -5252,7 +5281,7 @@ static int SetValidity(byte* output, int daysValid)
|
|||||||
|
|
||||||
SetTime(&local, before + beforeSz);
|
SetTime(&local, before + beforeSz);
|
||||||
beforeSz += ASN_GEN_TIME_SZ;
|
beforeSz += ASN_GEN_TIME_SZ;
|
||||||
|
|
||||||
/* after now + daysValid */
|
/* after now + daysValid */
|
||||||
local = *now;
|
local = *now;
|
||||||
after[0] = ASN_GENERALIZED_TIME;
|
after[0] = ASN_GENERALIZED_TIME;
|
||||||
@ -5260,7 +5289,8 @@ static int SetValidity(byte* output, int daysValid)
|
|||||||
|
|
||||||
/* add daysValid */
|
/* add daysValid */
|
||||||
local.tm_mday += daysValid;
|
local.tm_mday += daysValid;
|
||||||
mktime(&local);
|
normalTime = mktime(&local);
|
||||||
|
RebuildTime(&normalTime, &local);
|
||||||
|
|
||||||
/* adjust */
|
/* adjust */
|
||||||
local.tm_year += 1900;
|
local.tm_year += 1900;
|
||||||
|
Reference in New Issue
Block a user