Exemple #1
0
int
check_time(long offset)
{
	struct tm tm1, tm2;
	time_t t1, t2;
	time(&t1);
	t2 = t1 + offset;
	OPENSSL_gmtime(&t2, &tm2);
	OPENSSL_gmtime(&t1, &tm1);
	OPENSSL_gmtime_adj(&tm1, 0, offset);
	if ((tm1.tm_year == tm2.tm_year) &&
		(tm1.tm_mon == tm2.tm_mon) &&
	(tm1.tm_mday == tm2.tm_mday) &&
	(tm1.tm_hour == tm2.tm_hour) &&
	(tm1.tm_min == tm2.tm_min) &&
	(tm1.tm_sec == tm2.tm_sec))
	return 1;
	fprintf(stderr, "TIME ERROR!!\n");
	fprintf(stderr, "Time1: %d/%d/%d, %d:%02d:%02d\n",
	tm2.tm_mday, tm2.tm_mon + 1, tm2.tm_year + 1900,
	tm2.tm_hour, tm2.tm_min, tm2.tm_sec);
	fprintf(stderr, "Time2: %d/%d/%d, %d:%02d:%02d\n",
	tm1.tm_mday, tm1.tm_mon + 1, tm1.tm_year + 1900,
	tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
	return 0;
}
int check_time(long offset)
	{
	struct tm tm1, tm2;
	time_t t1, t2;
	TINYCLR_SSL_TIME(&t1);
	t2 = t1 + offset;
	OPENSSL_gmtime(&t2, &tm2);
	OPENSSL_gmtime(&t1, &tm1);
	OPENSSL_gmtime_adj(&tm1, 0, offset);
	if ((tm1.tm_year == tm2.tm_year) &&
	    (tm1.tm_mon == tm2.tm_mon) &&
	    (tm1.tm_mday == tm2.tm_mday) &&
	    (tm1.tm_hour == tm2.tm_hour) &&
	    (tm1.tm_min == tm2.tm_min) &&
	    (tm1.tm_sec == tm2.tm_sec))
		return 1;
	TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "TIME ERROR!!\n");
	TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "Time1: %d/%d/%d, %d:%02d:%02d\n",
			tm2.tm_mday, tm2.tm_mon + 1, tm2.tm_year + 1900,
			tm2.tm_hour, tm2.tm_min, tm2.tm_sec);
	TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "Time2: %d/%d/%d, %d:%02d:%02d\n",
			tm1.tm_mday, tm1.tm_mon + 1, tm1.tm_year + 1900,
			tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
	return 0;
	}
Exemple #3
0
static int check_time(long offset)
{
    struct tm tm1, tm2, o1;
    int off_day, off_sec;
    long toffset;
    time_t t1, t2;

    time(&t1);

    t2 = t1 + offset;
    OPENSSL_gmtime(&t2, &tm2);
    OPENSSL_gmtime(&t1, &tm1);
    o1 = tm1;
    OPENSSL_gmtime_adj(&tm1, 0, offset);
    if (!TEST_int_eq(tm1.tm_year, tm2.tm_year)
        || !TEST_int_eq(tm1.tm_mon, tm2.tm_mon)
        || !TEST_int_eq(tm1.tm_mday, tm2.tm_mday)
        || !TEST_int_eq(tm1.tm_hour, tm2.tm_hour)
        || !TEST_int_eq(tm1.tm_min, tm2.tm_min)
        || !TEST_int_eq(tm1.tm_sec, tm2.tm_sec)
        || !TEST_true(OPENSSL_gmtime_diff(&off_day, &off_sec, &o1, &tm1)))
        return 0;
    toffset = (long)off_day * SECS_PER_DAY + off_sec;
    if (!TEST_long_eq(offset, toffset))
        return 0;
    return 1;
}
Exemple #4
0
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
	     time_t t, int offset_day, long offset_sec)
	{
	ASN1_GENERALIZEDTIME *alloced = NULL;

	char *p;
	struct tm *ts;
	struct tm data;
	size_t len = 20; 

	if (s == NULL)
		alloced = s=M_ASN1_GENERALIZEDTIME_new();
	if (s == NULL)
		return(NULL);

	ts=OPENSSL_gmtime(&t, &data);
	if (ts == NULL)
	{
		if(alloced)
			M_ASN1_GENERALIZEDTIME_free(alloced);
		return(NULL);
	}

	if (offset_day || offset_sec)
		{ 
		if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
			{
			if(alloced)
				M_ASN1_GENERALIZEDTIME_free(alloced);
			return NULL;
			}
		}

	p=(char *)s->data;
	if ((p == NULL) || ((size_t)s->length < len))
		{
		p= (char *) OPENSSL_malloc(len);
		if (p == NULL)
			{
			if(alloced)
				M_ASN1_GENERALIZEDTIME_free(alloced);
			ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ,
				ERR_R_MALLOC_FAILURE);
			return(NULL);
			}
		if (s->data != NULL)
			OPENSSL_free(s->data);
		s->data=(unsigned char *)p;
		}

	BIO_snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
		     ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
	s->length=op_strlen(p);
	s->type=V_ASN1_GENERALIZEDTIME;
