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