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)
 
 __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 []
 
char private_key_len []
 
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 51 of file privkey.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __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 94 of file privkey.c.

94  {
95  struct private_key *key =
97 
98  free ( key->builder.data );
99  free ( key );
100 }
A reference counter.
Definition: refcnt.h:26
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A private key.
Definition: privkey.h:16
union @383 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 107 of file privkey.c.

107  {
108  static void *key_data = NULL;
109  int len;
110 
111  /* Allow private key to be overridden only if not explicitly
112  * specified at build time.
113  */
114  if ( ALLOW_KEY_OVERRIDE ) {
115 
116  /* Restore default private key */
118  sizeof ( private_key.builder ) );
119 
120  /* Fetch new private key, if any */
121  free ( key_data );
122  if ( ( len = fetch_raw_setting_copy ( NULL, &privkey_setting,
123  &key_data ) ) >= 0 ) {
124  private_key.builder.data = key_data;
126  }
127  }
128 
129  /* Debug */
130  if ( private_key.builder.len ) {
131  DBGC ( &private_key, "PRIVKEY using %s private key:\n",
132  ( key_data ? "external" : "built-in" ) );
135  } else {
136  DBGC ( &private_key, "PRIVKEY has no private key\n" );
137  }
138 
139  return 0;
140 }
void * data
Data.
Definition: asn1.h:35
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition: settings.c:821
#define DBGC(...)
Definition: compiler.h:505
struct asn1_builder builder
ASN.1 object builder.
Definition: privkey.h:20
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DBGC_HDA(...)
Definition: compiler.h:506
static struct asn1_cursor default_private_key
Default private key.
Definition: privkey.c:76
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define ALLOW_KEY_OVERRIDE
Definition: privkey.c:51
A private key.
Definition: privkey.h:16
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
size_t len
Length of data.
Definition: asn1.h:37

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

Variable Documentation

◆ private_key_data

char private_key_data[]

◆ private_key_len

char private_key_len[]

◆ private_key

Initial value:
= {
.refcnt = REF_INIT ( ref_no_free ),
.builder = {
.len = ( ( size_t ) private_key_len ),
},
}
__SIZE_TYPE__ size_t
Definition: stdint.h:6
char private_key_data[]
char private_key_len[]
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition: refcnt.h:77
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
Definition: refcnt.c:101

Private key.

Definition at line 67 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[]
char private_key_len[]

Default private key.

Definition at line 76 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:107

Private key settings applicator.

Definition at line 143 of file privkey.c.