| 764 | char hexa[17] = "0123456789abcdef"; |
| 765 | |
| 766 | static int createAuthHeaderAKAv1MD5( |
| 767 | const char* user, const char* aka_OP, const char* aka_AMF, |
| 768 | const char* aka_K, const char* method, const char* uri, |
| 769 | const char* msgbody, const char* auth, const char* algo, |
| 770 | unsigned int nonce_count, char* result, size_t result_len) |
| 771 | { |
| 772 | |
| 773 | char tmp[MAX_HEADER_LEN]; |
| 774 | char *start, *end; |
| 775 | int has_auts = 0; |
| 776 | int written = 0; |
| 777 | char *nonce64, *nonce; |
| 778 | int noncelen; |
| 779 | AMF amf; |
| 780 | OP op; |
| 781 | RAND rnd; |
| 782 | AUTS auts_bin; |
| 783 | AUTS64 auts_hex; |
| 784 | MAC mac, xmac; |
| 785 | SQN sqn, sqnxoraka, sqn_ms; |
| 786 | K k; |
| 787 | RES res; |
| 788 | CK ck; |
| 789 | IK ik; |
| 790 | AK ak; |
| 791 | int i; |
| 792 | |
| 793 | // Extract the Nonce |
| 794 | if ((start = stristr(auth, "nonce=")) == nullptr) { |
| 795 | snprintf(result, result_len, "createAuthHeaderAKAv1MD5: couldn't parse nonce"); |
| 796 | return 0; |
| 797 | } |
| 798 | start = start + strlen("nonce="); |
| 799 | if (*start == '"') { |
| 800 | start++; |
| 801 | } |
| 802 | end = start + strcspn(start, " ,\"\r\n"); |
| 803 | strncpy(tmp, start, end - start); |
| 804 | tmp[end - start] ='\0'; |
| 805 | |
| 806 | /* Compute the AKA RES */ |
| 807 | nonce64 = tmp; |
| 808 | nonce = base64_decode_string(nonce64, end-start, &noncelen); |
| 809 | if (noncelen < RANDLEN + AUTNLEN) { |
| 810 | if (nonce) |
| 811 | free(nonce); |
| 812 | snprintf( |
| 813 | result, result_len, |
| 814 | "createAuthHeaderAKAv1MD5 : Nonce is too short %d < %d expected\n", |
| 815 | noncelen, RANDLEN + AUTNLEN); |
| 816 | return 0; |
| 817 | } |
| 818 | memcpy(rnd, nonce, RANDLEN); |
| 819 | memcpy(sqnxoraka, nonce + RANDLEN, SQNLEN); |
| 820 | memcpy(mac, nonce + RANDLEN + SQNLEN + AMFLEN, MACLEN); |
| 821 | memcpy(k, aka_K, KLEN); |
| 822 | memcpy(amf, aka_AMF, AMFLEN); |
| 823 | memcpy(op, aka_OP, OPLEN); |
no test coverage detected