iPXE
Defines | 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.

Defines

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

Variables

char private_key_data []
char private_key_len []
struct asn1_cursor 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.


Define Documentation

#define ALLOW_KEY_OVERRIDE   1

Definition at line 51 of file privkey.c.

Referenced by privkey_apply_settings().


Function Documentation

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   
) [static, read]

Private key setting.

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.

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

                                           {
        static void *key_data = NULL;
        int len;

        /* Allow private key to be overridden only if not explicitly
         * specified at build time.
         */
        if ( ALLOW_KEY_OVERRIDE ) {

                /* Restore default private key */
                memcpy ( &private_key, &default_private_key,
                         sizeof ( private_key ) );

                /* Fetch new private key, if any */
                free ( key_data );
                if ( ( len = fetch_raw_setting_copy ( NULL, &privkey_setting,
                                                      &key_data ) ) >= 0 ) {
                        private_key.data = key_data;
                        private_key.len = len;
                }
        }

        /* Debug */
        if ( private_key.len ) {
                DBGC ( &private_key, "PRIVKEY using %s private key:\n",
                       ( key_data ? "external" : "built-in" ) );
                DBGC_HDA ( &private_key, 0, private_key.data, private_key.len );
        } else {
                DBGC ( &private_key, "PRIVKEY has no private key\n" );
        }

        return 0;
}

Variable Documentation

Initial value:
 {
        .data = private_key_data,
        .len = ( ( size_t ) private_key_len ),
}

Private key.

Definition at line 67 of file privkey.c.

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

Initial value:
 {
        .data = private_key_data,
        .len = ( ( size_t ) private_key_len ),
}

Default private key.

Definition at line 73 of file privkey.c.

struct settings_applicator privkey_applicator __settings_applicator
Initial value:
 {
        .apply = privkey_apply_settings,
}

Private key settings applicator.

Definition at line 126 of file privkey.c.