iPXE
tls.h File Reference

Transport Layer Security Protocol. More...

#include <stdint.h>
#include <ipxe/refcnt.h>
#include <ipxe/interface.h>
#include <ipxe/process.h>
#include <ipxe/crypto.h>
#include <ipxe/x509.h>
#include <ipxe/privkey.h>
#include <ipxe/pending.h>
#include <ipxe/iobuf.h>
#include <ipxe/tables.h>
#include <ipxe/channel.h>
#include <ipxe/tlskey.h>

Go to the source code of this file.

Data Structures

struct  tls_header
 A TLS header. More...
struct  tls_auth_header
 TLS authentication header. More...
struct  tls_verify_data
 TLS verification data. More...
struct  tls_key_exchange_parameters
 TLS key exchange parameters. More...
struct  tls_key_exchange_algorithm
 A TLS key exchange algorithm. More...
struct  tls_cipher_suite
 A TLS cipher suite. More...
struct  tls_named_group
 A TLS named group. More...
struct  tls_cipherspec
 A TLS cipher specification. More...
struct  tls_cipherspec_pair
 A TLS cipher specification pair. More...
struct  tls_signature_hash_algorithm
 A TLS signature algorithm. More...
struct  tls_session_id
 A TLS session ID. More...
struct  tls_session_ticket
 A TLS session ticket. More...
struct  tls_session
 A TLS session. More...
struct  tls_tx
 TLS transmit state. More...
struct  tls_rx
 TLS receive state. More...
struct  tls_client
 TLS client state. More...
struct  tls_server
 TLS server state. More...
struct  tls_connection
 A TLS connection. More...

Macros

#define TLS_VERSION_TLS_1_1   0x0302
 TLS version 1.1.
#define TLS_VERSION_TLS_1_2   0x0303
 TLS version 1.2.
#define TLS_VERSION_TLS_1_3   0x0304
 TLS version 1.3.
#define TLS_TYPE_CHANGE_CIPHER   20
 Change cipher content type.
#define TLS_CHANGE_CIPHER_SPEC   1
 Change cipher spec magic byte.
#define TLS_TYPE_ALERT   21
 Alert content type.
#define TLS_TYPE_HANDSHAKE   22
 Handshake content type.
#define TLS_TYPE_DATA   23
 Application data content type.
#define TLS_HELLO_REQUEST   0
#define TLS_CLIENT_HELLO   1
#define TLS_SERVER_HELLO   2
#define TLS_NEW_SESSION_TICKET   4
#define TLS_CERTIFICATE   11
#define TLS_SERVER_KEY_EXCHANGE   12
#define TLS_CERTIFICATE_REQUEST   13
#define TLS_SERVER_HELLO_DONE   14
#define TLS_CERTIFICATE_VERIFY   15
#define TLS_CLIENT_KEY_EXCHANGE   16
#define TLS_FINISHED   20
#define TLS_ALERT_WARNING   1
#define TLS_ALERT_FATAL   2
#define TLS_ALERT_CLOSE_NOTIFY   0
#define TLS_RSA_WITH_NULL_MD5   0x0001
#define TLS_RSA_WITH_NULL_SHA   0x0002
#define TLS_RSA_WITH_AES_128_CBC_SHA   0x002f
#define TLS_DHE_RSA_WITH_AES_128_CBC_SHA   0x0033
#define TLS_RSA_WITH_AES_256_CBC_SHA   0x0035
#define TLS_DHE_RSA_WITH_AES_256_CBC_SHA   0x0039
#define TLS_RSA_WITH_AES_128_CBC_SHA256   0x003c
#define TLS_RSA_WITH_AES_256_CBC_SHA256   0x003d
#define TLS_DHE_RSA_WITH_AES_128_CBC_SHA256   0x0067
#define TLS_DHE_RSA_WITH_AES_256_CBC_SHA256   0x006b
#define TLS_RSA_WITH_AES_128_GCM_SHA256   0x009c
#define TLS_RSA_WITH_AES_256_GCM_SHA384   0x009d
#define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256   0x009e
#define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384   0x009f
#define TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA   0xc009
#define TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA   0xc00a
#define TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA   0xc013
#define TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA   0xc014
#define TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256   0xc023
#define TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384   0xc024
#define TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256   0xc027
#define TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384   0xc028
#define TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256   0xc02b
#define TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384   0xc02c
#define TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256   0xc02f
#define TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384   0xc030
#define TLS_RSA_SHA1_ALGORITHM   0x0201
#define TLS_RSA_SHA224_ALGORITHM   0x0301
#define TLS_ECDSA_SHA224_ALGORITHM   0x0303
#define TLS_RSA_SHA256_ALGORITHM   0x0401
#define TLS_ECDSA_SHA256_ALGORITHM   0x0403
#define TLS_RSA_SHA384_ALGORITHM   0x0501
#define TLS_ECDSA_SHA384_ALGORITHM   0x0503
#define TLS_RSA_SHA512_ALGORITHM   0x0601
#define TLS_ECDSA_SHA512_ALGORITHM   0x0603
#define TLS_RSA_PSS_RSAE_SHA256_ALGORITHM   0x0804
#define TLS_RSA_PSS_RSAE_SHA384_ALGORITHM   0x0805
#define TLS_RSA_PSS_RSAE_SHA512_ALGORITHM   0x0806
#define TLS_RSA_PSS_PSS_SHA256_ALGORITHM   0x0809
#define TLS_RSA_PSS_PSS_SHA384_ALGORITHM   0x080a
#define TLS_RSA_PSS_PSS_SHA512_ALGORITHM   0x080b
#define TLS_SERVER_NAME   0
#define TLS_SERVER_NAME_HOST_NAME   0
#define TLS_MAX_FRAGMENT_LENGTH   1
#define TLS_MAX_FRAGMENT_LENGTH_512   1
#define TLS_MAX_FRAGMENT_LENGTH_1024   2
#define TLS_MAX_FRAGMENT_LENGTH_2048   3
#define TLS_MAX_FRAGMENT_LENGTH_4096   4
#define TLS_NAMED_GROUP   10
#define TLS_NAMED_GROUP_SECP256R1   23
#define TLS_NAMED_GROUP_SECP384R1   24
#define TLS_NAMED_GROUP_X25519   29
#define TLS_NAMED_GROUP_FFDHE2048   256
#define TLS_NAMED_GROUP_FFDHE3072   257
#define TLS_NAMED_GROUP_FFDHE4096   258
#define TLS_SIGNATURE_ALGORITHMS   13
#define TLS_EXTENDED_MASTER_SECRET   23
#define TLS_SESSION_TICKET   35
#define TLS_RENEGOTIATION_INFO   0xff01
#define TLS_CIPHER_SUITES   __table ( struct tls_cipher_suite, "tls_cipher_suites" )
 TLS cipher suite table.
