iPXE
Data Structures | Macros | Enumerations | Functions
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/md5.h>
#include <ipxe/sha1.h>
#include <ipxe/sha256.h>
#include <ipxe/x509.h>
#include <ipxe/pending.h>
#include <ipxe/iobuf.h>
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  tls_header
 A TLS header. More...
 
struct  tls_verify_data
 TLS verification data. More...
 
struct  tls_cipher_suite
 A TLS cipher suite. More...
 
struct  tls_cipherspec
 A TLS cipher specification. More...
 
struct  tls_signature_hash_id
 A TLS signature and hash algorithm identifier. More...
 
struct  tls_signature_hash_algorithm
 A TLS signature algorithm. More...
 
struct  tls_pre_master_secret
 TLS pre-master secret. More...
 
struct  tls_client_random
 TLS client random data. More...
 
struct  md5_sha1_context
 An MD5+SHA1 context. More...
 
struct  md5_sha1_digest
 An MD5+SHA1 digest. More...
 
struct  tls_session
 A TLS session. More...
 
struct  tls_connection
 A TLS connection. More...
 

Macros

#define TLS_VERSION_TLS_1_0   0x0301
 TLS version 1.0. More...
 
#define TLS_VERSION_TLS_1_1   0x0302
 TLS version 1.1. More...
 
#define TLS_VERSION_TLS_1_2   0x0303
 TLS version 1.2. More...
 
#define TLS_TYPE_CHANGE_CIPHER   20
 Change cipher content type. More...
 
#define TLS_TYPE_ALERT   21
 Alert content type. More...
 
#define TLS_TYPE_HANDSHAKE   22
 Handshake content type. More...
 
#define TLS_TYPE_DATA   23
 Application data content type. More...
 
#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_RSA_WITH_NULL_MD5   0x0001
 
#define TLS_RSA_WITH_NULL_SHA   0x0002
 
#define TLS_RSA_WITH_AES_128_CBC_SHA   0x002f
 
#define TLS_RSA_WITH_AES_256_CBC_SHA   0x0035
 
#define TLS_RSA_WITH_AES_128_CBC_SHA256   0x003c
 
#define TLS_RSA_WITH_AES_256_CBC_SHA256   0x003d
 
#define TLS_MD5_ALGORITHM   1
 
#define TLS_SHA1_ALGORITHM   2
 
#define TLS_SHA224_ALGORITHM   3
 
#define TLS_SHA256_ALGORITHM   4
 
#define TLS_SHA384_ALGORITHM   5
 
#define TLS_SHA512_ALGORITHM   6
 
#define TLS_RSA_ALGORITHM   1
 
#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_SIGNATURE_ALGORITHMS   13
 
#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. More...
 
#define __tls_cipher_suite(pref)   __table_entry ( TLS_CIPHER_SUITES, pref )
 Declare a TLS cipher suite. More...
 
#define TLS_SIG_HASH_ALGORITHMS
 TLS signature hash algorithm table. More...
 
#define __tls_sig_hash_algorithm   __table_entry ( TLS_SIG_HASH_ALGORITHMS, 01 )
 Declare a TLS signature hash algorithm. More...
 
#define MD5_SHA1_CTX_SIZE   sizeof ( struct md5_sha1_context )
 MD5+SHA1 context size. More...
 
#define MD5_SHA1_DIGEST_SIZE   sizeof ( struct md5_sha1_digest )
 MD5+SHA1 digest size. More...
 
#define TLS_RX_BUFSIZE   4096
 RX I/O buffer size. More...
 
#define TLS_RX_MIN_BUFSIZE   512
 Minimum RX I/O buffer size. More...
 
#define TLS_RX_ALIGN   16
 RX I/O buffer alignment. More...
 

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)
 
int add_tls (struct interface *xfer, const char *name, struct interface **next)
 

Detailed Description

Transport Layer Security Protocol.

Definition in file tls.h.

Macro Definition Documentation

◆ TLS_VERSION_TLS_1_0

#define TLS_VERSION_TLS_1_0   0x0301

TLS version 1.0.

Definition at line 42 of file tls.h.

◆ 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.

◆ TLS_TYPE_CHANGE_CIPHER

#define TLS_TYPE_CHANGE_CIPHER   20

Change cipher content type.

Definition at line 51 of file tls.h.

◆ TLS_TYPE_ALERT

#define TLS_TYPE_ALERT   21

Alert content type.

Definition at line 54 of file tls.h.

◆ TLS_TYPE_HANDSHAKE

#define TLS_TYPE_HANDSHAKE   22

Handshake content type.

Definition at line 57 of file tls.h.

◆ TLS_TYPE_DATA

#define TLS_TYPE_DATA   23

Application data content type.

Definition at line 60 of file tls.h.

