Ejemplo n.º 1
0
int uuid_str2bin(const char *str, u8 *bin)
{
    const char *pos;
    u8 *opos;

    pos = str;
    opos = bin;

    if (hexstr2bin(pos, opos, 4))
        return -1;
    pos += 8;
    opos += 4;

    if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
        return -1;
    pos += 4;
    opos += 2;

    if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
        return -1;
    pos += 4;
    opos += 2;

    if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
        return -1;
    pos += 4;
    opos += 2;

    if (*pos++ != '-' || hexstr2bin(pos, opos, 6))
        return -1;

    return 0;
}
Ejemplo n.º 2
0
static int get_reauth_cb(void *ctx, int argc, char *argv[], char *col[])
{
	struct eap_sim_db_data *data = ctx;
	int i;
	struct eap_sim_reauth *reauth = &data->db_tmp_reauth;

	for (i = 0; i < argc; i++) {
		if (os_strcmp(col[i], "permanent") == 0 && argv[i]) {
			os_strlcpy(data->db_tmp_identity, argv[i],
				   sizeof(data->db_tmp_identity));
			reauth->permanent = data->db_tmp_identity;
		} else if (os_strcmp(col[i], "counter") == 0 && argv[i]) {
			reauth->counter = atoi(argv[i]);
		} else if (os_strcmp(col[i], "mk") == 0 && argv[i]) {
			hexstr2bin(argv[i], reauth->mk, sizeof(reauth->mk));
		} else if (os_strcmp(col[i], "k_encr") == 0 && argv[i]) {
			hexstr2bin(argv[i], reauth->k_encr,
				   sizeof(reauth->k_encr));
		} else if (os_strcmp(col[i], "k_aut") == 0 && argv[i]) {
			hexstr2bin(argv[i], reauth->k_aut,
				   sizeof(reauth->k_aut));
		} else if (os_strcmp(col[i], "k_re") == 0 && argv[i]) {
			hexstr2bin(argv[i], reauth->k_re,
				   sizeof(reauth->k_re));
		}
	}

	return 0;
}
Ejemplo n.º 3
0
static int set_app_config(app_attribs *app_data, char *port_id, u32 subtype,
		char *ibuf, int ilen)
{
	cmd_status status = cmd_success;
	int off;
	int plen;
	u8 applen = 0;
	
	plen=strlen(port_id);
	off = DCB_PORT_OFF + plen + CFG_LEN;

	hexstr2bin(ibuf+off+APP_LEN, &applen, sizeof(applen));

	if (ilen == (off + APP_DATA + applen)) {
		app_data->Length = applen/2;
		if (hexstr2bin(ibuf+off+APP_DATA, app_data->AppData, applen/2))
			return cmd_bad_params;
	} else if (ilen != off) {
		/* at least needs to include the protocol settings */
		printf("error - setcommand has invalid argument length\n");
		return cmd_failed;
	}

	status = put_app(port_id, subtype, app_data);

	if (status != cmd_success)
		printf("error[%d] setting APP data for %s\n", status, port_id);

	return status;
}
Ejemplo n.º 4
0
static int eap_sim_ext_sim_result(struct eap_sm *sm, struct eap_sim_data *data,
				  struct eap_peer_config *conf)
{
	char *resp, *pos;
	size_t i;

	wpa_printf(MSG_DEBUG,
		   "EAP-SIM: Use result from external SIM processing");

	resp = conf->external_sim_resp;
	conf->external_sim_resp = NULL;

	if (os_strncmp(resp, "GSM-AUTH:", 9) != 0) {
		wpa_printf(MSG_DEBUG, "EAP-SIM: Unrecognized external SIM processing response");
		os_free(resp);
		return -1;
	}

	pos = resp + 9;
	for (i = 0; i < data->num_chal; i++) {
		wpa_hexdump(MSG_DEBUG, "EAP-SIM: RAND",
			    data->rand[i], GSM_RAND_LEN);

		if (hexstr2bin(pos, data->kc[i], EAP_SIM_KC_LEN) < 0)
			goto invalid;
		wpa_hexdump_key(MSG_DEBUG, "EAP-SIM: Kc",
				data->kc[i], EAP_SIM_KC_LEN);
		pos += EAP_SIM_KC_LEN * 2;
		if (*pos != ':')
			goto invalid;
		pos++;

		if (hexstr2bin(pos, data->sres[i], EAP_SIM_SRES_LEN) < 0)
			goto invalid;
		wpa_hexdump_key(MSG_DEBUG, "EAP-SIM: SRES",
				data->sres[i], EAP_SIM_SRES_LEN);
		pos += EAP_SIM_SRES_LEN * 2;
		if (i + 1 < data->num_chal) {
			if (*pos != ':')
				goto invalid;
			pos++;
		}
	}

