dexter has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38635?usp=email )
Change subject: global_platform/scp: refactor _wrap_cmd_apdu
......................................................................
global_platform/scp: refactor _wrap_cmd_apdu
The _wrap_cmd_apdu methods for SCP02 and SCP03 are a bit hard to read. Let's
refactor them so that it is easier to understand what happens. In particular
that one can not have encryption (cenc) without signing (cmac)
Related: OS#6367
Change-Id: I4c5650337779a4bd1f98673650c6c3cb526d518b
---
M pySim/global_platform/scp.py
1 file changed, 41 insertions(+), 34 deletions(-)
Approvals:
fixeria: Looks good to me, but someone else must approve
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/pySim/global_platform/scp.py b/pySim/global_platform/scp.py
index 0b1f6a9..ee08058 100644
--- a/pySim/global_platform/scp.py
+++ b/pySim/global_platform/scp.py
@@ -275,34 +275,39 @@
def _wrap_cmd_apdu(self, apdu: bytes, *args, **kwargs) -> bytes:
"""Wrap Command APDU for SCP02: calculate MAC and encrypt."""
+ logger.debug("wrap_cmd_apdu(%s)", b2h(apdu))
+
+ if not self.do_cmac:
+ return apdu
+
lc = len(apdu) - 5
assert len(apdu) >= 5, "Wrong APDU length: %d" % len(apdu)
assert len(apdu) == 5 or apdu[4] == lc, "Lc differs from length of data: %d vs %d" % (apdu[4], lc)
- logger.debug("wrap_cmd_apdu(%s)", b2h(apdu))
-
+ # CLA without log. channel can be 80 or 00 only
cla = apdu[0]
b8 = cla & 0x80
if cla & 0x03 or cla & CLA_SM:
# nonzero logical channel in APDU, check that are the same
assert cla == self._cla(False, b8), "CLA mismatch"
- # CLA without log. channel can be 80 or 00 only
- if self.do_cmac:
- if self.mac_on_unmodified:
- mlc = lc
- clac = cla
- else: # CMAC on modified APDU
- mlc = lc + 8
- clac = cla | CLA_SM
- mac = self.sk.calc_mac_1des(bytes([clac]) + apdu[1:4] + bytes([mlc]) + apdu[5:])
- if self.do_cenc:
- k = DES3.new(self.sk.enc, DES.MODE_CBC, b'\x00'*8)
- data = k.encrypt(pad80(apdu[5:], 8))
- lc = len(data)
- else:
- data = apdu[5:]
- lc += 8
- apdu = bytes([self._cla(True, b8)]) + apdu[1:4] + bytes([lc]) + data + mac
+
+ if self.mac_on_unmodified:
+ mlc = lc
+ clac = cla
+ else:
+ # CMAC on modified APDU
+ mlc = lc + 8
+ clac = cla | CLA_SM
+ mac = self.sk.calc_mac_1des(bytes([clac]) + apdu[1:4] + bytes([mlc]) + apdu[5:])
+ if self.do_cenc:
+ k = DES3.new(self.sk.enc, DES.MODE_CBC, b'\x00'*8)
+ data = k.encrypt(pad80(apdu[5:], 8))
+ lc = len(data)
+ else:
+ data = apdu[5:]
+
+ lc += 8
+ apdu = bytes([self._cla(True, b8)]) + apdu[1:4] + bytes([lc]) + data + mac
return apdu
def unwrap_rsp_apdu(self, sw: bytes, rsp_apdu: bytes) -> bytes:
@@ -475,6 +480,11 @@
def _wrap_cmd_apdu(self, apdu: bytes, skip_cenc: bool = False) -> bytes:
"""Wrap Command APDU for SCP03: calculate MAC and encrypt."""
+ logger.debug("wrap_cmd_apdu(%s)", b2h(apdu))
+
+ if not self.do_cmac:
+ return apdu
+
cla = apdu[0]
ins = apdu[1]
p1 = apdu[2]
@@ -484,7 +494,6 @@
cmd_data = apdu[5:]
if self.do_cenc and not skip_cenc:
- assert self.do_cmac
if lc == 0:
# No encryption shall be applied to a command where there is no command data field. In this
# case, the encryption counter shall still be incremented
@@ -498,20 +507,18 @@
# perform AES-CBC with ICV + S_ENC
cmd_data = self.sk._encrypt(padded_data)
- if self.do_cmac:
- # The length of the command message (Lc) shall be incremented by 8 (in S8 mode) or 16 (in S16
- # mode) to indicate the inclusion of the C-MAC in the data field of the command message.
- mlc = lc + self.s_mode
- if mlc >= 256:
- raise ValueError('Modified Lc (%u) would exceed maximum when appending %u bytes of mac' % (mlc, self.s_mode))
- # The class byte shall be modified for the generation or verification of the C-MAC: The logical
- # channel number shall be set to zero, bit 4 shall be set to 0 and bit 3 shall be set to 1 to indicate
- # GlobalPlatform proprietary secure messaging.
- mcla = (cla & 0xF0) | CLA_SM
- apdu = bytes([mcla, ins, p1, p2, mlc]) + cmd_data
- cmac = self.sk.calc_cmac(apdu)
- apdu += cmac[:self.s_mode]
-
+ # The length of the command message (Lc) shall be incremented by 8 (in S8 mode) or 16 (in S16
+ # mode) to indicate the inclusion of the C-MAC in the data field of the command message.
+ mlc = lc + self.s_mode
+ if mlc >= 256:
+ raise ValueError('Modified Lc (%u) would exceed maximum when appending %u bytes of mac' % (mlc, self.s_mode))
+ # The class byte shall be modified for the generation or verification of the C-MAC: The logical
+ # channel number shall be set to zero, bit 4 shall be set to 0 and bit 3 shall be set to 1 to indicate
+ # GlobalPlatform proprietary secure messaging.
+ mcla = (cla & 0xF0) | CLA_SM
+ apdu = bytes([mcla, ins, p1, p2, mlc]) + cmd_data
+ cmac = self.sk.calc_cmac(apdu)
+ apdu += cmac[:self.s_mode]
return apdu
def unwrap_rsp_apdu(self, sw: bytes, rsp_apdu: bytes) -> bytes:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38635?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4c5650337779a4bd1f98673650c6c3cb526d518b
Gerrit-Change-Number: 38635
Gerrit-PatchSet: 3
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Attention is currently required from: falconia.
fixeria has posted comments on this change by falconia. ( https://gerrit.osmocom.org/c/osmo-hlr/+/38818?usp=email )
Change subject: vty: always emit reject-cause lines in saved config
......................................................................
Patch Set 1: Code-Review+1
(1 comment)
Patchset:
PS1:
I never liked hiding settings, even if they're set to default, so CR+1 from me.
--
To view, visit https://gerrit.osmocom.org/c/osmo-hlr/+/38818?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Change-Id: I18708fc1c08a85e98582c97ec59dd3822a0767fb
Gerrit-Change-Number: 38818
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon(a)freecalypso.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: falconia <falcon(a)freecalypso.org>
Gerrit-Comment-Date: Tue, 19 Nov 2024 09:35:08 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: fixeria.
pespin has posted comments on this change by fixeria. ( https://gerrit.osmocom.org/c/osmo-bts/+/38817?usp=email )
Change subject: csd_v110: clarify lchan description for TCH/F14.4
......................................................................
Patch Set 1: Code-Review+1
(1 comment)
File include/osmo-bts/csd_v110.h:
https://gerrit.osmocom.org/c/osmo-bts/+/38817/comment/95eef219_96026898?usp… :
PS1, Line 11: uint16_t num_other_bits; /* number of other bits (e.g. M-bits for TCH/F14.4) */
this can be a uint8_t afaiu?
--
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/38817?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I4f11eda98420587efa339484b62f46bf19f78809
Gerrit-Change-Number: 38817
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: falconia <falcon(a)freecalypso.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 19 Nov 2024 09:18:39 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: fixeria.
pespin has posted comments on this change by fixeria. ( https://gerrit.osmocom.org/c/osmo-bts/+/38816?usp=email )
Change subject: csd_v110: clarify field names in csd_v110_lchan_desc[]
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/38816?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: If97787a64e30ff9b39c26749ba32aed09d3d7983
Gerrit-Change-Number: 38816
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: falconia <falcon(a)freecalypso.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 19 Nov 2024 09:17:51 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38778?usp=email )
(
2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
)Change subject: testenv: make it pass 'ruff check' linter
......................................................................
testenv: make it pass 'ruff check' linter
I've added 'ruff check' to my pre-commit script. Make it pass initially,
so it can detect future bugs. The missing f-string is a bug that causes
ggsn testsuites with a custom kernel path to not work.
Change-Id: I3e5cd05ce0aa241509d77391c5ed64e618f385ba
---
M _testenv/testenv/podman.py
M _testenv/testenv/testsuite.py
2 files changed, 2 insertions(+), 2 deletions(-)
Approvals:
pespin: Looks good to me, but someone else must approve
fixeria: Looks good to me, approved
laforge: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/_testenv/testenv/podman.py b/_testenv/testenv/podman.py
index 16db400..1281b3b 100644
--- a/_testenv/testenv/podman.py
+++ b/_testenv/testenv/podman.py
@@ -254,7 +254,7 @@
cmd += ["--volume", "/dev/kvm:/dev/kvm"]
if os.path.islink(testenv.custom_kernel_path):
dest = os.readlink(testenv.custom_kernel_path)
- cmd += ["--volume", "{dest}:{dest}:ro"]
+ cmd += ["--volume", f"{dest}:{dest}:ro"]
cmd += [
"--volume",
diff --git a/_testenv/testenv/testsuite.py b/_testenv/testenv/testsuite.py
index 0fa42ab..9b28668 100644
--- a/_testenv/testenv/testsuite.py
+++ b/_testenv/testenv/testsuite.py
@@ -225,7 +225,7 @@
try:
with open(path, "r") as h:
return h.readline().rstrip()
- except:
+ except: # noqa
# File may not exist, e.g. if test was stopped
return None
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38778?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I3e5cd05ce0aa241509d77391c5ed64e618f385ba
Gerrit-Change-Number: 38778
Gerrit-PatchSet: 3
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38803?usp=email )
(
2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
)Change subject: testenv: install dbg pkgs with --binary-repo too
......................................................................
testenv: install dbg pkgs with --binary-repo too
When using --binary-repo, figure out the -dbg and -dbgsym packages for
all dependencies of packages to be installed, and install them as well.
This will make debug symbols available in jenkins, useful for the
related issue. Before this patch debug symbols were only available when
building locally without --binary-repo.
Related: OS#6630
Change-Id: I4dc57257b944126fed2c7b031c92c77a3d4286e0
---
M _testenv/data/podman/Dockerfile
M _testenv/testenv/podman_install.py
2 files changed, 58 insertions(+), 0 deletions(-)
Approvals:
fixeria: Looks good to me, approved
Jenkins Builder: Verified
pespin: Looks good to me, but someone else must approve
laforge: Looks good to me, but someone else must approve
diff --git a/_testenv/data/podman/Dockerfile b/_testenv/data/podman/Dockerfile
index 6f6c739..5321bfe 100644
--- a/_testenv/data/podman/Dockerfile
+++ b/_testenv/data/podman/Dockerfile
@@ -19,6 +19,7 @@
-y \
--no-install-recommends \
-o Dpkg::Options::="--force-confold" \
+ apt-rdepends \
autoconf \
automake \
bc \
diff --git a/_testenv/testenv/podman_install.py b/_testenv/testenv/podman_install.py
index 9c680b9..3c38285 100644
--- a/_testenv/testenv/podman_install.py
+++ b/_testenv/testenv/podman_install.py
@@ -3,6 +3,9 @@
import logging
import multiprocessing
import os
+import shlex
+import string
+import subprocess
import sys
import testenv.cmd
import testenv.podman
@@ -30,6 +33,58 @@
os.makedirs(git_dir, exist_ok=True)
+def get_dbg_pkgs(dep):
+ ret = [f"{dep}-dbg", f"{dep}-dbgsym"]
+
+ # Get from e.g. libosmocore22 to libosmocore-dbg
+ dep_nodigits = dep.rstrip(string.digits)
+ if dep_nodigits != dep:
+ ret += [f"{dep_nodigits}-dbg", f"{dep_nodigits}-dbgsym"]
+
+ return ret
+
+
+def apt_get_dbg_pkgs(pkgs):
+ dbg_pkgs_all = os.path.join(testenv.args.cache, "podman", "dbg_pkgs_all")
+ dbg_pkgs = {}
+
+ testenv.cmd.run(f"apt-cache pkgnames | grep -- -dbg > {shlex.quote(dbg_pkgs_all)}")
+
+ for pkg in pkgs:
+ # Iterate over apt-rdepends, example output:
+ # osmo-mgw
+ # Depends: libc6 (>= 2.34)
+ # Depends: libosmoabis13
+ rdeps = testenv.cmd.run(["apt-rdepends", pkg], stdout=subprocess.PIPE)
+ for line in rdeps.stdout.decode("utf-8").split("\n"):
+ if line.startswith(" "):
+ continue
+ dep = line.rstrip().split(" ", 1)[0]
+
+ if dep not in dbg_pkgs:
+ for dbg_pkg in get_dbg_pkgs(dep):
+ # Use subprocess.run so we don't get lots of log messages.
+ # Also we don't need to run grep through podman.
+ grep = subprocess.run(["grep", "-q", f"^{dbg_pkg}$", dbg_pkgs_all])
+
+ if grep.returncode == 0:
+ dbg_pkgs[dep] = dbg_pkg
+ break
+
+ if dep not in dbg_pkgs:
+ dbg_pkgs[dep] = None
+
+ if dbg_pkgs[dep]:
+ logging.debug(f"{pkg} -> {dep}: installing {dbg_pkgs[dep]}")
+
+ ret = []
+ for dep, dbg in dbg_pkgs.items():
+ if dbg:
+ ret += [dbg]
+
+ return ret
+
+
def apt_install(pkgs):
if not pkgs:
return
@@ -37,6 +92,8 @@
# Remove duplicates
pkgs = list(set(pkgs))
+ pkgs += apt_get_dbg_pkgs(pkgs)
+
logging.info(f"Installing packages: {', '.join(pkgs)}")
testenv.cmd.run(["apt-get", "-q", "install", "-y", "--no-install-recommends"] + pkgs)
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38803?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I4dc57257b944126fed2c7b031c92c77a3d4286e0
Gerrit-Change-Number: 38803
Gerrit-PatchSet: 3
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>