Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2010-2016 Free Software Foundation, Inc. |
3 | | * Copyright (C) 2015-2016 Red Hat, Inc. |
4 | | * |
5 | | * Author: Nikos Mavrogiannopoulos |
6 | | * |
7 | | * This file is part of GnuTLS. |
8 | | * |
9 | | * The GnuTLS is free software; you can redistribute it and/or |
10 | | * modify it under the terms of the GNU Lesser General Public License |
11 | | * as published by the Free Software Foundation; either version 2.1 of |
12 | | * the License, or (at your option) any later version. |
13 | | * |
14 | | * This library is distributed in the hope that it will be useful, but |
15 | | * WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | | * Lesser General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public License |
20 | | * along with this program. If not, see <https://www.gnu.org/licenses/> |
21 | | * |
22 | | */ |
23 | | |
24 | | #include <config.h> |
25 | | #include <system.h> |
26 | | #include "gnutls_int.h" |
27 | | #include "errors.h" |
28 | | |
29 | | #include <sys/socket.h> |
30 | | #include <errno.h> |
31 | | #include <sys/stat.h> |
32 | | #include <sys/types.h> |
33 | | #include <time.h> |
34 | | |
35 | | #ifdef _WIN32 |
36 | | # include <windows.h> |
37 | | # include <wincrypt.h> |
38 | | # if defined(NEED_CERT_ENUM_CRLS) |
39 | | CertEnumCRLsInStoreFunc pCertEnumCRLsInStore; |
40 | | static HMODULE Crypt32_dll; |
41 | | # endif |
42 | | #endif |
43 | | |
44 | | /* System specific function wrappers for certificate stores. |
45 | | */ |
46 | | gnutls_time_func gnutls_time; |
47 | | gnutls_gettime_func gnutls_gettime; |
48 | | |
49 | | /* emulate gnulib's gettime using gettimeofday to avoid linking to |
50 | | * librt */ |
51 | | static void _gnutls_gettime(struct timespec *t) |
52 | 0 | { |
53 | 0 | #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME) |
54 | 0 | clock_gettime(CLOCK_REALTIME, t); |
55 | | #else |
56 | | struct timeval tv; |
57 | | gettimeofday(&tv, NULL); |
58 | | t->tv_sec = tv.tv_sec; |
59 | | t->tv_nsec = tv.tv_usec * 1000; |
60 | | #endif |
61 | 0 | } |
62 | | |
63 | | void _gnutls_global_set_gettime_function(gnutls_gettime_func gettime_func) |
64 | 0 | { |
65 | 0 | gnutls_gettime = gettime_func; |
66 | 0 | } |
67 | | |
68 | | int gnutls_system_global_init(void) |
69 | 2 | { |
70 | | #if defined(_WIN32) && defined(NEED_CERT_ENUM_CRLS) |
71 | | /* used in system/certs.c */ |
72 | | HMODULE crypto; |
73 | | crypto = LoadLibrary(TEXT("Crypt32.dll")); |
74 | | |
75 | | if (crypto == NULL) |
76 | | return GNUTLS_E_CRYPTO_INIT_FAILED; |
77 | | |
78 | | pCertEnumCRLsInStore = |
79 | | (CertEnumCRLsInStoreFunc) GetProcAddress(crypto, |
80 | | "CertEnumCRLsInStore"); |
81 | | if (pCertEnumCRLsInStore == NULL) { |
82 | | FreeLibrary(crypto); |
83 | | return GNUTLS_E_CRYPTO_INIT_FAILED; |
84 | | } |
85 | | |
86 | | Crypt32_dll = crypto; |
87 | | #endif |
88 | 2 | gnutls_time = time; |
89 | 2 | gnutls_gettime = _gnutls_gettime; |
90 | 2 | return 0; |
91 | 2 | } |
92 | | |
93 | | void gnutls_system_global_deinit(void) |
94 | 0 | { |
95 | | #if defined(_WIN32) && defined(NEED_CERT_ENUM_CRLS) |
96 | | FreeLibrary(Crypt32_dll); |
97 | | #endif |
98 | 0 | gnutls_time = time; |
99 | 0 | gnutls_gettime = _gnutls_gettime; |
100 | 0 | } |