Skip to content

Commit 7432ecc

Browse files
committed
Merge branch 'select-timestamp-fmt' into develop
2 parents 7f44ad3 + cf256be commit 7432ecc

30 files changed

+376
-95
lines changed

src/agency.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define DEFAULT_DIGEST_HASH_PDULIMIT 1000
4141
#define DEFAULT_DIGEST_SIGN_HASHLIMIT 15
4242
#define DEFAULT_DIGEST_HASH_METHOD OPENLI_DIGEST_HASH_ALGO_SHA256
43+
#define DEFAULT_AGENCY_TIMESTAMP_FORMAT OPENLI_ENCODED_TIMESTAMP_MICROSECONDS
4344

4445
typedef enum {
4546
OPENLI_DIGEST_HASH_ALGO_SHA1 = 1,
@@ -60,6 +61,7 @@ typedef struct liagency {
6061
uint32_t keepalivewait;
6162
uint16_t handover_retry;
6263
uint32_t resend_window_kbs;
64+
openli_timestamp_encoding_fmt_t time_fmt;
6365

6466
openli_integrity_hash_method_t digest_hash_method;
6567
openli_integrity_hash_method_t digest_sign_method;
@@ -84,6 +86,7 @@ typedef struct liagency {
8486
a->handover_retry == b->handover_retry && \
8587
a->resend_window_kbs == b->resend_window_kbs && \
8688
a->digest_required == b->digest_required && \
89+
a->time_fmt == b->time_fmt && \
8790
((!a->digest_required) || ( \
8891
a->digest_hash_timeout == b->digest_hash_timeout && \
8992
a->digest_hash_pdulimit == b->digest_hash_pdulimit && \

src/collector/collector_publish.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ openli_export_recv_t *create_intercept_details_msg(intercept_common_t *common,
7171
expmsg->data.cept.encryptmethod = common->encrypt;
7272
expmsg->data.cept.cepttype = cepttype;
7373
expmsg->data.cept.targetagency = strdup(common->targetagency);
74+
expmsg->data.cept.timefmt = common->time_fmt;
7475

7576
if (common->xid_count > 0) {
7677
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
char *encryptkey;
214+
openli_timestamp_encoding_fmt_t timefmt;
214215
uuid_t *xids;
215216
size_t xid_count;
216217
openli_intercept_types_t cepttype;

src/collector/collector_seqtracker.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ static void track_new_intercept(seqtracker_thread_data_t *seqdata,
210210
intstate->details.authcc_len = strlen(cept->authcc);
211211
intstate->details.delivcc_len = strlen(cept->delivcc);
212212
intstate->details.encryptmethod = cept->encryptmethod;
213+
intstate->details.timefmt = cept->timefmt;
213214
intstate->version ++;
214215

215216
} else {
@@ -223,6 +224,7 @@ static void track_new_intercept(seqtracker_thread_data_t *seqdata,
223224
intstate->details.authcc_len = strlen(cept->authcc);
224225
intstate->details.delivcc_len = strlen(cept->delivcc);
225226
intstate->details.encryptmethod = cept->encryptmethod;
227+
intstate->details.timefmt = cept->timefmt;
226228
intstate->cinsequencing = NULL;
227229
intstate->version = 0;
228230

@@ -282,7 +284,7 @@ static int modify_tracked_intercept(seqtracker_thread_data_t *seqdata,
282284
intstate->details.delivcc_len = strlen(msg->delivcc);
283285

284286
intstate->details.encryptmethod = msg->encryptmethod;
285-
287+
intstate->details.timefmt = msg->timefmt;
286288

287289
remove_preencoded(seqdata, intstate);
288290
preencode_etsi_fields(seqdata, intstate);
@@ -364,6 +366,7 @@ static int run_encoding_job(seqtracker_thread_data_t *seqdata,
364366
job.cin = (int64_t)cin;
365367
job.cept_version = intstate->version;
366368
job.encryptmethod = intstate->details.encryptmethod;
369+
job.timefmt = intstate->details.timefmt;
367370

368371
if (recvd->type == OPENLI_EXPORT_IPMMCC ||
369372
recvd->type == OPENLI_EXPORT_IPCC ||

src/collector/email_worker.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -735,19 +735,9 @@ static int update_modified_email_intercept(openli_email_worker_t *state,
735735
}
736736

737737
if (encodingchanged) {
738-
expmsg = (openli_export_recv_t *)calloc(1, sizeof(openli_export_recv_t));
738+
expmsg = create_intercept_details_msg(&(found->common),
739+
OPENLI_INTERCEPT_TYPE_EMAIL);
739740
expmsg->type = OPENLI_EXPORT_INTERCEPT_CHANGED;
740-
expmsg->data.cept.liid = strdup(found->common.liid);
741-
expmsg->data.cept.authcc = strdup(found->common.authcc);
742-
expmsg->data.cept.delivcc = strdup(found->common.delivcc);
743-
expmsg->data.cept.seqtrackerid = found->common.seqtrackerid;
744-
expmsg->data.cept.encryptmethod = found->common.encrypt;
745-
if (found->common.encryptkey) {
746-
expmsg->data.cept.encryptkey = strdup(found->common.encryptkey);
747-
} else {
748-
expmsg->data.cept.encryptkey = NULL;
749-
}
750-
751741
publish_openli_msg(state->zmq_pubsocks[found->common.seqtrackerid],
752742
expmsg);
753743
}

src/collector/encoder_worker.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -756,21 +756,29 @@ static encoded_header_template_t *encode_templated_psheader(
756756
if (job->origreq->ts.tv_sec == 0) {
757757
gettimeofday(&(job->origreq->ts), NULL);
758758
}
759-
760759
seqlen = DERIVE_INTEGER_LENGTH(job->seqno);
761-
tvsec_len = DERIVE_INTEGER_LENGTH(job->origreq->ts.tv_sec);
762-
tvusec_len = DERIVE_INTEGER_LENGTH(job->origreq->ts.tv_usec);
763760

764-
key = (job->cept_version << 24) + (seqlen << 16) +
765-
(tvsec_len << 8) + tvusec_len;
761+
if (job->timefmt == OPENLI_ENCODED_TIMESTAMP_MICROSECONDS) {
762+
tvsec_len = DERIVE_INTEGER_LENGTH(job->origreq->ts.tv_sec);
763+
tvusec_len = DERIVE_INTEGER_LENGTH(job->origreq->ts.tv_usec);
764+
765+
key = (job->cept_version << 24) + (seqlen << 16) +
766+
(tvsec_len << 8) + tvusec_len;
767+
} else if (job->timefmt == OPENLI_ENCODED_TIMESTAMP_GENERALIZED) {
768+
// all libwandder generalized timestamps are encoded with the
769+
// same length
770+
key = (job->cept_version << 24) + (seqlen << 16);
771+
} else {
772+
return NULL;
773+
}
766774

767775
JLI(pval, t_set->headers, key);
768776
if (*pval == 0) {
769777
tplate = calloc(1, sizeof(encoded_header_template_t));
770778

771779
if (etsili_create_header_template(encoder, job->preencoded,
772780
(int64_t)job->cin, (int64_t)job->seqno, &(job->origreq->ts),
773-
tplate) < 0) {
781+
tplate, job->timefmt) < 0) {
774782
free(tplate);
775783
return NULL;
776784
}
@@ -781,7 +789,7 @@ static encoded_header_template_t *encode_templated_psheader(
781789
tplate = (encoded_header_template_t *)(*pval);
782790

783791
if (etsili_update_header_template(tplate, (int64_t)job->seqno,
784-
&(job->origreq->ts)) < 0) {
792+
&(job->origreq->ts), job->timefmt) < 0) {
785793
return NULL;
786794
}
787795
}
@@ -798,7 +806,8 @@ static int encode_etsi(openli_encoder_t *enc, openli_encoding_job_t *job,
798806
saved_encoding_templates_t *t_set = NULL;
799807
encoded_header_template_t *hdr_tplate = NULL;
800808

801-
snprintf(keystr, 1000, "%s-%s", job->liid, job->cinstr);
809+
snprintf(keystr, 1000, "%s-%s-%u", job->liid, job->cinstr,
810+
job->timefmt);
802811
JSLI(pval, enc->saved_intercept_templates, (const uint8_t *)keystr);
803812
if ((*pval)) {
804813
t_set = (saved_encoding_templates_t *)(*pval);
@@ -902,7 +911,6 @@ static int process_job(openli_encoder_t *enc, void *socket) {
902911
} else if (job.origreq->type == OPENLI_EXPORT_RAW_IRI) {
903912
encode_rawip(&job, &(result[next]), OPENLI_PROTO_RAWIP_IRI);
904913
} else {
905-
906914
if ((x = encode_etsi(enc, &job, &(result[next]))) <= 0) {
907915
/* What do we do in the event of an error? */
908916
if (x < 0) {

src/collector/etsiencoding/etsiencoding.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ static inline uint8_t encode_pspdu_sequence(uint8_t *space, uint8_t space_len,
7171

7272
void encode_etsili_pshdr(wandder_encoder_t *encoder,
7373
wandder_etsipshdr_data_t *hdrdata, int64_t cin,
74-
int64_t seqno, struct timeval *tv) {
74+
int64_t seqno, struct timeval *tv,
75+
openli_timestamp_encoding_fmt_t timefmt) {
7576

7677
uint32_t tvclass = 1; // timeOfInterception
7778

@@ -120,26 +121,30 @@ void encode_etsili_pshdr(wandder_encoder_t *encoder,
120121
wandder_encode_next(encoder, WANDDER_TAG_INTEGER,
121122
WANDDER_CLASS_CONTEXT_PRIMITIVE, 4, &(seqno),
122123
sizeof(int64_t));
123-
/*
124-
wandder_encode_next(encoder, WANDDER_TAG_GENERALTIME,
125-
WANDDER_CLASS_CONTEXT_PRIMITIVE, 5, tv,
126-
sizeof(struct timeval));
127-
*/
124+
125+
if (timefmt == OPENLI_ENCODED_TIMESTAMP_GENERALIZED) {
126+
wandder_encode_next(encoder, WANDDER_TAG_GENERALTIME,
127+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 5, tv,
128+
sizeof(struct timeval));
129+
}
128130

129131
if (hdrdata->intpointid) {
130132
wandder_encode_next(encoder, WANDDER_TAG_PRINTABLE,
131133
WANDDER_CLASS_CONTEXT_PRIMITIVE, 6, hdrdata->intpointid,
132134
hdrdata->intpointid_len);
133135
}
134136

135-
ENC_CSEQUENCE(encoder, 7);
136-
wandder_encode_next(encoder, WANDDER_TAG_INTEGER,
137-
WANDDER_CLASS_CONTEXT_PRIMITIVE, 0, &(tv->tv_sec),
138-
sizeof(tv->tv_sec));
139-
wandder_encode_next(encoder, WANDDER_TAG_INTEGER,
140-
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, &(tv->tv_usec),
141-
sizeof(tv->tv_usec));
142-
wandder_encode_endseq(encoder);
137+
138+
if (timefmt == OPENLI_ENCODED_TIMESTAMP_MICROSECONDS) {
139+
ENC_CSEQUENCE(encoder, 7);
140+
wandder_encode_next(encoder, WANDDER_TAG_INTEGER,
141+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 0, &(tv->tv_sec),
142+
sizeof(tv->tv_sec));
143+
wandder_encode_next(encoder, WANDDER_TAG_INTEGER,
144+
WANDDER_CLASS_CONTEXT_PRIMITIVE, 1, &(tv->tv_usec),
145+
sizeof(tv->tv_usec));
146+
wandder_encode_endseq(encoder);
147+
}
143148

144149
wandder_encode_next(encoder, WANDDER_TAG_ENUM,
145150
WANDDER_CLASS_CONTEXT_PRIMITIVE, 8, &tvclass, sizeof(tvclass));

src/collector/etsiencoding/etsiencoding.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ typedef struct encoder_job {
140140
char *liid;
141141
uint8_t cept_version;
142142
payload_encryption_method_t encryptmethod;
143+
openli_timestamp_encoding_fmt_t timefmt;
143144
} PACKED openli_encoding_job_t;
144145

145146
void encode_ipaddress(wandder_encoder_t *encoder,
@@ -177,22 +178,27 @@ void clear_global_templates(Pvoid_t *saved_templates);
177178

178179
void encode_etsili_pshdr(wandder_encoder_t *encoder,
179180
wandder_etsipshdr_data_t *hdrdata, int64_t cin,
180-
int64_t seqno, struct timeval *tv);
181+
int64_t seqno, struct timeval *tv,
182+
openli_timestamp_encoding_fmt_t timefmt);
181183

182184
/* defined in tripayload.c */
183185
wandder_encoded_result_t *encode_etsi_keepalive(wandder_encoder_t *encoder,
184-
wandder_etsipshdr_data_t *hdrdata, int64_t seqno);
186+
wandder_etsipshdr_data_t *hdrdata, int64_t seqno,
187+
openli_timestamp_encoding_fmt_t timefmt);
188+
185189
wandder_encoded_result_t *encode_etsi_integrity_check(
186190
wandder_encoder_t *encoder, wandder_etsipshdr_data_t *hdrdata,
187191
int64_t self_seqno, openli_integrity_hash_method_t hashmethod,
188192
uint32_t datatype, openli_proto_msgtype_t msgtype,
189193
uint8_t *checkval, unsigned int checkvallen,
190-
int64_t *inclseqnos, size_t numseqnos);
194+
int64_t *inclseqnos, size_t numseqnos,
195+
openli_timestamp_encoding_fmt_t timefmt);
191196

192197
/* defined in hi1notification.c */
193198
wandder_encoded_result_t *encode_etsi_hi1_notification(
194199
wandder_encoder_t *encoder, hi1_notify_data_t *not_data,
195-
char *operatorid, char *shortopid);
200+
char *operatorid, char *shortopid,
201+
openli_timestamp_encoding_fmt_t timefmt);
196202

197203
/* defined in encryptcontainer.c */
198204
int encrypt_aes_192_cbc(EVP_CIPHER_CTX *ctx, uint8_t *buf, uint16_t buflen,

src/collector/etsiencoding/hi1notification.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ static inline void encode_hi1_notification_body(wandder_encoder_t *encoder,
9696

9797
wandder_encoded_result_t *encode_etsi_hi1_notification(
9898
wandder_encoder_t *encoder, hi1_notify_data_t *not_data,
99-
char *operatorid, char *shortopid) {
99+
char *operatorid, char *shortopid,
100+
openli_timestamp_encoding_fmt_t timefmt) {
100101

101102
struct timeval tv;
102103
wandder_etsipshdr_data_t hdrdata;
@@ -115,7 +116,8 @@ wandder_encoded_result_t *encode_etsi_hi1_notification(
115116
hdrdata.intpointid_len = 0;
116117

117118
gettimeofday(&tv, NULL);
118-
encode_etsili_pshdr(encoder, &hdrdata, 0, (int64_t)not_data->seqno, &tv);
119+
encode_etsili_pshdr(encoder, &hdrdata, 0, (int64_t)not_data->seqno, &tv,
120+
timefmt);
119121
encode_hi1_notification_body(encoder, not_data, shortopid);
120122
return wandder_encode_finish(encoder);
121123
}

src/collector/etsiencoding/tripayload.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ wandder_encoded_result_t *encode_etsi_integrity_check(
3636
int64_t self_seqno, openli_integrity_hash_method_t hashmethod,
3737
uint32_t checktype, openli_proto_msgtype_t msgtype,
3838
uint8_t *checkval, unsigned int checkvallen,
39-
int64_t *inclseqnos, size_t numseqnos) {
39+
int64_t *inclseqnos, size_t numseqnos,
40+
openli_timestamp_encoding_fmt_t timefmt) {
4041

4142

4243
struct timeval tv;
@@ -45,7 +46,7 @@ wandder_encoded_result_t *encode_etsi_integrity_check(
4546
uint32_t hashalgo = 0;
4647

4748
gettimeofday(&tv, NULL);
48-
encode_etsili_pshdr(encoder, hdrdata, 0, self_seqno, &tv);
49+
encode_etsili_pshdr(encoder, hdrdata, 0, self_seqno, &tv, timefmt);
4950
ENC_CSEQUENCE(encoder, 2); // Payload
5051
ENC_CSEQUENCE(encoder, 2); // TRIPayload
5152
ENC_CSEQUENCE(encoder, 0); // integrityCheck
@@ -90,12 +91,13 @@ wandder_encoded_result_t *encode_etsi_integrity_check(
9091
}
9192

9293
wandder_encoded_result_t *encode_etsi_keepalive(wandder_encoder_t *encoder,
93-
wandder_etsipshdr_data_t *hdrdata, int64_t seqno) {
94+
wandder_etsipshdr_data_t *hdrdata, int64_t seqno,
95+
openli_timestamp_encoding_fmt_t timefmt) {
9496

9597
struct timeval tv;
9698

9799
gettimeofday(&tv, NULL);
98-
encode_etsili_pshdr(encoder, hdrdata, 0, seqno, &tv);
100+
encode_etsili_pshdr(encoder, hdrdata, 0, seqno, &tv, timefmt);
99101
ENC_CSEQUENCE(encoder, 2); // Payload
100102
ENC_CSEQUENCE(encoder, 2); // TRIPayload
101103
wandder_encode_next(encoder, WANDDER_TAG_NULL,

0 commit comments

Comments
 (0)