#define __tls_cipher_suite(pref)
 Declare a TLS cipher suite.
#define TLS_NAMED_CURVE_TYPE   3
 TLS named curve type.
#define TLS_NAMED_GROUPS   __table ( struct tls_named_group, "tls_named_groups" )
 TLS named group table.
#define __tls_named_group(pref)
 Declare a TLS named group.
#define __tls_anon_named_group   __tls_named_group ( 98 )
 Declare a TLS anonymous named group.
#define TLS_NUM_NAMED_GROUPS
 Number of non-anonymous TLS named groups.
#define TLS_SIG_HASH_ALGORITHMS
 TLS signature hash algorithm table.
#define __tls_sig_hash_algorithm   __table_entry ( TLS_SIG_HASH_ALGORITHMS, 01 )
 Declare a TLS signature hash algorithm.
#define TLS_MAX_FRAGMENT_LENGTH_VALUE   TLS_MAX_FRAGMENT_LENGTH_4096
 Advertised maximum fragment length.
#define TLS_TX_BUFSIZE   4096
 TX maximum fragment length.
#define TLS_RX_BUFSIZE   4096
 RX I/O buffer size.
#define TLS_RX_MIN_BUFSIZE   512
 Minimum RX I/O buffer size.
#define TLS_RX_ALIGN   16
 RX I/O buffer alignment.

Enumerations

enum  tls_rx_state { TLS_RX_HEADER = 0 , TLS_RX_DATA }
 TLS RX state machine state. More...
enum  tls_tx_pending {
  TLS_TX_CLIENT_HELLO = 0x0001 , TLS_TX_CERTIFICATE = 0x0002 , TLS_TX_CLIENT_KEY_EXCHANGE = 0x0004 , TLS_TX_CERTIFICATE_VERIFY = 0x0008 ,
  TLS_TX_CHANGE_CIPHER = 0x0010 , TLS_TX_FINISHED = 0x0020
}
 TLS TX pending flags. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int add_tls (struct interface *xfer, const char *name, struct x509_root *root, struct private_key *key)
 Add TLS on an interface.

Variables

struct exchange_algorithm tls_classic_pre_master_algorithm
 Classic pre-master secret key exchange algorithm.
struct tls_key_exchange_algorithm tls_null_exchange_algorithm
 Null key exchange algorithm.
struct tls_key_exchange_algorithm tls_pubkey_exchange_algorithm
 Public key exchange algorithm.
struct tls_key_exchange_algorithm tls_dhe_exchange_algorithm
 Ephemeral Diffie-Hellman key exchange algorithm.
struct tls_key_exchange_algorithm tls_ecdhe_exchange_algorithm
 Ephemeral Elliptic Curve Diffie-Hellman key exchange algorithm.

Detailed Description

Transport Layer Security Protocol.

Definition in file tls.h.

Macro Definition Documentation

◆ TLS_VERSION_TLS_1_1

#define TLS_VERSION_TLS_1_1   0x0302

TLS version 1.1.

Definition at line 45 of file tls.h.

◆ TLS_VERSION_TLS_1_2

#define TLS_VERSION_TLS_1_2   0x0303

TLS version 1.2.

Definition at line 48 of file tls.h.

Referenced by tls_new_server_key_exchange(), tls_select_cipher(), tls_send_certificate_verify(), and tls_set_digest().

◆ TLS_VERSION_TLS_1_3

#define TLS_VERSION_TLS_1_3   0x0304

TLS version 1.3.

Definition at line 51 of file tls.h.

Referenced by tls_keysize_is_variable().

◆ TLS_TYPE_CHANGE_CIPHER

#define TLS_TYPE_CHANGE_CIPHER   20

Change cipher content type.

Definition at line 54 of file tls.h.

Referenced by tls_new_record(), and tls_send_change_cipher().

◆ TLS_CHANGE_CIPHER_SPEC

#define TLS_CHANGE_CIPHER_SPEC   1

