lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

August 2022

  • 3 participants
  • 2402 discussions
Change in libosmo-pfcp[master]: gtlv: check memory bounds 3/3: encoding to str
by neels 11 Aug '22

11 Aug '22
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/29041 ) Change subject: gtlv: check memory bounds 3/3: encoding to str ...................................................................... gtlv: check memory bounds 3/3: encoding to str See Id8d997c9d5e655ff1842ec69eab6c073875c6330 Related: CID#275417 Change-Id: I63d52a4f5dba32d3a3887dd9c5e42e1695fb2aa3 --- M include/osmocom/gtlv/gtlv_dec_enc.h M src/libosmo-gtlv/gtlv_dec_enc.c M src/libosmo-gtlv/gtlv_gen.c M tests/libosmo-gtlv/gtlv_dec_enc_test.c M tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c M tests/libosmo-gtlv/test_tliv/tliv_test.c 6 files changed, 30 insertions(+), 23 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-pfcp refs/changes/41/29041/1 diff --git a/include/osmocom/gtlv/gtlv_dec_enc.h b/include/osmocom/gtlv/gtlv_dec_enc.h index 243ad96..acb4ad4 100644 --- a/include/osmocom/gtlv/gtlv_dec_enc.h +++ b/include/osmocom/gtlv/gtlv_dec_enc.h @@ -191,10 +191,12 @@ unsigned int obj_ofs, const struct osmo_gtlv_coding *ie_coding, osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs); -int osmo_gtlvs_encode_to_str_buf(char *buf, size_t buflen, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs); -char *osmo_gtlvs_encode_to_str_c(void *ctx, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs); +int osmo_gtlvs_encode_to_str_buf(char *buf, size_t buflen, + const void *decoded_struct, size_t decoded_struct_max_len, unsigned int obj_ofs, + const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs); +char *osmo_gtlvs_encode_to_str_c(void *ctx, + const void *decoded_struct, size_t decoded_struct_max_len, unsigned int obj_ofs, + const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs); static inline bool osmo_gtlv_coding_end(const struct osmo_gtlv_coding *iec) { diff --git a/src/libosmo-gtlv/gtlv_dec_enc.c b/src/libosmo-gtlv/gtlv_dec_enc.c index e442baa..7e8d524 100644 --- a/src/libosmo-gtlv/gtlv_dec_enc.c +++ b/src/libosmo-gtlv/gtlv_dec_enc.c @@ -28,9 +28,6 @@ #include <osmocom/gtlv/gtlv_dec_enc.h> -/* Reverse offsetof(): return the address of the struct member for a given osmo_gtlv_msg and member ofs_foo value. */ -#define MEMB(M, MEMB_OFS) ((void *)((char *)(M) + (MEMB_OFS))) - #define RETURN_ERROR(RC, TAG_INST, FMT, ARGS...) \ do {\ if (err_cb) { \ @@ -482,19 +479,23 @@ * \param[in] iei_strs value_string array to give IEI names in tag headers, or NULL. * \return number of characters that would be written if the buffer is large enough, like snprintf(). */ -int osmo_gtlvs_encode_to_str_buf(char *buf, size_t buflen, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs) +int osmo_gtlvs_encode_to_str_buf(char *buf, size_t buflen, + const void *decoded_struct, size_t decoded_struct_max_len, unsigned int obj_ofs, + const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs) { struct osmo_strbuf sb = { .buf = buf, .len = buflen }; - void *obj = MEMB(decoded_struct, obj_ofs); + const void *obj = membof_const(decoded_struct, decoded_struct_max_len, obj_ofs); + size_t obj_maxlen = decoded_struct_max_len - obj_ofs; if (!ie_coding) return -ENOTSUP; for (; !osmo_gtlv_coding_end(ie_coding); ie_coding++) { - bool *presence_flag_p = ie_coding->has_presence_flag ? MEMB(obj, ie_coding->presence_flag_ofs) : NULL; - unsigned int *multi_count_p = ie_coding->has_count ? MEMB(obj, ie_coding->count_ofs) : NULL; + const bool *presence_flag_p = ie_coding->has_presence_flag ? + membof_const(obj, obj_maxlen, ie_coding->presence_flag_ofs) : NULL; + const unsigned int *multi_count_p = ie_coding->has_count ? + membof_const(obj, obj_maxlen, ie_coding->count_ofs) : NULL; unsigned int n; unsigned int i; @@ -527,12 +528,14 @@ if (ie_coding->nested_ies) { OSMO_STRBUF_PRINTF(sb, "{"); - OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, decoded_struct, obj_ofs + memb_ofs, + OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, + decoded_struct, decoded_struct_max_len, obj_ofs + memb_ofs, ie_coding->nested_ies, iei_strs); OSMO_STRBUF_PRINTF(sb, " }"); } else { if (ie_coding->enc_to_str_func) - OSMO_STRBUF_APPEND(sb, ie_coding->enc_to_str_func, MEMB(obj, memb_ofs)); + OSMO_STRBUF_APPEND(sb, ie_coding->enc_to_str_func, + membof_const(obj, obj_maxlen, memb_ofs)); else OSMO_STRBUF_PRINTF(sb, "(enc_to_str_func==NULL)"); } @@ -553,8 +556,10 @@ * \param[in] iei_strs value_string array to give IEI names in tag headers, or NULL. * \return human readable string. */ -char *osmo_gtlvs_encode_to_str_c(void *ctx, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs) +char *osmo_gtlvs_encode_to_str_c(void *ctx, + const void *decoded_struct, size_t decoded_struct_max_len, unsigned int obj_ofs, + const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs) { - OSMO_NAME_C_IMPL(ctx, 256, "ERROR", osmo_gtlvs_encode_to_str_buf, decoded_struct, obj_ofs, ie_coding, iei_strs) + OSMO_NAME_C_IMPL(ctx, 256, "ERROR", osmo_gtlvs_encode_to_str_buf, decoded_struct, decoded_struct_max_len, + obj_ofs, ie_coding, iei_strs) } diff --git a/src/libosmo-gtlv/gtlv_gen.c b/src/libosmo-gtlv/gtlv_gen.c index 3b2b1f0..e374ea9 100644 --- a/src/libosmo-gtlv/gtlv_gen.c +++ b/src/libosmo-gtlv/gtlv_gen.c @@ -397,7 +397,7 @@ "int %s_ies_encode_to_str(char *buf, size_t buflen, const union %s_ies *src,\n" " %s message_type, const struct value_string *iei_strs)\n" "{\n" - " return osmo_gtlvs_encode_to_str_buf(buf, buflen, src, 0, %s_get_msg_coding(message_type), iei_strs);\n" + " return osmo_gtlvs_encode_to_str_buf(buf, buflen, src, sizeof(*src), 0, %s_get_msg_coding(message_type), iei_strs);\n" "}\n", g_cfg->proto_name, g_cfg->proto_name, g_cfg->message_type_enum ? : "int", g_cfg->proto_name); } diff --git a/tests/libosmo-gtlv/gtlv_dec_enc_test.c b/tests/libosmo-gtlv/gtlv_dec_enc_test.c index a542cfa..f0de7b0 100644 --- a/tests/libosmo-gtlv/gtlv_dec_enc_test.c +++ b/tests/libosmo-gtlv/gtlv_dec_enc_test.c @@ -286,7 +286,7 @@ char *decoded_msg_to_str(const struct decoded_msg *m) { - return osmo_gtlvs_encode_to_str_c(ctx, m, 0, msg_ie_coding, tag_names); + return osmo_gtlvs_encode_to_str_c(ctx, m, sizeof(*m), 0, msg_ie_coding, tag_names); } diff --git a/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c b/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c index ef5372c..1997fdc 100644 --- a/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c +++ b/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c @@ -203,8 +203,8 @@ { struct osmo_strbuf sb = { .buf = buf, .len = buflen }; OSMO_STRBUF_PRINTF(sb, "%s={", get_value_string(myproto_msg_type_names, m->type)); - OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, &m->ies, 0, myproto_get_msg_coding(m->type), - myproto_iei_names); + OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, &m->ies, sizeof(m->ies), 0, + myproto_get_msg_coding(m->type), myproto_iei_names); OSMO_STRBUF_PRINTF(sb, " }"); return sb.chars_needed; diff --git a/tests/libosmo-gtlv/test_tliv/tliv_test.c b/tests/libosmo-gtlv/test_tliv/tliv_test.c index fd4e310..49ae25c 100644 --- a/tests/libosmo-gtlv/test_tliv/tliv_test.c +++ b/tests/libosmo-gtlv/test_tliv/tliv_test.c @@ -101,8 +101,8 @@ { struct osmo_strbuf sb = { .buf = buf, .len = buflen }; OSMO_STRBUF_PRINTF(sb, "%s={", get_value_string(myproto_msg_type_names, m->type)); - OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, &m->ies, 0, myproto_get_msg_coding(m->type), - myproto_iei_names); + OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, &m->ies, sizeof(m->ies), 0, + myproto_get_msg_coding(m->type), myproto_iei_names); OSMO_STRBUF_PRINTF(sb, " }"); return sb.chars_needed; -- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/29041 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: I63d52a4f5dba32d3a3887dd9c5e42e1695fb2aa3 Gerrit-Change-Number: 29041 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in libosmo-pfcp[master]: pfcp_cp_peer: check use count correctness
by neels 11 Aug '22

