summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <max.suraev@fairwaves.co>2014-06-06 16:36:40 +0200
committerSylvain Munaut <tnt@246tNt.com>2014-06-15 19:00:13 +0200
commitd7b69212f8c7a230102a1313d74fdaa99b86dc9b (patch)
tree452d58bdefcc17d78141811441081987433ceeb9
parenta903b3c1ee27047c79728b18ff6340d23d1aad2e (diff)
mobile: Use osmocom auth API instead of direct calls
Submitted-by: Max <max.suraev@fairwaves.co> Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rw-r--r--src/host/layer23/include/osmocom/bb/mobile/settings.h6
-rw-r--r--src/host/layer23/src/mobile/subscriber.c33
-rw-r--r--src/host/layer23/src/mobile/vty_interface.c9
3 files changed, 20 insertions, 28 deletions
diff --git a/src/host/layer23/include/osmocom/bb/mobile/settings.h b/src/host/layer23/include/osmocom/bb/mobile/settings.h
index f3ac796..cdf6323 100644
--- a/src/host/layer23/include/osmocom/bb/mobile/settings.h
+++ b/src/host/layer23/include/osmocom/bb/mobile/settings.h
@@ -1,12 +1,6 @@
#ifndef _settings_h
#define _settings_h
-/* type of test SIM key */
-enum {
- GSM_SIM_KEY_XOR = 0,
- GSM_SIM_KEY_COMP128
-};
-
struct gsm_settings {
char layer2_socket_path[128];
char sap_socket_path[128];
diff --git a/src/host/layer23/src/mobile/subscriber.c b/src/host/layer23/src/mobile/subscriber.c
index fa59d9f..ba3c328 100644
--- a/src/host/layer23/src/mobile/subscriber.c
+++ b/src/host/layer23/src/mobile/subscriber.c
@@ -24,7 +24,7 @@
#include <string.h>
#include <arpa/inet.h>
#include <osmocom/core/talloc.h>
-#include <osmocom/gsm/comp128.h>
+#include <osmocom/crypt/auth.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
@@ -81,16 +81,6 @@ static char *sim_decode_bcd(uint8_t *data, uint8_t length)
return result;
}
-static void xor96(uint8_t *ki, uint8_t *rand, uint8_t *sres, uint8_t *kc)
-{
- int i;
-
- for (i=0; i < 4; i++)
- sres[i] = rand[i] ^ ki[i];
- for (i=0; i < 8; i++)
- kc[i] = rand[i] ^ ki[i+4];
-}
-
/*
* init/exit
*/
@@ -262,7 +252,7 @@ static int subscr_sim_imsi(struct osmocom_ms *ms, uint8_t *data,
/* decode IMSI, skip first digit (parity) */
imsi = sim_decode_bcd(data + 1, length);
if (strlen(imsi) - 1 > GSM_IMSI_LENGTH - 1 || strlen(imsi) - 1 < 6) {
- LOGP(DMM, LOGL_NOTICE, "IMSI invalid length = %d\n",
+ LOGP(DMM, LOGL_NOTICE, "IMSI invalid length = %zu\n",
strlen(imsi) - 1);
return -EINVAL;
}
@@ -940,22 +930,29 @@ int gsm_subscr_generate_kc(struct osmocom_ms *ms, uint8_t key_seq,
/* test SIM */
if (subscr->sim_type == GSM_SIM_TYPE_TEST) {
struct gsm48_mm_event *nmme;
- uint8_t sres[4];
struct gsm_settings *set = &ms->settings;
+ static struct osmo_sub_auth_data auth = {
+ .type = OSMO_AUTH_TYPE_GSM
+ };
+ struct osmo_auth_vector _vec;
+ struct osmo_auth_vector *vec = &_vec;
+
+ auth.algo = set->test_ki_type;
+ memcpy(auth.u.gsm.ki, set->test_ki, sizeof(auth.u.gsm.ki));
+ int ret = osmo_auth_gen_vec(vec, &auth, rand);
+ if (ret < 0)
+ return ret;
- if (set->test_ki_type == GSM_SIM_KEY_COMP128)
- comp128(set->test_ki, rand, sres, subscr->key);
- else
- xor96(set->test_ki, rand, sres, subscr->key);
/* store sequence */
subscr->key_seq = key_seq;
+ memcpy(subscr->key, vec->kc, 8);
LOGP(DMM, LOGL_INFO, "Sending authentication response\n");
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_AUTH_RESPONSE);
if (!nmsg)
return -ENOMEM;
nmme = (struct gsm48_mm_event *) nmsg->data;
- memcpy(nmme->sres, sres, 4);
+ memcpy(nmme->sres, vec->sres, 4);
gsm48_mmevent_msg(ms, nmsg);
return 0;
diff --git a/src/host/layer23/src/mobile/vty_interface.c b/src/host/layer23/src/mobile/vty_interface.c
index 22ef7ae..5782a17 100644
--- a/src/host/layer23/src/mobile/vty_interface.c
+++ b/src/host/layer23/src/mobile/vty_interface.c
@@ -29,6 +29,7 @@
#include <osmocom/gsm/gsm48.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/signal.h>
+#include <osmocom/crypt/auth.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/networks.h>
@@ -1453,11 +1454,11 @@ static void config_write_ms(struct vty *vty, struct osmocom_ms *ms)
vty_out(vty, " test-sim%s", VTY_NEWLINE);
vty_out(vty, " imsi %s%s", set->test_imsi, VTY_NEWLINE);
switch (set->test_ki_type) {
- case GSM_SIM_KEY_XOR:
+ case OSMO_AUTH_ALG_XOR:
vty_out(vty, " ki xor %s%s",
osmo_hexdump(set->test_ki, 12), VTY_NEWLINE);
break;
- case GSM_SIM_KEY_COMP128:
+ case OSMO_AUTH_ALG_COMP128v1:
vty_out(vty, " ki comp128 %s%s",
osmo_hexdump(set->test_ki, 16), VTY_NEWLINE);
break;
@@ -2500,7 +2501,7 @@ DEFUN(cfg_test_ki_xor, cfg_test_ki_xor_cmd, "ki xor HEX HEX HEX HEX HEX HEX "
ki[i] = strtoul(p, NULL, 16);
}
- set->test_ki_type = GSM_SIM_KEY_XOR;
+ set->test_ki_type = OSMO_AUTH_ALG_XOR;
memcpy(set->test_ki, ki, 12);
return CMD_SUCCESS;
}
@@ -2529,7 +2530,7 @@ DEFUN(cfg_test_ki_comp128, cfg_test_ki_comp128_cmd, "ki comp128 HEX HEX HEX "
ki[i] = strtoul(p, NULL, 16);
}
- set->test_ki_type = GSM_SIM_KEY_COMP128;
+ set->test_ki_type = OSMO_AUTH_ALG_COMP128v1;
memcpy(set->test_ki, ki, 16);
return CMD_SUCCESS;
}