Change cipher spec magic byte.

Definition at line 57 of file tls.h.

Referenced by tls_new_change_cipher(), and tls_send_change_cipher().

◆ TLS_TYPE_ALERT

#define TLS_TYPE_ALERT   21

Alert content type.

Definition at line 60 of file tls.h.

Referenced by tls_new_record(), and tls_send_alert().

◆ TLS_TYPE_HANDSHAKE

#define TLS_TYPE_HANDSHAKE   22

Handshake content type.

Definition at line 63 of file tls.h.

Referenced by tls_new_record(), tls_send_certificate(), tls_send_handshake(), and tls_send_record().

◆ TLS_TYPE_DATA

#define TLS_TYPE_DATA   23

Application data content type.

Definition at line 66 of file tls.h.

Referenced by tls_new_record(), and tls_plainstream_deliver().

◆ TLS_HELLO_REQUEST

#define TLS_HELLO_REQUEST   0

Definition at line 69 of file tls.h.

Referenced by tls_new_handshake().

◆ TLS_CLIENT_HELLO

#define TLS_CLIENT_HELLO   1

Definition at line 70 of file tls.h.

Referenced by tls_client_hello().

◆ TLS_SERVER_HELLO

#define TLS_SERVER_HELLO   2

Definition at line 71 of file tls.h.

Referenced by tls_new_handshake().

◆ TLS_NEW_SESSION_TICKET

#define TLS_NEW_SESSION_TICKET   4

Definition at line 72 of file tls.h.

Referenced by tls_new_handshake().

◆ TLS_CERTIFICATE

#define TLS_CERTIFICATE   11

Definition at line 73 of file tls.h.

Referenced by tls_new_handshake(), and tls_send_certificate().

◆ TLS_SERVER_KEY_EXCHANGE

#define TLS_SERVER_KEY_EXCHANGE   12

Definition at line 74 of file tls.h.

Referenced by tls_new_handshake().

◆ TLS_CERTIFICATE_REQUEST

#define TLS_CERTIFICATE_REQUEST   13

Definition at line 75 of file tls.h.

Referenced by tls_new_handshake().

◆ TLS_SERVER_HELLO_DONE

#define TLS_SERVER_HELLO_DONE   14

Definition at line 76 of file tls.h.

Referenced by tls_new_handshake().

◆ TLS_CERTIFICATE_VERIFY

#define TLS_CERTIFICATE_VERIFY   15

Definition at line 77 of file tls.h.

Referenced by tls_send_certificate_verify().

◆ TLS_CLIENT_KEY_EXCHANGE

#define TLS_CLIENT_KEY_EXCHANGE   16

Definition at line 78 of file tls.h.

Referenced by tls_send_client_key_exchange().

◆ TLS_FINISHED

#define TLS_FINISHED   20

Definition at line 79 of file tls.h.

Referenced by tls_new_handshake(), and tls_send_finished().

◆ TLS_ALERT_WARNING

#define TLS_ALERT_WARNING   1

Definition at line 82 of file tls.h.

Referenced by tls_close_alert(), and tls_new_alert().

◆ TLS_ALERT_FATAL

#define TLS_ALERT_FATAL   2

Definition at line 83 of file tls.h.

Referenced by tls_new_alert().

◆ TLS_ALERT_CLOSE_NOTIFY

#define TLS_ALERT_CLOSE_NOTIFY   0

Definition at line 86 of file tls.h.

Referenced by tls_close_alert(), and tls_new_alert().

◆ TLS_RSA_WITH_NULL_MD5

#define TLS_RSA_WITH_NULL_MD5   0x0001

Definition at line 89 of file tls.h.

◆ TLS_RSA_WITH_NULL_SHA

#define TLS_RSA_WITH_NULL_SHA   0x0002

Definition at line 90 of file tls.h.

◆ TLS_RSA_WITH_AES_128_CBC_SHA

#define TLS_RSA_WITH_AES_128_CBC_SHA   0x002f

Definition at line 91 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_DHE_RSA_WITH_AES_128_CBC_SHA

#define TLS_DHE_RSA_WITH_AES_128_CBC_SHA   0x0033

Definition at line 92 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_RSA_WITH_AES_256_CBC_SHA

#define TLS_RSA_WITH_AES_256_CBC_SHA   0x0035

Definition at line 93 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_DHE_RSA_WITH_AES_256_CBC_SHA

#define TLS_DHE_RSA_WITH_AES_256_CBC_SHA   0x0039

Definition at line 94 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_RSA_WITH_AES_128_CBC_SHA256

#define TLS_RSA_WITH_AES_128_CBC_SHA256   0x003c

Definition at line 95 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_RSA_WITH_AES_256_CBC_SHA256

#define TLS_RSA_WITH_AES_256_CBC_SHA256   0x003d

Definition at line 96 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_DHE_RSA_WITH_AES_128_CBC_SHA256

#define TLS_DHE_RSA_WITH_AES_128_CBC_SHA256   0x0067

Definition at line 97 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_DHE_RSA_WITH_AES_256_CBC_SHA256

#define TLS_DHE_RSA_WITH_AES_256_CBC_SHA256   0x006b

Definition at line 98 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_RSA_WITH_AES_128_GCM_SHA256

#define TLS_RSA_WITH_AES_128_GCM_SHA256   0x009c

Definition at line 99 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_RSA_WITH_AES_256_GCM_SHA384

