This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Vadim Yanitskiy gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/7397 libmsc/VTY: clean up the a3a8 command implementation This change separates the 'subscriber ID a3a8 none' into a separate command in order to simplify the original one. Also, let's obtain and then update subscriber info after making sure that both authentication algorithm and Ki are valid. Change-Id: Ia21d4c97c30505e1826aa401c5da180dd2ba27d2 --- M openbsc/src/libmsc/vty_interface_layer3.c 1 file changed, 68 insertions(+), 34 deletions(-) git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/97/7397/1 diff --git a/openbsc/src/libmsc/vty_interface_layer3.c b/openbsc/src/libmsc/vty_interface_layer3.c index a97e1ec..f2ac626 100644 --- a/openbsc/src/libmsc/vty_interface_layer3.c +++ b/openbsc/src/libmsc/vty_interface_layer3.c @@ -22,6 +22,7 @@ #include <limits.h> #include <unistd.h> #include <stdbool.h> +#include <strings.h> #include <inttypes.h> #include <time.h> @@ -775,34 +776,63 @@ return CMD_SUCCESS; } -#define A3A8_ALG_TYPES "(none|xor|comp128v1|comp128v2|comp128v3)" +#define A3A8_ALG_TYPES "(xor|comp128v1|comp128v2|comp128v3)" #define A3A8_ALG_HELP \ - "Use No A3A8 algorithm\n" \ "Use XOR algorithm\n" \ "Use COMP128v1 algorithm\n" \ "Use COMP128v2 algorithm\n" \ "Use COMP128v3 algorithm\n" -DEFUN(ena_subscr_a3a8, - ena_subscr_a3a8_cmd, - "subscriber " SUBSCR_TYPES " ID a3a8 " A3A8_ALG_TYPES " [KI]", +DEFUN(ena_subscr_no_a3a8, + ena_subscr_no_a3a8_cmd, + "subscriber " SUBSCR_TYPES " ID a3a8 none", SUBSCR_HELP "Set a3a8 parameters for the subscriber\n" - A3A8_ALG_HELP "Encryption Key Ki\n") + "Use No A3A8 algorithm\n") { - struct gsm_network *gsmnet = gsmnet_from_vty(vty); - struct gsm_subscriber *subscr = - get_subscr_by_argv(gsmnet, argv[0], argv[1]); - const char *alg_str = argv[2]; - const char *ki_str = argc == 4 ? argv[3] : NULL; - struct gsm_auth_info ainfo; - int rc, minlen, maxlen; + struct gsm_subscriber *subscr; + const char *id_type = argv[0]; + const char *id = argv[1]; + int rc; + /* Get subscriber info */ + subscr = get_subscr_by_argv(gsmnet_from_vty(vty), id_type, id); if (!subscr) { vty_out(vty, "%% No subscriber found for %s %s%s", - argv[0], argv[1], VTY_NEWLINE); + id_type, id, VTY_NEWLINE); return CMD_WARNING; } + rc = db_sync_authinfo_for_subscr(NULL, subscr); + + /* The last tuple probably invalid with the new auth settings */ + db_sync_lastauthtuple_for_subscr(NULL, subscr); + subscr_put(subscr); + + if (rc) { + vty_out(vty, "%% Operation has failed%s", VTY_NEWLINE); + return CMD_WARNING; + } + + return CMD_SUCCESS; +} + +DEFUN(ena_subscr_a3a8, + ena_subscr_a3a8_cmd, + "subscriber " SUBSCR_TYPES " ID a3a8 " A3A8_ALG_TYPES " KI", + SUBSCR_HELP "Set a3a8 parameters for the subscriber\n" + A3A8_ALG_HELP "Encryption Key Ki\n") +{ + struct gsm_subscriber *subscr; + struct gsm_auth_info ainfo; + size_t minlen, maxlen; + int rc; + + const char *id_type = argv[0]; + const char *id = argv[1]; + const char *alg_str = argv[2]; + const char *ki_str = argv[3]; + + /* Parse authentication algorithm */ if (!strcasecmp(alg_str, "none")) { ainfo.auth_algo = AUTH_ALGO_NONE; minlen = maxlen = 0; @@ -821,33 +851,35 @@ minlen = maxlen = A38_COMP128_KEY_LEN; } else { /* Unknown method */ - subscr_put(subscr); vty_out(vty, "%% Unknown auth method %s%s", alg_str, VTY_NEWLINE); return CMD_WARNING; } - if (ki_str) { - rc = osmo_hexparse(ki_str, ainfo.a3a8_ki, sizeof(ainfo.a3a8_ki)); - if ((rc > maxlen) || (rc < minlen)) { - subscr_put(subscr); - vty_out(vty, "%% Wrong Ki `%s'%s", - ki_str, VTY_NEWLINE); - return CMD_WARNING; - } - ainfo.a3a8_ki_len = rc; - } else { - ainfo.a3a8_ki_len = 0; - if (minlen) { - subscr_put(subscr); - vty_out(vty, "%% Missing Ki argument%s", VTY_NEWLINE); - return CMD_WARNING; - } + /* Make sure KI is valid */ + if (!osmo_is_hexstr(ki_str, minlen * 2, maxlen * 2, true)) { + vty_out(vty, "%% Invalid value for KI: '%s'%s", + ki_str, VTY_NEWLINE); + return CMD_WARNING; } - rc = db_sync_authinfo_for_subscr( - ainfo.auth_algo == AUTH_ALGO_NONE ? NULL : &ainfo, - subscr); + /* Copy KI */ + ainfo.a3a8_ki_len = osmo_hexparse(ki_str, ainfo.a3a8_ki, + sizeof(ainfo.a3a8_ki)); + if (ainfo.a3a8_ki_len < minlen || ainfo.a3a8_ki_len > maxlen) { + vty_out(vty, "%% Couldn't parse KI value%s", VTY_NEWLINE); + return CMD_WARNING; + } + + /* Get subscriber info */ + subscr = get_subscr_by_argv(gsmnet_from_vty(vty), id_type, id); + if (!subscr) { + vty_out(vty, "%% No subscriber found for %s %s%s", + id_type, id, VTY_NEWLINE); + return CMD_WARNING; + } + + rc = db_sync_authinfo_for_subscr(&ainfo, subscr); /* the last tuple probably invalid with the new auth settings */ db_sync_lastauthtuple_for_subscr(NULL, subscr); @@ -857,6 +889,7 @@ vty_out(vty, "%% Operation has failed%s", VTY_NEWLINE); return CMD_WARNING; } + return CMD_SUCCESS; } @@ -1278,6 +1311,7 @@ install_element(ENABLE_NODE, &ena_subscr_name_cmd); install_element(ENABLE_NODE, &ena_subscr_extension_cmd); install_element(ENABLE_NODE, &ena_subscr_authorized_cmd); + install_element(ENABLE_NODE, &ena_subscr_no_a3a8_cmd); install_element(ENABLE_NODE, &ena_subscr_a3a8_cmd); install_element(ENABLE_NODE, &ena_subscr_handover_cmd); install_element(ENABLE_NODE, &subscriber_purge_cmd); -- To view, visit https://gerrit.osmocom.org/7397 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia21d4c97c30505e1826aa401c5da180dd2ba27d2 Gerrit-PatchSet: 1 Gerrit-Project: openbsc Gerrit-Branch: master Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>