11 Aug '22
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/29038 ) Change subject: pfcp_cp_peer: check use count correctness ...................................................................... pfcp_cp_peer: check use count correctness Related: CID#275418 Change-Id: Id79a84312b3ff8d562e26a525866b8bb09f9d0bf --- M src/libosmo-pfcp/pfcp_cp_peer.c 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-pfcp refs/changes/38/29038/1 diff --git a/src/libosmo-pfcp/pfcp_cp_peer.c b/src/libosmo-pfcp/pfcp_cp_peer.c index 959206a..d900370 100644 --- a/src/libosmo-pfcp/pfcp_cp_peer.c +++ b/src/libosmo-pfcp/pfcp_cp_peer.c @@ -388,7 +388,7 @@ m->ctx.peer_use_count = &cp_peer->use_count; m->ctx.peer_use_token = (m->rx ? "PFCPrx" : "PFCPtx"); - osmo_use_count_get_put(m->ctx.peer_use_count, m->ctx.peer_use_token, 1); + OSMO_ASSERT(osmo_use_count_get_put(m->ctx.peer_use_count, m->ctx.peer_use_token, 1) == 0); } /* Allocate a new PFCP request message to be sent to cp_peer->remote_addr. */ -- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/29038 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: Id79a84312b3ff8d562e26a525866b8bb09f9d0bf Gerrit-Change-Number: 29038 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in libosmo-pfcp[master]: doc: minor fix in pfcp_cp_peer_fsm.dot
by neels 11 Aug '22

11 Aug '22
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/29037 ) Change subject: doc: minor fix in pfcp_cp_peer_fsm.dot ...................................................................... doc: minor fix in pfcp_cp_peer_fsm.dot Change-Id: I0de10d5331df128081d6b875e3ba9c0c3c32bd9f --- M doc/charts/pfcp_cp_peer_fsm.dot 1 file changed, 1 insertion(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-pfcp refs/changes/37/29037/1 diff --git a/doc/charts/pfcp_cp_peer_fsm.dot b/doc/charts/pfcp_cp_peer_fsm.dot index 101fe07..ec0d1fd 100644 --- a/doc/charts/pfcp_cp_peer_fsm.dot +++ b/doc/charts/pfcp_cp_peer_fsm.dot @@ -4,6 +4,7 @@ cp [label="CP function",shape="box"] +cp -> DISABLED [label="cp_peer_alloc()"] cp -> WAIT_ASSOC_SETUP_RESP [label="cp_peer_associate()"] txrx [label="PFCP socket",shape="box"] -- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/29037 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: I0de10d5331df128081d6b875e3ba9c0c3c32bd9f Gerrit-Change-Number: 29037 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in osmo-bts[master]: rsl: Reduce scope of variable
by pespin 11 Aug '22

11 Aug '22
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/29036 ) Change subject: rsl: Reduce scope of variable ...................................................................... rsl: Reduce scope of variable The function is length/complex enough, so having one extra strct in_addr declared the function top only used in one specific small path to print the variable is unnecesary. Let's move it to the conditional path where it is used to print the ip address. Change-Id: I4c16bbca6a6779537517b6b196828b47eddaa516 --- M src/common/rsl.c 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/36/29036/1 diff --git a/src/common/rsl.c b/src/common/rsl.c index 8cdb662..413c28d 100644 --- a/src/common/rsl.c +++ b/src/common/rsl.c @@ -2702,7 +2702,6 @@ int rc, inc_ip_port = 0; char *name; struct in_addr ia; - struct in_addr addr; if (dch->c.msg_type == RSL_MT_IPAC_CRCX) name = "CRCX"; @@ -2721,6 +2720,7 @@ LOGPLCHAN(lchan, DRSL, LOGL_DEBUG, "IPAC_%s: ", name); if (TLVP_PRES_LEN(&tp, RSL_IE_IPAC_REMOTE_IP, 4)) { + struct in_addr addr; connect_ip = tlvp_val32_unal(&tp, RSL_IE_IPAC_REMOTE_IP); addr.s_addr = connect_ip; LOGPC(DRSL, LOGL_DEBUG, "connect_ip=%s ", inet_ntoa(addr)); -- To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/29036 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bts Gerrit-Branch: master Gerrit-Change-Id: I4c16bbca6a6779537517b6b196828b47eddaa516 Gerrit-Change-Number: 29036 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in pysim[master]: Add new pySim.ota library, implement SIM OTA crypto
by laforge 11 Aug '22

