Example #1
0
ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
	     long length)
	{
	ASN1_UTCTIME *ret=NULL;

	ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
		V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
	if (ret == NULL)
		{
		ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR);
		return(NULL);
		}
#ifdef CHARSET_EBCDIC
	ascii2ebcdic(ret->data, ret->data, ret->length);
#endif
	if (!ASN1_UTCTIME_check(ret))
		{
		ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT);
		goto err;
		}

	return(ret);
err:
	if ((ret != NULL) && ((a == NULL) || (*a != ret)))
		M_ASN1_UTCTIME_free(ret);
	return(NULL);
	}
Example #2
0
static int get_days_remaining(ASN1_UTCTIME *tm)
{
    apr_time_t then, now = apr_time_now();
    apr_time_exp_t exp = {0};
    int diff;

    /* Fail if the time isn't a valid ASN.1 UTCTIME; RFC3280 mandates
     * that the seconds digits are present even though ASN.1
     * doesn't. */
    if (tm->length < 11 || !ASN1_UTCTIME_check(tm))
        return 0;

    exp.tm_year = DIGIT2NUM(tm->data);
    exp.tm_mon  = DIGIT2NUM(tm->data + 2) - 1;
    exp.tm_mday = DIGIT2NUM(tm->data + 4) + 1;
    exp.tm_hour = DIGIT2NUM(tm->data + 6);
    exp.tm_min  = DIGIT2NUM(tm->data + 8);
    exp.tm_sec  = DIGIT2NUM(tm->data + 10);

    if (exp.tm_year <= 50)
        exp.tm_year += 100;
    if (apr_time_exp_gmt_get(&then, &exp) != APR_SUCCESS)
        return 0;

    diff = (int)((apr_time_sec(then) - apr_time_sec(now)) / (60*60*24));
    return diff > 0 ? diff : 0;
}
Example #3
0
int64_t sln_asn1_time_to_timestamp(ASN1_UTCTIME *tm) {
    int64_t rv = 0;
    /* Converts a ASN1_UTCTIME to an int64_t of seconds since 1970.  Returns 0 on
     * failure. */
    time_exp_t exp = {0};

    /* Fail if the time isn't a valid ASN.1 UTCTIME; RFC3280 mandates
    * that the seconds digits are present even though ASN.1
    * doesn't. */
    if (tm->length < 11 || !ASN1_UTCTIME_check(tm)) {
        return 0;
    }

    exp.tm_year = DIGIT2NUM(tm->data);
    exp.tm_mon = DIGIT2NUM(tm->data + 2) - 1;
    exp.tm_mday = DIGIT2NUM(tm->data + 4) + 1;
    exp.tm_hour = DIGIT2NUM(tm->data + 6);
    exp.tm_min = DIGIT2NUM(tm->data + 8);
    exp.tm_sec = DIGIT2NUM(tm->data + 10);

    if (exp.tm_year <= 50) {
        exp.tm_year += 100;
    }

    time_exp_gmt_get(&rv, &exp);

    return rv;
}
Example #4
0
int ASN1_TIME_check(ASN1_TIME *t)
  {
  if (t->type == V_ASN1_GENERALIZEDTIME)
    return ASN1_GENERALIZEDTIME_check(t);
  else if (t->type == V_ASN1_UTCTIME)
    return ASN1_UTCTIME_check(t);
  return 0;
  }
Example #5
0
int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
{
    ASN1_UTCTIME t;

    t.type = V_ASN1_UTCTIME;
    t.length = strlen(str);
    t.data = (unsigned char *)str;
    if (ASN1_UTCTIME_check(&t)) {
        if (s != NULL) {
            if (!ASN1_STRING_set((ASN1_STRING *)s, str, t.length))
                return 0;
            s->type = V_ASN1_UTCTIME;
        }
        return (1);
    } else
        return (0);
}
Example #6
0
ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
                               long length)
{
    ASN1_UTCTIME *ret = NULL;

    ret = (ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a, pp, length,
                                         V_ASN1_UTCTIME, V_ASN1_UNIVERSAL);
    if (ret == NULL) {
        OPENSSL_PUT_ERROR(ASN1, ERR_R_NESTED_ASN1_ERROR);
        return (NULL);
    }
    if (!ASN1_UTCTIME_check(ret)) {
        OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT);
        goto err;
    }

    return (ret);
 err:
    if ((ret != NULL) && ((a == NULL) || (*a != ret)))
        M_ASN1_UTCTIME_free(ret);
    return (NULL);
}
Example #7
0
		inline bool utctime::check() const
		{
			return (ASN1_UTCTIME_check(ptr().get()) != 0);
		}