◆ TLS_HELLO_REQUEST

#define TLS_HELLO_REQUEST   0

Definition at line 63 of file tls.h.

◆ TLS_CLIENT_HELLO

#define TLS_CLIENT_HELLO   1

Definition at line 64 of file tls.h.

◆ TLS_SERVER_HELLO

#define TLS_SERVER_HELLO   2

Definition at line 65 of file tls.h.

◆ TLS_NEW_SESSION_TICKET

#define TLS_NEW_SESSION_TICKET   4

Definition at line 66 of file tls.h.

◆ TLS_CERTIFICATE

#define TLS_CERTIFICATE   11

Definition at line 67 of file tls.h.

◆ TLS_SERVER_KEY_EXCHANGE

#define TLS_SERVER_KEY_EXCHANGE   12

Definition at line 68 of file tls.h.

◆ TLS_CERTIFICATE_REQUEST

#define TLS_CERTIFICATE_REQUEST   13

Definition at line 69 of file tls.h.

◆ TLS_SERVER_HELLO_DONE

#define TLS_SERVER_HELLO_DONE   14

Definition at line 70 of file tls.h.

◆ TLS_CERTIFICATE_VERIFY

#define TLS_CERTIFICATE_VERIFY   15

Definition at line 71 of file tls.h.

◆ TLS_CLIENT_KEY_EXCHANGE

#define TLS_CLIENT_KEY_EXCHANGE   16

Definition at line 72 of file tls.h.

◆ TLS_FINISHED

#define TLS_FINISHED   20

Definition at line 73 of file tls.h.

◆ TLS_ALERT_WARNING

#define TLS_ALERT_WARNING   1

Definition at line 76 of file tls.h.

◆ TLS_ALERT_FATAL

#define TLS_ALERT_FATAL   2

Definition at line 77 of file tls.h.

◆ TLS_RSA_WITH_NULL_MD5

#define TLS_RSA_WITH_NULL_MD5   0x0001

Definition at line 80 of file tls.h.

◆ TLS_RSA_WITH_NULL_SHA

#define TLS_RSA_WITH_NULL_SHA   0x0002

Definition at line 81 of file tls.h.

◆ TLS_RSA_WITH_AES_128_CBC_SHA

#define TLS_RSA_WITH_AES_128_CBC_SHA   0x002f

Definition at line 82 of file tls.h.

◆ TLS_RSA_WITH_AES_256_CBC_SHA

#define TLS_RSA_WITH_AES_256_CBC_SHA   0x0035

Definition at line 83 of file tls.h.

◆ TLS_RSA_WITH_AES_128_CBC_SHA256

#define TLS_RSA_WITH_AES_128_CBC_SHA256   0x003c

Definition at line 84 of file tls.h.

◆ TLS_RSA_WITH_AES_256_CBC_SHA256

#define TLS_RSA_WITH_AES_256_CBC_SHA256   0x003d

Definition at line 85 of file tls.h.

◆ TLS_MD5_ALGORITHM

#define TLS_MD5_ALGORITHM   1

Definition at line 88 of file tls.h.

◆ TLS_SHA1_ALGORITHM

#define TLS_SHA1_ALGORITHM   2

Definition at line 89 of file tls.h.

◆ TLS_SHA224_ALGORITHM

#define TLS_SHA224_ALGORITHM   3

Definition at line 90 of file tls.h.

◆ TLS_SHA256_ALGORITHM

#define TLS_SHA256_ALGORITHM   4

Definition at line 91 of file tls.h.

◆ TLS_SHA384_ALGORITHM

#define TLS_SHA384_ALGORITHM   5

Definition at line 92 of file tls.h.

◆ TLS_SHA512_ALGORITHM

#define TLS_SHA512_ALGORITHM   6

Definition at line 93 of file tls.h.

◆ TLS_RSA_ALGORITHM

#define TLS_RSA_ALGORITHM   1

Definition at line 96 of file tls.h.

◆ TLS_SERVER_NAME

#define TLS_SERVER_NAME   0

Definition at line 99 of file tls.h.

◆ TLS_SERVER_NAME_HOST_NAME

#define TLS_SERVER_NAME_HOST_NAME   0

Definition at line 100 of file tls.h.

◆ TLS_MAX_FRAGMENT_LENGTH

#define TLS_MAX_FRAGMENT_LENGTH   1

Definition at line 103 of file tls.h.

◆ TLS_MAX_FRAGMENT_LENGTH_512

#define TLS_MAX_FRAGMENT_LENGTH_512   1

Definition at line 104 of file tls.h.

◆ TLS_MAX_FRAGMENT_LENGTH_1024

#define TLS_MAX_FRAGMENT_LENGTH_1024   2

Definition at line 105 of file tls.h.

