Skip to content

Commit 79bc2cd

Browse files
committed
Merge branch 'hex-liid' into develop
2 parents 37028aa + 965d89c commit 79bc2cd

34 files changed

+372
-75
lines changed

src/collector/collector_publish.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ openli_export_recv_t *create_intercept_details_msg(intercept_common_t *common,
7373
expmsg->data.cept.cepttype = cepttype;
7474
expmsg->data.cept.targetagency = strdup(common->targetagency);
7575
expmsg->data.cept.timefmt = common->time_fmt;
76+
expmsg->data.cept.liid_format = common->liid_format;
7677

7778
if (common->xid_count > 0) {
7879
expmsg->data.cept.xids = calloc(common->xid_count, sizeof(uuid_t));

src/collector/collector_publish.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ typedef struct published_intercept_msg {
211211
int seqtrackerid;
212212
payload_encryption_method_t encryptmethod;
213213
openli_timestamp_encoding_fmt_t timefmt;
214+
openli_liid_format_t liid_format;
214215
uint8_t *encryptkey;
215216
size_t encryptkey_len;
216217
uuid_t *xids;

src/collector/collector_seqtracker.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static inline void preencode_etsi_fields(seqtracker_thread_data_t *seqdata,
176176
etsili_intercept_details_t intdetails;
177177

178178
intdetails.liid = intstate->details.liid;
179+
intdetails.liid_format = intstate->details.liid_format;
179180
intdetails.authcc = intstate->details.authcc;
180181
intdetails.delivcc = intstate->details.delivcc;
181182

@@ -213,6 +214,7 @@ static void track_new_intercept(seqtracker_thread_data_t *seqdata,
213214

214215
intstate->details.encryptmethod = cept->encryptmethod;
215216
intstate->details.timefmt = cept->timefmt;
217+
intstate->details.liid_format = cept->liid_format;
216218
intstate->version ++;
217219

218220
} else {
@@ -226,6 +228,7 @@ static void track_new_intercept(seqtracker_thread_data_t *seqdata,
226228
intstate->details.authcc_len = strlen(cept->authcc);
227229
intstate->details.delivcc_len = strlen(cept->delivcc);
228230
intstate->details.timefmt = cept->timefmt;
231+
intstate->details.liid_format = cept->liid_format;
229232
intstate->details.encryptmethod = cept->encryptmethod;
230233
intstate->cinsequencing = NULL;
231234
intstate->version = 0;
@@ -284,7 +287,7 @@ static int modify_tracked_intercept(seqtracker_thread_data_t *seqdata,
284287
}
285288
intstate->details.delivcc = strdup(msg->delivcc);
286289
intstate->details.delivcc_len = strlen(msg->delivcc);
287-
290+
intstate->details.liid_format = msg->liid_format;
288291
intstate->details.timefmt = msg->timefmt;
289292
intstate->details.encryptmethod = msg->encryptmethod;
290293
remove_preencoded(seqdata, intstate);
@@ -368,6 +371,7 @@ static int run_encoding_job(seqtracker_thread_data_t *seqdata,
368371
job.cept_version = intstate->version;
369372
job.encryptmethod = intstate->details.encryptmethod;
370373
job.timefmt = intstate->details.timefmt;
374+
job.liid_format = intstate->details.liid_format;
371375
if (recvd->type == OPENLI_EXPORT_IPMMCC ||
372376
recvd->type == OPENLI_EXPORT_IPCC ||
373377
recvd->type == OPENLI_EXPORT_UMTSCC ||

src/collector/email_worker.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,9 @@ static void start_email_intercept(openli_email_worker_t *state,
707707
expmsg->data.cept.delivcc = strdup(em->common.delivcc);
708708
expmsg->data.cept.seqtrackerid = em->common.seqtrackerid;
709709
expmsg->data.cept.encryptmethod = em->common.encrypt;
710+
expmsg->data.cept.timefmt = em->common.time_fmt;
711+
expmsg->data.cept.liid_format = em->common.liid_format;
712+
710713
if (em->common.encrypt != OPENLI_PAYLOAD_ENCRYPTION_NONE &&
711714
em->common.encryptkey_len > 0) {
712715
expmsg->data.cept.encryptkey_len = em->common.encryptkey_len;

src/collector/encoder_worker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static int encode_templated_epscc(openli_encoder_t *enc,
419419

420420
body = encode_epscc_body(enc->encoder, job->preencoded, job->liid,
421421
job->cin, epsccjob->gtpseqno, epsccjob->dir, job->origreq->ts,
422-
epsccjob->icetype, epsccjob->ipclen);
422+
epsccjob->icetype, epsccjob->ipclen, job->liid_format);
423423

424424
if (body == NULL || body->len == 0 || body->encoded == NULL) {
425425
logger(LOG_INFO, "OpenLI: failed to encode ETSI EPSCC body");

src/collector/epscc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ openli_export_recv_t *create_epscc_job(char *liid, uint32_t cin,
4242
wandder_encoded_result_t *encode_epscc_body(wandder_encoder_t *encoder,
4343
wandder_encode_job_t *precomputed, const char *liid, uint32_t cin,
4444
uint16_t gtpseqno, uint8_t dir, struct timeval tv, uint8_t icetype,
45-
uint32_t ipclen);
45+
uint32_t ipclen, openli_liid_format_t liid_format);
4646

4747
#endif
4848
// vim: set sw=4 tabstop=4 softtabstop=4 expandtab :

src/collector/etsiencoding/epscc.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
#include <libwandder_etsili.h>
28+
#include <assert.h>
2829
#include "etsiencoding.h"
2930
#include "logger.h"
3031
#include "intercept.h"
@@ -61,7 +62,7 @@ openli_export_recv_t *create_epscc_job(char *liid, uint32_t cin,
6162
wandder_encoded_result_t *encode_epscc_body(wandder_encoder_t *encoder,
6263
wandder_encode_job_t *precomputed, const char *liid, uint32_t cin,
6364
uint16_t gtpseqno, uint8_t dir, struct timeval tv, uint8_t icetype,
64-
uint32_t ipclen) {
65+
uint32_t ipclen, openli_liid_format_t liid_format) {
6566

6667
wandder_encode_job_t *jobarray[8];
6768
char correlation[32];
@@ -86,8 +87,25 @@ wandder_encoded_result_t *encode_epscc_body(wandder_encoder_t *encoder,
8687
jobarray[7] = &(precomputed[OPENLI_PREENCODE_EPSCCOID]); // hi3DomainID
8788
wandder_encode_next_preencoded(encoder, jobarray, 8);
8889

89-
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
90-
WANDDER_CLASS_CONTEXT_PRIMITIVE, 2, (void *)liid, strlen(liid));
90+
/* convert LIID to binary if it is currently in a hex string format */
91+
if (liid_format == OPENLI_LIID_FORMAT_BINARY_OCTETS) {
92+
uint8_t liidbuf[OPENLI_LIID_MAXSIZE];
93+
size_t liidsize = 0;
94+
liidsize = openli_convert_hexstring_to_binary(liid, liidbuf,
95+
OPENLI_LIID_MAXSIZE);
96+
if (liidsize > 0) {
97+
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
98+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 2, liidbuf, liidsize);
99+
} else {
100+
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
101+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 2, "unknown",
102+
strlen("unknown"));
103+
}
104+
} else {
105+
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
106+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 2, (void *)liid,
107+
strlen(liid));
108+
}
91109

92110
snprintf(correlation, 32, "%u", cin);
93111
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,

src/collector/etsiencoding/etsiencoding.c

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,34 @@
3030
#include "logger.h"
3131
#include "intercept.h"
3232
#include "etsiencoding.h"
33+
#include "util.h"
3334

3435
static inline uint8_t encode_pspdu_sequence(uint8_t *space, uint8_t space_len,
35-
uint32_t contentsize, char *liid, uint16_t liidlen) {
36+
uint32_t contentsize, char *liid) {
3637

3738
uint8_t len_space_req = DERIVE_INTEGER_LENGTH(contentsize);
3839
int i;
39-
uint16_t l;
40+
uint16_t l, l_swap;
41+
l = (uint16_t)strlen(liid);
4042

41-
if (liidlen > space_len - 8) {
43+
if (l > space_len - 8) {
4244
logger(LOG_INFO,
43-
"OpenLI: invalid LIID for PSPDU: %s (%u %u)", liid, liidlen, space_len);
45+
"OpenLI: invalid LIID for PSPDU: %s (%u %u)", liid, l, space_len);
4446
return 0;
4547
}
4648

47-
l = htons(liidlen);
48-
memcpy(space, &l, sizeof(uint16_t));
49-
memcpy(space + 2, liid, liidlen);
50-
space += (2 + liidlen);
49+
l_swap = htons(l);
50+
memcpy(space, &l_swap, sizeof(uint16_t));
51+
memcpy(space + 2, liid, l);
52+
space += (2 + l);
5153

5254
*space = (uint8_t)((WANDDER_CLASS_UNIVERSAL_CONSTRUCT << 5) |
5355
WANDDER_TAG_SEQUENCE);
5456
space ++;
5557

5658
if (len_space_req == 1) {
5759
*space = (uint8_t)contentsize;
58-
return 2 + (2 + liidlen);
60+
return 2 + (2 + l);
5961
}
6062

6163
*space = len_space_req | 0x80;
@@ -66,7 +68,7 @@ static inline uint8_t encode_pspdu_sequence(uint8_t *space, uint8_t space_len,
6668
contentsize = contentsize >> 8;
6769
}
6870

69-
return len_space_req + 2 + (2 + liidlen);
71+
return len_space_req + 2 + (2 + l);
7072
}
7173

7274
void encode_etsili_pshdr(wandder_encoder_t *encoder,
@@ -89,9 +91,30 @@ void encode_etsili_pshdr(wandder_encoder_t *encoder,
8991
WANDDER_CLASS_CONTEXT_PRIMITIVE, 0,
9092
(uint8_t *)WANDDER_ETSILI_PSDOMAINID,
9193
sizeof(WANDDER_ETSILI_PSDOMAINID));
92-
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
93-
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, hdrdata->liid,
94-
hdrdata->liid_len);
94+
95+
// if the LIID is binary octets, we need to first convert the
96+
// hex string that we have into pure binary
97+
98+
if (hdrdata->liid_format == OPENLI_LIID_FORMAT_BINARY_OCTETS) {
99+
uint8_t liidbuf[OPENLI_LIID_MAXSIZE];
100+
size_t liidsize = 0;
101+
liidsize = openli_convert_hexstring_to_binary(hdrdata->liid, liidbuf,
102+
OPENLI_LIID_MAXSIZE);
103+
if (liidsize > 0) {
104+
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
105+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, liidbuf,
106+
liidsize);
107+
} else {
108+
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
109+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, "liidmissing",
110+
strlen("liidmissing"));
111+
}
112+
} else {
113+
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
114+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, hdrdata->liid,
115+
hdrdata->liid_len);
116+
}
117+
95118
wandder_encode_next(encoder, WANDDER_TAG_PRINTABLE,
96119
WANDDER_CLASS_CONTEXT_PRIMITIVE, 2, hdrdata->authcc,
97120
hdrdata->authcc_len);
@@ -256,8 +279,7 @@ int create_etsi_encoded_result(openli_encoded_result_t *res,
256279
* a preceding pS-PDU sequence with the appropriate length...
257280
*/
258281
pspdu_len = encode_pspdu_sequence(pspdu, sizeof(pspdu),
259-
hdr_tplate->header_len + bodylen, job->liid,
260-
job->preencoded[OPENLI_PREENCODE_LIID].vallen);
282+
hdr_tplate->header_len + bodylen, job->liid);
261283

262284
if (pspdu_len == 0) {
263285
return -1;

src/collector/etsiencoding/etsiencoding.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ typedef struct encoder_job {
140140
uint8_t cept_version;
141141
payload_encryption_method_t encryptmethod;
142142
openli_timestamp_encoding_fmt_t timefmt;
143+
openli_liid_format_t liid_format;
143144
} PACKED openli_encoding_job_t;
144145

145146
void encode_ipaddress(wandder_encoder_t *encoder,

src/collector/etsiencoding/hi1notification.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "etsili_core.h"
3030
#include "etsiencoding.h"
3131
#include "logger.h"
32+
#include "util.h"
3233

3334
uint8_t etsi_hi1operationoid[8] = {0x00, 0x04, 0x00, 0x02, 0x02, 0x00, 0x01,
3435
0x06};
@@ -53,9 +54,26 @@ static inline void encode_hi1_notification_body(wandder_encoder_t *encoder,
5354
WANDDER_CLASS_CONTEXT_PRIMITIVE, 0,
5455
etsi_hi1operationoid, sizeof(etsi_hi1operationoid));
5556

56-
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
57-
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, not_data->liid,
58-
strlen(not_data->liid));
57+
// encoding will differ based on whether LIID is binary or ASCII
58+
if (not_data->liid_format == OPENLI_LIID_FORMAT_BINARY_OCTETS) {
59+
uint8_t liidbuf[OPENLI_LIID_MAXSIZE];
60+
size_t liidsize = 0;
61+
liidsize = openli_convert_hexstring_to_binary(not_data->liid,
62+
liidbuf, OPENLI_LIID_MAXSIZE);
63+
if (liidsize > 0) {
64+
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
65+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, liidbuf, liidsize);
66+
67+
} else {
68+
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
69+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, "unknown",
70+
strlen("unknown"));
71+
}
72+
} else {
73+
wandder_encode_next(encoder, WANDDER_TAG_OCTETSTRING,
74+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, not_data->liid,
75+
strlen(not_data->liid));
76+
}
5977

6078
ENC_CSEQUENCE(encoder, 2); // CommunicationIdentifier (HI2)
6179

@@ -114,6 +132,7 @@ wandder_encoded_result_t *encode_etsi_hi1_notification(
114132
hdrdata.networkelemid_len = 0;
115133
hdrdata.intpointid = NULL;
116134
hdrdata.intpointid_len = 0;
135+
hdrdata.liid_format = not_data->liid_format;
117136

118137
gettimeofday(&tv, NULL);
119138
encode_etsili_pshdr(encoder, &hdrdata, 0, (int64_t)not_data->seqno, &tv,

0 commit comments

Comments
 (0)