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...
 
static int privkey_apply_settings (void)
 Apply private key configuration settings. More...
 

Variables

char private_key_data []
 
char private_key_len []
 
struct asn1_cursor 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_apply_settings()

static int privkey_apply_settings ( void  )
static

Apply private key configuration settings.

Return values
rcReturn status code

Definition at line 91 of file privkey.c.

91  {
92  static void *key_data = NULL;
93  int len;
94 
95  /* Allow private key to be overridden only if not explicitly
96  * specified at build time.
97  */
98  if ( ALLOW_KEY_OVERRIDE ) {
99 
100  /* Restore default private key */
102  sizeof ( private_key ) );
103 
104  /* Fetch new private key, if any */
105  free ( key_data );
106  if ( ( len = fetch_raw_setting_copy ( NULL, &privkey_setting,
107  &key_data ) ) >= 0 ) {
108  private_key.data = key_data;
109  private_key.len = len;
110  }
111  }
112 
113  /* Debug */
114  if ( private_key.len ) {
115  DBGC ( &private_key, "PRIVKEY using %s private key:\n",
116  ( key_data ? "external" : "built-in" ) );
118  } else {
119  DBGC ( &private_key, "PRIVKEY has no private key\n" );
120  }
121 
122  return 0;
123 }
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition: settings.c:825
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
size_t len
Length of data.
Definition: asn1.h:23
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:73
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct asn1_cursor private_key
Private key.
Definition: privkey.c:67
#define ALLOW_KEY_OVERRIDE
Definition: privkey.c:51
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Variable Documentation

◆ private_key_data

char private_key_data[]

◆ private_key_len

char private_key_len[]

Referenced by pubkey_match(), and rsa_match().

◆ private_key

struct asn1_cursor private_key
Initial value:
= {
.len = ( ( size_t ) private_key_len ),
}
__SIZE_TYPE__ size_t
Definition: stdint.h:6
char private_key_data[]
char private_key_len[]

Private key.

Definition at line 67 of file privkey.c.

Referenced by privkey_apply_settings(), pubkey_match(), rsa_match(), tls_new_certificate_request(), and tls_send_certificate_verify().

◆ 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 73 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:91

Private key settings applicator.

Definition at line 126 of file privkey.c.