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 -----
  • December
  • 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 2023

  • 1 participants
  • 1514 discussions
[S] Change in pysim[master]: sim-rest-server: use UiccCardBase instead of UsimCard
by laforge 21 Aug '23

21 Aug '23
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/34153 ) Change subject: sim-rest-server: use UiccCardBase instead of UsimCard ...................................................................... sim-rest-server: use UiccCardBase instead of UsimCard The class UsimCard is deprecated and only still used in very old legacy applications. let's use the more modern UiccCardBase class instead. Related: RT#67094 Change-Id: I3676f033833665751c0d953176eafe175b20c14a --- M contrib/sim-rest-server.py 1 file changed, 16 insertions(+), 2 deletions(-) Approvals: laforge: Looks good to me, approved osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/contrib/sim-rest-server.py b/contrib/sim-rest-server.py index ccf4430..9f31168 100755 --- a/contrib/sim-rest-server.py +++ b/contrib/sim-rest-server.py @@ -26,7 +26,7 @@ from pySim.transport import ApduTracer from pySim.transport.pcsc import PcscSimLink from pySim.commands import SimCardCommands -from pySim.cards import UsimCard +from pySim.cards import UiccCardBase from pySim.exceptions import * class ApduPrintTracer(ApduTracer): @@ -39,7 +39,7 @@ tp.connect() scc = SimCardCommands(tp) - card = UsimCard(scc) + card = UiccCardBase(scc) # this should be part of UsimCard, but FairewavesSIM breaks with that :/ scc.cla_byte = "00" -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34153 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I3676f033833665751c0d953176eafe175b20c14a Gerrit-Change-Number: 34153 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: cards: get rid of method read_iccid
by laforge 21 Aug '23

21 Aug '23
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/34151 ) Change subject: cards: get rid of method read_iccid ...................................................................... cards: get rid of method read_iccid The method read_iccid in class CardBase should be put back to legacy/cards.py. The reason for this is that it falls in the same category like read_imsi, read_ki, etc. We should not use those old methods in future programs since we have a more modern infrastructure (lchan) now. Also pySim-shell.py is the only caller of this method now. It is not used in any other place. Related: RT#67094 Change-Id: Ied3ae6fd107992abcc1b5ea3edb0eb4bdcd2f892 --- M pySim-shell.py M pySim/cards.py M pySim/legacy/cards.py 3 files changed, 32 insertions(+), 11 deletions(-) Approvals: laforge: Looks good to me, approved osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/pySim-shell.py b/pySim-shell.py index 2727a5b..af7dbca 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -52,7 +52,7 @@ from pySim.transport import init_reader, ApduTracer, argparse_add_reader_args, ProactiveHandler from pySim.cards import card_detect, SimCardBase, UiccCardBase from pySim.utils import h2b, b2h, i2h, swap_nibbles, rpad, JsonEncoder, bertlv_parse_one, sw_match -from pySim.utils import sanitize_pin_adm, tabulate_str_list, boxed_heading_str, Hexstr +from pySim.utils import sanitize_pin_adm, tabulate_str_list, boxed_heading_str, Hexstr, dec_iccid from pySim.card_handler import CardHandler, CardHandlerAuto from pySim.filesystem import CardDF, CardADF, CardModel, CardApplication @@ -240,7 +240,10 @@ self.register_command_set(Iso7816Commands()) self.register_command_set(Ts102222Commands()) self.register_command_set(PySimCommands()) - self.iccid, sw = self.card.read_iccid() + + self.lchan.select('MF/EF.ICCID', self) + self.iccid = dec_iccid(self.lchan.read_binary()[0]) + self.lchan.select('MF', self) rc = True else: diff --git a/pySim/cards.py b/pySim/cards.py index c87c488..b1adcf2 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -23,7 +23,7 @@ # from typing import Optional, Dict, Tuple -from pySim.ts_102_221 import EF_DIR, EF_ICCID +from pySim.ts_102_221 import EF_DIR from pySim.ts_51_011 import DF_GSM from pySim.transport import LinkBase import abc @@ -69,14 +69,6 @@ # callers having to do hasattr('read_aids') ahead of every call. return [] - def read_iccid(self) -> Tuple[Optional[Hexstr], SwHexstr]: - ef_iccid = EF_ICCID() - (res, sw) = self._scc.read_binary(ef_iccid.fid) - if sw == '9000': - return (dec_iccid(res), sw) - else: - return (None, sw) - class SimCardBase(CardBase): """Here we only add methods for commands specified in TS 51.011, without diff --git a/pySim/legacy/cards.py b/pySim/legacy/cards.py index e64b5c3..496ce78 100644 --- a/pySim/legacy/cards.py +++ b/pySim/legacy/cards.py @@ -59,6 +59,13 @@ (res, sw) = self._scc.verify_chv(self._adm_chv_num, key) return sw + def read_iccid(self): + (res, sw) = self._scc.read_binary(EF['ICCID']) + if sw == '9000': + return (dec_iccid(res), sw) + else: + return (None, sw) + def update_iccid(self, iccid): data, sw = self._scc.update_binary(EF['ICCID'], enc_iccid(iccid)) return sw -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34151 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: Ied3ae6fd107992abcc1b5ea3edb0eb4bdcd2f892 Gerrit-Change-Number: 34151 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: sim-rest-server: do not select ADF.USIM in connect_to_card
by laforge 21 Aug '23