#define TLS_RSA_WITH_AES_256_GCM_SHA384   0x009d

Definition at line 100 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_DHE_RSA_WITH_AES_128_GCM_SHA256

#define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256   0x009e

Definition at line 101 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_DHE_RSA_WITH_AES_256_GCM_SHA384

#define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384   0x009f

Definition at line 102 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA

#define TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA   0xc009

Definition at line 103 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA

#define TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA   0xc00a

Definition at line 104 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

#define TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA   0xc013

Definition at line 105 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA

#define TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA   0xc014

Definition at line 106 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256

#define TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256   0xc023

Definition at line 107 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384

#define TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384   0xc024

Definition at line 108 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256

#define TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256   0xc027

Definition at line 109 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384

#define TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384   0xc028

Definition at line 110 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256

#define TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256   0xc02b

Definition at line 111 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384

#define TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384   0xc02c

Definition at line 112 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256

#define TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256   0xc02f

Definition at line 113 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384

#define TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384   0xc030

Definition at line 114 of file tls.h.

Referenced by __tls_cipher_suite().

◆ TLS_RSA_SHA1_ALGORITHM

#define TLS_RSA_SHA1_ALGORITHM   0x0201

Definition at line 117 of file tls.h.

◆ TLS_RSA_SHA224_ALGORITHM

#define TLS_RSA_SHA224_ALGORITHM   0x0301

Definition at line 118 of file tls.h.

◆ TLS_ECDSA_SHA224_ALGORITHM

#define TLS_ECDSA_SHA224_ALGORITHM   0x0303

Definition at line 119 of file tls.h.

◆ TLS_RSA_SHA256_ALGORITHM

#define TLS_RSA_SHA256_ALGORITHM   0x0401

Definition at line 120 of file tls.h.

◆ TLS_ECDSA_SHA256_ALGORITHM

#define TLS_ECDSA_SHA256_ALGORITHM   0x0403

Definition at line 121 of file tls.h.

◆ TLS_RSA_SHA384_ALGORITHM

#define TLS_RSA_SHA384_ALGORITHM   0x0501

Definition at line 122 of file tls.h.

◆ TLS_ECDSA_SHA384_ALGORITHM

#define TLS_ECDSA_SHA384_ALGORITHM   0x0503

Definition at line 123 of file tls.h.

◆ TLS_RSA_SHA512_ALGORITHM

#define TLS_RSA_SHA512_ALGORITHM   0x0601

Definition at line 124 of file tls.h.

◆ TLS_ECDSA_SHA512_ALGORITHM

#define TLS_ECDSA_SHA512_ALGORITHM   0x0603

Definition at line 125 of file tls.h.

◆ TLS_RSA_PSS_RSAE_SHA256_ALGORITHM

#define TLS_RSA_PSS_RSAE_SHA256_ALGORITHM   0x0804

Definition at line 126 of file tls.h.

◆ TLS_RSA_PSS_RSAE_SHA384_ALGORITHM

#define TLS_RSA_PSS_RSAE_SHA384_ALGORITHM   0x0805

Definition at line 127 of file tls.h.

◆ TLS_RSA_PSS_RSAE_SHA512_ALGORITHM

#define TLS_RSA_PSS_RSAE_SHA512_ALGORITHM   0x0806

Definition at line 128 of file tls.h.

◆ TLS_RSA_PSS_PSS_SHA256_ALGORITHM

#define TLS_RSA_PSS_PSS_SHA256_ALGORITHM   0x0809

Definition at line 129 of file tls.h.

◆ TLS_RSA_PSS_PSS_SHA384_ALGORITHM

#define TLS_RSA_PSS_PSS_SHA384_ALGORITHM   0x080a

Definition at line 130 of file tls.h.

◆ TLS_RSA_PSS_PSS_SHA512_ALGORITHM

#define TLS_RSA_PSS_PSS_SHA512_ALGORITHM   0x080b

Definition at line 131 of file tls.h.

◆ TLS_SERVER_NAME

#define TLS_SERVER_NAME   0

Definition at line 134 of file tls.h.

Referenced by tls_client_hello().

◆ TLS_SERVER_NAME_HOST_NAME

#define TLS_SERVER_NAME_HOST_NAME   0

Definition at line 135 of file tls.h.

Referenced by tls_client_hello().

◆ TLS_MAX_FRAGMENT_LENGTH

#define TLS_MAX_FRAGMENT_LENGTH   1

Definition at line 138 of file tls.h.

Referenced by tls_client_hello().

◆ TLS_MAX_FRAGMENT_LENGTH_512

#define TLS_MAX_FRAGMENT_LENGTH_512   1

Definition at line 139 of file tls.h.

◆ TLS_MAX_FRAGMENT_LENGTH_1024

#define TLS_MAX_FRAGMENT_LENGTH_1024   2

Definition at line 140 of file tls.h.

◆ TLS_MAX_FRAGMENT_LENGTH_2048

#define TLS_MAX_FRAGMENT_LENGTH_2048   3

Definition at line 141 of file tls.h.

◆ TLS_MAX_FRAGMENT_LENGTH_4096

#define TLS_MAX_FRAGMENT_LENGTH_4096   4

Definition at line 142 of file tls.h.

◆ TLS_NAMED_GROUP

#define TLS_NAMED_GROUP   10

Definition at line 145 of file tls.h.

Referenced by tls_client_hello().

◆ TLS_NAMED_GROUP_SECP256R1

