Changeset 2580 for pjproject/trunk/pjnath/src/pjnath-test/stun.c
- Timestamp:
- Apr 7, 2009 9:42:58 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath-test/stun.c
r2394 r2580 431 431 } 432 432 433 /* 434 * Test vectors, from: 435 * http://tools.ietf.org/html/draft-denis-behave-rfc3489bis-test-vectors-02 436 */ 433 437 typedef struct test_vector test_vector; 434 438 435 439 static pj_stun_msg* create_msgint1(pj_pool_t *pool, test_vector *v); 436 440 static pj_stun_msg* create_msgint2(pj_pool_t *pool, test_vector *v); 441 static pj_stun_msg* create_msgint3(pj_pool_t *pool, test_vector *v); 437 442 438 443 enum … … 442 447 }; 443 448 444 st ruct test_vector449 static struct test_vector 445 450 { 446 451 unsigned msg_type; … … 451 456 char *username; 452 457 char *password; 458 char *realm; 459 char *nonce; 453 460 pj_stun_msg* (*create)(pj_pool_t*, test_vector*); 454 461 } test_vectors[] = … … 470 477 "evtj:h6vY", 471 478 "VOkJxbRl1RmTxUk/WvJxBt", 479 "", 480 "", 472 481 &create_msgint1 473 482 }, … … 475 484 PJ_STUN_BINDING_RESPONSE, 476 485 "\xb7\xe7\xa7\x01\xbc\x34\xd6\x86\xfa\x87\xdf\xae", 477 "\x01\x01\x00\x3c\x21\x12\xa4\x42\xb7\xe7" 478 "\xa7\x01\xbc\x34\xd6\x86\xfa\x87\xdf\xae" 479 "\x80\x22\x00\x0b\x74\x65\x73\x74\x20\x76" 480 "\x65\x63\x74\x6f\x72\x20\x00\x20\x00\x08" 481 "\x00\x01\xa1\x47\x5e\x12\xa4\x43\x00\x08" 482 "\x00\x14\xab\x4e\x53\x29\x61\x00\x08\x4c" 483 "\x89\xf2\x7c\x69\x30\x33\x5c\xa3\x58\x14" 484 "\xea\x90\x80\x28\x00\x04\xae\x25\x8d\xf2", 486 "\x01\x01\x00\x3c" 487 "\x21\x12\xa4\x42" 488 "\xb7\xe7\xa7\x01\xbc\x34\xd6\x86\xfa\x87\xdf\xae" 489 "\x80\x22\x00\x0b" 490 "\x74\x65\x73\x74\x20\x76\x65\x63\x74\x6f\x72\x20" 491 "\x00\x20\x00\x08" 492 "\x00\x01\xa1\x47\xe1\x12\xa6\x43" 493 "\x00\x08\x00\x14" 494 "\x2b\x91\xf5\x99\xfd\x9e\x90\xc3\x8c\x74\x89\xf9" 495 "\x2a\xf9\xba\x53\xf0\x6b\xe7\xd7" 496 "\x80\x28\x00\x04" 497 "\xc0\x7d\x4c\x96", 485 498 80, 486 499 USE_MESSAGE_INTEGRITY | USE_FINGERPRINT, 487 500 "evtj:h6vY", 488 501 "VOkJxbRl1RmTxUk/WvJxBt", 502 "", 503 "", 489 504 &create_msgint2 505 }, 506 { 507 PJ_STUN_BINDING_RESPONSE, 508 "\xb7\xe7\xa7\x01\xbc\x34\xd6\x86\xfa\x87\xdf\xae", 509 "\x01\x01\x00\x48" // Response type and message length 510 "\x21\x12\xa4\x42" // Message cookie 511 "\xb7\xe7\xa7\x01" // } 512 "\xbc\x34\xd6\x86" // } Transaction ID 513 "\xfa\x87\xdf\xae" // } 514 515 "\x80\x22\x00\x0b" // SOFTWARE, length=11 516 "\x74\x65\x73\x74" 517 "\x20\x76\x65\x63" 518 "\x74\x6f\x72\x20" 519 "\x00\x20\x00\x14" // XOR-MAPPED-ADDRESS 520 "\x00\x02\xa1\x47" 521 "\x01\x13\xa9\xfa" 522 "\xa5\xd3\xf1\x79" 523 "\xbc\x25\xf4\xb5" 524 "\xbe\xd2\xb9\xd9" 525 "\x00\x08\x00\x14" // MESSAGE-INTEGRITY attribute header 526 "\xa3\x82\x95\x4e" // } 527 "\x4b\xe6\x7b\xf1" // } 528 "\x17\x84\xc9\x7c" // } HMAC-SHA1 fingerprint 529 "\x82\x92\xc2\x75" // } 530 "\xbf\xe3\xed\x41" // } 531 "\x80\x28\x00\x04" // FINGERPRINT attribute header 532 "\xc8\xfb\x0b\x4c" // CRC32 fingerprint 533 , 534 92, 535 USE_MESSAGE_INTEGRITY | USE_FINGERPRINT, 536 "evtj:h6vY", 537 "VOkJxbRl1RmTxUk/WvJxBt", 538 "", 539 "", 540 &create_msgint3 490 541 } 491 542 }; … … 538 589 int rc = 0; 539 590 540 PJ_LOG(3,(THIS_FILE, " STUN message test vectors"));591 PJ_LOG(3,(THIS_FILE, " draft-denis-behave-rfc3489bis-test-vectors-02")); 541 592 542 593 pool = pj_pool_create(mem, "fingerprint", 1024, 1024, NULL); … … 586 637 /* Encode message */ 587 638 if (v->options & USE_MESSAGE_INTEGRITY) { 588 pj_str_t s1, s2; 589 590 pj_stun_create_key(pool, &key, NULL, pj_cstr(&s1, v->username), 591 PJ_STUN_PASSWD_PLAIN, pj_cstr(&s2, v->password)); 639 pj_str_t s1, s2, r; 640 641 pj_stun_create_key(pool, &key, pj_cstr(&r, v->realm), 642 pj_cstr(&s1, v->username), 643 PJ_STUN_PASSWD_PLAIN, 644 pj_cstr(&s2, v->password)); 592 645 pj_stun_msg_encode(msg, buf, sizeof(buf), 0, &key, &len); 593 646 … … 626 679 pj_bzero(&cred, sizeof(cred)); 627 680 cred.type = PJ_STUN_AUTH_CRED_STATIC; 681 cred.data.static_cred.realm = pj_str(v->realm); 628 682 cred.data.static_cred.username = pj_str(v->username); 629 683 cred.data.static_cred.data = pj_str(v->password); 684 cred.data.static_cred.nonce = pj_str(v->nonce); 630 685 631 686 status = pj_stun_authenticate_request(buf, len, msg, … … 700 755 pj_cstr(&s1, "test vector")); 701 756 702 pj_sockaddr_in_init(&mapped_addr, pj_cstr(&s1, "1 27.0.0.1"), 32853);757 pj_sockaddr_in_init(&mapped_addr, pj_cstr(&s1, "192.0.2.1"), 32853); 703 758 pj_stun_msg_add_sockaddr_attr(pool, msg, PJ_STUN_ATTR_XOR_MAPPED_ADDR, 704 759 PJ_TRUE, &mapped_addr, 705 760 sizeof(pj_sockaddr_in)); 761 762 pj_stun_msg_add_msgint_attr(pool, msg); 763 pj_stun_msg_add_uint_attr(pool, msg, PJ_STUN_ATTR_FINGERPRINT, 0); 764 765 return msg; 766 } 767 768 769 static pj_stun_msg* create_msgint3(pj_pool_t *pool, test_vector *v) 770 { 771 pj_stun_msg *msg; 772 pj_sockaddr mapped_addr; 773 pj_str_t s1; 774 775 pj_stun_msg_create(pool, v->msg_type, PJ_STUN_MAGIC, 776 (pj_uint8_t*)v->tsx_id, &msg); 777 778 pj_stun_msg_add_string_attr(pool, msg, PJ_STUN_ATTR_SOFTWARE, 779 pj_cstr(&s1, "test vector")); 780 781 pj_sockaddr_init(pj_AF_INET6(), &mapped_addr, 782 pj_cstr(&s1, "2001:db8:1234:5678:11:2233:4455:6677"), 783 32853); 784 785 pj_stun_msg_add_sockaddr_attr(pool, msg, PJ_STUN_ATTR_XOR_MAPPED_ADDR, 786 PJ_TRUE, &mapped_addr, 787 sizeof(pj_sockaddr)); 706 788 707 789 pj_stun_msg_add_msgint_attr(pool, msg);
Note: See TracChangeset
for help on using the changeset viewer.