2012-04-26 09:59:52 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2018-05-14 03:55:34 -04:00
|
|
|
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2012-04-26 09:59:52 -04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2012-04-26 09:59:52 -04:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
#include "tool_setup.h"
|
2012-05-08 11:20:17 -04:00
|
|
|
|
2012-06-07 17:49:27 -04:00
|
|
|
#ifdef USE_METALINK
|
2012-05-26 17:20:23 -04:00
|
|
|
|
2012-06-08 17:13:32 -04:00
|
|
|
#include <sys/stat.h>
|
2016-11-01 19:08:36 -04:00
|
|
|
#include <stdlib.h>
|
2012-06-08 17:13:32 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
# include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2017-09-12 14:14:00 -04:00
|
|
|
#undef HAVE_NSS_CONTEXT
|
|
|
|
|
2015-03-05 04:57:52 -05:00
|
|
|
#ifdef USE_OPENSSL
|
|
|
|
# include <openssl/md5.h>
|
|
|
|
# include <openssl/sha.h>
|
2012-06-08 08:21:29 -04:00
|
|
|
#elif defined(USE_GNUTLS_NETTLE)
|
|
|
|
# include <nettle/md5.h>
|
|
|
|
# include <nettle/sha.h>
|
|
|
|
# define MD5_CTX struct md5_ctx
|
|
|
|
# define SHA_CTX struct sha1_ctx
|
|
|
|
# define SHA256_CTX struct sha256_ctx
|
|
|
|
#elif defined(USE_GNUTLS)
|
|
|
|
# include <gcrypt.h>
|
|
|
|
# define MD5_CTX gcry_md_hd_t
|
|
|
|
# define SHA_CTX gcry_md_hd_t
|
|
|
|
# define SHA256_CTX gcry_md_hd_t
|
2012-10-30 09:59:48 -04:00
|
|
|
#elif defined(USE_NSS)
|
|
|
|
# include <nss.h>
|
|
|
|
# include <pk11pub.h>
|
|
|
|
# define MD5_CTX void *
|
|
|
|
# define SHA_CTX void *
|
|
|
|
# define SHA256_CTX void *
|
2017-09-12 14:14:00 -04:00
|
|
|
# define HAVE_NSS_CONTEXT
|
2013-12-02 11:00:35 -05:00
|
|
|
static NSSInitContext *nss_context;
|
2014-06-15 11:35:49 -04:00
|
|
|
#elif defined(USE_POLARSSL)
|
|
|
|
# include <polarssl/md5.h>
|
|
|
|
# include <polarssl/sha1.h>
|
|
|
|
# include <polarssl/sha256.h>
|
|
|
|
# define MD5_CTX md5_context
|
|
|
|
# define SHA_CTX sha1_context
|
|
|
|
# define SHA256_CTX sha256_context
|
2013-07-30 22:20:20 -04:00
|
|
|
#elif (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
|
|
|
|
(__MAC_OS_X_VERSION_MAX_ALLOWED >= 1040)) || \
|
|
|
|
(defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
|
|
|
|
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 20000))
|
2012-10-16 13:48:55 -04:00
|
|
|
/* For Apple operating systems: CommonCrypto has the functions we need.
|
|
|
|
The library's headers are even backward-compatible with OpenSSL's
|
|
|
|
headers as long as we define COMMON_DIGEST_FOR_OPENSSL first.
|
2012-08-07 19:08:54 -04:00
|
|
|
|
2013-07-30 22:20:20 -04:00
|
|
|
These functions are available on Tiger and later, as well as iOS 2.0
|
2012-08-07 19:08:54 -04:00
|
|
|
and later. If you're building for an older cat, well, sorry. */
|
|
|
|
# define COMMON_DIGEST_FOR_OPENSSL
|
|
|
|
# include <CommonCrypto/CommonDigest.h>
|
2012-09-10 19:58:10 -04:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
/* For Windows: If no other crypto library is provided, we fallback
|
|
|
|
to the hash functions provided within the Microsoft Windows CryptoAPI */
|
2012-09-11 08:35:18 -04:00
|
|
|
# include <wincrypt.h>
|
2012-09-10 19:58:10 -04:00
|
|
|
/* Custom structure in order to store the required provider and hash handle */
|
|
|
|
struct win32_crypto_hash {
|
|
|
|
HCRYPTPROV hCryptProv;
|
|
|
|
HCRYPTHASH hHash;
|
|
|
|
};
|
|
|
|
/* Custom Microsoft AES Cryptographic Provider defines required for MinGW */
|
|
|
|
# ifndef ALG_SID_SHA_256
|
|
|
|
# define ALG_SID_SHA_256 12
|
|
|
|
# endif
|
|
|
|
# ifndef CALG_SHA_256
|
|
|
|
# define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)
|
|
|
|
# endif
|
|
|
|
# define MD5_CTX struct win32_crypto_hash
|
|
|
|
# define SHA_CTX struct win32_crypto_hash
|
|
|
|
# define SHA256_CTX struct win32_crypto_hash
|
2012-06-08 08:21:29 -04:00
|
|
|
#else
|
|
|
|
# error "Can't compile METALINK support without a crypto library."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ENABLE_CURLX_PRINTF
|
|
|
|
/* use our own printf() functions */
|
|
|
|
#include "curlx.h"
|
|
|
|
|
2012-04-28 10:46:32 -04:00
|
|
|
#include "tool_getparam.h"
|
|
|
|
#include "tool_paramhlp.h"
|
2012-05-25 06:24:32 -04:00
|
|
|
#include "tool_cfgable.h"
|
2012-06-08 08:21:29 -04:00
|
|
|
#include "tool_metalink.h"
|
2012-06-20 11:51:06 -04:00
|
|
|
#include "tool_msgs.h"
|
2012-04-26 09:59:52 -04:00
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "memdebug.h" /* keep this as LAST include */
|
2012-04-26 09:59:52 -04:00
|
|
|
|
2012-04-28 10:46:32 -04:00
|
|
|
/* Copied from tool_getparam.c */
|
|
|
|
#define GetStr(str,val) do { \
|
|
|
|
if(*(str)) { \
|
|
|
|
free(*(str)); \
|
|
|
|
*(str) = NULL; \
|
|
|
|
} \
|
|
|
|
if((val)) \
|
|
|
|
*(str) = strdup((val)); \
|
|
|
|
if(!(val)) \
|
|
|
|
return PARAM_NO_MEM; \
|
|
|
|
} WHILE_FALSE
|
|
|
|
|
2017-08-18 01:53:33 -04:00
|
|
|
#if defined(USE_OPENSSL)
|
|
|
|
/* Functions are already defined */
|
|
|
|
#elif defined(USE_GNUTLS_NETTLE)
|
2012-06-08 08:21:29 -04:00
|
|
|
|
2012-10-30 09:21:54 -04:00
|
|
|
static int MD5_Init(MD5_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
md5_init(ctx);
|
2012-11-13 07:09:43 -05:00
|
|
|
return 1;
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void MD5_Update(MD5_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
md5_update(ctx, inputLen, input);
|
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
md5_digest(ctx, 16, digest);
|
|
|
|
}
|
|
|
|
|
2012-10-30 09:21:54 -04:00
|
|
|
static int SHA1_Init(SHA_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
sha1_init(ctx);
|
2012-11-13 07:09:43 -05:00
|
|
|
return 1;
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA1_Update(SHA_CTX *ctx,
|
2012-06-08 08:21:29 -04:00
|
|
|
const unsigned char *input,
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
sha1_update(ctx, inputLen, input);
|
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
sha1_digest(ctx, 20, digest);
|
|
|
|
}
|
|
|
|
|
2012-10-30 09:21:54 -04:00
|
|
|
static int SHA256_Init(SHA256_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
sha256_init(ctx);
|
2012-11-13 07:09:43 -05:00
|
|
|
return 1;
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA256_Update(SHA256_CTX *ctx,
|
2012-06-08 08:21:29 -04:00
|
|
|
const unsigned char *input,
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
sha256_update(ctx, inputLen, input);
|
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
sha256_digest(ctx, 32, digest);
|
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
#elif defined(USE_GNUTLS)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
|
2012-10-30 09:21:54 -04:00
|
|
|
static int MD5_Init(MD5_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
gcry_md_open(ctx, GCRY_MD_MD5, 0);
|
2012-11-13 07:09:43 -05:00
|
|
|
return 1;
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void MD5_Update(MD5_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
gcry_md_write(*ctx, input, inputLen);
|
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
memcpy(digest, gcry_md_read(*ctx, 0), 16);
|
|
|
|
gcry_md_close(*ctx);
|
|
|
|
}
|
|
|
|
|
2012-10-30 09:21:54 -04:00
|
|
|
static int SHA1_Init(SHA_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
gcry_md_open(ctx, GCRY_MD_SHA1, 0);
|
2012-11-13 07:09:43 -05:00
|
|
|
return 1;
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void SHA1_Update(SHA_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int inputLen)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
gcry_md_write(*ctx, input, inputLen);
|
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
memcpy(digest, gcry_md_read(*ctx, 0), 20);
|
|
|
|
gcry_md_close(*ctx);
|
|
|
|
}
|
|
|
|
|
2012-10-30 09:21:54 -04:00
|
|
|
static int SHA256_Init(SHA256_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
gcry_md_open(ctx, GCRY_MD_SHA256, 0);
|
2012-11-13 07:09:43 -05:00
|
|
|
return 1;
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void SHA256_Update(SHA256_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int inputLen)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
gcry_md_write(*ctx, input, inputLen);
|
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
{
|
|
|
|
memcpy(digest, gcry_md_read(*ctx, 0), 32);
|
|
|
|
gcry_md_close(*ctx);
|
|
|
|
}
|
|
|
|
|
2012-10-30 09:59:48 -04:00
|
|
|
#elif defined(USE_NSS)
|
|
|
|
|
|
|
|
static int nss_hash_init(void **pctx, SECOidTag hash_alg)
|
|
|
|
{
|
|
|
|
PK11Context *ctx;
|
|
|
|
|
2018-03-15 22:51:03 -04:00
|
|
|
/* we have to initialize NSS if not initialized already */
|
2012-10-30 09:59:48 -04:00
|
|
|
if(!NSS_IsInitialized() && !nss_context) {
|
|
|
|
static NSSInitParameters params;
|
2018-05-11 17:40:58 -04:00
|
|
|
params.length = sizeof(params);
|
2012-10-30 09:59:48 -04:00
|
|
|
nss_context = NSS_InitContext("", "", "", "", ¶ms, NSS_INIT_READONLY
|
|
|
|
| NSS_INIT_NOCERTDB | NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN
|
|
|
|
| NSS_INIT_NOROOTINIT | NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = PK11_CreateDigestContext(hash_alg);
|
|
|
|
if(!ctx)
|
2012-11-13 07:09:43 -05:00
|
|
|
return /* failure */ 0;
|
2012-10-30 09:59:48 -04:00
|
|
|
|
|
|
|
if(PK11_DigestBegin(ctx) != SECSuccess) {
|
|
|
|
PK11_DestroyContext(ctx, PR_TRUE);
|
2012-11-13 07:09:43 -05:00
|
|
|
return /* failure */ 0;
|
2012-10-30 09:59:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*pctx = ctx;
|
2012-11-13 07:09:43 -05:00
|
|
|
return /* success */ 1;
|
2012-10-30 09:59:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void nss_hash_final(void **pctx, unsigned char *out, unsigned int len)
|
|
|
|
{
|
|
|
|
PK11Context *ctx = *pctx;
|
|
|
|
unsigned int outlen;
|
|
|
|
PK11_DigestFinal(ctx, out, &outlen, len);
|
|
|
|
PK11_DestroyContext(ctx, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MD5_Init(MD5_CTX *pctx)
|
|
|
|
{
|
|
|
|
return nss_hash_init(pctx, SEC_OID_MD5);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MD5_Update(MD5_CTX *pctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int input_len)
|
|
|
|
{
|
|
|
|
PK11_DigestOp(*pctx, input, input_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MD5_Final(unsigned char digest[16], MD5_CTX *pctx)
|
|
|
|
{
|
|
|
|
nss_hash_final(pctx, digest, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SHA1_Init(SHA_CTX *pctx)
|
|
|
|
{
|
|
|
|
return nss_hash_init(pctx, SEC_OID_SHA1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA1_Update(SHA_CTX *pctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int input_len)
|
|
|
|
{
|
|
|
|
PK11_DigestOp(*pctx, input, input_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA1_Final(unsigned char digest[20], SHA_CTX *pctx)
|
|
|
|
{
|
|
|
|
nss_hash_final(pctx, digest, 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SHA256_Init(SHA256_CTX *pctx)
|
|
|
|
{
|
|
|
|
return nss_hash_init(pctx, SEC_OID_SHA256);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA256_Update(SHA256_CTX *pctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int input_len)
|
|
|
|
{
|
|
|
|
PK11_DigestOp(*pctx, input, input_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA256_Final(unsigned char digest[32], SHA256_CTX *pctx)
|
|
|
|
{
|
|
|
|
nss_hash_final(pctx, digest, 32);
|
|
|
|
}
|
|
|
|
|
2014-06-15 11:35:49 -04:00
|
|
|
#elif defined(USE_POLARSSL)
|
|
|
|
|
|
|
|
static int MD5_Init(MD5_CTX *ctx)
|
|
|
|
{
|
|
|
|
md5_starts(ctx);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MD5_Update(MD5_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
md5_update(ctx, input, inputLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
|
|
|
|
{
|
|
|
|
md5_finish(ctx, digest);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SHA1_Init(SHA_CTX *ctx)
|
|
|
|
{
|
|
|
|
sha1_starts(ctx);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA1_Update(SHA_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
sha1_update(ctx, input, inputLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
|
|
|
|
{
|
|
|
|
sha1_finish(ctx, digest);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SHA256_Init(SHA256_CTX *ctx)
|
|
|
|
{
|
|
|
|
sha256_starts(ctx, 0); /* 0 = sha256 */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA256_Update(SHA256_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
sha256_update(ctx, input, inputLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
|
|
|
|
{
|
|
|
|
sha256_finish(ctx, digest);
|
|
|
|
}
|
|
|
|
|
2017-08-18 01:53:33 -04:00
|
|
|
#elif defined(_WIN32)
|
2012-09-10 19:58:10 -04:00
|
|
|
|
|
|
|
static void win32_crypto_final(struct win32_crypto_hash *ctx,
|
|
|
|
unsigned char *digest,
|
|
|
|
unsigned int digestLen)
|
|
|
|
{
|
|
|
|
unsigned long length;
|
|
|
|
CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
|
|
|
|
if(length == digestLen)
|
|
|
|
CryptGetHashParam(ctx->hHash, HP_HASHVAL, digest, &length, 0);
|
|
|
|
if(ctx->hHash)
|
|
|
|
CryptDestroyHash(ctx->hHash);
|
|
|
|
if(ctx->hCryptProv)
|
|
|
|
CryptReleaseContext(ctx->hCryptProv, 0);
|
|
|
|
}
|
|
|
|
|
2012-10-30 09:21:54 -04:00
|
|
|
static int MD5_Init(MD5_CTX *ctx)
|
2012-09-10 19:58:10 -04:00
|
|
|
{
|
|
|
|
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL,
|
|
|
|
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
|
|
|
|
CryptCreateHash(ctx->hCryptProv, CALG_MD5, 0, 0, &ctx->hHash);
|
|
|
|
}
|
2012-11-13 07:09:43 -05:00
|
|
|
return 1;
|
2012-09-10 19:58:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MD5_Update(MD5_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
|
|
|
|
{
|
|
|
|
win32_crypto_final(ctx, digest, 16);
|
|
|
|
}
|
|
|
|
|
2012-10-30 09:21:54 -04:00
|
|
|
static int SHA1_Init(SHA_CTX *ctx)
|
2012-09-10 19:58:10 -04:00
|
|
|
{
|
|
|
|
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL,
|
|
|
|
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
|
|
|
|
CryptCreateHash(ctx->hCryptProv, CALG_SHA1, 0, 0, &ctx->hHash);
|
|
|
|
}
|
2012-11-13 07:09:43 -05:00
|
|
|
return 1;
|
2012-09-10 19:58:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA1_Update(SHA_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
|
|
|
|
{
|
|
|
|
win32_crypto_final(ctx, digest, 20);
|
|
|
|
}
|
|
|
|
|
2012-10-30 09:21:54 -04:00
|
|
|
static int SHA256_Init(SHA256_CTX *ctx)
|
2012-09-10 19:58:10 -04:00
|
|
|
{
|
|
|
|
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL,
|
|
|
|
PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) {
|
|
|
|
CryptCreateHash(ctx->hCryptProv, CALG_SHA_256, 0, 0, &ctx->hHash);
|
|
|
|
}
|
2012-11-13 07:09:43 -05:00
|
|
|
return 1;
|
2012-09-10 19:58:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA256_Update(SHA256_CTX *ctx,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned int inputLen)
|
|
|
|
{
|
|
|
|
CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
|
|
|
|
{
|
|
|
|
win32_crypto_final(ctx, digest, 32);
|
|
|
|
}
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
#endif /* CRYPTO LIBS */
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
|
2012-08-06 13:20:35 -04:00
|
|
|
const digest_params MD5_DIGEST_PARAMS[] = {
|
|
|
|
{
|
2018-08-10 11:32:01 -04:00
|
|
|
CURLX_FUNCTION_CAST(Curl_digest_init_func, MD5_Init),
|
|
|
|
CURLX_FUNCTION_CAST(Curl_digest_update_func, MD5_Update),
|
|
|
|
CURLX_FUNCTION_CAST(Curl_digest_final_func, MD5_Final),
|
2012-08-06 13:20:35 -04:00
|
|
|
sizeof(MD5_CTX),
|
|
|
|
16
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const digest_params SHA1_DIGEST_PARAMS[] = {
|
|
|
|
{
|
2018-08-10 11:32:01 -04:00
|
|
|
CURLX_FUNCTION_CAST(Curl_digest_init_func, SHA1_Init),
|
|
|
|
CURLX_FUNCTION_CAST(Curl_digest_update_func, SHA1_Update),
|
|
|
|
CURLX_FUNCTION_CAST(Curl_digest_final_func, SHA1_Final),
|
2012-08-06 13:20:35 -04:00
|
|
|
sizeof(SHA_CTX),
|
|
|
|
20
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const digest_params SHA256_DIGEST_PARAMS[] = {
|
|
|
|
{
|
2018-08-10 11:32:01 -04:00
|
|
|
CURLX_FUNCTION_CAST(Curl_digest_init_func, SHA256_Init),
|
|
|
|
CURLX_FUNCTION_CAST(Curl_digest_update_func, SHA256_Update),
|
|
|
|
CURLX_FUNCTION_CAST(Curl_digest_final_func, SHA256_Final),
|
2012-08-06 13:20:35 -04:00
|
|
|
sizeof(SHA256_CTX),
|
|
|
|
32
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const metalink_digest_def SHA256_DIGEST_DEF[] = {
|
|
|
|
{"sha-256", SHA256_DIGEST_PARAMS}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const metalink_digest_def SHA1_DIGEST_DEF[] = {
|
|
|
|
{"sha-1", SHA1_DIGEST_PARAMS}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const metalink_digest_def MD5_DIGEST_DEF[] = {
|
|
|
|
{"md5", MD5_DIGEST_PARAMS}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The alias of supported hash functions in the order by preference
|
|
|
|
* (basically stronger hash comes first). We included "sha-256" and
|
|
|
|
* "sha256". The former is the name defined in the IANA registry named
|
|
|
|
* "Hash Function Textual Names". The latter is widely (and
|
|
|
|
* historically) used in Metalink version 3.
|
|
|
|
*/
|
|
|
|
static const metalink_digest_alias digest_aliases[] = {
|
|
|
|
{"sha-256", SHA256_DIGEST_DEF},
|
|
|
|
{"sha256", SHA256_DIGEST_DEF},
|
|
|
|
{"sha-1", SHA1_DIGEST_DEF},
|
|
|
|
{"sha1", SHA1_DIGEST_DEF},
|
|
|
|
{"md5", MD5_DIGEST_DEF},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
digest_context *Curl_digest_init(const digest_params *dparams)
|
|
|
|
{
|
|
|
|
digest_context *ctxt;
|
|
|
|
|
|
|
|
/* Create digest context */
|
2018-05-11 17:40:58 -04:00
|
|
|
ctxt = malloc(sizeof(*ctxt));
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
|
|
|
|
if(!ctxt)
|
|
|
|
return ctxt;
|
|
|
|
|
|
|
|
ctxt->digest_hashctx = malloc(dparams->digest_ctxtsize);
|
|
|
|
|
|
|
|
if(!ctxt->digest_hashctx) {
|
|
|
|
free(ctxt);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt->digest_hash = dparams;
|
|
|
|
|
2012-11-13 07:09:43 -05:00
|
|
|
if(dparams->digest_init(ctxt->digest_hashctx) != 1) {
|
2017-11-24 03:02:54 -05:00
|
|
|
free(ctxt->digest_hashctx);
|
2012-10-30 09:21:54 -04:00
|
|
|
free(ctxt);
|
|
|
|
return NULL;
|
|
|
|
}
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
|
|
|
|
return ctxt;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Curl_digest_update(digest_context *context,
|
|
|
|
const unsigned char *data,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
|
|
|
(*context->digest_hash->digest_update)(context->digest_hashctx, data, len);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Curl_digest_final(digest_context *context, unsigned char *result)
|
|
|
|
{
|
2017-11-24 03:02:54 -05:00
|
|
|
if(result)
|
|
|
|
(*context->digest_hash->digest_final)(result, context->digest_hashctx);
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
|
|
|
|
free(context->digest_hashctx);
|
|
|
|
free(context);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-26 08:21:53 -04:00
|
|
|
static unsigned char hex_to_uint(const char *s)
|
|
|
|
{
|
2016-11-01 19:08:36 -04:00
|
|
|
char buf[3];
|
|
|
|
unsigned long val;
|
|
|
|
buf[0] = s[0];
|
|
|
|
buf[1] = s[1];
|
|
|
|
buf[2] = 0;
|
|
|
|
val = strtoul(buf, NULL, 16);
|
|
|
|
return (unsigned char)(val&0xff);
|
2012-05-26 08:21:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check checksum of file denoted by filename. The expected hash value
|
|
|
|
* is given in hex_hash which is hex-encoded string.
|
|
|
|
*
|
|
|
|
* This function returns 1 if it succeeds or one of the following
|
|
|
|
* integers:
|
|
|
|
*
|
|
|
|
* 0:
|
|
|
|
* Checksum didn't match.
|
|
|
|
* -1:
|
|
|
|
* Could not open file; or could not read data from file.
|
2012-10-30 09:21:54 -04:00
|
|
|
* -2:
|
|
|
|
* Hash algorithm not available.
|
2012-05-26 08:21:53 -04:00
|
|
|
*/
|
|
|
|
static int check_hash(const char *filename,
|
|
|
|
const metalink_digest_def *digest_def,
|
2012-06-16 09:58:06 -04:00
|
|
|
const unsigned char *digest, FILE *error)
|
2012-05-26 08:21:53 -04:00
|
|
|
{
|
|
|
|
unsigned char *result;
|
|
|
|
digest_context *dctx;
|
2012-09-11 02:20:43 -04:00
|
|
|
int check_ok, flags, fd;
|
|
|
|
|
|
|
|
flags = O_RDONLY;
|
|
|
|
#ifdef O_BINARY
|
2012-09-10 19:42:58 -04:00
|
|
|
/* O_BINARY is required in order to avoid binary EOF in text mode */
|
2012-09-11 02:20:43 -04:00
|
|
|
flags |= O_BINARY;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fd = open(filename, flags);
|
2012-05-26 08:21:53 -04:00
|
|
|
if(fd == -1) {
|
2012-09-11 18:09:23 -04:00
|
|
|
fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename,
|
|
|
|
digest_def->hash_name, strerror(errno));
|
2012-05-26 08:21:53 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2012-10-30 09:21:54 -04:00
|
|
|
|
2012-05-26 08:21:53 -04:00
|
|
|
dctx = Curl_digest_init(digest_def->dparams);
|
2012-10-30 09:21:54 -04:00
|
|
|
if(!dctx) {
|
|
|
|
fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename,
|
|
|
|
digest_def->hash_name, "failed to initialize hash algorithm");
|
|
|
|
close(fd);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2012-05-26 08:21:53 -04:00
|
|
|
result = malloc(digest_def->dparams->digest_resultlen);
|
2015-03-19 04:07:11 -04:00
|
|
|
if(!result) {
|
|
|
|
close(fd);
|
2017-11-24 03:02:54 -05:00
|
|
|
Curl_digest_final(dctx, NULL);
|
2015-03-06 17:14:25 -05:00
|
|
|
return -1;
|
2015-03-19 04:07:11 -04:00
|
|
|
}
|
2012-05-26 08:21:53 -04:00
|
|
|
while(1) {
|
|
|
|
unsigned char buf[4096];
|
|
|
|
ssize_t len = read(fd, buf, sizeof(buf));
|
|
|
|
if(len == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(len == -1) {
|
2012-09-11 18:09:23 -04:00
|
|
|
fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename,
|
|
|
|
digest_def->hash_name, strerror(errno));
|
2012-05-26 08:21:53 -04:00
|
|
|
Curl_digest_final(dctx, result);
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
Curl_digest_update(dctx, buf, (unsigned int)len);
|
|
|
|
}
|
|
|
|
Curl_digest_final(dctx, result);
|
2012-06-16 09:58:06 -04:00
|
|
|
check_ok = memcmp(result, digest,
|
|
|
|
digest_def->dparams->digest_resultlen) == 0;
|
2012-06-20 11:51:06 -04:00
|
|
|
/* sha*sum style verdict output */
|
|
|
|
if(check_ok)
|
2012-09-11 18:09:23 -04:00
|
|
|
fprintf(error, "Metalink: validating (%s) [%s] OK\n", filename,
|
|
|
|
digest_def->hash_name);
|
2012-06-20 11:51:06 -04:00
|
|
|
else
|
2012-09-11 18:09:23 -04:00
|
|
|
fprintf(error, "Metalink: validating (%s) [%s] FAILED (digest mismatch)\n",
|
|
|
|
filename, digest_def->hash_name);
|
2012-06-20 11:51:06 -04:00
|
|
|
|
2012-05-26 08:21:53 -04:00
|
|
|
free(result);
|
|
|
|
close(fd);
|
|
|
|
return check_ok;
|
|
|
|
}
|
|
|
|
|
2014-03-01 08:00:31 -05:00
|
|
|
int metalink_check_hash(struct GlobalConfig *config,
|
2012-05-26 08:21:53 -04:00
|
|
|
metalinkfile *mlfile,
|
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
int rv;
|
2012-06-27 11:20:20 -04:00
|
|
|
fprintf(config->errors, "Metalink: validating (%s)...\n", filename);
|
2012-05-26 08:21:53 -04:00
|
|
|
if(mlfile->checksum == NULL) {
|
2012-06-27 11:20:20 -04:00
|
|
|
fprintf(config->errors,
|
2014-03-01 08:00:31 -05:00
|
|
|
"Metalink: validating (%s) FAILED (digest missing)\n", filename);
|
2012-05-26 08:21:53 -04:00
|
|
|
return -2;
|
|
|
|
}
|
2012-06-16 09:58:06 -04:00
|
|
|
rv = check_hash(filename, mlfile->checksum->digest_def,
|
|
|
|
mlfile->checksum->digest, config->errors);
|
2012-05-26 08:21:53 -04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:58:06 -04:00
|
|
|
static metalink_checksum *new_metalink_checksum_from_hex_digest
|
|
|
|
(const metalink_digest_def *digest_def, const char *hex_digest)
|
2012-05-25 06:24:32 -04:00
|
|
|
{
|
|
|
|
metalink_checksum *chksum;
|
2012-06-16 09:58:06 -04:00
|
|
|
unsigned char *digest;
|
|
|
|
size_t i;
|
|
|
|
size_t len = strlen(hex_digest);
|
|
|
|
digest = malloc(len/2);
|
2015-03-06 17:14:25 -05:00
|
|
|
if(!digest)
|
|
|
|
return 0;
|
|
|
|
|
2012-06-16 09:58:06 -04:00
|
|
|
for(i = 0; i < len; i += 2) {
|
2017-09-09 17:55:08 -04:00
|
|
|
digest[i/2] = hex_to_uint(hex_digest + i);
|
2012-06-16 09:58:06 -04:00
|
|
|
}
|
2012-05-25 06:24:32 -04:00
|
|
|
chksum = malloc(sizeof(metalink_checksum));
|
2015-03-06 17:14:25 -05:00
|
|
|
if(chksum) {
|
|
|
|
chksum->digest_def = digest_def;
|
|
|
|
chksum->digest = digest;
|
|
|
|
}
|
2017-11-24 03:02:54 -05:00
|
|
|
else
|
|
|
|
free(digest);
|
2012-05-25 06:24:32 -04:00
|
|
|
return chksum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static metalink_resource *new_metalink_resource(const char *url)
|
|
|
|
{
|
|
|
|
metalink_resource *res;
|
|
|
|
res = malloc(sizeof(metalink_resource));
|
2015-03-06 17:14:25 -05:00
|
|
|
if(res) {
|
|
|
|
res->next = NULL;
|
|
|
|
res->url = strdup(url);
|
|
|
|
if(!res->url) {
|
|
|
|
free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-05-25 06:24:32 -04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:58:06 -04:00
|
|
|
/* Returns nonzero if hex_digest is properly formatted; that is each
|
|
|
|
letter is in [0-9A-Za-z] and the length of the string equals to the
|
|
|
|
result length of digest * 2. */
|
|
|
|
static int check_hex_digest(const char *hex_digest,
|
|
|
|
const metalink_digest_def *digest_def)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for(i = 0; hex_digest[i]; ++i) {
|
|
|
|
char c = hex_digest[i];
|
|
|
|
if(!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') ||
|
|
|
|
('A' <= c && c <= 'Z'))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return digest_def->dparams->digest_resultlen * 2 == i;
|
|
|
|
}
|
|
|
|
|
2012-05-25 06:24:32 -04:00
|
|
|
static metalinkfile *new_metalinkfile(metalink_file_t *fileinfo)
|
|
|
|
{
|
|
|
|
metalinkfile *f;
|
|
|
|
f = (metalinkfile*)malloc(sizeof(metalinkfile));
|
2015-03-06 17:14:25 -05:00
|
|
|
if(!f)
|
|
|
|
return NULL;
|
|
|
|
|
2012-04-26 09:59:52 -04:00
|
|
|
f->next = NULL;
|
2012-05-25 06:24:32 -04:00
|
|
|
f->filename = strdup(fileinfo->name);
|
2015-03-06 17:14:25 -05:00
|
|
|
if(!f->filename) {
|
|
|
|
free(f);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-05-25 06:24:32 -04:00
|
|
|
f->checksum = NULL;
|
|
|
|
f->resource = NULL;
|
|
|
|
if(fileinfo->checksums) {
|
2012-06-16 09:58:06 -04:00
|
|
|
const metalink_digest_alias *digest_alias;
|
|
|
|
for(digest_alias = digest_aliases; digest_alias->alias_name;
|
|
|
|
++digest_alias) {
|
|
|
|
metalink_checksum_t **p;
|
|
|
|
for(p = fileinfo->checksums; *p; ++p) {
|
2016-10-31 16:49:38 -04:00
|
|
|
if(curl_strequal(digest_alias->alias_name, (*p)->type) &&
|
2012-06-16 09:58:06 -04:00
|
|
|
check_hex_digest((*p)->hash, digest_alias->digest_def)) {
|
|
|
|
f->checksum =
|
|
|
|
new_metalink_checksum_from_hex_digest(digest_alias->digest_def,
|
|
|
|
(*p)->hash);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(f->checksum) {
|
|
|
|
break;
|
|
|
|
}
|
2012-05-25 06:24:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(fileinfo->resources) {
|
|
|
|
metalink_resource_t **p;
|
|
|
|
metalink_resource root, *tail;
|
|
|
|
root.next = NULL;
|
|
|
|
tail = &root;
|
|
|
|
for(p = fileinfo->resources; *p; ++p) {
|
|
|
|
metalink_resource *res;
|
2012-09-17 10:05:39 -04:00
|
|
|
/* Filter by type if it is non-NULL. In Metalink v3, type
|
|
|
|
includes the type of the resource. In curl, we are only
|
|
|
|
interested in HTTP, HTTPS and FTP. In addition to them,
|
|
|
|
Metalink v3 file may contain bittorrent type URL, which
|
|
|
|
points to the BitTorrent metainfo file. We ignore it here.
|
|
|
|
In Metalink v4, type was deprecated and all
|
|
|
|
fileinfo->resources point to the target file. BitTorrent
|
|
|
|
metainfo file URL may be appeared in fileinfo->metaurls.
|
|
|
|
*/
|
|
|
|
if((*p)->type == NULL ||
|
2016-10-31 16:49:38 -04:00
|
|
|
curl_strequal((*p)->type, "http") ||
|
|
|
|
curl_strequal((*p)->type, "https") ||
|
|
|
|
curl_strequal((*p)->type, "ftp") ||
|
|
|
|
curl_strequal((*p)->type, "ftps")) {
|
2012-09-17 10:05:39 -04:00
|
|
|
res = new_metalink_resource((*p)->url);
|
2017-11-24 03:02:54 -05:00
|
|
|
if(res) {
|
|
|
|
tail->next = res;
|
|
|
|
tail = res;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tail = root.next;
|
|
|
|
|
|
|
|
/* clean up the linked list */
|
|
|
|
while(tail) {
|
|
|
|
res = tail->next;
|
|
|
|
free(tail->url);
|
|
|
|
free(tail);
|
|
|
|
tail = res;
|
|
|
|
}
|
|
|
|
free(f->filename);
|
|
|
|
free(f);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-09-17 10:05:39 -04:00
|
|
|
}
|
2012-05-25 06:24:32 -04:00
|
|
|
}
|
|
|
|
f->resource = root.next;
|
|
|
|
}
|
2012-04-26 09:59:52 -04:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2014-02-23 07:59:59 -05:00
|
|
|
int parse_metalink(struct OperationConfig *config, struct OutStruct *outs,
|
2012-06-26 09:55:16 -04:00
|
|
|
const char *metalink_url)
|
2012-04-28 10:46:32 -04:00
|
|
|
{
|
|
|
|
metalink_error_t r;
|
|
|
|
metalink_t* metalink;
|
|
|
|
metalink_file_t **files;
|
2012-06-27 11:20:20 -04:00
|
|
|
bool warnings = FALSE;
|
2012-04-28 10:46:32 -04:00
|
|
|
|
2012-06-20 11:51:06 -04:00
|
|
|
/* metlaink_parse_final deletes outs->metalink_parser */
|
|
|
|
r = metalink_parse_final(outs->metalink_parser, NULL, 0, &metalink);
|
|
|
|
outs->metalink_parser = NULL;
|
2012-04-28 10:46:32 -04:00
|
|
|
if(r != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-05-14 08:55:48 -04:00
|
|
|
if(metalink->files == NULL) {
|
2014-03-01 08:00:31 -05:00
|
|
|
fprintf(config->global->errors, "Metalink: parsing (%s) WARNING "
|
2012-06-26 09:55:16 -04:00
|
|
|
"(missing or invalid file name)\n",
|
|
|
|
metalink_url);
|
2012-05-25 06:24:32 -04:00
|
|
|
metalink_delete(metalink);
|
2012-06-27 11:20:20 -04:00
|
|
|
return -1;
|
2012-05-14 08:55:48 -04:00
|
|
|
}
|
2012-04-28 10:46:32 -04:00
|
|
|
for(files = metalink->files; *files; ++files) {
|
|
|
|
struct getout *url;
|
|
|
|
/* Skip an entry which has no resource. */
|
2012-05-14 08:55:48 -04:00
|
|
|
if(!(*files)->resources) {
|
2014-03-01 08:00:31 -05:00
|
|
|
fprintf(config->global->errors, "Metalink: parsing (%s) WARNING "
|
2012-06-26 09:55:16 -04:00
|
|
|
"(missing or invalid resource)\n",
|
2017-06-07 08:00:23 -04:00
|
|
|
metalink_url);
|
2012-05-14 08:55:48 -04:00
|
|
|
continue;
|
|
|
|
}
|
2012-04-28 10:46:32 -04:00
|
|
|
if(config->url_get ||
|
|
|
|
((config->url_get = config->url_list) != NULL)) {
|
|
|
|
/* there's a node here, if it already is filled-in continue to
|
|
|
|
find an "empty" node */
|
|
|
|
while(config->url_get && (config->url_get->flags & GETOUT_URL))
|
|
|
|
config->url_get = config->url_get->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now there might or might not be an available node to fill in! */
|
|
|
|
|
|
|
|
if(config->url_get)
|
|
|
|
/* existing node */
|
|
|
|
url = config->url_get;
|
|
|
|
else
|
|
|
|
/* there was no free node, create one! */
|
2012-05-25 06:24:32 -04:00
|
|
|
url = new_getout(config);
|
2012-04-28 10:46:32 -04:00
|
|
|
|
|
|
|
if(url) {
|
2015-03-06 17:14:25 -05:00
|
|
|
metalinkfile *mlfile = new_metalinkfile(*files);
|
|
|
|
if(!mlfile)
|
|
|
|
break;
|
|
|
|
|
2012-06-27 11:20:20 -04:00
|
|
|
if(!mlfile->checksum) {
|
|
|
|
warnings = TRUE;
|
2014-03-01 08:00:31 -05:00
|
|
|
fprintf(config->global->errors,
|
|
|
|
"Metalink: parsing (%s) WARNING (digest missing)\n",
|
2012-06-27 11:20:20 -04:00
|
|
|
metalink_url);
|
|
|
|
}
|
2012-04-28 10:46:32 -04:00
|
|
|
/* Set name as url */
|
2012-05-25 06:24:32 -04:00
|
|
|
GetStr(&url->url, mlfile->filename);
|
2012-04-28 10:46:32 -04:00
|
|
|
|
|
|
|
/* set flag metalink here */
|
|
|
|
url->flags |= GETOUT_URL | GETOUT_METALINK;
|
|
|
|
|
|
|
|
if(config->metalinkfile_list) {
|
|
|
|
config->metalinkfile_last->next = mlfile;
|
|
|
|
config->metalinkfile_last = mlfile;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
config->metalinkfile_list = config->metalinkfile_last = mlfile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-25 06:24:32 -04:00
|
|
|
metalink_delete(metalink);
|
2012-06-27 11:20:20 -04:00
|
|
|
return (warnings) ? -2 : 0;
|
2012-04-28 10:46:32 -04:00
|
|
|
}
|
2012-05-08 11:20:17 -04:00
|
|
|
|
2012-06-20 11:51:06 -04:00
|
|
|
size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb,
|
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
struct OutStruct *outs = userdata;
|
2014-02-23 07:59:59 -05:00
|
|
|
struct OperationConfig *config = outs->config;
|
2012-06-20 11:51:06 -04:00
|
|
|
int rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Once that libcurl has called back tool_write_cb() the returned value
|
|
|
|
* is checked against the amount that was intended to be written, if
|
|
|
|
* it does not match then it fails with CURLE_WRITE_ERROR. So at this
|
|
|
|
* point returning a value different from sz*nmemb indicates failure.
|
|
|
|
*/
|
2017-08-10 08:54:55 -04:00
|
|
|
const size_t failure = (sz && nmemb) ? 0 : 1;
|
2012-06-20 11:51:06 -04:00
|
|
|
|
|
|
|
if(!config)
|
|
|
|
return failure;
|
|
|
|
|
2017-08-18 01:58:16 -04:00
|
|
|
rv = metalink_parse_update(outs->metalink_parser, buffer, sz * nmemb);
|
2012-06-20 11:51:06 -04:00
|
|
|
if(rv == 0)
|
|
|
|
return sz * nmemb;
|
|
|
|
else {
|
2014-03-01 08:00:31 -05:00
|
|
|
fprintf(config->global->errors, "Metalink: parsing FAILED\n");
|
2012-06-20 11:51:06 -04:00
|
|
|
return failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 11:20:17 -04:00
|
|
|
/*
|
|
|
|
* Returns nonzero if content_type includes mediatype.
|
|
|
|
*/
|
|
|
|
static int check_content_type(const char *content_type, const char *media_type)
|
|
|
|
{
|
|
|
|
const char *ptr = content_type;
|
|
|
|
size_t media_type_len = strlen(media_type);
|
|
|
|
for(; *ptr && (*ptr == ' ' || *ptr == '\t'); ++ptr);
|
|
|
|
if(!*ptr) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-31 16:49:38 -04:00
|
|
|
return curl_strnequal(ptr, media_type, media_type_len) &&
|
2017-09-09 17:55:08 -04:00
|
|
|
(*(ptr + media_type_len) == '\0' || *(ptr + media_type_len) == ' ' ||
|
|
|
|
*(ptr + media_type_len) == '\t' || *(ptr + media_type_len) == ';');
|
2012-05-08 11:20:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int check_metalink_content_type(const char *content_type)
|
|
|
|
{
|
|
|
|
return check_content_type(content_type, "application/metalink+xml");
|
|
|
|
}
|
2012-05-26 09:51:03 -04:00
|
|
|
|
|
|
|
int count_next_metalink_resource(metalinkfile *mlfile)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
metalink_resource *res;
|
|
|
|
for(res = mlfile->resource; res; res = res->next, ++count);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_metalink_checksum(metalink_checksum *chksum)
|
|
|
|
{
|
|
|
|
if(chksum == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-16 09:58:06 -04:00
|
|
|
Curl_safefree(chksum->digest);
|
2012-05-26 09:51:03 -04:00
|
|
|
Curl_safefree(chksum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_metalink_resource(metalink_resource *res)
|
|
|
|
{
|
|
|
|
if(res == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Curl_safefree(res->url);
|
|
|
|
Curl_safefree(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_metalinkfile(metalinkfile *mlfile)
|
|
|
|
{
|
|
|
|
metalink_resource *res;
|
|
|
|
if(mlfile == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Curl_safefree(mlfile->filename);
|
2012-06-16 09:58:06 -04:00
|
|
|
delete_metalink_checksum(mlfile->checksum);
|
2012-05-26 09:51:03 -04:00
|
|
|
for(res = mlfile->resource; res;) {
|
|
|
|
metalink_resource *next;
|
|
|
|
next = res->next;
|
|
|
|
delete_metalink_resource(res);
|
|
|
|
res = next;
|
|
|
|
}
|
|
|
|
Curl_safefree(mlfile);
|
|
|
|
}
|
|
|
|
|
2014-02-23 07:59:59 -05:00
|
|
|
void clean_metalink(struct OperationConfig *config)
|
2012-05-26 09:51:03 -04:00
|
|
|
{
|
|
|
|
while(config->metalinkfile_list) {
|
|
|
|
metalinkfile *mlfile = config->metalinkfile_list;
|
|
|
|
config->metalinkfile_list = config->metalinkfile_list->next;
|
|
|
|
delete_metalinkfile(mlfile);
|
|
|
|
}
|
|
|
|
config->metalinkfile_last = 0;
|
|
|
|
}
|
2012-05-26 17:20:23 -04:00
|
|
|
|
2012-10-31 05:43:36 -04:00
|
|
|
void metalink_cleanup(void)
|
|
|
|
{
|
2017-09-12 14:14:00 -04:00
|
|
|
#ifdef HAVE_NSS_CONTEXT
|
2012-10-30 09:59:48 -04:00
|
|
|
if(nss_context) {
|
|
|
|
NSS_ShutdownContext(nss_context);
|
|
|
|
nss_context = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2012-10-31 05:43:36 -04:00
|
|
|
}
|
|
|
|
|
2012-06-07 17:49:27 -04:00
|
|
|
#endif /* USE_METALINK */
|