/*++ /* NAME /* tls_bio_ops 3 /* SUMMARY /* TLS network basic I/O management /* SYNOPSIS /* #define TLS_INTERNAL /* #include <tls.h> /* /* int tls_bio_connect(fd, timeout, context) /* int fd; /* int timeout; /* TLS_SESS_STATE *context; /* /* int tls_bio_accept(fd, timeout, context) /* int fd; /* int timeout; /* TLS_SESS_STATE *context; /* /* int tls_bio_shutdown(fd, timeout, context) /* int fd; /* int timeout; /* TLS_SESS_STATE *context; /* /* int tls_bio_read(fd, buf, len, timeout, context) /* int fd; /* void *buf; /* int len; /* int timeout; /* TLS_SESS_STATE *context; /* /* int tls_bio_write(fd, buf, len, timeout, context) /* int fd; /* void *buf; /* int len; /* int timeout; /* TLS_SESS_STATE *context; /* DESCRIPTION /* This module enforces VSTREAM-style timeouts on non-blocking /* I/O while performing TLS handshake or input/output operations. /* /* The Postfix VSTREAM read/write routines invoke the /* tls_bio_read/write routines to send and receive plain-text /* data. In addition, this module provides tls_bio_connect/accept /* routines that trigger the initial TLS handshake. The /* tls_bio_xxx routines invoke the corresponding SSL routines /* that translate the requests into TLS protocol messages. /* /* Whenever an SSL operation indicates that network input (or /* output) needs to happen, the tls_bio_xxx routines wait for /* the network to become readable (or writable) within the /* timeout limit, then retry the SSL operation. This works /* because the network socket is in non-blocking mode. /* /* tls_bio_connect() performs the SSL_connect() operation. /* /* tls_bio_accept() performs the SSL_accept() operation. /* /* tls_bio_shutdown() performs the SSL_shutdown() operation. /* /* tls_bio_read() performs the SSL_read() operation. /* /* tls_bio_write() performs the SSL_write() operation. /* /* Arguments: /* .IP fd /* Network socket. /* .IP buf /* Read/write buffer. /* .IP len /* Read/write request size. /* .IP timeout /* Read/write timeout. /* .IP TLScontext /* TLS session state. /* DIAGNOSTICS /* A result value > 0 means successful completion. /* /* A result value < 0 means that the requested operation did /* not complete due to TLS protocol failure, system call /* failure, or for any reason described under "in addition" /* below. /* /* A result value of 0 from tls_bio_shutdown() means that the /* operation is in progress. A result value of 0 from other /* tls_bio_ops(3) operations means that the remote party either /* closed the network connection or that it sent a TLS shutdown /* request. /* /* Upon return from the tls_bio_ops(3) routines the global /* errno value is non-zero when the requested operation did not /* complete due to system call failure. /* /* In addition, the result value is set to -1, and the global /* errno value is set to ETIMEDOUT, when some network read/write /* operation did not complete within the time limit. /* LICENSE /* .ad /* .fi /* This software is free. You can do with it whatever you want. /* The original author kindly requests that you acknowledge /* the use of his software. /* AUTHOR(S) /* Originally written by: /* Lutz Jaenicke /* BTU Cottbus /* Allgemeine Elektrotechnik /* Universitaetsplatz 3-4 /* D-03044 Cottbus, Germany /* /* Updated by: /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA /* /* Victor Duchovni /* Morgan Stanley
/*--*/
/* System library. */
#include <sys_defs.h> #include <sys/time.h>
#ifndef timersub /* res = a - b */ #define timersub(a, b, res) do { \
(res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ if ((res)->tv_usec < 0) { \
(res)->tv_sec--; \
(res)->tv_usec += 1000000; \
} \
} while (0) #endif
int tls_bio(int fd, int timeout, TLS_SESS_STATE *TLScontext, int (*hsfunc) (SSL *), int (*rfunc) (SSL *, void *, int), int (*wfunc) (SSL *, constvoid *, int), void *buf, int num)
{ constchar *myname = "tls_bio"; int status; int err; int enable_deadline; struct timeval time_left; /* amount of time left */ struct timeval time_deadline; /* time of deadline */ struct timeval time_now; /* time after SSL_mumble() call */
if (hsfunc)
status = hsfunc(TLScontext->con); elseif (rfunc)
status = rfunc(TLScontext->con, buf, num); elseif (wfunc)
status = wfunc(TLScontext->con, buf, num); else
msg_panic("%s: nothing to do here", myname);
err = SSL_get_error(TLScontext->con, status);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.