#define TLS_NAMED_GROUP_SECP256R1   23

Definition at line 146 of file tls.h.

Referenced by __tls_named_group().

◆ TLS_NAMED_GROUP_SECP384R1

#define TLS_NAMED_GROUP_SECP384R1   24

Definition at line 147 of file tls.h.

Referenced by __tls_named_group().

◆ TLS_NAMED_GROUP_X25519

#define TLS_NAMED_GROUP_X25519   29

Definition at line 148 of file tls.h.

Referenced by __tls_named_group().

◆ TLS_NAMED_GROUP_FFDHE2048

#define TLS_NAMED_GROUP_FFDHE2048   256

Definition at line 149 of file tls.h.

Referenced by __tls_named_group().

◆ TLS_NAMED_GROUP_FFDHE3072

#define TLS_NAMED_GROUP_FFDHE3072   257

Definition at line 150 of file tls.h.

Referenced by __tls_named_group().

◆ TLS_NAMED_GROUP_FFDHE4096

#define TLS_NAMED_GROUP_FFDHE4096   258

Definition at line 151 of file tls.h.

Referenced by __tls_named_group().

◆ TLS_SIGNATURE_ALGORITHMS

#define TLS_SIGNATURE_ALGORITHMS   13

Definition at line 154 of file tls.h.

Referenced by tls_client_hello().

◆ TLS_EXTENDED_MASTER_SECRET

#define TLS_EXTENDED_MASTER_SECRET   23

Definition at line 157 of file tls.h.

Referenced by tls_client_hello(), and tls_new_server_hello().

◆ TLS_SESSION_TICKET

#define TLS_SESSION_TICKET   35

Definition at line 160 of file tls.h.

Referenced by tls_client_hello().

◆ TLS_RENEGOTIATION_INFO

#define TLS_RENEGOTIATION_INFO   0xff01

Definition at line 163 of file tls.h.

Referenced by tls_client_hello(), and tls_new_server_hello().

◆ TLS_CIPHER_SUITES

#define TLS_CIPHER_SUITES   __table ( struct tls_cipher_suite, "tls_cipher_suites" )

TLS cipher suite table.

Definition at line 263 of file tls.h.

263#define TLS_CIPHER_SUITES \
264 __table ( struct tls_cipher_suite, "tls_cipher_suites" )

Referenced by tls_client_hello(), and tls_find_cipher_suite().

◆ __tls_cipher_suite

#define __tls_cipher_suite ( pref)
Value:
#define __table_entry(table, idx)
Declare a linker table entry.
Definition tables.h:239
#define TLS_CIPHER_SUITES
TLS cipher suite table.
Definition tls.h:263

Declare a TLS cipher suite.

Definition at line 267 of file tls.h.

267#define __tls_cipher_suite( pref ) \
268 __table_entry ( TLS_CIPHER_SUITES, pref )

Referenced by __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), and __tls_cipher_suite().

◆ TLS_NAMED_CURVE_TYPE

#define TLS_NAMED_CURVE_TYPE   3

TLS named curve type.

Definition at line 271 of file tls.h.

Referenced by tls_parse_ecdhe().

◆ TLS_NAMED_GROUPS

#define TLS_NAMED_GROUPS   __table ( struct tls_named_group, "tls_named_groups" )

TLS named group table.

Definition at line 282 of file tls.h.

282#define TLS_NAMED_GROUPS \
283 __table ( struct tls_named_group, "tls_named_groups" )

Referenced by tls_client_hello(), tls_find_named_group(), and tls_find_param_group().

◆ __tls_named_group

#define __tls_named_group ( pref)
Value:
#define TLS_NAMED_GROUPS
TLS named group table.
Definition tls.h:282

Declare a TLS named group.

Definition at line 286 of file tls.h.

286#define __tls_named_group( pref ) \
287 __table_entry ( TLS_NAMED_GROUPS, pref )

Referenced by __tls_named_group(), __tls_named_group(), and __tls_named_group().

◆ __tls_anon_named_group

#define __tls_anon_named_group   __tls_named_group ( 98 )

Declare a TLS anonymous named group.

Definition at line 290 of file tls.h.

◆ TLS_NUM_NAMED_GROUPS

#define TLS_NUM_NAMED_GROUPS
Value:
( ( unsigned int ) \
#define __table_entries(table, idx)
Get start of linker table entries.
Definition tables.h:250
#define table_start(table)
Get start of linker table.
Definition tables.h:283

Number of non-anonymous TLS named groups.

Definition at line 293 of file tls.h.

293#define TLS_NUM_NAMED_GROUPS \
294 ( ( unsigned int ) \
295 ( __table_entries ( TLS_NAMED_GROUPS, 97 ) \
296 - table_start ( TLS_NAMED_GROUPS ) ) )

Referenced by tls_client_hello().

◆ TLS_SIG_HASH_ALGORITHMS

#define TLS_SIG_HASH_ALGORITHMS
Value:
"tls_sig_hash_algorithms" )
A TLS signature algorithm.
Definition tls.h:323
#define __table(type, name)
Declare a linker table.
Definition tables.h:180

TLS signature hash algorithm table.

Note that the default (TLSv1.1 and earlier) algorithm using MD5+SHA1 is never explicitly specified.

Definition at line 339 of file tls.h.