	os_free(resp);
	return 0;

invalid:
	wpa_printf(MSG_DEBUG, "EAP-SIM: Invalid external SIM processing GSM-AUTH response");
	os_free(resp);
	return -1;
}
Ejemplo n.º 5
0
void cardJobSetup(struct _cardJob *j,
                     int spi, int kic, int kid,  // profile data
                     uchar *ICCID,
                     uchar *KIC, uchar *KID, // personal data
                     int counter) {
if (j==0) j = &cardJob; /// default global
//printf("j=%x\n",j);
j->spi = spi; j->kic = kic; j->kid = kid;
strNcpy(j->ICCID,ICCID);
hexstr2bin(j->KID,KID,-1); // copy pair?
hexstr2bin(j->KIC,KIC,-1);
j->counter = counter;
}
Ejemplo n.º 6
0
/*
 * uuid_str2bin
 *
 * Convert an UUID in hex string format to a 16 bytes array
 *
 * from: 00000000-0000-0000-0000-000000000000
 *   to: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
 */
int8_t
uuid_str2bin(const char    *str,
             uint8_t *bin)
{
    const char *inptr = str;
    uint8_t *outptr = bin;
    int sz;

#define ADVANCE_IN       inptr++
#define ADVANCE_BOTH     inptr += sz*2; outptr += sz

    /*  Parse uuid string: first four bytes */
    sz = 4;
    if (hexstr2bin(inptr, outptr, sz)) return NV_KO;
    ADVANCE_BOTH;

    /* skip dash then next 2 bytes */
    if (*inptr != '-') return NV_KO;
    ADVANCE_IN;
    sz = 2;
    if (hexstr2bin(inptr, outptr, sz)) return NV_KO;
    ADVANCE_BOTH;

    /* skip dash then next 2 bytes */
    if (*inptr != '-') return NV_KO;
    ADVANCE_IN;
    sz = 2;
    if (hexstr2bin(inptr, outptr, sz)) return NV_KO;
    ADVANCE_BOTH;

    /* skip dash then next 2 bytes */
    if (*inptr != '-') return NV_KO;
    ADVANCE_IN;
    sz = 2;
    if (hexstr2bin(inptr, outptr, sz)) return NV_KO;
    ADVANCE_BOTH;

    /* skip dash then last 6 bytes */
    if (*inptr != '-') return NV_KO;
    ADVANCE_IN;
    sz = 6;
    if (hexstr2bin(inptr, outptr, sz)) return NV_KO;
    ADVANCE_BOTH;

#undef ADVANCE_IN
#undef ADVANCE_BOTH

    return NV_OK;
}
Ejemplo n.º 7
0
int wpas_wps_er_config(struct wpa_supplicant *wpa_s, const char *uuid,
		       const char *pin, struct wps_new_ap_settings *settings)
{
	u8 u[UUID_LEN];
	struct wps_credential cred;
	size_t len;

	if (uuid_str2bin(uuid, u))
		return -1;
	if (settings->ssid_hex == NULL || settings->auth == NULL ||
	    settings->encr == NULL || settings->key_hex == NULL)
		return -1;

	os_memset(&cred, 0, sizeof(cred));
	len = os_strlen(settings->ssid_hex);
	if ((len & 1) || len > 2 * sizeof(cred.ssid) ||
	    hexstr2bin(settings->ssid_hex, cred.ssid, len / 2))
		return -1;
	cred.ssid_len = len / 2;

	len = os_strlen(settings->key_hex);
	if ((len & 1) || len > 2 * sizeof(cred.key) ||
	    hexstr2bin(settings->key_hex, cred.key, len / 2))
		return -1;
	cred.key_len = len / 2;

	if (os_strcmp(settings->auth, "OPEN") == 0)
		cred.auth_type = WPS_AUTH_OPEN;
	else if (os_strcmp(settings->auth, "WPAPSK") == 0)
		cred.auth_type = WPS_AUTH_WPAPSK;
	else if (os_strcmp(settings->auth, "WPA2PSK") == 0)
		cred.auth_type = WPS_AUTH_WPA2PSK;
	else
		return -1;

	if (os_strcmp(settings->encr, "NONE") == 0)
		cred.encr_type = WPS_ENCR_NONE;
	else if (os_strcmp(settings->encr, "WEP") == 0)
		cred.encr_type = WPS_ENCR_WEP;
	else if (os_strcmp(settings->encr, "TKIP") == 0)
		cred.encr_type = WPS_ENCR_TKIP;
	else if (os_strcmp(settings->encr, "CCMP") == 0)
		cred.encr_type = WPS_ENCR_AES;
	else
		return -1;

	return wps_er_config(wpa_s->wps_er, u, (const u8 *) pin,
			     os_strlen(pin), &cred);
}
Ejemplo n.º 8
0
static int add_pmk_file(struct wlantest *wt, const char *pmk_file)
{
	FILE *f;
	u8 pmk[32];
	char buf[300], *pos;
	struct wlantest_pmk *p;

	f = fopen(pmk_file, "r");
	if (f == NULL) {
		wpa_printf(MSG_ERROR, "Could not open '%s'", pmk_file);
		return -1;
	}

	while (fgets(buf, sizeof(buf), f)) {
		pos = buf;
		while (*pos && *pos != '\r' && *pos != '\n')
			pos++;
		*pos = '\0';
		if (pos - buf < 2 * 32)
			continue;
		if (hexstr2bin(buf, pmk, 32) < 0)
			continue;
		p = os_zalloc(sizeof(*p));
		if (p == NULL)
			break;
		os_memcpy(p->pmk, pmk, 32);
		dl_list_add(&wt->pmk, &p->list);
		wpa_hexdump(MSG_DEBUG, "Added PMK from file", pmk, 32);
	}

	fclose(f);
	return 0;
}
Ejemplo n.º 9
0
static char * wpa_config_parse_string(const char *value, size_t *len)
{
	if (*value == '"') {
		char *pos;
		value++;
		pos = strchr(value, '"');
		if (pos == NULL || pos[1] != '\0')
			return NULL;
		*pos = '\0';
		*len = strlen(value);
		return strdup(value);
	} else {
		u8 *str;
		size_t hlen = strlen(value);
		if (hlen % 1)
			return NULL;
		*len = hlen / 2;
		str = malloc(*len);
		if (str == NULL)
			return NULL;
		if (hexstr2bin(value, str, *len)) {
			free(str);
			return NULL;
		}
		return (char *) str;
	}
}
Ejemplo n.º 10
0
static int wpa_config_parse_psk(struct parse_data *data, int line,
				const char *value)
{
	if (*value == '"') {
		char *pos;
		size_t len;

		value++;
		pos = strrchr(value, '"');
		if (pos)
			*pos = '\0';
		len = strlen(value);
		if (len < 8 || len > 63) {
			wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
				   "length %lu (expected: 8..63) '%s'.",
				   line, (unsigned long) len, value);
			return -1;
		}
		wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
				      (u8 *) value, len);
		data->ssid->passphrase = strdup(value);
		return data->ssid->passphrase == NULL ? -1 : 0;
	}

	if (hexstr2bin(value, data->ssid->psk, PMK_LEN) ||
	    value[PMK_LEN * 2] != '\0') {
		wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
			   line, value);
		return -1;
	}
	data->ssid->psk_set = 1;
	wpa_hexdump_key(MSG_MSGDUMP, "PSK", data->ssid->psk, PMK_LEN);
	return 0;
}
Ejemplo n.º 11
0
static cmd_status set_bwg_desc(char *port_id, char *ibuf, int ilen)
{
	u8 pgid;
	u8 desc_len = 0;
	int plen;
	cmd_status rval = cmd_success;

	plen = strlen(port_id);
	if (ilen >=  DCB_PORT_OFF + plen + PG_DESC_SET_DLEN) {
		hexstr2bin(ibuf+DCB_PORT_OFF + plen + PG_DESC_LEN,
			&desc_len, sizeof(desc_len));
		pgid = *(ibuf + DCB_PORT_OFF + plen + PG_DESC_PGID) & 0x0f;
	} else {
		printf("ilen[%d] < %d\n", ilen, DCB_PORT_OFF + plen +
			PG_DESC_SET_DLEN);
		return cmd_bad_params;
	}

	if (ilen ==  DCB_PORT_OFF + plen + PG_DESC_SET_DLEN + desc_len) {
		if (pgid < 1 || pgid > 8 || desc_len > 100) {
			printf("pgid = %d, desc_len = %d\n", pgid, desc_len);
			rval = cmd_bad_params;
		} else {
			rval = put_bwg_descrpt(port_id, pgid-1,
				ibuf+DCB_PORT_OFF+plen+PG_DESC_DATA);
		}
	} else {
		printf("ilen[%d] != %d\n", ilen, DCB_PORT_OFF + plen +
			PG_DESC_SET_DLEN + desc_len);
		rval = cmd_bad_params;
	}

	return rval;
}
Ejemplo n.º 12
0
static char * wpa_config_parse_string(const char *value, size_t *len)
{
	if (*value == '"') {
		const char *pos;
		char *str;
		value++;
		pos = os_strrchr(value, '"');
		if (pos == NULL || pos[1] != '\0')
			return NULL;
		*len = pos - value;
		str = os_malloc(*len + 1);
		if (str == NULL)
			return NULL;
		os_memcpy(str, value, *len);
		str[*len] = '\0';
		return str;
	} else {
		u8 *str;
		size_t tlen, hlen = os_strlen(value);
		if (hlen & 1)
			return NULL;
		tlen = hlen / 2;
		str = os_malloc(tlen + 1);
		if (str == NULL)
			return NULL;
		if (hexstr2bin(value, str, tlen)) {
			os_free(str);
			return NULL;
		}
		str[tlen] = '\0';
		*len = tlen;
		return (char *) str;
	}
}
int hostapd_wps_config_ap(struct hostapd_data *hapd, const char *ssid,
			  const char *auth, const char *encr, const char *key)
{
	struct wps_credential cred;
	size_t len;

	os_memset(&cred, 0, sizeof(cred));

	len = os_strlen(ssid);
	if ((len & 1) || len > 2 * sizeof(cred.ssid) ||
	    hexstr2bin(ssid, cred.ssid, len / 2))
		return -1;
	cred.ssid_len = len / 2;

	if (os_strncmp(auth, "OPEN", 4) == 0)
		cred.auth_type = WPS_AUTH_OPEN;
	else if (os_strncmp(auth, "WPAPSK", 6) == 0)
		cred.auth_type = WPS_AUTH_WPAPSK;
	else if (os_strncmp(auth, "WPA2PSK", 7) == 0)
		cred.auth_type = WPS_AUTH_WPA2PSK;
	else
		return -1;

	if (encr) {
		if (os_strncmp(encr, "NONE", 4) == 0)
			cred.encr_type = WPS_ENCR_NONE;
		else if (os_strncmp(encr, "WEP", 3) == 0)
			cred.encr_type = WPS_ENCR_WEP;
		else if (os_strncmp(encr, "TKIP", 4) == 0)
			cred.encr_type = WPS_ENCR_TKIP;
		else if (os_strncmp(encr, "CCMP", 4) == 0)
			cred.encr_type = WPS_ENCR_AES;
		else
			return -1;
	} else
		cred.encr_type = WPS_ENCR_NONE;

	if (key) {
		len = os_strlen(key);
		if ((len & 1) || len > 2 * sizeof(cred.key) ||
		    hexstr2bin(key, cred.key, len / 2))
			return -1;
		cred.key_len = len / 2;
	}

	return wps_registrar_config_ap(hapd->wps->registrar, &cred);
}
Ejemplo n.º 14
0
int hostapd_ctrl_iface_pmksa_add(struct hostapd_data *hapd, char *cmd)
{
	u8 spa[ETH_ALEN];
	u8 pmkid[PMKID_LEN];
	u8 pmk[PMK_LEN_MAX];
	size_t pmk_len;
	char *pos, *pos2;
	int akmp = 0, expiration = 0;

	/*
	 * Entry format:
	 * <STA addr> <PMKID> <PMK> <expiration in seconds> <akmp>
	 */

	if (hwaddr_aton(cmd, spa))
		return -1;

	pos = os_strchr(cmd, ' ');
	if (!pos)
		return -1;
	pos++;

	if (hexstr2bin(pos, pmkid, PMKID_LEN) < 0)
		return -1;

	pos = os_strchr(pos, ' ');
	if (!pos)
		return -1;
	pos++;

	pos2 = os_strchr(pos, ' ');
	if (!pos2)
		return -1;
	pmk_len = (pos2 - pos) / 2;
	if (pmk_len < PMK_LEN || pmk_len > PMK_LEN_MAX ||
	    hexstr2bin(pos, pmk, pmk_len) < 0)
		return -1;

	pos = pos2 + 1;

	if (sscanf(pos, "%d %d", &expiration, &akmp) != 2)
		return -1;

	return wpa_auth_pmksa_add2(hapd->wpa_auth, spa, pmk, pmk_len,
				   pmkid, expiration, akmp);
}
Ejemplo n.º 15
0
void print_ttl(UNUSED u16 len, char *info)
{
	u16 ttl;

	hexstr2bin(info, (u8 *)&ttl, sizeof(ttl));
	ttl = ntohs(ttl);
	printf("%d\n", ttl);
}
Ejemplo n.º 16
0
static int wpa_config_parse_psk(const struct parse_data *data,
				struct wpa_ssid *ssid, int line,
				const char *value)
{
	if (*value == '"') {
#ifndef CONFIG_NO_PBKDF2
		const char *pos;
		size_t len;

		value++;
		pos = os_strrchr(value, '"');
		if (pos)
			len = pos - value;
		else
			len = os_strlen(value);
		if (len < 8 || len > 63) {
			wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
				   "length %lu (expected: 8..63) '%s'.",
				   line, (unsigned long) len, value);
			return -1;
		}
		wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
				      (u8 *) value, len);
		if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
		    os_memcmp(ssid->passphrase, value, len) == 0)
			return 0;
		ssid->psk_set = 0;
		os_free(ssid->passphrase);
		ssid->passphrase = os_malloc(len + 1);
		if (ssid->passphrase == NULL)
			return -1;
		os_memcpy(ssid->passphrase, value, len);
		ssid->passphrase[len] = '\0';
		return 0;
