2016-12-08 16:50:03 +00:00
|
|
|
/* Test Osmocom Authentication Protocol */
|
|
|
|
/*
|
2017-11-12 16:00:26 +00:00
|
|
|
* (C) 2016 by sysmocom - s.f.m.c. GmbH
|
|
|
|
* Author: Neels Hofmeyr
|
2016-12-08 16:50:03 +00:00
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-01-12 15:47:13 +00:00
|
|
|
#include <osmocom/core/application.h>
|
2016-12-08 16:50:03 +00:00
|
|
|
#include <osmocom/core/logging.h>
|
|
|
|
#include <osmocom/core/utils.h>
|
|
|
|
#include <osmocom/gsm/oap.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
static struct msgb *oap_encoded(const struct osmo_oap_message *oap_msg)
|
|
|
|
{
|
|
|
|
struct msgb *msgb = msgb_alloc_headroom(1000, 64, __func__);
|
|
|
|
OSMO_ASSERT(msgb);
|
|
|
|
osmo_oap_encode(msgb, oap_msg);
|
|
|
|
return msgb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool encode_decode_makes_same_msg(struct osmo_oap_message *oap_msg)
|
|
|
|
{
|
|
|
|
struct osmo_oap_message oap_msg_decoded;
|
|
|
|
struct msgb *msgb;
|
|
|
|
int rc;
|
|
|
|
bool result;
|
|
|
|
memset(&oap_msg_decoded, 0, sizeof(oap_msg_decoded));
|
|
|
|
|
|
|
|
msgb = oap_encoded(oap_msg);
|
|
|
|
printf("encoded message:\n%s\n",
|
|
|
|
osmo_hexdump((void*)msgb_l2(msgb), msgb_l2len(msgb)));
|
|
|
|
rc = osmo_oap_decode(&oap_msg_decoded, msgb_l2(msgb), msgb_l2len(msgb));
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
printf("osmo_oap_decode() returned error: %d\n", rc);
|
|
|
|
result = false;
|
|
|
|
goto free_msgb;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = memcmp(oap_msg, &oap_msg_decoded, sizeof(oap_msg_decoded));
|
|
|
|
if (rc) {
|
|
|
|
printf("decoded message mismatches encoded message\n");
|
|
|
|
printf("original:\n%s\n",
|
|
|
|
osmo_hexdump((void*)oap_msg, sizeof(*oap_msg)));
|
|
|
|
printf("en- and decoded:\n%s\n",
|
|
|
|
osmo_hexdump((void*)&oap_msg_decoded, sizeof(oap_msg_decoded)));
|
|
|
|
result = false;
|
|
|
|
goto free_msgb;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("ok\n");
|
|
|
|
result = true;
|
|
|
|
|
|
|
|
free_msgb:
|
|
|
|
talloc_free(msgb);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_oap_messages_dec_enc(void)
|
|
|
|
{
|
|
|
|
printf("Testing OAP messages\n");
|
|
|
|
|
|
|
|
struct osmo_oap_message oap_msg;
|
|
|
|
|
|
|
|
#define CLEAR() memset(&oap_msg, 0, sizeof(oap_msg))
|
|
|
|
#define CHECK() OSMO_ASSERT(encode_decode_makes_same_msg(&oap_msg))
|
|
|
|
|
|
|
|
printf("- Register Request\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_REGISTER_REQUEST;
|
|
|
|
oap_msg.client_id = 0x2342;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
printf("- Register Error\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_REGISTER_ERROR;
|
|
|
|
oap_msg.cause = GMM_CAUSE_PROTO_ERR_UNSPEC;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
printf("- Register Result\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_REGISTER_RESULT;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
printf("- Challenge Request, no rand, no autn\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_CHALLENGE_REQUEST;
|
|
|
|
oap_msg.rand_present = 0;
|
|
|
|
oap_msg.autn_present = 0;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
printf("- Challenge Request, with rand, no autn\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_CHALLENGE_REQUEST;
|
|
|
|
osmo_hexparse("0102030405060708090a0b0c0d0e0f10",
|
|
|
|
oap_msg.rand, 16);
|
|
|
|
oap_msg.rand_present = 1;
|
|
|
|
oap_msg.autn_present = 0;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
printf("- Challenge Request, no rand, with autn\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_CHALLENGE_REQUEST;
|
|
|
|
oap_msg.rand_present = 0;
|
|
|
|
osmo_hexparse("cec4e3848a33000086781158ca40f136",
|
|
|
|
oap_msg.autn, 16);
|
|
|
|
oap_msg.autn_present = 1;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
printf("- Challenge Request, with rand, with autn\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_CHALLENGE_REQUEST;
|
|
|
|
osmo_hexparse("0102030405060708090a0b0c0d0e0f10",
|
|
|
|
oap_msg.rand, 16);
|
|
|
|
oap_msg.rand_present = 1;
|
|
|
|
osmo_hexparse("cec4e3848a33000086781158ca40f136",
|
|
|
|
oap_msg.autn, 16);
|
|
|
|
oap_msg.autn_present = 1;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
printf("- Challenge Error\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_CHALLENGE_ERROR;
|
|
|
|
oap_msg.cause = GMM_CAUSE_GSM_AUTH_UNACCEPT;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
printf("- Challenge Result\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_CHALLENGE_RESULT;
|
|
|
|
osmo_hexparse("0102030405060708",
|
|
|
|
oap_msg.xres, 8);
|
|
|
|
oap_msg.xres_present = 1;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
printf("- Sync Request\n");
|
|
|
|
CLEAR();
|
|
|
|
oap_msg.message_type = OAP_MSGT_SYNC_REQUEST;
|
GSUP, OAP, osmo-gen-vec: fix AUTS length to 14, not 16
GSUP transmits AUTS for UMTS authentication procedures, and OAP uses the same
procedures to authenticate. osmo-gen-vec is a utility program that passes AUTS
to our osmo_auth_gen_vec_auts() API.
According to 3GPP 33.102 6.3.3, AUTS = SQN^AK || MAC-S, which are 6 || 8 == 14
bytes. This is confirmed by 24.008 9.2.3a where the TLV has 16 bytes, TL = 2
and AUTS being the V = 14.
It is not harmful for milenage_gen_vec_auts() to pass two more AUTS bytes. But
writing 16 bytes to a GSUP struct is a potential problem when passing in a 14
byte long AUTS buffer to the GSUP API, which then reads past the AUTS buffer.
The API implies the length, so far to be 16, so passing in a 14 byte buffer to
GSUP would require copying to a larger buffer first.
Fix this by using a length of 14 for AUTS everywhere instead.
This constitues an ABI breakage, we may handle it as a "fix before an official
release", otherwise we need a version bump.
The OAP protocol document has also been updated, needs an update in the
osmo-gsm-manuals as well.
Change-Id: If25b173d9ec57ea4c504d860954912b7d82af455
2017-02-02 19:05:14 +00:00
|
|
|
osmo_hexparse("102030405060708090a0b0c0d0e0",
|
|
|
|
oap_msg.auts, 14);
|
2016-12-08 16:50:03 +00:00
|
|
|
oap_msg.auts_present = 1;
|
|
|
|
CHECK();
|
|
|
|
|
|
|
|
/* Sync Error and Sync Result are not used in OAP */
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct log_info_cat default_categories[] = {
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct log_info info = {
|
|
|
|
.cat = default_categories,
|
|
|
|
.num_cat = ARRAY_SIZE(default_categories),
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2018-04-05 01:02:35 +00:00
|
|
|
void *ctx = talloc_named_const(NULL, 0, "oap_test");
|
|
|
|
osmo_init_logging2(ctx, &info);
|
|
|
|
msgb_talloc_ctx_init(ctx, 0);
|
2016-12-08 16:50:03 +00:00
|
|
|
|
|
|
|
test_oap_messages_dec_enc();
|
|
|
|
|
|
|
|
printf("Done.\n");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|