Example #1
0
static ASN1_UTCTIME *
ASN1_UTCTIME_adj_internal(ASN1_UTCTIME *s, time_t t, int offset_day,
    long offset_sec)
{
	char *p;
	struct tm *ts;
	struct tm data;

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

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

	if ((p = utctime_string_from_tm(ts)) == NULL) {
		ASN1err(ASN1_F_ASN1_UTCTIME_ADJ, ERR_R_MALLOC_FAILURE);
		return (NULL);
	}
	free(s->data);
	s->data = p;
	s->length = strlen(p);

	s->type = V_ASN1_UTCTIME;
	return (s);
}
Example #2
0
static ASN1_TIME *
ASN1_TIME_adj_internal(ASN1_TIME *s, time_t t, int offset_day, long offset_sec,
    int mode)
{
	int allocated = 0;
	struct tm tm;
	size_t len;
	char * p;

 	if (gmtime_r(&t, &tm) == NULL)
 		return (NULL);

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

	switch (mode) {
	case V_ASN1_UTCTIME:
		p = utctime_string_from_tm(&tm);
		break;
	case V_ASN1_GENERALIZEDTIME:
		p = gentime_string_from_tm(&tm);
		break;
	case RFC5280:
		p = rfc5280_string_from_tm(&tm);
		break;
	default:
		return (NULL);
	}
	if (p == NULL) {
		ASN1error(ASN1_R_ILLEGAL_TIME_VALUE);
		return (NULL);
	}

	if (s == NULL) {
		if ((s = ASN1_TIME_new()) == NULL)
			return (NULL);
		allocated = 1;
	}

	len = strlen(p);
	switch (len) {
	case GENTIME_LENGTH:
		s->type = V_ASN1_GENERALIZEDTIME;
		break;
 	case UTCTIME_LENGTH:
		s->type = V_ASN1_UTCTIME;
		break;
	default:
		if (allocated)
			ASN1_TIME_free(s);
		free(p);
		return (NULL);
	}
	free(s->data);
	s->data = p;
	s->length = len;
	return (s);
}
Example #3
0
/* Format a time correctly for an X509 object as per RFC 5280 */
char *
rfc5280_string_from_tm(struct tm *tm)
{
	char *ret = NULL;
	int year;

	year = tm->tm_year + 1900;
	if (year < 1950 || year > 9999)
		return (NULL);

	if (year < 2050)
		ret = utctime_string_from_tm(tm);
	else
		ret = gentime_string_from_tm(tm);

	return (ret);
}