pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sigtran/+/42530?usp=email )
Change subject: xua_asp_fsm: XUA_ASP_E_ASPTM_ASPAC: Validate RCTX AS is associated to ASP
......................................................................
xua_asp_fsm: XUA_ASP_E_ASPTM_ASPAC: Validate RCTX AS is associated to ASP
Previously we only validated that a local AS was configured for the
provided routing context, but we didn't validate that the AS was actually
associated to the requesting ASP.
Change-Id: Idcd51b9bbe38064ed03d076a76279384a3927334
---
M src/ss7_asp.c
M src/ss7_asp.h
M src/xua_asp_fsm.c
M tests/ss7/ss7_test.c
4 files changed, 21 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/30/42530/1
diff --git a/src/ss7_asp.c b/src/ss7_asp.c
index f83de19..ba3b95c 100644
--- a/src/ss7_asp.c
+++ b/src/ss7_asp.c
@@ -1578,6 +1578,21 @@
return _ss7_asp_get_all_rctx(asp, rctx, rctx_size, excl_as, false);
}
+/*! \brief Find Application Server associated to ASP by given routing context
+ * \param[in] asp Application Server Process through which to send
+ * \param[in] rctx Routing Context
+ * \returns pointer to Application Server on success; NULL otherwise */
+struct osmo_ss7_as *ss7_asp_find_as_by_rctx(const struct osmo_ss7_asp *asp, uint32_t rctx)
+{
+ struct ss7_as_asp_assoc *assoc;
+
+ llist_for_each_entry(assoc, &asp->assoc_as_list, asp_entry) {
+ if (assoc->as->cfg.routing_key.context == rctx)
+ return assoc->as;
+ }
+ return NULL;
+}
+
/* Get first AS in the ASP, or NULL if no AS associated.
* This is useful for instance in IPA code, where we assume only up to 1 AS is configured per ASP. */
struct osmo_ss7_as *ss7_asp_get_first_as(const struct osmo_ss7_asp *asp)
diff --git a/src/ss7_asp.h b/src/ss7_asp.h
index 834f910..6b8e974 100644
--- a/src/ss7_asp.h
+++ b/src/ss7_asp.h
@@ -198,6 +198,7 @@
const struct osmo_ss7_as *excl_as);
unsigned int ss7_asp_get_all_rctx_be(const struct osmo_ss7_asp *asp, uint32_t *rctx, unsigned int rctx_size,
const struct osmo_ss7_as *excl_as);
+struct osmo_ss7_as *ss7_asp_find_as_by_rctx(const struct osmo_ss7_asp *asp, uint32_t rctx);
struct osmo_ss7_as *ss7_asp_get_first_as(const struct osmo_ss7_asp *asp);
int ss7_asp_determine_traf_mode(const struct osmo_ss7_asp *asp);
diff --git a/src/xua_asp_fsm.c b/src/xua_asp_fsm.c
index 5cb28fc..d627795 100644
--- a/src/xua_asp_fsm.c
+++ b/src/xua_asp_fsm.c
@@ -704,7 +704,7 @@
if ((part = xua_msg_find_tag(xua_in, M3UA_IEI_ROUTE_CTX))) {
for (i = 0; i < part->len / sizeof(uint32_t); i++) {
uint32_t rctx = osmo_load32be(&part->dat[i * sizeof(uint32_t)]);
- as = osmo_ss7_as_find_by_rctx(asp->inst, rctx);
+ as = ss7_asp_find_as_by_rctx(asp, rctx);
if (!as) {
LOGPFSML(fi, LOGL_NOTICE,
"ASPAC: Couldn't find any AS with rctx=%u. Check your config!\n",
diff --git a/tests/ss7/ss7_test.c b/tests/ss7/ss7_test.c
index 977f1f4..aec886f 100644
--- a/tests/ss7/ss7_test.c
+++ b/tests/ss7/ss7_test.c
@@ -289,7 +289,11 @@
OSMO_ASSERT(asp);
OSMO_ASSERT(osmo_ss7_as_has_asp(as, asp) == false);
+ OSMO_ASSERT(ss7_asp_find_as_by_rctx(asp, as->cfg.routing_key.context) == NULL);
+
OSMO_ASSERT(osmo_ss7_as_add_asp(as, "asp1") == 0);
+ OSMO_ASSERT(osmo_ss7_as_has_asp(as, asp) == true);
+ OSMO_ASSERT(ss7_asp_find_as_by_rctx(asp, as->cfg.routing_key.context) == as);
osmo_ss7_asp_restart(asp);
--
To view, visit https://gerrit.osmocom.org/c/libosmo-sigtran/+/42530?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: Idcd51b9bbe38064ed03d076a76279384a3927334
Gerrit-Change-Number: 42530
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sigtran/+/42531?usp=email )
Change subject: xua_rkm: handle_rkey_reg(): Skip AS ilookup of known free RCTX
......................................................................
xua_rkm: handle_rkey_reg(): Skip AS ilookup of known free RCTX
There's no need to attempt a look up for an AS with a RCTX we just
ensured is not yet allocated to any AS.
Change-Id: I40719527c527db58244972a797c4287107306532
---
M src/xua_rkm.c
1 file changed, 12 insertions(+), 11 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/31/42531/1
diff --git a/src/xua_rkm.c b/src/xua_rkm.c
index d6dfa51..e9972b3 100644
--- a/src/xua_rkm.c
+++ b/src/xua_rkm.c
@@ -171,7 +171,7 @@
{
uint32_t rk_id, rctx, _tmode, dpc;
enum osmo_ss7_as_traffic_mode tmode;
- struct osmo_ss7_as *as;
+ struct osmo_ss7_as *as = NULL;
struct ss7_as_asp_assoc *assoc;
struct osmo_ss7_route *rt;
char namebuf[32];
@@ -211,14 +211,6 @@
return -1;
}
- /* if the ASP did not include a routing context number, allocate
- * one locally (will be part of response) */
- if (!rctx)
- rctx = osmo_ss7_find_free_rctx(asp->inst);
-
- LOGPASP(asp, DLSS7, LOGL_INFO, "RKM: Registering routing key %u for DPC %s\n",
- rctx, osmo_ss7_pointcode_print(asp->inst, dpc));
-
/* We have two cases here:
* a) pre-configured routing context on both ASP and SG (or IPSP peers):
* We will find the AS based on the RCTX send by the client, check if
@@ -231,8 +223,17 @@
* all AS/RK in situations where the peers are trusted.
*/
- /* check if there is already an AS for this routing key */
- as = osmo_ss7_as_find_by_rctx(asp->inst, rctx);
+ if (rctx) {
+ /* check if there is already an AS for this routing key */
+ as = osmo_ss7_as_find_by_rctx(asp->inst, rctx);
+ } else {
+ /* if the ASP did not include a routing context number, allocate
+ * one locally (will be part of response) */
+ rctx = osmo_ss7_find_free_rctx(asp->inst);
+ }
+
+ LOGPASP(asp, DLSS7, LOGL_INFO, "RKM: Registering routing key %u for DPC %s\n",
+ rctx, osmo_ss7_pointcode_print(asp->inst, dpc));
if (!as && !asp->inst->cfg.permit_dyn_rkm_alloc) {
/* not permitted to create dynamic RKM entries */
--
To view, visit https://gerrit.osmocom.org/c/libosmo-sigtran/+/42531?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: I40719527c527db58244972a797c4287107306532
Gerrit-Change-Number: 42531
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sigtran/+/42532?usp=email )
Change subject: xua_find_as_for_asp(): Optimize lookup
......................................................................
xua_find_as_for_asp(): Optimize lookup
Instead of looking up on all AS configured in an instance, look up on
the subset associated to the ASP we are looking up for.
Since we are also not looking a 2nd pass to then validate if ASP and
returned AS is related, in worst case this would split lookup complexity
by half.
Change-Id: If85ad27ad5e55be0c22e2716fa7329409a7b85b5
---
M src/xua_shared.c
1 file changed, 4 insertions(+), 11 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/32/42532/1
diff --git a/src/xua_shared.c b/src/xua_shared.c
index 0fa94c4..51cbbf2 100644
--- a/src/xua_shared.c
+++ b/src/xua_shared.c
@@ -58,21 +58,14 @@
*as = NULL;
if (rctx_ie) {
- uint32_t rctx = xua_msg_part_get_u32(rctx_ie);
/* Use routing context IE to look up the AS for which the
* message was received. */
- *as = osmo_ss7_as_find_by_rctx(asp->inst, rctx);
+ uint32_t rctx = xua_msg_part_get_u32(rctx_ie);
+ *as = ss7_asp_find_as_by_rctx(asp, rctx);
if (!*as) {
- LOGPASP(asp, log_ss, LOGL_ERROR, "%s(): invalid routing context: %u\n",
- __func__, rctx);
- return M3UA_ERR_INVAL_ROUT_CTX;
- }
-
- /* Verify that this ASP is part of the AS. */
- if (!osmo_ss7_as_has_asp(*as, asp)) {
LOGPASP(asp, log_ss, LOGL_ERROR,
- "%s(): This Application Server Process is not part of the AS %s "
- "resolved by routing context %u\n", __func__, (*as)->cfg.name, rctx);
+ "%s(): This Application Server Process is not serving any AS with routing context: %u\n",
+ __func__, rctx);
return M3UA_ERR_NO_CONFGD_AS_FOR_ASP;
}
} else {
--
To view, visit https://gerrit.osmocom.org/c/libosmo-sigtran/+/42532?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: If85ad27ad5e55be0c22e2716fa7329409a7b85b5
Gerrit-Change-Number: 42532
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sigtran/+/42533?usp=email )
Change subject: handle_rkey_dereg(): Optimize lookup
......................................................................
handle_rkey_dereg(): Optimize lookup
Instead of looking up on all AS configured in an instance, look up on
the subset associated to the ASP we are looking up for.
Since we are also not looking a 2nd pass to then validate if ASP and
returned AS is related, in worst case this would split lookup complexity
by half.
Change-Id: I56ac5caef9bcded9dd08ca532a413af94070a1bd
---
M src/xua_rkm.c
1 file changed, 1 insertion(+), 7 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/33/42533/1
diff --git a/src/xua_rkm.c b/src/xua_rkm.c
index e9972b3..f3136e4 100644
--- a/src/xua_rkm.c
+++ b/src/xua_rkm.c
@@ -401,7 +401,7 @@
struct osmo_ss7_as *as;
struct osmo_ss7_route *rt;
- as = osmo_ss7_as_find_by_rctx(inst, rctx);
+ as = ss7_asp_find_as_by_rctx(asp, rctx);
if (!as) {
msgb_append_dereg_res(resp, M3UA_RKM_DEREG_ERR_INVAL_RCTX, 0);
return -1;
@@ -413,12 +413,6 @@
return -1;
}
- /* Reject if ASP is not even part of AS */
- if (!osmo_ss7_as_has_asp(as, asp)) {
- msgb_append_dereg_res(resp, M3UA_RKM_DEREG_ERR_INVAL_RCTX, 0);
- return -1;
- }
-
/* Reject if ASP is still active */
if (asp->fi->state == XUA_ASP_S_ACTIVE) {
msgb_append_dereg_res(resp, M3UA_RKM_DEREG_ERR_ASP_ACTIVE, 0);
--
To view, visit https://gerrit.osmocom.org/c/libosmo-sigtran/+/42533?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: I56ac5caef9bcded9dd08ca532a413af94070a1bd
Gerrit-Change-Number: 42533
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/42526?usp=email )
Change subject: stp: m3ua: Fix incorrect RCTX being sent in TC_combinedlset_loadshare
......................................................................
stp: m3ua: Fix incorrect RCTX being sent in TC_combinedlset_loadshare
An ASPAC was being sent containing an RCTX of an unrelated AS to the
sending ASP.
Newer libosmo-sigtran properly validates AS/RCTX is associated to the
ASP in the local config, and hence now returns an error properly making
the test fail.
Change-Id: Id8381a028a919a265ca330ef4f61c76637c168f6
---
M stp/STP_Tests_M3UA.ttcn
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/26/42526/1
diff --git a/stp/STP_Tests_M3UA.ttcn b/stp/STP_Tests_M3UA.ttcn
index 485ca76..59839b0 100644
--- a/stp/STP_Tests_M3UA.ttcn
+++ b/stp/STP_Tests_M3UA.ttcn
@@ -1738,7 +1738,7 @@
}
/* activate the second 'receiver' side ASP+AS */
- f_M3UA_asp_up_act(2, c_M3UA_TMT_override, rctx_receiver);
+ f_M3UA_asp_up_act(2, c_M3UA_TMT_override, rctx_receiver2);
/* verify traffic is routed from sender to new receiver */
const integer iter_per_asp := 20;
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/42526?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Id8381a028a919a265ca330ef4f61c76637c168f6
Gerrit-Change-Number: 42526
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/42441?usp=email )
Change subject: transport: change APDU format paradigm
......................................................................
transport: change APDU format paradigm
Unfortunately we have mixed up the concept of TPDUs and APDUs in
earlier versions of pySim-shell. This lead to problems with
detecteding the APDU case properly (see also ISO/IEC 7816-3) and
also prevented us from adding support for T=1.
This problem has been fixed long time ago and all APDUs sent from
the pySim-shell code should be well formed and valid according to
ISO/IEC 7816-3.
To ensure that we continue to format APDUs correctly as APDUs (and
not TPDUs) we have added a mechanism to the LinkBase class that
would either raise an exception or print a warning if someone
mistakenly tries to send an APDU that is really a TPDU. Whether a
warning is printed or an exception is raised is controlled via the
apdu_strict member in the LinkBase class, which is false (print
warning only) by default.
The reason why we have implemneted the mechanism this way was
because we wanted to ensure that existing APDU scripts (pySim-shell
apdu command) keep working, even though when those scripts uses
APDUs which are formally invalid.
Sending a TPDU instead of an APDU via a T=0 link will still work
in almost all cases. This is also the reason why this problem
slipped through unnoticed for long time. However, there may still
be subtile problems araising from this practice. The root of the
problem is that it is impossible to distinguish between APDU case
3 and 4 when a TPDU instead of an APDU is sent. However in order
to handle a case 4 APDU correctly we must be able to distinguish
the APDU case correctly to handle the case correctly.
ETSI TS 102 221, section 7.3.1.1.4, clause 4 is very clear about
the fact that not (only) the status word (e.g. 61xx) but the
APDU case is what matters.
To complete the logic in LinkBaseTpdu and to maintain compatibility
(older APDU scripts), we must still be able to switch between the
'apdu_strict' mode and the non-strict mode. However, since
pySim-shell, pySim-prog and pySim-read internally use proper APDUs,
we may enable the 'apdu_strict' mode by default.
At the same time we will limit the effect of pySim-shell's
apdu_strict setable to the apdu command only. By doing so, the
bahviour of the apdu command is not altered. Users will still
have to enable the 'strict' mode explicitly. At the same time
all the internal functionality of pySim-shell will always use
the 'strict' mode.
Related: OS#6970
Change-Id: I9a531a825def318b28bf58291d811cf119003fab
---
M pySim-shell.py
M pySim/transport/__init__.py
2 files changed, 12 insertions(+), 11 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/pySim-shell.py b/pySim-shell.py
index 50deea2..2bfc720 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -136,8 +136,7 @@
self.add_settable(Settable2Compat('apdu_trace', bool, 'Trace and display APDUs exchanged with card', self,
onchange_cb=self._onchange_apdu_trace))
self.add_settable(Settable2Compat('apdu_strict', bool,
- 'Enforce APDU responses according to ISO/IEC 7816-3, table 12', self,
- onchange_cb=self._onchange_apdu_strict))
+ 'Strictly apply APDU format according to ISO/IEC 7816-3, table 12', self))
self.add_settable(Settable2Compat('verbose', bool,
'Enable/disable verbose logging', self,
onchange_cb=self._onchange_verbose))
@@ -218,13 +217,6 @@
else:
self.card._scc._tp.apdu_tracer = None
- def _onchange_apdu_strict(self, param_name, old, new):
- if self.card:
- if new == True:
- self.card._scc._tp.apdu_strict = True
- else:
- self.card._scc._tp.apdu_strict = False
-
def _onchange_verbose(self, param_name, old, new):
PySimLogger.set_verbose(new)
if new == True:
@@ -281,7 +273,7 @@
apdu_cmd_parser.add_argument('--expect-sw', help='expect a specified status word', type=str, default=None)
apdu_cmd_parser.add_argument('--expect-response-regex', help='match response against regex', type=str, default=None)
apdu_cmd_parser.add_argument('--raw', help='Bypass the logical channel (and secure channel)', action='store_true')
- apdu_cmd_parser.add_argument('APDU', type=is_hexstr, help='APDU as hex string')
+ apdu_cmd_parser.add_argument('APDU', type=is_hexstr, help='APDU as hex string (see also: ISO/IEC 7816-3, section 12.1')
@cmd2.with_argparser(apdu_cmd_parser)
def do_apdu(self, opts):
@@ -290,14 +282,23 @@
tracked. Depending on the raw APDU sent, pySim-shell may not continue to work as expected if you e.g. select
a different file."""
+ if not hasattr(self, 'apdu_strict_warning_displayed') and self.apdu_strict is False:
+ self.poutput("Warning: The default for the setable parameter `apdu_strict` will be changed from")
+ self.poutput(" `False` to `True` in future pySim-shell releases. In case you are using")
+ self.poutput(" the `apdu` command from a script that still mixes APDUs with TPDUs, consider")
+ self.poutput(" fixing or adding a `set apdu_strict false` line at the beginning.")
+ self.apdu_strict_warning_displayed = True;
+
# When sending raw APDUs we access the scc object through _scc member of the card object. It should also be
# noted that the apdu command plays an exceptional role since it is the only card accessing command that
# can be executed without the presence of a runtime state (self.rs) object. However, this also means that
# self.lchan is also not present (see method equip).
+ self.card._scc._tp.apdu_strict = self.apdu_strict
if opts.raw or self.lchan is None:
data, sw = self.card._scc.send_apdu(opts.APDU, apply_lchan = False)
else:
data, sw = self.lchan.scc.send_apdu(opts.APDU, apply_lchan = False)
+ self.card._scc._tp.apdu_strict = True
if data:
self.poutput("SW: %s, RESP: %s" % (sw, data))
else:
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index f19790c..6833a90 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -90,7 +90,7 @@
self.sw_interpreter = sw_interpreter
self.apdu_tracer = apdu_tracer
self.proactive_handler = proactive_handler
- self.apdu_strict = False
+ self.apdu_strict = True
@abc.abstractmethod
def __str__(self) -> str:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42441?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: I9a531a825def318b28bf58291d811cf119003fab
Gerrit-Change-Number: 42441
Gerrit-PatchSet: 3
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>