Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
salcock committed Mar 20, 2024
2 parents 1ffcac0 + 0947b17 commit c6ce1a5
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deb-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- "debian:bullseye"
- "ubuntu:focal"
- "ubuntu:jammy"
- "ubuntu:noble"

steps:
- name: Checkout repo
Expand Down Expand Up @@ -57,6 +58,7 @@ jobs:
- "ubuntu:focal"
- "ubuntu:jammy"
- "debian:bookworm"
- "ubuntu:noble"
needs: build
steps:
- name: Set environment variables for download
Expand Down Expand Up @@ -96,6 +98,7 @@ jobs:
- "debian:bookworm"
- "ubuntu:focal"
- "ubuntu:jammy"
- "ubuntu:noble"
needs: test
steps:
- name: Set environment variables for download
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 2.0.11
* Add support for decoding sequences of UTF8Strings
* ETSILI: fix broken decoding hierarchy for Email Address Lists

Version 2.0.10
=============
* Fix incorrect encoding of UTCTime fields
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
libwandder -- C library for DER encoding and decoding.

Current Stable Version: 2.0.10
Current Stable Version: 2.0.11

---------------------------------------------------------------------------
Copyright (c) 2017-2024 The University of Waikato, Hamilton, New Zealand.
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Super primitive configure script

AC_INIT(libwandder, 2.0.10, [email protected])
AC_INIT(libwandder, 2.0.11, [email protected])

AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_SRCDIR(src/decoder.c)
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
libwandder2 (2.0.11-1) unstable; urgency=medium

* Add support for decoding sequences of UTF8Strings
* ETSILI: fix incorrect decoding hierarchy for Email Address Lists

-- Shane Alcock <[email protected]> Wed, 20 Mar 2024 16:23:51 +1300

libwandder2 (2.0.10-1) unstable; urgency=medium

* Fix incorrect encoding of UTCTime fields
Expand Down
5 changes: 4 additions & 1 deletion rpm/libwandder2.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: libwandder2
Version: 2.0.10
Version: 2.0.11
Release: 1%{?dist}
Summary: C Library for encoding and decoding data using DER

Expand Down Expand Up @@ -59,6 +59,9 @@ find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
%{_libdir}/*.so

%changelog
* Wed Mar 20 2024 Shane Alcock <[email protected]> - 2.0.11-1
- Updated to 2.0.11 release of libwandder

* Fri Feb 16 2024 Shane Alcock <[email protected]> - 2.0.10-1
- Updated to 2.0.10 release of libwandder

Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ libwandder_la_SOURCES=encoder.c decoder.c libwandder.h libwandder_etsili.c \
libwandder_etsili.h itemhandler.c itemhandler.h wandder_internal.h

libwandder_la_LIBADD = @ADD_LIBS@
libwandder_la_LDFLAGS = @ADD_LDFLAGS@ -version-info 4:3:2
libwandder_la_LDFLAGS = @ADD_LDFLAGS@ -version-info 4:4:2
libwandder_la_CPPFLAGS = -Werror -Wall

99 changes: 84 additions & 15 deletions src/libwandder_etsili.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,53 @@ static unsigned char * hex2bin (char *hexstr, unsigned char *binvalue,
return(binvalue);
}

static uint32_t decode_length_field(uint8_t *lenstart, uint32_t maxrem,
int *lenlen) {

uint8_t lenoctets;
uint8_t byte;
uint32_t result = 0;
int i;

if (maxrem == 0) {
*lenlen = 0;
return 0;
}

byte = *lenstart;
if ((byte & 0x80) == 0) {
/* definite short form */
*lenlen = 1;
return (byte & 0x7f);
}
lenoctets = byte;
if (lenoctets) {
/* definite long form */
if (lenoctets > 8) {
fprintf(stderr, "libwandder cannot decode length fields longer than 8 bytes!\n");
*lenlen = 0;
return 0;
}
if (lenoctets > maxrem) {
fprintf(stderr, "libwandder: length field size is larger than the amount of bytes remaining in the current field? (%u vs %u)\n", lenoctets, maxrem);
*lenlen = 0;
return 0;
}
*lenlen = lenoctets + 1;
for (i = 0; i < (int)lenoctets; i++) {
byte = *(lenstart + i + 1);
result = result << 8;
result |= (byte);
}
} else {
/* indefinite form */
*lenlen = 1;
result = 0xFFFFFFFF;
}