11 Aug '22
Attention is currently required from: laforge, pespin, Christian Amsüss. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/29033 ) Change subject: Add new pySim.ota library, implement SIM OTA crypto ...................................................................... Set Ready For Review -- To view, visit https://gerrit.osmocom.org/c/pysim/+/29033 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I193ff4712c8503279c017b4b1324f0c3d38b9f84 Gerrit-Change-Number: 29033 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Christian Amsüss <chrysn(a)fsfe.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Attention: Christian Amsüss <chrysn(a)fsfe.org> Gerrit-Comment-Date: Thu, 11 Aug 2022 16:32:43 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: No Gerrit-MessageType: comment
1 0
0 0
Change in osmo-bts[master]: Use libosmocore API msgb_queue_free() to free lists
by pespin 11 Aug '22

11 Aug '22
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/29035 ) Change subject: Use libosmocore API msgb_queue_free() to free lists ...................................................................... Use libosmocore API msgb_queue_free() to free lists There's no need to maintain a duplicate msgb_queue_flush(), which returns the amount of freed messages (feature not used at all by the callers). Change-Id: I9841e18ca0b7b852130bbb02a510e43a3b3fd93f --- M include/osmo-bts/rsl.h M src/common/lchan.c M src/common/rsl.c M src/common/scheduler.c 4 files changed, 2 insertions(+), 17 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/35/29035/1 diff --git a/include/osmo-bts/rsl.h b/include/osmo-bts/rsl.h index dcd476c..a530734 100644 --- a/include/osmo-bts/rsl.h +++ b/include/osmo-bts/rsl.h @@ -4,8 +4,6 @@ #define LCHAN_FN_DUMMY 0xFFFFFFFF #define LCHAN_FN_WAIT 0xFFFFFFFE -int msgb_queue_flush(struct llist_head *list); - int down_rsl(struct gsm_bts_trx *trx, struct msgb *msg); int rsl_tx_rf_res(struct gsm_bts_trx *trx); int rsl_tx_chan_rqd(struct gsm_bts_trx *trx, struct gsm_time *gtime, diff --git a/src/common/lchan.c b/src/common/lchan.c index 83d20da..c7d8d45 100644 --- a/src/common/lchan.c +++ b/src/common/lchan.c @@ -638,6 +638,6 @@ { osmo_rtp_socket_free(lchan->abis_ip.rtp_socket); lchan->abis_ip.rtp_socket = NULL; - msgb_queue_flush(&lchan->dl_tch_queue); + msgb_queue_free(&lchan->dl_tch_queue); lchan->dl_tch_queue_len = 0; } diff --git a/src/common/rsl.c b/src/common/rsl.c index bcbe27c..8cdb662 100644 --- a/src/common/rsl.c +++ b/src/common/rsl.c @@ -88,19 +88,6 @@ } #define OSMO_IN_ARRAY(search, arr) osmo_in_array(search, arr, ARRAY_SIZE(arr)) -int msgb_queue_flush(struct llist_head *list) -{ - struct msgb *msg, *msg2; - int count = 0; - - llist_for_each_entry_safe(msg, msg2, list, list) { - msgb_free(msg); - count++; - } - - return count; -} - /* FIXME: move this to libosmocore */ void gsm48_gen_starting_time(uint8_t *out, struct gsm_time *gtime) { diff --git a/src/common/scheduler.c b/src/common/scheduler.c index 6564e5a..14aff34 100644 --- a/src/common/scheduler.c +++ b/src/common/scheduler.c @@ -659,7 +659,7 @@ struct l1sched_ts *l1ts = ts->priv; unsigned int i; - msgb_queue_flush(&l1ts->dl_prims); + msgb_queue_free(&l1ts->dl_prims); rate_ctr_group_free(l1ts->ctrs); l1ts->ctrs = NULL; -- To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/29035 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bts Gerrit-Branch: master Gerrit-Change-Id: I9841e18ca0b7b852130bbb02a510e43a3b3fd93f Gerrit-Change-Number: 29035 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in osmo-bts[master]: Avoid counting lchan->dl_tch_queue length every time a msg is enqueued
by pespin 11 Aug '22