◆ TLS_MAX_FRAGMENT_LENGTH_2048

#define TLS_MAX_FRAGMENT_LENGTH_2048   3

Definition at line 106 of file tls.h.

◆ TLS_MAX_FRAGMENT_LENGTH_4096

#define TLS_MAX_FRAGMENT_LENGTH_4096   4

Definition at line 107 of file tls.h.

◆ TLS_SIGNATURE_ALGORITHMS

#define TLS_SIGNATURE_ALGORITHMS   13

Definition at line 110 of file tls.h.

◆ TLS_SESSION_TICKET

#define TLS_SESSION_TICKET   35

Definition at line 113 of file tls.h.

◆ TLS_RENEGOTIATION_INFO

#define TLS_RENEGOTIATION_INFO   0xff01

Definition at line 116 of file tls.h.

◆ TLS_CIPHER_SUITES

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

TLS cipher suite table.

Definition at line 157 of file tls.h.

◆ __tls_cipher_suite

#define __tls_cipher_suite (   pref)    __table_entry ( TLS_CIPHER_SUITES, pref )

Declare a TLS cipher suite.

Definition at line 161 of file tls.h.

◆ TLS_SIG_HASH_ALGORITHMS

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

TLS signature hash algorithm table.

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

Definition at line 203 of file tls.h.

◆ __tls_sig_hash_algorithm

#define __tls_sig_hash_algorithm   __table_entry ( TLS_SIG_HASH_ALGORITHMS, 01 )

Declare a TLS signature hash algorithm.

Definition at line 208 of file tls.h.

◆ MD5_SHA1_CTX_SIZE

#define MD5_SHA1_CTX_SIZE   sizeof ( struct md5_sha1_context )

MD5+SHA1 context size.

Definition at line 236 of file tls.h.

◆ MD5_SHA1_DIGEST_SIZE

#define MD5_SHA1_DIGEST_SIZE   sizeof ( struct md5_sha1_digest )

MD5+SHA1 digest size.

Definition at line 247 of file tls.h.

◆ 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 368 of file tls.h.

◆ 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 376 of file tls.h.

◆ TLS_RX_ALIGN

#define TLS_RX_ALIGN   16

RX I/O buffer alignment.

Definition at line 379 of file tls.h.

Enumeration Type Documentation

◆ tls_rx_state

TLS RX state machine state.

Enumerator
TLS_RX_HEADER 
TLS_RX_DATA 

Definition at line 127 of file tls.h.

127  {
128  TLS_RX_HEADER = 0,
129  TLS_RX_DATA,
130 };

◆ 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 133 of file tls.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ add_tls()

int add_tls ( struct interface xfer,
const char *  name,
struct interface **  next 
)

Definition at line 3091 of file tls.c.

