正在显示
2 个修改的文件
包含
137 行增加
和
3 行删除
| @@ -23,7 +23,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -23,7 +23,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | 23 | ||
| 24 | #include <srs_core_complex_handshake.hpp> | 24 | #include <srs_core_complex_handshake.hpp> |
| 25 | 25 | ||
| 26 | +#include <time.h> | ||
| 27 | +#include <stdlib.h> | ||
| 28 | + | ||
| 26 | #include <srs_core_error.hpp> | 29 | #include <srs_core_error.hpp> |
| 30 | +#include <srs_core_log.hpp> | ||
| 27 | 31 | ||
| 28 | SrsComplexHandshake::SrsComplexHandshake() | 32 | SrsComplexHandshake::SrsComplexHandshake() |
| 29 | { | 33 | { |
| @@ -33,9 +37,139 @@ SrsComplexHandshake::~SrsComplexHandshake() | @@ -33,9 +37,139 @@ SrsComplexHandshake::~SrsComplexHandshake() | ||
| 33 | { | 37 | { |
| 34 | } | 38 | } |
| 35 | 39 | ||
| 36 | -int SrsComplexHandshake::handshake(SrsSocket& skt, char* c1) | 40 | +/** |
| 41 | +* 764bytes key结构 | ||
| 42 | +* random-data: (offset)bytes | ||
| 43 | +* key-data: 128bytes | ||
| 44 | +* random-data: (764-offset-128-4)bytes | ||
| 45 | +* offset: 4bytes | ||
| 46 | +*/ | ||
| 47 | +struct key_block | ||
| 48 | +{ | ||
| 49 | + // (offset)bytes | ||
| 50 | + char* random0; | ||
| 51 | + int random0_size; | ||
| 52 | + | ||
| 53 | + // 128bytes | ||
| 54 | + char key[128]; | ||
| 55 | + | ||
| 56 | + // (764-offset-128-4)bytes | ||
| 57 | + char* random1; | ||
| 58 | + int random1_size; | ||
| 59 | + | ||
| 60 | + // 4bytes | ||
| 61 | + int32_t offset; | ||
| 62 | +}; | ||
| 63 | +void srs_key_block_init(key_block* key) | ||
| 64 | +{ | ||
| 65 | +} | ||
| 66 | +void srs_key_block_free(key_block* key) | ||
| 67 | +{ | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +/** | ||
| 71 | +* 764bytes digest结构 | ||
| 72 | +* offset: 4bytes | ||
| 73 | +* random-data: (offset)bytes | ||
| 74 | +* digest-data: 32bytes | ||
| 75 | +* random-data: (764-4-offset-32)bytes | ||
| 76 | +*/ | ||
| 77 | +struct digest_block | ||
| 78 | +{ | ||
| 79 | + // 4bytes | ||
| 80 | + int32_t offset; | ||
| 81 | + | ||
| 82 | + // (offset)bytes | ||
| 83 | + char* random0; | ||
| 84 | + int random0_size; | ||
| 85 | + | ||
| 86 | + // 32bytes | ||
| 87 | + char digest[32]; | ||
| 88 | + | ||
| 89 | + // (764-4-offset-32)bytes | ||
| 90 | + char* random1; | ||
| 91 | + int random1_size; | ||
| 92 | +}; | ||
| 93 | +void srs_digest_block_init(digest_block* digest) | ||
| 94 | +{ | ||
| 95 | +} | ||
| 96 | +void srs_digest_block_free(digest_block* digest) | ||
| 97 | +{ | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +/** | ||
| 101 | +* c1s1 schema0 | ||
| 102 | +* time: 4bytes | ||
| 103 | +* version: 4bytes | ||
| 104 | +* key: 764bytes | ||
| 105 | +* digest: 764bytes | ||
| 106 | +* c1s1 schema1 | ||
| 107 | +* time: 4bytes | ||
| 108 | +* version: 4bytes | ||
| 109 | +* digest: 764bytes | ||
| 110 | +* key: 764bytes | ||
| 111 | +*/ | ||
| 112 | +struct c1s1 | ||
| 113 | +{ | ||
| 114 | + enum schema_type { | ||
| 115 | + schema0 = 0, | ||
| 116 | + schema1 = 1 | ||
| 117 | + }; | ||
| 118 | + union block { | ||
| 119 | + key_block key; | ||
| 120 | + digest_block digest; | ||
| 121 | + }; | ||
| 122 | + | ||
| 123 | + // 4bytes | ||
| 124 | + int32_t time; | ||
| 125 | + // 4bytes | ||
| 126 | + int32_t version; | ||
| 127 | + // 764bytes | ||
| 128 | + // if schema0, use key | ||
| 129 | + // if schema1, use digest | ||
| 130 | + block block0; | ||
| 131 | + // 764bytes | ||
| 132 | + // if schema0, use digest | ||
| 133 | + // if schema1, use key | ||
| 134 | + block block1; | ||
| 135 | + | ||
| 136 | + // the logic schema | ||
| 137 | + schema_type schema; | ||
| 138 | + | ||
| 139 | + c1s1() | ||
| 140 | + { | ||
| 141 | + time = ::time(NULL); | ||
| 142 | + version = 0x00; | ||
| 143 | + | ||
| 144 | + schema = c1s1::schema0; | ||
| 145 | + srs_key_block_init(&block0.key); | ||
| 146 | + srs_digest_block_init(&block1.digest); | ||
| 147 | + } | ||
| 148 | + virtual ~c1s1() | ||
| 149 | + { | ||
| 150 | + if (schema == c1s1::schema0) { | ||
| 151 | + srs_key_block_free(&block0.key); | ||
| 152 | + srs_digest_block_free(&block1.digest); | ||
| 153 | + } else { | ||
| 154 | + srs_digest_block_free(&block0.digest); | ||
| 155 | + srs_key_block_free(&block1.key); | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | +}; | ||
| 159 | + | ||
| 160 | +int SrsComplexHandshake::handshake(SrsSocket& skt, char* _c1) | ||
| 37 | { | 161 | { |
| 38 | int ret = ERROR_SUCCESS; | 162 | int ret = ERROR_SUCCESS; |
| 163 | + | ||
| 164 | + static bool _random_initialized = false; | ||
| 165 | + if (!_random_initialized) { | ||
| 166 | + srand(0); | ||
| 167 | + _random_initialized = true; | ||
| 168 | + srs_trace("srand initialized the random."); | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + c1s1 c1; | ||
| 172 | + | ||
| 39 | return ret; | 173 | return ret; |
| 40 | } | 174 | } |
| 41 | 175 |
| @@ -45,14 +45,14 @@ public: | @@ -45,14 +45,14 @@ public: | ||
| 45 | public: | 45 | public: |
| 46 | /** | 46 | /** |
| 47 | * complex hanshake. | 47 | * complex hanshake. |
| 48 | - * @c1, size of c1 must be 1536. | 48 | + * @_c1, size of c1 must be 1536. |
| 49 | * @remark, user must free the c1. | 49 | * @remark, user must free the c1. |
| 50 | * @return user must: | 50 | * @return user must: |
| 51 | * continue connect app if success, | 51 | * continue connect app if success, |
| 52 | * try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS, | 52 | * try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS, |
| 53 | * otherwise, disconnect | 53 | * otherwise, disconnect |
| 54 | */ | 54 | */ |
| 55 | - virtual int handshake(SrsSocket& skt, char* c1); | 55 | + virtual int handshake(SrsSocket& skt, char* _c1); |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | #endif | 58 | #endif |
-
请 注册 或 登录 后发表评论