#ifdef CHARSET_EBCDIC_not
	ebcdic2ascii(s->data, s->data, s->length);
#endif
	return(s);
	}
Exemple #5
0
ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
				int offset_day, long offset_sec)
	{
	char *p;
	struct tm *ts;
	struct tm data;
	size_t len = 20;
	int free_s = 0;

	if (s == NULL)
		{
		free_s = 1;
		s=M_ASN1_UTCTIME_new();
		}
	if (s == NULL)
		goto err;


	ts=OPENSSL_gmtime(&t, &data);
	if (ts == NULL)
		goto err;

	if (offset_day || offset_sec)
		{ 
		if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
			goto err;
		}

	if((ts->tm_year < 50) || (ts->tm_year >= 150))
		goto err;

	p=(char *)s->data;
	if ((p == NULL) || ((size_t)s->length < len))
		{
		p=OPENSSL_malloc(len);
		if (p == NULL)
			{
			ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE);
			goto err;
			}
		if (s->data != NULL)
			OPENSSL_free(s->data);
		s->data=(unsigned char *)p;
		}

	BIO_snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100,
		     ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
	s->length=strlen(p);
	s->type=V_ASN1_UTCTIME;
#ifdef CHARSET_EBCDIC_not
	ebcdic2ascii(s->data, s->data, s->length);
#endif
	return(s);
	err:
	if (free_s && s)
		M_ASN1_UTCTIME_free(s);
	return NULL;
	}
Exemple #6
0
int check_time(long offset)
	{
	struct tm tm1, tm2, o1;
	int off_day, off_sec;
	long toffset;
	time_t t1, t2;
	time(&t1);
	t2 = t1 + offset;
	OPENSSL_gmtime(&t2, &tm2);
	OPENSSL_gmtime(&t1, &tm1);
	o1 = tm1;
	OPENSSL_gmtime_adj(&tm1, 0, offset);
	if ((tm1.tm_year != tm2.tm_year) ||
	    (tm1.tm_mon != tm2.tm_mon) ||
	    (tm1.tm_mday != tm2.tm_mday) ||
	    (tm1.tm_hour != tm2.tm_hour) ||
	    (tm1.tm_min != tm2.tm_min) ||
	    (tm1.tm_sec != tm2.tm_sec))
		{
		fprintf(stderr, "TIME ERROR!!\n");
		fprintf(stderr, "Time1: %d/%d/%d, %d:%02d:%02d\n",
				tm2.tm_mday, tm2.tm_mon + 1, tm2.tm_year + 1900,
				tm2.tm_hour, tm2.tm_min, tm2.tm_sec);
		fprintf(stderr, "Time2: %d/%d/%d, %d:%02d:%02d\n",
				tm1.tm_mday, tm1.tm_mon + 1, tm1.tm_year + 1900,
				tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
		return 0;
		}
	OPENSSL_gmtime_diff(&o1, &tm1, &off_day, &off_sec);
	toffset = (long)off_day * SECS_PER_DAY + off_sec;
	if (offset != toffset)
		{
		fprintf(stderr, "TIME OFFSET ERROR!!\n");
		fprintf(stderr, "Expected %ld, Got %ld (%d:%d)\n",
					offset, toffset, off_day, off_sec);
		return 0;
		}
	return 1;
	}
Exemple #7
0
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
                                               time_t t, int offset_day,
                                               long offset_sec)
{
    char *p;
    struct tm *ts;
    struct tm data;
    size_t len = 20;
    ASN1_GENERALIZEDTIME *tmps = NULL;

    if (s == NULL)
        tmps = ASN1_GENERALIZEDTIME_new();
    else
        tmps = s;
    if (tmps == NULL)
        return NULL;

    ts = OPENSSL_gmtime(&t, &data);
    if (ts == NULL)
        goto err;

    if (offset_day || offset_sec) {
        if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
            goto err;
    }

    p = (char *)tmps->data;
    if ((p == NULL) || ((size_t)tmps->length < len)) {
        p = OPENSSL_malloc(len);
        if (p == NULL) {
            ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE);
            goto err;
        }
        OPENSSL_free(tmps->data);
        tmps->data = (unsigned char *)p;
    }

    BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900,
                 ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min,
                 ts->tm_sec);
    tmps->length = strlen(p);
    tmps->type = V_ASN1_GENERALIZEDTIME;
