Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023-2026 Free Software Foundation, Inc. |
3 | | * |
4 | | * This file is part of libwget. |
5 | | * |
6 | | * Libwget is free software: you can redistribute it and/or modify |
7 | | * it under the terms of the GNU Lesser General Public License as published by |
8 | | * the Free Software Foundation, either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * Libwget is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public License |
17 | | * along with libwget. If not, see <https://www.gnu.org/licenses/>. |
18 | | * |
19 | | * |
20 | | * Shared code for the TLS/SSL implementations. |
21 | | */ |
22 | | |
23 | | #include <config.h> |
24 | | |
25 | | #include <wget.h> |
26 | | |
27 | | #ifndef _WIN32 |
28 | | |
29 | | const char *wget_ssl_default_cert_dir(void) |
30 | 4 | { |
31 | 4 | #ifndef __OS2__ |
32 | 4 | return "/etc/ssl/certs"; |
33 | | #else |
34 | | return "/@unixroot/etc/ssl/certs"; |
35 | | #endif |
36 | 4 | } |
37 | | |
38 | | const char *wget_ssl_default_ca_bundle_path(void) |
39 | 4 | { |
40 | 4 | #ifndef __OS2__ |
41 | 4 | return NULL; |
42 | | #else |
43 | | return "/@unixroot/etc/ssl/cert.pem"; |
44 | | #endif |
45 | 4 | } |
46 | | |
47 | | #else // _WIN32 |
48 | | |
49 | | #include <stdlib.h> // getenv |
50 | | #include "filename.h" // ISSLASH |
51 | | |
52 | | #include "private.h" |
53 | | |
54 | | static const char *ssl_default_certdir_path; |
55 | | static const char *ssl_default_certbundle_path; |
56 | | |
57 | | // ssl_default_path() is only called once in tls_init(). |
58 | | static const char *ssl_default_path(const char *base) |
59 | | { |
60 | | if (access("/etc/ssl/certs", F_OK) == 0) { |
61 | | return wget_strdup("/etc/ssl/certs"); |
62 | | } |
63 | | |
64 | | const char *progData = getenv("ProgramData"); |
65 | | |
66 | | if (!progData) |
67 | | progData = "/ProgramData"; |
68 | | |
69 | | return wget_aprintf("%s%s%s%s", |
70 | | progData, |
71 | | ISSLASH(progData[strlen(progData) - 1]) ? "" : "/", |
72 | | "ssl/", |
73 | | base); |
74 | | } |
75 | | |
76 | | const char *wget_ssl_default_cert_dir(void) |
77 | | { |
78 | | if (!ssl_default_certdir_path) |
79 | | ssl_default_certdir_path = ssl_default_path("certs/"); |
80 | | return ssl_default_certdir_path; |
81 | | } |
82 | | |
83 | | const char *wget_ssl_default_ca_bundle_path(void) |
84 | | { |
85 | | if (!ssl_default_certbundle_path) |
86 | | ssl_default_certbundle_path = ssl_default_path("ca-bundle.pem"); |
87 | | return access(ssl_default_certbundle_path, F_OK) == 0 ? ssl_default_certbundle_path: NULL; |
88 | | } |
89 | | #endif |