static int est_strcasecmp_s (char *s1, char *s2) { errno_t safec_rc; int diff; safec_rc = strcasecmp_s(s1, strnlen_s(s1, RSIZE_MAX_STR), s2, &diff); if (safec_rc != EOK) { /* * Log that we encountered a SafeC error */ EST_LOG_INFO("strcasecmp_s error 0x%xO\n", safec_rc); } return diff; }
unsigned MATCHESZ(const char *lhs, const char *rhs) { return strcasecmp_s(lhs, rhs) == 0; }
/* * This function takes in the list of headers that were in the server's * response, it walks through the headers looking for a Retry-After response * header. If one is found, the value is parsed and saved away in the EST * context. This value can be in one of two formats, both are represented as * an ASCII string. The first format can be a count of the number of seconds * the client should wait before retrying the request. The second format is a * time/date stamp of the point in time at which the client should retry the * request. The result of this function is the setting of the retry_after * values in the context. If no retry-after header was received, or was * received and could not be parsed, the values will be zero, otherwise, they * are set to the value received. * * NOTE: The EST client currently does not support the time/date format * response and will not process a response in this format. */ static EST_ERROR est_io_parse_http_retry_after_resp (EST_CTX *ctx, HTTP_HEADER *hdrs, int hdr_cnt) { EST_ERROR rv = EST_ERR_INVALID_RETRY_VALUE; int i; int cmp_result, diff; int rc; long long int temp_ll; int found = 0; /* * Initialize assuming there was no retry-after header. */ ctx->retry_after_delay = 0; ctx->retry_after_date = 0; for (i = 0; i < hdr_cnt; i++) { cmp_result = strcasecmp_s(hdrs[i].name, sizeof(EST_HTTP_HDR_RETRY_AFTER), EST_HTTP_HDR_RETRY_AFTER, &diff); if (cmp_result == EOK && !diff) { EST_LOG_INFO("Retry-After value = %s", hdrs[i].value); found = 1; /* * Determine whether or not the value is a date/time string * or is an integer representing the number of seconds * that the client must wait. */ if (isalpha(*(char *)hdrs[i].value)) { #ifdef RETRY_AFTER_DELAY_TIME_SUPPORT int rc; /* * Convert the date/time string into a time_t */ rc = parsedate(hdrs[i].value, &ctx->retry_after_date); if (rc != PARSEDATE_OK) { EST_LOG_ERR("Retry-After value could not be parsed"); } #else /* * This format is not currently supported. */ EST_LOG_ERR("Retry-After value not in the correct format"); #endif } else { /* * make sure it's all digits, make sure it's no larger than a * four byte integer, and cache away the value returned for * the retry delay. */ rc = strisdigit_s(hdrs[i].value, 10); // max of 10 decimal places if (rc) { temp_ll = atoll(hdrs[i].value); if (temp_ll <= INT_MAX) { ctx->retry_after_delay = (int) temp_ll; rv = EST_ERR_CA_ENROLL_RETRY; } else { EST_LOG_ERR("Retry-After value too large"); } } else { EST_LOG_ERR("Retry-After value could not be parsed"); } } } } if (found == 0) { EST_LOG_ERR("Retry-After header missing"); } return rv; }