mirror of
https://github.com/curl/curl.git
synced 2026-07-24 21:07:28 +03:00
digest: support SHA-512/256
Also fix the tests. New implementation tested with GNU libmicrohttpd. The new numbers in tests are real SHA-512/256 numbers (not just some random ;) numbers ).
This commit is contained in:
parent
6d6113e122
commit
e3461bbd05
5 changed files with 40 additions and 13 deletions
|
|
@ -38,6 +38,7 @@
|
|||
#include "curl_hmac.h"
|
||||
#include "curl_md5.h"
|
||||
#include "curl_sha256.h"
|
||||
#include "curl_sha512_256.h"
|
||||
#include "vtls/vtls.h"
|
||||
#include "warnless.h"
|
||||
#include "strtok.h"
|
||||
|
|
@ -150,7 +151,7 @@ static void auth_digest_md5_to_ascii(unsigned char *source, /* 16 bytes */
|
|||
msnprintf((char *) &dest[i * 2], 3, "%02x", source[i]);
|
||||
}
|
||||
|
||||
/* Convert sha256 chunk to RFC7616 -suitable ascii string */
|
||||
/* Convert sha256 or SHA-512/256 chunk to RFC7616 -suitable ascii string */
|
||||
static void auth_digest_sha256_to_ascii(unsigned char *source, /* 32 bytes */
|
||||
unsigned char *dest) /* 65 bytes */
|
||||
{
|
||||
|
|
@ -601,10 +602,20 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
|
|||
digest->algo = ALGO_SHA256;
|
||||
else if(strcasecompare(content, "SHA-256-SESS"))
|
||||
digest->algo = ALGO_SHA256SESS;
|
||||
else if(strcasecompare(content, "SHA-512-256"))
|
||||
else if(strcasecompare(content, "SHA-512-256")) {
|
||||
#ifdef CURL_HAVE_SHA512_256
|
||||
digest->algo = ALGO_SHA512_256;
|
||||
else if(strcasecompare(content, "SHA-512-256-SESS"))
|
||||
#else /* ! CURL_HAVE_SHA512_256 */
|
||||
return CURLE_NOT_BUILT_IN;
|
||||
#endif /* ! CURL_HAVE_SHA512_256 */
|
||||
}
|
||||
else if(strcasecompare(content, "SHA-512-256-SESS")) {
|
||||
#ifdef CURL_HAVE_SHA512_256
|
||||
digest->algo = ALGO_SHA512_256SESS;
|
||||
#else /* ! CURL_HAVE_SHA512_256 */
|
||||
return CURLE_NOT_BUILT_IN;
|
||||
#endif /* ! CURL_HAVE_SHA512_256 */
|
||||
}
|
||||
else
|
||||
return CURLE_BAD_CONTENT_ENCODING;
|
||||
}
|
||||
|
|
@ -957,12 +968,24 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
|
|||
outptr, outlen,
|
||||
auth_digest_md5_to_ascii,
|
||||
Curl_md5it);
|
||||
DEBUGASSERT(digest->algo <= ALGO_SHA512_256SESS);
|
||||
return auth_create_digest_http_message(data, userp, passwdp,
|
||||
request, uripath, digest,
|
||||
outptr, outlen,
|
||||
auth_digest_sha256_to_ascii,
|
||||
Curl_sha256it);
|
||||
|
||||
if(digest->algo <= ALGO_SHA256SESS)
|
||||
return auth_create_digest_http_message(data, userp, passwdp,
|
||||
request, uripath, digest,
|
||||
outptr, outlen,
|
||||
auth_digest_sha256_to_ascii,
|
||||
Curl_sha256it);
|
||||
#ifdef CURL_HAVE_SHA512_256
|
||||
if(digest->algo <= ALGO_SHA512_256SESS)
|
||||
return auth_create_digest_http_message(data, userp, passwdp,
|
||||
request, uripath, digest,
|
||||
outptr, outlen,
|
||||
auth_digest_sha256_to_ascii,
|
||||
Curl_sha512_256it);
|
||||
#endif /* CURL_HAVE_SHA512_256 */
|
||||
|
||||
/* Should be unreachable */
|
||||
return CURLE_BAD_CONTENT_ENCODING;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue