3636
3737#include "https_source_hook_bearssl.h"
3838
39+ static const char * error_string (int error_code )
40+ {
41+ switch (error_code ) {
42+ case BR_ERR_OK :
43+ return "OK" ;
44+ case BR_ERR_BAD_PARAM :
45+ return "BAD_PARAM" ;
46+ case BR_ERR_BAD_STATE :
47+ return "BAD_STATE" ;
48+ case BR_ERR_UNSUPPORTED_VERSION :
49+ return "UNSUPPORTED_VERSION" ;
50+ case BR_ERR_BAD_VERSION :
51+ return "BAD_VERSION" ;
52+ case BR_ERR_BAD_LENGTH :
53+ return "BAD_LENGTH" ;
54+ case BR_ERR_TOO_LARGE :
55+ return "TOO_LARGE" ;
56+ case BR_ERR_BAD_MAC :
57+ return "BAD_MAC" ;
58+ case BR_ERR_NO_RANDOM :
59+ return "NO_RANDOM" ;
60+ case BR_ERR_UNKNOWN_TYPE :
61+ return "UNKNOWN_TYPE" ;
62+ case BR_ERR_UNEXPECTED :
63+ return "UNEXPECTED" ;
64+ case BR_ERR_BAD_CCS :
65+ return "BAD_CCS" ;
66+ case BR_ERR_BAD_ALERT :
67+ return "BAD_ALERT" ;
68+ case BR_ERR_BAD_HANDSHAKE :
69+ return "BAD_HANDSHAKE" ;
70+ case BR_ERR_OVERSIZED_ID :
71+ return "OVERSIZED_ID" ;
72+ case BR_ERR_BAD_CIPHER_SUITE :
73+ return "BAD_CIPHER_SUITE" ;
74+ case BR_ERR_BAD_COMPRESSION :
75+ return "BAD_COMPRESSION" ;
76+ case BR_ERR_BAD_FRAGLEN :
77+ return "BAD_FRAGLEN" ;
78+ case BR_ERR_BAD_SECRENEG :
79+ return "BAD_SECRENEG" ;
80+ case BR_ERR_EXTRA_EXTENSION :
81+ return "EXTRA_EXTENSION" ;
82+ case BR_ERR_BAD_SNI :
83+ return "BAD_SNI" ;
84+ case BR_ERR_BAD_HELLO_DONE :
85+ return "BAD_HELLO_DONE" ;
86+ case BR_ERR_LIMIT_EXCEEDED :
87+ return "LIMIT_EXCEEDED" ;
88+ case BR_ERR_BAD_FINISHED :
89+ return "BAD_FINISHED" ;
90+ case BR_ERR_RESUME_MISMATCH :
91+ return "RESUME_MISMATCH" ;
92+ case BR_ERR_INVALID_ALGORITHM :
93+ return "INVALID_ALGORITHM" ;
94+ case BR_ERR_BAD_SIGNATURE :
95+ return "BAD_SIGNATURE" ;
96+ case BR_ERR_WRONG_KEY_USAGE :
97+ return "WRONG_KEY_USAGE" ;
98+ case BR_ERR_NO_CLIENT_AUTH :
99+ return "NO_CLIENT_AUTH" ;
100+ case BR_ERR_IO :
101+ return "IO" ;
102+ case BR_ERR_RECV_FATAL_ALERT :
103+ return "RECV_FATAL_ALERT" ;
104+ case BR_ERR_SEND_FATAL_ALERT :
105+ return "SEND_FATAL_ALERT" ;
106+ case BR_ERR_X509_OK :
107+ return "X509_OK" ;
108+ case BR_ERR_X509_INVALID_VALUE :
109+ return "X509_INVALID_VALUE" ;
110+ case BR_ERR_X509_TRUNCATED :
111+ return "X509_TRUNCATED" ;
112+ case BR_ERR_X509_EMPTY_CHAIN :
113+ return "X509_EMPTY_CHAIN" ;
114+ case BR_ERR_X509_INNER_TRUNC :
115+ return "X509_INNER_TRUNC" ;
116+ case BR_ERR_X509_BAD_TAG_CLASS :
117+ return "X509_BAD_TAG_CLASS" ;
118+ case BR_ERR_X509_BAD_TAG_VALUE :
119+ return "X509_BAD_TAG_VALUE" ;
120+ case BR_ERR_X509_INDEFINITE_LENGTH :
121+ return "X509_INDEFINITE_LENGTH" ;
122+ case BR_ERR_X509_EXTRA_ELEMENT :
123+ return "X509_EXTRA_ELEMENT" ;
124+ case BR_ERR_X509_UNEXPECTED :
125+ return "X509_UNEXPECTED" ;
126+ case BR_ERR_X509_NOT_CONSTRUCTED :
127+ return "X509_NOT_CONSTRUCTED" ;
128+ case BR_ERR_X509_NOT_PRIMITIVE :
129+ return "X509_NOT_PRIMITIVE" ;
130+ case BR_ERR_X509_PARTIAL_BYTE :
131+ return "X509_PARTIAL_BYTE" ;
132+ case BR_ERR_X509_BAD_BOOLEAN :
133+ return "X509_BAD_BOOLEAN" ;
134+ case BR_ERR_X509_OVERFLOW :
135+ return "X509_OVERFLOW" ;
136+ case BR_ERR_X509_BAD_DN :
137+ return "X509_BAD_DN" ;
138+ case BR_ERR_X509_BAD_TIME :
139+ return "X509_BAD_TIME" ;
140+ case BR_ERR_X509_UNSUPPORTED :
141+ return "X509_UNSUPPORTED" ;
142+ case BR_ERR_X509_LIMIT_EXCEEDED :
143+ return "X509_LIMIT_EXCEEDED" ;
144+ case BR_ERR_X509_WRONG_KEY_TYPE :
145+ return "X509_WRONG_KEY_TYPE" ;
146+ case BR_ERR_X509_BAD_SIGNATURE :
147+ return "X509_BAD_SIGNATURE" ;
148+ case BR_ERR_X509_TIME_UNKNOWN :
149+ return "X509_TIME_UNKNOWN" ;
150+ case BR_ERR_X509_EXPIRED :
151+ return "X509_EXPIRED" ;
152+ case BR_ERR_X509_DN_MISMATCH :
153+ return "X509_DN_MISMATCH" ;
154+ case BR_ERR_X509_BAD_SERVER_NAME :
155+ return "X509_BAD_SERVER_NAME" ;
156+ case BR_ERR_X509_CRITICAL_EXTENSION :
157+ return "X509_CRITICAL_EXTENSION" ;
158+ case BR_ERR_X509_NOT_CA :
159+ return "X509_NOT_CA" ;
160+ case BR_ERR_X509_FORBIDDEN_KEY_USAGE :
161+ return "X509_FORBIDDEN_KEY_USAGE" ;
162+ case BR_ERR_X509_WEAK_PUBLIC_KEY :
163+ return "X509_WEAK_PUBLIC_KEY" ;
164+ case BR_ERR_X509_NOT_TRUSTED :
165+ return "X509_NOT_TRUSTED" ;
166+ }
167+ return "Unknown error" ;
168+ }
169+
39170/** This describes a x509 no anchor context to allow not trusted certificate. */
40171struct x509_noanchor_context {
41172 const br_x509_class * vtable ;
@@ -168,12 +299,14 @@ static int https_src_hook_state_to_code(unsigned state)
168299
169300/** @internal @This reads from the socket to the SSL engine.
170301 *
302+ * @param upipe description structure of the pipe
171303 * @param hook SSL hook structure
172304 * @param fd socket file descriptor
173305 * @return 0 or negative value on error, 1 if more data is needed, 2 otherwise
174306 */
175307static int
176- https_src_hook_transport_read (struct upipe_http_src_hook * hook , int fd )
308+ https_src_hook_transport_read (struct upipe * upipe ,
309+ struct upipe_http_src_hook * hook , int fd )
177310{
178311 struct https_src_hook_bearssl * https =
179312 https_src_hook_bearssl_from_hook (hook );
@@ -196,12 +329,14 @@ https_src_hook_transport_read(struct upipe_http_src_hook *hook, int fd)
196329
197330/** @internal @This writes from the SSL engine to the socket.
198331 *
332+ * @param upipe description structure of the pipe
199333 * @param hook SSL hook structure
200334 * @param fd socket file descriptor
201335 * @return 0 or negative value on error, 1 if more data is needed, 2 otherwise
202336 */
203337static int
204- https_src_hook_transport_write (struct upipe_http_src_hook * hook , int fd )
338+ https_src_hook_transport_write (struct upipe * upipe ,
339+ struct upipe_http_src_hook * hook , int fd )
205340{
206341 struct https_src_hook_bearssl * https =
207342 https_src_hook_bearssl_from_hook (hook );
@@ -223,13 +358,15 @@ https_src_hook_transport_write(struct upipe_http_src_hook *hook, int fd)
223358
224359/** @internal @This reads data from the SSL engine to a buffer.
225360 *
361+ * @param upipe description structure of the pipe
226362 * @param hook SSL hook structure
227363 * @param buffer filled with data
228364 * @param count buffer size
229365 * @return a negative value on error, 0 if the connection is closed, the number
230366 * of bytes written to the buffer
231367 */
232- static ssize_t https_src_hook_data_read (struct upipe_http_src_hook * hook ,
368+ static ssize_t https_src_hook_data_read (struct upipe * upipe ,
369+ struct upipe_http_src_hook * hook ,
233370 uint8_t * buffer , size_t count )
234371{
235372 struct https_src_hook_bearssl * https =
@@ -247,8 +384,10 @@ static ssize_t https_src_hook_data_read(struct upipe_http_src_hook *hook,
247384 }
248385 else if (state & BR_SSL_CLOSED ) {
249386 int err = br_ssl_engine_last_error (eng );
250- if (err )
387+ if (err ) {
388+ upipe_err_va (upipe , "connection failed (%s)" , error_string (err ));
251389 errno = EIO ;
390+ }
252391 rsize = err ? -1 : 0 ;
253392 }
254393 else
@@ -259,12 +398,14 @@ static ssize_t https_src_hook_data_read(struct upipe_http_src_hook *hook,
259398
260399/** @internal @This writes data from a buffer to the SSL engine.
261400 *
401+ * @param upipe description structure of the pipe
262402 * @param hook SSL hook structure
263403 * @param buffer data to write
264404 * @param count buffer number of bytes in the buffer
265405 * @return a negative value on error or the number of bytes read from the buffer
266406 */
267- static ssize_t https_src_hook_data_write (struct upipe_http_src_hook * hook ,
407+ static ssize_t https_src_hook_data_write (struct upipe * upipe ,
408+ struct upipe_http_src_hook * hook ,
268409 const uint8_t * buffer , size_t count )
269410{
270411 struct https_src_hook_bearssl * https =
0 commit comments