11 Aug '22
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/29034 ) Change subject: Avoid counting lchan->dl_tch_queue length every time a msg is enqueued ...................................................................... Avoid counting lchan->dl_tch_queue length every time a msg is enqueued The queue_limit_to method iterates the entire list of messages every time a new message is added. Let's use msgb_{enqueue,dequeue}_count() APIs to do that in constant time. It is true that since the queue is limited to 1, there's usually at most 1 item in the queue so it's not a real problem. However, when we add Osmux in the future, we may need to tweak the amount of messages which can be in the list, due to Osmux batching mechansim which may be more bursty sometimes. In any case, this change doesn't make things worse for sure. The patch also takes the chance to group the queue_limit_to + enqueue into one function to avoid having the code spread several times. Change-Id: I61818a3bb521c27bd21a8b6fa70581d27638ec9b --- M include/osmo-bts/lchan.h M src/common/l1sap.c M src/common/lchan.c 3 files changed, 16 insertions(+), 19 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/34/29034/1 diff --git a/include/osmo-bts/lchan.h b/include/osmo-bts/lchan.h index c86acb0..64b7efa 100644 --- a/include/osmo-bts/lchan.h +++ b/include/osmo-bts/lchan.h @@ -191,6 +191,7 @@ uint8_t sapis_ul[23]; struct lapdm_channel lapdm_ch; struct llist_head dl_tch_queue; + unsigned int dl_tch_queue_len; struct { /* bitmask of all SI that are present/valid in si_buf */ uint32_t valid; diff --git a/src/common/l1sap.c b/src/common/l1sap.c index b74fd5a..d7b7abf 100644 --- a/src/common/l1sap.c +++ b/src/common/l1sap.c @@ -153,17 +153,16 @@ } /*! limit number of queue entries to %u; drops any surplus messages */ -static void queue_limit_to(const char *prefix, struct llist_head *queue, unsigned int limit) +static void lchan_dl_tch_queue_enqueue(struct gsm_lchan *lchan, struct msgb *msg, unsigned int limit) { - unsigned int count = llist_count(queue); - - if (count > limit) - LOGP(DL1P, LOGL_NOTICE, "%s: freeing %d queued frames\n", prefix, count-limit); - while (count > limit) { - struct msgb *tmp = msgb_dequeue(queue); + if (lchan->dl_tch_queue_len > limit) + LOGPLCHAN(lchan, DL1P, LOGL_NOTICE, "freeing %d queued frames\n", + lchan->dl_tch_queue_len - limit); + while (lchan->dl_tch_queue_len > limit) { + struct msgb *tmp = msgb_dequeue_count(&lchan->dl_tch_queue, &lchan->dl_tch_queue_len); msgb_free(tmp); - count--; } + msgb_enqueue_count(&lchan->dl_tch_queue, msg, &lchan->dl_tch_queue_len); } /* allocate a msgb containing a osmo_phsap_prim + optional l2 data @@ -915,7 +914,7 @@ uint8_t *p; /* de-queue response message (loopback) */ - loop_msg = msgb_dequeue(&lchan->dl_tch_queue); + loop_msg = msgb_dequeue_count(&lchan->dl_tch_queue, &lchan->dl_tch_queue_len); if (!loop_msg) { LOGPGT(DL1P, LOGL_NOTICE, tm, "%s: no looped PDTCH message, sending empty\n", gsm_lchan_name(lchan)); @@ -1305,7 +1304,7 @@ lchan->abis_ip.rtp_socket->rx_user_ts += GSM_RTP_DURATION; } /* get a msgb from the dl_tx_queue */ - resp_msg = msgb_dequeue(&lchan->dl_tch_queue); + resp_msg = msgb_dequeue_count(&lchan->dl_tch_queue, &lchan->dl_tch_queue_len); if (!resp_msg) { DEBUGPGT(DL1P, &g_time, "%s DL TCH Tx queue underrun\n", gsm_lchan_name(lchan)); resp_l1sap = &empty_l1sap; @@ -1500,8 +1499,7 @@ /* we are in loopback mode (for BER testing) * mode and need to enqeue the frame to be * returned in downlink */ - queue_limit_to(gsm_lchan_name(lchan), &lchan->dl_tch_queue, 1); - msgb_enqueue(&lchan->dl_tch_queue, msg); + lchan_dl_tch_queue_enqueue(lchan, msg, 1); /* Return 1 to signal that we're still using msg * and it should not be freed */ @@ -1622,10 +1620,8 @@ msg->data, msg->len, fn_ms_adj(fn, lchan), lchan->rtp_tx_marker); /* if loopback is enabled, also queue received RTP data */ if (lchan->loopback) { - /* make sure the queue doesn't get too long */ - queue_limit_to(gsm_lchan_name(lchan), &lchan->dl_tch_queue, 1); - /* add new frame to queue */ - msgb_enqueue(&lchan->dl_tch_queue, msg); + /* add new frame to queue, make sure the queue doesn't get too long */ + lchan_dl_tch_queue_enqueue(lchan, msg, 1); /* Return 1 to signal that we're still using msg and it should not be freed */ return 1; } @@ -1914,9 +1910,7 @@ rtpmsg_ts(msg) = timestamp; /* make sure the queue doesn't get too long */ - queue_limit_to(gsm_lchan_name(lchan), &lchan->dl_tch_queue, 1); - - msgb_enqueue(&lchan->dl_tch_queue, msg); + lchan_dl_tch_queue_enqueue(lchan, msg, 1); } static int l1sap_chan_act_dact_modify(struct gsm_bts_trx *trx, uint8_t chan_nr, diff --git a/src/common/lchan.c b/src/common/lchan.c index 6f344e2..83d20da 100644 --- a/src/common/lchan.c +++ b/src/common/lchan.c @@ -132,6 +132,7 @@ INIT_LLIST_HEAD(&lchan->sapi_cmds); INIT_LLIST_HEAD(&lchan->dl_tch_queue); + lchan->dl_tch_queue_len = 0; } void gsm_lchan_name_update(struct gsm_lchan *lchan) @@ -638,4 +639,5 @@ osmo_rtp_socket_free(lchan->abis_ip.rtp_socket); lchan->abis_ip.rtp_socket = NULL; msgb_queue_flush(&lchan->dl_tch_queue); + lchan->dl_tch_queue_len = 0; } -- To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/29034 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bts Gerrit-Branch: master Gerrit-Change-Id: I61818a3bb521c27bd21a8b6fa70581d27638ec9b Gerrit-Change-Number: 29034 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in pysim[master]: Add new pySim.ota library, implement SIM OTA crypto
by laforge 11 Aug '22

