7 * Transport Layer Security Protocol
11 #include <gpxe/refcnt.h>
12 #include <gpxe/filter.h>
13 #include <gpxe/process.h>
14 #include <gpxe/crypto.h>
16 #include <gpxe/sha1.h>
17 #include <gpxe/x509.h>
23 * This is a TLS_TYPE_XXX constant
28 * This is a TLS_VERSION_XXX constant
31 /** Length of payload */
33 } __attribute__ (( packed
));
35 /** TLS version 1.0 */
36 #define TLS_VERSION_TLS_1_0 0x0301
38 /** TLS version 1.1 */
39 #define TLS_VERSION_TLS_1_1 0x0302
41 /** Change cipher content type */
42 #define TLS_TYPE_CHANGE_CIPHER 20
44 /** Alert content type */
45 #define TLS_TYPE_ALERT 21
47 /** Handshake content type */
48 #define TLS_TYPE_HANDSHAKE 22
50 /** Application data content type */
51 #define TLS_TYPE_DATA 23
53 /* Handshake message types */
54 #define TLS_HELLO_REQUEST 0
55 #define TLS_CLIENT_HELLO 1
56 #define TLS_SERVER_HELLO 2
57 #define TLS_CERTIFICATE 11
58 #define TLS_SERVER_KEY_EXCHANGE 12
59 #define TLS_CERTIFICATE_REQUEST 13
60 #define TLS_SERVER_HELLO_DONE 14
61 #define TLS_CERTIFICATE_VERIFY 15
62 #define TLS_CLIENT_KEY_EXCHANGE 16
63 #define TLS_FINISHED 20
65 /* TLS alert levels */
66 #define TLS_ALERT_WARNING 1
67 #define TLS_ALERT_FATAL 2
69 /* TLS cipher specifications */
70 #define TLS_RSA_WITH_NULL_MD5 0x0001
71 #define TLS_RSA_WITH_NULL_SHA 0x0002
72 #define TLS_RSA_WITH_AES_128_CBC_SHA 0x002f
73 #define TLS_RSA_WITH_AES_256_CBC_SHA 0x0035
75 /** TLS RX state machine state */
81 /** TLS TX state machine state */
85 TLS_TX_CLIENT_KEY_EXCHANGE
,
91 /** A TLS cipher specification */
92 struct tls_cipherspec
{
93 /** Public-key encryption algorithm */
94 struct pubkey_algorithm
*pubkey
;
95 /** Bulk encryption cipher algorithm */
96 struct cipher_algorithm
*cipher
;
97 /** MAC digest algorithm */
98 struct digest_algorithm
*digest
;
101 /** Dynamically-allocated storage */
103 /** Public key encryption context */
105 /** Bulk encryption cipher context */
107 /** Next bulk encryption cipher context (TX only) */
108 void *cipher_next_ctx
;
113 /** TLS pre-master secret */
114 struct tls_pre_master_secret
{
119 } __attribute__ (( packed
));
121 /** TLS client random data */
122 struct tls_client_random
{
124 uint32_t gmt_unix_time
;
127 } __attribute__ (( packed
));
131 /** Reference counter */
132 struct refcnt refcnt
;
134 /** Plaintext stream */
135 struct xfer_filter_half plainstream
;
136 /** Ciphertext stream */
137 struct xfer_filter_half cipherstream
;
139 /** Current TX cipher specification */
140 struct tls_cipherspec tx_cipherspec
;
141 /** Next TX cipher specification */
142 struct tls_cipherspec tx_cipherspec_pending
;
143 /** Current RX cipher specification */
144 struct tls_cipherspec rx_cipherspec
;
145 /** Next RX cipher specification */
146 struct tls_cipherspec rx_cipherspec_pending
;
147 /** Premaster secret */
148 struct tls_pre_master_secret pre_master_secret
;
150 uint8_t master_secret
[48];
151 /** Server random bytes */
152 uint8_t server_random
[32];
153 /** Client random bytes */
154 struct tls_client_random client_random
;
155 /** MD5 context for handshake verification */
156 uint8_t handshake_md5_ctx
[MD5_CTX_SIZE
];
157 /** SHA1 context for handshake verification */
158 uint8_t handshake_sha1_ctx
[SHA1_CTX_SIZE
];
160 /** Hack: server RSA public key */
161 struct x509_rsa_public_key rsa
;
163 /** TX sequence number */
166 enum tls_tx_state tx_state
;
168 struct process process
;
170 /** RX sequence number */
173 enum tls_rx_state rx_state
;
174 /** Offset within current RX state */
176 /** Current received record header */
177 struct tls_header rx_header
;
178 /** Current received raw data buffer */
182 extern int add_tls ( struct xfer_interface
*xfer
,
183 struct xfer_interface
**next
);
185 #endif /* _GPXE_TLS_H */