MCPcopy Create free account
hub / github.com/apache/httpd / ssl_var_lookup_ssl_cert_remain

Function ssl_var_lookup_ssl_cert_remain

modules/ssl/ssl_engine_vars.c:691–737  ·  view source on GitHub ↗

Return a string giving the number of days remaining until 'tm', or * "0" if this can't be determined. */

Source from the content-addressed store, hash-verified

689/* Return a string giving the number of days remaining until 'tm', or
690 * "0" if this can't be determined. */
691static char *ssl_var_lookup_ssl_cert_remain(apr_pool_t *p, const ASN1_TIME *tm)
692{
693#if OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined(LIBRESSL_VERSION_NUMBER)
694 int diff;
695
696 if (ASN1_TIME_check(tm) != 1 || ASN1_TIME_diff(&diff, NULL, NULL, tm) != 1) {
697 return "0";
698 }
699#else
700 apr_time_t then, now = apr_time_now();
701 apr_time_exp_t exp = {0};
702 long diff;
703 unsigned char *dp;
704
705 /* Fail if the time isn't a valid ASN.1 TIME; RFC3280 mandates
706 * that the seconds digits are present even though ASN.1
707 * doesn't. */
708 if ((tm->type == V_ASN1_UTCTIME && tm->length < 11) ||
709 (tm->type == V_ASN1_GENERALIZEDTIME && tm->length < 13) ||
710 !ASN1_TIME_check(tm)) {
711 return apr_pstrdup(p, "0");
712 }
713
714 if (tm->type == V_ASN1_UTCTIME) {
715 exp.tm_year = DIGIT2NUM(tm->data);
716 if (exp.tm_year <= 50) exp.tm_year += 100;
717 dp = tm->data + 2;
718 } else {
719 exp.tm_year = DIGIT2NUM(tm->data) * 100 + DIGIT2NUM(tm->data + 2) - 1900;
720 dp = tm->data + 4;
721 }
722
723 exp.tm_mon = DIGIT2NUM(dp) - 1;
724 exp.tm_mday = DIGIT2NUM(dp + 2) + 1;
725 exp.tm_hour = DIGIT2NUM(dp + 4);
726 exp.tm_min = DIGIT2NUM(dp + 6);
727 exp.tm_sec = DIGIT2NUM(dp + 8);
728
729 if (apr_time_exp_gmt_get(&then, &exp) != APR_SUCCESS) {
730 return apr_pstrdup(p, "0");
731 }
732
733 diff = (long)((apr_time_sec(then) - apr_time_sec(now)) / (60*60*24));
734#endif
735
736 return diff > 0 ? apr_ltoa(p, diff) : apr_pstrdup(p, "0");
737}
738
739static char *ssl_var_lookup_ssl_cert_serial(apr_pool_t *p, X509 *xs)
740{

Callers 1

ssl_var_lookup_ssl_certFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected