Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
tls.c
Go to the documentation of this file.
1/*
2 * File: tls.c
3 *
4 * Copyright (C) 2011 Benjamin Johnson <obeythepenguin@users.sourceforge.net>
5 * (for the https code offered from dplus browser that formed the basis...)
6 * Copyright 2016 corvid
7 * Copyright (C) 2023-2024 Rodrigo Arias Mallo <rodarima@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * As a special exception, permission is granted to link Dillo with the OpenSSL
15 * or LibreSSL library, and distribute the linked executables without
16 * including the source code for OpenSSL or LibreSSL in the source
17 * distribution. You must obey the GNU General Public License, version 3, in
18 * all respects for all of the code used other than OpenSSL or LibreSSL.
19 */
20
21#include "config.h"
22#include "../msg.h"
23
24#include "tls.h"
25#include "tls_openssl.h"
26#include "tls_mbedtls.h"
27
31const char *a_Tls_version(char *buf, int n)
32{
33#if ! defined(ENABLE_TLS)
34 return NULL;
35#elif defined(HAVE_OPENSSL)
36 return a_Tls_openssl_version(buf, n);
37#elif defined(HAVE_MBEDTLS)
38 return a_Tls_mbedtls_version(buf, n);
39#else
40# error "no TLS library found but ENABLE_TLS set"
41#endif
42}
43
47void a_Tls_init(void)
48{
49#if ! defined(ENABLE_TLS)
50 MSG("TLS: Disabled at compilation time.\n");
51#elif defined(HAVE_OPENSSL)
53#elif defined(HAVE_MBEDTLS)
55#else
56# error "no TLS library found but ENABLE_TLS set"
57#endif
58}
59
64void *a_Tls_connection(int fd)
65{
66#if ! defined(ENABLE_TLS)
67 return NULL;
68#elif defined(HAVE_OPENSSL)
69 return a_Tls_openssl_connection(fd);
70#elif defined(HAVE_MBEDTLS)
71 return a_Tls_mbedtls_connection(fd);
72#else
73# error "no TLS library found but ENABLE_TLS set"
74#endif
75}
76
85{
86#if ! defined(ENABLE_TLS)
87 return TLS_CONNECT_NEVER;
88#elif defined(HAVE_OPENSSL)
90#elif defined(HAVE_MBEDTLS)
92#else
93# error "no TLS library found but ENABLE_TLS set"
94#endif
95}
96
102{
103#if ! defined(ENABLE_TLS)
104 return 0;
105#elif defined(HAVE_OPENSSL)
107#elif defined(HAVE_MBEDTLS)
109#else
110# error "no TLS library found but ENABLE_TLS set"
111#endif
112}
113
118{
119#if ! defined(ENABLE_TLS)
120 return;
121#elif defined(HAVE_OPENSSL)
123#elif defined(HAVE_MBEDTLS)
125#else
126# error "no TLS library found but ENABLE_TLS set"
127#endif
128}
129
130
132{
133#if ! defined(ENABLE_TLS)
134 return;
135#elif defined(HAVE_OPENSSL)
137#elif defined(HAVE_MBEDTLS)
139#else
140# error "no TLS library found but ENABLE_TLS set"
141#endif
142}
143
144void a_Tls_connect(int fd, const DilloUrl *url)
145{
146#if ! defined(ENABLE_TLS)
147 return;
148#elif defined(HAVE_OPENSSL)
149 a_Tls_openssl_connect(fd, url);
150#elif defined(HAVE_MBEDTLS)
151 a_Tls_mbedtls_connect(fd, url);
152#else
153# error "no TLS library found but ENABLE_TLS set"
154#endif
155}
156
158{
159#if ! defined(ENABLE_TLS)
160 return;
161#elif defined(HAVE_OPENSSL)
163#elif defined(HAVE_MBEDTLS)
165#else
166# error "no TLS library found but ENABLE_TLS set"
167#endif
168}
169
170int a_Tls_read(void *conn, void *buf, size_t len)
171{
172#if ! defined(ENABLE_TLS)
173 return 0;
174#elif defined(HAVE_OPENSSL)
175 return a_Tls_openssl_read(conn, buf, len);
176#elif defined(HAVE_MBEDTLS)
177 return a_Tls_mbedtls_read(conn, buf, len);
178#else
179# error "no TLS library found but ENABLE_TLS set"
180#endif
181}
182
183int a_Tls_write(void *conn, void *buf, size_t len)
184{
185#if ! defined(ENABLE_TLS)
186 return 0;
187#elif defined(HAVE_OPENSSL)
188 return a_Tls_openssl_write(conn, buf, len);
189#elif defined(HAVE_MBEDTLS)
190 return a_Tls_mbedtls_write(conn, buf, len);
191#else
192# error "no TLS library found but ENABLE_TLS set"
193#endif
194}
#define MSG(...)
Definition bookmarks.c:46
Definition url.h:88
void a_Tls_reset_server_state(const DilloUrl *url)
Definition tls.c:131
void a_Tls_connect(int fd, const DilloUrl *url)
Definition tls.c:144
int a_Tls_read(void *conn, void *buf, size_t len)
Definition tls.c:170
int a_Tls_connect_ready(const DilloUrl *url)
The purpose here is to permit a single initial connection to a server.
Definition tls.c:84
const char * a_Tls_version(char *buf, int n)
Get the version of the TLS library.
Definition tls.c:31
void a_Tls_init(void)
Initialize TLS library.
Definition tls.c:47
int a_Tls_write(void *conn, void *buf, size_t len)
Definition tls.c:183
void a_Tls_close_by_fd(int fd)
Definition tls.c:157
int a_Tls_certificate_is_clean(const DilloUrl *url)
Did everything seem proper with the certificate – no warnings to click through?.
Definition tls.c:101
void a_Tls_freeall(void)
Clean up the TLS library.
Definition tls.c:117
void * a_Tls_connection(int fd)
Return TLS connection information for a given file descriptor, or NULL if no TLS connection was found...
Definition tls.c:64
#define TLS_CONNECT_NEVER
Definition tls.h:30
const char * a_Tls_mbedtls_version(char *buf, int n)
int a_Tls_mbedtls_certificate_is_clean(const DilloUrl *url)
void * a_Tls_mbedtls_connection(int fd)
void a_Tls_mbedtls_init(void)
void a_Tls_mbedtls_reset_server_state(const DilloUrl *url)
void a_Tls_mbedtls_freeall(void)
void a_Tls_mbedtls_close_by_fd(int fd)
int a_Tls_mbedtls_write(void *conn, void *buf, size_t len)
int a_Tls_mbedtls_read(void *conn, void *buf, size_t len)
int a_Tls_mbedtls_connect_ready(const DilloUrl *url)
void a_Tls_mbedtls_connect(int fd, const DilloUrl *url)
void a_Tls_openssl_reset_server_state(const DilloUrl *url)
int a_Tls_openssl_read(void *conn, void *buf, size_t len)
void * a_Tls_openssl_connection(int fd)
int a_Tls_openssl_connect_ready(const DilloUrl *url)
void a_Tls_openssl_init(void)
void a_Tls_openssl_close_by_fd(int fd)
const char * a_Tls_openssl_version(char *buf, int n)
void a_Tls_openssl_connect(int fd, const DilloUrl *url)
int a_Tls_openssl_certificate_is_clean(const DilloUrl *url)
void a_Tls_openssl_freeall(void)
int a_Tls_openssl_write(void *conn, void *buf, size_t len)