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))
            return 1;
        return 0;
    }

    if (s->type == V_ASN1_UTCTIME) {
        memset(tm, 0, sizeof(*tm));
        return asn1_utctime_to_tm(tm, s);
    }
    if (s->type == V_ASN1_GENERALIZEDTIME) {
        memset(tm, 0, sizeof(*tm));
        return asn1_generalizedtime_to_tm(tm, s);
    }

    return 0;
}