simauth.h (4940B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2017-2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #include <stdint.h> 24 #include <stdbool.h> 25 26 #define EAP_AKA_KI_LEN 16 27 #define EAP_AKA_OPC_LEN 16 28 #define EAP_AKA_AMF_LEN 2 29 #define EAP_AKA_SQN_LEN 6 30 #define EAP_SIM_KC_LEN 8 31 #define EAP_SIM_SRES_LEN 4 32 33 #define NUM_RANDS_MAX 3 34 35 struct iwd_sim_auth; 36 37 typedef void (*sim_auth_unregistered_cb_t)(void *data); 38 39 /* 40 * Callback containing Milenage keys. 41 * 42 * @param res RES value 43 * @param ck CK key 44 * @param ik IK key 45 * @param auts AUTS key, if sync failure this will be non NULL. With a 46 * normal success, this should be NULL. 47 * @param data User data 48 * 49 * Note: If there was an error (invalid AUTN or some other error), all the keys 50 * (res/ck/ik/auts) will be NULL. A sync error will result in res, ck, and ik 51 * being NULL but auts should point to a valid AUTS key. 52 */ 53 typedef void (*sim_auth_check_milenage_cb_t)(const uint8_t *res, 54 const uint8_t *ck, const uint8_t *ik, const uint8_t *auts, 55 void *data); 56 57 /* 58 * Callback with GSM data 59 * 60 * @param sres SRES value 61 * @param kc Kc value 62 * @param user_data User data 63 * 64 * Note: If GSM authentication was unsuccessful sres and kc will both be NULL 65 */ 66 typedef void (*sim_auth_run_gsm_cb_t)(const uint8_t *sres, 67 const uint8_t *kc, void *user_data); 68 69 struct iwd_sim_auth_driver { 70 const char *name; 71 int (*check_milenage)(struct iwd_sim_auth *auth, const uint8_t *rand, 72 const uint8_t *autn, 73 sim_auth_check_milenage_cb_t cb, void *data); 74 int (*run_gsm)(struct iwd_sim_auth *auth, const uint8_t *rands, 75 int num_rands, sim_auth_run_gsm_cb_t cb, 76 void *data); 77 void (*cancel_request)(struct iwd_sim_auth *auth, int id); 78 void (*remove)(struct iwd_sim_auth *auth); 79 }; 80 81 /* 82 * Create a new authentication provider. This new provider will be added to 83 * the list of available providers. It is expected that the auth provider 84 * should be immediately available for auth requests. 85 */ 86 struct iwd_sim_auth *iwd_sim_auth_create( 87 const struct iwd_sim_auth_driver *driver); 88 89 void iwd_sim_auth_set_nai(struct iwd_sim_auth *auth, const char *nai); 90 91 void iwd_sim_auth_set_capabilities(struct iwd_sim_auth *auth, 92 bool sim_supported, bool aka_supported); 93 94 void iwd_sim_auth_set_data(struct iwd_sim_auth *auth, void *driver_data); 95 96 bool iwd_sim_auth_register(struct iwd_sim_auth *auth); 97 98 void *iwd_sim_auth_get_data(struct iwd_sim_auth *auth); 99 100 void iwd_sim_auth_remove(struct iwd_sim_auth *auth); 101 102 const char *iwd_sim_auth_get_nai(struct iwd_sim_auth *auth); 103 104 unsigned int sim_auth_unregistered_watch_add(struct iwd_sim_auth *auth, 105 sim_auth_unregistered_cb_t cb, void *data); 106 107 void sim_auth_unregistered_watch_remove(struct iwd_sim_auth *auth, 108 unsigned int id); 109 /* 110 * Find an appropriate driver for running SIM/AKA algorithms 111 * 112 * @param sim True if the driver should support SIM authentication 113 * @param aka True if the driver should support AKA authentication 114 * 115 * @returns Driver handle found, NULL if none available 116 */ 117 struct iwd_sim_auth *iwd_sim_auth_find(bool sim, bool aka); 118 /* 119 * Check that 'rand' and 'autn' are valid from the server. 120 * 121 * @param auth Auth handle found with iwd_sim_auth_find() 122 * @param rand List of RAND's from the server 123 * @param autn AUTN from server 124 * @param cb Callback with milenage values 125 * @param data User data 126 * 127 * @return Transaction ID, used to cancel the request if needed 128 * < 0 in case of an error 129 */ 130 int sim_auth_check_milenage(struct iwd_sim_auth *auth, 131 const uint8_t *rand, const uint8_t *autn, 132 sim_auth_check_milenage_cb_t cb, void *data); 133 134 /* 135 * Retrieve EAP-SIM Kc and SRES values 136 * 137 * @param Auth Auth handle found with iwd_sim_auth_find() 138 * @param rands Buffer containing N 16 byte RANDs (n == 2 || n == 3) 139 * @param num_rands Number of 16 byte RANDs in 'rand' 140 * @param cb Callback with GSM key values 141 * @param data User data 142 * 143 * @return Transaction ID, used to cancel the request if needed 144 * < 0 in case of an error 145 */ 146 int sim_auth_run_gsm(struct iwd_sim_auth *auth, const uint8_t *rands, 147 int num_rands, sim_auth_run_gsm_cb_t cb, void *data); 148 149 void sim_auth_cancel_request(struct iwd_sim_auth *auth, int id);