21 Aug '23
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/34152 ) Change subject: sim-rest-server: do not select ADF.USIM in connect_to_card ...................................................................... sim-rest-server: do not select ADF.USIM in connect_to_card When the function connect_to_card is done, it selects ADF.USIM. This might be contraproductive in case someone needs to access files on MF level in one of the REST methods. Instead fo ADF.USIM, let's use MF as a common ground to start from. At the moment the only existing REST (info, auth) immediately select ADF.USIM after calling connect_to_card already, so there are no further modifications necessary. Related: RT#67094 Change-Id: I16e7f3c991c83f81989ecc4e4764bb6cc799c01d --- M contrib/sim-rest-server.py 1 file changed, 22 insertions(+), 1 deletion(-) Approvals: laforge: Looks good to me, approved osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/contrib/sim-rest-server.py b/contrib/sim-rest-server.py index f2ed63e..ccf4430 100755 --- a/contrib/sim-rest-server.py +++ b/contrib/sim-rest-server.py @@ -46,7 +46,9 @@ scc.sel_ctrl = "0004" card.read_aids() - card.select_adf_by_aid(adf='usim') + + # ensure that MF is selected when we are done. + card._scc.select_file('3f00') return tp, scc, card -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34152 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I16e7f3c991c83f81989ecc4e4764bb6cc799c01d Gerrit-Change-Number: 34152 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
[S] Change in osmo-tetra[master]: Fixups and clarifying comments for msgb tail modifications
by laforge 21 Aug '23

21 Aug '23
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-tetra/+/34000 ) Change subject: Fixups and clarifying comments for msgb tail modifications ...................................................................... Fixups and clarifying comments for msgb tail modifications Added fixups for msgb len field whenever the tail is modified Also, added some clarifying comments Change-Id: Ia725edbeafe26bd2ea9b5a1810d0b26bc79d84db --- M src/lower_mac/tetra_lower_mac.c M src/tetra_llc.c M src/tetra_upper_mac.c 3 files changed, 30 insertions(+), 9 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/src/lower_mac/tetra_lower_mac.c b/src/lower_mac/tetra_lower_mac.c index 21998f7..f8e7810 100644 --- a/src/lower_mac/tetra_lower_mac.c +++ b/src/lower_mac/tetra_lower_mac.c @@ -325,23 +325,26 @@ int pdu_bits = 0; uint32_t offset = 0; - uint8_t *orig_head = msg->head; - uint8_t *orig_tail = msg->tail; + uint8_t *orig_head = msg->head; /* The true start of the timeslot */ + uint8_t *orig_tail = msg->tail; /* The true end of the timeslot */ while (offset < tbp->type1_bits - 16) { /* send Rx time along with the TMV-UNITDATA.ind primitive */ memcpy(&tup->tdma_time, &tcd->time, sizeof(tup->tdma_time)); + + /* Parse MAC element in timeslot (just one, possibly more later in the loop) */ pdu_bits = upper_mac_prim_recv(&ttp->oph, tms); - if (pdu_bits < 0) { - /* -1 is returned when pdu fills slot or length could not be determined */ + /* Check if we are done (-1 returned) */ + if (pdu_bits < 0) break; - } - /* Increment head and l1h ptrs and reset tail to end of msg (may be altered by removing FCS) */ + /* Not done */ + /* Increment head and l1h ptrs */ + /* Reset tail to end of msg (may be altered by removing FCS) */ offset += pdu_bits; - msg->head = orig_head + offset; - msg->tail = orig_tail; - msg->len = msg->tail - msg->head; + msg->head = orig_head + offset; /* New head is old head plus parsed len from prev msg */ + msg->tail = orig_tail; /* Restore original tail */ + msg->len = msg->tail - msg->head; /* Fixup len */ msg->l1h = msg->head; msg->l2h = 0; msg->l3h = 0; diff --git a/src/tetra_llc.c b/src/tetra_llc.c index b8a378d..cdbfea0 100644 --- a/src/tetra_llc.c +++ b/src/tetra_llc.c @@ -122,6 +122,7 @@ tetra_llc_pdu_parse(&lpp, msg->l2h, len); msg->l3h = lpp.tl_sdu; msg->tail = msg->l3h + lpp.tl_sdu_len; // Strips off FCS (if present) + msg->len = msg->tail - msg->head; printf("TM-SDU(%s)", tetra_get_llc_pdut_dec_name(lpp.pdu_type)); if (lpp.have_fcs) { diff --git a/src/tetra_upper_mac.c b/src/tetra_upper_mac.c index 94a58ce..3b2092b 100644 --- a/src/tetra_upper_mac.c +++ b/src/tetra_upper_mac.c @@ -175,12 +175,14 @@ } else { pdu_bits = rsd.macpdu_length * 8; /* Length given */ msg->tail = msg->head + pdu_bits; + msg->len = msg->tail - msg->head; } /* Strip fill bits */ if (rsd.fill_bits) { int num_fill_bits = get_num_fill_bits(msg->l1h, msgb_l1len(msg)); msg->tail -= num_fill_bits; + msg->len = msg->tail - msg->head; } /* Decrypt buffer if encrypted and key available */ @@ -301,6 +303,7 @@ if (fillbits_present) { int num_fill_bits = get_num_fill_bits(msg->l1h, msgb_l1len(msg)); msg->tail -= num_fill_bits; + msg->len = msg->tail - msg->head; } /* Decrypt (if required) */ @@ -349,9 +352,11 @@ /* Determine msg len, strip fill bits if any */ msg->tail = msg->head + length_indicator * 8; + msg->len = msg->tail - msg->head; if (fillbits_present) { num_fill_bits = get_num_fill_bits(msg->l1h, msgb_l1len(msg)); msg->tail -= num_fill_bits; + msg->len = msg->tail - msg->head; } /* Decrypt (if required) */ -- To view, visit https://gerrit.osmocom.org/c/osmo-tetra/+/34000 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-tetra Gerrit-Branch: master Gerrit-Change-Id: Ia725edbeafe26bd2ea9b5a1810d0b26bc79d84db Gerrit-Change-Number: 34000 Gerrit-PatchSet: 3 Gerrit-Owner: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[M] Change in osmo-tetra[master]: Added functions that prepare for decryption
by laforge 21 Aug '23

21 Aug '23
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-tetra/+/34001 ) Change subject: Added functions that prepare for decryption ...................................................................... Added functions that prepare for decryption Added functions that will eventually allow for mac resource decryption, voice/traffic decryption and identity decryption. Calls to the true TEA keystream generator functions and TA61 identity decryption function will need to be added in a later patch. Change-Id: I4e6147f206ad6046f32e08015ec9721b64382ca1 --- M src/crypto/tetra_crypto.c M src/crypto/tetra_crypto.h 2 files changed, 131 insertions(+), 13 deletions(-) Approvals: laforge: Looks good to me, approved; Verified diff --git a/src/crypto/tetra_crypto.c b/src/crypto/tetra_crypto.c index 9515a25..d7df293 100644 --- a/src/crypto/tetra_crypto.c +++ b/src/crypto/tetra_crypto.c @@ -150,19 +150,123 @@ return ((tm->tn - 1) | (tm->fn << 2) | (tm->mn << 7) | ((hn & 0x7FFF) << 13) | (dir << 28)); } -int decrypt_identity(struct tetra_crypto_state *tcs, struct tetra_addr *addr) +static bool generate_keystream(struct tetra_crypto_state *tcs, struct tetra_key *key, struct tetra_tdma_time *t, int num_bits, uint8_t *ks_out) { - return 0; + if (!key) + return false; + + /* Construct IV and prepare buf for bytewise keystream */ + int num_bytes = (num_bits + 7) / 8; + uint8_t ks_bytes[num_bytes]; + uint32_t iv = tea_build_iv(t, tcs->hn, 0); + + /* Compute ECK from net info and CK */ + if (tcs->cn < 0 || tcs->la < 0 || tcs->cc < 0) + /* Missing data for TB5 */ + return false; + + uint8_t eck[10]; + uint8_t cn[2] = {(tcs->cn >> 8) & 0xFF, tcs->cn & 0xFF}; + uint8_t la[2] = {(tcs->la >> 8) & 0xFF, tcs->la & 0xFF}; + uint8_t cc[1] = {tcs->cc & 0xFF}; + /* TODO FIXME add call to TB5 to derive eck */ + + /* Generate keystream with required KSG */ + switch (key->network_info->ksg_type) { + /* TODO FIXME add cases/calls to TEA keystream generator functions */ + default: + fprintf(stderr, "tetra_crypto: KSG type %d not supported\n", key->network_info->ksg_type); + return false; + } + + for (int i = 0; i < num_bytes; i++) + for (int j = 0; j < 8; j++) + ks_out[i * 8 + j] = (ks_bytes[i] >> (7-j)) & 1; + + /* Expand keystream bytes into ubit format */ + for (int i = 0; i < num_bits; i++) + ks_out[i] = (ks_bytes[num_bits / 8] >> (7-(num_bits % 8))) & 1; + + return true; } -int decrypt_mac_element(struct tetra_crypto_state *tcs, struct tetra_tmvsap_prim *tmvp, struct tetra_key *key, int l1_len, int tmpdu_offset) +bool decrypt_identity(struct tetra_crypto_state *tcs, struct tetra_addr *addr) { - return 0; + /* TODO FIXME implement TA61 decryption */ + return false; } -int decrypt_voice_timeslot(struct tetra_crypto_state *tcs, struct tetra_tdma_time *tdma_time, int16_t *type1_block) +bool decrypt_mac_element(struct tetra_crypto_state *tcs, struct tetra_tmvsap_prim *tmvp, struct tetra_key *key, int l1_len, int tmpdu_offset) { - return 0; + if (!key || l1_len - tmpdu_offset <= 0) + return false; + + if (tcs->cn < 0 || tcs->la < 0 || tcs->cc < 0) { + printf("tetra_crypto: can't compute TB5 due to incomplete network info (carr %d la %d cc %d)\n", + tcs->cn, tcs->la, tcs->cc); + return false; + } + + struct tetra_tdma_time *tdma_time = &tmvp->u.unitdata.tdma_time; + + /* Compute keystream offset to apply */ + /* TODO FIXME maybe we can rework channel type setting in lower mac, and + avoid using TETRA_LC_UNKNOWN below */ + uint32_t ks_skip_bits = 0; + if (tmvp->u.unitdata.blk_num == BLK_2 && ( + tmvp->u.unitdata.lchan == TETRA_LC_SCH_HD || + tmvp->u.unitdata.lchan == TETRA_LC_UNKNOWN)) { + ks_skip_bits = 216; + printf("tetra_crypto: 2nd half slot; skipping bits\n"); + } + + /* Generate keystream */ + struct msgb *msg = tmvp->oph.msg; + int ct_len = l1_len - tmpdu_offset; + int ks_num_bits = ks_skip_bits + ct_len; + uint8_t *ct_start = msg->l1h + tmpdu_offset; + uint8_t ks[ks_num_bits]; + if (!generate_keystream(tcs, key, tdma_time, ks_num_bits, ks)) + return false; + + /* Apply keystream */ + for (int i = 0; i < ct_len; i++) + ct_start[i] = ct_start[i] ^ ks[i + ks_skip_bits]; + + printf("tetra_crypto: addr %8d -> key %4d, time %5d/%s, tmpdu offset %d, decrypting %d bits\n", + key->addr, key->index, tcs->hn, tetra_tdma_time_dump(tdma_time), tmpdu_offset, ct_len); + + return true; +} + +bool decrypt_voice_timeslot(struct tetra_crypto_state *tcs, struct tetra_tdma_time *tdma_time, int16_t *type1_block) +{ + /* TODO FIXME implement proper key selection for voice blocks */ + struct tetra_key *key = tcs->cck; + if (!key) + return false; + + if (tcs->cn < 0 || tcs->la < 0 || tcs->cc < 0) { + printf("tetra_crypto: can't compute TB5 due to incomplete network info (carr %d la %d cc %d)\n", + tcs->cn, tcs->la, tcs->cc); + return false; + } + + /* Generate keystream */ + int ks_num_bits = 137*2; // two half slots of voice + uint8_t ks[ks_num_bits]; + if (!generate_keystream(tcs, key, tdma_time, ks_num_bits, ks)) + return false; + + /* Apply keystream */ + for (int i = 0; i < 137; i++) { + type1_block[i + 1] = type1_block[i + 1] ^ ks[i]; + type1_block[i + 139] = type1_block[i + 139] ^ ks[i + 137]; + } + + printf("tetra_crypto: addr %8d -> key %4d, time %5d/%s, decrypted voice\n", + key->addr, key->index, tcs->hn, tetra_tdma_time_dump(tdma_time)); + return true; } int load_keystore(char *tetra_keyfile) @@ -197,7 +301,7 @@ while (fgets(buf, sizeof(buf), fp)) { if (strlen(buf) <= 1 || buf[0] == '#') { - // Commented/empty line + /* Commented/empty line */ continue; } else if (!strncmp(buf, "network ", 8)) { @@ -299,11 +403,11 @@ void update_current_network(struct tetra_crypto_state *tcs, int mcc, int mnc) { - // Update globals + /* Update globals */ tcs->mcc = mcc; tcs->mnc = mnc; - // Network changed, update reference to current network + /* Network changed, update reference to current network */ tcs->network = 0; for (int i = 0; i < tcdb->num_nets; i++) { struct tetra_netinfo *network = &tcdb->nets[i]; @@ -313,7 +417,7 @@ } } - // (Try to) select new CCK/SCK + /* (Try to) select new CCK/SCK */ update_current_cck(tcs); } diff --git a/src/crypto/tetra_crypto.h b/src/crypto/tetra_crypto.h index e50a45e..ace4c04 100644 --- a/src/crypto/tetra_crypto.h +++ b/src/crypto/tetra_crypto.h @@ -111,9 +111,9 @@ /* Keystream generation and decryption functions */ uint32_t tea_build_iv(struct tetra_tdma_time *tm, uint16_t hn, uint8_t dir); -int decrypt_identity(struct tetra_crypto_state *tcs, struct tetra_addr *addr); -int decrypt_mac_element(struct tetra_crypto_state *tcs, struct tetra_tmvsap_prim *tmvp, struct tetra_key *key, int l1_len, int tmpdu_offset); -int decrypt_voice_timeslot(struct tetra_crypto_state *tcs, struct tetra_tdma_time *tdma_time, int16_t *type1_bits); +bool decrypt_identity(struct tetra_crypto_state *tcs, struct tetra_addr *addr); +bool decrypt_mac_element(struct tetra_crypto_state *tcs, struct tetra_tmvsap_prim *tmvp, struct tetra_key *key, int l1_len, int tmpdu_offset); +bool decrypt_voice_timeslot(struct tetra_crypto_state *tcs, struct tetra_tdma_time *tdma_time, int16_t *type1_bits); /* Key selection and crypto state management */ struct tetra_netinfo *get_network_info(int mcc, int mnc); -- To view, visit https://gerrit.osmocom.org/c/osmo-tetra/+/34001 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-tetra Gerrit-Branch: master Gerrit-Change-Id: I4e6147f206ad6046f32e08015ec9721b64382ca1 Gerrit-Change-Number: 34001 Gerrit-PatchSet: 5 Gerrit-Owner: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in osmo-tetra[master]: Fixups and clarifying comments for msgb tail modifications
by laforge 21 Aug '23

21 Aug '23
Attention is currently required from: wbokslag. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-tetra/+/34000 ) Change subject: Fixups and clarifying comments for msgb tail modifications ...................................................................... Patch Set 3: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmo-tetra/+/34000 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-tetra Gerrit-Branch: master Gerrit-Change-Id: Ia725edbeafe26bd2ea9b5a1810d0b26bc79d84db Gerrit-Change-Number: 34000 Gerrit-PatchSet: 3 Gerrit-Owner: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Comment-Date: Mon, 21 Aug 2023 18:35:50 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[M] Change in osmo-tetra[master]: Added functions that prepare for decryption
by laforge 21 Aug '23