return result;
}

static inline int decrypt_length_sanity_check(uint8_t *data, uint64_t dlen) {

uint64_t obslen = 0, headerlen = 0, gap = 0;
Expand Down Expand Up @@ -1495,8 +1542,6 @@ static char *stringify_sequenced_primitives(char *sequence_name,

wandder_item_t *parent = dec->current;
uint8_t *ptr = (uint8_t *)(parent->valptr);
int64_t nextint;
uint32_t nextintlen;
char *writer = space;
int namelen = strlen(sequence_name);
int first = 1;
Expand All @@ -1516,6 +1561,9 @@ static char *stringify_sequenced_primitives(char *sequence_name,
while (ptr - parent->valptr < parent->length) {
char tmp[1024];
int tmplen;
int64_t nextint;
uint32_t nextintlen;

assert((*ptr) == WANDDER_TAG_INTEGER);
ptr ++;
/* integer len should always be a single byte (?) */
Expand All @@ -1539,6 +1587,38 @@ static char *stringify_sequenced_primitives(char *sequence_name,
}
ptr += nextintlen;
}
} else if (interpretas == WANDDER_TAG_UTF8STR) {
while (ptr - parent->valptr < parent->length) {
int lenlen = 0;
uint32_t strlength = 0;

assert((*ptr) == WANDDER_TAG_UTF8STR);
ptr ++;

strlength = decode_length_field(ptr,
parent->length - (ptr - parent->valptr), &lenlen);

if (strlength == 0) {
break;
} else if (strlength == 0xFFFFFFFF) {
/* TODO handle indefinite length fields... */
break;
}
ptr += lenlen;
if (spacelen - (writer - space) > strlength + 2) {
if (!first) {
*writer = ',';
writer ++;
*writer = ' ';
writer ++;
} else {
first = 0;
}
memcpy(writer, ptr, strlength);
writer += strlength;
}
ptr += strlength;
}
}

/* TODO add code for other primitive types if they crop up */
Expand Down Expand Up @@ -2581,7 +2661,6 @@ static void free_dumpers(wandder_etsispec_t *dec) {
free(dec->ipiri.members);
free(dec->emailiri.members);
free(dec->emailcc.members);
free(dec->emailrecipientsingle.members);
free(dec->aaainformation.members);
free(dec->pop3aaainformation.members);
free(dec->asmtpaaainformation.members);
Expand Down Expand Up @@ -4109,8 +4188,8 @@ static void init_dumpers(wandder_etsispec_t *dec) {
dec->emailiri.members[10] =
(struct wandder_dump_action) {
.name = "e-mail-Recipients",
.descend = &(dec->emailrecipients),
.interpretas = WANDDER_TAG_NULL
NULL,
.interpretas = WANDDER_TAG_UTF8STR
};
dec->emailiri.members[11] =
(struct wandder_dump_action) {
Expand Down Expand Up @@ -4159,21 +4238,11 @@ static void init_dumpers(wandder_etsispec_t *dec) {
dec->emailrecipients.membercount = 0;
dec->emailrecipients.members = NULL;
dec->emailrecipients.sequence =
(struct wandder_dump_action) {
.name = "E-mail-Address-List",
.descend = &(dec->emailrecipientsingle),
.interpretas = WANDDER_TAG_NULL
};

dec->emailrecipientsingle.membercount = 1;
ALLOC_MEMBERS(dec->emailrecipientsingle);
dec->emailrecipientsingle.members[0] =
(struct wandder_dump_action) {
.name = "recipient",
.descend = NULL,
.interpretas = WANDDER_TAG_UTF8STR
};
dec->emailrecipientsingle.sequence = WANDDER_NOACTION;

dec->aaainformation.membercount = 3;
ALLOC_MEMBERS(dec->aaainformation);
Expand Down
1 change: 0 additions & 1 deletion src/libwandder_etsili.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ typedef struct wandder_etsispec {
wandder_dumper_t emailiri;
wandder_dumper_t emailcc;
wandder_dumper_t emailrecipients;
wandder_dumper_t emailrecipientsingle;
wandder_dumper_t aaainformation;
wandder_dumper_t pop3aaainformation;
wandder_dumper_t asmtpaaainformation;
Expand Down

0 comments on commit c6ce1a5

Please sign in to comment.