339#define TLS_SIG_HASH_ALGORITHMS \
340 __table ( struct tls_signature_hash_algorithm, \
341 "tls_sig_hash_algorithms" )

Referenced by tls_client_hello(), tls_find_signature_hash(), and tls_signature_hash_algorithm().

◆ __tls_sig_hash_algorithm

struct tls_signature_hash_algorithm tls_rsa_pss_pss_sha512 __tls_sig_hash_algorithm   __table_entry ( TLS_SIG_HASH_ALGORITHMS, 01 )

Declare a TLS signature hash algorithm.

RSA-PSS with RSASSA-PSS OID and SHA-512 signature hash algorithm.

RSA-PSS with rsaEncryption OID and SHA-512 signature hash algorithm.

RSA-PSS with RSASSA-PSS OID and SHA-384 signature hash algorithm.

RSA-PSS with rsaEncryption OID and SHA-384 signature hash algorithm.

RSA-PSS with RSASSA-PSS OID and SHA-256 signature hash algorithm.

RSA-PSS with rsaEncryption OID and SHA-256 signature hash algorithm.

Definition at line 344 of file tls.h.

344#define __tls_sig_hash_algorithm \
345 __table_entry ( TLS_SIG_HASH_ALGORITHMS, 01 )

◆ TLS_MAX_FRAGMENT_LENGTH_VALUE

#define TLS_MAX_FRAGMENT_LENGTH_VALUE   TLS_MAX_FRAGMENT_LENGTH_4096

Advertised maximum fragment length.

Definition at line 489 of file tls.h.

Referenced by tls_client_hello().

◆ TLS_TX_BUFSIZE

#define TLS_TX_BUFSIZE   4096

TX maximum fragment length.

TLS requires us to limit our transmitted records to the maximum fragment length that we attempt to negotiate, even if the server does not respect this choice.

Definition at line 497 of file tls.h.

Referenced by tls_iob_reserved(), and tls_send_record().

◆ TLS_RX_BUFSIZE

#define TLS_RX_BUFSIZE   4096

RX I/O buffer size.

The maximum fragment length extension is optional, and many common implementations (including OpenSSL) do not support it. We must therefore be prepared to receive records of up to 16kB in length. The chance of an allocation of this size failing is non-negligible, so we must split received data into smaller allocations.

Definition at line 507 of file tls.h.

Referenced by tls_newdata_process_header().

◆ TLS_RX_MIN_BUFSIZE

#define TLS_RX_MIN_BUFSIZE   512

Minimum RX I/O buffer size.

To simplify manipulations, we ensure that no RX I/O buffer is smaller than this size. This allows us to assume that the MAC and padding are entirely contained within the final I/O buffer.

Definition at line 515 of file tls.h.

Referenced by tls_newdata_process_header().

◆ TLS_RX_ALIGN

#define TLS_RX_ALIGN   16

RX I/O buffer alignment.

Definition at line 518 of file tls.h.

Referenced by tls_newdata_process_header().

Enumeration Type Documentation

◆ tls_rx_state

TLS RX state machine state.

Enumerator
TLS_RX_HEADER 
TLS_RX_DATA 

Definition at line 182 of file tls.h.

182 {
183 TLS_RX_HEADER = 0,
185};
@ TLS_RX_HEADER
Definition tls.h:183
@ TLS_RX_DATA
Definition tls.h:184

◆ tls_tx_pending

TLS TX pending flags.

Enumerator
TLS_TX_CLIENT_HELLO 
TLS_TX_CERTIFICATE 
TLS_TX_CLIENT_KEY_EXCHANGE 
TLS_TX_CERTIFICATE_VERIFY 
TLS_TX_CHANGE_CIPHER 
TLS_TX_FINISHED 

Definition at line 188 of file tls.h.

188 {
189 TLS_TX_CLIENT_HELLO = 0x0001,
190 TLS_TX_CERTIFICATE = 0x0002,
193 TLS_TX_CHANGE_CIPHER = 0x0010,
194 TLS_TX_FINISHED = 0x0020,
195};
@ TLS_TX_FINISHED
Definition tls.h:194
@ TLS_TX_CLIENT_KEY_EXCHANGE
Definition tls.h:191
@ TLS_TX_CLIENT_HELLO
Definition tls.h:189
@ TLS_TX_CHANGE_CIPHER
Definition tls.h:193
@ TLS_TX_CERTIFICATE_VERIFY
Definition tls.h:192
@ TLS_TX_CERTIFICATE
Definition tls.h:190

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ add_tls()

int add_tls ( struct interface * xfer,
const char * name,
struct x509_root * root,
struct private_key * key )
extern

Add TLS on an interface.

Parameters
xferData transfer interface
nameHost name
rootRoot of trust (or NULL to use default)
keyPrivate key (or NULL to use default)
Return values
rcReturn status code

Definition at line 4119 of file tls.c.

