]> granicus.if.org Git - curl/commitdiff
vtls: move sha256sum into the Curl_ssl struct
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 22 Jun 2017 23:04:56 +0000 (01:04 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 28 Aug 2017 12:56:56 +0000 (14:56 +0200)
The SHA-256 checksumming is also an SSL backend-specific function.
Let's include it in the struct declaring the functionality of SSL
backends.

In contrast to MD5, there is no fall-back code. To indicate this, the
respective entries are NULL for those backends that offer no support for
SHA-256 checksumming.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
19 files changed:
lib/vtls/axtls.c
lib/vtls/cyassl.c
lib/vtls/cyassl.h
lib/vtls/darwinssl.c
lib/vtls/darwinssl.h
lib/vtls/gskit.c
lib/vtls/gtls.c
lib/vtls/gtls.h
lib/vtls/mbedtls.c
lib/vtls/mbedtls.h
lib/vtls/nss.c
lib/vtls/nssg.h
lib/vtls/openssl.c
lib/vtls/openssl.h
lib/vtls/polarssl.c
lib/vtls/polarssl.h
lib/vtls/schannel.c
lib/vtls/vtls.c
lib/vtls/vtls.h

index 138a80ade80e40f3615bf0fd41deb40d871ed221..3446dac446d4fb8e373269bed8de4aef30c0ce9a 100644 (file)
@@ -722,7 +722,8 @@ const struct Curl_ssl Curl_ssl_axtls = {
   Curl_none_set_engine_default,   /* set_engine_default */
   Curl_none_engines_list,         /* engines_list */
   Curl_none_false_start,          /* false_start */
-  Curl_none_md5sum                /* md5sum */
+  Curl_none_md5sum,               /* md5sum */
+  NULL                            /* sha256sum */
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_axtls;
index 74052318fd2ac6b1386cb62e4b5eaca2e4a4df8e..62db13c1beaa33c80b9d4469322f5a1ac2e60576 100644 (file)
@@ -939,10 +939,10 @@ CURLcode Curl_cyassl_random(struct Curl_easy *data,
   return CURLE_OK;
 }
 
-void Curl_cyassl_sha256sum(const unsigned char *tmp, /* input */
-                      size_t tmplen,
-                      unsigned char *sha256sum /* output */,
-                      size_t unused)
+static void Curl_cyassl_sha256sum(const unsigned char *tmp, /* input */
+                                  size_t tmplen,
+                                  unsigned char *sha256sum /* output */,
+                                  size_t unused)
 {
   Sha256 SHA256pw;
   (void)unused;
@@ -971,7 +971,8 @@ const struct Curl_ssl Curl_ssl_cyassl = {
   Curl_none_set_engine_default,    /* set_engine_default */
   Curl_none_engines_list,          /* engines_list */
   Curl_none_false_start,           /* false_start */
-  Curl_none_md5sum                 /* md5sum */
+  Curl_none_md5sum,                /* md5sum */
+  Curl_cyassl_sha256sum            /* sha256sum */
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_cyassl;
index 23d7139bebebc26dae7000606d4ad3173f407c6c..abee7cf80455fea6b45844963de442d71a38028f 100644 (file)
@@ -54,10 +54,6 @@ CURLcode Curl_cyassl_connect_nonblocking(struct connectdata *conn,
 CURLcode Curl_cyassl_random(struct Curl_easy *data,
                             unsigned char *entropy,
                             size_t length);
-void Curl_cyassl_sha256sum(const unsigned char *tmp, /* input */
-                     size_t tmplen,
-                     unsigned char *sha256sum, /* output */
-                     size_t unused);
 
 extern const struct Curl_ssl Curl_ssl_cyassl;
 
@@ -72,7 +68,5 @@ extern const struct Curl_ssl Curl_ssl_cyassl;
 #define have_curlssl_pinnedpubkey 1
 #endif
 
-#define curlssl_sha256sum(a,b,c,d) Curl_cyassl_sha256sum(a,b,c,d)
-
 #endif /* USE_CYASSL */
 #endif /* HEADER_CURL_CYASSL_H */
index 71e5a9790ff4d23fe5fa43365b4720eadd40c142..23be96a20f0ba08deafc230d304e8c5da9e13f03 100644 (file)
@@ -2733,10 +2733,10 @@ static CURLcode Curl_darwinssl_md5sum(unsigned char *tmp, /* input */
   return CURLE_OK;
 }
 
-void Curl_darwinssl_sha256sum(const unsigned char *tmp, /* input */
-                              size_t tmplen,
-                              unsigned char *sha256sum, /* output */
-                              size_t sha256len)
+static void Curl_darwinssl_sha256sum(const unsigned char *tmp, /* input */
+                                     size_t tmplen,
+                                     unsigned char *sha256sum, /* output */
+                                     size_t sha256len)
 {
   assert(sha256len >= SHA256_DIGEST_LENGTH);
   (void)CC_SHA256(tmp, (CC_LONG)tmplen, sha256sum);
@@ -2877,7 +2877,8 @@ const struct Curl_ssl Curl_ssl_darwinssl = {
   Curl_none_set_engine_default,       /* set_engine_default */
   Curl_none_engines_list,             /* engines_list */
   Curl_darwinssl_false_start,         /* false_start */
-  Curl_darwinssl_md5sum               /* md5sum */
+  Curl_darwinssl_md5sum,              /* md5sum */
+  Curl_darwinssl_sha256sum            /* sha256sum */
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_darwinssl;
index 4815cec1e87a75e727e7af15beadb96b5c947b08..37fe8164f115b5596fdd524cc2cc057ba953b95a 100644 (file)
@@ -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_sha256sum(const unsigned char *tmp, /* input */
-                              size_t tmplen,
-                              unsigned char *sha256sum, /* output */
-                              size_t sha256len);
 bool Curl_darwinssl_false_start(void);
 
 extern const struct Curl_ssl Curl_ssl_darwinssl;
@@ -74,7 +70,5 @@ extern const struct Curl_ssl Curl_ssl_darwinssl;
 #define have_curlssl_pinnedpubkey 1
 #endif /* DARWIN_SSL_PINNEDPUBKEY */
 
-#define curlssl_sha256sum(a,b,c,d) Curl_darwinssl_sha256sum(a, b, c, d)
-
 #endif /* USE_DARWINSSL */
 #endif /* HEADER_CURL_DARWINSSL_H */
index ed1e39dbc114976e3c91e983747fe3caeb180195..d82f658fd66805c0e5e539b7a83c3f1633fea251 100644 (file)
@@ -1355,7 +1355,8 @@ const struct Curl_ssl Curl_ssl_gskit = {
   Curl_none_set_engine_default,   /* set_engine_default */
   Curl_none_engines_list,         /* engines_list */
   Curl_none_false_start,          /* false_start */
-  Curl_none_md5sum                /* md5sum */
+  Curl_none_md5sum,               /* md5sum */
+  NULL                            /* sha256sum */
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_gskit;
index ac5fe33217d0608aaa5eb62ca273e6bea92082a6..3105a4b13aff5968d8ab235b6dec43fbf8aa1e96 100644 (file)
@@ -1758,10 +1758,10 @@ static CURLcode Curl_gtls_md5sum(unsigned char *tmp, /* input */
   return CURLE_OK;
 }
 
-void Curl_gtls_sha256sum(const unsigned char *tmp, /* input */
-                      size_t tmplen,
-                      unsigned char *sha256sum, /* output */
-                      size_t sha256len)
+static void Curl_gtls_sha256sum(const unsigned char *tmp, /* input */
+                                size_t tmplen,
+                                unsigned char *sha256sum, /* output */
+                                size_t sha256len)
 {
 #if defined(USE_GNUTLS_NETTLE)
   struct sha256_ctx SHA256pw;
@@ -1806,7 +1806,8 @@ const struct Curl_ssl Curl_ssl_gnutls = {
   Curl_none_set_engine_default,  /* set_engine_default */
   Curl_none_engines_list,        /* engines_list */
   Curl_none_false_start,         /* false_start */
-  Curl_gtls_md5sum               /* md5sum */
+  Curl_gtls_md5sum,              /* md5sum */
+  Curl_gtls_sha256sum            /* sha256sum */
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_gnutls;
index 626dbd33fbaeefb92acf4cdbc282927db599a015..05bd834f2974622753cd3707a5a0b512d0319426 100644 (file)
@@ -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_sha256sum(const unsigned char *tmp, /* input */
-                      size_t tmplen,
-                      unsigned char *sha256sum, /* output */
-                      size_t sha256len);
 
 bool Curl_gtls_cert_status_request(void);
 
@@ -70,7 +66,5 @@ extern const struct Curl_ssl Curl_ssl_gnutls;
 /* this backend supports CURLOPT_PINNEDPUBLICKEY */
 #define have_curlssl_pinnedpubkey 1
 
-#define curlssl_sha256sum(a,b,c,d) Curl_gtls_sha256sum(a,b,c,d)
-
 #endif /* USE_GNUTLS */
 #endif /* HEADER_CURL_GTLS_H */
index 68ad9a499b565a7878f69ae2c5948c635a113894..0ab471306fea0af45bf83719feb230ba0f8b148c 100644 (file)
@@ -1007,6 +1007,14 @@ bool Curl_mbedtls_data_pending(const struct connectdata *conn, int sockindex)
   return mbedtls_ssl_get_bytes_avail(&conn->ssl[sockindex].ssl) != 0;
 }
 
+static void Curl_mbedtls_sha256sum(const unsigned char *input,
+                                    size_t inputlen,
+                                    unsigned char *sha256sum,
+                                    size_t sha256len UNUSED_PARAM)
+{
+  mbedtls_sha256(input, inputlen, sha256sum, 0);
+}
+
 const struct Curl_ssl Curl_ssl_mbedtls = {
   "mbedtls",                        /* name */
 
@@ -1027,7 +1035,8 @@ const struct Curl_ssl Curl_ssl_mbedtls = {
   Curl_none_set_engine_default,     /* set_engine_default */
   Curl_none_engines_list,           /* engines_list */
   Curl_none_false_start,            /* false_start */
-  Curl_none_md5sum                  /* md5sum */
+  Curl_none_md5sum,                 /* md5sum */
+  Curl_mbedtls_sha256sum            /* sha256sum */
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_mbedtls;
index 1df297a5d19c4dcdf408285b640e25e24d0fc53f..39e64c350ecbe106c16b9811962b3377b164c12e 100644 (file)
@@ -26,8 +26,6 @@
 
 #ifdef USE_MBEDTLS
 
-#include <mbedtls/sha256.h>
-
 /* Called on first use mbedTLS, setup threading if supported */
 int  Curl_mbedtls_init(void);
 void Curl_mbedtls_cleanup(void);
@@ -62,7 +60,6 @@ CURLcode Curl_mbedtls_random(struct Curl_easy *data, unsigned char *entropy,
 extern const struct Curl_ssl Curl_ssl_mbedtls;
 
 #define CURL_SSL_BACKEND CURLSSLBACKEND_MBEDTLS
-#define curlssl_sha256sum(a,b,c,d) mbedtls_sha256(a,b,c,0)
 
 #endif /* USE_MBEDTLS */
 #endif /* HEADER_CURL_MBEDTLS_H */
index 9490549a961668260142eb1edf1b3dcfe0562ef8..603601b55171b4e600e842407e657b06118aa005 100644 (file)
@@ -2293,10 +2293,10 @@ static CURLcode Curl_nss_md5sum(unsigned char *tmp, /* input */
   return CURLE_OK;
 }
 
-void Curl_nss_sha256sum(const unsigned char *tmp, /* input */
-                     size_t tmplen,
-                     unsigned char *sha256sum, /* output */
-                     size_t sha256len)
+static void Curl_nss_sha256sum(const unsigned char *tmp, /* input */
+                               size_t tmplen,
+                               unsigned char *sha256sum, /* output */
+                               size_t sha256len)
 {
   PK11Context *SHA256pw = PK11_CreateDigestContext(SEC_OID_SHA256);
   unsigned int SHA256out;
@@ -2346,7 +2346,8 @@ const struct Curl_ssl Curl_ssl_nss = {
   Curl_none_set_engine_default, /* set_engine_default */
   Curl_none_engines_list,       /* engines_list */
   Curl_nss_false_start,         /* false_start */
-  Curl_nss_md5sum               /* md5sum */
+  Curl_nss_md5sum,              /* md5sum */
+  Curl_nss_sha256sum            /* sha256sum */
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_nss;
index d5473bfb9cd2fda6e551d435c09105d6f1dbe414..37c4b5b7110efb2effa6e8f09f16dc79d66c0bd8 100644 (file)
@@ -51,10 +51,6 @@ CURLcode Curl_nss_random(struct Curl_easy *data,
                          unsigned char *entropy,
                          size_t length);
 
-void Curl_nss_sha256sum(const unsigned char *tmp, /* input */
-                     size_t tmplen,
-                     unsigned char *sha256sum, /* output */
-                     size_t sha256len);
 
 bool Curl_nss_cert_status_request(void);
 
@@ -77,7 +73,5 @@ extern const struct Curl_ssl Curl_ssl_nss;
 /* this backends supports CURLOPT_PINNEDPUBLICKEY */
 #define have_curlssl_pinnedpubkey 1
 
-#define curlssl_sha256sum(a,b,c,d) Curl_nss_sha256sum(a,b,c,d)
-
 #endif /* USE_NSS */
 #endif /* HEADER_CURL_NSSG_H */
index e24c79515e42fe3a52f16d7ba971f5e2404f8349..eeecd9da61d8594f8b84579fc4def842f71e4fed 100644 (file)
@@ -3364,10 +3364,10 @@ static CURLcode Curl_ossl_md5sum(unsigned char *tmp, /* input */
 }
 
 #if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_SHA256)
-void Curl_ossl_sha256sum(const unsigned char *tmp, /* input */
-                      size_t tmplen,
-                      unsigned char *sha256sum /* output */,
-                      size_t unused)
+static void Curl_ossl_sha256sum(const unsigned char *tmp, /* input */
+                                size_t tmplen,
+                                unsigned char *sha256sum /* output */,
+                                size_t unused)
 {
   SHA256_CTX SHA256pw;
   (void)unused;
@@ -3407,7 +3407,12 @@ const struct Curl_ssl Curl_ssl_openssl = {
   Curl_ossl_set_engine_default,  /* set_engine_default */
   Curl_ossl_engines_list,        /* engines_list */
   Curl_none_false_start,         /* false_start */
-  Curl_ossl_md5sum               /* md5sum */
+  Curl_ossl_md5sum,              /* md5sum */
+#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_SHA256)
+  Curl_ossl_sha256sum            /* sha256sum */
+#else
+  NULL                           /* sha256sum */
+#endif
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_openssl;
index 4abc6d4c45273d0df6a9e2798e6b7bb422acff5a..8e14f45492368e6c928d4ba261271a7ff09b3bce 100644 (file)
@@ -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_sha256sum(const unsigned char *tmp, /* input */
-                      size_t tmplen,
-                      unsigned char *sha256sum /* output */,
-                      size_t unused);
 
 bool Curl_ossl_cert_status_request(void);
 
@@ -95,10 +91,6 @@ extern const struct Curl_ssl Curl_ssl_openssl;
 /* this backend supports CURLOPT_PINNEDPUBLICKEY */
 #define have_curlssl_pinnedpubkey 1
 
-#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_SHA256)
-#define curlssl_sha256sum(a,b,c,d) Curl_ossl_sha256sum(a,b,c,d)
-#endif
-
 #define DEFAULT_CIPHER_SELECTION \
   "ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH"
 
index f2a7c93b8c51e3b35f36e2e761d4d05486b5776c..5b48945a625fcd83df6f480b600fca27912d5898 100644 (file)
@@ -870,6 +870,14 @@ bool Curl_polarssl_data_pending(const struct connectdata *conn, int sockindex)
   return ssl_get_bytes_avail(&conn->ssl[sockindex].ssl) != 0;
 }
 
+static void Curl_polarssl_sha256sum(const unsigned char *input,
+                                    size_t inputlen,
+                                    unsigned char *sha256sum,
+                                    size_t sha256len UNUSED_PARAM)
+{
+  sha256(input, inputlen, sha256sum, 0);
+}
+
 const struct Curl_ssl Curl_ssl_polarssl = {
   "polarssl",                        /* name */
 
@@ -893,7 +901,8 @@ const struct Curl_ssl Curl_ssl_polarssl = {
   Curl_none_set_engine_default,      /* set_engine_default */
   Curl_none_engines_list,            /* engines_list */
   Curl_none_false_start,             /* false_start */
-  Curl_none_md5sum                   /* md5sum */
+  Curl_none_md5sum,                  /* md5sum */
+  Curl_polarssl_sha256sum            /* sha256sum */
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_polarssl;
index fc0a7ccd98c7dc3bcb5b7ac2169f19997db26353..7109fe5ba85c91f6f254c2bfe7bbbccbbffb4fca 100644 (file)
@@ -26,8 +26,6 @@
 
 #ifdef USE_POLARSSL
 
-#include <polarssl/sha256.h>
-
 /* Called on first use PolarSSL, setup threading if supported */
 int  Curl_polarssl_init(void);
 void Curl_polarssl_cleanup(void);
@@ -58,7 +56,5 @@ extern const struct Curl_ssl Curl_ssl_polarssl;
 /* this backends supports CURLOPT_PINNEDPUBLICKEY */
 #define have_curlssl_pinnedpubkey 1
 
-#define curlssl_sha256sum(a,b,c,d) sha256(a,b,c,0)
-
 #endif /* USE_POLARSSL */
 #endif /* HEADER_CURL_POLARSSL_H */
index ea3c221f337cad3ec6df7e24f69bddd90ed96057..6ee707b0d4da379678c17d942cacd69a48e633d6 100644 (file)
@@ -1746,7 +1746,8 @@ const struct Curl_ssl Curl_ssl_schannel = {
   Curl_none_set_engine_default,      /* set_engine_default */
   Curl_none_engines_list,            /* engines_list */
   Curl_none_false_start,             /* false_start */
-  Curl_none_md5sum                   /* md5sum */
+  Curl_none_md5sum,                  /* md5sum */
+  NULL                               /* sha256sum */
 };
 
 const struct Curl_ssl *Curl_ssl = &Curl_ssl_schannel;
index 88ee1a7596b11e29027f724a100093767a66ef53..86bb46c2ae59c138f142903f4059daa8d28cddb2 100644 (file)
@@ -791,12 +791,10 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
   size_t size, pem_len;
   CURLcode pem_read;
   CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
-#ifdef curlssl_sha256sum
   CURLcode encode;
   size_t encodedlen, pinkeylen;
   char *encoded, *pinkeycopy, *begin_pos, *end_pos;
   unsigned char *sha256sumdigest = NULL;
-#endif
 
   /* if a path wasn't specified, don't pin */
   if(!pinnedpubkey)
@@ -806,13 +804,17 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
 
   /* only do this if pinnedpubkey starts with "sha256//", length 8 */
   if(strncmp(pinnedpubkey, "sha256//", 8) == 0) {
-#ifdef curlssl_sha256sum
+    if(!Curl_ssl->sha256sum) {
+      /* without sha256 support, this cannot match */
+      return result;
+    }
+
     /* compute sha256sum of public key */
     sha256sumdigest = malloc(SHA256_DIGEST_LENGTH);
     if(!sha256sumdigest)
       return CURLE_OUT_OF_MEMORY;
-    curlssl_sha256sum(pubkey, pubkeylen,
-                      sha256sumdigest, SHA256_DIGEST_LENGTH);
+    Curl_ssl->sha256sum(pubkey, pubkeylen,
+                        sha256sumdigest, SHA256_DIGEST_LENGTH);
     encode = Curl_base64_encode(data, (char *)sha256sumdigest,
                                 SHA256_DIGEST_LENGTH, &encoded, &encodedlen);
     Curl_safefree(sha256sumdigest);
@@ -859,10 +861,6 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
     } while(end_pos && begin_pos);
     Curl_safefree(encoded);
     Curl_safefree(pinkeycopy);
-#else
-    /* without sha256 support, this cannot match */
-    (void)data;
-#endif
     return result;
   }
 
index f95b9236edb2829eb63daba1d8159e48bbc70620..d42422d118319c7d0436ec07d7aa16ed6719ac0b 100644 (file)
@@ -57,6 +57,8 @@ struct Curl_ssl {
 
   CURLcode (*md5sum)(unsigned char *input, size_t inputlen,
                      unsigned char *md5sum, size_t md5sumlen);
+  void (*sha256sum)(const unsigned char *input, size_t inputlen,
+                    unsigned char *sha256sum, size_t sha256sumlen);
 };
 
 #ifdef USE_SSL