iPXE
der.c File Reference

DER-encoded ASN.1 data. More...

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <ipxe/asn1.h>
#include <ipxe/der.h>
#include <ipxe/image.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int der_asn1 (const void *data, size_t len, size_t offset, struct asn1_cursor **cursor)
 Extract ASN.1 object from DER data.
static int der_image_probe (struct image *image)
 Probe DER image.
static int der_image_asn1 (struct image *image, size_t offset, struct asn1_cursor **cursor)
 Extract ASN.1 object from DER image.
struct image_type der_image_type __image_type (PROBE_NORMAL)
 DER image type.

Detailed Description

DER-encoded ASN.1 data.

Definition in file der.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ der_asn1()

int der_asn1 ( const void * data,
size_t len,
size_t offset,
struct asn1_cursor ** cursor )

Extract ASN.1 object from DER data.

Parameters
dataDER data
lenLength of DER data
offsetOffset within data
cursorASN.1 cursor to fill in
Return values
nextOffset to next object, or negative error

The caller is responsible for eventually calling free() on the allocated ASN.1 cursor.

Definition at line 53 of file der.c.

54 {
55 size_t remaining;
56 void *raw;
57
58 /* Sanity check */
59 assert ( offset <= len );
60 remaining = ( len - offset );
61
62 /* Allocate cursor and data buffer */
63 *cursor = malloc ( sizeof ( **cursor ) + remaining );
64 if ( ! *cursor )
65 return -ENOMEM;
66 raw = ( ( ( void * ) *cursor ) + sizeof ( **cursor ) );
67
68 /* Populate cursor and data buffer */
69 (*cursor)->data = raw;
70 (*cursor)->len = remaining;
71 memcpy ( raw, ( data + offset ), remaining );
72
73 /* Shrink cursor */
74 asn1_shrink_any ( *cursor );
75
76 return ( offset + (*cursor)->len );
77}
__be32 raw[7]
Definition CIB_PRM.h:0
int asn1_shrink_any(struct asn1_cursor *cursor)
Shrink ASN.1 object of any type.
Definition asn1.c:300
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint16_t offset
Offset to command line.
Definition bzimage.h:3
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define ENOMEM
Not enough space.
Definition errno.h:535
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:621

References asn1_shrink_any(), assert, data, ENOMEM, len, malloc(), memcpy(), offset, and raw.

Referenced by der_image_asn1(), and efisig_asn1().

◆ der_image_probe()

int der_image_probe ( struct image * image)
static

Probe DER image.

Parameters
imageDER image
Return values
rcReturn status code

Definition at line 85 of file der.c.

85 {
86 struct asn1_cursor cursor;
87 int rc;
88
89 /* Prepare cursor */
90 cursor.data = image->data;
91 cursor.len = image->len;
92
93 /* Check that image begins with an ASN.1 sequence object */
94 if ( ( rc = asn1_skip ( &cursor, ASN1_SEQUENCE ) ) != 0 ) {
95 DBGC ( image, "DER %s is not valid ASN.1: %s\n",
96 image->name, strerror ( rc ) );
97 return rc;
98 }
99
100 /* Check that image comprises a single well-formed ASN.1 object */
101 if ( cursor.len ) {
102 DBGC ( image, "DER %s is not single ASN.1\n", image->name );
103 return -ENOEXEC;
104 }
105
106 return 0;
107}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
int asn1_skip(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object.
Definition asn1.c:231
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition asn1.h:90
#define DBGC(...)
Definition compiler.h:505
#define ENOEXEC
Exec format error.
Definition errno.h:520
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
An ASN.1 object cursor.
Definition asn1.h:21
An executable image.
Definition image.h:24
const void * data
Read-only data.
Definition image.h:51
char * name
Name.
Definition image.h:38
size_t len
Length of raw file image.
Definition image.h:56

References ASN1_SEQUENCE, asn1_skip(), asn1_cursor::data, image::data, DBGC, ENOEXEC, asn1_cursor::len, image::len, image::name, rc, and strerror().

Referenced by __image_type().

◆ der_image_asn1()

int der_image_asn1 ( struct image * image,
size_t offset,
struct asn1_cursor ** cursor )
static

Extract ASN.1 object from DER image.

Parameters
imageDER image
offsetOffset within image
cursorASN.1 cursor to fill in
Return values
nextOffset to next image, or negative error

The caller is responsible for eventually calling free() on the allocated ASN.1 cursor.

Definition at line 120 of file der.c.

121 {
122 int next;
123 int rc;
124
125 /* Extract ASN.1 object */
126 if ( ( next = der_asn1 ( image->data, image->len, offset,
127 cursor ) ) < 0 ) {
128 rc = next;
129 DBGC ( image, "DER %s could not extract ASN.1: %s\n",
130 image->name, strerror ( rc ) );
131 return rc;
132 }
133
134 return next;
135}
int der_asn1(const void *data, size_t len, size_t offset, struct asn1_cursor **cursor)
Extract ASN.1 object from DER data.
Definition der.c:53
uint32_t next
Next descriptor address.
Definition dwmac.h:11

References image::data, DBGC, der_asn1(), image::len, image::name, next, offset, rc, and strerror().

Referenced by __image_type().

◆ __image_type()

struct image_type zimg_image_type __image_type ( PROBE_NORMAL )
Initial value:
= {
.name = "zimg",
.probe = zimg_probe,
.extract = zimg_extract,
}
int image_extract_exec(struct image *image)
Extract and execute image.
Definition archive.c:108
static int zimg_extract(struct image *image, struct image *extracted)
Extract compresed kernel image.
Definition lkrn.c:321
static int zimg_probe(struct image *image)
Probe compressed kernel image.
Definition lkrn.c:350

DER image type.

Linux kernel compressed image type.

References __image_type, der_image_asn1(), der_image_probe(), and PROBE_NORMAL.