iPXE
privkey.c File Reference

Private key. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <ipxe/dhcp.h>
#include <ipxe/settings.h>
#include <ipxe/x509.h>
#include <ipxe/privkey.h>

Go to the source code of this file.

Macros

#define ALLOW_KEY_OVERRIDE   1

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
size_t ABS_SYMBOL (private_key_len)
 __asm__ (".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
static struct setting privkey_setting __setting (SETTING_CRYPTO, privkey)
 Private key setting.
void privkey_free (struct refcnt *refcnt)
 Free private key.
static int privkey_apply_settings (void)
 Apply private key configuration settings.

Variables

char private_key_data []
struct private_key private_key
 Private key.
static struct asn1_cursor default_private_key
 Default private key.
struct settings_applicator privkey_applicator __settings_applicator
 Private key settings applicator.

Detailed Description

Private key.

Life would in theory be easier if we could use a single file to hold both the certificate and corresponding private key. Unfortunately, the only common format which supports this is PKCS#12 (aka PFX), which is too ugly to be allowed anywhere near my codebase. See, for reference and amusement:

http://www.cs.auckland.ac.nz/~pgut001/pubs/pfx.html

Definition in file privkey.c.

Macro Definition Documentation

◆ ALLOW_KEY_OVERRIDE

#define ALLOW_KEY_OVERRIDE   1

Definition at line 52 of file privkey.c.

Referenced by privkey_apply_settings().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ABS_SYMBOL()

size_t ABS_SYMBOL ( private_key_len )
extern

◆ __asm__()

__asm__ ( ".section \".rodata\" ,
\"a\" ,
" PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data,
(. - private_key_data)\n\t" ".equ private_key_len,
(. - private_key_data)\n\t" ".previous\n\t"  )

References PROGBITS.

Referenced by __attribute__(), __attribute__(), __attribute__(), __attribute__(), __attribute__(), __attribute__(), __attribute__(), __attribute__(), __attribute__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), __volatile__(), _dump_regs(), apm_poweroff(), asm(), asm(), asm(), asm(), bios_cpu_nap(), bios_currticks(), bios_getchar(), bios_handle_cup(), bios_handle_dectcem_reset(), bios_handle_dectcem_set(), bios_handle_ed(), bios_inject(), bios_inject_startup(), bios_iskey(), bios_mp_exec_boot(), bios_putchar(), bios_reboot(), bochsbp(), bzimage_exec(), call_bootsector(), com32_cfarcall(), com32_exec_loop(), com32_farcall(), com32_intcall(), comboot_exec_loop(), comboot_force_text_mode(), copy_from_real_libkir(), copy_to_real_libkir(), cpuid_instruction_supported(), elfboot_exec(), extmemsize_88(), extmemsize_e801(), fake_e820(), gdbmach_breakpoint(), gdbmach_handler(), gdbmach_update(), hook_comboot_interrupts(), i386_readq(), i386_writeq(), if(), int13_hook_vector(), int13_load_eltorito(), int13_load_mbr(), int13con_init(), int13con_rw(), int22(), interrupt(), IOAPI_INLINE(), IOAPI_INLINE(), iounmap_pages(), librm_test_exec(), meme820(), multiboot_exec(), nbi_boot16(), nbi_boot32(), pcibios_discover(), pcibios_read(), pcibios_write(), pxe_activate(), pxe_start_nbp(), rdrand_get_noise(), rdtsc_raw(), rdtsc_scaled(), rtc_entropy_check(), rtc_get_noise(), rtc_hook_isr(), sdi_exec(), stack_check(), tcpip_continue_chksum(), undi_load(), undinet_call(), undinet_poll(), vesafb_font(), vesafb_init(), vesafb_mode_info(), vesafb_mode_list(), vesafb_restore(), and vesafb_set_mode().

◆ __setting()

struct setting privkey_setting __setting ( SETTING_CRYPTO ,
privkey  )
static

Private key setting.

References __setting, DHCP_EB_KEY, and SETTING_CRYPTO.

◆ privkey_free()

void privkey_free ( struct refcnt * refcnt)

Free private key.

Parameters
refcntReference counter

Definition at line 95 of file privkey.c.

95 {
96 struct private_key *key =
98
99 free ( key->builder.data );
100 free ( key );
101}
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
A private key.
Definition privkey.h:17
A reference counter.
Definition refcnt.h:27

References container_of, free, and key.

Referenced by privkey_init().

◆ privkey_apply_settings()

int privkey_apply_settings ( void )
static

Apply private key configuration settings.

Return values
rcReturn status code

Definition at line 108 of file privkey.c.

108 {
109 static void *key_data = NULL;
110 int len;
111
112 /* Allow private key to be overridden only if not explicitly
113 * specified at build time.
114 */
115 if ( ALLOW_KEY_OVERRIDE ) {
116
117 /* Restore default private key */
119 sizeof ( private_key.builder ) );
120
121 /* Fetch new private key, if any */
122 free ( key_data );
123 if ( ( len = fetch_raw_setting_copy ( NULL, &privkey_setting,
124 &key_data ) ) >= 0 ) {
125 private_key.builder.data = key_data;
127 }
128 }
129
130 /* Debug */
131 if ( private_key.builder.len ) {
132 DBGC ( &private_key, "PRIVKEY using %s private key:\n",
133 ( key_data ? "external" : "built-in" ) );
136 } else {
137 DBGC ( &private_key, "PRIVKEY has no private key\n" );
138 }
139
140 return 0;
141}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
ring len
Length.
Definition dwmac.h:226
#define DBGC(...)
Definition compiler.h:505
#define DBGC_HDA(...)
Definition compiler.h:506
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct asn1_cursor default_private_key
Default private key.
Definition privkey.c:77
#define ALLOW_KEY_OVERRIDE
Definition privkey.c:52
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition settings.c:822
void * data
Data.
Definition asn1.h:36
size_t len
Length of data.
Definition asn1.h:38
struct asn1_builder builder
ASN.1 object builder.
Definition privkey.h:21

