Lines Matching refs:msg

52 struct radius_hdr * radius_msg_get_hdr(struct radius_msg *msg)  in radius_msg_get_hdr()  argument
54 return msg->hdr; in radius_msg_get_hdr()
58 struct wpabuf * radius_msg_get_buf(struct radius_msg *msg) in radius_msg_get_buf() argument
60 return msg->buf; in radius_msg_get_buf()
65 radius_get_attr_hdr(struct radius_msg *msg, int idx) in radius_get_attr_hdr() argument
68 (wpabuf_mhead_u8(msg->buf) + msg->attr_pos[idx]); in radius_get_attr_hdr()
72 static void radius_msg_set_hdr(struct radius_msg *msg, u8 code, u8 identifier) in radius_msg_set_hdr() argument
74 msg->hdr->code = code; in radius_msg_set_hdr()
75 msg->hdr->identifier = identifier; in radius_msg_set_hdr()
79 static int radius_msg_initialize(struct radius_msg *msg) in radius_msg_initialize() argument
81 msg->attr_pos = os_calloc(RADIUS_DEFAULT_ATTR_COUNT, in radius_msg_initialize()
82 sizeof(*msg->attr_pos)); in radius_msg_initialize()
83 if (msg->attr_pos == NULL) in radius_msg_initialize()
86 msg->attr_size = RADIUS_DEFAULT_ATTR_COUNT; in radius_msg_initialize()
87 msg->attr_used = 0; in radius_msg_initialize()
104 struct radius_msg *msg; in radius_msg_new() local
106 msg = os_zalloc(sizeof(*msg)); in radius_msg_new()
107 if (msg == NULL) in radius_msg_new()
110 msg->buf = wpabuf_alloc(RADIUS_DEFAULT_MSG_SIZE); in radius_msg_new()
111 if (msg->buf == NULL || radius_msg_initialize(msg)) { in radius_msg_new()
112 radius_msg_free(msg); in radius_msg_new()
115 msg->hdr = wpabuf_put(msg->buf, sizeof(struct radius_hdr)); in radius_msg_new()
117 radius_msg_set_hdr(msg, code, identifier); in radius_msg_new()
119 return msg; in radius_msg_new()
127 void radius_msg_free(struct radius_msg *msg) in radius_msg_free() argument
129 if (msg == NULL) in radius_msg_free()
132 wpabuf_free(msg->buf); in radius_msg_free()
133 os_free(msg->attr_pos); in radius_msg_free()
134 os_free(msg); in radius_msg_free()
347 void radius_msg_dump(struct radius_msg *msg) in radius_msg_dump() argument
352 msg->hdr->code, radius_code_string(msg->hdr->code), in radius_msg_dump()
353 msg->hdr->identifier, be_to_host16(msg->hdr->length)); in radius_msg_dump()
355 for (i = 0; i < msg->attr_used; i++) { in radius_msg_dump()
356 struct radius_attr_hdr *attr = radius_get_attr_hdr(msg, i); in radius_msg_dump()
362 int radius_msg_finish(struct radius_msg *msg, const u8 *secret, in radius_msg_finish() argument
370 attr = radius_msg_add_attr(msg, in radius_msg_finish()
378 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish()
379 hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_finish()
380 wpabuf_len(msg->buf), (u8 *) (attr + 1)); in radius_msg_finish()
382 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish()
384 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish()
386 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish()
393 int radius_msg_finish_srv(struct radius_msg *msg, const u8 *secret, in radius_msg_finish_srv() argument
402 attr = radius_msg_add_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, in radius_msg_finish_srv()
408 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish_srv()
409 os_memcpy(msg->hdr->authenticator, req_authenticator, in radius_msg_finish_srv()
410 sizeof(msg->hdr->authenticator)); in radius_msg_finish_srv()
411 hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_finish_srv()
412 wpabuf_len(msg->buf), (u8 *) (attr + 1)); in radius_msg_finish_srv()
415 addr[0] = (u8 *) msg->hdr; in radius_msg_finish_srv()
419 addr[2] = wpabuf_head_u8(msg->buf) + sizeof(struct radius_hdr); in radius_msg_finish_srv()
420 len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr); in radius_msg_finish_srv()
423 md5_vector(4, addr, len, msg->hdr->authenticator); in radius_msg_finish_srv()
425 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish_srv()
427 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish_srv()
434 int radius_msg_finish_das_resp(struct radius_msg *msg, const u8 *secret, in radius_msg_finish_das_resp() argument
444 attr = radius_msg_add_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, in radius_msg_finish_das_resp()
451 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish_das_resp()
452 os_memcpy(msg->hdr->authenticator, req_hdr->authenticator, 16); in radius_msg_finish_das_resp()
453 hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_finish_das_resp()
454 wpabuf_len(msg->buf), (u8 *) (attr + 1)); in radius_msg_finish_das_resp()
457 addr[0] = wpabuf_head_u8(msg->buf); in radius_msg_finish_das_resp()
458 len[0] = wpabuf_len(msg->buf); in radius_msg_finish_das_resp()
461 if (md5_vector(2, addr, len, msg->hdr->authenticator) < 0) in radius_msg_finish_das_resp()
464 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish_das_resp()
466 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish_das_resp()
473 void radius_msg_finish_acct(struct radius_msg *msg, const u8 *secret, in radius_msg_finish_acct() argument
479 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish_acct()
480 os_memset(msg->hdr->authenticator, 0, MD5_MAC_LEN); in radius_msg_finish_acct()
481 addr[0] = wpabuf_head(msg->buf); in radius_msg_finish_acct()
482 len[0] = wpabuf_len(msg->buf); in radius_msg_finish_acct()
485 md5_vector(2, addr, len, msg->hdr->authenticator); in radius_msg_finish_acct()
487 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish_acct()
489 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish_acct()
494 void radius_msg_finish_acct_resp(struct radius_msg *msg, const u8 *secret, in radius_msg_finish_acct_resp() argument
500 msg->hdr->length = host_to_be16(wpabuf_len(msg->buf)); in radius_msg_finish_acct_resp()
501 os_memcpy(msg->hdr->authenticator, req_authenticator, MD5_MAC_LEN); in radius_msg_finish_acct_resp()
502 addr[0] = wpabuf_head(msg->buf); in radius_msg_finish_acct_resp()
503 len[0] = wpabuf_len(msg->buf); in radius_msg_finish_acct_resp()
506 md5_vector(2, addr, len, msg->hdr->authenticator); in radius_msg_finish_acct_resp()
508 if (wpabuf_len(msg->buf) > 0xffff) { in radius_msg_finish_acct_resp()
510 (unsigned long) wpabuf_len(msg->buf)); in radius_msg_finish_acct_resp()
515 int radius_msg_verify_acct_req(struct radius_msg *msg, const u8 *secret, in radius_msg_verify_acct_req() argument
524 addr[0] = (u8 *) msg->hdr; in radius_msg_verify_acct_req()
528 addr[2] = (u8 *) (msg->hdr + 1); in radius_msg_verify_acct_req()
529 len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr); in radius_msg_verify_acct_req()
533 return os_memcmp_const(msg->hdr->authenticator, hash, MD5_MAC_LEN) != 0; in radius_msg_verify_acct_req()
537 int radius_msg_verify_das_req(struct radius_msg *msg, const u8 *secret, in radius_msg_verify_das_req() argument
551 addr[0] = (u8 *) msg->hdr; in radius_msg_verify_das_req()
555 addr[2] = (u8 *) (msg->hdr + 1); in radius_msg_verify_das_req()
556 len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr); in radius_msg_verify_das_req()
560 if (os_memcmp_const(msg->hdr->authenticator, hash, MD5_MAC_LEN) != 0) in radius_msg_verify_das_req()
563 for (i = 0; i < msg->attr_used; i++) { in radius_msg_verify_das_req()
564 tmp = radius_get_attr_hdr(msg, i); in radius_msg_verify_das_req()
583 os_memcpy(orig_authenticator, msg->hdr->authenticator, in radius_msg_verify_das_req()
585 os_memset(msg->hdr->authenticator, 0, in radius_msg_verify_das_req()
586 sizeof(msg->hdr->authenticator)); in radius_msg_verify_das_req()
587 hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_verify_das_req()
588 wpabuf_len(msg->buf), auth); in radius_msg_verify_das_req()
590 os_memcpy(msg->hdr->authenticator, orig_authenticator, in radius_msg_verify_das_req()
597 static int radius_msg_add_attr_to_array(struct radius_msg *msg, in radius_msg_add_attr_to_array() argument
600 if (msg->attr_used >= msg->attr_size) { in radius_msg_add_attr_to_array()
602 int nlen = msg->attr_size * 2; in radius_msg_add_attr_to_array()
604 nattr_pos = os_realloc_array(msg->attr_pos, nlen, in radius_msg_add_attr_to_array()
605 sizeof(*msg->attr_pos)); in radius_msg_add_attr_to_array()
609 msg->attr_pos = nattr_pos; in radius_msg_add_attr_to_array()
610 msg->attr_size = nlen; in radius_msg_add_attr_to_array()
613 msg->attr_pos[msg->attr_used++] = in radius_msg_add_attr_to_array()
614 (unsigned char *) attr - wpabuf_head_u8(msg->buf); in radius_msg_add_attr_to_array()
620 struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type, in radius_msg_add_attr() argument
634 if (wpabuf_tailroom(msg->buf) < buf_needed) { in radius_msg_add_attr()
636 if (wpabuf_resize(&msg->buf, buf_needed) < 0) in radius_msg_add_attr()
638 msg->hdr = wpabuf_mhead(msg->buf); in radius_msg_add_attr()
641 attr = wpabuf_put(msg->buf, sizeof(struct radius_attr_hdr)); in radius_msg_add_attr()
644 wpabuf_put_data(msg->buf, data, data_len); in radius_msg_add_attr()
646 if (radius_msg_add_attr_to_array(msg, attr)) in radius_msg_add_attr()
664 struct radius_msg *msg; in radius_msg_parse() local
686 msg = os_zalloc(sizeof(*msg)); in radius_msg_parse()
687 if (msg == NULL) in radius_msg_parse()
690 msg->buf = wpabuf_alloc_copy(data, msg_len); in radius_msg_parse()
691 if (msg->buf == NULL || radius_msg_initialize(msg)) { in radius_msg_parse()
692 radius_msg_free(msg); in radius_msg_parse()
695 msg->hdr = wpabuf_mhead(msg->buf); in radius_msg_parse()
698 pos = wpabuf_mhead_u8(msg->buf) + sizeof(struct radius_hdr); in radius_msg_parse()
699 end = wpabuf_mhead_u8(msg->buf) + wpabuf_len(msg->buf); in radius_msg_parse()
711 if (radius_msg_add_attr_to_array(msg, attr)) in radius_msg_parse()
717 return msg; in radius_msg_parse()
720 radius_msg_free(msg); in radius_msg_parse()
725 int radius_msg_add_eap(struct radius_msg *msg, const u8 *data, size_t data_len) in radius_msg_add_eap() argument
737 if (!radius_msg_add_attr(msg, RADIUS_ATTR_EAP_MESSAGE, in radius_msg_add_eap()
749 struct wpabuf * radius_msg_get_eap(struct radius_msg *msg) in radius_msg_get_eap() argument
755 if (msg == NULL) in radius_msg_get_eap()
759 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_eap()
760 attr = radius_get_attr_hdr(msg, i); in radius_msg_get_eap()
773 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_eap()
774 attr = radius_get_attr_hdr(msg, i); in radius_msg_get_eap()
786 int radius_msg_verify_msg_auth(struct radius_msg *msg, const u8 *secret, in radius_msg_verify_msg_auth() argument
794 for (i = 0; i < msg->attr_used; i++) { in radius_msg_verify_msg_auth()
795 tmp = radius_get_attr_hdr(msg, i); in radius_msg_verify_msg_auth()
813 os_memcpy(orig_authenticator, msg->hdr->authenticator, in radius_msg_verify_msg_auth()
815 os_memcpy(msg->hdr->authenticator, req_auth, in radius_msg_verify_msg_auth()
816 sizeof(msg->hdr->authenticator)); in radius_msg_verify_msg_auth()
818 hmac_md5(secret, secret_len, wpabuf_head(msg->buf), in radius_msg_verify_msg_auth()
819 wpabuf_len(msg->buf), auth); in radius_msg_verify_msg_auth()
822 os_memcpy(msg->hdr->authenticator, orig_authenticator, in radius_msg_verify_msg_auth()
835 int radius_msg_verify(struct radius_msg *msg, const u8 *secret, in radius_msg_verify() argument
848 radius_msg_verify_msg_auth(msg, secret, secret_len, in radius_msg_verify()
854 addr[0] = (u8 *) msg->hdr; in radius_msg_verify()
858 addr[2] = wpabuf_head_u8(msg->buf) + sizeof(struct radius_hdr); in radius_msg_verify()
859 len[2] = wpabuf_len(msg->buf) - sizeof(struct radius_hdr); in radius_msg_verify()
863 if (os_memcmp_const(hash, msg->hdr->authenticator, MD5_MAC_LEN) != 0) { in radius_msg_verify()
897 void radius_msg_make_authenticator(struct radius_msg *msg, in radius_msg_make_authenticator() argument
913 md5_vector(3, addr, elen, msg->hdr->authenticator); in radius_msg_make_authenticator()
923 static u8 *radius_msg_get_vendor_attr(struct radius_msg *msg, u32 vendor, in radius_msg_get_vendor_attr() argument
929 if (msg == NULL) in radius_msg_get_vendor_attr()
932 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_vendor_attr()
933 struct radius_attr_hdr *attr = radius_get_attr_hdr(msg, i); in radius_msg_get_vendor_attr()
1107 radius_msg_get_ms_keys(struct radius_msg *msg, struct radius_msg *sent_msg, in radius_msg_get_ms_keys() argument
1114 if (msg == NULL || sent_msg == NULL) in radius_msg_get_ms_keys()
1121 key = radius_msg_get_vendor_attr(msg, RADIUS_VENDOR_ID_MICROSOFT, in radius_msg_get_ms_keys()
1136 key = radius_msg_get_vendor_attr(msg, RADIUS_VENDOR_ID_MICROSOFT, in radius_msg_get_ms_keys()
1156 radius_msg_get_cisco_keys(struct radius_msg *msg, struct radius_msg *sent_msg, in radius_msg_get_cisco_keys() argument
1163 if (msg == NULL || sent_msg == NULL) in radius_msg_get_cisco_keys()
1170 key = radius_msg_get_vendor_attr(msg, RADIUS_VENDOR_ID_CISCO, in radius_msg_get_cisco_keys()
1185 int radius_msg_add_mppe_keys(struct radius_msg *msg, in radius_msg_add_mppe_keys() argument
1220 attr = radius_msg_add_attr(msg, RADIUS_ATTR_VENDOR_SPECIFIC, in radius_msg_add_mppe_keys()
1245 attr = radius_msg_add_attr(msg, RADIUS_ATTR_VENDOR_SPECIFIC, in radius_msg_add_mppe_keys()
1256 int radius_msg_add_wfa(struct radius_msg *msg, u8 subtype, const u8 *data, in radius_msg_add_wfa() argument
1273 attr = radius_msg_add_attr(msg, RADIUS_ATTR_VENDOR_SPECIFIC, in radius_msg_add_wfa()
1283 int radius_user_password_hide(struct radius_msg *msg, in radius_user_password_hide() argument
1309 addr[1] = msg->hdr->authenticator; in radius_user_password_hide()
1337 radius_msg_add_attr_user_password(struct radius_msg *msg, in radius_msg_add_attr_user_password() argument
1344 res = radius_user_password_hide(msg, data, data_len, in radius_msg_add_attr_user_password()
1349 return radius_msg_add_attr(msg, RADIUS_ATTR_USER_PASSWORD, in radius_msg_add_attr_user_password()
1354 int radius_msg_get_attr(struct radius_msg *msg, u8 type, u8 *buf, size_t len) in radius_msg_get_attr() argument
1359 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_attr()
1360 tmp = radius_get_attr_hdr(msg, i); in radius_msg_get_attr()
1377 int radius_msg_get_attr_ptr(struct radius_msg *msg, u8 type, u8 **buf, in radius_msg_get_attr_ptr() argument
1383 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_attr_ptr()
1384 tmp = radius_get_attr_hdr(msg, i); in radius_msg_get_attr_ptr()
1401 int radius_msg_count_attr(struct radius_msg *msg, u8 type, int min_len) in radius_msg_count_attr() argument
1406 for (count = 0, i = 0; i < msg->attr_used; i++) { in radius_msg_count_attr()
1407 struct radius_attr_hdr *attr = radius_get_attr_hdr(msg, i); in radius_msg_count_attr()
1430 int radius_msg_get_vlanid(struct radius_msg *msg) in radius_msg_get_vlanid() argument
1441 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_vlanid()
1442 attr = radius_get_attr_hdr(msg, i); in radius_msg_get_vlanid()
1505 char * radius_msg_get_tunnel_password(struct radius_msg *msg, int *keylen, in radius_msg_get_tunnel_password() argument
1526 for (i = 0; i < msg->attr_used; i++) { in radius_msg_get_tunnel_password()
1527 attr = radius_get_attr_hdr(msg, i); in radius_msg_get_tunnel_password()
1653 u8 radius_msg_find_unlisted_attr(struct radius_msg *msg, u8 *attrs) in radius_msg_find_unlisted_attr() argument
1658 for (i = 0; i < msg->attr_used; i++) { in radius_msg_find_unlisted_attr()
1659 attr = radius_get_attr_hdr(msg, i); in radius_msg_find_unlisted_attr()