iPXE
channel.h
Go to the documentation of this file.
1#ifndef _IPXE_CHANNEL_H
2#define _IPXE_CHANNEL_H
3
4/** @file
5 *
6 * Secure channel abstraction
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <ipxe/crypto.h>
15#include <ipxe/x509.h>
16#include <ipxe/sha256.h>
17
18/** Ephemeral master secret digest algorithm */
19#define channel_ephemeral_algorithm sha256_algorithm
20
21/** Secure channel properties */
23 /** Channel contains key material derived from a shared secret */
24 int keyed;
25 /**
26 * Bound peer identity (if any)
27 *
28 * This is guaranteed to be set only if the "keyed" property
29 * is also set.
30 */
32 /**
33 * Confirmed peer identity (if any)
34 *
35 * This is guaranteed to be set only if the "bound" property
36 * is also set, and then to have the same value as the "bound"
37 * property.
38 */
40 /**
41 * Established peer identity (if any)
42 *
43 * This is guaranteed to be set only if the "confirmed"
44 * property is also set, and then to have the same value as
45 * both the "confirmed" and "bound" properties.
46 *
47 * If an established peer identity exists, then it is
48 * guaranteed that the channel may be used for confidential
49 * communication with the peer that was specified at the point
50 * that the channel was established as trusted.
51 */
53};
54
55/** A secure channel transmit or receive pipe */
57 /** Cipher algorithm */
59 /** Cipher context */
60 void *ctx;
61};
62
63/**
64 * A secure channel
65 *
66 * This is designed to be embedded within a containing structure that
67 * represents the consumer, such as a TLS connection.
68 *
69 * The containing structure must have been initialised to all zeros
70 * before use.
71 */
73 /** Channel operations */
75
76 /** Ephemeral master secret */
78 /** Security properties */
80
81 /** Transmit pipe */
83 /** Receive pipe */
85};
86
87/**
88 * A pre-shared bound peer identity
89 *
90 * This is designed to be embedded within a containing structure that
91 * also holds the pre-shared key material, such as a TLS session
92 * structure.
93 *
94 * The containing structure must have been initialised to all zeros
95 * before use.
96 */
98 /** Bound peer identity */
100};
101
102/** Secure channel operations */
104 /**
105 * Reset the key schedule
106 *
107 * @v channel Secure channel
108 *
109 * Return the key schedule to a freshly initialised state,
110 * with all key material destroyed.
111 *
112 * The consumer must leave the key schedule in a state that is
113 * ready to receive an initial shared secret.
114 *
115 * This method is used to clean up after errors and when the
116 * secure channel is closed. It may be invoked repeatedly,
117 * and may not fail.
118 */
119 void ( * reset ) ( struct secure_channel *channel );
120 /**
121 * Apply a new shared secret to key schedule
122 *
123 * @v channel Secure channel
124 * @v exchange Key exchange algorithm
125 * @v shared New shared secret
126 * @v accumulated Accumulation flag to fill in
127 * @ret rc Return status code
128 *
129 * Incorporate a new shared secret into the key schedule to
130 * produce the key material required to operate the channel
131 * (e.g. to subsequently derive traffic keys).
132 *
133 * If the resulting key material is cryptographically
134 * dependent upon all previously incorporated shared secrets
135 * as well as upon the new shared secret (as is the case with
136 * the HKDF-based key schedule used in TLS version 1.3), then
137 * this method may set the accumulation flag. If the key
138 * material depends solely upon the new shared secret (as is
139 * the case with the master secret computation in earlier
140 * versions of TLS), then the method must not set the
141 * accumulation flag.
142 *
143 * This method implicitly asserts to the secure channel that
144 * the ability of the peer to subsequently demonstrate
145 * possession of the resulting key material is sufficient to
146 * demonstrate the peer's possession of the new shared secret.
147 *
148 * Setting the accumulation flag asserts to the secure channel
149 * that the ability of the peer to demonstrate possession of
150 * the resulting key material is also sufficient to
151 * demonstrate the peer's possession of all previously
152 * incorporated shared secrets, and therefore that any peer
153 * identity that was already bound to the old shared secret
154 * remains bound to the new shared secret.
155 *
156 * Conversely, leaving the accumulation flag unset indicates
157 * to the secure channel that the ability of the peer to
158 * demonstrate possession of the resulting key material does
159 * not necessarily suffice to demonstrate possession of any
160 * previously incorporated shared secrets, and therefore that
161 * any peer identity that was bound to the old shared secret
162 * is not bound to the new shared secret.
163 *
164 * If this method does not set the accumulation flag, then the
165 * secure channel will therefore automatically unbind any
166 * stored peer identity that had previously been bound to the
167 * old shared secret.
168 *
169 * If this method returns an error, then the secure channel
170 * will be reset to a non-keyed state.
171 */
172 int ( * apply ) ( struct secure_channel *channel,
173 struct exchange_algorithm *exchange,
174 const void *shared, int *accumulated );
175 /**
176 * Save a pre-shared key for future resumption of the key schedule
177 *
178 * @v channel Secure channel
179 * @v psid Pre-shared bound peer identity
180 * @ret rc Return status code
181 *
182 * Save key material alongside an already bound peer identity,
183 * so that a future operation may resume the key schedule with
184 * the peer identity already bound to the key material.
185 *
186 * This method asserts to the secure channel that the ability
187 * of the peer to subsequently demonstrate possession of the
188 * future resumed key material is sufficient to demonstrate
189 * the peer's possession of the current key material.
190 *
191 * This method is optional if the consumer does not support
192 * resumption from a pre-shared key.
193 *
194 * If this method returns an error, then any existing
195 * pre-shared bound peer identity will be cleared.
196 */
197 int ( * save ) ( struct secure_channel *channel,
198 struct secure_preshared_identity *psid );
199 /**
200 * Load a pre-shared key and resume the key schedule
201 *
202 * @v channel Secure channel
203 * @v psid Pre-shared bound peer identity
204 * @ret rc Return status code
205 *
206 * Load key material that was previously saved alongside a
207 * bound peer identity.
208 *
209 * This method asserts to the secure channel that the ability
210 * of the peer to subsequently demonstrate possession of the
211 * resumed key material is sufficient to demonstrate the
212 * peer's possession of the originally saved key material.
213 *
214 * This method is optional if the consumer does not support
215 * resumption from a pre-shared key.
216 *
217 * If this method returns an error, then the secure channel
218 * will be reset to a non-keyed state.
219 */
220 int ( * load ) ( struct secure_channel *channel,
221 struct secure_preshared_identity *psid );
222 /**
223 * Verify authenticator value
224 *
225 * @v channel Secure channel
226 * @v auth Authenticator value
227 * @v len Length of authenticator value
228 * @ret rc Return status code
229 *
230 * Verify that the peer has demonstrated possession of the key
231 * material (and hence has demonstrated possession of the
232 * identity-bound shared secret).
233 *
234 * This method asserts to the secure channel that the
235 * authenticator value is guaranteed to be non-replayable
236 * (e.g. by being constructed as a digest that covers a
237 * challenge nonce, as with the TLS Finished verification data
238 * which covers the client random bytes within the handshake
239 * transcript).
240 *
241 * If this method returns an error, then the secure channel
242 * will be left in a non-confirmed state.
243 */
244 int ( * verify ) ( struct secure_channel *channel,
245 const void *auth, size_t len );
246};
247
249
250/**
251 * Initialise secure channel
252 *
253 * @v channel Secure channel
254 * @v op Channel operations
255 */
256static inline void channel_init ( struct secure_channel *channel,
257 struct secure_channel_operations *op ) {
258
259 channel->op = op;
260 channel->tx.cipher = &channel_dead_cipher;
261 channel->rx.cipher = &channel_dead_cipher;
262}
263
264/**
265 * Check if secure channel has been established
266 *
267 * @v channel Secure channel
268 * @ret is_established Channel has been established
269 */
270static inline __attribute__ (( always_inline )) int
272
273 return ( channel->props.established != NULL );
274}
275
276/**
277 * Clear pre-shared bound peer identity
278 *
279 * @v psid Pre-shared identity
280 */
281static inline __attribute__ (( always_inline )) void
283
284 x509_put ( psid->bound );
285 psid->bound = NULL;
286}
287
288extern void channel_ephemeral ( struct secure_channel *channel,
289 const void *info, size_t info_len,
290 void *out, size_t len );
292 const char *label, void *out,
293 size_t len );
294extern void channel_unkey ( struct secure_channel *channel );
295extern int channel_key_share ( struct secure_channel *channel,
296 struct exchange_algorithm *exchange,
297 void *public );
298extern int channel_key_agree ( struct secure_channel *channel,
299 struct exchange_algorithm *exchange,
300 const void *partner );
301extern int channel_bind_verify ( struct secure_channel *channel,
302 struct x509_certificate *identity,
303 struct pubkey_algorithm *pubkey,
304 struct digest_algorithm *digest,
305 const void *value,
306 const struct asn1_cursor *signature );
307extern int channel_bind_encrypt ( struct secure_channel *channel,
308 struct x509_certificate *identity,
309 struct exchange_algorithm *exchange,
310 struct pubkey_algorithm *pubkey,
311 struct asn1_builder *ciphertext );
312extern int channel_save ( struct secure_channel *channel,
313 struct secure_preshared_identity *psid );
314extern int channel_load ( struct secure_channel *channel,
315 struct secure_preshared_identity *psid );
316extern int channel_confirm ( struct secure_channel *channel,
317 const void *auth, size_t len );
318extern int channel_establish ( struct secure_channel *channel,
319 const char *name, struct x509_root *root );
320extern int channel_set_cipher ( struct secure_channel *channel,
321 struct secure_pipe *pipe,
322 struct cipher_algorithm *cipher,
323 const void *key, size_t len );
324extern int channel_open ( struct secure_channel *channel );
325extern void channel_reopen ( struct secure_channel *channel );
326extern void channel_close ( struct secure_channel *channel );
327
328#endif /* _IPXE_CHANNEL_H */
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
__be32 out[4]
Definition CIB_PRM.h:8
u8 signature
CPU signature.
Definition CIB_PRM.h:7
union @162305117151260234136356364136041353210355154177 key
#define SHA256_DIGEST_SIZE
Definition Tpm20.h:29
u32 info
Definition ar9003_mac.h:0
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned char uint8_t
Definition stdint.h:10
const char * name
Definition ath9k_hw.c:1986
struct cipher_algorithm channel_dead_cipher
Dead cipher.
Definition channel.c:1073
int channel_set_cipher(struct secure_channel *channel, struct secure_pipe *pipe, struct cipher_algorithm *cipher, const void *key, size_t len)
Set cipher algorithm and key.
Definition channel.c:1136
void channel_reopen(struct secure_channel *channel)
Reopen secure channel.
Definition channel.c:1269
int channel_bind_encrypt(struct secure_channel *channel, struct x509_certificate *identity, struct exchange_algorithm *exchange, struct pubkey_algorithm *pubkey, struct asn1_builder *ciphertext)
Bind peer identity via shared secret encryption.
Definition channel.c:648
void channel_ephemeral(struct secure_channel *channel, const void *info, size_t info_len, void *out, size_t len)
Generate ephemeral secret.
Definition channel.c:195
void channel_unkey(struct secure_channel *channel)
Clear shared secret.
Definition channel.c:273
int channel_key_agree(struct secure_channel *channel, struct exchange_algorithm *exchange, const void *partner)
Agree shared secret.
Definition channel.c:424
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
int channel_bind_verify(struct secure_channel *channel, struct x509_certificate *identity, struct pubkey_algorithm *pubkey, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature)
Bind peer identity via ephemeral public key signature verification.
Definition channel.c:611
int channel_establish(struct secure_channel *channel, const char *name, struct x509_root *root)
Establish channel as trusted for application data.
Definition channel.c:986
int channel_save(struct secure_channel *channel, struct secure_preshared_identity *psid)
Save a pre-shared key.
Definition channel.c:738
int channel_confirm(struct secure_channel *channel, const void *auth, size_t len)
Confirm peer identity.
Definition channel.c:896
static void channel_clear_preshared(struct secure_preshared_identity *psid)
Clear pre-shared bound peer identity.
Definition channel.h:282
int channel_key_share(struct secure_channel *channel, struct exchange_algorithm *exchange, void *public)
Share public key.
Definition channel.c:320
static int channel_is_established(struct secure_channel *channel)
Check if secure channel has been established.
Definition channel.h:271
void channel_ephemeral_label(struct secure_channel *channel, const char *label, void *out, size_t len)
Generate labelled ephemeral secret.
Definition channel.c:215
int channel_load(struct secure_channel *channel, struct secure_preshared_identity *psid)
Load a pre-shared key.
Definition channel.c:783
ring len
Length.
Definition dwmac.h:226
struct eth_slow_lacp_entity_tlv partner
Partner information.
Definition eth_slow.h:5
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
uint8_t info_len
Reject information length.
Definition ib_mad.h:7
#define __attribute__(x)
Definition compiler.h:10
Cryptographic API.
uint32_t channel
RNDIS channel.
Definition netvsc.h:3
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
SHA-256 algorithm.
struct stp_switch root
Root switch.
Definition stp.h:15
An ASN.1 object builder.
Definition asn1.h:29
An ASN.1 object cursor.
Definition asn1.h:21
A cipher algorithm.
Definition crypto.h:58
void(* auth)(struct cipher_algorithm *cipher, void *ctx, void *auth)
Generate authentication tag.
Definition crypto.h:135
A message digest algorithm.
Definition crypto.h:19
A key exchange algorithm.
Definition crypto.h:210
A text label widget.
Definition label.h:16
A public key algorithm.
Definition crypto.h:142
Secure channel operations.
Definition channel.h:103
void(* reset)(struct secure_channel *channel)
Reset the key schedule.
Definition channel.h:119
int(* apply)(struct secure_channel *channel, struct exchange_algorithm *exchange, const void *shared, int *accumulated)
Apply a new shared secret to key schedule.
Definition channel.h:172
int(* verify)(struct secure_channel *channel, const void *auth, size_t len)
Verify authenticator value.
Definition channel.h:244
int(* load)(struct secure_channel *channel, struct secure_preshared_identity *psid)
Load a pre-shared key and resume the key schedule.
Definition channel.h:220
int(* save)(struct secure_channel *channel, struct secure_preshared_identity *psid)
Save a pre-shared key for future resumption of the key schedule.
Definition channel.h:197
Secure channel properties.
Definition channel.h:22
struct x509_certificate * confirmed
Confirmed peer identity (if any).
Definition channel.h:39
struct x509_certificate * bound
Bound peer identity (if any).
Definition channel.h:31
struct x509_certificate * established
Established peer identity (if any).
Definition channel.h:52
int keyed
Channel contains key material derived from a shared secret.
Definition channel.h:24
A secure channel.
Definition channel.h:72
struct secure_pipe tx
Transmit pipe.
Definition channel.h:82
struct secure_channel_properties props
Security properties.
Definition channel.h:79
struct secure_pipe rx
Receive pipe.
Definition channel.h:84
struct secure_channel_operations * op
Channel operations.
Definition channel.h:74
uint8_t ephemeral[SHA256_DIGEST_SIZE]
Ephemeral master secret.
Definition channel.h:77
A secure channel transmit or receive pipe.
Definition channel.h:56
void * ctx
Cipher context.
Definition channel.h:60
struct cipher_algorithm * cipher
Cipher algorithm.
Definition channel.h:58
A pre-shared bound peer identity.
Definition channel.h:97
struct x509_certificate * bound
Bound peer identity.
Definition channel.h:99
An X.509 certificate.
Definition x509.h:216
An X.509 root certificate list.
Definition x509.h:375
X.509 certificates.
static void x509_put(struct x509_certificate *cert)
Drop reference to X.509 certificate.
Definition x509.h:278