45 #define EINVAL_ASN1_EMPTY \ 46 __einfo_error ( EINFO_EINVAL_ASN1_EMPTY ) 47 #define EINFO_EINVAL_ASN1_EMPTY \ 48 __einfo_uniqify ( EINFO_EINVAL, 0x01, "Empty or underlength cursor" ) 49 #define EINVAL_ASN1_LEN_LEN \ 50 __einfo_error ( EINFO_EINVAL_ASN1_LEN_LEN ) 51 #define EINFO_EINVAL_ASN1_LEN_LEN \ 52 __einfo_uniqify ( EINFO_EINVAL, 0x02, "Length field overruns cursor" ) 53 #define EINVAL_ASN1_LEN \ 54 __einfo_error ( EINFO_EINVAL_ASN1_LEN ) 55 #define EINFO_EINVAL_ASN1_LEN \ 56 __einfo_uniqify ( EINFO_EINVAL, 0x03, "Field overruns cursor" ) 57 #define EINVAL_ASN1_BOOLEAN \ 58 __einfo_error ( EINFO_EINVAL_ASN1_BOOLEAN ) 59 #define EINFO_EINVAL_ASN1_BOOLEAN \ 60 __einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid boolean" ) 61 #define EINVAL_ASN1_INTEGER \ 62 __einfo_error ( EINFO_EINVAL_ASN1_INTEGER ) 63 #define EINFO_EINVAL_ASN1_INTEGER \ 64 __einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid integer" ) 65 #define EINVAL_ASN1_TIME \ 66 __einfo_error ( EINFO_EINVAL_ASN1_TIME ) 67 #define EINFO_EINVAL_ASN1_TIME \ 68 __einfo_uniqify ( EINFO_EINVAL, 0x05, "Invalid time" ) 69 #define EINVAL_ASN1_ALGORITHM \ 70 __einfo_error ( EINFO_EINVAL_ASN1_ALGORITHM ) 71 #define EINFO_EINVAL_ASN1_ALGORITHM \ 72 __einfo_uniqify ( EINFO_EINVAL, 0x06, "Invalid algorithm" ) 73 #define EINVAL_BIT_STRING \ 74 __einfo_error ( EINFO_EINVAL_BIT_STRING ) 75 #define EINFO_EINVAL_BIT_STRING \ 76 __einfo_uniqify ( EINFO_EINVAL, 0x07, "Invalid bit string" ) 77 #define ENOTSUP_ALGORITHM \ 78 __einfo_error ( EINFO_ENOTSUP_ALGORITHM ) 79 #define EINFO_ENOTSUP_ALGORITHM \ 80 __einfo_uniqify ( EINFO_ENOTSUP, 0x01, "Unsupported algorithm" ) 81 #define ENOTTY_ALGORITHM \ 82 __einfo_error ( EINFO_ENOTTY_ALGORITHM ) 83 #define EINFO_ENOTTY_ALGORITHM \ 84 __einfo_uniqify ( EINFO_ENOTTY, 0x01, "Inappropriate algorithm" ) 95 .
name =
"ecPublicKey",
116 unsigned int len_len;
120 if ( cursor->
len < 2 ) {
122 DBGC ( cursor,
"ASN1 %p too short\n", cursor );
129 DBGC ( cursor,
"ASN1 %p type mismatch (expected %d, got %d)\n",
138 if ( len_len & 0x80 ) {
139 len_len = ( len_len & 0x7f );
145 if ( cursor->
len < len_len ) {
146 DBGC ( cursor,
"ASN1 %p bad length field length %d (max " 147 "%zd)\n", cursor, len_len, cursor->
len );
153 for (
len = 0 ; len_len ; len_len-- ) {
159 if ( cursor->
len <
len ) {
160 DBGC ( cursor,
"ASN1 %p bad length %d (max %zd)\n",
161 cursor,
len, cursor->
len );
192 if ( ( (
size_t )
len ) <= cursor->
len )
195 DBGC ( cursor,
"ASN1 %p entered object type %02x (len %x)\n",
226 DBGC ( cursor,
"ASN1 %p skipped object type %02x (len %x)\n",
272 memcpy ( &temp, cursor,
sizeof ( temp ) );
329 unsigned int unused_bits;
338 if ( cursor->
len < sizeof ( *bit_string ) ) {
339 DBGC ( cursor,
"ASN1 %p invalid bit string:\n", cursor );
344 bit_string = cursor->
data;
345 cursor->
data = &bit_string->data;
347 unused_bits = bit_string->unused;
350 unused_mask = ( 0xff >> ( 8 - unused_bits ) );
351 last = ( cursor->
data + cursor->
len - 1 );
352 if ( ( unused_bits >= 8 ) ||
353 ( ( unused_bits > 0 ) && ( cursor->
len == 0 ) ) ||
354 ( ( *last & unused_mask ) != 0 ) ) {
355 DBGC ( cursor,
"ASN1 %p invalid bit string:\n", cursor );
364 }
else if ( unused_bits ) {
365 DBGC ( cursor,
"ASN1 %p invalid integral bit string:\n",
388 memcpy ( &contents, cursor,
sizeof ( contents ) );
390 if ( contents.
len != sizeof ( *
boolean ) )
394 boolean = contents.
data;
395 return boolean->value;
411 memcpy ( &contents, cursor,
sizeof ( contents ) );
414 if ( contents.
len < 1 )
423 while ( contents.
len ) {
424 high_byte = ( (*value) >> ( 8 * (
sizeof ( *value ) - 1 ) ) );
425 if ( ( high_byte != 0x00 ) && ( high_byte != 0xff ) ) {
426 DBGC ( cursor,
"ASN1 %p integer overflow\n", cursor );
451 difference = ( cursor2->
len - cursor1->
len );
452 return ( difference ? difference :
490 memcpy ( &contents, cursor,
sizeof ( contents ) );
495 memcpy ( params, &contents,
sizeof ( *params ) );
501 DBGC ( cursor,
"ASN1 %p cannot locate algorithm OID:\n",
510 DBGC ( cursor,
"ASN1 %p unrecognised algorithm:\n", cursor );
516 if ( params && (*algorithm)->parse &&
517 ( (
rc = (*algorithm)->parse ( *
algorithm, params ) ) != 0 ) ) {
518 DBGC ( cursor,
"ASN1 %p cannot parse %s parameters: %s\n",
519 cursor, (*algorithm)->name,
strerror (
rc ) );
542 if ( ! (*algorithm)->pubkey ) {
543 DBGC ( cursor,
"ASN1 %p algorithm %s is not a public-key " 544 "algorithm:\n", cursor, (*algorithm)->name );
568 if ( ! (*algorithm)->digest ) {
569 DBGC ( cursor,
"ASN1 %p algorithm %s is not a digest " 570 "algorithm:\n", cursor, (*algorithm)->name );
596 if ( ! (*algorithm)->cipher ) {
597 DBGC ( cursor,
"ASN1 %p algorithm %s is not a cipher " 598 "algorithm:\n", cursor, (*algorithm)->name );
622 if ( ! (*algorithm)->pubkey ) {
623 DBGC ( cursor,
"ASN1 %p algorithm %s is not a signature " 624 "algorithm:\n", cursor, (*algorithm)->name );
630 if ( ! (*algorithm)->digest ) {
631 DBGC ( cursor,
"ASN1 %p algorithm %s is not a signature " 632 "algorithm:\n", cursor, (*algorithm)->name );
660 memcpy ( &curve, cursor,
sizeof ( curve ) );
667 DBGC ( cursor,
"ASN1 %p unrecognised EC algorithm:\n",
674 if ( ! (*algorithm)->curve ) {
675 DBGC ( cursor,
"ASN1 %p algorithm %s is not an elliptic curve " 676 "algorithm:\n", cursor, (*algorithm)->name );
703 if ( actual != expected ) {
704 DBGC ( cursor,
"ASN1 %p algorithm %s does not match %s\n",
705 cursor, actual->
name, expected->
name );
766 unsigned int have_century;
789 memcpy ( &contents, cursor,
sizeof ( contents ) );
799 DBGC ( cursor,
"ASN1 %p invalid time type %02x\n",
807 DBGC ( cursor,
"ASN1 %p cannot locate %s time:\n", cursor,
814 memset ( &pairs, 0,
sizeof ( pairs ) );
816 remaining = contents.
len;
817 for ( i = ( have_century ? 0 : 1 ) ; i <
sizeof ( pairs.raw ) ; i++ ) {
818 if ( remaining < 2 ) {
822 if ( i == (
sizeof ( pairs.raw ) - 1 ) )
824 DBGC ( cursor,
"ASN1 %p invalid time:\n", cursor );
831 DBGC ( cursor,
"ASN1 %p invalid time:\n", cursor );
835 pairs.raw[i] = ( ( 10 * ( tens -
'0' ) ) + ( units -
'0' ) );
841 if ( ! have_century )
842 pairs.named.century = ( ( pairs.named.year >= 50 ) ? 19 : 20 );
845 if ( ( remaining != 1 ) || (
data[0] !=
'Z' ) ) {
846 DBGC ( cursor,
"ASN1 %p invalid time:\n", cursor );
852 tm.
tm_year = ( ( ( pairs.named.century - 19 ) * 100 ) +
854 tm.
tm_mon = ( pairs.named.month - 1 );
875 unsigned int type,
size_t len ) {
876 unsigned int header_len = 2;
877 unsigned int len_len = 0;
885 for ( temp =
len ; temp ; temp >>= 8 )
887 header->length[0] = ( 0x80 | len_len );
888 header_len += len_len;
889 for ( temp =
len ; temp ; temp >>= 8 )
890 header->length[len_len--] = ( temp & 0xff );
908 if ( builder->
len && ! builder->
data )
923 builder->
len = new_len;
960 const void *
data,
size_t len ) {
995 if ( (
rc =
asn1_grow ( builder, header_len ) ) != 0 )
1031 DBGC (
image,
"IMAGE %s could not extract ASN.1 object: %s\n",
#define EINVAL_ASN1_ALGORITHM
#define EINVAL
Invalid argument.
size_t blocksize
Block size.
An ASN.1 OID-identified algorithm.
int asn1_curve_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified elliptic curve algorithm.
struct arbelprm_rc_send_wqe rc
int tm_min
Minutes [0,59].
int asn1_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm, struct asn1_cursor *params)
Parse ASN.1 OID-identified algorithm.
int asn1_compare(const struct asn1_cursor *cursor1, const struct asn1_cursor *cursor2)
Compare two ASN.1 objects.
#define EINVAL_BIT_STRING
#define EINVAL_ASN1_LEN_LEN
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
int asn1_generalized_time(const struct asn1_cursor *cursor, time_t *time)
Parse ASN.1 GeneralizedTime.
#define ASN1_BOOLEAN
ASN.1 boolean.
uint8_t extra
Signature extra byte.
struct image_type * type
Image type, if known.
uint32_t type
Operating system type.
int asn1_enter_bits(struct asn1_cursor *cursor, unsigned int *unused)
Enter ASN.1 bit string.
int tm_mday
Day of month [1,31].
int asn1_prepend_raw(struct asn1_builder *builder, const void *data, size_t len)
Prepend raw data to ASN.1 builder.
const void * data
Start of data.
int asn1_digest_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified digest algorithm.
static int asn1_start(struct asn1_cursor *cursor, unsigned int type)
Start parsing ASN.1 object.
int image_asn1(struct image *image, size_t offset, struct asn1_cursor **cursor)
Extract ASN.1 object from image.
int tm_year
Years since 1900.
#define offsetof(type, field)
Get offset of a field within a structure.
static unsigned int asn1_type(const struct asn1_cursor *cursor)
Extract ASN.1 type.
int asn1_skip_any(struct asn1_cursor *cursor)
Skip ASN.1 object of any type.
#define ASN1_ANY
ASN.1 "any tag" magic value.
int asn1_signature_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified signature algorithm.
#define ENOTSUP
Operation not supported.
size_t len
Length of data.
static int isdigit(int character)
Check if character is a decimal digit.
#define ENOMEM
Not enough space.
int asn1_shrink(struct asn1_cursor *cursor, unsigned int type)
Shrink ASN.1 cursor to fit object.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int asn1_boolean(const struct asn1_cursor *cursor)
Parse value of ASN.1 boolean.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define ASN1_CURSOR(value)
Define an ASN.1 cursor for a static value.
struct asn1_algorithm ecpubkey_algorithm __asn1_algorithm
Generic elliptic curve container algorithm.
pseudo_bit_t value[0x00020]
#define __unused
Declare a variable or data structure as unused.
int tm_mon
Month of year [0,11].
#define EINVAL_ASN1_INTEGER
int(* asn1)(struct image *image, size_t offset, struct asn1_cursor **cursor)
Extract ASN.1 object from image.
time_t mktime(struct tm *tm)
Calculate seconds since the Epoch.
#define ASN1_GENERALIZED_TIME
ASN.1 generalized time.
int asn1_grow(struct asn1_builder *builder, size_t extra)
Grow ASN.1 builder.
REQUIRE_OBJECT(config_asn1)
char * strerror(int errno)
Retrieve string representation of error number.
static void(* free)(struct refcnt *refcnt))
static void asn1_invalidate_cursor(struct asn1_cursor *cursor)
Invalidate ASN.1 object cursor.
int asn1_pubkey_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified public-key algorithm.
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
int asn1_enter_any(struct asn1_cursor *cursor)
Enter ASN.1 object of any type.
int asn1_shrink_any(struct asn1_cursor *cursor)
Shrink ASN.1 object of any type.
int asn1_parse_gcm(struct asn1_algorithm *algorithm __unused, struct asn1_cursor *params)
Parse ASN.1 GCM cipher parameters.
int asn1_wrap(struct asn1_builder *builder, unsigned int type)
Wrap ASN.1 builder.
static size_t asn1_header(struct asn1_builder_header *header, unsigned int type, size_t len)
Construct ASN.1 header.
#define ASN1_SEQUENCE
ASN.1 sequence.
uint32_t next
Next descriptor address.
void * memmove(void *dest, const void *src, size_t len) __nonnull
#define ASN1_INTEGER
ASN.1 integer.
u16 algorithm
Authentication algorithm (Open System or Shared Key)
static struct asn1_algorithm * asn1_find_algorithm(const struct asn1_cursor *cursor)
Identify ASN.1 algorithm by OID.
#define ASN1_OID
ASN.1 object identifier.
#define ENXIO
No such device or address.
#define ASN1_ALGORITHMS
ASN.1 OID-identified algorithms.
REQUIRING_SYMBOL(image_asn1)
static uint8_t oid_ecpublickey[]
"ecPublicKey" object identifier
int asn1_skip_if_exists(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object if present.
int asn1_cipher_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm, struct asn1_cursor *params)
Parse ASN.1 OID-identified cipher algorithm.
#define ASN1_OID_ECPUBLICKEY
ASN.1 OID for ecPublicKey (1.2.840.10045.2.1)
int asn1_integer(const struct asn1_cursor *cursor, int *value)
Parse value of ASN.1 integer.
int asn1_skip(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object.
#define ENOTSUP_ALGORITHM
int asn1_prepend(struct asn1_builder *builder, unsigned int type, const void *data, size_t len)
Prepend data to ASN.1 builder.
uint8_t century
Century (BCD)
struct ena_llq_option header
Header locations.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int asn1_check_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm *expected, struct asn1_cursor *params)
Check ASN.1 OID-identified algorithm.
uint32_t end
Ending offset.
uint8_t data[48]
Additional event data.
int tm_sec
Seconds [0,60].
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
#define ASN1_UTC_TIME
ASN.1 UTC time.
#define EINVAL_ASN1_BOOLEAN
typeof(acpi_finder=acpi_find)
ACPI table finder.
uint16_t offset
Offset to command line.
int64_t time_t
Seconds since the Epoch.
#define ASN1_OCTET_STRING
ASN.1 octet string.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
#define NULL
NULL pointer (VOID *)
size_t len
Length of data.
#define EINVAL_ASN1_EMPTY
int asn1_parse_cbc(struct asn1_algorithm *algorithm, struct asn1_cursor *params)
Parse ASN.1 CBC cipher parameters.
#define ASN1_BIT_STRING
ASN.1 bit string.
void * memset(void *dest, int character, size_t len) __nonnull