|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* Copyright (C) 2010-2016 Free Software Foundation, Inc.
|
|
Packit |
aea12f |
* Copyright (C) 2015-2016 Red Hat, Inc.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Author: Nikos Mavrogiannopoulos
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This file is part of GnuTLS.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* The GnuTLS is free software; you can redistribute it and/or
|
|
Packit |
aea12f |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit |
aea12f |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
aea12f |
* the License, or (at your option) any later version.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This library is distributed in the hope that it will be useful, but
|
|
Packit |
aea12f |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aea12f |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
aea12f |
* Lesser General Public License for more details.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
aea12f |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <config.h>
|
|
Packit |
aea12f |
#include <system.h>
|
|
Packit |
aea12f |
#include "gnutls_int.h"
|
|
Packit |
aea12f |
#include "errors.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <sys/socket.h>
|
|
Packit |
aea12f |
#include <errno.h>
|
|
Packit |
aea12f |
#include <sys/stat.h>
|
|
Packit |
aea12f |
#include <sys/types.h>
|
|
Packit |
aea12f |
#include <time.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#ifdef _WIN32
|
|
Packit |
aea12f |
# include <windows.h>
|
|
Packit |
aea12f |
# include <wincrypt.h>
|
|
Packit |
aea12f |
# if defined(NEED_CERT_ENUM_CRLS)
|
|
Packit |
aea12f |
CertEnumCRLsInStoreFunc pCertEnumCRLsInStore;
|
|
Packit |
aea12f |
static HMODULE Crypt32_dll;
|
|
Packit |
aea12f |
# endif
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* System specific function wrappers for certificate stores.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_time_func gnutls_time;
|
|
Packit |
aea12f |
gnutls_gettime_func gnutls_gettime;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* emulate gnulib's gettime using gettimeofday to avoid linking to
|
|
Packit |
aea12f |
* librt */
|
|
Packit |
aea12f |
static void _gnutls_gettime(struct timespec *t)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
|
|
Packit |
aea12f |
clock_gettime(CLOCK_REALTIME, t);
|
|
Packit |
aea12f |
#else
|
|
Packit |
aea12f |
struct timeval tv;
|
|
Packit |
aea12f |
gettimeofday(&tv, NULL);
|
|
Packit |
aea12f |
t->tv_sec = tv.tv_sec;
|
|
Packit |
aea12f |
t->tv_nsec = tv.tv_usec * 1000;
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
void _gnutls_global_set_gettime_function(gnutls_gettime_func gettime_func)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
gnutls_gettime = gettime_func;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
int gnutls_system_global_init(void)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
#if defined(_WIN32) && defined(NEED_CERT_ENUM_CRLS)
|
|
Packit |
aea12f |
/* used in system/certs.c */
|
|
Packit |
aea12f |
HMODULE crypto;
|
|
Packit |
aea12f |
crypto = LoadLibrary(TEXT("Crypt32.dll"));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (crypto == NULL)
|
|
Packit |
aea12f |
return GNUTLS_E_CRYPTO_INIT_FAILED;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
pCertEnumCRLsInStore =
|
|
Packit |
aea12f |
(CertEnumCRLsInStoreFunc) GetProcAddress(crypto,
|
|
Packit |
aea12f |
"CertEnumCRLsInStore");
|
|
Packit |
aea12f |
if (pCertEnumCRLsInStore == NULL) {
|
|
Packit |
aea12f |
FreeLibrary(crypto);
|
|
Packit |
aea12f |
return GNUTLS_E_CRYPTO_INIT_FAILED;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
Crypt32_dll = crypto;
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
gnutls_time = time;
|
|
Packit |
aea12f |
gnutls_gettime = _gnutls_gettime;
|
|
Packit |
aea12f |
return 0;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
void gnutls_system_global_deinit(void)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
#if defined(_WIN32) && defined(NEED_CERT_ENUM_CRLS)
|
|
Packit |
aea12f |
FreeLibrary(Crypt32_dll);
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
gnutls_time = time;
|
|
Packit |
aea12f |
gnutls_gettime = _gnutls_gettime;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|