1 /* 2 * Copyright (c) 2017, 2019-2020 Paul Mattes. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * * Neither the names of Paul Mattes, Don Russell, Jeff Sparkes, GTRC 14 * nor their contributors may be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY PAUL MATTES "AS IS" AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL PAUL MATTES BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /* 30 * sio.h 31 * External definitions for functions and data for secure I/O, 32 * implemented in various platform-specific ways. 33 */ 34 35 /* Special return values from sio_read and sio_write. */ 36 #define SIO_EOF 0 37 #define SIO_FATAL_ERROR (-1) 38 #define SIO_EWOULDBLOCK (-2) 39 40 /* Return values from sio_init. */ 41 typedef enum { 42 SI_SUCCESS, /* success */ 43 SI_FAILURE, /* failure, reason in sio_last_error */ 44 SI_NEED_PASSWORD, /* need a password */ 45 SI_WRONG_PASSWORD /* password is wrong */ 46 } sio_init_ret_t; 47 48 /* Return values from sio_negotiate. */ 49 typedef enum { 50 SIG_SUCCESS, /* success */ 51 SIG_FAILURE, /* failure */ 52 SIG_WANTMORE /* more input needed */ 53 } sio_negotiate_ret_t; 54 55 typedef void *sio_t; 56 57 /* Implemented in common code. */ 58 const char *sio_last_error(void); 59 unsigned sio_all_options_supported(); 60 61 /* Implemented in platform-specific code. */ 62 bool sio_supported(void); 63 const char *sio_provider(void); 64 unsigned sio_options_supported(void); 65 sio_init_ret_t sio_init(tls_config_t *config, const char *password, 66 sio_t *sio_ret); 67 sio_negotiate_ret_t sio_negotiate(sio_t sio, socket_t sock, 68 const char *hostname, bool *data); 69 int sio_read(sio_t sio, char *buf, size_t buflen); 70 int sio_write(sio_t sio, const char *buf, size_t buflen); 71 void sio_close(sio_t sio); 72 bool sio_secure_unverified(sio_t sio); 73 const char *sio_session_info(sio_t sio); 74 const char *sio_server_cert_info(sio_t sio); 75