4120 {
4121 struct tls_connection *tls;
4122 int rc;
4123
4124 /* Allocate and initialise TLS structure */
4125 tls = malloc ( sizeof ( *tls ) );
4126 if ( ! tls ) {
4127 rc = -ENOMEM;
4128 goto err_alloc;
4129 }
4130 memset ( tls, 0, sizeof ( *tls ) );
4131 ref_init ( &tls->refcnt, free_tls );
4132 INIT_LIST_HEAD ( &tls->list );
4137 &tls->refcnt );
4138 tls->client.key = privkey_get ( key ? key : &private_key );
4140 tls->version = TLS_VERSION_MAX;
4141 tls->exchange = &exchange_null;
4143 tls_clear_digest ( tls );
4145 tls_clear_cipher ( tls, &tls->tx.cipherspec.active );
4146 tls_clear_cipher ( tls, &tls->tx.cipherspec.pending );
4148 tls_clear_cipher ( tls, &tls->rx.cipherspec.active );
4149 tls_clear_cipher ( tls, &tls->rx.cipherspec.pending );
4150 iob_populate ( &tls->rx.iobuf, &tls->rx.header, 0,
4151 sizeof ( tls->rx.header ) );
4152 INIT_LIST_HEAD ( &tls->rx.data );
4153
4154 /* Open secure channel */
4155 if ( ( rc = channel_open ( &tls->channel ) ) != 0 )
4156 goto err_channel;
4157
4158 /* Find or create session */
4159 if ( ( rc = tls_session ( tls, name ) ) != 0 )
4160 goto err_session;
4161 list_add_tail ( &tls->list, &tls->session->conn );
4162
4163 /* Start negotiation */
4164 tls_restart ( tls );
4165
4166 /* Attach to parent interface, mortalise self, and return */
4167 intf_insert ( xfer, &tls->plainstream, &tls->cipherstream );
4168 ref_put ( &tls->refcnt );
4169 return 0;
4170
4171 err_session:
4172 channel_close ( &tls->channel );
4173 err_channel:
4174 ref_put ( &tls->refcnt );
4175 err_alloc:
4176 return rc;
4177}
union @162305117151260234136356364136041353210355154177 key
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
const char * name
Definition ath9k_hw.c:1986
int channel_open(struct secure_channel *channel)
Open secure channel.
Definition channel.c:1205
void channel_close(struct secure_channel *channel)
Close secure channel.
Definition channel.c:1301
static void channel_init(struct secure_channel *channel, struct secure_channel_operations *op)
Initialise secure channel.
Definition channel.h:256
#define TLS_VERSION_MAX
Maximum TLS version.
Definition crypto.h:17
struct exchange_algorithm exchange_null
#define ENOMEM
Not enough space.
Definition errno.h:578
void * memset(void *dest, int character, size_t len) __nonnull
void intf_insert(struct interface *intf, struct interface *upper, struct interface *lower)
Insert a filter interface.
Definition interface.c:402
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
static void iob_populate(struct io_buffer *iobuf, void *data, size_t len, size_t max_len)
Create a temporary I/O buffer.
Definition iobuf.h:255
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:677
static struct private_key * privkey_get(struct private_key *key)
Get reference to private key.
Definition privkey.h:31
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
Definition process.h:146
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
struct x509_root root_certificates
Root certificates.
Definition rootcert.c:79
struct stp_switch root
Root switch.
Definition stp.h:15
A private key.
Definition privkey.h:17
struct tls_cipherspec pending
Next cipher specification.
Definition tls.h:319
struct tls_cipherspec active
Current cipher specification.
Definition tls.h:317
const struct tls_endpoint * writer
Writer endpoint.
Definition tls.h:315
TLS client state.
Definition tls.h:421
struct private_key * key
Private key.
Definition tls.h:423
A TLS connection.
Definition tls.h:445
struct interface cipherstream
Ciphertext stream.
Definition tls.h:461
struct tls_session * session
Session.
Definition tls.h:450
struct tls_server server
Server state.
Definition tls.h:485
struct tls_rx rx
Receive state.
Definition tls.h:481
struct secure_channel channel
Secure channel.
Definition tls.h:475
struct interface plainstream
Plaintext stream.
Definition tls.h:459
struct tls_tx tx
Transmit state.
Definition tls.h:479
struct exchange_algorithm * exchange
Key exchange algorithm.
Definition tls.h:466
struct list_head list
List of connections within the same session.
Definition tls.h:452
struct tls_client client
Client state.
Definition tls.h:483
uint16_t version
Protocol version.
Definition tls.h:464
struct refcnt refcnt
Reference counter.
Definition tls.h:447
struct tls_cipherspec_pair cipherspec
Cipher specifications.
Definition tls.h:405
struct list_head data
List of received data buffers.
Definition tls.h:415
struct io_buffer iobuf
Current received record header (static I/O buffer).
Definition tls.h:413
struct tls_header header
Current received record header.
Definition tls.h:411
TLS server state.
Definition tls.h:431
struct interface validator
Certificate validator.
Definition tls.h:437
struct x509_root * root
Root of trust.
Definition tls.h:433
A TLS session.
Definition tls.h:364
struct list_head conn
List of connections.
Definition tls.h:387
struct tls_cipherspec_pair cipherspec
Cipher specifications.
Definition tls.h:393
struct process process
Transmit process.
Definition tls.h:399
static struct interface_descriptor tls_cipherstream_desc
TLS ciphertext stream interface descriptor.
Definition tls.c:3934
static void tls_clear_digest(struct tls_connection *tls)
Clear key schedule digest algorithm.
Definition tls.c:457
static struct secure_channel_operations tls_channel_ops
Secure channel operations.
Definition tls.c:1383
static struct interface_descriptor tls_validator_desc
TLS certificate validator interface descriptor.
Definition tls.c:3991
static struct interface_descriptor tls_plainstream_desc
TLS plaintext stream interface descriptor.
Definition tls.c:3716
static void free_tls(struct refcnt *refcnt)
Free TLS connection.
Definition tls.c:344
static void tls_restart(struct tls_connection *tls)
Restart negotiation.
Definition tls.c:1564
static struct process_descriptor tls_process_desc
TLS TX process descriptor.
Definition tls.c:4100
static void tls_clear_cipher(struct tls_connection *tls, struct tls_cipherspec *cipherspec)
static struct x509_root * x509_root_get(struct x509_root *root)
Get reference to X.509 root certificate list.
Definition x509.h:393