11 Aug '22
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/29033 ) Change subject: Add new pySim.ota library, implement SIM OTA crypto ...................................................................... Add new pySim.ota library, implement SIM OTA crypto This introduces a hierarchy of classes implementing * ETS TS 102 225 (general command structure) * 3GPP TS 31.115 (dialects for SMS-PP) In this initial patch only the SMS "dialect" is supported, but it is foreseen that USSD/SMSCB/HTTPS dialects can be added at a later point. Change-Id: I193ff4712c8503279c017b4b1324f0c3d38b9f84 --- A pySim/ota.py A tests/test_ota.py 2 files changed, 536 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/33/29033/1 diff --git a/pySim/ota.py b/pySim/ota.py new file mode 100644 index 0000000..4cac28d --- /dev/null +++ b/pySim/ota.py @@ -0,0 +1,451 @@ +"""Code related to SIM/UICC OTA according to TS 102 225 + TS 31.115.""" + +# (C) 2021-2022 by Harald Welte <laforge(a)osmocom.org> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from pySim.construct import * +from pySim.utils import b2h +from pySim.sms import UserDataHeader +from construct import * +from bidict import bidict +import zlib +import abc +import struct + +# ETS TS 102 225 gives the general command structure and the dialects for CAT_TP, TCP/IP and HTTPS +# 3GPP TS 31.115 gives the dialects for SMS-PP, SMS-CB, USSD and HTTP + +# CPI CPL CHI CHL SPI KIc KID TAR CNTR PCNTR RC/CC/DS data + +# CAT_TP TCP/IP SMS +# CPI 0x01 0x01 =IEIa=70,len=0 +# CHI NULL NULL NULL +# CPI, CPL and CHL included in RC/CC/DS true true +# RPI 0x02 0x02 =IEIa=71,len=0 +# RHI NULL NULL +# RPI, RPL and RHL included in RC/CC/DS true true +# packet-id 0-bf,ff 0-bf,ff +# identification packet false 102 225 tbl 6 + +# KVN 1..f; KI1=KIc, KI2=KID, KI3=DEK + +# TS 102 225 Table 5 +ota_status_codes = bidict({ + 0x00: 'PoR OK', + 0x01: 'RC/CC/DS failed', + 0x02: 'CNTR low', + 0x03: 'CNTR high', + 0x04: 'CNTR blocked', + 0x05: 'Ciphering error', + 0x06: 'Unidentified security error', + 0x07: 'Insufficient memory', + 0x08: 'more time', + 0x09: 'TAR unknown', + 0x0a: 'Insufficient security level', + 0x0b: 'Actual Response in SMS-SUBMIT', # 31.115 + 0x0c: 'Actual Response in USSD', # 31.115 +}) + +# ETSI TS 102 225 Table 5 + 3GPP TS 31.115 Section 7 +ResponseStatus = Enum(Int8ub, por_ok=0, rc_cc_ds_failed=1, cntr_low=2, cntr_high=3, + cntr_blocked=4, ciphering_error=5, undefined_security_error=6, + insufficient_memory=7, more_time_needed=8, tar_unknown=9, + insufficient_security_level=0x0A, + actual_response_sms_submit=0x0B, + actual_response_ussd=0x0C) + +# ETSI TS 102 226 Section 5.1.2 +CompactRemoteResp = Struct('number_of_commands'/Int8ub, + 'last_status_word'/HexAdapter(Bytes(2)), + 'last_response_data'/HexAdapter(GreedyBytes)) + +RC_CC_DS = Enum(BitsInteger(2), no_rc_cc_ds=0, rc=1, cc=2, ds=3) + +# TS 102 225 Section 5.1.1 + TS 31.115 Section 4.2 +SPI = BitStruct( # first octet + Padding(3), + 'counter'/Enum(BitsInteger(2), no_counter=0, counter_no_replay_or_seq=1, + counter_must_be_higher=2, counter_must_be_lower=3), + 'ciphering'/Flag, + 'rc_cc_ds'/RC_CC_DS, + # second octet + Padding(2), + 'por_in_submit'/Flag, + 'por_shall_be_ciphered'/Flag, + 'por_rc_cc_ds'/RC_CC_DS, + 'por'/Enum(BitsInteger(2), no_por=0, + por_required=1, por_only_when_error=2) +) + +# TS 102 225 Section 5.1.2 +KIC = BitStruct('key'/BitsInteger(4), + 'algo'/Enum(BitsInteger(4), implicit=0, single_des=1, triple_des_cbc2=5, triple_des_cbc3=9, + aes_cbc=2) + ) + +# TS 102 225 Section 5.1.3.1 +KID_CC = BitStruct('key'/BitsInteger(4), + 'algo'/Enum(BitsInteger(4), implicit=0, single_des=1, triple_des_cbc2=5, triple_des_cbc3=9, + aes_cmac=2) + ) + +# TS 102 225 Section 5.1.3.2 +KID_RC = BitStruct('key'/BitsInteger(4), + 'algo'/Enum(BitsInteger(4), implicit=0, crc16=1, crc32=5, proprietary=3) + ) + +SmsCommandPacket = Struct('cmd_pkt_len'/Int16ub, + 'cmd_hdr_len'/Int8ub, + 'spi'/SPI, + 'kic'/KIC, + 'kid'/Switch(this.spi.rc_cc_ds, {'cc': KID_CC, 'rc': KID_RC }), + 'tar'/Bytes(3), + 'secured_data'/GreedyBytes) + +class OtaKeyset: + """The OTA related data (key material, counter) to be used in encrypt/decrypt.""" + def __init__(self, algo_crypt: str, kic_idx: int, kic: bytes, + algo_auth: str, kid_idx: int, kid: bytes, cntr: int = 0): + self.algo_crypt = algo_crypt + self.kic = bytes(kic) + self.kic_idx = kic_idx + self.algo_auth = algo_auth + self.kid = bytes(kid) + self.kid_idx = kid_idx + self.cntr = cntr + + @property + def auth(self): + """Return an instance of the matching OtaAlgoAuth.""" + return OtaAlgoAuth.fromKeyset(self) + + @property + def crypt(self): + """Return an instance of the matching OtaAlgoCrypt.""" + return OtaAlgoCrypt.fromKeyset(self) + +class OtaCheckError(Exception): + pass + +class OtaDialect(abc.ABC): + """Base Class for OTA dialects such as SMS, BIP, ...""" + + def _compute_sig_len(self, spi:SPI): + if spi['rc_cc_ds'] == 'no_rc_cc_ds': + return 0 + elif spi['rc_cc_ds'] == 'rc': # CRC-32 + return 4 + elif spi['rc_cc_ds'] == 'cc': # Cryptographic Checksum (CC) + # TODO: this is not entirely correct, as in AES case it could be 4 or 8 + return 8 + else: + raise ValueError("Invalid rc_cc_ds: %s" % spi['rc_cc_ds']) + + @abc.abstractmethod + def encode_cmd(self, otak: OtaKeyset, tar: bytes, apdu: bytes) -> bytes: + pass + + @abc.abstractmethod + def decode_resp(self, otak: OtaKeyset, apdu: bytes) -> bytes: + pass + + +from Cryptodome.Cipher import DES, DES3, AES +from Cryptodome.Hash import CMAC + +class OtaAlgo(abc.ABC): + iv = b'\x00\x00\x00\x00\x00\x00\x00\x00' + blocksize = None + + @staticmethod + def _get_padding(in_len: int, multiple: int, padding: int = 0): + """Return padding bytes towards multiple of N.""" + if in_len % multiple == 0: + return b'' + pad_cnt = multiple - (in_len % multiple) + return b'\x00' * pad_cnt + + @staticmethod + def _pad_to_multiple(indat: bytes, multiple: int, padding: int = 0): + """Pad input bytes to multiple of N.""" + return indat + OtaAlgo._get_padding(len(indat), multiple, padding) + + def pad_to_blocksize(self, indat: bytes, padding: int = 0): + """Pad the given input data to multiple of the cipher block size.""" + return self._pad_to_multiple(indat, self.blocksize, padding) + + def __init__(self, otak: OtaKeyset): + self.otak = otak + + def __str__(self): + return self.__class__.__name__ + +class OtaAlgoCrypt(OtaAlgo, abc.ABC): + def __init__(self, otak: OtaKeyset): + if self.enum_name != otak.algo_crypt: + raise ValueError('Cannot use algorithm %s with key for %s' % (self.enum_name, otak.algo_crypt)) + super().__init__(otak) + + def encrypt(self, data:bytes) -> bytes: + """Encrypt given input bytes using the key material given in constructor.""" + padded_data = self.pad_to_blocksize(data) + return self._encrypt(data) + + def decrypt(self, data:bytes) -> bytes: + """Decrypt given input bytes using the key material given in constructor.""" + return self._decrypt(data) + + @abc.abstractmethod + def _encrypt(self, data:bytes) -> bytes: + """Actual implementation, to be implemented by derived class.""" + pass + + @abc.abstractmethod + def _decrypt(self, data:bytes) -> bytes: + """Actual implementation, to be implemented by derived class.""" + pass + + @classmethod + def fromKeyset(cls, otak: OtaKeyset) -> 'OtaAlgoCrypt': + """Resolve the class for the encryption algorithm of otak and instantiate it.""" + for subc in cls.__subclasses__(): + if subc.enum_name == otak.algo_crypt: + return subc(otak) + raise ValueError('No implementation for crypt algorithm %s' % otak.algo_auth) + +class OtaAlgoAuth(OtaAlgo, abc.ABC): + def __init__(self, otak: OtaKeyset): + if self.enum_name != otak.algo_auth: + raise ValueError('Cannot use algorithm %s with key for %s' % (self.enum_name, otak.algo_crypt)) + super().__init__(otak) + + def sign(self, data:bytes) -> bytes: + """Compute the CC/CR check bytes for the input data using key material + given in constructor.""" + padded_data = self.pad_to_blocksize(data) + sig = self._sign(padded_data) + return sig + + def check_sig(self, data:bytes, cc_received:bytes): + """Compute the CC/CR check bytes for the input data and compare against cc_received.""" + cc = self.sign(data) + if cc_received != cc: + raise OtaCheckError('Received CC (%s) != Computed CC (%s)' % (b2h(cc_received), b2h(cc))) + + @abc.abstractmethod + def _sign(self, data:bytes) -> bytes: + """Actual implementation, to be implemented by derived class.""" + pass + + @classmethod + def fromKeyset(cls, otak: OtaKeyset) -> 'OtaAlgoAuth': + """Resolve the class for the authentication algorithm of otak and instantiate it.""" + for subc in cls.__subclasses__(): + if subc.enum_name == otak.algo_auth: + return subc(otak) + raise ValueError('No implementation for auth algorithm %s' % otak.algo_auth) + +class OtaAlgoCryptDES(OtaAlgoCrypt): + """DES is insecure. For backwards compatibility with pre-Rel8""" + name = 'DES' + enum_name = 'single_des' + blocksize = 8 + def _encrypt(self, data:bytes) -> bytes: + cipher = DES.new(self.otak.kic, DES.MODE_CBC, self.iv) + return cipher.encrypt(data) + + def _decrypt(self, data:bytes) -> bytes: + cipher = DES.new(self.otak.kic, DES.MODE_CBC, self.iv) + return cipher.decrypt(data) + +class OtaAlgoAuthDES(OtaAlgoAuth): + """DES is insecure. For backwards compatibility with pre-Rel8""" + name = 'DES' + enum_name = 'single_des' + blocksize = 8 + def _sign(self, data:bytes) -> bytes: + cipher = DES.new(self.otak.kid, DES.MODE_CBC, self.iv) + ciph = cipher.encrypt(data) + return ciph[len(ciph) - 8:] + +class OtaAlgoCryptDES3(OtaAlgoCrypt): + name = '3DES' + enum_name = 'triple_des_cbc2' + blocksize = 8 + def _encrypt(self, data:bytes) -> bytes: + cipher = DES3.new(self.otak.kic, DES3.MODE_CBC, self.iv) + return cipher.encrypt(data) + + def _decrypt(self, data:bytes) -> bytes: + cipher = DES3.new(self.otak.kic, DES3.MODE_CBC, self.iv) + return cipher.decrypt(data) + +class OtaAlgoAuthDES3(OtaAlgoAuth): + name = '3DES' + enum_name = 'triple_des_cbc2' + blocksize = 8 + def _sign(self, data:bytes) -> bytes: + cipher = DES3.new(self.otak.kid, DES3.MODE_CBC, self.iv) + ciph = cipher.encrypt(data) + return ciph[len(ciph) - 8:] + +class OtaAlgoCryptAES(OtaAlgoCrypt): + name = 'AES' + enum_name = 'aes_cbc' + blocksize = 16 # TODO: is this needed? + def _encrypt(self, data:bytes) -> bytes: + cipher = AES.new(self.otak.kic, AES.MODE_CBC, self.iv) + return cipher.encrypt(data) + + def _decrypt(self, data:bytes) -> bytes: + cipher = AES.new(self.otak.kic, AES.MODE_CBC, self.iv) + return cipher.decrypt(data) + +class OtaAlgoAuthAES(OtaAlgoAuth): + name = 'AES' + enum_name = 'aes_cmac' + blocksize = 16 # TODO: is this needed? + def _sign(self, data:bytes) -> bytes: + cmac = CMAC.new(self.otak.kid, ciphermod=AES, mac_len=8) + cmac.update(data) + ciph = cmac.digest() + return ciph[len(ciph) - 8:] + + + +class OtaDialectSms(OtaDialect): + """OTA dialect for SMS based transport, as described in 3GPP TS 31.115.""" + SmsResponsePacket = Struct('rpl'/Int16ub, + 'rhl'/Int8ub, + 'tar'/Bytes(3), + 'cntr'/Bytes(5), + 'pcntr'/Int8ub, + 'response_status'/ResponseStatus, + 'cc_rc'/Bytes(this.rhl-10), + 'secured_data'/GreedyBytes) + + def encode_cmd(self, otak: OtaKeyset, tar: bytes, spi: dict, apdu: bytes) -> bytes: + # length of signature in octets + len_sig = self._compute_sig_len(spi) + pad_cnt = 0 + if spi['ciphering']: # ciphering is requested + # append padding bytes to end up with blocksize + len_cipher = 6 + len_sig + len(apdu) + apdu += otak.crypt._get_padding(len_cipher, otak.crypt.blocksize) + + kic = {'key': otak.kic_idx, 'algo': otak.algo_crypt} + kid = {'key': otak.kid_idx, 'algo': otak.algo_auth} + + # CHL = number of octets from (and including) SPI to the end of RC/CC/DS + # 13 == SPI(2) + KIc(1) + KId(1) + TAR(3) + CNTR(5) + PCNTR(1) + chl = 13 + len_sig + + # CHL + SPI (+ KIC + KID) + c = Struct('chl'/Int8ub, 'spi'/SPI, 'kic'/KIC, 'kid'/KID_CC, 'tar'/Bytes(3)) + part_head = c.build({'chl': chl, 'spi':spi, 'kic':kic, 'kid':kid, 'tar':tar}) + #print("part_head: %s" % b2h(part_head)) + + # CNTR + PCNTR (CNTR not used) + part_cnt = otak.cntr.to_bytes(5, 'big') + pad_cnt.to_bytes(1, 'big') + #print("part_cnt: %s" % b2h(part_cnt)) + + envelope_data = part_head + part_cnt + apdu + #print("envelope_data: %s" % b2h(envelope_data)) + + # 2-byte CPL. CPL is part of RC/CC/CPI to end of secured data, including any padding for ciphering + # CPL from and including CPI to end of secured data, including any padding for ciphering + cpl = len(envelope_data) + len_sig + envelope_data = cpl.to_bytes(2, 'big') + envelope_data + #print("envelope_data with cpl: %s" % b2h(envelope_data)) + + if spi['rc_cc_ds'] == 'cc': + cc = otak.auth.sign(envelope_data) + envelope_data = part_cnt + cc + apdu + elif spi['rc_cc_ds'] == 'rc': + # CRC32 + crc32 = zlib.crc32(envelope_data) & 0xffffffff + envelope_data = part_cnt + crc32.to_bytes(4, 'big') + apdu + elif spi['rc_cc_ds'] == 'no_rc_cc_ds': + envelope_data = part_cnt + apdu + else: + raise ValueError("Invalid rc_cc_ds: %s" % spi['rc_cc_ds']) + + #print("envelope_data with sig: %s" % b2h(envelope_data)) + + # encrypt as needed + if spi['ciphering']: # ciphering is requested + ciph = otak.crypt.encrypt(envelope_data) + envelope_data = part_head + ciph + # prefix with another CPL + cpl = len(envelope_data) + envelope_data = cpl.to_bytes(2, 'big') + envelope_data + else: + envelope_data = part_head + envelope_data + + #print("envelope_data: %s" % b2h(envelope_data)) + + return envelope_data + + def decode_resp(self, otak: OtaKeyset, spi: dict, data: bytes) -> bytes: + if isinstance(data, str): + data = h2b(data) + # plain-text POR: 027100000e0ab000110000000000000001612f + # UDHL RPI IEDLa RPL RHL TAR CNTR PCNTR STS + # 02 71 00 000e 0a b00011 0000000000 00 00 01 612f + # POR with CC: 027100001612b000110000000000000055f47118381175fb01612f + # POR with CC+CIPH: 027100001c12b000119660ebdb81be189b5e4389e9e7ab2bc0954f963ad869ed7c + if data[0] != 0x02: + raise ValueError('Unexpected UDL=0x%02x' % data[0]) + udhd, remainder = UserDataHeader.fromBytes(data) + if not udhd.has_ie(0x71): + raise ValueError('RPI 0x71 not found in UDH') + rph_rhl_tar = remainder[:6] # RPH+RHL+TAR; not ciphered + res = self.SmsResponsePacket.parse(remainder) + + if spi['por_shall_be_ciphered']: + # decrypt + ciphered_part = remainder[6:] + deciph = otak.crypt.decrypt(ciphered_part) + temp_data = rph_rhl_tar + deciph + res = self.SmsResponsePacket.parse(temp_data) + # remove specified number of padding bytes, if any + if res['pcntr'] != 0: + # this conditional is needed as python [:-0] renders an empty return! + res['secured_data'] = res['secured_data'][:-res['pcntr']] + remainder = temp_data + + # is there a CC/RC present? + len_sig = res['rhl'] - 10 + if spi['por_rc_cc_ds'] == 'no_rc_cc_ds': + if len_sig: + raise OtaCheckError('No RC/CC/DS requested, but len_sig=%u' % len_sig) + elif spi['por_rc_cc_ds'] == 'cc': + # verify signature + # UDH is part of CC/RC! + udh = data[:3] + # RPL, RHL, TAR, CNTR, PCNTR and STSare part of CC/RC + rpl_rhl_tar_cntr_pcntr_sts = remainder[:13] + # remove the CC/RC bytes + temp_data = udh + rpl_rhl_tar_cntr_pcntr_sts + remainder[13+len_sig:] + cc = otak.auth.check_sig(temp_data, res['cc_rc']) + # TODO: CRC + else: + raise OtaCheckError('Unknown por_rc_cc_ds: %s' % spi['por_rc_cc_ds']) + + # TODO: ExpandedRemoteResponse according to TS 102 226 5.2.2 + dec = CompactRemoteResp.parse(res['secured_data']) + dec['tar'] = res['tar'] + dec['response_status'] = res['response_status'] + return dec diff --git a/tests/test_ota.py b/tests/test_ota.py new file mode 100644 index 0000000..e8f56f8 --- /dev/null +++ b/tests/test_ota.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 + +import unittest +from pySim.utils import h2b, b2h +from pySim.ota import * + +class Test_SMS_3DES(unittest.TestCase): + tar = h2b('b00000') + """Test the OtaDialectSms for 3DES algorithms.""" + def __init__(self, foo, **kwargs): + super().__init__(foo, **kwargs) + # KIC1 + KID1 of 8988211000000467285 + KIC1 = h2b('D0FDA31990D8D64178601317191669B4') + KID1 = h2b('D24EB461799C5E035C77451FD9404463') + KIC3 = h2b('C21DD66ACAC13CB3BC8B331B24AFB57B') + KID3 = h2b('12110C78E678C25408233076AA033615') + self.od = OtaKeyset(algo_crypt='triple_des_cbc2', kic_idx=3, kic=KIC3, + algo_auth='triple_des_cbc2', kid_idx=3, kid=KID3) + self.dialect = OtaDialectSms() + self.spi_base = { + 'counter':'no_counter', + 'ciphering': True, + 'rc_cc_ds': 'cc', + 'por_in_submit':False, + 'por': 'por_required', + 'por_shall_be_ciphered': True, + 'por_rc_cc_ds': 'cc', + } + + def _check_response(self, r): + self.assertEqual(r['number_of_commands'], 1) + self.assertEqual(r['last_status_word'], '612f') + self.assertEqual(r['last_response_data'], u'') + self.assertEqual(r['response_status'], 'por_ok') + + def test_resp_3des_ciphered(self): + spi = self.spi_base + spi['por_shall_be_ciphered'] = True + spi['por_rc_cc_ds'] = 'cc' + r = self.dialect.decode_resp(self.od, spi, '027100001c12b000119660ebdb81be189b5e4389e9e7ab2bc0954f963ad869ed7c') + self._check_response(r) + + def test_resp_3des_signed(self): + spi = self.spi_base + spi['por_shall_be_ciphered'] = False + spi['por_rc_cc_ds'] = 'cc' + r = self.dialect.decode_resp(self.od, spi, '027100001612b000110000000000000055f47118381175fb01612f') + self._check_response(r) + + def test_resp_3des_signed_err(self): + """Expect an OtaCheckError exception if the computed CC != received CC""" + spi = self.spi_base + spi['por_shall_be_ciphered'] = False + spi['por_rc_cc_ds'] = 'cc' + with self.assertRaises(OtaCheckError) as context: + r = self.dialect.decode_resp(self.od, spi, '027100001612b000110000000000000055f47118381175fb02612f') + self.assertTrue('!= Computed CC' in str(context.exception)) + + def test_resp_3des_none(self): + spi = self.spi_base + spi['por_shall_be_ciphered'] = False + spi['por_rc_cc_ds'] = 'no_rc_cc_ds' + r = self.dialect.decode_resp(self.od, spi, '027100000e0ab000110000000000000001612f') + self._check_response(r) + + def test_cmd_3des_ciphered(self): + spi = self.spi_base + spi['ciphering'] = True + spi['rc_cc_ds'] = 'no_rc_cc_ds' + r = self.dialect.encode_cmd(self.od, self.tar, spi, h2b('00a40000023f00')) + self.assertEqual(b2h(r), '00180d04193535b000000c8478b552a4ffc5a8f099b83cad7123') + + def test_cmd_3des_signed(self): + spi = self.spi_base + spi['ciphering'] = False + spi['rc_cc_ds'] = 'cc' + r = self.dialect.encode_cmd(self.od, self.tar, spi, h2b('00a40000023f00')) + self.assertEqual(b2h(r), '1502193535b00000000000000000072ea17bdb72060e00a40000023f00') + + def test_cmd_3des_none(self): + spi = self.spi_base + spi['ciphering'] = False + spi['rc_cc_ds'] = 'no_rc_cc_ds' + r = self.dialect.encode_cmd(self.od, self.tar, spi, h2b('00a40000023f00')) + self.assertEqual(b2h(r), '0d00193535b0000000000000000000a40000023f00') -- To view, visit https://gerrit.osmocom.org/c/pysim/+/29033 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I193ff4712c8503279c017b4b1324f0c3d38b9f84 Gerrit-Change-Number: 29033 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
Change in osmo-bts[master]: Split out lchan rtp socket creation from rsl handling code
by dexter 11 Aug '22

11 Aug '22
Attention is currently required from: pespin. dexter has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bts/+/29032 ) Change subject: Split out lchan rtp socket creation from rsl handling code ...................................................................... Patch Set 2: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/29032 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bts Gerrit-Branch: master Gerrit-Change-Id: Iade43fde7f6113f9d68539f7d6cc9843783c2b3f Gerrit-Change-Number: 29032 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Thu, 11 Aug 2022 15:32:46 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
Change in osmo-bts[master]: Split out lchan rtp socket creation from rsl handling code
by fixeria 11 Aug '22

11 Aug '22
Attention is currently required from: pespin. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bts/+/29032 ) Change subject: Split out lchan rtp socket creation from rsl handling code ...................................................................... Patch Set 2: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/29032 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bts Gerrit-Branch: master Gerrit-Change-Id: Iade43fde7f6113f9d68539f7d6cc9843783c2b3f Gerrit-Change-Number: 29032 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Thu, 11 Aug 2022 14:44:16 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • ...
  • 241
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.