Dillo v3.1.1-46-g8a360e32
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 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
31void a_Tls_init(void)
32{
33#if ! defined(ENABLE_TLS)
34 MSG("TLS: Disabled at compilation time.\n");
35#elif defined(HAVE_OPENSSL)
37#elif defined(HAVE_MBEDTLS)
39#else
40# error "no TLS library found but ENABLE_TLS set"
41#endif
42}
43
48void *a_Tls_connection(int fd)
49{
50#if ! defined(ENABLE_TLS)
51 return NULL;
52#elif defined(HAVE_OPENSSL)
53 return a_Tls_openssl_connection(fd);
54#elif defined(HAVE_MBEDTLS)
55 return a_Tls_mbedtls_connection(fd);
56#else
57# error "no TLS library found but ENABLE_TLS set"
58#endif
59}
60
69{
70#if ! defined(ENABLE_TLS)
71 return TLS_CONNECT_NEVER;
72#elif defined(HAVE_OPENSSL)
74#elif defined(HAVE_MBEDTLS)
76#else
77# error "no TLS library found but ENABLE_TLS set"
78#endif
79}
80
86{
87#if ! defined(ENABLE_TLS)
88 return 0;
89#elif defined(HAVE_OPENSSL)
91#elif defined(HAVE_MBEDTLS)
93#else
94# error "no TLS library found but ENABLE_TLS set"
95#endif
96}
97
102{
103#if ! defined(ENABLE_TLS)
104 return;
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
114
116{
117#if ! defined(ENABLE_TLS)
118 return;
119#elif defined(HAVE_OPENSSL)
121#elif defined(HAVE_MBEDTLS)
123#else
124# error "no TLS library found but ENABLE_TLS set"
125#endif
126}
127
128void a_Tls_connect(int fd, const DilloUrl *url)
129{
130#if ! defined(ENABLE_TLS)
131 return;
132#elif defined(HAVE_OPENSSL)
133 a_Tls_openssl_connect(fd, url);
134#elif defined(HAVE_MBEDTLS)
135 a_Tls_mbedtls_connect(fd, url);
136#else
137# error "no TLS library found but ENABLE_TLS set"
138#endif
139}
140
142{
143#if ! defined(ENABLE_TLS)
144 return;
145#elif defined(HAVE_OPENSSL)
147#elif defined(HAVE_MBEDTLS)
149#else
150# error "no TLS library found but ENABLE_TLS set"
151#endif
152}
153
154int a_Tls_read(void *conn, void *buf, size_t len)
155{
156#if ! defined(ENABLE_TLS)
157 return 0;
158#elif defined(HAVE_OPENSSL)
159 return a_Tls_openssl_read(conn, buf, len);
160#elif defined(HAVE_MBEDTLS)
161 return a_Tls_mbedtls_read(conn, buf, len);
162#else
163# error "no TLS library found but ENABLE_TLS set"
164#endif
165}
166
167int a_Tls_write(void *conn, void *buf, size_t len)
168{
169#if ! defined(ENABLE_TLS)
170 return 0;
171#elif defined(HAVE_OPENSSL)
172 return a_Tls_openssl_write(conn, buf, len);
173#elif defined(HAVE_MBEDTLS)
174 return a_Tls_mbedtls_write(conn, buf, len);
175#else
176# error "no TLS library found but ENABLE_TLS set"
177#endif
178}
#define MSG(...)
Definition bookmarks.c:46
Definition url.h:88
void a_Tls_reset_server_state(const DilloUrl *url)
Definition tls.c:115
void a_Tls_connect(int fd, const DilloUrl *url)
Definition tls.c:128
int a_Tls_read(void *conn, void *buf, size_t len)
Definition tls.c:154
int a_Tls_connect_ready(const DilloUrl *url)
The purpose here is to permit a single initial connection to a server.
Definition tls.c:68
void a_Tls_init(void)
Initialize TLS library.
Definition tls.c:31
int a_Tls_write(void *conn, void *buf, size_t len)
Definition tls.c:167
void a_Tls_close_by_fd(int fd)
Definition tls.c:141
int a_Tls_certificate_is_clean(const DilloUrl *url)
Did everything seem proper with the certificate – no warnings to click through?.
Definition tls.c:85
void a_Tls_freeall(void)
Clean up the TLS library.
Definition tls.c:101
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:48
#define TLS_CONNECT_NEVER
Definition tls.h:30
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)
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)