正在显示
5 个修改的文件
包含
157 行增加
和
105 行删除
| @@ -97,7 +97,7 @@ namespace srs | @@ -97,7 +97,7 @@ namespace srs | ||
| 97 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" \ | 97 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" \ |
| 98 | "FFFFFFFFFFFFFFFF" | 98 | "FFFFFFFFFFFFFFFF" |
| 99 | int __openssl_generate_key( | 99 | int __openssl_generate_key( |
| 100 | - u_int8_t*& _private_key, u_int8_t*& _public_key, int32_t& size, | 100 | + u_int8_t* _private_key, u_int8_t* _public_key, int32_t& size, |
| 101 | DH*& pdh, int32_t& bits_count, u_int8_t*& shared_key, int32_t& shared_key_length, BIGNUM*& peer_public_key | 101 | DH*& pdh, int32_t& bits_count, u_int8_t*& shared_key, int32_t& shared_key_length, BIGNUM*& peer_public_key |
| 102 | ){ | 102 | ){ |
| 103 | int ret = ERROR_SUCCESS; | 103 | int ret = ERROR_SUCCESS; |
| @@ -200,7 +200,7 @@ namespace srs | @@ -200,7 +200,7 @@ namespace srs | ||
| 200 | BIGNUM* peer_public_key = NULL; | 200 | BIGNUM* peer_public_key = NULL; |
| 201 | 201 | ||
| 202 | ret = __openssl_generate_key( | 202 | ret = __openssl_generate_key( |
| 203 | - (u_int8_t*&)_private_key, (u_int8_t*&)_public_key, size, | 203 | + (u_int8_t*)_private_key, (u_int8_t*)_public_key, size, |
| 204 | pdh, bits_count, shared_key, shared_key_length, peer_public_key | 204 | pdh, bits_count, shared_key, shared_key_length, peer_public_key |
| 205 | ); | 205 | ); |
| 206 | 206 | ||
| @@ -543,6 +543,14 @@ namespace srs | @@ -543,6 +543,14 @@ namespace srs | ||
| 543 | u_int8_t* a = (u_int8_t*)pa; | 543 | u_int8_t* a = (u_int8_t*)pa; |
| 544 | u_int8_t* b = (u_int8_t*)pb; | 544 | u_int8_t* b = (u_int8_t*)pb; |
| 545 | 545 | ||
| 546 | + if (!a && !b) { | ||
| 547 | + return true; | ||
| 548 | + } | ||
| 549 | + | ||
| 550 | + if (!a || !b) { | ||
| 551 | + return false; | ||
| 552 | + } | ||
| 553 | + | ||
| 546 | for(int i = 0; i < size; i++){ | 554 | for(int i = 0; i < size; i++){ |
| 547 | if(a[i] != b[i]){ | 555 | if(a[i] != b[i]){ |
| 548 | return false; | 556 | return false; |
| @@ -36,6 +36,77 @@ ISrsThreadContext* _srs_context = new ISrsThreadContext(); | @@ -36,6 +36,77 @@ ISrsThreadContext* _srs_context = new ISrsThreadContext(); | ||
| 36 | SrsConfig* _srs_config = NULL; | 36 | SrsConfig* _srs_config = NULL; |
| 37 | SrsServer* _srs_server = NULL; | 37 | SrsServer* _srs_server = NULL; |
| 38 | 38 | ||
| 39 | +MockEmptyIO::MockEmptyIO() | ||
| 40 | +{ | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +MockEmptyIO::~MockEmptyIO() | ||
| 44 | +{ | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +bool MockEmptyIO::is_never_timeout(int64_t /*timeout_us*/) | ||
| 48 | +{ | ||
| 49 | + return true; | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +int MockEmptyIO::read_fully(const void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) | ||
| 53 | +{ | ||
| 54 | + return ERROR_SUCCESS; | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +int MockEmptyIO::write(const void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite*/) | ||
| 58 | +{ | ||
| 59 | + return ERROR_SUCCESS; | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +void MockEmptyIO::set_recv_timeout(int64_t /*timeout_us*/) | ||
| 63 | +{ | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +int64_t MockEmptyIO::get_recv_timeout() | ||
| 67 | +{ | ||
| 68 | + return -1; | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +int64_t MockEmptyIO::get_recv_bytes() | ||
| 72 | +{ | ||
| 73 | + return -1; | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +int MockEmptyIO::get_recv_kbps() | ||
| 77 | +{ | ||
| 78 | + return 0; | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +void MockEmptyIO::set_send_timeout(int64_t /*timeout_us*/) | ||
| 82 | +{ | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +int64_t MockEmptyIO::get_send_timeout() | ||
| 86 | +{ | ||
| 87 | + return 0; | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +int64_t MockEmptyIO::get_send_bytes() | ||
| 91 | +{ | ||
| 92 | + return 0; | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +int MockEmptyIO::get_send_kbps() | ||
| 96 | +{ | ||
| 97 | + return 0; | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +int MockEmptyIO::writev(const iovec */*iov*/, int /*iov_size*/, ssize_t* /*nwrite*/) | ||
| 101 | +{ | ||
| 102 | + return ERROR_SUCCESS; | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +int MockEmptyIO::read(const void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) | ||
| 106 | +{ | ||
| 107 | + return ERROR_SUCCESS; | ||
| 108 | +} | ||
| 109 | + | ||
| 39 | // basic test and samples. | 110 | // basic test and samples. |
| 40 | VOID TEST(SampleTest, FastSampleInt64Test) | 111 | VOID TEST(SampleTest, FastSampleInt64Test) |
| 41 | { | 112 | { |
| @@ -34,4 +34,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,4 +34,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 34 | // we add an empty macro for upp to show the smart tips. | 34 | // we add an empty macro for upp to show the smart tips. |
| 35 | #define VOID | 35 | #define VOID |
| 36 | 36 | ||
| 37 | +#include <srs_protocol_io.hpp> | ||
| 38 | + | ||
| 39 | +class MockEmptyIO : public ISrsProtocolReaderWriter | ||
| 40 | +{ | ||
| 41 | +public: | ||
| 42 | + MockEmptyIO(); | ||
| 43 | + virtual ~MockEmptyIO(); | ||
| 44 | +// for protocol | ||
| 45 | +public: | ||
| 46 | + virtual bool is_never_timeout(int64_t timeout_us); | ||
| 47 | +// for handshake. | ||
| 48 | +public: | ||
| 49 | + virtual int read_fully(const void* buf, size_t size, ssize_t* nread); | ||
| 50 | + virtual int write(const void* buf, size_t size, ssize_t* nwrite); | ||
| 51 | +// for protocol | ||
| 52 | +public: | ||
| 53 | + virtual void set_recv_timeout(int64_t timeout_us); | ||
| 54 | + virtual int64_t get_recv_timeout(); | ||
| 55 | + virtual int64_t get_recv_bytes(); | ||
| 56 | + virtual int get_recv_kbps(); | ||
| 57 | +// for protocol | ||
| 58 | +public: | ||
| 59 | + virtual void set_send_timeout(int64_t timeout_us); | ||
| 60 | + virtual int64_t get_send_timeout(); | ||
| 61 | + virtual int64_t get_send_bytes(); | ||
| 62 | + virtual int get_send_kbps(); | ||
| 63 | + virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite); | ||
| 64 | +// for protocol/amf0/msg-codec | ||
| 65 | +public: | ||
| 66 | + virtual int read(const void* buf, size_t size, ssize_t* nread); | ||
| 67 | +}; | ||
| 68 | + | ||
| 37 | #endif | 69 | #endif |
| @@ -24,77 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -24,77 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 24 | 24 | ||
| 25 | #include <srs_kernel_error.hpp> | 25 | #include <srs_kernel_error.hpp> |
| 26 | #include <srs_core_autofree.hpp> | 26 | #include <srs_core_autofree.hpp> |
| 27 | - | ||
| 28 | -MockEmptyIO::MockEmptyIO() | ||
| 29 | -{ | ||
| 30 | -} | ||
| 31 | - | ||
| 32 | -MockEmptyIO::~MockEmptyIO() | ||
| 33 | -{ | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -bool MockEmptyIO::is_never_timeout(int64_t /*timeout_us*/) | ||
| 37 | -{ | ||
| 38 | - return true; | ||
| 39 | -} | ||
| 40 | - | ||
| 41 | -int MockEmptyIO::read_fully(const void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) | ||
| 42 | -{ | ||
| 43 | - return ERROR_SUCCESS; | ||
| 44 | -} | ||
| 45 | - | ||
| 46 | -int MockEmptyIO::write(const void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite*/) | ||
| 47 | -{ | ||
| 48 | - return ERROR_SUCCESS; | ||
| 49 | -} | ||
| 50 | - | ||
| 51 | -void MockEmptyIO::set_recv_timeout(int64_t /*timeout_us*/) | ||
| 52 | -{ | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -int64_t MockEmptyIO::get_recv_timeout() | ||
| 56 | -{ | ||
| 57 | - return -1; | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | -int64_t MockEmptyIO::get_recv_bytes() | ||
| 61 | -{ | ||
| 62 | - return -1; | ||
| 63 | -} | ||
| 64 | - | ||
| 65 | -int MockEmptyIO::get_recv_kbps() | ||
| 66 | -{ | ||
| 67 | - return 0; | ||
| 68 | -} | ||
| 69 | - | ||
| 70 | -void MockEmptyIO::set_send_timeout(int64_t /*timeout_us*/) | ||
| 71 | -{ | ||
| 72 | -} | ||
| 73 | - | ||
| 74 | -int64_t MockEmptyIO::get_send_timeout() | ||
| 75 | -{ | ||
| 76 | - return 0; | ||
| 77 | -} | ||
| 78 | - | ||
| 79 | -int64_t MockEmptyIO::get_send_bytes() | ||
| 80 | -{ | ||
| 81 | - return 0; | ||
| 82 | -} | ||
| 83 | - | ||
| 84 | -int MockEmptyIO::get_send_kbps() | ||
| 85 | -{ | ||
| 86 | - return 0; | ||
| 87 | -} | ||
| 88 | - | ||
| 89 | -int MockEmptyIO::writev(const iovec */*iov*/, int /*iov_size*/, ssize_t* /*nwrite*/) | ||
| 90 | -{ | ||
| 91 | - return ERROR_SUCCESS; | ||
| 92 | -} | ||
| 93 | - | ||
| 94 | -int MockEmptyIO::read(const void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) | ||
| 95 | -{ | ||
| 96 | - return ERROR_SUCCESS; | ||
| 97 | -} | 27 | +#include <srs_protocol_utility.hpp> |
| 98 | 28 | ||
| 99 | // verify the sha256 | 29 | // verify the sha256 |
| 100 | VOID TEST(HandshakeTest, OpensslSha256) | 30 | VOID TEST(HandshakeTest, OpensslSha256) |
| @@ -124,6 +54,37 @@ VOID TEST(HandshakeTest, OpensslSha256) | @@ -124,6 +54,37 @@ VOID TEST(HandshakeTest, OpensslSha256) | ||
| 124 | EXPECT_TRUE(srs_bytes_equals(digest, expect_digest, 32)); | 54 | EXPECT_TRUE(srs_bytes_equals(digest, expect_digest, 32)); |
| 125 | } | 55 | } |
| 126 | 56 | ||
| 57 | +// verify the dh key | ||
| 58 | +VOID TEST(HandshakeTest, DHKey) | ||
| 59 | +{ | ||
| 60 | + char pri_key[] = { | ||
| 61 | + 0x6e, 0x65, 0x69, 0x2d, 0x69, 0x2d, 0x69, 0x73, | ||
| 62 | + 0x6e, 0x69, 0x73, 0x6c, 0x65, 0x72, 0x69, 0x72, | ||
| 63 | + 0x76, 0x65, 0x72, 0x69, 0x77, 0x74, 0x2e, 0x6e, | ||
| 64 | + 0x72, 0x76, 0x72, 0x65, 0x72, 0x70, 0x72, 0x69, | ||
| 65 | + 0x69, 0x70, 0x72, 0x73, 0x6e, 0x65, 0x72, 0x72, | ||
| 66 | + 0x6e, 0x2d, 0x65, 0x74, 0x72, 0x6c, 0x69, 0x74, | ||
| 67 | + 0x69, 0x65, 0x40, 0x69, 0x69, 0x76, 0x77, 0x2d, | ||
| 68 | + 0x73, 0x65, 0x72, 0x72, 0x76, 0x73, 0x72, 0x2e, | ||
| 69 | + 0x2d, 0x76, 0x65, 0x31, 0x65, 0x6d, 0x6d, 0x73, | ||
| 70 | + 0x69, 0x73, 0x74, 0x2e, 0x74, 0x72, 0x65, 0x65, | ||
| 71 | + 0x72, 0x65, 0x2d, 0x74, 0x69, 0x31, 0x65, 0x2d, | ||
| 72 | + 0x6f, 0x77, 0x2e, 0x76, 0x77, 0x2d, 0x77, 0x72, | ||
| 73 | + 0x65, 0x65, 0x31, 0x74, 0x73, 0x70, 0x74, 0x6e, | ||
| 74 | + 0x72, 0x6e, 0x73, 0x6d, 0x2e, 0x69, 0x72, 0x2d, | ||
| 75 | + 0x65, 0x69, 0x77, 0x69, 0x76, 0x72, 0x77, 0x72, | ||
| 76 | + 0x32, 0x6e, 0x65, 0x6c, 0x2e, 0x2d, 0x6e, 0x69 | ||
| 77 | + }; | ||
| 78 | + | ||
| 79 | + char pub_key1[128]; | ||
| 80 | + openssl_generate_key(pri_key, pub_key1, 128); | ||
| 81 | + | ||
| 82 | + char pub_key2[128]; | ||
| 83 | + openssl_generate_key(pri_key, pub_key2, 128); | ||
| 84 | + | ||
| 85 | + EXPECT_FALSE(srs_bytes_equals(pub_key1, pub_key2, 128)); | ||
| 86 | +} | ||
| 87 | + | ||
| 127 | // flash will sendout a c0c1 encrypt by ssl. | 88 | // flash will sendout a c0c1 encrypt by ssl. |
| 128 | VOID TEST(HandshakeTest, VerifyFPC0C1) | 89 | VOID TEST(HandshakeTest, VerifyFPC0C1) |
| 129 | { | 90 | { |
| @@ -263,5 +224,16 @@ VOID TEST(HandshakeTest, ComplexHandshake) | @@ -263,5 +224,16 @@ VOID TEST(HandshakeTest, ComplexHandshake) | ||
| 263 | 224 | ||
| 264 | VOID TEST(HandshakeTest, BytesEqual) | 225 | VOID TEST(HandshakeTest, BytesEqual) |
| 265 | { | 226 | { |
| 266 | - //srs_bytes_equals | 227 | + char a1[] = { 0x01 }; |
| 228 | + char b1[] = { 0x02 }; | ||
| 229 | + char a2[] = { 0x01, 0x02 }; | ||
| 230 | + char b2[] = { 0x02, 0x03 }; | ||
| 231 | + | ||
| 232 | + EXPECT_TRUE(srs_bytes_equals(NULL, NULL, 0)); | ||
| 233 | + EXPECT_FALSE(srs_bytes_equals(a1, NULL, 1)); | ||
| 234 | + EXPECT_FALSE(srs_bytes_equals(NULL, a1, 1)); | ||
| 235 | + EXPECT_FALSE(srs_bytes_equals(a1, b1, 1)); | ||
| 236 | + EXPECT_TRUE(srs_bytes_equals(a1, a1, 1)); | ||
| 237 | + EXPECT_TRUE(srs_bytes_equals(a1, a2, 1)); | ||
| 238 | + EXPECT_FALSE(srs_bytes_equals(a1, b2, 1)); | ||
| 267 | } | 239 | } |
| @@ -29,39 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -29,39 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 29 | */ | 29 | */ |
| 30 | #include <srs_utest.hpp> | 30 | #include <srs_utest.hpp> |
| 31 | 31 | ||
| 32 | -#include <srs_protocol_io.hpp> | ||
| 33 | #include <srs_protocol_rtmp.hpp> | 32 | #include <srs_protocol_rtmp.hpp> |
| 34 | #include <srs_protocol_handshake.hpp> | 33 | #include <srs_protocol_handshake.hpp> |
| 35 | using namespace srs; | 34 | using namespace srs; |
| 36 | 35 | ||
| 37 | -class MockEmptyIO : public ISrsProtocolReaderWriter | ||
| 38 | -{ | ||
| 39 | -public: | ||
| 40 | - MockEmptyIO(); | ||
| 41 | - virtual ~MockEmptyIO(); | ||
| 42 | -// for protocol | ||
| 43 | -public: | ||
| 44 | - virtual bool is_never_timeout(int64_t timeout_us); | ||
| 45 | -// for handshake. | ||
| 46 | -public: | ||
| 47 | - virtual int read_fully(const void* buf, size_t size, ssize_t* nread); | ||
| 48 | - virtual int write(const void* buf, size_t size, ssize_t* nwrite); | ||
| 49 | -// for protocol | ||
| 50 | -public: | ||
| 51 | - virtual void set_recv_timeout(int64_t timeout_us); | ||
| 52 | - virtual int64_t get_recv_timeout(); | ||
| 53 | - virtual int64_t get_recv_bytes(); | ||
| 54 | - virtual int get_recv_kbps(); | ||
| 55 | -// for protocol | ||
| 56 | -public: | ||
| 57 | - virtual void set_send_timeout(int64_t timeout_us); | ||
| 58 | - virtual int64_t get_send_timeout(); | ||
| 59 | - virtual int64_t get_send_bytes(); | ||
| 60 | - virtual int get_send_kbps(); | ||
| 61 | - virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite); | ||
| 62 | -// for protocol/amf0/msg-codec | ||
| 63 | -public: | ||
| 64 | - virtual int read(const void* buf, size_t size, ssize_t* nread); | ||
| 65 | -}; | ||
| 66 | - | ||
| 67 | #endif | 36 | #endif |
-
请 注册 或 登录 后发表评论