#else /* CONFIG_NO_PBKDF2 */
		wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
			   "supported.", line);
		return -1;
#endif /* CONFIG_NO_PBKDF2 */
	}

	if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
	    value[PMK_LEN * 2] != '\0') {
		wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
			   line, value);
		return -1;
	}

	os_free(ssid->passphrase);
	ssid->passphrase = NULL;

	ssid->psk_set = 1;
	wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
	return 0;
}
Ejemplo n.º 17
0
void * hostapd_ctrl_iface_pmksa_create_entry(const u8 *aa, char *cmd)
{
	u8 spa[ETH_ALEN];
	u8 pmkid[PMKID_LEN];
	u8 pmk[PMK_LEN_MAX];
	char *pos;
	int expiration;

	/*
	 * Entry format:
	 * <BSSID> <PMKID> <PMK> <expiration in seconds>
	 */

	if (hwaddr_aton(cmd, spa))
		return NULL;

	pos = os_strchr(cmd, ' ');
	if (!pos)
		return NULL;
	pos++;

	if (hexstr2bin(pos, pmkid, PMKID_LEN) < 0)
		return NULL;

	pos = os_strchr(pos, ' ');
	if (!pos)
		return NULL;
	pos++;

	if (hexstr2bin(pos, pmk, PMK_LEN) < 0)
		return NULL;

	pos = os_strchr(pos, ' ');
	if (!pos)
		return NULL;
	pos++;

	if (sscanf(pos, "%d", &expiration) != 1)
		return NULL;

	return wpa_auth_pmksa_create_entry(aa, spa, pmk, pmkid, expiration);
}
Ejemplo n.º 18
0
static u8 * eap_mschapv2_success(struct eap_sm *sm,
				 struct eap_mschapv2_data *data,
				 struct eap_method_ret *ret,
				 struct eap_mschapv2_hdr *req,
				 size_t *respDataLen)
{
	struct eap_mschapv2_hdr *resp;
	u8 *pos, recv_response[20];
	int len, left;

	wpa_printf(MSG_DEBUG, "EAP-MSCHAPV2: Received success");
	len = be_to_host16(req->length);
	pos = (u8 *) (req + 1);
	if (!data->auth_response_valid || len < sizeof(*req) + 42 ||
	    pos[0] != 'S' || pos[1] != '=' ||
	    hexstr2bin((char *) (pos + 2), recv_response, 20) ||
	    memcmp(data->auth_response, recv_response, 20) != 0) {
		wpa_printf(MSG_WARNING, "EAP-MSCHAPV2: Invalid authenticator "
			   "response in success request");
		ret->methodState = METHOD_DONE;
		ret->decision = DECISION_FAIL;
		return NULL;
	}
	pos += 42;
	left = len - sizeof(*req) - 42;
	while (left > 0 && *pos == ' ') {
		pos++;
		left--;
	}
	wpa_hexdump_ascii(MSG_DEBUG, "EAP-MSCHAPV2: Success message",
			  pos, left);
	wpa_printf(MSG_INFO, "EAP-MSCHAPV2: Authentication succeeded");
	*respDataLen = 6;
	resp = malloc(6);
	if (resp == NULL) {
		wpa_printf(MSG_DEBUG, "EAP-MSCHAPV2: Failed to allocate "
			   "buffer for success response");
		ret->ignore = TRUE;
		return NULL;
	}

	resp->code = EAP_CODE_RESPONSE;
	resp->identifier = req->identifier;
	resp->length = host_to_be16(6);
	resp->type = EAP_TYPE_MSCHAPV2;
	resp->op_code = MSCHAPV2_OP_SUCCESS;

	ret->methodState = METHOD_DONE;
	ret->decision = DECISION_UNCOND_SUCC;
	ret->allowNotifications = FALSE;
	data->success = 1;

	return (u8 *) resp;
}
static int wpa_config_process_os_version(const struct global_parse_data *data,
					 struct wpa_config *config, int line,
					 const char *pos)
{
	if (hexstr2bin(pos, config->os_version, 4)) {
		wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
		return -1;
	}
	wpa_printf(MSG_DEBUG, "os_version=%08x",
		   WPA_GET_BE32(config->os_version));
	return 0;
}
Ejemplo n.º 20
0
int cardJobLoadCfg(struct _cardJob *j,char *_iccid,char *filename) { // Loads Info from a file
if (!j) j = &cardJob;
if (!filename) filename="/root/.telco/sims.cfg";
FILE *f = fopen(filename,"r");
if (!f) {  printf("Load File %s failed\n",filename); return -2;   }
char buf[1024];
while( fgets(buf,sizeof(buf),f) ) {
  uchar *c=buf;
  uchar *iccid = get_word(&c);
  if (strcmp(iccid,_iccid)==0) { // found !
    //printf("FOUND! <%s>\n",c);
   strNcpy( j->ICCID, iccid );
   sscanf( get_wordl(&c,4) ,"%04X", &j->spi); sscanf( get_wordl(&c,2) ,"%02X", &j->kic); sscanf( get_wordl(&c,2) ,"%04X", &j->kid);
   //printf("Line2\n");
   hexstr2bin( j->tar, get_wordl(&c,3),-1);  hexstr2bin( j->KIC, get_wordl(&c,24*2),-1); hexstr2bin( j->KID, get_wordl(&c,24*2),-1);
   //printf("Line3\n");
   uchar *s = get_wordl(&c,24); strNcpy(j->MSISDN,s);
          s = get_wordl(&c,24); strNcpy(j->IMSI,s);
   sscanf( get_wordl(&c,4) ,"%04X", &j->counter);
   fclose(f);
   //printf("NOW - update counter\n");
   mkdir("/root/.telco",S_IRWXU); mkdir("/root/.telco/counter",S_IRWXU); // ensure dir exists
  // Now - update counter - if any
   sprintf(buf,"/root/.telco/counter/%s",j->ICCID);
   f = fopen(buf,"r");
   if (f) {
      if (fgets(buf,sizeof(buf),f)) if (sscanf(buf,"%x",&j->counter)) {
           //printf("CounterUpdated: %d, hex:%x\n",j->counter,j->counter);
           }
      fclose(f);
       }
    j->saveCounter = cardJobSaveCounter;
    //exit(1222);
    return 1; // OK - config loaded
    }
  }
fclose(f);
printf("DataFor ICCID %s not found\n",_iccid);
return 0;
}
Ejemplo n.º 21
0
int mschapv2_verify_auth_response(const u8 *auth_response,
				  const u8 *buf, size_t buf_len)
{
	u8 recv_response[MSCHAPV2_AUTH_RESPONSE_LEN];
	if (buf_len < 2 + 2 * MSCHAPV2_AUTH_RESPONSE_LEN ||
	    buf[0] != 'S' || buf[1] != '=' ||
	    hexstr2bin((char *) (buf + 2), recv_response,
		       MSCHAPV2_AUTH_RESPONSE_LEN) ||
	    os_memcmp(auth_response, recv_response,
		      MSCHAPV2_AUTH_RESPONSE_LEN) != 0)
		return -1;
	return 0;
}
Ejemplo n.º 22
0
static int add_ptk_file(struct wlantest *wt, const char *ptk_file)
{
	FILE *f;
	u8 ptk[64];
	size_t ptk_len;
	char buf[300], *pos;
	struct wlantest_ptk *p;

	f = fopen(ptk_file, "r");
	if (f == NULL) {
		wpa_printf(MSG_ERROR, "Could not open '%s'", ptk_file);
		return -1;
	}

	while (fgets(buf, sizeof(buf), f)) {
		pos = buf;
		while (*pos && *pos != '\r' && *pos != '\n')
			pos++;
		*pos = '\0';
		ptk_len = pos - buf;
		if (ptk_len & 1)
			continue;
		ptk_len /= 2;
		if (ptk_len != 16 && ptk_len != 32 &&
		    ptk_len != 48 && ptk_len != 64)
			continue;
		if (hexstr2bin(buf, ptk, ptk_len) < 0)
			continue;
		p = os_zalloc(sizeof(*p));
		if (p == NULL)
			break;
		if (ptk_len < 48) {
			os_memcpy(p->ptk.tk, ptk, ptk_len);
			p->ptk.tk_len = ptk_len;
			p->ptk_len = 32 + ptk_len;
		} else {
			os_memcpy(p->ptk.kck, ptk, 16);
			p->ptk.kck_len = 16;
			os_memcpy(p->ptk.kek, ptk + 16, 16);
			p->ptk.kek_len = 16;
			os_memcpy(p->ptk.tk, ptk + 32, ptk_len - 32);
			p->ptk.tk_len = ptk_len - 32;
			p->ptk_len = ptk_len;
		}
		dl_list_add(&wt->ptk, &p->list);
		wpa_hexdump(MSG_DEBUG, "Added PTK from file", ptk, ptk_len);
	}

	fclose(f);
	return 0;
}
Ejemplo n.º 23
0
static int add_extra_attr(struct radius_msg *msg,
			  struct extra_radius_attr *attr)
{
	size_t len;
	char *pos;
	u32 val;
	char buf[128];

