*********************************************************************/
static int host_to_hash(struct client_state *csp)
{
- int ret = 0;
- size_t i;
-
SHA256((unsigned char *)csp->http->host, strlen(csp->http->host),
csp->http->hash_of_host);
- /* Converting hash into string with hex */
- for (i = 0; i < HASH_OF_HOST_BUF_SIZE; i++)
- {
- if ((ret = sprintf((char *)csp->http->hash_of_host_hex + 2 * i, "%02x",
- csp->http->hash_of_host[i])) < 0)
- {
- log_error(LOG_LEVEL_ERROR, "Sprintf return value: %d", ret);
- return -1;
- }
- }
+ return create_hexadecimal_hash_of_host(csp);
- return 0;
}
*********************************************************************/
static int host_to_hash(struct client_state *csp)
{
- int ret;
- size_t i;
-
mbedtls_sha256((unsigned char *)csp->http->host,
strlen(csp->http->host), csp->http->hash_of_host, 0);
- /* Converting hash into string with hex */
- for (i = 0; i < HASH_OF_HOST_BUF_SIZE; i++)
- {
- if ((ret = sprintf((char *)csp->http->hash_of_host_hex + 2 * i, "%02x",
- csp->http->hash_of_host[i])) < 0)
- {
- log_error(LOG_LEVEL_ERROR, "Sprintf return value: %d", ret);
- return -1;
- }
- }
-
- return 0;
+ return create_hexadecimal_hash_of_host(csp);
}
return 0;
}
+
+
+/*********************************************************************
+ *
+ * Function : create_hexadecimal_hash_of_host
+ *
+ * Description : Converts the binary hash of a host into a
+ * hexadecimal string.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ *
+ * Returns : -1 => Error while creating hash
+ * 0 => Hash created successfully
+ *
+ *********************************************************************/
+int create_hexadecimal_hash_of_host(struct client_state *csp)
+{
+ int i;
+ int ret;
+
+ for (i = 0; i < HASH_OF_HOST_BUF_SIZE; i++)
+ {
+ ret = sprintf((char *)csp->http->hash_of_host_hex + 2 * i, "%02x",
+ csp->http->hash_of_host[i]);
+ if (ret < 0)
+ {
+ log_error(LOG_LEVEL_ERROR, "sprintf() return value: %d", ret);
+ return -1;
+ }
+ }
+
+ return 0;
+
+}
extern int get_certificate_valid_from_date(char *buffer, size_t buffer_size, const char *fmt);
extern int get_certificate_valid_to_date(char *buffer, size_t buffer_size, const char *fmt);
extern int enforce_sane_certificate_state(const char *certificate, const char *key);
+extern int create_hexadecimal_hash_of_host(struct client_state *csp);
#endif /* ndef SSL_COMMON_H_INCLUDED */
static int host_to_hash(struct client_state *csp)
{
int ret;
- size_t i;
ret = wc_Sha256Hash((const byte *)csp->http->host,
(word32)strlen(csp->http->host), (byte *)csp->http->hash_of_host);
return -1;
}
- /* Converting hash into string with hex */
- for (i = 0; i < HASH_OF_HOST_BUF_SIZE; i++)
- {
- ret = snprintf((char *)csp->http->hash_of_host_hex + 2 * i,
- sizeof(csp->http->hash_of_host_hex) - 2 * i,
- "%02x", csp->http->hash_of_host[i]);
- if (ret < 0)
- {
- log_error(LOG_LEVEL_ERROR, "sprintf() failed. Return value: %d", ret);
- return -1;
- }
- }
-
- return 0;
+ return create_hexadecimal_hash_of_host(csp);
}