From d82e0eb697abab4eb994800ab649bc36cca99a83 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 6 Dec 2011 21:53:42 +0100 Subject: Add a generic abstraction for GSM/3G authentication algorithms Indiidual algorithms can be implemented as plugins. libosmogsm itself only provides COMP128v1 via this generic interface. --- src/gsm/Makefile.am | 2 +- src/gsm/auth_comp128v1.c | 47 ++++++++++++++++++++++++ src/gsm/auth_core.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 src/gsm/auth_comp128v1.c create mode 100644 src/gsm/auth_core.c (limited to 'src') diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am index 2fa6b4dd..ec05148d 100644 --- a/src/gsm/Makefile.am +++ b/src/gsm/Makefile.am @@ -11,7 +11,7 @@ libosmogsm_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c gsm_utils.c \ rsl.c gsm48.c gsm48_ie.c gsm0808.c sysinfo.c \ gprs_cipher_core.c gsm0480.c abis_nm.c gsm0502.c \ gsm0411_utils.c gsm0411_smc.c gsm0411_smr.c \ - lapd_core.c lapdm.c + lapd_core.c lapdm.c auth_core.c auth_comp128v1.c libosmogsm_la_LDFLAGS = -version-info $(LIBVERSION) libosmogsm_la_LIBADD = $(top_builddir)/src/libosmocore.la diff --git a/src/gsm/auth_comp128v1.c b/src/gsm/auth_comp128v1.c new file mode 100644 index 00000000..2e1ad2c9 --- /dev/null +++ b/src/gsm/auth_comp128v1.c @@ -0,0 +1,47 @@ + +/* GSM/GPRS/3G authentication core infrastructure */ + +/* (C) 2010-2011 by Harald Welte + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include + +static int c128v1_gen_vec(struct osmo_auth_vector *vec, + struct osmo_sub_auth_data *aud, + const uint8_t *_rand) +{ + comp128(aud->gsm.ki, _rand, vec->sres, vec->kc); + vec->auth_types = OSMO_AUTH_TYPE_GSM; + + return 0; +} + +static struct osmo_auth_impl c128v1_alg = { + .algo = OSMO_AUTH_ALG_COMP128v1, + .name = "COMP128v1 (libosmogsm built-in)", + .priority = 1000, + .gen_vec = &c128v1_gen_vec, +}; + +static __attribute__((constructor)) void on_dso_load_c128(void) +{ + osmo_auth_register(&c128v1_alg); +} diff --git a/src/gsm/auth_core.c b/src/gsm/auth_core.c new file mode 100644 index 00000000..78121bf7 --- /dev/null +++ b/src/gsm/auth_core.c @@ -0,0 +1,93 @@ +/* GSM/GPRS/3G authentication core infrastructure */ + +/* (C) 2010-2011 by Harald Welte + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include + +#include +#include +#include + +#include + +static LLIST_HEAD(osmo_auths); + +static struct osmo_auth_impl *selected_auths[_OSMO_AUTH_ALG_NUM]; + +/* register a cipher with the core */ +int osmo_auth_register(struct osmo_auth_impl *impl) +{ + if (impl->algo >= ARRAY_SIZE(selected_auths)) + return -ERANGE; + + llist_add_tail(&impl->list, &osmo_auths); + + /* check if we want to select this implementation over others */ + if (!selected_auths[impl->algo] || + (selected_auths[impl->algo]->priority > impl->priority)) + selected_auths[impl->algo] = impl; + + return 0; +} + +/* load all available GPRS cipher plugins */ +int osmo_auth_load(const char *path) +{ + /* load all plugins available from path */ + return osmo_plugin_load_all(path); +} + +int osmo_auth_supported(enum osmo_auth_algo algo) +{ + if (algo >= ARRAY_SIZE(selected_auths)) + return -ERANGE; + + if (selected_auths[algo]) + return 1; + + return 0; +} + +int osmo_auth_gen_vec(struct osmo_auth_vector *vec, + struct osmo_sub_auth_data *aud, + const uint8_t *_rand) +{ + struct osmo_auth_impl *impl = selected_auths[aud->type]; + + if (!impl) + return -ENOENT; + + return impl->gen_vec(vec, aud, _rand); +} + +int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec, + struct osmo_sub_auth_data *aud, + const uint8_t *rand_auts, const uint8_t *auts, + const uint8_t *_rand) +{ + struct osmo_auth_impl *impl = selected_auths[aud->type]; + + if (!impl || !impl->gen_vec_auts) + return -ENOENT; + + return impl->gen_vec_auts(vec, aud, rand_auts, auts, _rand); +} -- cgit v1.2.3