mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
vtls: move md5sum into the Curl_ssl struct
The MD5 summing is also an SSL backend-specific function. So let's include it, offering the previous fall-back code as a separate function now: Curl_none_md5sum(). To allow for that, the signature had to be changed so that an error could be returned from the implementation (Curl_none_md5sum() can run out of memory). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
parent
52e8237bfc
commit
e35205a0c4
@ -721,7 +721,8 @@ const struct Curl_ssl Curl_ssl_axtls = {
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_none_false_start /* false_start */
|
||||
Curl_none_false_start, /* false_start */
|
||||
Curl_none_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_axtls;
|
||||
|
@ -970,7 +970,8 @@ const struct Curl_ssl Curl_ssl_cyassl = {
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_none_false_start /* false_start */
|
||||
Curl_none_false_start, /* false_start */
|
||||
Curl_none_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_cyassl;
|
||||
|
@ -2723,13 +2723,14 @@ CURLcode Curl_darwinssl_random(struct Curl_easy *data UNUSED_PARAM,
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_darwinssl_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len)
|
||||
static CURLcode Curl_darwinssl_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len)
|
||||
{
|
||||
(void)md5len;
|
||||
(void)CC_MD5(tmp, (CC_LONG)tmplen, md5sum);
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_darwinssl_sha256sum(const unsigned char *tmp, /* input */
|
||||
@ -2875,7 +2876,8 @@ const struct Curl_ssl Curl_ssl_darwinssl = {
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_darwinssl_false_start /* false_start */
|
||||
Curl_darwinssl_false_start, /* false_start */
|
||||
Curl_darwinssl_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_darwinssl;
|
||||
|
@ -44,10 +44,6 @@ bool Curl_darwinssl_data_pending(const struct connectdata *conn,
|
||||
|
||||
CURLcode Curl_darwinssl_random(struct Curl_easy *data, unsigned char *entropy,
|
||||
size_t length);
|
||||
void Curl_darwinssl_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len);
|
||||
void Curl_darwinssl_sha256sum(const unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *sha256sum, /* output */
|
||||
@ -78,7 +74,6 @@ extern const struct Curl_ssl Curl_ssl_darwinssl;
|
||||
#define have_curlssl_pinnedpubkey 1
|
||||
#endif /* DARWIN_SSL_PINNEDPUBKEY */
|
||||
|
||||
#define curlssl_md5sum(a,b,c,d) Curl_darwinssl_md5sum(a,b,c,d)
|
||||
#define curlssl_sha256sum(a,b,c,d) Curl_darwinssl_sha256sum(a, b, c, d)
|
||||
|
||||
#endif /* USE_DARWINSSL */
|
||||
|
@ -1354,7 +1354,8 @@ const struct Curl_ssl Curl_ssl_gskit = {
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_none_false_start /* false_start */
|
||||
Curl_none_false_start, /* false_start */
|
||||
Curl_none_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_gskit;
|
||||
|
@ -1738,10 +1738,10 @@ CURLcode Curl_gtls_random(struct Curl_easy *data,
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_gtls_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len)
|
||||
static CURLcode Curl_gtls_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len)
|
||||
{
|
||||
#if defined(USE_GNUTLS_NETTLE)
|
||||
struct md5_ctx MD5pw;
|
||||
@ -1755,6 +1755,7 @@ void Curl_gtls_md5sum(unsigned char *tmp, /* input */
|
||||
memcpy(md5sum, gcry_md_read(MD5pw, 0), md5len);
|
||||
gcry_md_close(MD5pw);
|
||||
#endif
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_gtls_sha256sum(const unsigned char *tmp, /* input */
|
||||
@ -1804,7 +1805,8 @@ const struct Curl_ssl Curl_ssl_gnutls = {
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_none_false_start /* false_start */
|
||||
Curl_none_false_start, /* false_start */
|
||||
Curl_gtls_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_gnutls;
|
||||
|
@ -46,10 +46,6 @@ int Curl_gtls_shutdown(struct connectdata *conn, int sockindex);
|
||||
CURLcode Curl_gtls_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
void Curl_gtls_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len);
|
||||
void Curl_gtls_sha256sum(const unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *sha256sum, /* output */
|
||||
@ -74,7 +70,6 @@ extern const struct Curl_ssl Curl_ssl_gnutls;
|
||||
/* this backend supports CURLOPT_PINNEDPUBLICKEY */
|
||||
#define have_curlssl_pinnedpubkey 1
|
||||
|
||||
#define curlssl_md5sum(a,b,c,d) Curl_gtls_md5sum(a,b,c,d)
|
||||
#define curlssl_sha256sum(a,b,c,d) Curl_gtls_sha256sum(a,b,c,d)
|
||||
|
||||
#endif /* USE_GNUTLS */
|
||||
|
@ -1026,7 +1026,8 @@ const struct Curl_ssl Curl_ssl_mbedtls = {
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_none_false_start /* false_start */
|
||||
Curl_none_false_start, /* false_start */
|
||||
Curl_none_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_mbedtls;
|
||||
|
@ -2278,10 +2278,10 @@ CURLcode Curl_nss_random(struct Curl_easy *data,
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_nss_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len)
|
||||
static CURLcode Curl_nss_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len)
|
||||
{
|
||||
PK11Context *MD5pw = PK11_CreateDigestContext(SEC_OID_MD5);
|
||||
unsigned int MD5out;
|
||||
@ -2289,6 +2289,8 @@ void Curl_nss_md5sum(unsigned char *tmp, /* input */
|
||||
PK11_DigestOp(MD5pw, tmp, curlx_uztoui(tmplen));
|
||||
PK11_DigestFinal(MD5pw, md5sum, &MD5out, curlx_uztoui(md5len));
|
||||
PK11_DestroyContext(MD5pw, PR_TRUE);
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_nss_sha256sum(const unsigned char *tmp, /* input */
|
||||
@ -2343,7 +2345,8 @@ const struct Curl_ssl Curl_ssl_nss = {
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_nss_false_start /* false_start */
|
||||
Curl_nss_false_start, /* false_start */
|
||||
Curl_nss_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_nss;
|
||||
|
@ -51,11 +51,6 @@ CURLcode Curl_nss_random(struct Curl_easy *data,
|
||||
unsigned char *entropy,
|
||||
size_t length);
|
||||
|
||||
void Curl_nss_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len);
|
||||
|
||||
void Curl_nss_sha256sum(const unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *sha256sum, /* output */
|
||||
@ -82,7 +77,6 @@ extern const struct Curl_ssl Curl_ssl_nss;
|
||||
/* this backends supports CURLOPT_PINNEDPUBLICKEY */
|
||||
#define have_curlssl_pinnedpubkey 1
|
||||
|
||||
#define curlssl_md5sum(a,b,c,d) Curl_nss_md5sum(a,b,c,d)
|
||||
#define curlssl_sha256sum(a,b,c,d) Curl_nss_sha256sum(a,b,c,d)
|
||||
|
||||
#endif /* USE_NSS */
|
||||
|
@ -3350,16 +3350,17 @@ CURLcode Curl_ossl_random(struct Curl_easy *data, unsigned char *entropy,
|
||||
return (rc == 1 ? CURLE_OK : CURLE_FAILED_INIT);
|
||||
}
|
||||
|
||||
void Curl_ossl_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum /* output */,
|
||||
size_t unused)
|
||||
static CURLcode Curl_ossl_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum /* output */,
|
||||
size_t unused)
|
||||
{
|
||||
MD5_CTX MD5pw;
|
||||
(void)unused;
|
||||
MD5_Init(&MD5pw);
|
||||
MD5_Update(&MD5pw, tmp, tmplen);
|
||||
MD5_Final(md5sum, &MD5pw);
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_SHA256)
|
||||
@ -3405,7 +3406,8 @@ const struct Curl_ssl Curl_ssl_openssl = {
|
||||
Curl_ossl_set_engine, /* set_engine */
|
||||
Curl_ossl_set_engine_default, /* set_engine_default */
|
||||
Curl_ossl_engines_list, /* engines_list */
|
||||
Curl_none_false_start /* false_start */
|
||||
Curl_none_false_start, /* false_start */
|
||||
Curl_ossl_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_openssl;
|
||||
|
@ -68,10 +68,6 @@ bool Curl_ossl_data_pending(const struct connectdata *conn,
|
||||
/* return 0 if a find random is filled in */
|
||||
CURLcode Curl_ossl_random(struct Curl_easy *data, unsigned char *entropy,
|
||||
size_t length);
|
||||
void Curl_ossl_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum /* output */,
|
||||
size_t unused);
|
||||
void Curl_ossl_sha256sum(const unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *sha256sum /* output */,
|
||||
@ -99,7 +95,6 @@ extern const struct Curl_ssl Curl_ssl_openssl;
|
||||
/* this backend supports CURLOPT_PINNEDPUBLICKEY */
|
||||
#define have_curlssl_pinnedpubkey 1
|
||||
|
||||
#define curlssl_md5sum(a,b,c,d) Curl_ossl_md5sum(a,b,c,d)
|
||||
#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_SHA256)
|
||||
#define curlssl_sha256sum(a,b,c,d) Curl_ossl_sha256sum(a,b,c,d)
|
||||
#endif
|
||||
|
@ -892,7 +892,8 @@ const struct Curl_ssl Curl_ssl_polarssl = {
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_none_false_start /* false_start */
|
||||
Curl_none_false_start, /* false_start */
|
||||
Curl_none_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_polarssl;
|
||||
|
@ -1745,7 +1745,8 @@ const struct Curl_ssl Curl_ssl_schannel = {
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_none_false_start /* false_start */
|
||||
Curl_none_false_start, /* false_start */
|
||||
Curl_none_md5sum /* md5sum */
|
||||
};
|
||||
|
||||
const struct Curl_ssl *Curl_ssl = &Curl_ssl_schannel;
|
||||
|
@ -938,20 +938,7 @@ CURLcode Curl_ssl_md5sum(unsigned char *tmp, /* input */
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len)
|
||||
{
|
||||
#ifdef curlssl_md5sum
|
||||
curlssl_md5sum(tmp, tmplen, md5sum, md5len);
|
||||
#else
|
||||
MD5_context *MD5pw;
|
||||
|
||||
(void) md5len;
|
||||
|
||||
MD5pw = Curl_MD5_init(Curl_DIGEST_MD5);
|
||||
if(!MD5pw)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
Curl_MD5_update(MD5pw, tmp, curlx_uztoui(tmplen));
|
||||
Curl_MD5_final(MD5pw, md5sum);
|
||||
#endif
|
||||
return CURLE_OK;
|
||||
return Curl_ssl->md5sum(tmp, tmplen, md5sum, md5len);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1055,4 +1042,19 @@ bool Curl_none_false_start(void)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CURLcode Curl_none_md5sum(unsigned char *input, size_t inputlen,
|
||||
unsigned char *md5sum, size_t md5len UNUSED_PARAM)
|
||||
{
|
||||
MD5_context *MD5pw;
|
||||
|
||||
(void)md5len;
|
||||
|
||||
MD5pw = Curl_MD5_init(Curl_DIGEST_MD5);
|
||||
if(!MD5pw)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
Curl_MD5_update(MD5pw, input, curlx_uztoui(inputlen));
|
||||
Curl_MD5_final(MD5pw, md5sum);
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#endif /* USE_SSL */
|
||||
|
@ -54,6 +54,9 @@ struct Curl_ssl {
|
||||
struct curl_slist *(*engines_list)(struct Curl_easy *data);
|
||||
|
||||
bool (*false_start)(void);
|
||||
|
||||
CURLcode (*md5sum)(unsigned char *input, size_t inputlen,
|
||||
unsigned char *md5sum, size_t md5sumlen);
|
||||
};
|
||||
|
||||
#ifdef USE_SSL
|
||||
@ -74,6 +77,8 @@ CURLcode Curl_none_set_engine(struct Curl_easy *data, const char *engine);
|
||||
CURLcode Curl_none_set_engine_default(struct Curl_easy *data);
|
||||
struct curl_slist *Curl_none_engines_list(struct Curl_easy *data);
|
||||
bool Curl_none_false_start(void);
|
||||
CURLcode Curl_none_md5sum(unsigned char *input, size_t inputlen,
|
||||
unsigned char *md5sum, size_t md5len);
|
||||
|
||||
#include "openssl.h" /* OpenSSL versions */
|
||||
#include "gtls.h" /* GnuTLS versions */
|
||||
|
Loading…
Reference in New Issue
Block a user