laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/33090 )
Change subject: osmo-auc-gen: Convert over to osmo_auth_gen_vec*2 API ......................................................................
osmo-auc-gen: Convert over to osmo_auth_gen_vec*2 API
This allows the tool to support K/OPc lengths != 128 bit.
Let's add more length checks of command-line arguments while we're adding those checks for K/OPc.
Change-Id: Iffed02ec0fc9c9a996da6f218d67314e381cbb29 --- M utils/osmo-auc-gen.c 1 file changed, 47 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/90/33090/1
diff --git a/utils/osmo-auc-gen.c b/utils/osmo-auc-gen.c index e3e1b43..765ca0b 100644 --- a/utils/osmo-auc-gen.c +++ b/utils/osmo-auc-gen.c @@ -80,7 +80,7 @@ } }
-static struct osmo_sub_auth_data test_aud = { +static struct osmo_sub_auth_data2 test_aud = { .type = OSMO_AUTH_TYPE_NONE, .algo = OSMO_AUTH_ALG_NONE, }; @@ -114,6 +114,7 @@ struct osmo_auth_vector *vec = &_vec; uint8_t _rand[16], _auts[14]; uint64_t sqn = 0; + /* 3GPP TS 33.102 6.3.7: "The authentication key (K) shall have a length of 128 bits or 256 bits." */ unsigned int ind = 0; int rc, option_index; int rand_is_set = 0; @@ -174,10 +175,21 @@ case OSMO_AUTH_TYPE_GSM: rc = osmo_hexparse(optarg, test_aud.u.gsm.ki, sizeof(test_aud.u.gsm.ki)); + if (rc != sizeof(test_aud.u.gsm.ki)) { + fprintf(stderr, "Invalid Ki length %d\n", rc); + exit(2); + } break; case OSMO_AUTH_TYPE_UMTS: rc = osmo_hexparse(optarg, test_aud.u.umts.k, sizeof(test_aud.u.umts.k)); + /* 3GPP TS 33.102 6.3.7: "The authentication key (K) shall have a length of + * 128 bits or 256 bits." */ + if (rc != 16 && rc != 32) { + fprintf(stderr, "Invalid K length %d\n", rc); + exit(2); + } + test_aud.u.umts.k_len = rc; break; default: fprintf(stderr, "please specify 2g/3g first!\n"); @@ -190,6 +202,11 @@ } rc = osmo_hexparse(optarg, test_aud.u.umts.opc, sizeof(test_aud.u.umts.opc)); + if (rc != 16 && rc != 32) { + fprintf(stderr, "Invalid OPC length %d\n", rc); + exit(2); + } + test_aud.u.umts.opc_len = rc; test_aud.u.umts.opc_is_op = 0; break; case 'O': @@ -199,6 +216,11 @@ } rc = osmo_hexparse(optarg, test_aud.u.umts.opc, sizeof(test_aud.u.umts.opc)); + if (rc != 16 && rc != 32) { + fprintf(stderr, "Invalid OP length %d\n", rc); + exit(2); + } + test_aud.u.umts.opc_len = rc; test_aud.u.umts.opc_is_op = 1; break; case 'A': @@ -216,6 +238,10 @@ } rc = osmo_hexparse(optarg, test_aud.u.umts.amf, sizeof(test_aud.u.umts.amf)); + if (rc != 2) { + fprintf(stderr, "Invalid AMF length %d\n", rc); + exit(2); + } break; case 's': if (test_aud.type != OSMO_AUTH_TYPE_UMTS) { @@ -242,6 +268,10 @@ break; case 'r': rc = osmo_hexparse(optarg, _rand, sizeof(_rand)); + if (rc != sizeof(_rand)) { + fprintf(stderr, "Invalid RAND length %d\n", rc); + exit(2); + } rand_is_set = 1; break; case 'I': @@ -316,9 +346,9 @@ }
if (!auts_is_set) - rc = osmo_auth_gen_vec(vec, &test_aud, _rand); + rc = osmo_auth_gen_vec2(vec, &test_aud, _rand); else - rc = osmo_auth_gen_vec_auts(vec, &test_aud, _auts, _rand, _rand); + rc = osmo_auth_gen_vec_auts2(vec, &test_aud, _auts, _rand, _rand); if (rc < 0) { if (!auts_is_set) fprintf(stderr, "error generating auth vector\n");