正在显示
6 个修改的文件
包含
367 行增加
和
185 行删除
| @@ -392,7 +392,7 @@ if [ $SRS_LIBRTMP = YES ]; then | @@ -392,7 +392,7 @@ if [ $SRS_LIBRTMP = YES ]; then | ||
| 392 | fi | 392 | fi |
| 393 | # | 393 | # |
| 394 | # utest, the unit-test cases of srs, base on gtest1.6 | 394 | # utest, the unit-test cases of srs, base on gtest1.6 |
| 395 | -MODULE_FILES=("srs_utest" "srs_utest_amf0") | 395 | +MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_handshake") |
| 396 | ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot}) | 396 | ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot}) |
| 397 | ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) | 397 | ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) |
| 398 | MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") | 398 | MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") |
| @@ -31,6 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,6 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | #include <srs_kernel_log.hpp> | 31 | #include <srs_kernel_log.hpp> |
| 32 | #include <srs_protocol_io.hpp> | 32 | #include <srs_protocol_io.hpp> |
| 33 | 33 | ||
| 34 | +using namespace srs; | ||
| 35 | + | ||
| 34 | void srs_random_generate(char* bytes, int size) | 36 | void srs_random_generate(char* bytes, int size) |
| 35 | { | 37 | { |
| 36 | static char cdata[] = { | 38 | static char cdata[] = { |
| @@ -47,7 +49,7 @@ void srs_random_generate(char* bytes, int size) | @@ -47,7 +49,7 @@ void srs_random_generate(char* bytes, int size) | ||
| 47 | #ifdef SRS_SSL | 49 | #ifdef SRS_SSL |
| 48 | 50 | ||
| 49 | // 68bytes FMS key which is used to sign the sever packet. | 51 | // 68bytes FMS key which is used to sign the sever packet. |
| 50 | -u_int8_t SrsGenuineFMSKey[] = { | 52 | +u_int8_t srs::SrsGenuineFMSKey[] = { |
| 51 | 0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20, | 53 | 0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20, |
| 52 | 0x41, 0x64, 0x6f, 0x62, 0x65, 0x20, 0x46, 0x6c, | 54 | 0x41, 0x64, 0x6f, 0x62, 0x65, 0x20, 0x46, 0x6c, |
| 53 | 0x61, 0x73, 0x68, 0x20, 0x4d, 0x65, 0x64, 0x69, | 55 | 0x61, 0x73, 0x68, 0x20, 0x4d, 0x65, 0x64, 0x69, |
| @@ -60,7 +62,7 @@ u_int8_t SrsGenuineFMSKey[] = { | @@ -60,7 +62,7 @@ u_int8_t SrsGenuineFMSKey[] = { | ||
| 60 | }; // 68 | 62 | }; // 68 |
| 61 | 63 | ||
| 62 | // 62bytes FP key which is used to sign the client packet. | 64 | // 62bytes FP key which is used to sign the client packet. |
| 63 | -u_int8_t SrsGenuineFPKey[] = { | 65 | +u_int8_t srs::SrsGenuineFPKey[] = { |
| 64 | 0x47, 0x65, 0x6E, 0x75, 0x69, 0x6E, 0x65, 0x20, | 66 | 0x47, 0x65, 0x6E, 0x75, 0x69, 0x6E, 0x65, 0x20, |
| 65 | 0x41, 0x64, 0x6F, 0x62, 0x65, 0x20, 0x46, 0x6C, | 67 | 0x41, 0x64, 0x6F, 0x62, 0x65, 0x20, 0x46, 0x6C, |
| 66 | 0x61, 0x73, 0x68, 0x20, 0x50, 0x6C, 0x61, 0x79, | 68 | 0x61, 0x73, 0x68, 0x20, 0x50, 0x6C, 0x61, 0x79, |
| @@ -73,7 +75,8 @@ u_int8_t SrsGenuineFPKey[] = { | @@ -73,7 +75,8 @@ u_int8_t SrsGenuineFPKey[] = { | ||
| 73 | 75 | ||
| 74 | #include <openssl/evp.h> | 76 | #include <openssl/evp.h> |
| 75 | #include <openssl/hmac.h> | 77 | #include <openssl/hmac.h> |
| 76 | -int openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest) { | 78 | +int srs::openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest) |
| 79 | +{ | ||
| 77 | HMAC_CTX ctx; | 80 | HMAC_CTX ctx; |
| 78 | 81 | ||
| 79 | HMAC_CTX_init(&ctx); | 82 | HMAC_CTX_init(&ctx); |
| @@ -234,32 +237,6 @@ int openssl_generate_key(char* _private_key, char* _public_key, int32_t size) | @@ -234,32 +237,6 @@ int openssl_generate_key(char* _private_key, char* _public_key, int32_t size) | ||
| 234 | return ret; | 237 | return ret; |
| 235 | } | 238 | } |
| 236 | 239 | ||
| 237 | -// the digest key generate size. | ||
| 238 | -#define OpensslHashSize 512 | ||
| 239 | - | ||
| 240 | -/** | ||
| 241 | -* 764bytes key结构 | ||
| 242 | -* random-data: (offset)bytes | ||
| 243 | -* key-data: 128bytes | ||
| 244 | -* random-data: (764-offset-128-4)bytes | ||
| 245 | -* offset: 4bytes | ||
| 246 | -*/ | ||
| 247 | -struct key_block | ||
| 248 | -{ | ||
| 249 | - // (offset)bytes | ||
| 250 | - char* random0; | ||
| 251 | - int random0_size; | ||
| 252 | - | ||
| 253 | - // 128bytes | ||
| 254 | - char key[128]; | ||
| 255 | - | ||
| 256 | - // (764-offset-128-4)bytes | ||
| 257 | - char* random1; | ||
| 258 | - int random1_size; | ||
| 259 | - | ||
| 260 | - // 4bytes | ||
| 261 | - int32_t offset; | ||
| 262 | -}; | ||
| 263 | // calc the offset of key, | 240 | // calc the offset of key, |
| 264 | // the key->offset cannot be used as the offset of key. | 241 | // the key->offset cannot be used as the offset of key. |
| 265 | int srs_key_block_get_offset(key_block* key) | 242 | int srs_key_block_get_offset(key_block* key) |
| @@ -349,29 +326,6 @@ void srs_key_block_free(key_block* key) | @@ -349,29 +326,6 @@ void srs_key_block_free(key_block* key) | ||
| 349 | } | 326 | } |
| 350 | } | 327 | } |
| 351 | 328 | ||
| 352 | -/** | ||
| 353 | -* 764bytes digest结构 | ||
| 354 | -* offset: 4bytes | ||
| 355 | -* random-data: (offset)bytes | ||
| 356 | -* digest-data: 32bytes | ||
| 357 | -* random-data: (764-4-offset-32)bytes | ||
| 358 | -*/ | ||
| 359 | -struct digest_block | ||
| 360 | -{ | ||
| 361 | - // 4bytes | ||
| 362 | - int32_t offset; | ||
| 363 | - | ||
| 364 | - // (offset)bytes | ||
| 365 | - char* random0; | ||
| 366 | - int random0_size; | ||
| 367 | - | ||
| 368 | - // 32bytes | ||
| 369 | - char digest[32]; | ||
| 370 | - | ||
| 371 | - // (764-4-offset-32)bytes | ||
| 372 | - char* random1; | ||
| 373 | - int random1_size; | ||
| 374 | -}; | ||
| 375 | // calc the offset of digest, | 329 | // calc the offset of digest, |
| 376 | // the key->offset cannot be used as the offset of digest. | 330 | // the key->offset cannot be used as the offset of digest. |
| 377 | int srs_digest_block_get_offset(digest_block* digest) | 331 | int srs_digest_block_get_offset(digest_block* digest) |
| @@ -460,15 +414,6 @@ void srs_digest_block_free(digest_block* digest) | @@ -460,15 +414,6 @@ void srs_digest_block_free(digest_block* digest) | ||
| 460 | } | 414 | } |
| 461 | } | 415 | } |
| 462 | 416 | ||
| 463 | -/** | ||
| 464 | -* the schema type. | ||
| 465 | -*/ | ||
| 466 | -enum srs_schema_type { | ||
| 467 | - srs_schema0 = 0, // key-digest sequence | ||
| 468 | - srs_schema1 = 1, // digest-key sequence | ||
| 469 | - srs_schema_invalid = 2, | ||
| 470 | -}; | ||
| 471 | - | ||
| 472 | void __srs_time_copy_to(char*& pp, int32_t time) | 417 | void __srs_time_copy_to(char*& pp, int32_t time) |
| 473 | { | 418 | { |
| 474 | // 4bytes time | 419 | // 4bytes time |
| @@ -560,13 +505,14 @@ void srs_schema1_copy_to(char* bytes, bool with_digest, | @@ -560,13 +505,14 @@ void srs_schema1_copy_to(char* bytes, bool with_digest, | ||
| 560 | srs_assert(pp - bytes == 1536 - 32); | 505 | srs_assert(pp - bytes == 1536 - 32); |
| 561 | } | 506 | } |
| 562 | } | 507 | } |
| 508 | + | ||
| 563 | /** | 509 | /** |
| 564 | * c1s1 is splited by digest: | 510 | * c1s1 is splited by digest: |
| 565 | * c1s1-part1: n bytes (time, version, key and digest-part1). | 511 | * c1s1-part1: n bytes (time, version, key and digest-part1). |
| 566 | * digest-data: 32bytes | 512 | * digest-data: 32bytes |
| 567 | * c1s1-part2: (1536-n-32)bytes (digest-part2) | 513 | * c1s1-part2: (1536-n-32)bytes (digest-part2) |
| 568 | */ | 514 | */ |
| 569 | -char* srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, digest_block* digest) | 515 | +char* srs::srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, digest_block* digest) |
| 570 | { | 516 | { |
| 571 | char* bytes = new char[1536 -32]; | 517 | char* bytes = new char[1536 -32]; |
| 572 | 518 | ||
| @@ -574,13 +520,14 @@ char* srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, dige | @@ -574,13 +520,14 @@ char* srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, dige | ||
| 574 | 520 | ||
| 575 | return bytes; | 521 | return bytes; |
| 576 | } | 522 | } |
| 523 | + | ||
| 577 | /** | 524 | /** |
| 578 | * c1s1 is splited by digest: | 525 | * c1s1 is splited by digest: |
| 579 | * c1s1-part1: n bytes (time, version and digest-part1). | 526 | * c1s1-part1: n bytes (time, version and digest-part1). |
| 580 | * digest-data: 32bytes | 527 | * digest-data: 32bytes |
| 581 | * c1s1-part2: (1536-n-32)bytes (digest-part2 and key) | 528 | * c1s1-part2: (1536-n-32)bytes (digest-part2 and key) |
| 582 | */ | 529 | */ |
| 583 | -char* srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest, key_block* key) | 530 | +char* srs::srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest, key_block* key) |
| 584 | { | 531 | { |
| 585 | char* bytes = new char[1536 -32]; | 532 | char* bytes = new char[1536 -32]; |
| 586 | 533 | ||
| @@ -592,7 +539,8 @@ char* srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest | @@ -592,7 +539,8 @@ char* srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest | ||
| 592 | /** | 539 | /** |
| 593 | * compare the memory in bytes. | 540 | * compare the memory in bytes. |
| 594 | */ | 541 | */ |
| 595 | -bool srs_bytes_equals(void* pa, void* pb, int size){ | 542 | +bool srs::srs_bytes_equals(void* pa, void* pb, int size) |
| 543 | +{ | ||
| 596 | u_int8_t* a = (u_int8_t*)pa; | 544 | u_int8_t* a = (u_int8_t*)pa; |
| 597 | u_int8_t* b = (u_int8_t*)pb; | 545 | u_int8_t* b = (u_int8_t*)pb; |
| 598 | 546 | ||
| @@ -605,126 +553,6 @@ bool srs_bytes_equals(void* pa, void* pb, int size){ | @@ -605,126 +553,6 @@ bool srs_bytes_equals(void* pa, void* pb, int size){ | ||
| 605 | return true; | 553 | return true; |
| 606 | } | 554 | } |
| 607 | 555 | ||
| 608 | -/** | ||
| 609 | -* c1s1 schema0 | ||
| 610 | -* time: 4bytes | ||
| 611 | -* version: 4bytes | ||
| 612 | -* key: 764bytes | ||
| 613 | -* digest: 764bytes | ||
| 614 | -* c1s1 schema1 | ||
| 615 | -* time: 4bytes | ||
| 616 | -* version: 4bytes | ||
| 617 | -* digest: 764bytes | ||
| 618 | -* key: 764bytes | ||
| 619 | -*/ | ||
| 620 | -struct c1s1 | ||
| 621 | -{ | ||
| 622 | - union block { | ||
| 623 | - key_block key; | ||
| 624 | - digest_block digest; | ||
| 625 | - }; | ||
| 626 | - | ||
| 627 | - // 4bytes | ||
| 628 | - int32_t time; | ||
| 629 | - // 4bytes | ||
| 630 | - int32_t version; | ||
| 631 | - // 764bytes | ||
| 632 | - // if schema0, use key | ||
| 633 | - // if schema1, use digest | ||
| 634 | - block block0; | ||
| 635 | - // 764bytes | ||
| 636 | - // if schema0, use digest | ||
| 637 | - // if schema1, use key | ||
| 638 | - block block1; | ||
| 639 | - | ||
| 640 | - // the logic schema | ||
| 641 | - srs_schema_type schema; | ||
| 642 | - | ||
| 643 | - c1s1(); | ||
| 644 | - virtual ~c1s1(); | ||
| 645 | - /** | ||
| 646 | - * get the digest key. | ||
| 647 | - */ | ||
| 648 | - virtual char* get_digest(); | ||
| 649 | - /** | ||
| 650 | - * copy to bytes. | ||
| 651 | - */ | ||
| 652 | - virtual void dump(char* _c1s1); | ||
| 653 | - | ||
| 654 | - /** | ||
| 655 | - * client: create and sign c1 by schema. | ||
| 656 | - * sign the c1, generate the digest. | ||
| 657 | - * calc_c1_digest(c1, schema) { | ||
| 658 | - * get c1s1-joined from c1 by specified schema | ||
| 659 | - * digest-data = HMACsha256(c1s1-joined, FPKey, 30) | ||
| 660 | - * return digest-data; | ||
| 661 | - * } | ||
| 662 | - * random fill 1536bytes c1 // also fill the c1-128bytes-key | ||
| 663 | - * time = time() // c1[0-3] | ||
| 664 | - * version = [0x80, 0x00, 0x07, 0x02] // c1[4-7] | ||
| 665 | - * schema = choose schema0 or schema1 | ||
| 666 | - * digest-data = calc_c1_digest(c1, schema) | ||
| 667 | - * copy digest-data to c1 | ||
| 668 | - */ | ||
| 669 | - virtual int c1_create(srs_schema_type _schema); | ||
| 670 | - /** | ||
| 671 | - * server: parse the c1s1, discovery the key and digest by schema. | ||
| 672 | - * use the c1_validate_digest() to valid the digest of c1. | ||
| 673 | - */ | ||
| 674 | - virtual int c1_parse(char* _c1s1, srs_schema_type _schema); | ||
| 675 | - /** | ||
| 676 | - * server: validate the parsed schema and c1s1 | ||
| 677 | - */ | ||
| 678 | - virtual int c1_validate_digest(bool& is_valid); | ||
| 679 | - /** | ||
| 680 | - * server: create and sign the s1 from c1. | ||
| 681 | - */ | ||
| 682 | - virtual int s1_create(c1s1* c1); | ||
| 683 | -private: | ||
| 684 | - virtual int calc_s1_digest(char*& digest); | ||
| 685 | - virtual int calc_c1_digest(char*& digest); | ||
| 686 | - virtual void destroy_blocks(); | ||
| 687 | -}; | ||
| 688 | - | ||
| 689 | -/** | ||
| 690 | -* the c2s2 complex handshake structure. | ||
| 691 | -* random-data: 1504bytes | ||
| 692 | -* digest-data: 32bytes | ||
| 693 | -*/ | ||
| 694 | -struct c2s2 | ||
| 695 | -{ | ||
| 696 | - char random[1504]; | ||
| 697 | - char digest[32]; | ||
| 698 | - | ||
| 699 | - c2s2(); | ||
| 700 | - virtual ~c2s2(); | ||
| 701 | - | ||
| 702 | - /** | ||
| 703 | - * copy to bytes. | ||
| 704 | - */ | ||
| 705 | - virtual void dump(char* _c2s2); | ||
| 706 | - | ||
| 707 | - /** | ||
| 708 | - * create c2. | ||
| 709 | - * random fill c2s2 1536 bytes | ||
| 710 | - * | ||
| 711 | - * // client generate C2, or server valid C2 | ||
| 712 | - * temp-key = HMACsha256(s1-digest, FPKey, 62) | ||
| 713 | - * c2-digest-data = HMACsha256(c2-random-data, temp-key, 32) | ||
| 714 | - */ | ||
| 715 | - virtual int c2_create(c1s1* s1); | ||
| 716 | - | ||
| 717 | - /** | ||
| 718 | - * create s2. | ||
| 719 | - * random fill c2s2 1536 bytes | ||
| 720 | - * | ||
| 721 | - * // server generate S2, or client valid S2 | ||
| 722 | - * temp-key = HMACsha256(c1-digest, FMSKey, 68) | ||
| 723 | - * s2-digest-data = HMACsha256(s2-random-data, temp-key, 32) | ||
| 724 | - */ | ||
| 725 | - virtual int s2_create(c1s1* c1); | ||
| 726 | -}; | ||
| 727 | - | ||
| 728 | c2s2::c2s2() | 556 | c2s2::c2s2() |
| 729 | { | 557 | { |
| 730 | srs_random_generate(random, 1504); | 558 | srs_random_generate(random, 1504); |
| @@ -76,4 +76,217 @@ public: | @@ -76,4 +76,217 @@ public: | ||
| 76 | virtual int handshake_with_server(ISrsProtocolReaderWriter* io); | 76 | virtual int handshake_with_server(ISrsProtocolReaderWriter* io); |
| 77 | }; | 77 | }; |
| 78 | 78 | ||
| 79 | +namespace srs | ||
| 80 | +{ | ||
| 81 | + /** | ||
| 82 | + * the schema type. | ||
| 83 | + */ | ||
| 84 | + enum srs_schema_type { | ||
| 85 | + srs_schema0 = 0, // key-digest sequence | ||
| 86 | + srs_schema1 = 1, // digest-key sequence | ||
| 87 | + srs_schema_invalid = 2, | ||
| 88 | + }; | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * 764bytes key结构 | ||
| 92 | + * random-data: (offset)bytes | ||
| 93 | + * key-data: 128bytes | ||
| 94 | + * random-data: (764-offset-128-4)bytes | ||
| 95 | + * offset: 4bytes | ||
| 96 | + * @see also: http://blog.csdn.net/win_lin/article/details/13006803 | ||
| 97 | + */ | ||
| 98 | + struct key_block | ||
| 99 | + { | ||
| 100 | + // (offset)bytes | ||
| 101 | + char* random0; | ||
| 102 | + int random0_size; | ||
| 103 | + | ||
| 104 | + // 128bytes | ||
| 105 | + char key[128]; | ||
| 106 | + | ||
| 107 | + // (764-offset-128-4)bytes | ||
| 108 | + char* random1; | ||
| 109 | + int random1_size; | ||
| 110 | + | ||
| 111 | + // 4bytes | ||
| 112 | + int32_t offset; | ||
| 113 | + }; | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 764bytes digest结构 | ||
| 117 | + * offset: 4bytes | ||
| 118 | + * random-data: (offset)bytes | ||
| 119 | + * digest-data: 32bytes | ||
| 120 | + * random-data: (764-4-offset-32)bytes | ||
| 121 | + * @see also: http://blog.csdn.net/win_lin/article/details/13006803 | ||
| 122 | + */ | ||
| 123 | + struct digest_block | ||
| 124 | + { | ||
| 125 | + // 4bytes | ||
| 126 | + int32_t offset; | ||
| 127 | + | ||
| 128 | + // (offset)bytes | ||
| 129 | + char* random0; | ||
| 130 | + int random0_size; | ||
| 131 | + | ||
| 132 | + // 32bytes | ||
| 133 | + char digest[32]; | ||
| 134 | + | ||
| 135 | + // (764-4-offset-32)bytes | ||
| 136 | + char* random1; | ||
| 137 | + int random1_size; | ||
| 138 | + }; | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * c1s1 schema0 | ||
| 142 | + * time: 4bytes | ||
| 143 | + * version: 4bytes | ||
| 144 | + * key: 764bytes | ||
| 145 | + * digest: 764bytes | ||
| 146 | + * c1s1 schema1 | ||
| 147 | + * time: 4bytes | ||
| 148 | + * version: 4bytes | ||
| 149 | + * digest: 764bytes | ||
| 150 | + * key: 764bytes | ||
| 151 | + * @see also: http://blog.csdn.net/win_lin/article/details/13006803 | ||
| 152 | + */ | ||
| 153 | + struct c1s1 | ||
| 154 | + { | ||
| 155 | + union block { | ||
| 156 | + key_block key; | ||
| 157 | + digest_block digest; | ||
| 158 | + }; | ||
| 159 | + | ||
| 160 | + // 4bytes | ||
| 161 | + int32_t time; | ||
| 162 | + // 4bytes | ||
| 163 | + int32_t version; | ||
| 164 | + // 764bytes | ||
| 165 | + // if schema0, use key | ||
| 166 | + // if schema1, use digest | ||
| 167 | + block block0; | ||
| 168 | + // 764bytes | ||
| 169 | + // if schema0, use digest | ||
| 170 | + // if schema1, use key | ||
| 171 | + block block1; | ||
| 172 | + | ||
| 173 | + // the logic schema | ||
| 174 | + srs_schema_type schema; | ||
| 175 | + | ||
| 176 | + c1s1(); | ||
| 177 | + virtual ~c1s1(); | ||
| 178 | + /** | ||
| 179 | + * get the digest key. | ||
| 180 | + */ | ||
| 181 | + virtual char* get_digest(); | ||
| 182 | + /** | ||
| 183 | + * copy to bytes. | ||
| 184 | + */ | ||
| 185 | + virtual void dump(char* _c1s1); | ||
| 186 | + | ||
| 187 | + /** | ||
| 188 | + * client: create and sign c1 by schema. | ||
| 189 | + * sign the c1, generate the digest. | ||
| 190 | + * calc_c1_digest(c1, schema) { | ||
| 191 | + * get c1s1-joined from c1 by specified schema | ||
| 192 | + * digest-data = HMACsha256(c1s1-joined, FPKey, 30) | ||
| 193 | + * return digest-data; | ||
| 194 | + * } | ||
| 195 | + * random fill 1536bytes c1 // also fill the c1-128bytes-key | ||
| 196 | + * time = time() // c1[0-3] | ||
| 197 | + * version = [0x80, 0x00, 0x07, 0x02] // c1[4-7] | ||
| 198 | + * schema = choose schema0 or schema1 | ||
| 199 | + * digest-data = calc_c1_digest(c1, schema) | ||
| 200 | + * copy digest-data to c1 | ||
| 201 | + */ | ||
| 202 | + virtual int c1_create(srs_schema_type _schema); | ||
| 203 | + /** | ||
| 204 | + * server: parse the c1s1, discovery the key and digest by schema. | ||
| 205 | + * use the c1_validate_digest() to valid the digest of c1. | ||
| 206 | + */ | ||
| 207 | + virtual int c1_parse(char* _c1s1, srs_schema_type _schema); | ||
| 208 | + /** | ||
| 209 | + * server: validate the parsed schema and c1s1 | ||
| 210 | + */ | ||
| 211 | + virtual int c1_validate_digest(bool& is_valid); | ||
| 212 | + /** | ||
| 213 | + * server: create and sign the s1 from c1. | ||
| 214 | + */ | ||
| 215 | + virtual int s1_create(c1s1* c1); | ||
| 216 | + private: | ||
| 217 | + virtual int calc_s1_digest(char*& digest); | ||
| 218 | + virtual int calc_c1_digest(char*& digest); | ||
| 219 | + virtual void destroy_blocks(); | ||
| 220 | + }; | ||
| 221 | + | ||
| 222 | + /** | ||
| 223 | + * the c2s2 complex handshake structure. | ||
| 224 | + * random-data: 1504bytes | ||
| 225 | + * digest-data: 32bytes | ||
| 226 | + * @see also: http://blog.csdn.net/win_lin/article/details/13006803 | ||
| 227 | + */ | ||
| 228 | + struct c2s2 | ||
| 229 | + { | ||
| 230 | + char random[1504]; | ||
| 231 | + char digest[32]; | ||
| 232 | + | ||
| 233 | + c2s2(); | ||
| 234 | + virtual ~c2s2(); | ||
| 235 | + | ||
| 236 | + /** | ||
| 237 | + * copy to bytes. | ||
| 238 | + */ | ||
| 239 | + virtual void dump(char* _c2s2); | ||
| 240 | + | ||
| 241 | + /** | ||
| 242 | + * create c2. | ||
| 243 | + * random fill c2s2 1536 bytes | ||
| 244 | + * | ||
| 245 | + * // client generate C2, or server valid C2 | ||
| 246 | + * temp-key = HMACsha256(s1-digest, FPKey, 62) | ||
| 247 | + * c2-digest-data = HMACsha256(c2-random-data, temp-key, 32) | ||
| 248 | + */ | ||
| 249 | + virtual int c2_create(c1s1* s1); | ||
| 250 | + | ||
| 251 | + /** | ||
| 252 | + * create s2. | ||
| 253 | + * random fill c2s2 1536 bytes | ||
| 254 | + * | ||
| 255 | + * // server generate S2, or client valid S2 | ||
| 256 | + * temp-key = HMACsha256(c1-digest, FMSKey, 68) | ||
| 257 | + * s2-digest-data = HMACsha256(s2-random-data, temp-key, 32) | ||
| 258 | + */ | ||
| 259 | + virtual int s2_create(c1s1* c1); | ||
| 260 | + }; | ||
| 261 | + | ||
| 262 | + /** | ||
| 263 | + * compare the memory in bytes. | ||
| 264 | + */ | ||
| 265 | + bool srs_bytes_equals(void* pa, void* pb, int size); | ||
| 266 | + | ||
| 267 | + /** | ||
| 268 | + * c1s1 is splited by digest: | ||
| 269 | + * c1s1-part1: n bytes (time, version, key and digest-part1). | ||
| 270 | + * digest-data: 32bytes | ||
| 271 | + * c1s1-part2: (1536-n-32)bytes (digest-part2) | ||
| 272 | + * @return a new allocated bytes, user must free it. | ||
| 273 | + */ | ||
| 274 | + char* srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, digest_block* digest); | ||
| 275 | + | ||
| 276 | + /** | ||
| 277 | + * c1s1 is splited by digest: | ||
| 278 | + * c1s1-part1: n bytes (time, version and digest-part1). | ||
| 279 | + * digest-data: 32bytes | ||
| 280 | + * c1s1-part2: (1536-n-32)bytes (digest-part2 and key) | ||
| 281 | + * @return a new allocated bytes, user must free it. | ||
| 282 | + */ | ||
| 283 | + char* srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest, key_block* key); | ||
| 284 | + | ||
| 285 | + // the digest key generate size. | ||
| 286 | + #define OpensslHashSize 512 | ||
| 287 | + extern u_int8_t SrsGenuineFMSKey[]; | ||
| 288 | + extern u_int8_t SrsGenuineFPKey[]; | ||
| 289 | + int openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest); | ||
| 290 | +} | ||
| 291 | + | ||
| 79 | #endif | 292 | #endif |
| @@ -78,6 +78,8 @@ file | @@ -78,6 +78,8 @@ file | ||
| 78 | ..\utest\srs_utest.cpp, | 78 | ..\utest\srs_utest.cpp, |
| 79 | ..\utest\srs_utest_amf0.hpp, | 79 | ..\utest\srs_utest_amf0.hpp, |
| 80 | ..\utest\srs_utest_amf0.cpp, | 80 | ..\utest\srs_utest_amf0.cpp, |
| 81 | + ..\utest\srs_utest_handshake.hpp, | ||
| 82 | + ..\utest\srs_utest_handshake.cpp, | ||
| 81 | research readonly separator, | 83 | research readonly separator, |
| 82 | ..\..\research\librtmp\srs_play.c, | 84 | ..\..\research\librtmp\srs_play.c, |
| 83 | ..\..\research\librtmp\srs_publish.c, | 85 | ..\..\research\librtmp\srs_publish.c, |
trunk/src/utest/srs_utest_handshake.cpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | +#include <srs_utest_handshake.hpp> | ||
| 24 | + | ||
| 25 | +#include <srs_kernel_error.hpp> | ||
| 26 | +#include <srs_core_autofree.hpp> | ||
| 27 | + | ||
| 28 | +// verify the sha256 | ||
| 29 | +VOID TEST(HandshakeTest, OpensslSha256) | ||
| 30 | +{ | ||
| 31 | + // randome bytes to ensure the openssl sha256 is ok. | ||
| 32 | + char random_bytes[] = { | ||
| 33 | + 0x8b, 0x1c, 0x5c, 0x5c, 0x3b, 0x98, 0x60, 0x80, 0x3c, 0x97, 0x43, 0x79, 0x9c, 0x94, 0xec, 0x63, 0xaa, 0xd9, 0x10, 0xd7, 0x0d, 0x91, 0xfb, 0x1f, 0xbf, 0xe0, 0x29, 0xde, 0x77, 0x09, 0x21, 0x34, 0xa5, 0x7d, 0xdf, 0xe3, 0xdf, 0x11, 0xdf, 0xd4, 0x00, 0x57, 0x38, 0x5b, 0xae, 0x9e, 0x89, 0x35, 0xcf, 0x07, 0x48, 0xca, 0xc8, 0x25, 0x46, 0x3c, | ||
| 34 | + 0xb6, 0xdb, 0x9b, 0x39, 0xa6, 0x07, 0x3d, 0xaf, 0x8b, 0x85, 0xa2, 0x2f, 0x03, 0x64, 0x5e, 0xbd, 0xb4, 0x20, 0x01, 0x48, 0x2e, 0xc2, 0xe6, 0xcc, 0xce, 0x61, 0x59, 0x47, 0xf9, 0xdd, 0xc2, 0xa2, 0xfe, 0x64, 0xe6, 0x0b, 0x41, 0x4f, 0xe4, 0x8a, 0xca, 0xbe, 0x4d, 0x0e, 0x73, 0xba, 0x82, 0x30, 0x3c, 0x53, 0x36, 0x2e, 0xd3, 0x04, 0xae, 0x49, | ||
| 35 | + 0x44, 0x71, 0x6d, 0x4d, 0x5a, 0x14, 0x94, 0x94, 0x57, 0x78, 0xb9, 0x2a, 0x34, 0x49, 0xf8, 0xc2, 0xec, 0x4e, 0x29, 0xb6, 0x28, 0x54, 0x4a, 0x5e, 0x68, 0x06, 0xfe, 0xfc, 0xd5, 0x01, 0x35, 0x0c, 0x95, 0x6f, 0xe9, 0x77, 0x8a, 0xfc, 0x11, 0x15, 0x1a, 0xda, 0x6c, 0xf5, 0xba, 0x9e, 0x41, 0xd9, 0x7e, 0x0f, 0xdb, 0x33, 0xda, 0x35, 0x9d, 0x34, | ||
| 36 | + 0x67, 0x8f, 0xdf, 0x71, 0x63, 0x04, 0x9c, 0x54, 0xb6, 0x18, 0x10, 0x2d, 0x42, 0xd2, 0xf3, 0x14, 0x34, 0xa1, 0x31, 0x90, 0x48, 0xc9, 0x4b, 0x87, 0xb5, 0xcd, 0x62, 0x6b, 0x77, 0x18, 0x36, 0xd9, 0xc9, 0xc9, 0xae, 0x89, 0xfb, 0xed, 0xcd, 0xcb, 0xdb, 0x6e, 0xe3, 0x22, 0xbf, 0x7b, 0x72, 0x8a, 0xc3, 0x79, 0xd6, 0x1b, 0x6c, 0xe7, 0x9c, 0xc9, | ||
| 37 | + 0xfd, 0x48, 0xaa, 0xc1, 0xfa, 0xbf, 0x33, 0x87, 0x5c, 0x0d, 0xe5, 0x34, 0x24, 0x70, 0x14, 0x1e, 0x4a, 0x48, 0x07, 0x6e, 0xaf, 0xbf, 0xfe, 0x34, 0x1e, 0x1e, 0x19, 0xfc, 0xb5, 0x8a, 0x4f, 0x3c, 0xb4, 0xcf, 0xde, 0x24, 0x79, 0x65, 0x17, 0x22, 0x3f, 0xc0, 0x06, 0x76, 0x4e, 0x3c, 0xfb, 0xc3, 0xd0, 0x7f, 0x7b, 0x87, 0x5c, 0xeb, 0x97, 0x87, | ||
| 38 | + }; | ||
| 39 | + | ||
| 40 | + char digest[OpensslHashSize]; | ||
| 41 | + ASSERT_EQ(ERROR_SUCCESS, | ||
| 42 | + openssl_HMACsha256( | ||
| 43 | + random_bytes, sizeof(random_bytes), | ||
| 44 | + SrsGenuineFPKey, 30, | ||
| 45 | + digest | ||
| 46 | + ) | ||
| 47 | + ); | ||
| 48 | + | ||
| 49 | + char expect_digest[] = { | ||
| 50 | + 0x1b, 0xc7, 0xe6, 0x14, 0xd5, 0x19, 0x8d, 0x99, 0x42, 0x0a, 0x21, 0x95, 0x26, 0x9a, 0x8a, 0x56, | ||
| 51 | + 0xb4, 0x82, 0x2a, 0x7f, 0xd3, 0x1d, 0xc3, 0xd8, 0x92, 0x97, 0xc4, 0x61, 0xb7, 0x4d, 0x5d, 0xd2 | ||
| 52 | + }; | ||
| 53 | + EXPECT_TRUE(srs_bytes_equals(digest, expect_digest, 32)); | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +// flash will sendout a c0c1 encrypt by ssl. | ||
| 57 | +VOID TEST(HandshakeTest, VerifyFPC0C1) | ||
| 58 | +{ | ||
| 59 | + char c0c1[] = { | ||
| 60 | + 0x03, 0x00, 0x0f, 0x64, 0xd0, 0x80, 0x00, 0x07, 0x02, 0xe6, 0x42, 0xe5, 0x2b, 0xf1, 0x1d, 0x0f, 0x6c, 0xc8, 0x50, 0xf2, 0x06, 0xae, 0xd5, 0x4f, 0xdb, 0xfe, 0x79, 0xc2, 0xef, 0xf5, 0x01, 0x74, 0x4b, 0x5b, 0xe7, 0x37, 0xa3, 0xe0, 0xca, 0xe1, 0x97, 0x07, 0xdb, 0x54, 0x1d, 0x4c, 0x4b, 0xa3, 0xc3, 0x3e, 0xa9, 0xeb, 0xa9, 0x5b, 0x2f, 0x38, 0xa0, 0xa9, 0x98, 0x38, 0x80, 0x1b, 0xfb, 0xa7, 0x04, 0xff, 0xfd, 0x45, 0xfe, 0xfa, 0xc1, 0xe4, 0x1c, 0x77, 0x9a, 0x19, 0x39, 0x34, 0x10, 0x79, 0x12, 0xcf, 0x4e, 0xea, 0x34, 0x7d, 0x88, 0x47, 0xca, 0xf2, 0xb3, 0x09, 0x50, 0xbb, 0xe1, 0x20, 0x9b, 0x25, 0xb0, 0x3c, 0xbc, 0x46, 0x7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6, 0xf7, 0x5d, 0x93, 0x21, 0x9d, 0x17, 0xde, 0x9e, 0x87, 0xdc, 0xcd, 0x9a, 0x6a, 0x30, 0x3e, 0xa9, 0x70, 0xed, 0x93, 0x1d, 0x43, 0xb5, 0x5d, 0xb0, 0x46, 0x74, 0x73, 0x3b, 0x25, 0xfa, 0x0e, 0xe3, 0x70, 0x74, 0x2d, 0x75, 0xd6, 0x14, 0x67, 0x40, 0x31, 0xf9, 0x2c, 0xf6, 0x38, 0xea, 0x45, 0x33, 0xc1, 0xb6, 0xd5, 0x93, 0x0f, 0x5c, 0xaf, 0x3a, 0x53, 0x75, 0xd6, 0xe8, 0x97, 0xa0, 0x51, 0x3f, 0x96, 0x41, 0x32, 0x0b, 0x59, 0x48, 0xbf, 0x2b, 0x19, 0x67, 0x98, 0x42, 0xfe, 0x44, 0x23, 0x84, 0xa9, 0x09, 0x40, 0x4e, 0x10, 0x25, 0xdf, 0x68, 0x93, 0x6b, 0x0d, 0xa8, 0x51, 0x47, 0x55, 0xb7, 0xb8, 0x22, 0xab, 0xa3, 0x3c, 0x78, 0xd6, 0x8b, 0x4f, 0x2a, 0x73, 0xc1, 0x4a, 0x4a, 0xdd, 0x73, 0xb1, 0xc0, 0x8c, 0x5f, 0xf6, 0xe7, 0xbe, 0x9c, 0x96, 0xd6, 0x37, 0x91, 0x05, 0x52, 0xd1, 0x2f, 0xa9, 0xdc, 0xca, 0x11, 0x30, 0x6d, 0x4f, 0xb5, 0x6e, 0x39, 0x24, 0x28, 0x80, 0x54, 0x28, 0x87, 0xe6, 0x40, 0xeb, 0xd8, 0x7a, 0x1f, 0x63, 0x56, 0xc1, 0x4d, 0xa0, 0xf8 | ||
| 67 | + }; | ||
| 68 | + ASSERT_EQ(1537, (int)sizeof(c0c1)); | ||
| 69 | + | ||
| 70 | + // c0 | ||
| 71 | + EXPECT_EQ(0x03, c0c1[0]); | ||
| 72 | + | ||
| 73 | + // c1 | ||
| 74 | + c1s1 c1; | ||
| 75 | + | ||
| 76 | + // the schema of data must be schema0: key-digest. | ||
| 77 | + ASSERT_EQ(ERROR_SUCCESS, c1.c1_parse(c0c1 + 1, srs_schema0)); | ||
| 78 | + EXPECT_EQ((int32_t)0xd0640f00, c1.time); | ||
| 79 | + EXPECT_EQ((int32_t)0x2070080, c1.version); | ||
| 80 | + | ||
| 81 | + // manually validate the c1 | ||
| 82 | + // @see: calc_c1_digest | ||
| 83 | + char* c1s1_joined_bytes = srs_bytes_join_schema0(c1.time, c1.version, &c1.block0.key, &c1.block1.digest); | ||
| 84 | + SrsAutoFree(char, c1s1_joined_bytes, true); | ||
| 85 | + | ||
| 86 | + bool is_valid; | ||
| 87 | + ASSERT_EQ(ERROR_SUCCESS, c1.c1_validate_digest(is_valid)); | ||
| 88 | + ASSERT_TRUE(is_valid); | ||
| 89 | + | ||
| 90 | + // 128bytes key | ||
| 91 | + char key[] = { | ||
| 92 | + 0x01, 0xc6, 0xba, 0xe4, 0xb8, 0xd5, 0xbd, 0x7b, 0x43, 0xc9, 0x69, 0x6b, 0x40, 0xf7, 0xdc, 0x65, 0xa4, 0xf7, 0xca, 0x1f, 0xd8, 0xe5, 0xba, 0x4c, 0xdf, 0xe4, 0x64, 0x9e, 0x7d, 0xbd, 0x54, 0x13, 0x13, 0xc6, 0x0c, 0xb8, 0x1d, 0x31, 0x0a, 0x49, 0xe2, 0x43, 0xb6, 0x95, 0x5f, 0x05, 0x6e, 0x66, | ||
| 93 | + 0xf4, 0x21, 0xa8, 0x65, 0xce, 0xf8, 0x8e, 0xcc, 0x16, 0x1e, 0xbb, 0xd8, 0x0e, 0xcb, 0xd2, 0x48, 0x37, 0xaf, 0x4e, 0x67, 0x45, 0xf1, 0x79, 0x69, 0xd2, 0xee, 0xa4, 0xb5, 0x01, 0xbf, 0x57, 0x0f, 0x68, 0x37, 0xbe, 0x4e, 0xff, 0xc9, 0xb9, 0x92, 0x23, 0x06, 0x75, 0xa0, 0x42, 0xe4, 0x0a, 0x30, | ||
| 94 | + 0xf0, 0xaf, 0xb0, 0x54, 0x88, 0x7c, 0xc0, 0xc1, 0x0c, 0x6d, 0x01, 0x36, 0x63, 0xf3, 0x3d, 0xbc, 0x72, 0xf6, 0x96, 0xc8, 0x87, 0xab, 0x8b, 0x0c, 0x91, 0x2f, 0x42, 0x2a, 0x11, 0xf6, 0x2d, 0x5e | ||
| 95 | + }; | ||
| 96 | + EXPECT_TRUE(srs_bytes_equals(c1.block0.key.key, key, 128)); | ||
| 97 | + | ||
| 98 | + // 32bytes digest | ||
| 99 | + char digest[] = { | ||
| 100 | + 0x6c, 0x96, 0x9f, 0x26, 0xeb, 0xdc, 0x61, 0xc4, 0x8f, 0xd3, 0x2b, 0x81, 0x86, 0x6c, 0x9c, 0xc2, | ||
| 101 | + 0xb1, 0xb5, 0xbc, 0xa6, 0xd6, 0xd6, 0x1d, 0xce, 0x93, 0x78, 0xb3, 0xec, 0xa8, 0x64, 0x19, 0x13 | ||
| 102 | + }; | ||
| 103 | + EXPECT_TRUE(srs_bytes_equals(c1.block1.digest.digest, digest, 32)); | ||
| 104 | +} |
trunk/src/utest/srs_utest_handshake.hpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_UTEST_HANDSHAKE_HPP | ||
| 25 | +#define SRS_UTEST_HANDSHAKE_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_utest_handshake.hpp> | ||
| 29 | +*/ | ||
| 30 | +#include <srs_utest.hpp> | ||
| 31 | + | ||
| 32 | +#include <srs_protocol_handshake.hpp> | ||
| 33 | +using namespace srs; | ||
| 34 | + | ||
| 35 | +#endif |
-
请 注册 或 登录 后发表评论