iPXE
channel.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27#include <string.h>
28#include <errno.h>
29#include <ipxe/malloc.h>
30#include <ipxe/crypto.h>
31#include <ipxe/hkdf.h>
32#include <ipxe/rbg.h>
33#include <ipxe/channel.h>
34
35/** @file
36 *
37 * Secure channel abstraction
38 *
39 * We define a concept of a secure channel as comprising a pair of
40 * ciphers (one for transmit, one for receive) together with the
41 * cryptographic state required to establish that these ciphers may be
42 * used for encrypted communication with a trusted peer. The model is
43 * loosely constructed as a generalisation of TLS minus the protocol
44 * specifics.
45 *
46 * The channel starts out with both ciphers operating in plaintext
47 * mode. Over this initially unencrypted channel, a shared secret is
48 * agreed, bound to a peer identity, and used to derive keys for the
49 * transmit and receive ciphers.
50 *
51 * The major channel operations are:
52 *
53 * - Key exchange: a shared secret is agreed (e.g. via Ephemeral
54 * Diffie-Hellman key exchange)
55 *
56 * - Key binding: the shared secret is bound to a peer identity
57 * (i.e. to a long-term public key as recorded in an X.509
58 * certificate)
59 *
60 * - Key derivation: the transmit and receive cipher keys are
61 * derived from the shared secret
62 *
63 * - Key confirmation: the peer demonstrates possession of the
64 * identity-bound shared secret
65 *
66 * - Identity validation: the long-term public key representing the
67 * peer identity is validated as being trusted and as matching the
68 * required identity (e.g. a TLS host name)
69 *
70 * The channel maintains the following security properties:
71 *
72 * - "keyed": a boolean flag indicating that the channel contains
73 * key material derived from the shared secret
74 *
75 * - "bound": a certificate reference representing the peer identity
76 * to which the shared secret has been bound
77 *
78 * - "confirmed": a certificate reference representing the peer
79 * identity that has demonstrated possession of the identity-bound
80 * shared secret
81 *
82 * - "established": a certificate reference representing the peer
83 * identity that has demonstrated possession of the identity-bound
84 * shared secret and has been verified as valid
85 *
86 * The peer identities are stored as references to X.509 certificates.
87 * The secure channel conceptual model is agnostic about how peer
88 * identities may be represented, but X.509 certificates are most
89 * convenient for use within iPXE. Validation of the certificate
90 * chain is outside the scope of the secure channel and must be
91 * performed separately.
92 *
93 * When the channel has a "confirmed" certificate reference and that
94 * certificate has separately been marked as valid, the secure channel
95 * may become established and may subsequently be used to transmit and
96 * receive application data.
97 *
98 * The channel is a passive entity: it does not itself initiate any
99 * messages. All communication is driven by the consumer (such as the
100 * TLS protocol). The set of operations described above that are used
101 * to establish a secure channel must be performed by the consumer
102 * according to its protocol definition.
103 *
104 * The order of these operations may vary based upon both the protocol
105 * definition and the options negotiated at runtime with the peer.
106 * The secure channel abstraction is responsible for maintaining the
107 * listed security properties and determining whether or not the
108 * required security conditions have been met, regardless of the order
109 * in which operations are performed by the consumer.
110 *
111 */
112
113/* Disambiguate the various error causes */
114#define ENOTTY_TRANSPORT __einfo_error ( EINFO_ENOTTY_TRANSPORT )
115#define EINFO_ENOTTY_TRANSPORT \
116 __einfo_uniqify ( EINFO_ENOTTY, 0x01, "Untransportable key" )
117#define EPERM_NOT_CONFIDENTIAL __einfo_error ( EINFO_EPERM_NOT_CONFIDENTIAL )
118#define EINFO_EPERM_NOT_CONFIDENTIAL \
119 __einfo_uniqify ( EINFO_EPERM, 0x01, "Not confidential" )
120#define EPERM_NOT_VALID __einfo_error ( EINFO_EPERM_NOT_VALID )
121#define EINFO_EPERM_NOT_VALID \
122 __einfo_uniqify ( EINFO_EPERM, 0x02, "Peer certificate not valid" )
123#define EPROTO_NOT_KEYED __einfo_error ( EINFO_EPROTO_NOT_KEYED )
124#define EINFO_EPROTO_NOT_KEYED \
125 __einfo_uniqify ( EINFO_EPROTO, 0x01, "No shared key material" )
126#define EPROTO_NOT_BOUND __einfo_error ( EINFO_EPROTO_NOT_BOUND )
127#define EINFO_EPROTO_NOT_BOUND \
128 __einfo_uniqify ( EINFO_EPROTO, 0x02, "No bound peer identity" )
129#define EPROTO_NOT_CONFIRMED __einfo_error ( EINFO_EPROTO_NOT_CONFIRMED )
130#define EINFO_EPROTO_NOT_CONFIRMED \
131 __einfo_uniqify ( EINFO_EPROTO, 0x03, "No confirmed peer identity" )
132
133static void channel_unbind ( struct secure_channel *channel );
134static void channel_unconfirm ( struct secure_channel *channel );
135static void channel_unestablish ( struct secure_channel *channel );
136
137/*****************************************************************************
138 *
139 * Ephemeral secrets
140 *
141 *****************************************************************************
142 *
143 * The channel maintains a single ephemeral master secret that can be
144 * used to derive an arbitrary number of other ephemeral secrets
145 * (e.g. for Diffie-Hellman key exchange).
146 *
147 * The use of a single ephemeral master secret avoids the need for key
148 * exchange mechanisms to retain individual copies of their ephemeral
149 * private keys, since those private keys can always be regenerated on
150 * demand.
151 *
152 * The ephemeral secret mechanism may also be used to derive other
153 * temporary secrets that may be required by the consumer (e.g. TLS
154 * client random data, or block cipher initialisation vectors).
155 *
156 */
157
158/**
159 * Initialise ephemeral master secret
160 *
161 * @v channel Secure channel
162 * @ret rc Return status code
163 */
166 static const char salt[16] = "channel master";
167 int rc;
168
169 /* Generate random bits with no additional input and without
170 * prediction resistance
171 */
172 if ( ( rc = rbg_generate ( NULL, 0, 0, channel->ephemeral,
173 sizeof ( channel->ephemeral ) ) ) != 0 ) {
174 DBGC ( channel, "CHANNEL %p could not generate random data: "
175 "%s\n", channel, strerror ( rc ) );
176 return rc;
177 }
178
179 /* Generate ephemeral master secret */
180 hkdf_extract ( digest, salt, sizeof ( salt ), channel->ephemeral,
181 sizeof ( channel->ephemeral ), channel->ephemeral );
182
183 return 0;
184}
185
186/**
187 * Generate ephemeral secret
188 *
189 * @v channel Secure channel
190 * @v info Additional information
191 * @v info_len Length of additional information
192 * @v out Ephemeral secret to fill in
193 * @v len Length of ephemeral secret
194 */
195void channel_ephemeral ( struct secure_channel *channel, const void *info,
196 size_t info_len, void *out, size_t len ) {
198
199 /* Additional info should always be provided */
200 assert ( info != NULL );
201 assert ( info_len > 0 );
202
203 /* Generate from ephemeral master secret and additional information */
204 hkdf_expand ( digest, channel->ephemeral, info, info_len, out, len );
205}
206
207/**
208 * Generate labelled ephemeral secret
209 *
210 * @v channel Secure channel
211 * @v label Additional information string
212 * @v out Ephemeral secret to fill in
213 * @v len Length of ephemeral secret
214 */
216 const char *label, void *out, size_t len ) {
217
218 /* Generate from ephemeral master secret and label */
220 DBGC2 ( channel, "CHANNEL %p ephemeral \"%s\":\n", channel, label );
221 DBGC2_HDA ( channel, 0, out, len );
222}
223
224/**
225 * Replace ephemeral master secret
226 *
227 * @v channel Secure channel
228 */
230
231 /* Generate a new ephemeral master key */
232 channel_ephemeral_label ( channel, "channel replace",
233 channel->ephemeral,
234 sizeof ( channel->ephemeral ) );
235}
236
237/*****************************************************************************
238 *
239 * Key exchange
240 *
241 *****************************************************************************
242 *
243 * Key exchange (or key transport) is used over the as-yet unencrypted
244 * channel to obtain a shared secret (e.g. a TLS pre-master secret
245 * obtained using ECDHE). The shared secret is then used to derive
246 * the channel key material (e.g. a TLS master secret).
247 *
248 * The channel is responsible for generating the ephemeral private
249 * keys (and the corresponding public keys), and for handling the
250 * underlying mechanics of the key exchange algorithm to obtain a
251 * shared secret.
252 *
253 * The consumer is responsible for incorporating the resulting shared
254 * secret into its key schedule to produce the key material required
255 * by the consumer to operate the channel (e.g. to derive traffic
256 * keys).
257 *
258 * The channel does not itself dictate how the key material is
259 * produced, since the key schedule is necessarily defined by the
260 * protocol in use (e.g. TLS).
261 *
262 * Key exchange alone provides no authentication of the peer. Key
263 * binding (see below) must be used to bind the shared secret to a
264 * peer identity.
265 *
266 */
267
268/**
269 * Clear shared secret
270 *
271 * @v channel Secure channel
272 */
274
275 /* Key binding is defined only for the current shared secret,
276 * and so any existing bound peer identity must be cleared.
277 */
279
280 /* Clear shared key */
281 channel->props.keyed = 0;
282
283 /* Reset the key schedule */
284 channel->op->reset ( channel );
285}
286
287/**
288 * Generate private key
289 *
290 * @v channel Secure channel
291 * @v exchange Key exchange algorithm
292 * @v private Private key to fill in
293 */
295 struct exchange_algorithm *exchange,
296 void *private ) {
297 size_t privsize = exchange->privsize;
298 const char *label;
299
300 /* Use exchange algorithm name as additional information */
301 label = exchange->name;
302
303 /* (Re)generate private key
304 *
305 * Note that key exchange private keys are always small enough
306 * to fit on the stack, even for algorithms such as FFDHE that
307 * have large public and shared keys.
308 */
309 channel_ephemeral_label ( channel, label, private, privsize );
310}
311
312/**
313 * Share public key
314 *
315 * @v channel Secure channel
316 * @v exchange Key exchange algorithm
317 * @v public Public key to fill in
318 * @ret rc Return status code
319 */
321 struct exchange_algorithm *exchange, void *public ) {
322 size_t privsize = exchange->privsize;
323 size_t pubsize = exchange->pubsize;
324 uint8_t private[privsize];
325 int rc;
326
327 /* (Re)generate private key */
328 channel_key_private ( channel, exchange, private );
329
330 /* Generate public key */
331 if ( ( rc = exchange_share ( exchange, private, public ) ) != 0 ) {
332 DBGC ( channel, "CHANNEL %p could not share \"%s\": %s\n",
333 channel, exchange->name, strerror ( rc ) );
334 goto err_share;
335 }
336
337 /* Show public key (for debugging) */
338 DBGC2 ( channel, "CHANNEL %p sharing \"%s\":\n",
339 channel, exchange->name );
340 DBGC2_HDA ( channel, 0, public, pubsize );
341
342 err_share:
343 /* Erase private key */
344 memset ( private, 0, sizeof ( private ) );
345 return rc;
346}
347
348/**
349 * Generate and apply shared secret
350 *
351 * @v channel Secure channel
352 * @v exchange Key exchange algorithm
353 * @v partner Partner public key
354 * @v shared Shared secret to fill in
355 * @ret rc Return status code
356 */
357static int channel_key ( struct secure_channel *channel,
358 struct exchange_algorithm *exchange,
359 const void *partner, void *shared ) {
360 size_t sharedsize = exchange->sharedsize;
361 size_t privsize = exchange->privsize;
362 uint8_t private[privsize];
363 int accumulated;
364 int rc;
365
366 /* (Re)generate private key */
367 channel_key_private ( channel, exchange, private );
368
369 /* Generate shared secret */
370 if ( ( rc = exchange_agree ( exchange, private, partner,
371 shared ) ) != 0 ) {
372 DBGC ( channel, "CHANNEL %p could not agree \"%s\": %s\n",
373 channel, exchange->name, strerror ( rc ) );
374 goto err_agree;
375 }
376
377 /* Show shared secret (for debugging) */
378 DBGC2 ( channel, "CHANNEL %p agreed \"%s\":\n",
379 channel, exchange->name );
380 DBGC2_HDA ( channel, 0, shared, sharedsize );
381
382 /* Apply shared secret to key schedule */
383 accumulated = 0;
384 if ( ( rc = channel->op->apply ( channel, exchange, shared,
385 &accumulated ) ) != 0 ) {
386 DBGC ( channel, "CHANNEL %p could not apply \"%s\": %s\n",
387 channel, exchange->name, strerror ( rc ) );
388 goto err_apply;
389 }
390
391 /* If the accumulation flag was not set, then the ability of
392 * the peer to subsequently demonstrate possession of the key
393 * material suffices to demonstrate possession of this shared
394 * secret, but does not necessarily suffice to demonstrate
395 * possession of any previously applied shared secrets. Any
396 * binding of the peer identity is therefore no longer valid.
397 */
398 if ( ! accumulated )
400
401 /* Channel now possesses a shared secret */
402 channel->props.keyed = 1;
403 DBGC ( channel, "CHANNEL %p key material obtained via \"%s\"\n",
404 channel, exchange->name );
405
406 err_apply:
407 err_agree:
408 /* Clear generated shared secret on any error */
409 if ( rc != 0 )
411 /* Erase private key */
412 memset ( private, 0, sizeof ( private ) );
413 return rc;
414}
415
416/**
417 * Agree shared secret
418 *
419 * @v channel Secure channel
420 * @v exchange Key exchange algorithm
421 * @v partner Partner public key
422 * @ret rc Return status code
423 */
425 struct exchange_algorithm *exchange,
426 const void *partner ) {
427 size_t sharedsize = exchange->sharedsize;
428 size_t pubsize = exchange->pubsize;
429 void *tmp;
430 int rc;
431
432 /* Show partner public key (for debugging) */
433 DBGC2 ( channel, "CHANNEL %p partner \"%s\":\n",
434 channel, exchange->name );
435 DBGC2_HDA ( channel, 0, partner, pubsize );
436
437 /* Allocate space for shared secret (may be too large for stack) */
438 tmp = zalloc ( sharedsize );
439 if ( ! tmp ) {
440 rc = -ENOMEM;
441 goto err_alloc;
442 }
443
444 /* Generate and apply shared secret */
445 if ( ( rc = channel_key ( channel, exchange, partner, tmp ) ) != 0 )
446 goto err_key;
447
448 err_key:
449 /* Erase shared secret */
450 zfree ( tmp );
451 err_alloc:
452 return rc;
453}
454
455/**
456 * Transport shared secret
457 *
458 * @v channel Secure channel
459 * @v exchange Key exchange algorithm
460 * @v shared Shared secret to fill in
461 * @ret rc Return status code
462 *
463 * Key transport is modelled as a key exchange algorithm with a public
464 * key size of zero: the shared secret is unilaterally generated by
465 * the local endpoint and must then be transported to the peer.
466 */
468 struct exchange_algorithm *exchange,
469 void *shared ) {
470 int rc;
471
472 /* Sanity check */
473 if ( ! is_key_transport ( exchange ) ) {
474 DBGC ( channel, "CHANNEL %p cannot transport \"%s\"\n",
475 channel, exchange->name );
476 return -ENOTTY_TRANSPORT;
477 }
478
479 /* Generate and apply shared secret */
480 if ( ( rc = channel_key ( channel, exchange, NULL, shared ) ) != 0 )
481 return rc;
482
483 return 0;
484}
485
486/*****************************************************************************
487 *
488 * Key binding
489 *
490 *****************************************************************************
491 *
492 * The shared secret that results from key exchange must be bound to a
493 * peer identity. This binding represents a delegation of authority
494 * from the peer's long-term authentication key (e.g. the RSA private
495 * key corresponding to its X.509 certificate) to the shared secret
496 * for the purpose of authenticating the channel by subsequently
497 * confirming possession of the shared secret.
498 *
499 * There are two distinct mechanisms through which this delegation may
500 * take place:
501 *
502 * - If the shared secret is obtained using key exchange, then the
503 * peer may delegate authority to the shared secret by using its
504 * long-term authentication key to sign a digest that covers at
505 * least its own ephemeral public key (e.g. the Diffie-Hellman
506 * parameters provided in a ServerKeyExchange record) and a
507 * challenge nonce (e.g. the TLS client random bytes). The
508 * signature over its public ephemeral key represents a choice by
509 * the peer to allow possession of the corresponding ephemeral
510 * private key to be used to demonstrate authenticity of the
511 * channel. The local endpoint trusts the peer's long-term
512 * identity to make this class of choice, and verifies the
513 * signature to authenticate that the peer's long-term identity
514 * made this choice. The possession of the ephemeral private key
515 * is subsequently demonstrated by key confirmation, which
516 * demonstrates possession of the shared secret (and hence of the
517 * ephemeral private key used to obtain the shared secret).
518 *
519 * - If the shared secret is obtained using key transport, then the
520 * local endpoint may delegate authority to the shared secret by
521 * encrypting the unilaterally chosen shared secret using the
522 * peer's long-term authentication key. The encryption represents
523 * a choice by the local endpoint to allow possession of the
524 * shared secret (as subsequently demonstrated by key
525 * confirmation) to be used as evidence of possession of the
526 * peer's long-term authentication key.
527 *
528 * In both cases, the end result is the same: the shared secret
529 * (whether exchanged or transported) may be relied upon to
530 * authenticate the channel as being connected to the peer.
531 *
532 * The shared secret may be bound to an identity that has not yet been
533 * validated. The consumer is responsible for separately performing
534 * validation of the identity (e.g. validation of the full X.509
535 * certificate chain, including OCSP checks) at some point before
536 * relying upon the channel to protect application data.
537 *
538 */
539
540/**
541 * Clear bound peer identity
542 *
543 * @v channel Secure channel
544 */
545static void channel_unbind ( struct secure_channel *channel ) {
546
547 /* Key confirmation is defined only for the currently bound
548 * identity, and so any existing confirmed peer identity must
549 * be cleared.
550 */
552
553 /* Drop and clear reference */
554 x509_put ( channel->props.bound );
555 channel->props.bound = NULL;
556}
557
558/**
559 * Set bound peer identity
560 *
561 * @v channel Secure channel
562 * @v identity Identity to be bound
563 * @ret rc Return status code
564 */
566 struct x509_certificate *identity ) {
567
568 /* Clear any existing binding */
570
571 /* Fail if there is no shared secret to be bound */
572 if ( ! channel->props.keyed ) {
573 DBGC ( channel, "CHANNEL %p cannot bind to empty key\n",
574 channel );
575 return -EPROTO_NOT_KEYED;
576 }
577
578 /* Record bound peer identity */
579 channel->props.bound = x509_get ( identity );
580 DBGC ( channel, "CHANNEL %p key material bound to \"%s\"\n",
581 channel, x509_name ( identity ) );
582
583 return 0;
584}
585
586/**
587 * Bind peer identity via ephemeral public key signature verification
588 *
589 * @v channel Secure channel
590 * @v identity Identity to be bound
591 * @v pubkey Public-key algorithm
592 * @v digest Digest algorithm
593 * @v value Digest value (must cover peer's ephemeral public key)
594 * @v signature Signature
595 * @ret rc Return status code
596 *
597 * The peer may delegate authority to the shared secret by signing a
598 * digest that covers at least its own ephemeral public key (e.g. the
599 * Diffie-Hellman parameters provided in a ServerKeyExchange record)
600 * and a challenge nonce (e.g. the TLS client random bytes).
601 *
602 * The consumer asserts to the secure channel that the digest covers
603 * at least the peer's ephemeral public key and a nonce. The digest
604 * may cover arbitrary additional information (e.g. the entire
605 * transcript hash as signed by a CertificateVerify record).
606 *
607 * This assertion is an unverifiable promise made by the consumer:
608 * there is no way for the secure channel itself to determine what is
609 * covered by the digest.
610 */
612 struct x509_certificate *identity,
613 struct pubkey_algorithm *pubkey,
614 struct digest_algorithm *digest, const void *value,
615 const struct asn1_cursor *signature ) {
616 const struct asn1_cursor *key = &identity->subject.public_key.raw;
617 int rc;
618
619 /* Verify signature */
620 if ( ( rc = pubkey_verify ( pubkey, key, digest, value,
621 signature ) ) != 0 ) {
622 DBGC ( channel, "CHANNEL %p could not verify binding: %s\n",
623 channel, strerror ( rc ) );
624 return rc;
625 }
626
627 /* Bind to the identity that signed the shared secret */
628 if ( ( rc = channel_bind ( channel, identity ) ) != 0 )
629 return rc;
630
631 return 0;
632}
633
634/**
635 * Bind peer identity via shared secret encryption
636 *
637 * @v channel Secure channel
638 * @v identity Identity to be bound
639 * @v exchange Key exchange algorithm
640 * @v pubkey Public-key algorithm
641 * @v ciphertext Encrypted shared secret
642 * @ret rc Return status code
643 *
644 * The local endpoint may delegate authority to the shared secret by
645 * encrypting a unilaterally chosen shared secret (e.g. a classic TLS
646 * static RSA pre-master secret).
647 */
649 struct x509_certificate *identity,
650 struct exchange_algorithm *exchange,
651 struct pubkey_algorithm *pubkey,
652 struct asn1_builder *ciphertext ) {
653 const struct asn1_cursor *key = &identity->subject.public_key.raw;
654 size_t sharedsize = exchange->sharedsize;
655 struct asn1_cursor plaintext;
656 void *tmp;
657 int rc;
658
659 /* Allocate space for shared secret (may be too large for stack) */
660 tmp = zalloc ( sharedsize );
661 if ( ! tmp ) {
662 rc = -ENOMEM;
663 goto err_alloc;
664 }
665 plaintext.data = tmp;
666 plaintext.len = sharedsize;
667
668 /* Generate unencrypted shared secret */
669 if ( ( rc = channel_key_transport ( channel, exchange, tmp ) ) != 0 )
670 goto err_transport;
671
672 /* Encrypt shared secret */
673 if ( ( rc = pubkey_encrypt ( pubkey, key, &plaintext,
674 ciphertext ) ) != 0 ) {
675 DBGC ( channel, "CHANNEL %p could not encrypt \"%s\": %s\n",
676 channel, exchange->name, strerror ( rc ) );
677 goto err_encrypt;
678 }
679
680 /* Bind to the identity that can decrypt the shared secret */
681 if ( ( rc = channel_bind ( channel, identity ) ) != 0 )
682 goto err_bind;
683
684 err_bind:
685 err_encrypt:
686 err_transport:
687 /* Clear the generated shared secret on any error */
688 if ( rc != 0 )
690 /* Erase unencrypted shared secret */
691 zfree ( tmp );
692 err_alloc:
693 return rc;
694}
695
696/*****************************************************************************
697 *
698 * Pre-shared keys
699 *
700 *****************************************************************************
701 *
702 * Once a shared secret has been bound to a peer identity, it may be
703 * saved as a pre-shared key alongside the bound peer identity. A
704 * future secure channel may resume the key schedule from this
705 * pre-shared and already bound key.
706 *
707 * The consumer is responsible for ensuring that the ability to
708 * demonstrate possession of the key material after resumption implies
709 * possession of the key material that was previously saved (and so
710 * implies possession of the original shared secret).
711 *
712 * The consumer may choose to save a pre-shared key at any point after
713 * the peer identity has been bound. A successful resumption will
714 * restore the previously bound peer identity but will clear the
715 * confirmed and established peer identities.
716 *
717 * Key confirmation to demonstrate possession of the key material is
718 * still required after resuming a secure channel from a pre-shared
719 * key.
720 *
721 * The establishment check is also still required after resuming a
722 * secure channel from a pre-shared key. It is technically possible
723 * (though unlikely in practice) for the establishment check to use a
724 * new required peer identity name or root of trust.
725 *
726 * Support for pre-shared keys is optional. The consumer may choose
727 * not to support the use of pre-shared keys.
728 *
729 */
730
731/**
732 * Save a pre-shared key
733 *
734 * @v channel Secure channel
735 * @v psid Pre-shared bound peer identity
736 * @ret rc Return status code
737 */
739 struct secure_preshared_identity *psid ) {
740 struct x509_certificate *identity;
741 int rc;
742
743 /* Clear any existing pre-shared bound peer identity */
745
746 /* Fail if there is no bound peer identity to save */
747 identity = channel->props.bound;
748 if ( ! identity ) {
749 DBGC ( channel, "CHANNEL %p cannot create pre-shared key "
750 "for unbound peer\n", channel );
751 return -EPROTO_NOT_BOUND;
752 }
753
754 /* Fail if consumer does not support pre-shared keys */
755 if ( ! channel->op->save ) {
756 DBGC ( channel, "CHANNEL %p does not support pre-shared "
757 "keys\n", channel );
758 return -ENOTSUP;
759 }
760
761 /* Save pre-shared key */
762 if ( ( rc = channel->op->save ( channel, psid ) ) != 0 ) {
763 DBGC ( channel, "CHANNEL %p could not save pre-shared "
764 "key: %s\n", channel, strerror ( rc ) );
765 return rc;
766 }
767
768 /* Record pre-shared bound peer identity */
769 psid->bound = x509_get ( identity );
770 DBGC ( channel, "CHANNEL %p key material saved for \"%s\"\n",
771 channel, x509_name ( identity ) );
772
773 return 0;
774}
775
776/**
777 * Load a pre-shared key
778 *
779 * @v channel Secure channel
780 * @v psid Pre-shared bound peer identity
781 * @ret rc Return status code
782 */
784 struct secure_preshared_identity *psid ) {
785 struct x509_certificate *identity;
786 int rc;
787
788 /* Clear any existing shared secret */
790
791 /* Fail if there is no bound peer identity to resume */
792 identity = psid->bound;
793 if ( ! identity ) {
794 DBGC ( channel, "CHANNEL %p cannot resume from empty "
795 "pre-shared key\n", channel );
797 goto err_empty;
798 }
799
800 /* Fail if consumer does not support pre-shared keys */
801 if ( ! channel->op->load ) {
802 DBGC ( channel, "CHANNEL %p does not support pre-shared "
803 "keys\n", channel );
804 rc = -ENOTSUP;
805 goto err_unsupported;
806 }
807
808 /* Load pre-shared key */
809 if ( ( rc = channel->op->load ( channel, psid ) ) != 0 ) {
810 DBGC ( channel, "CHANNEL %p could not load pre-shared key: "
811 "%s\n", channel, strerror ( rc ) );
812 goto err_load;
813 }
814
815 /* Channel now possesses a shared secret */
816 channel->props.keyed = 1;
817 DBGC ( channel, "CHANNEL %p key material obtained from pre-shared "
818 "key\n", channel );
819
820 /* Bind to the identity that was bound to the pre-shared key */
821 if ( ( rc = channel_bind ( channel, identity ) ) != 0 )
822 goto err_bind;
823
824 return 0;
825
826 err_bind:
827 err_load:
828 err_unsupported:
829 err_empty:
831 return rc;
832}
833
834/*****************************************************************************
835 *
836 * Key confirmation
837 *
838 *****************************************************************************
839 *
840 * The peer must authenticate the channel by demonstrating its
841 * possession of the current key material that was derived from the
842 * identity-bound shared secret in accordance with the key schedule.
843 *
844 * The peer may demonstrate its possession of the key material by
845 * constructing and sending an authenticator value that can be
846 * successfully verified by the local endpoint using the same key
847 * material.
848 *
849 * The receive pipe must already have transitioned to a cipher capable
850 * of providing confidentiality before the authenticator value is
851 * received, so that the authentication of the channel meaningfully
852 * endures beyond the receipt of the authenticator value itself.
853 *
854 * The key may be confirmed for an identity that has not yet been
855 * validated. The consumer is responsible for separately performing
856 * validation of the identity (e.g. validation of the full X.509
857 * certificate chain, including OCSP checks) at some point before
858 * relying upon the channel to protect application data.
859 *
860 */
861
862/**
863 * Clear confirmed peer identity
864 *
865 * @v channel Secure channel
866 */
867static void channel_unconfirm ( struct secure_channel *channel ) {
868
869 /* Establishment is defined only for the currently confirmed
870 * identity, and so any existing established identity must be
871 * cleared.
872 */
874
875 /* Drop and clear reference */
876 x509_put ( channel->props.confirmed );
877 channel->props.confirmed = NULL;
878}
879
880/**
881 * Confirm peer identity
882 *
883 * @v channel Secure channel
884 * @v auth Authenticator value
885 * @v len Length of authenticator value
886 * @ret rc Return status code
887 *
888 * The consumer asserts to the secure channel that the authenticator
889 * value was received after the receive pipe was transitioned to a
890 * cipher capable of providing confidentiality.
891 *
892 * This assertion is an unverifiable promise made by the consumer:
893 * there is no way for the secure channel itself to determine when the
894 * authenticator value was received.
895 */
897 const void *auth, size_t len ) {
898 struct x509_certificate *identity;
899 int rc;
900
901 /* Clear any existing confirmed peer identity */
903
904 /* Fail if there is no bound peer identity to authenticate */
905 identity = channel->props.bound;
906 if ( ! identity ) {
907 DBGC ( channel, "CHANNEL %p cannot authenticate unbound "
908 "peer\n", channel );
909 return -EPROTO_NOT_BOUND;
910 }
911
912 /* Sanity check: binding is not possible without keying */
913 assert ( channel->props.keyed );
914
915 /* Require key confirmation over a confidential channel */
916 if ( ! channel->rx.cipher->confidential ) {
917 DBGC ( channel, "CHANNEL %p cannot confirm key with a "
918 "non-confidential cipher\n", channel );
920 }
921
922 /* Verify authentication data */
923 if ( ( rc = channel->op->verify ( channel, auth, len ) ) != 0 ) {
924 DBGC ( channel, "CHANNEL %p failed to authenticate: %s\n",
925 channel, strerror ( rc ) );
926 return rc;
927 }
928
929 /* Record bound peer identity as confirmed peer identity */
930 channel->props.confirmed = x509_get ( identity );
931 DBGC ( channel, "CHANNEL %p key material confirmed for \"%s\"\n",
932 channel, x509_name ( identity ) );
933
934 return 0;
935}
936
937/*****************************************************************************
938 *
939 * Establishment
940 *
941 *****************************************************************************
942 *
943 * The channel may be used for application data once the peer identity
944 * has been validated, the peer has authenticated the channel via key
945 * confirmation, and both pipes have been transitioned to ciphers
946 * capable of providing confidentiality.
947 *
948 * Validating the peer identity (i.e. validating its X.509 certificate
949 * chain) is outside the scope of the secure channel and must be
950 * performed separately by the consumer. Validation is an
951 * asynchronous operation that will typically require network
952 * communication (e.g. to perform OCSP checks).
953 *
954 * Once the consumer knows that validation has completed and that the
955 * channel has been authenticated, it may mark the channel as
956 * established.
957 *
958 * Establishment performs a one-off check that the confirmed peer
959 * identity exists, matches the name required by the consumer, and is
960 * valid at this point in time. Future changes to the validity of the
961 * peer identity (e.g. due to certificate expiry) will not cause the
962 * channel to cease to be established.
963 *
964 */
965
966/**
967 * Clear established peer identity
968 *
969 * @v channel Secure channel
970 */
972
973 /* Drop and clear reference */
974 x509_put ( channel->props.established );
975 channel->props.established = NULL;
976}
977
978/**
979 * Establish channel as trusted for application data
980 *
981 * @v channel Secure channel
982 * @v name Required peer identity name
983 * @v root Root certificate list, or NULL to use default
984 * @ret rc Return status code
985 */
986int channel_establish ( struct secure_channel *channel, const char *name,
987 struct x509_root *root ) {
988 struct x509_certificate *identity;
989 int rc;
990
991 /* Clear any existing established peer identity */
993
994 /* Fail if there is no confirmed peer identity to establish */
995 identity = channel->props.confirmed;
996 if ( ! identity ) {
997 DBGC ( channel, "CHANNEL %p cannot establish unconfirmed "
998 "peer\n", channel );
999 return -EPROTO_NOT_CONFIRMED;
1000 }
1001
1002 /* Sanity check: confirmation is not possible without binding */
1003 assert ( channel->props.bound == identity );
1004 assert ( channel->props.keyed );
1005
1006 /* Fail if ciphers are still operating in plaintext mode */
1007 if ( ! ( channel->tx.cipher->confidential &&
1008 channel->rx.cipher->confidential ) ) {
1009 DBGC ( channel, "CHANNEL %p cannot establish channel with a "
1010 "non-confidential cipher\n", channel );
1011 return -EPERM_NOT_CONFIDENTIAL;
1012 }
1013
1014 /* Fail if confirmed peer identity name is incorrect */
1015 if ( ( rc = x509_check_name ( identity, name ) ) != 0 ) {
1016 DBGC ( channel, "CHANNEL %p identity \"%s\" does not match "
1017 "\"%s\": %s\n", channel, x509_name ( identity ),
1018 name, strerror ( rc ) );
1019 return rc;
1020 }
1021
1022 /* Fail if confirmed peer identity has not been validated */
1023 if ( ! x509_is_valid ( identity, root ) ) {
1024 DBGC ( channel, "CHANNEL %p identity \"%s\" has not been "
1025 "validated\n", channel, x509_name ( identity ) );
1026 return -EPERM_NOT_VALID;
1027 }
1028
1029 /* Record confirmed peer identity as established peer identity */
1030 channel->props.established = x509_get ( identity );
1031 DBGC ( channel, "CHANNEL %p established for \"%s\"\n",
1032 channel, x509_name ( identity ) );
1033
1034 return 0;
1035}
1036
1037/*****************************************************************************
1038 *
1039 * Cipher operation
1040 *
1041 *****************************************************************************
1042 *
1043 */
1044
1045/**
1046 * Encrypt or decrypt data via dead cipher
1047 *
1048 * @v cipher Cipher algorithm
1049 * @v ctx Context
1050 * @v src Data to encrypt or decrypt
1051 * @v dst Buffer for encrypted or decrypted data
1052 * @v len Length of data
1053 */
1054static void channel_dead_crypt ( struct cipher_algorithm *cipher __unused,
1055 void *ctx __unused, const void *src __unused,
1056 void *dst, size_t len ) {
1057 static const uint8_t pattern[] = { 0xde, 0xad, 0xc1, 0xfa };
1058 uint8_t *bytes = dst;
1059 unsigned int i;
1060
1061 /* Fill destination with fixed and easily spotted pattern */
1062 for ( i = 0 ; i < len ; i++ )
1063 bytes[i] = pattern[ i % sizeof ( pattern ) ];
1064}
1065
1066/**
1067 * Dead cipher
1068 *
1069 * We activate this cipher (rather than the null cipher) upon any
1070 * cipher-related failure, to guard against code paths that may fail
1071 * to check for cipher errors.
1072 */
1074 .name = "dead",
1075 .ctxsize = 0,
1076 .blocksize = 1,
1077 .alignsize = 1,
1078 .authsize = 0,
1079 .confidential = 0,
1080 .setkey = cipher_null_setkey,
1081 .setiv = cipher_null_setiv,
1082 .encrypt = channel_dead_crypt,
1083 .decrypt = channel_dead_crypt,
1084 .auth = cipher_null_auth,
1085};
1086
1087/**
1088 * Get pipe name (for debugging)
1089 *
1090 * @v channel Secure channel
1091 * @v pipe Secure channel pipe
1092 * @ret name Pipe name
1093 */
1094static inline const char * channel_pipe_name ( struct secure_channel *channel,
1095 struct secure_pipe *pipe ) {
1096
1097 return ( ( pipe == &channel->tx ) ? "TX" :
1098 ( pipe == &channel->rx ) ? "RX" : "INVALID" );
1099}
1100
1101/**
1102 * Clear cipher algorithm
1103 *
1104 * @v pipe Secure channel pipe
1105 */
1106static void channel_clear_cipher ( struct secure_pipe *pipe ) {
1107
1108 /* Zero and free any existing cipher context */
1109 zfree ( pipe->ctx );
1110 pipe->ctx = NULL;
1111
1112 /* Default to the dead cipher until set */
1113 pipe->cipher = &channel_dead_cipher;
1114}
1115
1116/**
1117 * Set cipher algorithm and key
1118 *
1119 * @v channel Secure channel
1120 * @v pipe Secure channel pipe
1121 * @v cipher Cipher algorithm
1122 * @v key Key
1123 * @v len Length of key
1124 * @ret rc Return status code
1125 *
1126 * The consumer asserts to the secure channel that the key is
1127 * ultimately derived from the shared secret that was previously
1128 * provided to the consumer by the secure channel, i.e. that
1129 * possession of the cipher key implies possession of the shared
1130 * secret.
1131 *
1132 * This assertion is an unverifiable promise made by the consumer: we
1133 * can check that a shared secret exists, but there is no way for the
1134 * secure channel itself to determine how the cipher key is derived.
1135 */
1137 struct secure_pipe *pipe,
1138 struct cipher_algorithm *cipher,
1139 const void *key, size_t len ) {
1140 int rc;
1141
1142 /* Zero and free any existing cipher context */
1143 channel_clear_cipher ( pipe );
1144
1145 /* Fail if there is no shared secret from which a key could derive */
1146 if ( ! channel->props.keyed ) {
1147 DBGC ( channel, "CHANNEL %p refusing to use definitely "
1148 "non-derived shared secret\n", channel );
1150 goto err_keyed;
1151 }
1152
1153 /* Refuse to explicitly set a non-confidential cipher */
1154 if ( ! cipher->confidential ) {
1155 DBGC ( channel, "CHANNEL %p %s refusing to use "
1156 "non-confidential cipher \"%s\"\n", channel,
1157 channel_pipe_name ( channel, pipe ), cipher->name );
1159 goto err_confidential;
1160 }
1161 pipe->cipher = cipher;
1162
1163 /* Allocate new context */
1164 pipe->ctx = zalloc ( cipher->ctxsize );
1165 if ( ! pipe->ctx ) {
1166 rc = -ENOMEM;
1167 goto err_alloc;
1168 }
1169
1170 /* Set cipher key */
1171 if ( ( rc = cipher_setkey ( cipher, pipe->ctx, key, len ) ) != 0 ) {
1172 DBGC ( channel, "CHANNEL %p %s could not set \"%s\" key: %s\n",
1174 cipher->name, strerror ( rc ) );
1175 goto err_setkey;
1176 }
1177
1178 DBGC ( channel, "CHANNEL %p %s using \"%s\" with %zd-bit key\n",
1180 cipher->name, ( 8 * len ) );
1181 return 0;
1182
1183 err_setkey:
1184 err_alloc:
1185 err_confidential:
1186 err_keyed:
1187 channel_clear_cipher ( pipe );
1188 return rc;
1189}
1190
1191/*****************************************************************************
1192 *
1193 * Life cycle management
1194 *
1195 *****************************************************************************
1196 *
1197 */
1198
1199/**
1200 * Open secure channel
1201 *
1202 * @v channel Secure channel
1203 * @ret rc Return status code
1204 */
1206 int rc;
1207
1208 /* Sanity checks */
1209 assert ( channel != NULL );
1210 assert ( channel->op != NULL );
1211 assert ( channel->op->reset != NULL );
1212 assert ( channel->op->apply != NULL );
1213 assert ( channel->op->verify != NULL );
1214
1215 /* Clear security properties (which should already be clear) */
1216 assert ( channel->props.keyed == 0 );
1217 assert ( channel->props.bound == NULL );
1218 assert ( channel->props.confirmed == NULL );
1219 assert ( channel->props.established == NULL );
1221 assert ( channel->props.keyed == 0 );
1222 assert ( channel->props.bound == NULL );
1223 assert ( channel->props.confirmed == NULL );
1224 assert ( channel->props.established == NULL );
1225
1226 /* Reset ciphers (which should already have no contexts) */
1227 assert ( channel->tx.ctx == NULL );
1228 assert ( channel->rx.ctx == NULL );
1231 assert ( channel->tx.ctx == NULL );
1232 assert ( channel->rx.ctx == NULL );
1233
1234 /* Initialise ephemeral master secret */
1235 if ( ( rc = channel_ephemeral_init ( channel ) ) != 0 )
1236 return rc;
1237
1238 /* Enable initial plaintext ciphers */
1239 channel->tx.cipher = &cipher_null;
1240 channel->rx.cipher = &cipher_null;
1241
1242 DBGC ( channel, "CHANNEL %p opened\n", channel );
1243 return 0;
1244}
1245
1246/**
1247 * Reopen secure channel
1248 *
1249 * @v channel Secure channel
1250 *
1251 * The channel will be returned to a freshly opened state (including a
1252 * new ephemeral master secret), but with any existing cipher state
1253 * retained. All security properties will be cleared.
1254 *
1255 * This allows a new secure channel to be established with either or
1256 * both of the transmit and receive pipes having already transitioned
1257 * to a cipher capable of providing confidentiality.
1258 *
1259 * The consumer may choose to reopen a fully established channel while
1260 * leaving the cipher keys intact (as is done in TLS renegotiation),
1261 * in which case it may choose to treat the channel as remaining
1262 * established (to the old peer identity) at least until the point
1263 * that the cipher keys are next changed (and possibly further,
1264 * depending upon the protocol design). The secure channel itself
1265 * does not attempt to model any such choice by the consumer:
1266 * reopening will clear all security properties including the
1267 * established peer identity.
1268 */
1270
1271 /* Clear security properties */
1273 assert ( channel->props.keyed == 0 );
1274 assert ( channel->props.bound == NULL );
1275 assert ( channel->props.confirmed == NULL );
1276 assert ( channel->props.established == NULL );
1277
1278 /* Replace ephemeral master secret
1279 *
1280 * We choose to replace rather than reinitialise the ephemeral
1281 * master secret so that this function may be used from code
1282 * paths that cannot allow for failure (such as when closing
1283 * the channel).
1284 */
1286
1287 DBGC ( channel, "CHANNEL %p reopened\n", channel );
1288}
1289
1290/**
1291 * Close secure channel
1292 *
1293 * @v channel Secure channel
1294 *
1295 * All secret values held by the secure channel will be destroyed,
1296 * including the ephemeral master secret.
1297 *
1298 * This function may safely be called on a channel that has already
1299 * been closed.
1300 */
1302
1303 /* Clear security properties */
1305 assert ( channel->props.keyed == 0 );
1306 assert ( channel->props.bound == NULL );
1307 assert ( channel->props.confirmed == NULL );
1308 assert ( channel->props.established == NULL );
1309
1310 /* Reset ciphers */
1313 assert ( channel->tx.ctx == NULL );
1314 assert ( channel->rx.ctx == NULL );
1315
1316 /* Replace ephemeral master secret
1317 *
1318 * We choose to replace rather than zero the ephemeral master
1319 * secret. For any channel that has been successfully opened,
1320 * this ensures that an erroneous reuse of the channel after
1321 * it has been closed cannot lead to the use of predictable
1322 * ephemeral secrets (derived from an all-zero value), or to
1323 * reuse of its previous ephemeral secrets.
1324 */
1326
1327 DBGC ( channel, "CHANNEL %p closed\n", channel );
1328}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
struct golan_eq_context ctx
Definition CIB_PRM.h:0
__be32 out[4]
Definition CIB_PRM.h:8
u8 signature
CPU signature.
Definition CIB_PRM.h:7
union @162305117151260234136356364136041353210355154177 key
u32 info
Definition ar9003_mac.h:0
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned char uint8_t
Definition stdint.h:10
static const void * src
Definition string.h:48
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:61
const char * name
Definition ath9k_hw.c:1986
static int channel_ephemeral_init(struct secure_channel *channel)
Initialise ephemeral master secret.
Definition channel.c:164
#define EPROTO_NOT_CONFIRMED
Definition channel.c:129
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
struct cipher_algorithm channel_dead_cipher
Dead cipher.
Definition channel.c:1073
#define EPERM_NOT_VALID
Definition channel.c:120
#define EPERM_NOT_CONFIDENTIAL
Definition channel.c:117
static int channel_bind(struct secure_channel *channel, struct x509_certificate *identity)
Set bound peer identity.
Definition channel.c:565
static const char * channel_pipe_name(struct secure_channel *channel, struct secure_pipe *pipe)
Get pipe name (for debugging).
Definition channel.c:1094
static void channel_unbind(struct secure_channel *channel)
Clear bound peer identity.
Definition channel.c:545
static int channel_key_transport(struct secure_channel *channel, struct exchange_algorithm *exchange, void *shared)
Transport shared secret.
Definition channel.c:467
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
static void channel_unconfirm(struct secure_channel *channel)
Clear confirmed peer identity.
Definition channel.c:867
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
static int channel_key(struct secure_channel *channel, struct exchange_algorithm *exchange, const void *partner, void *shared)
Generate and apply shared secret.
Definition channel.c:357
static void channel_dead_crypt(struct cipher_algorithm *cipher __unused, void *ctx __unused, const void *src __unused, void *dst, size_t len)
Encrypt or decrypt data via dead cipher.
Definition channel.c:1054
int channel_open(struct secure_channel *channel)
Open secure channel.
Definition channel.c:1205
static void channel_clear_cipher(struct secure_pipe *pipe)
Clear cipher algorithm.
Definition channel.c:1106
static void channel_ephemeral_replace(struct secure_channel *channel)
Replace ephemeral master secret.
Definition channel.c:229
void channel_close(struct secure_channel *channel)
Close secure channel.
Definition channel.c:1301
#define ENOTTY_TRANSPORT
Definition channel.c:114
#define EPROTO_NOT_BOUND
Definition channel.c:126
static void channel_key_private(struct secure_channel *channel, struct exchange_algorithm *exchange, void *private)
Generate private key.
Definition channel.c:294
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
#define EPROTO_NOT_KEYED
Definition channel.c:123
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_unestablish(struct secure_channel *channel)
Clear established peer identity.
Definition channel.c:971
int channel_key_share(struct secure_channel *channel, struct exchange_algorithm *exchange, void *public)
Share public key.
Definition channel.c:320
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
Secure channel abstraction.
#define channel_ephemeral_algorithm
Ephemeral master secret digest algorithm.
Definition channel.h:19
static void channel_clear_preshared(struct secure_preshared_identity *psid)
Clear pre-shared bound peer identity.
Definition channel.h:282
struct cipher_algorithm cipher_null
Definition crypto_null.c:94
int cipher_null_setiv(struct cipher_algorithm *cipher __unused, void *ctx __unused, const void *iv __unused, size_t ivlen __unused)
Definition crypto_null.c:70
void cipher_null_auth(struct cipher_algorithm *cipher __unused, void *ctx __unused, void *auth __unused)
Definition crypto_null.c:89
int cipher_null_setkey(struct cipher_algorithm *cipher __unused, void *ctx __unused, const void *key __unused, size_t keylen __unused)
Definition crypto_null.c:63
ring len
Length.
Definition dwmac.h:226
Error codes.
struct eth_slow_lacp_entity_tlv partner
Partner information.
Definition eth_slow.h:5
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:598
#define DBGC2(...)
Definition compiler.h:547
#define DBGC2_HDA(...)
Definition compiler.h:548
#define DBGC(...)
Definition compiler.h:530
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define ENOMEM
Not enough space.
Definition errno.h:578
#define ENOTSUP
Operation not supported.
Definition errno.h:633
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
void hkdf_expand(struct digest_algorithm *digest, const void *prk, const void *info, size_t info_len, void *out, size_t len)
Expand pseudorandom key.
Definition hkdf.c:95
void hkdf_extract(struct digest_algorithm *digest, const void *salt, size_t salt_len, const void *ikm, size_t ikm_len, void *prk)
Extract fixed-length pseudorandom key.
Definition hkdf.c:56
HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
uint8_t info_len
Reject information length.
Definition ib_mad.h:7
uint8_t bytes[64]
Definition ib_mad.h:5
Cryptographic API.
static int cipher_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
Definition crypto.h:310
static int pubkey_encrypt(struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, const struct asn1_cursor *plaintext, struct asn1_builder *ciphertext)
Definition crypto.h:362
static int exchange_share(struct exchange_algorithm *exchange, const void *private, void *public)
Definition crypto.h:397
static int pubkey_verify(struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature)
Definition crypto.h:383
static int exchange_agree(struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared)
Definition crypto.h:403
static int is_key_transport(struct exchange_algorithm *exchange)
Definition crypto.h:409
String functions.
void * memset(void *dest, int character, size_t len) __nonnull
unsigned long tmp
Definition linux_pci.h:65
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:718
void zfree(void *ptr)
Clear and free memory.
Definition malloc.c:738
Dynamic memory allocation.
uint32_t channel
RNDIS channel.
Definition netvsc.h:3
int rbg_generate(const void *additional, size_t additional_len, int prediction_resist, void *data, size_t len)
Generate bits using RBG.
Definition rbg.c:117
RBG mechanism.
struct stp_switch root
Root switch.
Definition stp.h:15
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
An ASN.1 object builder.
Definition asn1.h:29
An ASN.1 object cursor.
Definition asn1.h:21
const void * data
Start of data.
Definition asn1.h:23
size_t len
Length of data.
Definition asn1.h:25
A cipher algorithm.
Definition crypto.h:58
const char * name
Algorithm name.
Definition crypto.h:60
int confidential
Cipher is capable of providing confidentiality.
Definition crypto.h:84
size_t ctxsize
Context size.
Definition crypto.h:62
A message digest algorithm.
Definition crypto.h:19
A key exchange algorithm.
Definition crypto.h:210
size_t sharedsize
Shared secret size.
Definition crypto.h:218
size_t privsize
Private key size.
Definition crypto.h:214
size_t pubsize
Public key size.
Definition crypto.h:216
const char * name
Algorithm name.
Definition crypto.h:212
A text label widget.
Definition label.h:16
A public key algorithm.
Definition crypto.h:142
A secure channel.
Definition channel.h:72
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
struct x509_subject subject
Subject.
Definition x509.h:245
struct asn1_cursor raw
Raw public key information.
Definition x509.h:52
An X.509 root certificate list.
Definition x509.h:375
struct x509_public_key public_key
Public key information.
Definition x509.h:66
int x509_is_valid(struct x509_certificate *cert, struct x509_root *root)
Check if X.509 certificate is valid.
Definition x509.c:1313
int x509_check_name(struct x509_certificate *cert, const char *name)
Check X.509 certificate name.
Definition x509.c:1564
const char * x509_name(struct x509_certificate *cert)
Get X.509 certificate display name.
Definition x509.c:147
static struct x509_certificate * x509_get(struct x509_certificate *cert)
Get reference to X.509 certificate.
Definition x509.h:267
static void x509_put(struct x509_certificate *cert)
Drop reference to X.509 certificate.
Definition x509.h:278