static void rx_data_eapol_key_1_of_4(struct wlantest *wt, const u8 *dst, const u8 *src, const u8 *data, size_t len) { struct wlantest_bss *bss; struct wlantest_sta *sta; const struct ieee802_1x_hdr *eapol; const struct wpa_eapol_key *hdr; wpa_printf(MSG_DEBUG, "EAPOL-Key 1/4 " MACSTR " -> " MACSTR, MAC2STR(src), MAC2STR(dst)); bss = bss_get(wt, src); if (bss == NULL) return; sta = sta_get(bss, dst); if (sta == NULL) return; eapol = (const struct ieee802_1x_hdr *) data; hdr = (const struct wpa_eapol_key *) (eapol + 1); if (is_zero(hdr->key_nonce, WPA_NONCE_LEN)) { add_note(wt, MSG_INFO, "EAPOL-Key 1/4 from " MACSTR " used zero nonce", MAC2STR(src)); } if (!is_zero(hdr->key_rsc, 8)) { add_note(wt, MSG_INFO, "EAPOL-Key 1/4 from " MACSTR " used non-zero Key RSC", MAC2STR(src)); } os_memcpy(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN); }
static u8 * decrypt_eapol_key_data_aes(struct wlantest *wt, const u8 *kek, const struct wpa_eapol_key *hdr, size_t *len) { u8 *buf; u16 keydatalen = WPA_GET_BE16(hdr->key_data_length); if (keydatalen % 8) { add_note(wt, MSG_INFO, "Unsupported AES-WRAP len %d", keydatalen); return NULL; } keydatalen -= 8; /* AES-WRAP adds 8 bytes */ buf = os_malloc(keydatalen); if (buf == NULL) return NULL; if (aes_unwrap(kek, keydatalen / 8, (u8 *) (hdr + 1), buf)) { os_free(buf); add_note(wt, MSG_INFO, "AES unwrap failed - could not decrypt EAPOL-Key " "key data"); return NULL; } *len = keydatalen; return buf; }
static int tdls_verify_mic_teardown(struct wlantest *wt, struct wlantest_tdls *tdls, u8 trans_seq, const u8 *reason_code, struct ieee802_11_elems *elems) { u8 *buf, *pos; int len; u8 mic[16]; int ret; const struct rsn_ftie *rx_ftie; struct rsn_ftie *tmp_ftie; if (elems->link_id == NULL || elems->ftie == NULL || elems->ftie_len < sizeof(struct rsn_ftie)) return -1; len = 2 + 18 + 2 + 1 + 1 + 2 + elems->ftie_len; buf = os_zalloc(len); if (buf == NULL) return -1; pos = buf; /* 1) Link Identifier IE */ os_memcpy(pos, elems->link_id - 2, 2 + 18); pos += 2 + 18; /* 2) Reason Code */ os_memcpy(pos, reason_code, 2); pos += 2; /* 3) Dialog token */ *pos++ = tdls->dialog_token; /* 4) Transaction Sequence number */ *pos++ = trans_seq; /* 5) FTIE, with the MIC field of the FTIE set to 0 */ os_memcpy(pos, elems->ftie - 2, 2 + elems->ftie_len); pos += 2; tmp_ftie = (struct rsn_ftie *) pos; os_memset(tmp_ftie->mic, 0, 16); pos += elems->ftie_len; wpa_hexdump(MSG_DEBUG, "TDLS: Data for FTIE MIC", buf, pos - buf); wpa_hexdump_key(MSG_DEBUG, "TDLS: KCK", tdls->tpk.kck, 16); ret = omac1_aes_128(tdls->tpk.kck, buf, pos - buf, mic); os_free(buf); if (ret) return -1; wpa_hexdump(MSG_DEBUG, "TDLS: FTIE MIC", mic, 16); rx_ftie = (const struct rsn_ftie *) elems->ftie; if (os_memcmp(mic, rx_ftie->mic, 16) == 0) { add_note(wt, MSG_DEBUG, "TDLS: Valid MIC"); return 0; } add_note(wt, MSG_DEBUG, "TDLS: Invalid MIC"); return -1; }
static struct wlantest_tdls * get_tdls(struct wlantest *wt, const u8 *linkid, int create_new, const u8 *bssid) { struct wlantest_bss *bss; struct wlantest_sta *init, *resp; struct wlantest_tdls *tdls; bss = bss_find(wt, linkid); if (bss == NULL && bssid) { bss = bss_find(wt, bssid); if (bss) add_note(wt, MSG_INFO, "TDLS: Incorrect BSSID " MACSTR " in LinkId?! (init=" MACSTR " resp=" MACSTR ")", MAC2STR(linkid), MAC2STR(linkid + ETH_ALEN), MAC2STR(linkid + 2 * ETH_ALEN)); } if (bss == NULL) return NULL; init = sta_find(bss, linkid + ETH_ALEN); if (init == NULL) return NULL; resp = sta_find(bss, linkid + 2 * ETH_ALEN); if (resp == NULL) return NULL; dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) { if (tdls->init == init && tdls->resp == resp) return tdls; } if (!create_new) return NULL; add_note(wt, MSG_DEBUG, "Add new TDLS link context: initiator " MACSTR " responder " MACSTR " BSSID " MACSTR, MAC2STR(linkid + ETH_ALEN), MAC2STR(linkid + 2 * ETH_ALEN), MAC2STR(bssid)); tdls = os_zalloc(sizeof(*tdls)); if (tdls == NULL) return NULL; tdls->init = init; tdls->resp = resp; dl_list_add(&bss->tdls, &tdls->list); return tdls; }
static void derive_ptk(struct wlantest *wt, struct wlantest_bss *bss, struct wlantest_sta *sta, u16 ver, const u8 *data, size_t len) { struct wlantest_pmk *pmk; wpa_printf(MSG_DEBUG, "Trying to derive PTK for " MACSTR, MAC2STR(sta->addr)); dl_list_for_each(pmk, &bss->pmk, struct wlantest_pmk, list) { wpa_printf(MSG_DEBUG, "Try per-BSS PMK"); if (try_pmk(wt, bss, sta, ver, data, len, pmk) == 0) return; } dl_list_for_each(pmk, &wt->pmk, struct wlantest_pmk, list) { wpa_printf(MSG_DEBUG, "Try global PMK"); if (try_pmk(wt, bss, sta, ver, data, len, pmk) == 0) return; } if (!sta->ptk_set) { struct wlantest_ptk *ptk; int prev_level = wpa_debug_level; wpa_debug_level = MSG_WARNING; dl_list_for_each(ptk, &wt->ptk, struct wlantest_ptk, list) { if (check_mic(ptk->ptk.kck, ver, data, len) < 0) continue; wpa_printf(MSG_INFO, "Pre-set PTK matches for STA " MACSTR " BSSID " MACSTR, MAC2STR(sta->addr), MAC2STR(bss->bssid)); add_note(wt, MSG_DEBUG, "Using pre-set PTK"); os_memcpy(&sta->ptk, &ptk->ptk, sizeof(ptk->ptk)); wpa_hexdump(MSG_DEBUG, "PTK:KCK", sta->ptk.kck, 16); wpa_hexdump(MSG_DEBUG, "PTK:KEK", sta->ptk.kek, 16); wpa_hexdump(MSG_DEBUG, "PTK:TK1", sta->ptk.tk1, 16); if (ptk->ptk_len > 48) wpa_hexdump(MSG_DEBUG, "PTK:TK2", sta->ptk.u.tk2, 16); sta->ptk_set = 1; os_memset(sta->rsc_tods, 0, sizeof(sta->rsc_tods)); os_memset(sta->rsc_fromds, 0, sizeof(sta->rsc_fromds)); } wpa_debug_level = prev_level; } add_note(wt, MSG_DEBUG, "No matching PMK found to derive PTK"); }
static void rx_data_tdls_teardown(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr, const u8 *dst, const u8 *src, const u8 *data, size_t len) { u16 reason; struct ieee802_11_elems elems; struct wlantest_tdls *tdls; if (len < 2) return; reason = WPA_GET_LE16(data); wpa_printf(MSG_DEBUG, "TDLS Teardown " MACSTR " -> " MACSTR " (reason %d)", MAC2STR(src), MAC2STR(dst), reason); if (ieee802_11_parse_elems(data + 2, len - 2, &elems, 1) == ParseFailed || elems.link_id == NULL) return; wpa_printf(MSG_DEBUG, "TDLS Link Identifier: BSSID " MACSTR " initiator STA " MACSTR " responder STA " MACSTR, MAC2STR(elems.link_id), MAC2STR(elems.link_id + ETH_ALEN), MAC2STR(elems.link_id + 2 * ETH_ALEN)); tdls = get_tdls(wt, elems.link_id, 1, bssid); if (tdls) { if (tdls->link_up) add_note(wt, MSG_DEBUG, "TDLS: Link down"); tdls->link_up = 0; tdls->counters[WLANTEST_TDLS_COUNTER_TEARDOWN]++; tdls_verify_mic_teardown(wt, tdls, 4, data, &elems); } }
song& operator<<(const std::vector<note>& notes_) { for (auto n : notes_) { add_note(n); } return *this; }
static u8 * try_all_ptk(struct wlantest *wt, int pairwise_cipher, const struct ieee80211_hdr *hdr, const u8 *data, size_t data_len, size_t *decrypted_len) { struct wlantest_ptk *ptk; u8 *decrypted; int prev_level = wpa_debug_level; wpa_debug_level = MSG_WARNING; dl_list_for_each(ptk, &wt->ptk, struct wlantest_ptk, list) { decrypted = NULL; if ((pairwise_cipher == WPA_CIPHER_CCMP || pairwise_cipher == 0) && ptk->ptk_len == 48) { decrypted = ccmp_decrypt(ptk->ptk.tk1, hdr, data, data_len, decrypted_len); } if ((pairwise_cipher == WPA_CIPHER_TKIP || pairwise_cipher == 0) && ptk->ptk_len == 64) { decrypted = tkip_decrypt(ptk->ptk.tk1, hdr, data, data_len, decrypted_len); } if (decrypted) { wpa_debug_level = prev_level; add_note(wt, MSG_DEBUG, "Found PTK match from list of all known PTKs"); return decrypted; } } wpa_debug_level = prev_level; return NULL; }
static int merge_changes(struct notes_merge_options *o, struct notes_merge_pair *changes, int *num_changes, struct notes_tree *t) { int i, conflicts = 0; trace_printf("\tmerge_changes(num_changes = %i)\n", *num_changes); for (i = 0; i < *num_changes; i++) { struct notes_merge_pair *p = changes + i; trace_printf("\t\t%.7s: %.7s -> %.7s/%.7s\n", sha1_to_hex(p->obj), sha1_to_hex(p->base), sha1_to_hex(p->local), sha1_to_hex(p->remote)); if (!hashcmp(p->base, p->remote)) { /* no remote change; nothing to do */ trace_printf("\t\t\tskipping (no remote change)\n"); } else if (!hashcmp(p->local, p->remote)) { /* same change in local and remote; nothing to do */ trace_printf("\t\t\tskipping (local == remote)\n"); } else if (!hashcmp(p->local, uninitialized) || !hashcmp(p->local, p->base)) { /* no local change; adopt remote change */ trace_printf("\t\t\tno local change, adopted remote\n"); if (add_note(t, p->obj, p->remote, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); } else { /* need file-level merge between local and remote */ trace_printf("\t\t\tneed content-level merge\n"); conflicts += merge_one_change(o, p, t); } } return conflicts; }
//--------------------------------------------------------------------------------------- void ChordEngraver::set_middle_staffobj(ImoRelObj* UNUSED(pRO), ImoStaffObj* pSO, GmoShape* pStaffObjShape, int UNUSED(iInstr), int UNUSED(iStaff), int UNUSED(iSystem), int UNUSED(iCol), LUnits UNUSED(xRight), LUnits UNUSED(xLeft), LUnits UNUSED(yTop)) { add_note(pSO, pStaffObjShape); }
int copy_note(struct notes_tree *t, const unsigned char *from_obj, const unsigned char *to_obj, int force, combine_notes_fn combine_notes) { const unsigned char *note = get_note(t, from_obj); const unsigned char *existing_note = get_note(t, to_obj); if (!force && existing_note) return 1; if (note) return add_note(t, to_obj, note, combine_notes); else if (existing_note) return add_note(t, to_obj, null_sha1, combine_notes); return 0; }
int copy_note(struct notes_tree *t, const struct object_id *from_obj, const struct object_id *to_obj, int force, combine_notes_fn combine_notes) { const struct object_id *note = get_note(t, from_obj); const struct object_id *existing_note = get_note(t, to_obj); if (!force && existing_note) return 1; if (note) return add_note(t, to_obj, note, combine_notes); else if (existing_note) return add_note(t, to_obj, &null_oid, combine_notes); return 0; }
static int try_pmk(struct wlantest *wt, struct wlantest_bss *bss, struct wlantest_sta *sta, u16 ver, const u8 *data, size_t len, struct wlantest_pmk *pmk) { struct wpa_ptk ptk; size_t ptk_len = sta->pairwise_cipher == WPA_CIPHER_TKIP ? 64 : 48; wpa_pmk_to_ptk(pmk->pmk, sizeof(pmk->pmk), "Pairwise key expansion", bss->bssid, sta->addr, sta->anonce, sta->snonce, (u8 *) &ptk, ptk_len, wpa_key_mgmt_sha256(sta->key_mgmt)); if (check_mic(ptk.kck, ver, data, len) < 0) return -1; wpa_printf(MSG_INFO, "Derived PTK for STA " MACSTR " BSSID " MACSTR, MAC2STR(sta->addr), MAC2STR(bss->bssid)); sta->counters[WLANTEST_STA_COUNTER_PTK_LEARNED]++; if (sta->ptk_set) { /* * Rekeying - use new PTK for EAPOL-Key frames, but continue * using the old PTK for frame decryption. */ add_note(wt, MSG_DEBUG, "Derived PTK during rekeying"); os_memcpy(&sta->tptk, &ptk, sizeof(ptk)); wpa_hexdump(MSG_DEBUG, "TPTK:KCK", sta->tptk.kck, 16); wpa_hexdump(MSG_DEBUG, "TPTK:KEK", sta->tptk.kek, 16); wpa_hexdump(MSG_DEBUG, "TPTK:TK1", sta->tptk.tk1, 16); if (ptk_len > 48) wpa_hexdump(MSG_DEBUG, "TPTK:TK2", sta->tptk.u.tk2, 16); sta->tptk_set = 1; return 0; } add_note(wt, MSG_DEBUG, "Derived new PTK"); os_memcpy(&sta->ptk, &ptk, sizeof(ptk)); wpa_hexdump(MSG_DEBUG, "PTK:KCK", sta->ptk.kck, 16); wpa_hexdump(MSG_DEBUG, "PTK:KEK", sta->ptk.kek, 16); wpa_hexdump(MSG_DEBUG, "PTK:TK1", sta->ptk.tk1, 16); if (ptk_len > 48) wpa_hexdump(MSG_DEBUG, "PTK:TK2", sta->ptk.u.tk2, 16); sta->ptk_set = 1; os_memset(sta->rsc_tods, 0, sizeof(sta->rsc_tods)); os_memset(sta->rsc_fromds, 0, sizeof(sta->rsc_fromds)); return 0; }
int notes_cache_put(struct notes_cache *c, struct object_id *key_oid, const char *data, size_t size) { struct object_id value_oid; if (write_object_file(data, size, "blob", &value_oid) < 0) return -1; return add_note(&c->tree, key_oid, &value_oid, NULL); }
int notes_cache_put(struct notes_cache *c, unsigned char key_sha1[20], const char *data, size_t size) { unsigned char value_sha1[20]; if (write_sha1_file(data, size, "blob", value_sha1) < 0) return -1; return add_note(&c->tree, key_sha1, value_sha1, NULL); }
int notes_merge_commit(struct notes_merge_options *o, struct notes_tree *partial_tree, struct commit *partial_commit, unsigned char *result_sha1) { /* * Iterate through files in .git/NOTES_MERGE_WORKTREE and add all * found notes to 'partial_tree'. Write the updates notes tree to * the DB, and commit the resulting tree object while reusing the * commit message and parents from 'partial_commit'. * Finally store the new commit object SHA1 into 'result_sha1'. */ struct dir_struct dir; char *path = xstrdup(git_path(NOTES_MERGE_WORKTREE "/")); int path_len = strlen(path), i; const char *msg = strstr(partial_commit->buffer, "\n\n"); OUTPUT(o, 3, "Committing notes in notes merge worktree at %.*s", path_len - 1, path); if (!msg || msg[2] == '\0') die("partial notes commit has empty message"); msg += 2; memset(&dir, 0, sizeof(dir)); read_directory(&dir, path, path_len, NULL); for (i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; struct stat st; const char *relpath = ent->name + path_len; unsigned char obj_sha1[20], blob_sha1[20]; if (ent->len - path_len != 40 || get_sha1_hex(relpath, obj_sha1)) { OUTPUT(o, 3, "Skipping non-SHA1 entry '%s'", ent->name); continue; } /* write file as blob, and add to partial_tree */ if (stat(ent->name, &st)) die_errno("Failed to stat '%s'", ent->name); if (index_path(blob_sha1, ent->name, &st, HASH_WRITE_OBJECT)) die("Failed to write blob object from '%s'", ent->name); if (add_note(partial_tree, obj_sha1, blob_sha1, NULL)) die("Failed to add resolved note '%s' to notes tree", ent->name); OUTPUT(o, 4, "Added resolved note for object %s: %s", sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1)); } create_notes_commit(partial_tree, partial_commit->parents, msg, result_sha1); OUTPUT(o, 4, "Finalized notes merge commit: %s", sha1_to_hex(result_sha1)); free(path); return 0; }
static int merge_one_change(struct notes_merge_options *o, struct notes_merge_pair *p, struct notes_tree *t) { /* * Return 0 if change is successfully resolved (stored in notes_tree). * Return 1 is change results in a conflict (NOT stored in notes_tree, * but instead written to NOTES_MERGE_WORKTREE with conflict markers). */ switch (o->strategy) { case NOTES_MERGE_RESOLVE_MANUAL: return merge_one_change_manual(o, p, t); case NOTES_MERGE_RESOLVE_OURS: if (o->verbosity >= 2) printf("Using local notes for %s\n", sha1_to_hex(p->obj)); /* nothing to do */ return 0; case NOTES_MERGE_RESOLVE_THEIRS: if (o->verbosity >= 2) printf("Using remote notes for %s\n", sha1_to_hex(p->obj)); if (add_note(t, p->obj, p->remote, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); return 0; case NOTES_MERGE_RESOLVE_UNION: if (o->verbosity >= 2) printf("Concatenating local and remote notes for %s\n", sha1_to_hex(p->obj)); if (add_note(t, p->obj, p->remote, combine_notes_concatenate)) die("failed to concatenate notes " "(combine_notes_concatenate)"); return 0; case NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ: if (o->verbosity >= 2) printf("Concatenating unique lines in local and remote " "notes for %s\n", sha1_to_hex(p->obj)); if (add_note(t, p->obj, p->remote, combine_notes_cat_sort_uniq)) die("failed to concatenate notes " "(combine_notes_cat_sort_uniq)"); return 0; } die("Unknown strategy (%i).", o->strategy); }
static void rx_data_tdls_setup_request(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr, const u8 *dst, const u8 *src, const u8 *data, size_t len) { struct ieee802_11_elems elems; struct wlantest_tdls *tdls; u8 linkid[3 * ETH_ALEN]; if (len < 3) { add_note(wt, MSG_INFO, "Too short TDLS Setup Request " MACSTR " -> " MACSTR, MAC2STR(src), MAC2STR(dst)); return; } wpa_printf(MSG_DEBUG, "TDLS Setup Request " MACSTR " -> " MACSTR, MAC2STR(src), MAC2STR(dst)); if (ieee802_11_parse_elems(data + 3, len - 3, &elems, 1) == ParseFailed || elems.link_id == NULL) return; wpa_printf(MSG_DEBUG, "TDLS Link Identifier: BSSID " MACSTR " initiator STA " MACSTR " responder STA " MACSTR, MAC2STR(elems.link_id), MAC2STR(elems.link_id + ETH_ALEN), MAC2STR(elems.link_id + 2 * ETH_ALEN)); tdls = get_tdls(wt, elems.link_id, 1, bssid); if (tdls) { tdls->counters[WLANTEST_TDLS_COUNTER_SETUP_REQ]++; tdls->dialog_token = data[0]; if (elems.ftie && elems.ftie_len >= sizeof(struct rsn_ftie)) { const struct rsn_ftie *f; f = (const struct rsn_ftie *) elems.ftie; os_memcpy(tdls->inonce, f->snonce, WPA_NONCE_LEN); } } /* Check whether reverse direction context exists already */ os_memcpy(linkid, bssid, ETH_ALEN); os_memcpy(linkid + ETH_ALEN, dst, ETH_ALEN); os_memcpy(linkid + 2 * ETH_ALEN, src, ETH_ALEN); tdls = get_tdls(wt, linkid, 0, bssid); if (tdls) add_note(wt, MSG_INFO, "Reverse direction TDLS context exists"); }
//--------------------------------------------------------------------------------------- void ChordEngraver::set_start_staffobj(ImoRelObj* pRO, ImoStaffObj* pSO, GmoShape* pStaffObjShape, int iInstr, int iStaff, int UNUSED(iSystem), int UNUSED(iCol), LUnits UNUSED(xRight), LUnits UNUSED(xLeft), LUnits UNUSED(yTop)) { m_iInstr = iInstr; m_iStaff = iStaff; m_pChord = dynamic_cast<ImoChord*>(pRO); add_note(pSO, pStaffObjShape); }
/* actual song functions */ song& operator<<(const song& s) { auto start_of_phrase = beat_length_; for (auto t : s.timings_) { add_timing(t); } for (auto n : s.notes_) { n.duration.start += start_of_phrase; add_note(n); } return *this; }
//--------------------------------------------------------------------------------------- void ChordEngraver::set_end_staffobj(ImoRelObj* UNUSED(pRO), ImoStaffObj* pSO, GmoShape* pStaffObjShape, int UNUSED(iInstr), int UNUSED(iStaff), int UNUSED(iSystem), int UNUSED(iCol), LUnits UNUSED(xRight), LUnits UNUSED(xLeft), LUnits UNUSED(yTop)) { add_note(pSO, pStaffObjShape); if (m_numNotesMissing != 0) { LOMSE_LOG_ERROR("[ChordEngraver::set_end_staffobj] Num added notes doesn't match exzpected notes in chord"); throw runtime_error("[ChordEngraver::set_end_staffobj] Num added notes doesn't match exzpected notes in chord"); } }
/* priv <from> <to> <message> */ static void bot_priv(int idx, char *par) { char *from = NULL, *p = NULL, *to = TBUF, *tobot = NULL; int i; from = newsplit(&par); tobot = newsplit(&par); splitc(to, tobot, '@'); p = strchr(from, '@'); if (p != NULL) p++; else p = from; i = nextbot(p); if (i != idx) { fake_alert(idx, "direction", p, "priv_i"); return; } if (!to[0]) return; /* Silently ignore notes to '@bot' this * is legacy code */ if (!strcasecmp(tobot, conf.bot->nick)) { /* For me! */ if (p == from) add_note(to, from, par, -2, 0); else { i = add_note(to, from, par, -1, 0); if (from[0] != '@') switch (i) { case NOTE_ERROR: botnet_send_priv(idx, conf.bot->nick, from, NULL, "%s %s.", "No such user", to); break; } } } else { /* Pass it on */ i = nextbot(tobot); if (i >= 0) botnet_send_priv(i, from, to, tobot, "%s", par); } }
static void rx_data_tdls_setup_confirm_failure(struct wlantest *wt, const u8 *bssid, const u8 *src, u8 dialog_token, u16 status) { struct wlantest_bss *bss; struct wlantest_tdls *tdls; struct wlantest_sta *sta; if (status == WLAN_STATUS_SUCCESS) { add_note(wt, MSG_INFO, "TDLS: Invalid TDLS Setup Confirm from " MACSTR, MAC2STR(src)); return; } bss = bss_find(wt, bssid); if (!bss) return; sta = sta_find(bss, src); if (!sta) return; dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) { if (tdls->init == sta) { if (dialog_token != tdls->dialog_token) { add_note(wt, MSG_DEBUG, "TDLS: Dialog token " "mismatch in TDLS Setup Confirm " "(failure)"); break; } add_note(wt, MSG_DEBUG, "TDLS: Found matching TDLS " "setup session based on dialog token"); tdls->counters[ WLANTEST_TDLS_COUNTER_SETUP_CONF_FAIL]++; break; } } }
struct note_t *setup_transfer(char operation, const char *filename) { int fd; printf("operation %c\n", operation); fd = open(filename, (toupper(operation) == 'T') ? O_RDONLY : O_WRONLY | O_EXCL | O_CREAT, 0666); if (fd < 0) { perror("open"); fprintf(stderr, "Unable to handle file %s\n", filename); return NULL; } return add_note(filename, fd, operation); }
static u8 * decrypt_eapol_key_data(struct wlantest *wt, const u8 *kek, u16 ver, const struct wpa_eapol_key *hdr, size_t *len) { switch (ver) { case WPA_KEY_INFO_TYPE_HMAC_MD5_RC4: return decrypt_eapol_key_data_rc4(wt, kek, hdr, len); case WPA_KEY_INFO_TYPE_HMAC_SHA1_AES: case WPA_KEY_INFO_TYPE_AES_128_CMAC: return decrypt_eapol_key_data_aes(wt, kek, hdr, len); default: add_note(wt, MSG_INFO, "Unsupported EAPOL-Key Key Descriptor Version %u", ver); return NULL; } }
/*main program*/ int main(int argc, char *argv[]) { if(argc > 1){ if(strcmp(argv[1],"-a")==0 || strcmp(argv[1],"add")==0) add_note(); else if(strcmp(argv[1],"-c")==0 || strcmp(argv[1],"configure")==0) create_db(); else if(strcmp(argv[1],"-h")==0 || strcmp(argv[1],"help")==0) u_help(); else if(strcmp(argv[1],"-t")==0 || strcmp(argv[1],"truncate")==0) truncate(); else show_queried_note(argv[1]); } else show_notes(); return 0; }
static void rx_data_eapol_key_4_of_4(struct wlantest *wt, const u8 *dst, const u8 *src, const u8 *data, size_t len) { struct wlantest_bss *bss; struct wlantest_sta *sta; const struct ieee802_1x_hdr *eapol; const struct wpa_eapol_key *hdr; u16 key_info; const u8 *kck; wpa_printf(MSG_DEBUG, "EAPOL-Key 4/4 " MACSTR " -> " MACSTR, MAC2STR(src), MAC2STR(dst)); bss = bss_get(wt, dst); if (bss == NULL) return; sta = sta_get(bss, src); if (sta == NULL) return; eapol = (const struct ieee802_1x_hdr *) data; hdr = (const struct wpa_eapol_key *) (eapol + 1); if (!is_zero(hdr->key_rsc, 8)) { add_note(wt, MSG_INFO, "EAPOL-Key 4/4 from " MACSTR " used " "non-zero Key RSC", MAC2STR(src)); } key_info = WPA_GET_BE16(hdr->key_info); if (!sta->ptk_set && !sta->tptk_set) { add_note(wt, MSG_DEBUG, "No PTK known to process EAPOL-Key 4/4"); return; } kck = sta->ptk.kck; if (sta->tptk_set) { add_note(wt, MSG_DEBUG, "Use TPTK for validation EAPOL-Key MIC"); kck = sta->tptk.kck; } if (check_mic(kck, key_info & WPA_KEY_INFO_TYPE_MASK, data, len) < 0) { add_note(wt, MSG_INFO, "Mismatch in EAPOL-Key 4/4 MIC"); return; } add_note(wt, MSG_DEBUG, "Valid MIC found in EAPOL-Key 4/4"); if (sta->tptk_set) { add_note(wt, MSG_DEBUG, "Update PTK (rekeying)"); os_memcpy(&sta->ptk, &sta->tptk, sizeof(sta->ptk)); sta->ptk_set = 1; sta->tptk_set = 0; os_memset(sta->rsc_tods, 0, sizeof(sta->rsc_tods)); os_memset(sta->rsc_fromds, 0, sizeof(sta->rsc_fromds)); } }
void command_loop(){ char name[64]; char command[16]; char *note_file_path; printf("Please enter your name: "); fflush(stdout); fgets(name, 64, stdin); name[strcspn(name, "\n")] = '\0'; note_file_path = (char *)malloc(strlen(name)+10); sprintf(note_file_path, "notes/%s", name); while (true){ printf("Enter a command: "); fflush(stdout); if (fgets(command, 16, stdin) == NULL) goto exit; switch (command[0]){ case 'a': case 'A': add_note(note_file_path); break; case 'v': case 'V': view_notes(note_file_path); break; case 'q': case 'Q': goto exit; default: puts("Commands: [a]dd_note, [v]iew_notes, [q]uit"); fflush(stdout); break; } } exit: free(note_file_path); return; }
static void write_pcapng_decrypted(struct wlantest *wt) { size_t len; struct pcapng_enhanced_packet *pkt; u8 *pos; u32 *block_len; if (!wt->pcapng || wt->decrypted == NULL) return; add_note(wt, MSG_EXCESSIVE, "decrypted version of the previous frame"); len = sizeof(*pkt) + wt->decrypted_len + 100 + notes_len(wt, 32); pkt = os_zalloc(len); if (pkt == NULL) return; pkt->block_type = PCAPNG_BLOCK_ENHANCED_PACKET; pkt->interface_id = 0; pkt->timestamp_high = wt->write_pcapng_time_high; pkt->timestamp_low = wt->write_pcapng_time_low; pkt->captured_len = wt->decrypted_len; pkt->packet_len = wt->decrypted_len; pos = (u8 *) (pkt + 1); os_memcpy(pos, wt->decrypted, wt->decrypted_len); pos += ALIGN32(wt->decrypted_len); pos = pcapng_add_comments(wt, pos); block_len = (u32 *) pos; pos += 4; *block_len = pkt->block_total_len = pos - (u8 *) pkt; fwrite(pkt, pos - (u8 *) pkt, 1, wt->pcapng); if (wt->pcap_no_buffer) fflush(wt->pcapng); os_free(pkt); }
void mode_add(int argc, char **argv, note_db_t *db, int importance){ int i, has_text=0; note_t note=make_note(""); for(i=optind;i<argc;i++){ if(argv[i][0]=='#'){ //Increment pointer to skip past hash add_tag(¬e, ++argv[i]); }else{ append_note_text(¬e, argv[i]); append_note_text(¬e, " "); has_text=1; } } //Change extra space at end of text to NUL note.text[strlen(note.text)-1]='\0'; if(!has_text){ puts("Can't create note without text."); exit(9); } note.importance=importance; add_note(db, note); }