References ALLOW_KEY_OVERRIDE, private_key::builder, asn1_builder::data, DBGC, DBGC_HDA, default_private_key, fetch_raw_setting_copy(), free, asn1_builder::len, len, memcpy(), and NULL.

Variable Documentation

◆ private_key_data

char private_key_data[]
extern

◆ private_key

struct private_key private_key
Initial value:
= {
.refcnt = REF_INIT ( ref_no_free ),
.builder = {
.len = ABS_VALUE_INIT ( private_key_len ),
},
}
#define ABS_VALUE_INIT(name)
Get value of an absolute symbol for use in a static initializer.
Definition compiler.h:668
char private_key_data[]
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
Definition refcnt.c:102
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition refcnt.h:78

Private key.

Definition at line 68 of file privkey.c.

68 {
69 .refcnt = REF_INIT ( ref_no_free ),
70 .builder = {
71 .data = private_key_data,
72 .len = ABS_VALUE_INIT ( private_key_len ),
73 },
74};

◆ default_private_key

struct asn1_cursor default_private_key
static
Initial value:
= {
.len = ( ( size_t ) private_key_len ),
}
__SIZE_TYPE__ size_t
Definition stdint.h:6

Default private key.

Definition at line 77 of file privkey.c.

77 {
78 .data = private_key_data,
79 .len = ( ( size_t ) private_key_len ),
80};

Referenced by privkey_apply_settings().

◆ __settings_applicator

struct settings_applicator privkey_applicator __settings_applicator
Initial value:
= {
}
static int privkey_apply_settings(void)
Apply private key configuration settings.
Definition privkey.c:108

Private key settings applicator.

Definition at line 144 of file privkey.c.

144 {
145 .apply = privkey_apply_settings,
146};