#ifdef CHARSET_EBCDIC_not
    ebcdic2ascii(tmps->data, tmps->data, tmps->length);
#endif
    return tmps;
 err:
    if (s == NULL)
        ASN1_GENERALIZEDTIME_free(tmps);
    return NULL;
}
Exemple #8
0
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
{
    struct tm *ts;
    struct tm data;

    ts = OPENSSL_gmtime(&t, &data);
    if (ts == NULL) {
        ASN1err(ASN1_F_ASN1_TIME_SET, ASN1_R_ERROR_GETTING_TIME);
        return NULL;
    }
    if ((ts->tm_year >= 50) && (ts->tm_year < 150))
        return ASN1_UTCTIME_set(s, t);
    return ASN1_GENERALIZEDTIME_set(s, t);
}
Exemple #9
0
int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm)
{
    if (s == NULL) {
        time_t now_t;

        time(&now_t);
        memset(tm, 0, sizeof(*tm));
        if (OPENSSL_gmtime(&now_t, tm) != NULL)
            return 1;
        return 0;
    }

    return asn1_time_to_tm(tm, s);
}
Exemple #10
0
ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
                         int offset_day, long offset_sec)
{
    struct tm *ts;
    struct tm data;

    ts = OPENSSL_gmtime(&t, &data);
    if (ts == NULL) {
        ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME);
        return NULL;
    }
    if (offset_day || offset_sec) {
        if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
            return NULL;
    }
    return asn1_time_from_tm(s, ts, V_ASN1_UNDEF);
}
Exemple #11
0
static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t)
{
    if (t == NULL) {
        time_t now_t;
        time(&now_t);
        if (OPENSSL_gmtime(&now_t, tm))
            return 1;
        return 0;
    }

    if (t->type == V_ASN1_UTCTIME)
        return asn1_utctime_to_tm(tm, t);
    else if (t->type == V_ASN1_GENERALIZEDTIME)
        return asn1_generalizedtime_to_tm(tm, t);

    return 0;
}
Exemple #12
0
int ASN1_UTCTIME_cmp_time_t (const ASN1_UTCTIME * s, time_t t)
{
    struct tm *tm;

    struct tm data;

    int offset;

    int year;

#define g2(p) (((p)[0]-'0')*10+(p)[1]-'0')

    if (s->data[12] == 'Z')
        offset = 0;
    else
    {
        offset = g2 (s->data + 13) * 60 + g2 (s->data + 15);
        if (s->data[12] == '-')
            offset = -offset;
    }

    t -= offset * 60;            /* FIXME: may overflow in extreme cases */

    tm = OPENSSL_gmtime (&t, &data);
    /* NB: -1, 0, 1 already valid return values so use -2 to
     * indicate error.
     */
    if (tm == NULL)
        return -2;

#define return_cmp(a,b) if ((a)<(b)) return -1; else if ((a)>(b)) return 1
    year = g2 (s->data);
    if (year < 50)
        year += 100;
    return_cmp (year, tm->tm_year);
    return_cmp (g2 (s->data + 2) - 1, tm->tm_mon);
    return_cmp (g2 (s->data + 4), tm->tm_mday);
    return_cmp (g2 (s->data + 6), tm->tm_hour);
    return_cmp (g2 (s->data + 8), tm->tm_min);
    return_cmp (g2 (s->data + 10), tm->tm_sec);
#undef g2
#undef return_cmp

    return 0;
}
Exemple #13
0
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
                                               time_t t, int offset_day,
                                               long offset_sec)
{
    struct tm *ts;
    struct tm data;

    ts = OPENSSL_gmtime(&t, &data);
    if (ts == NULL)
        return NULL;

    if (offset_day || offset_sec) {
        if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
            return NULL;
    }

    return asn1_time_from_tm(s, ts, V_ASN1_GENERALIZEDTIME);
}
Exemple #14
0
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
	     time_t t, int offset_day, long offset_sec)
	{
	char *p;
	struct tm *ts;
	struct tm data;
	size_t len = 20; 

	if (s == NULL)
		s=M_ASN1_GENERALIZEDTIME_new();
	if (s == NULL)
		return(NULL);

	ts=OPENSSL_gmtime(&t, &data);
	if (ts == NULL)
		return(NULL);

	if (offset_day || offset_sec)
		{ 
		if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
			return NULL;
		}

	p=(char *)s->data;
	if ((p == NULL) || ((size_t)s->length < len))
		{
		p=OPENSSL_malloc(len);
		if (p == NULL)
			{
			OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
			return(NULL);
			}
		if (s->data != NULL)
			OPENSSL_free(s->data);
		s->data=(unsigned char *)p;
		}

	BIO_snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
		     ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
	s->length=strlen(p);
	s->type=V_ASN1_GENERALIZEDTIME;
	return(s);
	}
