iPXE
Macros | Functions | Variables
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. More...
 
void privkey_free (struct refcnt *refcnt)
 Free private key. More...
 
static int privkey_apply_settings (void)
 Apply private key configuration settings. More...
 

Variables

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

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.

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  )

◆ __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"   
)

◆ __setting()

static struct setting privkey_setting __setting ( SETTING_CRYPTO  ,
privkey   
)
static

Private key setting.

◆ 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 }
A reference counter.
Definition: refcnt.h:27
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
A private key.
Definition: privkey.h:17
union @391 key
Sense key.
Definition: scsi.h:18

References container_of, free, and key.

Referenced by privkey_init().

◆ privkey_apply_settings()

static 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 }
void * data
Data.
Definition: asn1.h:36
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition: settings.c:822
#define DBGC(...)
Definition: compiler.h:505
struct asn1_builder builder
ASN.1 object builder.
Definition: privkey.h:21
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DBGC_HDA(...)
Definition: compiler.h:506
ring len
Length.
Definition: dwmac.h:231
static struct asn1_cursor default_private_key
Default private key.
Definition: privkey.c:77
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
#define ALLOW_KEY_OVERRIDE
Definition: privkey.c:52
A private key.
Definition: privkey.h:17
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
size_t len
Length of data.
Definition: asn1.h:38

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[]

◆ private_key

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

Private key.

Definition at line 68 of file privkey.c.

◆ 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
char private_key_data[]

Default private key.

Definition at line 77 of file privkey.c.

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.