diff mbox

use osmocom auth API instead of direct calls

Message ID 1402065400-7969-1-git-send-email-Max.Suraev@fairwaves.co
State Accepted, archived
Headers show

Commit Message

Max June 6, 2014, 2:36 p.m. UTC
---
 .../layer23/include/osmocom/bb/mobile/settings.h   |  6 ----
 src/host/layer23/src/mobile/subscriber.c           | 33 ++++++++++------------
 src/host/layer23/src/mobile/vty_interface.c        |  9 +++---
 3 files changed, 20 insertions(+), 28 deletions(-)

Comments

Max June 6, 2014, 2:52 p.m. UTC | #1
This patch switches away from directly calling COMP128 to using generic osmocom
authentication API. The idea is that bypassing auth API will be deprecated in future
versions of libosmocore. Using generic API will allow us to trivially introduce
support for other algorithms like COMP128v23 for example.

Note: I'd appreciate help with testing to make sure there are no regressions.

-- best regards,
Max,
http://fairwaves.co
Choukou Moun June 6, 2014, 7:37 p.m. UTC | #2
Hello,

Im sorry for this newbies question but how to appling this patch to my
osmocom-bb install ?

Thanks for the plsong time to respond to me

Best.
Le 6 juin 2014 15:53, "☎" <Max.Suraev@fairwaves.co> a écrit :

> This patch switches away from directly calling COMP128 to using generic
> osmocom
> authentication API. The idea is that bypassing auth API will be deprecated
> in future
> versions of libosmocore. Using generic API will allow us to trivially
> introduce
> support for other algorithms like COMP128v23 for example.
>
> Note: I'd appreciate help with testing to make sure there are no
> regressions.
>
> -- best regards,
> Max,
> http://fairwaves.co
>
>
>
Max June 6, 2014, 11:52 p.m. UTC | #3
Something like this:

cd osmocom-bb
patch -p1 < "use osmocom auth API instead of direct calls.patch"

06.06.2014 21:37, Choukou Moun пишет:
> Hello,
> 
> Im sorry for this newbies question but how to appling this patch to my osmocom-bb
> install ?
> 
> Thanks for the plsong time to respond to me
> 
> Best.
> 
> Le 6 juin 2014 15:53, "☎" <Max.Suraev@fairwaves.co <mailto:Max.Suraev@fairwaves.co>>
> a écrit :
> 
>     This patch switches away from directly calling COMP128 to using generic osmocom
>     authentication API. The idea is that bypassing auth API will be deprecated in future
>     versions of libosmocore. Using generic API will allow us to trivially introduce
>     support for other algorithms like COMP128v23 for example.
> 
>     Note: I'd appreciate help with testing to make sure there are no regressions.
> 
>     -- best regards,
>     Max,
>     http://fairwaves.co
> 
>
Paul Wise June 7, 2014, 1:04 a.m. UTC | #4
On Sat, Jun 7, 2014 at 7:52 AM, ☎ <Max.Suraev@fairwaves.co> wrote:

> Something like this:
>
> cd osmocom-bb
> patch -p1 < "use osmocom auth API instead of direct calls.patch"

A better way to do it would be to save the mail as an mbox and then
run this. That way you get a proper commit in the git repository.

cd osmocom-bb
git am "use osmocom auth API instead of direct calls.patch"
Max June 7, 2014, 10:08 a.m. UTC | #5
Instead of saving email you could get patch from
http://patchwork.ozlabs.org/project/osmocom-bb/list/

That's a convenient way to track other patches pending review as well.

07.06.2014 03:04, Paul Wise пишет:
> On Sat, Jun 7, 2014 at 7:52 AM, ☎ <Max.Suraev@fairwaves.co> wrote:
> 
>> Something like this:
>>
>> cd osmocom-bb
>> patch -p1 < "use osmocom auth API instead of direct calls.patch"
> 
> A better way to do it would be to save the mail as an mbox and then
> run this. That way you get a proper commit in the git repository.
> 
> cd osmocom-bb
> git am "use osmocom auth API instead of direct calls.patch"
>
diff mbox

Patch

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;
 }