Exemple #15
0
ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
                         int offset_day, long offset_sec)
{
    struct tm *ts;
    struct tm data;

    ts = OPENSSL_gmtime(&t, &data);
    if (ts == NULL) {
        ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME);
        return NULL;
    }
    if (offset_day || offset_sec) {
        if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
            return NULL;
    }
    if ((ts->tm_year >= 50) && (ts->tm_year < 150))
        return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec);
    return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec);
}
Exemple #16
0
int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t)
{
    struct tm stm, ttm;
    int day, sec;

    if (!ASN1_TIME_to_tm(s, &stm))
        return -2;

    if (!OPENSSL_gmtime(&t, &ttm))
        return -2;

    if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm))
        return -2;

    if (day > 0 || sec > 0)
        return 1;
    if (day < 0 || sec < 0)
        return -1;
    return 0;
}
Exemple #17
0
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
	     time_t t)
	{
	char *p;
	struct tm *ts;
	struct tm data;
	size_t len = 20; 

	if (s == NULL)
		s=M_ASN1_GENERALIZEDTIME_new();
	if (s == NULL)
		return(NULL);

	ts=OPENSSL_gmtime(&t, &data);
	if (ts == NULL)
		return(NULL);

	p=(char *)s->data;
	if ((p == NULL) || ((size_t)s->length < len))
		{
		p=OPENSSL_malloc(len);
		if (p == NULL)
			{
			ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_SET,
				ERR_R_MALLOC_FAILURE);
			return(NULL);
			}
		if (s->data != NULL)
			OPENSSL_free(s->data);
		s->data=(unsigned char *)p;
		}

	BIO_snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
		     ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
	s->length=strlen(p);
	s->type=V_ASN1_GENERALIZEDTIME;
#ifdef CHARSET_EBCDIC_not
	ebcdic2ascii(s->data, s->data, s->length);
#endif
	return(s);
	}
Exemple #18
0
int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
{
    struct tm stm, ttm;
    int day, sec;

    if (!asn1_utctime_to_tm(&stm, s))
        return -2;

    if (!OPENSSL_gmtime(&t, &ttm))
        return -2;

    if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm))
        return -2;

    if (day > 0)
        return 1;
    if (day < 0)
        return -1;
    if (sec > 0)
        return 1;
    if (sec < 0)
        return -1;
    return 0;
}