正在显示
1 个修改的文件
包含
22 行增加
和
24 行删除
@@ -31,6 +31,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,6 +31,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | #include <srs_core_autofree.hpp> | 31 | #include <srs_core_autofree.hpp> |
32 | #include <srs_core_socket.hpp> | 32 | #include <srs_core_socket.hpp> |
33 | 33 | ||
34 | +void srs_random_generate(char* bytes, int size) | ||
35 | +{ | ||
36 | + static char cdata[] = { | ||
37 | + 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x2d, 0x72, 0x74, 0x6d, 0x70, 0x2d, 0x73, 0x65, | ||
38 | + 0x72, 0x76, 0x65, 0x72, 0x2d, 0x77, 0x69, 0x6e, 0x6c, 0x69, 0x6e, 0x2d, 0x77, 0x69, | ||
39 | + 0x6e, 0x74, 0x65, 0x72, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x40, 0x31, 0x32, 0x36, | ||
40 | + 0x2e, 0x63, 0x6f, 0x6d | ||
41 | + }; | ||
42 | + for (int i = 0; i < size; i++) { | ||
43 | + bytes[i] = cdata[rand() % (sizeof(cdata) - 1)]; | ||
44 | + } | ||
45 | +} | ||
46 | + | ||
34 | // 68bytes FMS key which is used to sign the sever packet. | 47 | // 68bytes FMS key which is used to sign the sever packet. |
35 | u_int8_t SrsGenuineFMSKey[] = { | 48 | u_int8_t SrsGenuineFMSKey[] = { |
36 | 0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20, | 49 | 0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20, |
@@ -274,21 +287,15 @@ void srs_key_block_init(key_block* key) | @@ -274,21 +287,15 @@ void srs_key_block_init(key_block* key) | ||
274 | key->random0_size = offset; | 287 | key->random0_size = offset; |
275 | if (key->random0_size > 0) { | 288 | if (key->random0_size > 0) { |
276 | key->random0 = new char[key->random0_size]; | 289 | key->random0 = new char[key->random0_size]; |
277 | - for (int i = 0; i < key->random0_size; i++) { | ||
278 | - *(key->random0 + i) = rand() % 256; | ||
279 | - } | 290 | + srs_random_generate(key->random0, key->random0_size); |
280 | } | 291 | } |
281 | 292 | ||
282 | - for (int i = 0; i < (int)sizeof(key->key); i++) { | ||
283 | - *(key->key + i) = rand() % 256; | ||
284 | - } | 293 | + srs_random_generate(key->key, sizeof(key->key)); |
285 | 294 | ||
286 | key->random1_size = 764 - offset - 128 - 4; | 295 | key->random1_size = 764 - offset - 128 - 4; |
287 | if (key->random1_size > 0) { | 296 | if (key->random1_size > 0) { |
288 | key->random1 = new char[key->random1_size]; | 297 | key->random1 = new char[key->random1_size]; |
289 | - for (int i = 0; i < key->random1_size; i++) { | ||
290 | - *(key->random1 + i) = rand() % 256; | ||
291 | - } | 298 | + srs_random_generate(key->random1, key->random1_size); |
292 | } | 299 | } |
293 | } | 300 | } |
294 | // parse key block from c1s1. | 301 | // parse key block from c1s1. |
@@ -392,21 +399,15 @@ void srs_digest_block_init(digest_block* digest) | @@ -392,21 +399,15 @@ void srs_digest_block_init(digest_block* digest) | ||
392 | digest->random0_size = offset; | 399 | digest->random0_size = offset; |
393 | if (digest->random0_size > 0) { | 400 | if (digest->random0_size > 0) { |
394 | digest->random0 = new char[digest->random0_size]; | 401 | digest->random0 = new char[digest->random0_size]; |
395 | - for (int i = 0; i < digest->random0_size; i++) { | ||
396 | - *(digest->random0 + i) = rand() % 256; | ||
397 | - } | 402 | + srs_random_generate(digest->random0, digest->random0_size); |
398 | } | 403 | } |
399 | 404 | ||
400 | - for (int i = 0; i < (int)sizeof(digest->digest); i++) { | ||
401 | - *(digest->digest + i) = rand() % 256; | ||
402 | - } | 405 | + srs_random_generate(digest->digest, sizeof(digest->digest)); |
403 | 406 | ||
404 | digest->random1_size = 764 - 4 - offset - 32; | 407 | digest->random1_size = 764 - 4 - offset - 32; |
405 | if (digest->random1_size > 0) { | 408 | if (digest->random1_size > 0) { |
406 | digest->random1 = new char[digest->random1_size]; | 409 | digest->random1 = new char[digest->random1_size]; |
407 | - for (int i = 0; i < digest->random1_size; i++) { | ||
408 | - *(digest->random1 + i) = rand() % 256; | ||
409 | - } | 410 | + srs_random_generate(digest->random1, digest->random1_size); |
410 | } | 411 | } |
411 | } | 412 | } |
412 | // parse digest block from c1s1. | 413 | // parse digest block from c1s1. |
@@ -724,12 +725,8 @@ struct c2s2 | @@ -724,12 +725,8 @@ struct c2s2 | ||
724 | 725 | ||
725 | c2s2::c2s2() | 726 | c2s2::c2s2() |
726 | { | 727 | { |
727 | - for (int i = 0; i < 1504; i++) { | ||
728 | - *(random + i) = rand(); | ||
729 | - } | ||
730 | - for (int i = 0; i < 32; i++) { | ||
731 | - *(digest + i) = rand(); | ||
732 | - } | 728 | + srs_random_generate(random, 1504); |
729 | + srs_random_generate(digest, 32); | ||
733 | } | 730 | } |
734 | 731 | ||
735 | c2s2::~c2s2() | 732 | c2s2::~c2s2() |
@@ -1101,6 +1098,7 @@ int SrsSimpleHandshake::handshake(SrsSocket& skt, SrsComplexHandshake& complex_h | @@ -1101,6 +1098,7 @@ int SrsSimpleHandshake::handshake(SrsSocket& skt, SrsComplexHandshake& complex_h | ||
1101 | srs_info("rollback complex to simple handshake. ret=%d", ret); | 1098 | srs_info("rollback complex to simple handshake. ret=%d", ret); |
1102 | 1099 | ||
1103 | char* s0s1s2 = new char[3073]; | 1100 | char* s0s1s2 = new char[3073]; |
1101 | + srs_random_generate(s0s1s2, 3073); | ||
1104 | SrsAutoFree(char, s0s1s2, true); | 1102 | SrsAutoFree(char, s0s1s2, true); |
1105 | // plain text required. | 1103 | // plain text required. |
1106 | s0s1s2[0] = 0x03; | 1104 | s0s1s2[0] = 0x03; |
-
请 注册 或 登录 后发表评论