	switch (attr->syntax) {
	case 's':
		os_snprintf(buf, sizeof(buf), "%s", attr->data);
		len = os_strlen(buf);
		break;
	case 'n':
		buf[0] = '\0';
		len = 1;
		break;
	case 'x':
		pos = attr->data;
		if (pos[0] == '0' && pos[1] == 'x')
			pos += 2;
		len = os_strlen(pos);
		if ((len & 1) || (len / 2) > sizeof(buf)) {
			printf("Invalid extra attribute hexstring\n");
			return -1;
		}
		len /= 2;
		if (hexstr2bin(pos, (u8 *) buf, len) < 0) {
			printf("Invalid extra attribute hexstring\n");
			return -1;
		}
		break;
	case 'd':
		val = htonl(atoi(attr->data));
		os_memcpy(buf, &val, 4);
		len = 4;
		break;
	default:
		printf("Incorrect extra attribute syntax specification\n");
		return -1;
	}

	if (!radius_msg_add_attr(msg, attr->type, (u8 *) buf, len)) {
		printf("Could not add attribute %d\n", attr->type);
		return -1;
	}

	return 0;
}
Ejemplo n.º 24
0
BOOL Cfg::IniStrToW(char *str, WCHAR *wstr)
{
	int		len = (int)strlen(str) + 1;

	if (needIniConvert && *str == '|') { // old style
		hexstr2bin(str + 1, (BYTE *)wstr, len, &len);
	}
	else {
		if (needIniConvert && !IsUTF8(str)) {
			AtoW(str, wstr, len);
		} else {
			U8toW(str, wstr, len);
		}
	}

	return	TRUE;
}
int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len)
{
	char rbuf[MAX_DRV_CMD_SIZE];
	char *cmd = "P2P_GET_NOA";
	int ret;

	wpa_printf(MSG_DEBUG, "%s: Entry", __func__);
	os_memset(buf, 0, len);
	ret = wpa_driver_nl80211_driver_cmd(priv, cmd, rbuf, sizeof(rbuf));
	if (ret <= 0)
		return 0;
	ret >>= 1;
	if (ret > (int)len)
		ret = (int)len;
	hexstr2bin(rbuf, buf, ret);
	return ret;
}
Ejemplo n.º 26
0
static int wpa_config_read_global_os_version(struct wpa_config *config,
					     HKEY hk)
{
	char *str;
	int ret = 0;

	str = wpa_config_read_reg_string(hk, TEXT("os_version"));
	if (str == NULL)
		return 0;

	if (hexstr2bin(str, config->os_version, 4))
		ret = -1;

	os_free(str);

	return ret;
}
Ejemplo n.º 27
0
/*
  1: success
  0: verify_error
 -1: no_digest_user
*/
int VerifyUserNameDigest(const char *user, const BYTE *key)
{
    BYTE		val1[8];
    BYTE		val2[8];
    int			len = 0;
    const char	*p;

    if (!(p = GetUserNameDigestField(user)) || !hexstr2bin(p+2, val1, 8, &len) || len != 8) {
        return -1;
    }

    if (!GenUserNameDigestVal(key, val2)) {
        return -1;
    }

    return	memcmp(val1, val2, 8) == 0 ? 1 : 0;
}
Ejemplo n.º 28
0
int wifi_display_subelem_set(struct wpa_global *global, char *cmd)
{
	char *pos;
	int subelem;
	size_t len;
	struct wpabuf *e;

	pos = os_strchr(cmd, ' ');
	if (pos == NULL)
		return -1;
	*pos++ = '\0';
	subelem = atoi(cmd);
	if (subelem < 0 || subelem >= MAX_WFD_SUBELEMS)
		return -1;

	len = os_strlen(pos);
	if (len & 1)
		return -1;
	len /= 2;

	if (len == 0) {
		/* Clear subelement */
		e = NULL;
		wpa_printf(MSG_DEBUG, "WFD: Clear subelement %d", subelem);
	} else {
		e = wpabuf_alloc(1 + len);
		if (e == NULL)
			return -1;
		wpabuf_put_u8(e, subelem);
		if (hexstr2bin(pos, wpabuf_put(e, len), len) < 0) {
			wpabuf_free(e);
			return -1;
		}
		wpa_printf(MSG_DEBUG, "WFD: Set subelement %d", subelem);
	}

	wpabuf_free(global->wfd_subelem[subelem]);
	global->wfd_subelem[subelem] = e;
	wifi_display_update_wfd_ie(global);

	return 0;
}
Ejemplo n.º 29
0
/**
 * wpas_dispatch_bssid_method - dispatch messages for scanned networks
 * @message: the incoming dbus message
 * @wpa_s: a network interface's data
 * @bssid: bssid of the scanned network we're interested in
 * Returns: a reply dbus message, or a dbus error message
 *
 * This function dispatches all incoming dbus messages for scanned networks.
 */
