tls.h revision 209158
1189251Ssam/* 2189251Ssam * WPA Supplicant / SSL/TLS interface definition 3189251Ssam * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi> 4189251Ssam * 5189251Ssam * This program is free software; you can redistribute it and/or modify 6189251Ssam * it under the terms of the GNU General Public License version 2 as 7189251Ssam * published by the Free Software Foundation. 8189251Ssam * 9189251Ssam * Alternatively, this software may be distributed under the terms of BSD 10189251Ssam * license. 11189251Ssam * 12189251Ssam * See README and COPYING for more details. 13189251Ssam */ 14189251Ssam 15189251Ssam#ifndef TLS_H 16189251Ssam#define TLS_H 17189251Ssam 18189251Ssamstruct tls_connection; 19189251Ssam 20189251Ssamstruct tls_keys { 21189251Ssam const u8 *master_key; /* TLS master secret */ 22189251Ssam size_t master_key_len; 23189251Ssam const u8 *client_random; 24189251Ssam size_t client_random_len; 25189251Ssam const u8 *server_random; 26189251Ssam size_t server_random_len; 27189251Ssam const u8 *inner_secret; /* TLS/IA inner secret */ 28189251Ssam size_t inner_secret_len; 29189251Ssam}; 30189251Ssam 31189251Ssamstruct tls_config { 32189251Ssam const char *opensc_engine_path; 33189251Ssam const char *pkcs11_engine_path; 34189251Ssam const char *pkcs11_module_path; 35189251Ssam}; 36189251Ssam 37209158Srpaulo#define TLS_CONN_ALLOW_SIGN_RSA_MD5 BIT(0) 38209158Srpaulo#define TLS_CONN_DISABLE_TIME_CHECKS BIT(1) 39209158Srpaulo 40189251Ssam/** 41189251Ssam * struct tls_connection_params - Parameters for TLS connection 42189251Ssam * @ca_cert: File or reference name for CA X.509 certificate in PEM or DER 43189251Ssam * format 44189251Ssam * @ca_cert_blob: ca_cert as inlined data or %NULL if not used 45189251Ssam * @ca_cert_blob_len: ca_cert_blob length 46189251Ssam * @ca_path: Path to CA certificates (OpenSSL specific) 47189251Ssam * @subject_match: String to match in the subject of the peer certificate or 48189251Ssam * %NULL to allow all subjects 49189251Ssam * @altsubject_match: String to match in the alternative subject of the peer 50189251Ssam * certificate or %NULL to allow all alternative subjects 51189251Ssam * @client_cert: File or reference name for client X.509 certificate in PEM or 52189251Ssam * DER format 53189251Ssam * @client_cert_blob: client_cert as inlined data or %NULL if not used 54189251Ssam * @client_cert_blob_len: client_cert_blob length 55189251Ssam * @private_key: File or reference name for client private key in PEM or DER 56189251Ssam * format (traditional format (RSA PRIVATE KEY) or PKCS#8 (PRIVATE KEY) 57189251Ssam * @private_key_blob: private_key as inlined data or %NULL if not used 58189251Ssam * @private_key_blob_len: private_key_blob length 59189251Ssam * @private_key_passwd: Passphrase for decrypted private key, %NULL if no 60189251Ssam * passphrase is used. 61189251Ssam * @dh_file: File name for DH/DSA data in PEM format, or %NULL if not used 62189251Ssam * @dh_blob: dh_file as inlined data or %NULL if not used 63189251Ssam * @dh_blob_len: dh_blob length 64189251Ssam * @engine: 1 = use engine (e.g., a smartcard) for private key operations 65189251Ssam * (this is OpenSSL specific for now) 66189251Ssam * @engine_id: engine id string (this is OpenSSL specific for now) 67189251Ssam * @ppin: pointer to the pin variable in the configuration 68189251Ssam * (this is OpenSSL specific for now) 69189251Ssam * @key_id: the private key's id when using engine (this is OpenSSL 70189251Ssam * specific for now) 71189251Ssam * @cert_id: the certificate's id when using engine 72189251Ssam * @ca_cert_id: the CA certificate's id when using engine 73189251Ssam * @tls_ia: Whether to enable TLS/IA (for EAP-TTLSv1) 74209158Srpaulo * @flags: Parameter options (TLS_CONN_*) 75189251Ssam * 76189251Ssam * TLS connection parameters to be configured with tls_connection_set_params() 77189251Ssam * and tls_global_set_params(). 78189251Ssam * 79189251Ssam * Certificates and private key can be configured either as a reference name 80189251Ssam * (file path or reference to certificate store) or by providing the same data 81189251Ssam * as a pointer to the data in memory. Only one option will be used for each 82189251Ssam * field. 83189251Ssam */ 84189251Ssamstruct tls_connection_params { 85189251Ssam const char *ca_cert; 86189251Ssam const u8 *ca_cert_blob; 87189251Ssam size_t ca_cert_blob_len; 88189251Ssam const char *ca_path; 89189251Ssam const char *subject_match; 90189251Ssam const char *altsubject_match; 91189251Ssam const char *client_cert; 92189251Ssam const u8 *client_cert_blob; 93189251Ssam size_t client_cert_blob_len; 94189251Ssam const char *private_key; 95189251Ssam const u8 *private_key_blob; 96189251Ssam size_t private_key_blob_len; 97189251Ssam const char *private_key_passwd; 98189251Ssam const char *dh_file; 99189251Ssam const u8 *dh_blob; 100189251Ssam size_t dh_blob_len; 101189251Ssam int tls_ia; 102189251Ssam 103189251Ssam /* OpenSSL specific variables */ 104189251Ssam int engine; 105189251Ssam const char *engine_id; 106189251Ssam const char *pin; 107189251Ssam const char *key_id; 108189251Ssam const char *cert_id; 109189251Ssam const char *ca_cert_id; 110209158Srpaulo 111209158Srpaulo unsigned int flags; 112189251Ssam}; 113189251Ssam 114189251Ssam 115189251Ssam/** 116189251Ssam * tls_init - Initialize TLS library 117189251Ssam * @conf: Configuration data for TLS library 118189251Ssam * Returns: Context data to be used as tls_ctx in calls to other functions, 119189251Ssam * or %NULL on failure. 120189251Ssam * 121189251Ssam * Called once during program startup and once for each RSN pre-authentication 122189251Ssam * session. In other words, there can be two concurrent TLS contexts. If global 123189251Ssam * library initialization is needed (i.e., one that is shared between both 124189251Ssam * authentication types), the TLS library wrapper should maintain a reference 125189251Ssam * counter and do global initialization only when moving from 0 to 1 reference. 126189251Ssam */ 127189251Ssamvoid * tls_init(const struct tls_config *conf); 128189251Ssam 129189251Ssam/** 130189251Ssam * tls_deinit - Deinitialize TLS library 131189251Ssam * @tls_ctx: TLS context data from tls_init() 132189251Ssam * 133189251Ssam * Called once during program shutdown and once for each RSN pre-authentication 134189251Ssam * session. If global library deinitialization is needed (i.e., one that is 135189251Ssam * shared between both authentication types), the TLS library wrapper should 136189251Ssam * maintain a reference counter and do global deinitialization only when moving 137189251Ssam * from 1 to 0 references. 138189251Ssam */ 139189251Ssamvoid tls_deinit(void *tls_ctx); 140189251Ssam 141189251Ssam/** 142189251Ssam * tls_get_errors - Process pending errors 143189251Ssam * @tls_ctx: TLS context data from tls_init() 144189251Ssam * Returns: Number of found error, 0 if no errors detected. 145189251Ssam * 146189251Ssam * Process all pending TLS errors. 147189251Ssam */ 148189251Ssamint tls_get_errors(void *tls_ctx); 149189251Ssam 150189251Ssam/** 151189251Ssam * tls_connection_init - Initialize a new TLS connection 152189251Ssam * @tls_ctx: TLS context data from tls_init() 153189251Ssam * Returns: Connection context data, conn for other function calls 154189251Ssam */ 155189251Ssamstruct tls_connection * tls_connection_init(void *tls_ctx); 156189251Ssam 157189251Ssam/** 158189251Ssam * tls_connection_deinit - Free TLS connection data 159189251Ssam * @tls_ctx: TLS context data from tls_init() 160189251Ssam * @conn: Connection context data from tls_connection_init() 161189251Ssam * 162189251Ssam * Release all resources allocated for TLS connection. 163189251Ssam */ 164189251Ssamvoid tls_connection_deinit(void *tls_ctx, struct tls_connection *conn); 165189251Ssam 166189251Ssam/** 167189251Ssam * tls_connection_established - Has the TLS connection been completed? 168189251Ssam * @tls_ctx: TLS context data from tls_init() 169189251Ssam * @conn: Connection context data from tls_connection_init() 170189251Ssam * Returns: 1 if TLS connection has been completed, 0 if not. 171189251Ssam */ 172189251Ssamint tls_connection_established(void *tls_ctx, struct tls_connection *conn); 173189251Ssam 174189251Ssam/** 175189251Ssam * tls_connection_shutdown - Shutdown TLS connection 176189251Ssam * @tls_ctx: TLS context data from tls_init() 177189251Ssam * @conn: Connection context data from tls_connection_init() 178189251Ssam * Returns: 0 on success, -1 on failure 179189251Ssam * 180189251Ssam * Shutdown current TLS connection without releasing all resources. New 181189251Ssam * connection can be started by using the same conn without having to call 182189251Ssam * tls_connection_init() or setting certificates etc. again. The new 183189251Ssam * connection should try to use session resumption. 184189251Ssam */ 185189251Ssamint tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn); 186189251Ssam 187189251Ssamenum { 188189251Ssam TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED = -3, 189189251Ssam TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED = -2 190189251Ssam}; 191189251Ssam 192189251Ssam/** 193189251Ssam * tls_connection_set_params - Set TLS connection parameters 194189251Ssam * @tls_ctx: TLS context data from tls_init() 195189251Ssam * @conn: Connection context data from tls_connection_init() 196189251Ssam * @params: Connection parameters 197189251Ssam * Returns: 0 on success, -1 on failure, 198189251Ssam * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on possible PIN error causing 199189251Ssam * PKCS#11 engine failure, or 200189251Ssam * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the 201189251Ssam * PKCS#11 engine private key. 202189251Ssam */ 203189251Ssamint __must_check 204189251Ssamtls_connection_set_params(void *tls_ctx, struct tls_connection *conn, 205189251Ssam const struct tls_connection_params *params); 206189251Ssam 207189251Ssam/** 208189251Ssam * tls_global_set_params - Set TLS parameters for all TLS connection 209189251Ssam * @tls_ctx: TLS context data from tls_init() 210189251Ssam * @params: Global TLS parameters 211189251Ssam * Returns: 0 on success, -1 on failure, 212189251Ssam * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on possible PIN error causing 213189251Ssam * PKCS#11 engine failure, or 214189251Ssam * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the 215189251Ssam * PKCS#11 engine private key. 216189251Ssam */ 217189251Ssamint __must_check tls_global_set_params( 218189251Ssam void *tls_ctx, const struct tls_connection_params *params); 219189251Ssam 220189251Ssam/** 221189251Ssam * tls_global_set_verify - Set global certificate verification options 222189251Ssam * @tls_ctx: TLS context data from tls_init() 223189251Ssam * @check_crl: 0 = do not verify CRLs, 1 = verify CRL for the user certificate, 224189251Ssam * 2 = verify CRL for all certificates 225189251Ssam * Returns: 0 on success, -1 on failure 226189251Ssam */ 227189251Ssamint __must_check tls_global_set_verify(void *tls_ctx, int check_crl); 228189251Ssam 229189251Ssam/** 230189251Ssam * tls_connection_set_verify - Set certificate verification options 231189251Ssam * @tls_ctx: TLS context data from tls_init() 232189251Ssam * @conn: Connection context data from tls_connection_init() 233189251Ssam * @verify_peer: 1 = verify peer certificate 234189251Ssam * Returns: 0 on success, -1 on failure 235189251Ssam */ 236189251Ssamint __must_check tls_connection_set_verify(void *tls_ctx, 237189251Ssam struct tls_connection *conn, 238189251Ssam int verify_peer); 239189251Ssam 240189251Ssam/** 241189251Ssam * tls_connection_set_ia - Set TLS/IA parameters 242189251Ssam * @tls_ctx: TLS context data from tls_init() 243189251Ssam * @conn: Connection context data from tls_connection_init() 244189251Ssam * @tls_ia: 1 = enable TLS/IA 245189251Ssam * Returns: 0 on success, -1 on failure 246189251Ssam * 247189251Ssam * This function is used to configure TLS/IA in server mode where 248189251Ssam * tls_connection_set_params() is not used. 249189251Ssam */ 250189251Ssamint __must_check tls_connection_set_ia(void *tls_ctx, 251189251Ssam struct tls_connection *conn, 252189251Ssam int tls_ia); 253189251Ssam 254189251Ssam/** 255189251Ssam * tls_connection_get_keys - Get master key and random data from TLS connection 256189251Ssam * @tls_ctx: TLS context data from tls_init() 257189251Ssam * @conn: Connection context data from tls_connection_init() 258189251Ssam * @keys: Structure of key/random data (filled on success) 259189251Ssam * Returns: 0 on success, -1 on failure 260189251Ssam */ 261189251Ssamint __must_check tls_connection_get_keys(void *tls_ctx, 262189251Ssam struct tls_connection *conn, 263189251Ssam struct tls_keys *keys); 264189251Ssam 265189251Ssam/** 266189251Ssam * tls_connection_prf - Use TLS-PRF to derive keying material 267189251Ssam * @tls_ctx: TLS context data from tls_init() 268189251Ssam * @conn: Connection context data from tls_connection_init() 269189251Ssam * @label: Label (e.g., description of the key) for PRF 270189251Ssam * @server_random_first: seed is 0 = client_random|server_random, 271189251Ssam * 1 = server_random|client_random 272189251Ssam * @out: Buffer for output data from TLS-PRF 273189251Ssam * @out_len: Length of the output buffer 274189251Ssam * Returns: 0 on success, -1 on failure 275189251Ssam * 276189251Ssam * This function is optional to implement if tls_connection_get_keys() provides 277189251Ssam * access to master secret and server/client random values. If these values are 278189251Ssam * not exported from the TLS library, tls_connection_prf() is required so that 279189251Ssam * further keying material can be derived from the master secret. If not 280189251Ssam * implemented, the function will still need to be defined, but it can just 281189251Ssam * return -1. Example implementation of this function is in tls_prf() function 282189251Ssam * when it is called with seed set to client_random|server_random (or 283189251Ssam * server_random|client_random). 284189251Ssam */ 285189251Ssamint __must_check tls_connection_prf(void *tls_ctx, 286189251Ssam struct tls_connection *conn, 287189251Ssam const char *label, 288189251Ssam int server_random_first, 289189251Ssam u8 *out, size_t out_len); 290189251Ssam 291189251Ssam/** 292189251Ssam * tls_connection_handshake - Process TLS handshake (client side) 293189251Ssam * @tls_ctx: TLS context data from tls_init() 294189251Ssam * @conn: Connection context data from tls_connection_init() 295189251Ssam * @in_data: Input data from TLS peer 296189251Ssam * @in_len: Input data length 297189251Ssam * @out_len: Length of the output buffer. 298189251Ssam * @appl_data: Pointer to application data pointer, or %NULL if dropped 299189251Ssam * @appl_data_len: Pointer to variable that is set to appl_data length 300189251Ssam * Returns: Pointer to output data, %NULL on failure 301189251Ssam * 302189251Ssam * Caller is responsible for freeing returned output data. If the final 303189251Ssam * handshake message includes application data, this is decrypted and 304189251Ssam * appl_data (if not %NULL) is set to point this data. Caller is responsible 305189251Ssam * for freeing appl_data. 306189251Ssam * 307189251Ssam * This function is used during TLS handshake. The first call is done with 308189251Ssam * in_data == %NULL and the library is expected to return ClientHello packet. 309189251Ssam * This packet is then send to the server and a response from server is given 310189251Ssam * to TLS library by calling this function again with in_data pointing to the 311189251Ssam * TLS message from the server. 312189251Ssam * 313189251Ssam * If the TLS handshake fails, this function may return %NULL. However, if the 314189251Ssam * TLS library has a TLS alert to send out, that should be returned as the 315189251Ssam * output data. In this case, tls_connection_get_failed() must return failure 316189251Ssam * (> 0). 317189251Ssam * 318189251Ssam * tls_connection_established() should return 1 once the TLS handshake has been 319189251Ssam * completed successfully. 320189251Ssam */ 321189251Ssamu8 * tls_connection_handshake(void *tls_ctx, struct tls_connection *conn, 322189251Ssam const u8 *in_data, size_t in_len, 323189251Ssam size_t *out_len, u8 **appl_data, 324189251Ssam size_t *appl_data_len); 325189251Ssam 326189251Ssam/** 327189251Ssam * tls_connection_server_handshake - Process TLS handshake (server side) 328189251Ssam * @tls_ctx: TLS context data from tls_init() 329189251Ssam * @conn: Connection context data from tls_connection_init() 330189251Ssam * @in_data: Input data from TLS peer 331189251Ssam * @in_len: Input data length 332189251Ssam * @out_len: Length of the output buffer. 333189251Ssam * Returns: pointer to output data, %NULL on failure 334189251Ssam * 335189251Ssam * Caller is responsible for freeing returned output data. 336189251Ssam */ 337189251Ssamu8 * tls_connection_server_handshake(void *tls_ctx, 338189251Ssam struct tls_connection *conn, 339189251Ssam const u8 *in_data, size_t in_len, 340189251Ssam size_t *out_len); 341189251Ssam 342189251Ssam/** 343189251Ssam * tls_connection_encrypt - Encrypt data into TLS tunnel 344189251Ssam * @tls_ctx: TLS context data from tls_init() 345189251Ssam * @conn: Connection context data from tls_connection_init() 346189251Ssam * @in_data: Pointer to plaintext data to be encrypted 347189251Ssam * @in_len: Input buffer length 348189251Ssam * @out_data: Pointer to output buffer (encrypted TLS data) 349189251Ssam * @out_len: Maximum out_data length 350189251Ssam * Returns: Number of bytes written to out_data, -1 on failure 351189251Ssam * 352189251Ssam * This function is used after TLS handshake has been completed successfully to 353189251Ssam * send data in the encrypted tunnel. 354189251Ssam */ 355189251Ssamint __must_check tls_connection_encrypt(void *tls_ctx, 356189251Ssam struct tls_connection *conn, 357189251Ssam const u8 *in_data, size_t in_len, 358189251Ssam u8 *out_data, size_t out_len); 359189251Ssam 360189251Ssam/** 361189251Ssam * tls_connection_decrypt - Decrypt data from TLS tunnel 362189251Ssam * @tls_ctx: TLS context data from tls_init() 363189251Ssam * @conn: Connection context data from tls_connection_init() 364189251Ssam * @in_data: Pointer to input buffer (encrypted TLS data) 365189251Ssam * @in_len: Input buffer length 366189251Ssam * @out_data: Pointer to output buffer (decrypted data from TLS tunnel) 367189251Ssam * @out_len: Maximum out_data length 368189251Ssam * Returns: Number of bytes written to out_data, -1 on failure 369189251Ssam * 370189251Ssam * This function is used after TLS handshake has been completed successfully to 371189251Ssam * receive data from the encrypted tunnel. 372189251Ssam */ 373189251Ssamint __must_check tls_connection_decrypt(void *tls_ctx, 374189251Ssam struct tls_connection *conn, 375189251Ssam const u8 *in_data, size_t in_len, 376189251Ssam u8 *out_data, size_t out_len); 377189251Ssam 378189251Ssam/** 379189251Ssam * tls_connection_resumed - Was session resumption used 380189251Ssam * @tls_ctx: TLS context data from tls_init() 381189251Ssam * @conn: Connection context data from tls_connection_init() 382189251Ssam * Returns: 1 if current session used session resumption, 0 if not 383189251Ssam */ 384189251Ssamint tls_connection_resumed(void *tls_ctx, struct tls_connection *conn); 385189251Ssam 386189251Ssamenum { 387189251Ssam TLS_CIPHER_NONE, 388189251Ssam TLS_CIPHER_RC4_SHA /* 0x0005 */, 389189251Ssam TLS_CIPHER_AES128_SHA /* 0x002f */, 390189251Ssam TLS_CIPHER_RSA_DHE_AES128_SHA /* 0x0031 */, 391189251Ssam TLS_CIPHER_ANON_DH_AES128_SHA /* 0x0034 */ 392189251Ssam}; 393189251Ssam 394189251Ssam/** 395189251Ssam * tls_connection_set_cipher_list - Configure acceptable cipher suites 396189251Ssam * @tls_ctx: TLS context data from tls_init() 397189251Ssam * @conn: Connection context data from tls_connection_init() 398189251Ssam * @ciphers: Zero (TLS_CIPHER_NONE) terminated list of allowed ciphers 399189251Ssam * (TLS_CIPHER_*). 400189251Ssam * Returns: 0 on success, -1 on failure 401189251Ssam */ 402189251Ssamint __must_check tls_connection_set_cipher_list(void *tls_ctx, 403189251Ssam struct tls_connection *conn, 404189251Ssam u8 *ciphers); 405189251Ssam 406189251Ssam/** 407189251Ssam * tls_get_cipher - Get current cipher name 408189251Ssam * @tls_ctx: TLS context data from tls_init() 409189251Ssam * @conn: Connection context data from tls_connection_init() 410189251Ssam * @buf: Buffer for the cipher name 411189251Ssam * @buflen: buf size 412189251Ssam * Returns: 0 on success, -1 on failure 413189251Ssam * 414189251Ssam * Get the name of the currently used cipher. 415189251Ssam */ 416189251Ssamint __must_check tls_get_cipher(void *tls_ctx, struct tls_connection *conn, 417189251Ssam char *buf, size_t buflen); 418189251Ssam 419189251Ssam/** 420189251Ssam * tls_connection_enable_workaround - Enable TLS workaround options 421189251Ssam * @tls_ctx: TLS context data from tls_init() 422189251Ssam * @conn: Connection context data from tls_connection_init() 423189251Ssam * Returns: 0 on success, -1 on failure 424189251Ssam * 425189251Ssam * This function is used to enable connection-specific workaround options for 426189251Ssam * buffer SSL/TLS implementations. 427189251Ssam */ 428189251Ssamint __must_check tls_connection_enable_workaround(void *tls_ctx, 429189251Ssam struct tls_connection *conn); 430189251Ssam 431189251Ssam/** 432189251Ssam * tls_connection_client_hello_ext - Set TLS extension for ClientHello 433189251Ssam * @tls_ctx: TLS context data from tls_init() 434189251Ssam * @conn: Connection context data from tls_connection_init() 435189251Ssam * @ext_type: Extension type 436189251Ssam * @data: Extension payload (%NULL to remove extension) 437189251Ssam * @data_len: Extension payload length 438189251Ssam * Returns: 0 on success, -1 on failure 439189251Ssam */ 440189251Ssamint __must_check tls_connection_client_hello_ext(void *tls_ctx, 441189251Ssam struct tls_connection *conn, 442189251Ssam int ext_type, const u8 *data, 443189251Ssam size_t data_len); 444189251Ssam 445189251Ssam/** 446189251Ssam * tls_connection_get_failed - Get connection failure status 447189251Ssam * @tls_ctx: TLS context data from tls_init() 448189251Ssam * @conn: Connection context data from tls_connection_init() 449189251Ssam * 450189251Ssam * Returns >0 if connection has failed, 0 if not. 451189251Ssam */ 452189251Ssamint tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn); 453189251Ssam 454189251Ssam/** 455189251Ssam * tls_connection_get_read_alerts - Get connection read alert status 456189251Ssam * @tls_ctx: TLS context data from tls_init() 457189251Ssam * @conn: Connection context data from tls_connection_init() 458189251Ssam * Returns: Number of times a fatal read (remote end reported error) has 459189251Ssam * happened during this connection. 460189251Ssam */ 461189251Ssamint tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn); 462189251Ssam 463189251Ssam/** 464189251Ssam * tls_connection_get_write_alerts - Get connection write alert status 465189251Ssam * @tls_ctx: TLS context data from tls_init() 466189251Ssam * @conn: Connection context data from tls_connection_init() 467189251Ssam * Returns: Number of times a fatal write (locally detected error) has happened 468189251Ssam * during this connection. 469189251Ssam */ 470189251Ssamint tls_connection_get_write_alerts(void *tls_ctx, 471189251Ssam struct tls_connection *conn); 472189251Ssam 473189251Ssam/** 474189251Ssam * tls_connection_get_keyblock_size - Get TLS key_block size 475189251Ssam * @tls_ctx: TLS context data from tls_init() 476189251Ssam * @conn: Connection context data from tls_connection_init() 477189251Ssam * Returns: Size of the key_block for the negotiated cipher suite or -1 on 478189251Ssam * failure 479189251Ssam */ 480189251Ssamint tls_connection_get_keyblock_size(void *tls_ctx, 481189251Ssam struct tls_connection *conn); 482189251Ssam 483189251Ssam#define TLS_CAPABILITY_IA 0x0001 /* TLS Inner Application (TLS/IA) */ 484189251Ssam/** 485189251Ssam * tls_capabilities - Get supported TLS capabilities 486189251Ssam * @tls_ctx: TLS context data from tls_init() 487189251Ssam * Returns: Bit field of supported TLS capabilities (TLS_CAPABILITY_*) 488189251Ssam */ 489189251Ssamunsigned int tls_capabilities(void *tls_ctx); 490189251Ssam 491189251Ssam/** 492189251Ssam * tls_connection_ia_send_phase_finished - Send a TLS/IA PhaseFinished message 493189251Ssam * @tls_ctx: TLS context data from tls_init() 494189251Ssam * @conn: Connection context data from tls_connection_init() 495189251Ssam * @final: 1 = FinalPhaseFinished, 0 = IntermediatePhaseFinished 496189251Ssam * @out_data: Pointer to output buffer (encrypted TLS/IA data) 497189251Ssam * @out_len: Maximum out_data length 498189251Ssam * Returns: Number of bytes written to out_data on success, -1 on failure 499189251Ssam * 500189251Ssam * This function is used to send the TLS/IA end phase message, e.g., when the 501189251Ssam * EAP server completes EAP-TTLSv1. 502189251Ssam */ 503189251Ssamint __must_check tls_connection_ia_send_phase_finished( 504189251Ssam void *tls_ctx, struct tls_connection *conn, int final, 505189251Ssam u8 *out_data, size_t out_len); 506189251Ssam 507189251Ssam/** 508189251Ssam * tls_connection_ia_final_phase_finished - Has final phase been completed 509189251Ssam * @tls_ctx: TLS context data from tls_init() 510189251Ssam * @conn: Connection context data from tls_connection_init() 511189251Ssam * Returns: 1 if valid FinalPhaseFinished has been received, 0 if not, or -1 512189251Ssam * on failure 513189251Ssam */ 514189251Ssamint __must_check tls_connection_ia_final_phase_finished( 515189251Ssam void *tls_ctx, struct tls_connection *conn); 516189251Ssam 517189251Ssam/** 518189251Ssam * tls_connection_ia_permute_inner_secret - Permute TLS/IA inner secret 519189251Ssam * @tls_ctx: TLS context data from tls_init() 520189251Ssam * @conn: Connection context data from tls_connection_init() 521189251Ssam * @key: Session key material (session_key vectors with 2-octet length), or 522189251Ssam * %NULL if no session key was generating in the current phase 523189251Ssam * @key_len: Length of session key material 524189251Ssam * Returns: 0 on success, -1 on failure 525189251Ssam */ 526189251Ssamint __must_check tls_connection_ia_permute_inner_secret( 527189251Ssam void *tls_ctx, struct tls_connection *conn, 528189251Ssam const u8 *key, size_t key_len); 529189251Ssam 530189251Ssamtypedef int (*tls_session_ticket_cb) 531189251Ssam(void *ctx, const u8 *ticket, size_t len, const u8 *client_random, 532189251Ssam const u8 *server_random, u8 *master_secret); 533189251Ssam 534189251Ssamint __must_check tls_connection_set_session_ticket_cb( 535189251Ssam void *tls_ctx, struct tls_connection *conn, 536189251Ssam tls_session_ticket_cb cb, void *ctx); 537189251Ssam 538189251Ssam#endif /* TLS_H */ 539