(mu_tls_begin): New function.
(_tls_stream_push): Added mu_error call. (_tls_open_client): Return MU_ERR_FAILURE instead of -1.
Showing
1 changed file
with
92 additions
and
6 deletions
... | @@ -235,6 +235,88 @@ initialize_tls_session (void) | ... | @@ -235,6 +235,88 @@ initialize_tls_session (void) |
235 | return session; | 235 | return session; |
236 | } | 236 | } |
237 | 237 | ||
238 | int | ||
239 | mu_tls_begin (void *iodata, | ||
240 | mu_tls_readline_fn reader, | ||
241 | mu_tls_writeline_fn writer, | ||
242 | mu_tls_stream_ctl_fn stream_ctl, | ||
243 | char *keywords[]) | ||
244 | { | ||
245 | int i = 0; | ||
246 | int status; | ||
247 | mu_stream_t oldstr, newstr; | ||
248 | |||
249 | if (keywords == NULL) | ||
250 | return EINVAL; | ||
251 | |||
252 | for (i = 0; keywords[i]; i++) | ||
253 | { | ||
254 | switch (i) | ||
255 | { | ||
256 | case 0: | ||
257 | /* | ||
258 | * Send STLS/STARTTLS | ||
259 | */ | ||
260 | status = writer (iodata, keywords[i]); | ||
261 | if (status != 0) | ||
262 | { | ||
263 | mu_error ("mu_tls_begin: writer (0): %s", mu_strerror (status)); | ||
264 | return status; | ||
265 | } | ||
266 | |||
267 | status = reader (iodata); | ||
268 | if (status != 0) | ||
269 | { | ||
270 | mu_error ("mu_tls_begin: reader (0): %s", mu_strerror (status)); | ||
271 | return status; | ||
272 | } | ||
273 | |||
274 | stream_ctl (iodata, &oldstr, NULL); | ||
275 | status = mu_tls_stream_create_client_from_tcp (&newstr, oldstr, 0); | ||
276 | if (status != 0) | ||
277 | { | ||
278 | mu_error ("mu_tls_begin: mu_tls_stream_create_client_from_tcp (0): %s", | ||
279 | mu_strerror (status)); | ||
280 | return status; | ||
281 | } | ||
282 | |||
283 | status = mu_stream_open (newstr); | ||
284 | if (status != 0) | ||
285 | { | ||
286 | mu_error ("mu_tls_begin: mu_stream_open (0): %s", | ||
287 | mu_strerror (status)); | ||
288 | return status; | ||
289 | } | ||
290 | |||
291 | stream_ctl (iodata, NULL, newstr); | ||
292 | break; | ||
293 | |||
294 | case 1: | ||
295 | /* | ||
296 | * Send CAPABILITIES request | ||
297 | */ | ||
298 | status = writer (iodata, keywords[i]); | ||
299 | if (status != 0) | ||
300 | { | ||
301 | mu_error ("mu_tls_begin: writer (1): %s", mu_strerror (status)); | ||
302 | return status; | ||
303 | } | ||
304 | |||
305 | status = reader (iodata); | ||
306 | if (status != 0) | ||
307 | { | ||
308 | mu_error ("mu_tls_begin: reader (1): %s", mu_strerror (status)); | ||
309 | return status; | ||
310 | } | ||
311 | break; | ||
312 | |||
313 | default: | ||
314 | return 1; | ||
315 | } | ||
316 | } | ||
317 | return 0; | ||
318 | } | ||
319 | |||
238 | /* ************************* TLS Stream Support **************************** */ | 320 | /* ************************* TLS Stream Support **************************** */ |
239 | 321 | ||
240 | enum tls_stream_state { | 322 | enum tls_stream_state { |
... | @@ -405,7 +487,10 @@ _tls_stream_push (gnutls_transport_ptr fd, const void *buf, size_t size) | ... | @@ -405,7 +487,10 @@ _tls_stream_push (gnutls_transport_ptr fd, const void *buf, size_t size) |
405 | 487 | ||
406 | rc = mu_stream_sequential_write (stream, buf, size); | 488 | rc = mu_stream_sequential_write (stream, buf, size); |
407 | if (rc) | 489 | if (rc) |
408 | return -1; | 490 | { |
491 | mu_error ("_tls_stream_push: %s", mu_strerror (rc)); /* FIXME */ | ||
492 | return -1; | ||
493 | } | ||
409 | mu_stream_flush (stream); | 494 | mu_stream_flush (stream); |
410 | return size; | 495 | return size; |
411 | } | 496 | } |
... | @@ -522,12 +607,12 @@ _tls_open_client (mu_stream_t stream) | ... | @@ -522,12 +607,12 @@ _tls_open_client (mu_stream_t stream) |
522 | s->last_err = rc; | 607 | s->last_err = rc; |
523 | gnutls_deinit (s->session); | 608 | gnutls_deinit (s->session); |
524 | s->state = state_init; | 609 | s->state = state_init; |
525 | return -1; | 610 | return MU_ERR_FAILURE; |
526 | } | 611 | } |
527 | break; | 612 | break; |
528 | 613 | ||
529 | default: | 614 | default: |
530 | return -1; | 615 | return MU_ERR_FAILURE; |
531 | } | 616 | } |
532 | 617 | ||
533 | /* FIXME: if (ssl_cafile) verify_certificate (s->session); */ | 618 | /* FIXME: if (ssl_cafile) verify_certificate (s->session); */ |
... | @@ -557,7 +642,8 @@ int | ... | @@ -557,7 +642,8 @@ int |
557 | _tls_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) | 642 | _tls_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) |
558 | { | 643 | { |
559 | struct _tls_stream *s = mu_stream_get_owner (stream); | 644 | struct _tls_stream *s = mu_stream_get_owner (stream); |
560 | if ((*pflags & (MU_STREAM_READY_RD|MU_STREAM_READY_WR)) == (MU_STREAM_READY_RD|MU_STREAM_READY_WR)) | 645 | if ((*pflags & (MU_STREAM_READY_RD|MU_STREAM_READY_WR)) |
646 | == (MU_STREAM_READY_RD|MU_STREAM_READY_WR)) | ||
561 | return EINVAL; /* Sorry, can't wait for both input and output. */ | 647 | return EINVAL; /* Sorry, can't wait for both input and output. */ |
562 | if (*pflags & MU_STREAM_READY_RD) | 648 | if (*pflags & MU_STREAM_READY_RD) |
563 | return mu_stream_wait (s->strin, pflags, tvp); | 649 | return mu_stream_wait (s->strin, pflags, tvp); |
... | @@ -568,8 +654,8 @@ _tls_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) | ... | @@ -568,8 +654,8 @@ _tls_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) |
568 | 654 | ||
569 | /* FIXME: if strin == strout sequential reads may intefere with | 655 | /* FIXME: if strin == strout sequential reads may intefere with |
570 | sequential writes (they would share stream->offset). This should | 656 | sequential writes (they would share stream->offset). This should |
571 | be fixed either in stream.c or here. In particular, mu_tls_stream_create_client | 657 | be fixed either in stream.c or here. In particular, |
572 | will malfunction */ | 658 | mu_tls_stream_create_client will malfunction */ |
573 | int | 659 | int |
574 | mu_tls_stream_create (mu_stream_t *stream, | 660 | mu_tls_stream_create (mu_stream_t *stream, |
575 | mu_stream_t strin, mu_stream_t strout, int flags) | 661 | mu_stream_t strin, mu_stream_t strout, int flags) | ... | ... |
-
Please register or sign in to post a comment