static DBusMessage * wpas_dispatch_bssid_method(DBusMessage *message,
						struct wpa_supplicant *wpa_s,
						const char *bssid_txt)
{
	u8 bssid[ETH_ALEN];
	struct wpa_bss *bss;

	if (hexstr2bin(bssid_txt, bssid, ETH_ALEN) < 0)
		return wpas_dbus_new_invalid_bssid_error(message);

	bss = wpa_bss_get_bssid(wpa_s, bssid);
	if (bss == NULL)
		return wpas_dbus_new_invalid_bssid_error(message);

	/* Dispatch the method call against the scanned bssid */
	if (os_strcmp(dbus_message_get_member(message), "properties") == 0)
		return wpas_dbus_bssid_properties(message, wpa_s, bss);

	return NULL;
}
Ejemplo n.º 30
0
static u8 * eap_fast_parse_hex(const char *value, size_t *len)
{
	int hlen;
	u8 *buf;

	if (value == NULL)
		return NULL;
	hlen = os_strlen(value);
	if (hlen & 1)
		return NULL;
	*len = hlen / 2;
	buf = os_malloc(*len);
	if (buf == NULL)
		return NULL;
	if (hexstr2bin(value, buf, *len)) {
		os_free(buf);
		return NULL;
	}
	return buf;
}