References tls_cipherspec_pair::active, tls_connection::channel, channel_close(), channel_init(), channel_open(), tls_rx::cipherspec, tls_tx::cipherspec, tls_connection::cipherstream, tls_connection::client, tls_session::conn, tls_rx::data, ENOMEM, tls_connection::exchange, exchange_null, free_tls(), tls_rx::header, INIT_LIST_HEAD, intf_init(), intf_insert(), iob_populate(), tls_rx::iobuf, key, tls_client::key, tls_connection::list, list_add_tail, malloc(), memset(), name, tls_cipherspec_pair::pending, tls_connection::plainstream, privkey_get(), tls_tx::process, process_init_stopped(), rc, ref_init, ref_put, tls_connection::refcnt, root, tls_server::root, root_certificates, tls_connection::rx, tls_connection::server, tls_connection::session, tls_channel_ops, tls_cipherstream_desc, tls_clear_cipher(), tls_clear_digest(), tls_plainstream_desc, tls_process_desc, tls_restart(), tls_validator_desc, TLS_VERSION_MAX, tls_connection::tx, tls_server::validator, tls_connection::version, tls_cipherspec_pair::writer, and x509_root_get().

Referenced by apply_syslogs_settings(), https_filter(), ipair_rx_session(), and REQUIRING_SYMBOL().

Variable Documentation

◆ tls_classic_pre_master_algorithm

struct exchange_algorithm tls_classic_pre_master_algorithm
extern

Classic pre-master secret key exchange algorithm.

Definition at line 101 of file tlsclassic.c.

101 {
102 .name = "classic pre-master",
103 .privsize = sizeof ( struct tls_classic_pre_master_private ),
104 .pubsize = 0,
105 .sharedsize = sizeof ( struct tls_classic_pre_master_shared ),
106 .share = exchange_null_share,
108};
int exchange_null_share(struct exchange_algorithm *exchange __unused, const void *private __unused, void *public __unused)
A classic pre-master private key.
Definition tlsclassic.c:62
A classic pre-master shared secret.
Definition tlsclassic.c:68
static int tls_classic_pre_master_agree(struct exchange_algorithm *exchange __unused, const void *private, const void *partner __unused, void *shared)
Agree classic pre-master secret.
Definition tlsclassic.c:85

◆ tls_null_exchange_algorithm

struct tls_key_exchange_algorithm tls_null_exchange_algorithm
extern

Null key exchange algorithm.

Definition at line 865 of file tls.c.

865 {
866 .name = "null",
867 .exchange = &exchange_null,
868 .parse = tls_parse_null,
869 .len_len = 0,
870};
static int tls_parse_null(struct tls_connection *tls, const void *data, size_t len, struct tls_key_exchange_parameters *params __unused)
Parse key exchange parameters from unexpected Server Key Exchange record.
Definition tls.c:856

◆ tls_pubkey_exchange_algorithm

struct tls_key_exchange_algorithm tls_pubkey_exchange_algorithm
extern

Public key exchange algorithm.

Definition at line 873 of file tls.c.

873 {
874 .name = "pubkey",
876 .parse = tls_parse_null,
877 .len_len = sizeof ( uint16_t ),
878};
unsigned short uint16_t
Definition stdint.h:11
struct exchange_algorithm tls_classic_pre_master_algorithm
Classic pre-master secret key exchange algorithm.
Definition tlsclassic.c:101

Referenced by __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), and tls_cipher_name().

◆ tls_dhe_exchange_algorithm

struct tls_key_exchange_algorithm tls_dhe_exchange_algorithm
extern

Ephemeral Diffie-Hellman key exchange algorithm.

Definition at line 944 of file tls.c.

944 {
945 .name = "dhe",
946 .exchange = &exchange_null,
947 .parse = tls_parse_dhe,
948 .len_len = sizeof ( uint16_t ),
949};
static int tls_parse_dhe(struct tls_connection *tls, const void *data, size_t len, struct tls_key_exchange_parameters *params)
Parse key exchange parameters from DHE Server Key Exchange record.
Definition tls.c:889

Referenced by __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), and __tls_cipher_suite().

◆ tls_ecdhe_exchange_algorithm

struct tls_key_exchange_algorithm tls_ecdhe_exchange_algorithm
extern

Ephemeral Elliptic Curve Diffie-Hellman key exchange algorithm.

Definition at line 1003 of file tls.c.

1003 {
1004 .name = "ecdhe",
1005 .exchange = &exchange_null,
1006 .parse = tls_parse_ecdhe,
1007 .len_len = sizeof ( uint8_t ),
1008};
unsigned char uint8_t
Definition stdint.h:10
static int tls_parse_ecdhe(struct tls_connection *tls, const void *data, size_t len, struct tls_key_exchange_parameters *params)
Parse key exchange parameters from ECDHE Server Key Exchange record.
Definition tls.c:960

Referenced by __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), and __tls_cipher_suite().