/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* include/k5-tls.h - internal pluggable interface for TLS */2/*3* Copyright (C) 2014 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* * Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12*13* * Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in15* the documentation and/or other materials provided with the16* distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS21* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE22* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,23* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES24* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR25* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,27* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED29* OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132/*33* This internal pluggable interface allows libkrb5 to load an in-tree module34* providing TLS support at runtime. It is currently tailored for the needs of35* the OpenSSL module as used for HTTP proxy support. As an internal36* interface, it can be changed to fit different implementations and consumers37* without regard for backward compatibility.38*/3940#ifndef K5_TLS_H41#define K5_TLS_H4243#include "k5-int.h"4445/* An abstract type for localauth module data. */46typedef struct k5_tls_handle_st *k5_tls_handle;4748typedef enum {49DATA_READ, DONE, WANT_READ, WANT_WRITE, ERROR_TLS50} k5_tls_status;5152/*53* Create a handle for fd, where the server certificate must match servername54* and be trusted according to anchors. anchors is a null-terminated list55* using the DIR:/FILE:/ENV: syntax borrowed from PKINIT. If anchors is null,56* use the system default trust anchors.57*/58typedef krb5_error_code59(*k5_tls_setup_fn)(krb5_context context, SOCKET fd, const char *servername,60char **anchors, k5_tls_handle *handle_out);6162/*63* Write len bytes of data using TLS. Return DONE if writing is complete,64* WANT_READ or WANT_WRITE if the underlying socket must be readable or65* writable to continue, and ERROR_TLS if the TLS channel or underlying socket66* experienced an error. After WANT_READ or WANT_WRITE, the operation will be67* retried with the same arguments even if some data has already been written.68* (OpenSSL makes this contract easy to fulfill. For other implementations we69* might want to change it.)70*/71typedef k5_tls_status72(*k5_tls_write_fn)(krb5_context context, k5_tls_handle handle,73const void *data, size_t len);7475/*76* Read up to data_size bytes of data using TLS. Return DATA_READ and set77* *len_out if any data is read. Return DONE if there is no more data to be78* read on the connection, WANT_READ or WANT_WRITE if the underlying socket79* must be readable or writable to continue, and ERROR_TLS if the TLS channel80* or underlying socket experienced an error.81*82* After DATA_READ, there may still be pending buffered data to read. The83* caller must call this method again with additional buffer space before84* selecting for reading on the underlying socket.85*/86typedef k5_tls_status87(*k5_tls_read_fn)(krb5_context context, k5_tls_handle handle, void *data,88size_t data_size, size_t *len_out);8990/* Release a handle. Do not pass a null pointer. */91typedef void92(*k5_tls_free_handle_fn)(krb5_context context, k5_tls_handle handle);9394/* All functions are mandatory unless they are all null, in which case the95* caller should assume that TLS is unsupported. */96typedef struct k5_tls_vtable_st {97k5_tls_setup_fn setup;98k5_tls_write_fn write;99k5_tls_read_fn read;100k5_tls_free_handle_fn free_handle;101} *k5_tls_vtable;102103#endif /* K5_TLS_H */104105106