21 Aug '23
Attention is currently required from: wbokslag. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-tetra/+/34001 ) Change subject: Added functions that prepare for decryption ...................................................................... Patch Set 5: Verified+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-tetra/+/34001 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-tetra Gerrit-Branch: master Gerrit-Change-Id: I4e6147f206ad6046f32e08015ec9721b64382ca1 Gerrit-Change-Number: 34001 Gerrit-PatchSet: 5 Gerrit-Owner: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Comment-Date: Mon, 21 Aug 2023 18:35:46 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[M] Change in osmo-tetra[master]: Added functions that prepare for decryption
by laforge 21 Aug '23

21 Aug '23
Attention is currently required from: wbokslag. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-tetra/+/34001 ) Change subject: Added functions that prepare for decryption ...................................................................... Patch Set 5: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmo-tetra/+/34001 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-tetra Gerrit-Branch: master Gerrit-Change-Id: I4e6147f206ad6046f32e08015ec9721b64382ca1 Gerrit-Change-Number: 34001 Gerrit-PatchSet: 5 Gerrit-Owner: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Comment-Date: Mon, 21 Aug 2023 18:35:29 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[S] Change in osmo-tetra[master]: Added keyfile loading
by laforge 21 Aug '23

21 Aug '23
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-tetra/+/33998 ) Change subject: Added keyfile loading ...................................................................... Added keyfile loading Added an additional command line flag -k to tetra-rx that allows for the loading of a file containing network and key definitions. Change-Id: I65b7ac8feb3c2a9a8cac95149f625e9ef534b66c --- M src/tetra-rx.c 1 file changed, 16 insertions(+), 1 deletion(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/src/tetra-rx.c b/src/tetra-rx.c index b37b4c0..121e7b7 100644 --- a/src/tetra-rx.c +++ b/src/tetra-rx.c @@ -53,11 +53,14 @@ trs = talloc_zero(tetra_tall_ctx, struct tetra_rx_state); trs->burst_cb_priv = tms; - while ((opt = getopt(argc, argv, "d:")) != -1) { + while ((opt = getopt(argc, argv, "d:k:")) != -1) { switch (opt) { case 'd': tms->dumpdir = strdup(optarg); break; + case 'k': + load_keystore(optarg); + break; default: fprintf(stderr, "Unknown option %c\n", opt); } -- To view, visit https://gerrit.osmocom.org/c/osmo-tetra/+/33998 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-tetra Gerrit-Branch: master Gerrit-Change-Id: I65b7ac8feb3c2a9a8cac95149f625e9ef534b66c Gerrit-Change-Number: 33998 Gerrit-PatchSet: 3 Gerrit-Owner: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[M] Change in osmo-tetra[master]: Added keyfile parsing code and various crypto improvements
by laforge 21 Aug '23

21 Aug '23
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-tetra/+/33997 ) Change subject: Added keyfile parsing code and various crypto improvements ...................................................................... Added keyfile parsing code and various crypto improvements Added keyfile parsing code, as well as various other improvements such as definition/enum updates and freeing the tetra_crypto_context when done Change-Id: I1c7afeeb2dcf97ece44bb4b604f44ba88882b93f --- M src/crypto/tetra_crypto.c M src/crypto/tetra_crypto.h M src/tetra-rx.c 3 files changed, 118 insertions(+), 16 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/src/crypto/tetra_crypto.c b/src/crypto/tetra_crypto.c index 67997e1..9515a25 100644 --- a/src/crypto/tetra_crypto.c +++ b/src/crypto/tetra_crypto.c @@ -38,9 +38,9 @@ static const struct value_string tetra_key_types[] = { { KEYTYPE_UNDEFINED, "UNDEFINED" }, + { KEYTYPE_CCK_SCK, "CCK/SCK" }, { KEYTYPE_DCK, "DCK" }, { KEYTYPE_MGCK, "MGCK" }, - { KEYTYPE_CCK_SCK, "CCK/SCK" }, { KEYTYPE_GCK, "GCK" }, { 0, NULL } }; @@ -50,7 +50,7 @@ return get_value_string(tetra_key_types, key_type); } -static const struct value_string tetra_tea_types[] = { +static const struct value_string tetra_ksg_types[] = { { UNKNOWN, "UNKNOWN" }, { KSG_TEA1, "TEA1" }, { KSG_TEA2, "TEA2" }, @@ -66,9 +66,9 @@ const char *tetra_get_ksg_type_name(enum tetra_ksg_type ksg_type) { if (ksg_type >= KSG_PROPRIETARY) - return tetra_tea_types[KSG_PROPRIETARY].str; + return tetra_ksg_types[KSG_PROPRIETARY].str; else - return get_value_string(tetra_tea_types, ksg_type); + return get_value_string(tetra_ksg_types, ksg_type); } static const struct value_string tetra_security_classes[] = { @@ -86,14 +86,15 @@ void tetra_crypto_state_init(struct tetra_crypto_state *tcs) { - /* Initialize tetra_crypto_state */ - tcs = talloc_zero(NULL, struct tetra_crypto_state); + /* Initialize network info fields to -1 to designate unknown */ tcs->mnc = -1; tcs->mcc = -1; tcs->cck_id = -1; tcs->hn = -1; tcs->la = -1; tcs->cc = -1; + + /* Initialize database key/network pointers to zero */ tcs->cck = 0; tcs->network = 0; } @@ -116,8 +117,8 @@ { static char pbuf[1024]; - int c = snprintf(pbuf, sizeof(pbuf), "MCC %4d MNC %4d key_type %02X", - k->mcc, k->mnc, k->key_type); + int c = snprintf(pbuf, sizeof(pbuf), "MCC %4d MNC %4d key_type %s", + k->mcc, k->mnc, tetra_get_key_type_name(k->key_type)); if (k->key_type & (KEYTYPE_DCK | KEYTYPE_MGCK)) c += snprintf(pbuf + c, sizeof(pbuf) - c, " addr: %8d", k->addr); @@ -166,6 +167,98 @@ int load_keystore(char *tetra_keyfile) { + /* Keystore file: + * Each line contains network or key definition. + * Lines starting with # are ignored as comments. + * + * network mcc 123 mnc 456 ksg_type 1 security_class 2 + * - ksg_type: decimal, see enum tetra_ksg_type + * - security_class: 2 for SCK, 3 for CCK (and DCK per ISSI) + * + * key mcc 123 mnc 456 addr 00000000 key_type 1 key_num 002 key 1234deadbeefcafebabe + * - addr: decimal, leave zero for key type 1 (CCK/SCK) + * - key_type: 1 CCK/SCK, 2 DCK, 3 MGCK, 4 GCK + * - key_num: SCK_VN or group key number depending on type + * - key: 80-bit key hex string + */ + + int i, c; + char buf[1000]; // max line len + FILE *fp; + + tetra_crypto_db_init(); + + fp = fopen(tetra_keyfile, "r"); + if (!fp) { + printf("tetra_crypto: cannot read keyfile\n"); + exit(1); + } + + while (fgets(buf, sizeof(buf), fp)) { + + if (strlen(buf) <= 1 || buf[0] == '#') { + // Commented/empty line + continue; + + } else if (!strncmp(buf, "network ", 8)) { + + /* Network definition */ + i = tcdb->num_nets; + if (i > 0 && (i % TCDB_ALLOC_BLOCK_SIZE == 0)) + tcdb->nets = talloc_realloc(NULL, tcdb->nets, struct tetra_netinfo, i + TCDB_ALLOC_BLOCK_SIZE); + + c = sscanf(buf, "network mcc %d mnc %d ksg_type %d security_class %d\n", + &tcdb->nets[i].mcc, &tcdb->nets[i].mnc, + (uint32_t *) &tcdb->nets[i].ksg_type, + (uint32_t *) &tcdb->nets[i].security_class); + + if (c != 4) { + printf("tetra_crypto: Failed to parse network info element %d [%s] (%d)\n", i, buf, c); + exit(1); + } + printf("tetra_crypto: Loaded MNC [%s]\n", dump_network_info(&tcdb->nets[i])); + tcdb->num_nets++; + + } else if (!strncmp(buf, "key ", 4)) { + + /* Key definition */ + i = tcdb->num_keys; + if (i > 0 && (i % TCDB_ALLOC_BLOCK_SIZE == 0)) + tcdb->keys = talloc_realloc(NULL, tcdb->keys, struct tetra_key, i + TCDB_ALLOC_BLOCK_SIZE); + + c = sscanf(buf, "key mcc %d mnc %d addr %d key_type %d key_num %d key %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n", + &tcdb->keys[i].mcc, &tcdb->keys[i].mnc, &tcdb->keys[i].addr, + (uint32_t *) &tcdb->keys[i].key_type, &tcdb->keys[i].key_num, + (uint32_t *) &tcdb->keys[i].key[0], (uint32_t *) &tcdb->keys[i].key[1], + (uint32_t *) &tcdb->keys[i].key[2], (uint32_t *) &tcdb->keys[i].key[3], + (uint32_t *) &tcdb->keys[i].key[4], (uint32_t *) &tcdb->keys[i].key[5], + (uint32_t *) &tcdb->keys[i].key[6], (uint32_t *) &tcdb->keys[i].key[7], + (uint32_t *) &tcdb->keys[i].key[8], (uint32_t *) &tcdb->keys[i].key[9]); + tcdb->keys[i].index = i; + if (c != 15) { + printf("tetra_crypto: Failed to parse key %d [%s] (%d)\n", i, buf, c); + exit(1); + } + printf("tetra_crypto: Loaded key [%s]\n", dump_key(&tcdb->keys[i])); + tcdb->num_keys++; + + } else { + printf("tetra_crypto: Could not parse line: %s\n", buf); + exit(1); + } + } + + /* Check network info available for each key and set ptrs for convenience */ + for (i = 0; i < tcdb->num_keys; i++) { + struct tetra_netinfo *network_info_ptr = get_network_info(tcdb->keys[i].mcc, tcdb->keys[i].mnc); + if (!network_info_ptr) { + printf("tetra_crypto: Required network info is missing for %4d", tcdb->keys[i].mnc); + exit(1); + } + tcdb->keys[i].network_info = network_info_ptr; + } + + fclose(fp); return 0; } diff --git a/src/crypto/tetra_crypto.h b/src/crypto/tetra_crypto.h index 0f36e1f..e50a45e 100644 --- a/src/crypto/tetra_crypto.h +++ b/src/crypto/tetra_crypto.h @@ -35,15 +35,13 @@ #define TCDB_ALLOC_BLOCK_SIZE 16 enum tetra_key_type { - KEYTYPE_UNDEFINED = 0x00, + KEYTYPE_UNDEFINED = 0, /* Keytypes usable as ECK after applying TB5 */ - KEYTYPE_DCK = 0x01, - KEYTYPE_MGCK = 0x02, - KEYTYPE_CCK_SCK = 0x04, /* SCK in class 2, CCK in class 3 networks */ - - /* Can be combined with SCK/CCK to get MGCK */ - KEYTYPE_GCK = 0x20, + KEYTYPE_CCK_SCK = 1, /* SCK in class 2, CCK in class 3 networks */ + KEYTYPE_DCK = 2, /* FIXME: add support for DCK */ + KEYTYPE_MGCK = 4, /* FIXME: add support for MGCK */ + KEYTYPE_GCK = 8, /* FIXME: add support. Used with SCK/CCK to derive MGCK */ }; enum tetra_ksg_type { @@ -109,7 +107,6 @@ /* Key loading / unloading */ void tetra_crypto_state_init(struct tetra_crypto_state *tcs); -void tetra_crypto_db_init(void); int load_keystore(char *filename); /* Keystream generation and decryption functions */ diff --git a/src/tetra-rx.c b/src/tetra-rx.c index 2fe95b5..b37b4c0 100644 --- a/src/tetra-rx.c +++ b/src/tetra-rx.c @@ -93,6 +93,7 @@ free(tms->dumpdir); talloc_free(trs); + talloc_free(tms->tcs); talloc_free(tms); exit(0); -- To view, visit https://gerrit.osmocom.org/c/osmo-tetra/+/33997 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-tetra Gerrit-Branch: master Gerrit-Change-Id: I1c7afeeb2dcf97ece44bb4b604f44ba88882b93f Gerrit-Change-Number: 33997 Gerrit-PatchSet: 2 Gerrit-Owner: wbokslag <w.bokslag(a)midnightblue.nl> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • ...
  • 152
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.