Implemented client side TLS.
Showing
1 changed file
with
50 additions
and
5 deletions
... | @@ -54,6 +54,7 @@ | ... | @@ -54,6 +54,7 @@ |
54 | #include <mailutils/property.h> | 54 | #include <mailutils/property.h> |
55 | #include <mailutils/stream.h> | 55 | #include <mailutils/stream.h> |
56 | #include <mailutils/url.h> | 56 | #include <mailutils/url.h> |
57 | #include <mailutils/tls.h> | ||
57 | 58 | ||
58 | #include <folder0.h> | 59 | #include <folder0.h> |
59 | #include <mailbox0.h> | 60 | #include <mailbox0.h> |
... | @@ -127,13 +128,13 @@ int _pop_apop __P ((authority_t)); | ... | @@ -127,13 +128,13 @@ int _pop_apop __P ((authority_t)); |
127 | static int pop_get_size __P ((mailbox_t, off_t *)); | 128 | static int pop_get_size __P ((mailbox_t, off_t *)); |
128 | /* We use pop_top for retreiving headers. */ | 129 | /* We use pop_top for retreiving headers. */ |
129 | /* static int pop_header_read (header_t, char *, size_t, off_t, size_t *); */ | 130 | /* static int pop_header_read (header_t, char *, size_t, off_t, size_t *); */ |
130 | static int pop_body_fd __P ((stream_t, int *)); | 131 | static int pop_body_fd __P ((stream_t, int *, int *)); |
131 | static int pop_body_size __P ((body_t, size_t *)); | 132 | static int pop_body_size __P ((body_t, size_t *)); |
132 | static int pop_body_lines __P ((body_t, size_t *)); | 133 | static int pop_body_lines __P ((body_t, size_t *)); |
133 | static int pop_body_read __P ((stream_t, char *, size_t, off_t, size_t *)); | 134 | static int pop_body_read __P ((stream_t, char *, size_t, off_t, size_t *)); |
134 | static int pop_message_read __P ((stream_t, char *, size_t, off_t, size_t *)); | 135 | static int pop_message_read __P ((stream_t, char *, size_t, off_t, size_t *)); |
135 | static int pop_message_size __P ((message_t, size_t *)); | 136 | static int pop_message_size __P ((message_t, size_t *)); |
136 | static int pop_message_fd __P ((stream_t, int *)); | 137 | static int pop_message_fd __P ((stream_t, int *, int *)); |
137 | static int pop_top __P ((header_t, char *, size_t, off_t, size_t *)); | 138 | static int pop_top __P ((header_t, char *, size_t, off_t, size_t *)); |
138 | static int pop_retr __P ((pop_message_t, char *, size_t, off_t, size_t *)); | 139 | static int pop_retr __P ((pop_message_t, char *, size_t, off_t, size_t *)); |
139 | static int pop_get_fd __P ((pop_message_t, int *)); | 140 | static int pop_get_fd __P ((pop_message_t, int *)); |
... | @@ -554,6 +555,40 @@ _pop_apop (authority_t auth) | ... | @@ -554,6 +555,40 @@ _pop_apop (authority_t auth) |
554 | return 0; | 555 | return 0; |
555 | } | 556 | } |
556 | 557 | ||
558 | static | ||
559 | int | ||
560 | tls (mailbox_t mbox) | ||
561 | { | ||
562 | #ifdef WITH_TLS | ||
563 | pop_data_t mpd = mbox->data; | ||
564 | int status; | ||
565 | stream_t str; | ||
566 | |||
567 | if (!mu_tls_enable || !(mpd->capa & CAPA_STLS)) | ||
568 | return -1; | ||
569 | |||
570 | status = pop_writeline (mpd, "STLS\r\n"); | ||
571 | CHECK_ERROR (mpd, status); | ||
572 | status = pop_write (mpd); | ||
573 | CHECK_EAGAIN (mpd, status); | ||
574 | status = pop_read_ack (mpd); | ||
575 | CHECK_ERROR (mpd, status); | ||
576 | MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); | ||
577 | if (strncasecmp (mpd->buffer, "+OK", 3) != 0) | ||
578 | return -1; | ||
579 | |||
580 | status = tls_stream_create_client_from_tcp (&str, mbox->stream, 0); | ||
581 | CHECK_ERROR (mpd, status); | ||
582 | status = stream_open (str); | ||
583 | if (status == 0) | ||
584 | mbox->stream = str; | ||
585 | MAILBOX_DEBUG1 (mbox, MU_DEBUG_PROT, "TLS negotiation %s\n", | ||
586 | status == 0 ? "succeeded" : "failed"); | ||
587 | return status; | ||
588 | #else | ||
589 | return -1; | ||
590 | #endif | ||
591 | } | ||
557 | 592 | ||
558 | /* Open the connection to the sever, and send the authentication. */ | 593 | /* Open the connection to the sever, and send the authentication. */ |
559 | static int | 594 | static int |
... | @@ -697,7 +732,7 @@ pop_open (mailbox_t mbox, int flags) | ... | @@ -697,7 +732,7 @@ pop_open (mailbox_t mbox, int flags) |
697 | 732 | ||
698 | case POP_STLS: | 733 | case POP_STLS: |
699 | case POP_STLS_ACK: | 734 | case POP_STLS_ACK: |
700 | 735 | tls (mbox); | |
701 | mpd->state = POP_AUTH; | 736 | mpd->state = POP_AUTH; |
702 | 737 | ||
703 | case POP_AUTH: | 738 | case POP_AUTH: |
... | @@ -1344,21 +1379,31 @@ pop_unset_attribute (attribute_t attr, int flags) | ... | @@ -1344,21 +1379,31 @@ pop_unset_attribute (attribute_t attr, int flags) |
1344 | 1379 | ||
1345 | /* Stub to call the fd from body object. */ | 1380 | /* Stub to call the fd from body object. */ |
1346 | static int | 1381 | static int |
1347 | pop_body_fd (stream_t stream, int *pfd) | 1382 | pop_body_fd (stream_t stream, int *pfd, int *pfd1) |
1348 | { | 1383 | { |
1384 | if (pfd1) | ||
1385 | return ENOSYS; | ||
1386 | else | ||
1387 | { | ||
1349 | body_t body = stream_get_owner (stream); | 1388 | body_t body = stream_get_owner (stream); |
1350 | message_t msg = body_get_owner (body); | 1389 | message_t msg = body_get_owner (body); |
1351 | pop_message_t mpm = message_get_owner (msg); | 1390 | pop_message_t mpm = message_get_owner (msg); |
1352 | return pop_get_fd (mpm, pfd); | 1391 | return pop_get_fd (mpm, pfd); |
1392 | } | ||
1353 | } | 1393 | } |
1354 | 1394 | ||
1355 | /* Stub to call the fd from message object. */ | 1395 | /* Stub to call the fd from message object. */ |
1356 | static int | 1396 | static int |
1357 | pop_message_fd (stream_t stream, int *pfd) | 1397 | pop_message_fd (stream_t stream, int *pfd, int *pfd2) |
1358 | { | 1398 | { |
1399 | if (pfd2) | ||
1400 | return ENOSYS; | ||
1401 | else | ||
1402 | { | ||
1359 | message_t msg = stream_get_owner (stream); | 1403 | message_t msg = stream_get_owner (stream); |
1360 | pop_message_t mpm = message_get_owner (msg); | 1404 | pop_message_t mpm = message_get_owner (msg); |
1361 | return pop_get_fd (mpm, pfd); | 1405 | return pop_get_fd (mpm, pfd); |
1406 | } | ||
1362 | } | 1407 | } |
1363 | 1408 | ||
1364 | /* Finally return the fd. */ | 1409 | /* Finally return the fd. */ | ... | ... |
-
Please register or sign in to post a comment