3092  {
3093  struct tls_connection *tls;
3094  int rc;
3095 
3096  /* Allocate and initialise TLS structure */
3097  tls = malloc ( sizeof ( *tls ) );
3098  if ( ! tls ) {
3099  rc = -ENOMEM;
3100  goto err_alloc;
3101  }
3102  memset ( tls, 0, sizeof ( *tls ) );
3103  ref_init ( &tls->refcnt, free_tls );
3104  INIT_LIST_HEAD ( &tls->list );
3105  intf_init ( &tls->plainstream, &tls_plainstream_desc, &tls->refcnt );
3107  intf_init ( &tls->validator, &tls_validator_desc, &tls->refcnt );
3109  &tls->refcnt );
3111  tls_clear_cipher ( tls, &tls->tx_cipherspec );
3112  tls_clear_cipher ( tls, &tls->tx_cipherspec_pending );
3113  tls_clear_cipher ( tls, &tls->rx_cipherspec );
3114  tls_clear_cipher ( tls, &tls->rx_cipherspec_pending );
3115  tls->client_random.gmt_unix_time = time ( NULL );
3116  iob_populate ( &tls->rx_header_iobuf, &tls->rx_header, 0,
3117  sizeof ( tls->rx_header ) );
3118  INIT_LIST_HEAD ( &tls->rx_data );
3119  if ( ( rc = tls_generate_random ( tls, &tls->client_random.random,
3120  ( sizeof ( tls->client_random.random ) ) ) ) != 0 ) {
3121  goto err_random;
3122  }
3123  tls->pre_master_secret.version = htons ( tls->version );
3124  if ( ( rc = tls_generate_random ( tls, &tls->pre_master_secret.random,
3125  ( sizeof ( tls->pre_master_secret.random ) ) ) ) != 0 ) {
3126  goto err_random;
3127  }
3128  if ( ( rc = tls_session ( tls, name ) ) != 0 )
3129  goto err_session;
3130  list_add_tail ( &tls->list, &tls->session->conn );
3131 
3132  /* Start negotiation */
3133  tls_restart ( tls );
3134 
3135  /* Attach to parent interface, mortalise self, and return */
3136  intf_plug_plug ( &tls->plainstream, xfer );
3137  *next = &tls->cipherstream;
3138  ref_put ( &tls->refcnt );
3139  return 0;
3140 
3141  err_session:
3142  err_random:
3143  ref_put ( &tls->refcnt );
3144  err_alloc:
3145  return rc;
3146 }
static void free_tls(struct refcnt *refcnt)
Free TLS connection.
Definition: tls.c:364
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
struct process process
TX process.
Definition: tls.h:346
struct tls_session * session
Session.
Definition: tls.h:279
struct io_buffer rx_header_iobuf
Current received record header (static I/O buffer)
Definition: tls.h:355
static void tls_restart(struct tls_connection *tls)
Restart negotiation.
Definition: tls.c:987
uint32_t next
Next descriptor address.
Definition: myson.h:18
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct refcnt refcnt
Reference counter.
Definition: tls.h:276
#define TLS_VERSION_TLS_1_2
TLS version 1.2.
Definition: tls.h:48
struct tls_header rx_header
Current received record header.
Definition: tls.h:353
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
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:186
static struct interface_descriptor tls_cipherstream_desc
TLS ciphertext stream interface descriptor.
Definition: tls.c:2822
static struct interface_descriptor tls_validator_desc
TLS certificate validator interface descriptor.
Definition: tls.c:2902
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct tls_cipherspec tx_cipherspec
Current TX cipher specification.
Definition: tls.h:299
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct list_head list
List of connections within the same session.
Definition: tls.h:281
uint32_t gmt_unix_time
GMT Unix time.
Definition: tls.h:222
struct tls_client_random client_random
Client random bytes.
Definition: tls.h:313
struct interface cipherstream
Ciphertext stream.
Definition: tls.h:294
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:145
struct tls_cipherspec rx_cipherspec
Current RX cipher specification.
Definition: tls.h:303
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
struct tls_cipherspec tx_cipherspec_pending
Next TX cipher specification.
Definition: tls.h:301
struct tls_pre_master_secret pre_master_secret
Premaster secret.
Definition: tls.h:307
uint8_t random[46]
Random data.
Definition: tls.h:216
struct list_head rx_data
List of received data buffers.
Definition: tls.h:357
static struct interface_descriptor tls_plainstream_desc
TLS plaintext stream interface descriptor.
Definition: tls.c:2625
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
uint8_t random[28]
Random data.
Definition: tls.h:224
struct interface validator
Certificate validator.
Definition: tls.h:332
A TLS session.
Definition: tls.h:250
static struct process_descriptor tls_process_desc
TLS TX process descriptor.
Definition: tls.c:3027
struct tls_cipherspec rx_cipherspec_pending
Next RX cipher specification.
Definition: tls.h:305
uint16_t version
Protocol version.
Definition: tls.h:297
A TLS connection.
Definition: tls.h:274
static void tls_clear_cipher(struct tls_connection *tls, struct tls_cipherspec *cipherspec)
struct list_head conn
List of connections.
Definition: tls.h:270
static int tls_generate_random(struct tls_connection *tls, void *data, size_t len)
Generate random data.
Definition: tls.c:436
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
struct interface plainstream
Plaintext stream.
Definition: tls.h:292
uint64_t time
Current time.
Definition: ntlm.h:20
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define htons(value)
Definition: byteswap.h:135
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
void * memset(void *dest, int character, size_t len) __nonnull
uint16_t version
TLS version.
Definition: tls.h:214

References tls_connection::cipherstream, tls_connection::client_random, tls_session::conn, ENOMEM, free_tls(), tls_client_random::gmt_unix_time, htons, INIT_LIST_HEAD, intf_init(), intf_plug_plug(), iob_populate(), tls_connection::list, list_add_tail, malloc(), memset(), name, next, NULL, tls_connection::plainstream, tls_connection::pre_master_secret, tls_connection::process, process_init_stopped(), tls_pre_master_secret::random, tls_client_random::random, rc, ref_init, ref_put, tls_connection::refcnt, tls_connection::rx_cipherspec, tls_connection::rx_cipherspec_pending, tls_connection::rx_data, tls_connection::rx_header, tls_connection::rx_header_iobuf, tls_connection::session, time, tls_cipherstream_desc, tls_clear_cipher(), tls_generate_random(), tls_plainstream_desc, tls_process_desc, tls_restart(), tls_validator_desc, TLS_VERSION_TLS_1_2, tls_connection::tx_cipherspec, tls_connection::tx_cipherspec_pending, tls_connection::validator, tls_pre_master_secret::version, and tls_connection::version.

Referenced by apply_syslogs_settings().