Home | History | Annotate | Line # | Download | only in man3
      1      1.1  christos =pod
      2      1.1  christos 
      3      1.1  christos =head1 NAME
      4      1.1  christos 
      5  1.1.1.6  christos SSL_write_ex, SSL_write, SSL_sendfile - write bytes to a TLS/SSL connection
      6      1.1  christos 
      7      1.1  christos =head1 SYNOPSIS
      8      1.1  christos 
      9      1.1  christos  #include <openssl/ssl.h>
     10      1.1  christos 
     11  1.1.1.6  christos  ossl_ssize_t SSL_sendfile(SSL *s, int fd, off_t offset, size_t size, int flags);
     12      1.1  christos  int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
     13      1.1  christos  int SSL_write(SSL *ssl, const void *buf, int num);
     14      1.1  christos 
     15      1.1  christos =head1 DESCRIPTION
     16      1.1  christos 
     17      1.1  christos SSL_write_ex() and SSL_write() write B<num> bytes from the buffer B<buf> into
     18      1.1  christos the specified B<ssl> connection. On success SSL_write_ex() will store the number
     19      1.1  christos of bytes written in B<*written>.
     20      1.1  christos 
     21  1.1.1.6  christos SSL_sendfile() writes B<size> bytes from offset B<offset> in the file
     22  1.1.1.6  christos descriptor B<fd> to the specified SSL connection B<s>. This function provides
     23  1.1.1.6  christos efficient zero-copy semantics. SSL_sendfile() is available only when
     24  1.1.1.6  christos Kernel TLS is enabled, which can be checked by calling BIO_get_ktls_send().
     25  1.1.1.6  christos It is provided here to allow users to maintain the same interface.
     26  1.1.1.6  christos The meaning of B<flags> is platform dependent.
     27  1.1.1.6  christos Currently, under Linux it is ignored.
     28  1.1.1.6  christos 
     29      1.1  christos =head1 NOTES
     30      1.1  christos 
     31      1.1  christos In the paragraphs below a "write function" is defined as one of either
     32      1.1  christos SSL_write_ex(), or SSL_write().
     33      1.1  christos 
     34      1.1  christos If necessary, a write function will negotiate a TLS/SSL session, if not already
     35      1.1  christos explicitly performed by L<SSL_connect(3)> or L<SSL_accept(3)>. If the peer
     36      1.1  christos requests a re-negotiation, it will be performed transparently during
     37      1.1  christos the write function operation. The behaviour of the write functions depends on the
     38      1.1  christos underlying BIO.
     39      1.1  christos 
     40      1.1  christos For the transparent negotiation to succeed, the B<ssl> must have been
     41      1.1  christos initialized to client or server mode. This is being done by calling
     42      1.1  christos L<SSL_set_connect_state(3)> or SSL_set_accept_state()
     43      1.1  christos before the first call to a write function.
     44      1.1  christos 
     45      1.1  christos If the underlying BIO is B<blocking>, the write functions will only return, once
     46      1.1  christos the write operation has been finished or an error occurred.
     47      1.1  christos 
     48  1.1.1.5  christos If the underlying BIO is B<nonblocking> the write functions will also return
     49      1.1  christos when the underlying BIO could not satisfy the needs of the function to continue
     50      1.1  christos the operation. In this case a call to L<SSL_get_error(3)> with the
     51      1.1  christos return value of the write function will yield B<SSL_ERROR_WANT_READ>
     52      1.1  christos or B<SSL_ERROR_WANT_WRITE>. As at any time a re-negotiation is possible, a
     53      1.1  christos call to a write function can also cause read operations! The calling process
     54      1.1  christos then must repeat the call after taking appropriate action to satisfy the needs
     55      1.1  christos of the write function. The action depends on the underlying BIO. When using a
     56  1.1.1.5  christos nonblocking socket, nothing is to be done, but select() can be used to check
     57      1.1  christos for the required condition. When using a buffering BIO, like a BIO pair, data
     58      1.1  christos must be written into or retrieved out of the BIO before being able to continue.
     59      1.1  christos 
     60      1.1  christos The write functions will only return with success when the complete contents of
     61      1.1  christos B<buf> of length B<num> has been written. This default behaviour can be changed
     62      1.1  christos with the SSL_MODE_ENABLE_PARTIAL_WRITE option of L<SSL_CTX_set_mode(3)>. When
     63      1.1  christos this flag is set the write functions will also return with success when a
     64      1.1  christos partial write has been successfully completed. In this case the write function
     65      1.1  christos operation is considered completed. The bytes are sent and a new write call with
     66      1.1  christos a new buffer (with the already sent bytes removed) must be started. A partial
     67      1.1  christos write is performed with the size of a message block, which is 16kB.
     68      1.1  christos 
     69  1.1.1.4  christos =head1 WARNINGS
     70      1.1  christos 
     71      1.1  christos When a write function call has to be repeated because L<SSL_get_error(3)>
     72      1.1  christos returned B<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE>, it must be repeated
     73      1.1  christos with the same arguments.
     74      1.1  christos The data that was passed might have been partially processed.
     75      1.1  christos When B<SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER> was set using L<SSL_CTX_set_mode(3)>
     76      1.1  christos the pointer can be different, but the data and length should still be the same.
     77      1.1  christos 
     78      1.1  christos You should not call SSL_write() with num=0, it will return an error.
     79      1.1  christos SSL_write_ex() can be called with num=0, but will not send application data to
     80      1.1  christos the peer.
     81      1.1  christos 
     82      1.1  christos =head1 RETURN VALUES
     83      1.1  christos 
     84      1.1  christos SSL_write_ex() will return 1 for success or 0 for failure. Success means that
     85      1.1  christos all requested application data bytes have been written to the SSL connection or,
     86      1.1  christos if SSL_MODE_ENABLE_PARTIAL_WRITE is in use, at least 1 application data byte has
     87      1.1  christos been written to the SSL connection. Failure means that not all the requested
     88      1.1  christos bytes have been written yet (if SSL_MODE_ENABLE_PARTIAL_WRITE is not in use) or
     89      1.1  christos no bytes could be written to the SSL connection (if
     90      1.1  christos SSL_MODE_ENABLE_PARTIAL_WRITE is in use). Failures can be retryable (e.g. the
     91      1.1  christos network write buffer has temporarily filled up) or non-retryable (e.g. a fatal
     92      1.1  christos network error). In the event of a failure call L<SSL_get_error(3)> to find out
     93      1.1  christos the reason which indicates whether the call is retryable or not.
     94      1.1  christos 
     95      1.1  christos For SSL_write() the following return values can occur:
     96      1.1  christos 
     97      1.1  christos =over 4
     98      1.1  christos 
     99      1.1  christos =item E<gt> 0
    100      1.1  christos 
    101      1.1  christos The write operation was successful, the return value is the number of
    102      1.1  christos bytes actually written to the TLS/SSL connection.
    103      1.1  christos 
    104      1.1  christos =item Z<><= 0
    105      1.1  christos 
    106      1.1  christos The write operation was not successful, because either the connection was
    107      1.1  christos closed, an error occurred or action must be taken by the calling process.
    108      1.1  christos Call SSL_get_error() with the return value B<ret> to find out the reason.
    109      1.1  christos 
    110      1.1  christos Old documentation indicated a difference between 0 and -1, and that -1 was
    111      1.1  christos retryable.
    112      1.1  christos You should instead call SSL_get_error() to find out if it's retryable.
    113      1.1  christos 
    114      1.1  christos =back
    115      1.1  christos 
    116  1.1.1.6  christos For SSL_sendfile(), the following return values can occur:
    117  1.1.1.6  christos 
    118  1.1.1.6  christos =over 4
    119  1.1.1.6  christos 
    120  1.1.1.6  christos =item Z<>>= 0
    121  1.1.1.6  christos 
    122  1.1.1.6  christos The write operation was successful, the return value is the number
    123  1.1.1.6  christos of bytes of the file written to the TLS/SSL connection. The return
    124  1.1.1.6  christos value can be less than B<size> for a partial write.
    125  1.1.1.6  christos 
    126  1.1.1.6  christos =item E<lt> 0
    127  1.1.1.6  christos 
    128  1.1.1.6  christos The write operation was not successful, because either the connection was
    129  1.1.1.6  christos closed, an error occurred or action must be taken by the calling process.
    130  1.1.1.6  christos Call SSL_get_error() with the return value to find out the reason.
    131  1.1.1.6  christos 
    132  1.1.1.6  christos =back
    133  1.1.1.6  christos 
    134      1.1  christos =head1 SEE ALSO
    135      1.1  christos 
    136      1.1  christos L<SSL_get_error(3)>, L<SSL_read_ex(3)>, L<SSL_read(3)>
    137      1.1  christos L<SSL_CTX_set_mode(3)>, L<SSL_CTX_new(3)>,
    138      1.1  christos L<SSL_connect(3)>, L<SSL_accept(3)>
    139  1.1.1.6  christos L<SSL_set_connect_state(3)>, L<BIO_ctrl(3)>,
    140      1.1  christos L<ssl(7)>, L<bio(7)>
    141      1.1  christos 
    142  1.1.1.3  christos =head1 HISTORY
    143  1.1.1.3  christos 
    144  1.1.1.3  christos The SSL_write_ex() function was added in OpenSSL 1.1.1.
    145  1.1.1.6  christos The SSL_sendfile() function was added in OpenSSL 3.0.
    146  1.1.1.3  christos 
    147      1.1  christos =head1 COPYRIGHT
    148      1.1  christos 
    149  1.1.1.6  christos Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
    150      1.1  christos 
    151  1.1.1.6  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    152      1.1  christos this file except in compliance with the License.  You can obtain a copy
    153      1.1  christos in the file LICENSE in the source distribution or at
    154      1.1  christos L<https://www.openssl.org/source/license.html>.
    155      1.1  christos 
    156      1.1  christos =cut
    157