9 /* #define TLS_INTERNAL
12 /* void tls_stream_start(stream, context)
14 /* TLS_SESS_STATE *context;
16 /* void tls_stream_stop(stream)
19 /* This module implements the VSTREAM over TLS support user interface.
20 /* The hard work is done elsewhere.
22 /* tls_stream_start() enables TLS on the named stream. All read
23 /* and write operations are directed through the TLS library,
24 /* using the state information specified with the context argument.
26 /* tls_stream_stop() replaces the VSTREAM read/write routines
27 /* by dummies that have no side effects, and deletes the
28 /* VSTREAM's reference to the TLS context.
30 /* dummy_read(3), placebo read routine
31 /* dummy_write(3), placebo write routine
35 /* This software is free. You can do with it whatever you want.
36 /* The original author kindly requests that you acknowledge
37 /* the use of his software.
39 /* Based on code that was originally written by:
42 /* Allgemeine Elektrotechnik
43 /* Universitaetsplatz 3-4
44 /* D-03044 Cottbus, Germany
48 /* IBM T.J. Watson Research
50 /* Yorktown Heights, NY 10598, USA
59 /* Utility library. */
70 /* tls_timed_read - read content from stream, then TLS decapsulate */
72 static ssize_t
tls_timed_read(int fd
, void *buf
, size_t len
, int timeout
,
75 const char *myname
= "tls_timed_read";
77 TLS_SESS_STATE
*TLScontext
;
79 TLScontext
= (TLS_SESS_STATE
*) context
;
81 msg_panic("%s: no context", myname
);
83 ret
= tls_bio_read(fd
, buf
, len
, timeout
, TLScontext
);
84 if (ret
> 0 && TLScontext
->log_level
>= 4)
85 msg_info("Read %ld chars: %.*s",
86 (long) ret
, (int) (ret
> 40 ? 40 : ret
), (char *) buf
);
90 /* tls_timed_write - TLS encapsulate content, then write to stream */
92 static ssize_t
tls_timed_write(int fd
, void *buf
, size_t len
, int timeout
,
95 const char *myname
= "tls_timed_write";
96 TLS_SESS_STATE
*TLScontext
;
98 TLScontext
= (TLS_SESS_STATE
*) context
;
100 msg_panic("%s: no context", myname
);
102 if (TLScontext
->log_level
>= 4)
103 msg_info("Write %ld chars: %.*s",
104 (long) len
, (int) (len
> 40 ? 40 : len
), (char *) buf
);
105 return (tls_bio_write(fd
, buf
, len
, timeout
, TLScontext
));
108 /* tls_stream_start - start VSTREAM over TLS */
110 void tls_stream_start(VSTREAM
*stream
, TLS_SESS_STATE
*context
)
112 vstream_control(stream
,
113 VSTREAM_CTL_READ_FN
, tls_timed_read
,
114 VSTREAM_CTL_WRITE_FN
, tls_timed_write
,
115 VSTREAM_CTL_CONTEXT
, (void *) context
,
119 /* tls_stream_stop - stop VSTREAM over TLS */
121 void tls_stream_stop(VSTREAM
*stream
)
125 * Prevent data leakage after TLS is turned off. The Postfix/TLS patch
126 * provided null function pointers; we use dummy routines that make less
129 vstream_control(stream
,
130 VSTREAM_CTL_READ_FN
, dummy_read
,
131 VSTREAM_CTL_WRITE_FN
, dummy_write
,
132 VSTREAM_CTL_CONTEXT
, (void *) 0,