winlin

finish utest for handshake.

... ... @@ -97,7 +97,7 @@ namespace srs
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" \
"FFFFFFFFFFFFFFFF"
int __openssl_generate_key(
u_int8_t*& _private_key, u_int8_t*& _public_key, int32_t& size,
u_int8_t* _private_key, u_int8_t* _public_key, int32_t& size,
DH*& pdh, int32_t& bits_count, u_int8_t*& shared_key, int32_t& shared_key_length, BIGNUM*& peer_public_key
){
int ret = ERROR_SUCCESS;
... ... @@ -200,7 +200,7 @@ namespace srs
BIGNUM* peer_public_key = NULL;
ret = __openssl_generate_key(
(u_int8_t*&)_private_key, (u_int8_t*&)_public_key, size,
(u_int8_t*)_private_key, (u_int8_t*)_public_key, size,
pdh, bits_count, shared_key, shared_key_length, peer_public_key
);
... ... @@ -543,6 +543,14 @@ namespace srs
u_int8_t* a = (u_int8_t*)pa;
u_int8_t* b = (u_int8_t*)pb;
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
for(int i = 0; i < size; i++){
if(a[i] != b[i]){
return false;
... ...
... ... @@ -36,6 +36,77 @@ ISrsThreadContext* _srs_context = new ISrsThreadContext();
SrsConfig* _srs_config = NULL;
SrsServer* _srs_server = NULL;
MockEmptyIO::MockEmptyIO()
{
}
MockEmptyIO::~MockEmptyIO()
{
}
bool MockEmptyIO::is_never_timeout(int64_t /*timeout_us*/)
{
return true;
}
int MockEmptyIO::read_fully(const void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/)
{
return ERROR_SUCCESS;
}
int MockEmptyIO::write(const void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite*/)
{
return ERROR_SUCCESS;
}
void MockEmptyIO::set_recv_timeout(int64_t /*timeout_us*/)
{
}
int64_t MockEmptyIO::get_recv_timeout()
{
return -1;
}
int64_t MockEmptyIO::get_recv_bytes()
{
return -1;
}
int MockEmptyIO::get_recv_kbps()
{
return 0;
}
void MockEmptyIO::set_send_timeout(int64_t /*timeout_us*/)
{
}
int64_t MockEmptyIO::get_send_timeout()
{
return 0;
}
int64_t MockEmptyIO::get_send_bytes()
{
return 0;
}
int MockEmptyIO::get_send_kbps()
{
return 0;
}
int MockEmptyIO::writev(const iovec */*iov*/, int /*iov_size*/, ssize_t* /*nwrite*/)
{
return ERROR_SUCCESS;
}
int MockEmptyIO::read(const void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/)
{
return ERROR_SUCCESS;
}
// basic test and samples.
VOID TEST(SampleTest, FastSampleInt64Test)
{
... ...
... ... @@ -34,4 +34,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// we add an empty macro for upp to show the smart tips.
#define VOID
#include <srs_protocol_io.hpp>
class MockEmptyIO : public ISrsProtocolReaderWriter
{
public:
MockEmptyIO();
virtual ~MockEmptyIO();
// for protocol
public:
virtual bool is_never_timeout(int64_t timeout_us);
// for handshake.
public:
virtual int read_fully(const void* buf, size_t size, ssize_t* nread);
virtual int write(const void* buf, size_t size, ssize_t* nwrite);
// for protocol
public:
virtual void set_recv_timeout(int64_t timeout_us);
virtual int64_t get_recv_timeout();
virtual int64_t get_recv_bytes();
virtual int get_recv_kbps();
// for protocol
public:
virtual void set_send_timeout(int64_t timeout_us);
virtual int64_t get_send_timeout();
virtual int64_t get_send_bytes();
virtual int get_send_kbps();
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
// for protocol/amf0/msg-codec
public:
virtual int read(const void* buf, size_t size, ssize_t* nread);
};
#endif
... ...
... ... @@ -24,77 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_error.hpp>
#include <srs_core_autofree.hpp>
MockEmptyIO::MockEmptyIO()
{
}
MockEmptyIO::~MockEmptyIO()
{
}
bool MockEmptyIO::is_never_timeout(int64_t /*timeout_us*/)
{
return true;
}
int MockEmptyIO::read_fully(const void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/)
{
return ERROR_SUCCESS;
}
int MockEmptyIO::write(const void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite*/)
{
return ERROR_SUCCESS;
}
void MockEmptyIO::set_recv_timeout(int64_t /*timeout_us*/)
{
}
int64_t MockEmptyIO::get_recv_timeout()
{
return -1;
}
int64_t MockEmptyIO::get_recv_bytes()
{
return -1;
}
int MockEmptyIO::get_recv_kbps()
{
return 0;
}
void MockEmptyIO::set_send_timeout(int64_t /*timeout_us*/)
{
}
int64_t MockEmptyIO::get_send_timeout()
{
return 0;
}
int64_t MockEmptyIO::get_send_bytes()
{
return 0;
}
int MockEmptyIO::get_send_kbps()
{
return 0;
}
int MockEmptyIO::writev(const iovec */*iov*/, int /*iov_size*/, ssize_t* /*nwrite*/)
{
return ERROR_SUCCESS;
}
int MockEmptyIO::read(const void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/)
{
return ERROR_SUCCESS;
}
#include <srs_protocol_utility.hpp>
// verify the sha256
VOID TEST(HandshakeTest, OpensslSha256)
... ... @@ -124,6 +54,37 @@ VOID TEST(HandshakeTest, OpensslSha256)
EXPECT_TRUE(srs_bytes_equals(digest, expect_digest, 32));
}
// verify the dh key
VOID TEST(HandshakeTest, DHKey)
{
char pri_key[] = {
0x6e, 0x65, 0x69, 0x2d, 0x69, 0x2d, 0x69, 0x73,
0x6e, 0x69, 0x73, 0x6c, 0x65, 0x72, 0x69, 0x72,
0x76, 0x65, 0x72, 0x69, 0x77, 0x74, 0x2e, 0x6e,
0x72, 0x76, 0x72, 0x65, 0x72, 0x70, 0x72, 0x69,
0x69, 0x70, 0x72, 0x73, 0x6e, 0x65, 0x72, 0x72,
0x6e, 0x2d, 0x65, 0x74, 0x72, 0x6c, 0x69, 0x74,
0x69, 0x65, 0x40, 0x69, 0x69, 0x76, 0x77, 0x2d,
0x73, 0x65, 0x72, 0x72, 0x76, 0x73, 0x72, 0x2e,
0x2d, 0x76, 0x65, 0x31, 0x65, 0x6d, 0x6d, 0x73,
0x69, 0x73, 0x74, 0x2e, 0x74, 0x72, 0x65, 0x65,
0x72, 0x65, 0x2d, 0x74, 0x69, 0x31, 0x65, 0x2d,
0x6f, 0x77, 0x2e, 0x76, 0x77, 0x2d, 0x77, 0x72,
0x65, 0x65, 0x31, 0x74, 0x73, 0x70, 0x74, 0x6e,
0x72, 0x6e, 0x73, 0x6d, 0x2e, 0x69, 0x72, 0x2d,
0x65, 0x69, 0x77, 0x69, 0x76, 0x72, 0x77, 0x72,
0x32, 0x6e, 0x65, 0x6c, 0x2e, 0x2d, 0x6e, 0x69
};
char pub_key1[128];
openssl_generate_key(pri_key, pub_key1, 128);
char pub_key2[128];
openssl_generate_key(pri_key, pub_key2, 128);
EXPECT_FALSE(srs_bytes_equals(pub_key1, pub_key2, 128));
}
// flash will sendout a c0c1 encrypt by ssl.
VOID TEST(HandshakeTest, VerifyFPC0C1)
{
... ... @@ -263,5 +224,16 @@ VOID TEST(HandshakeTest, ComplexHandshake)
VOID TEST(HandshakeTest, BytesEqual)
{
//srs_bytes_equals
char a1[] = { 0x01 };
char b1[] = { 0x02 };
char a2[] = { 0x01, 0x02 };
char b2[] = { 0x02, 0x03 };
EXPECT_TRUE(srs_bytes_equals(NULL, NULL, 0));
EXPECT_FALSE(srs_bytes_equals(a1, NULL, 1));
EXPECT_FALSE(srs_bytes_equals(NULL, a1, 1));
EXPECT_FALSE(srs_bytes_equals(a1, b1, 1));
EXPECT_TRUE(srs_bytes_equals(a1, a1, 1));
EXPECT_TRUE(srs_bytes_equals(a1, a2, 1));
EXPECT_FALSE(srs_bytes_equals(a1, b2, 1));
}
... ...
... ... @@ -29,39 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_utest.hpp>
#include <srs_protocol_io.hpp>
#include <srs_protocol_rtmp.hpp>
#include <srs_protocol_handshake.hpp>
using namespace srs;
class MockEmptyIO : public ISrsProtocolReaderWriter
{
public:
MockEmptyIO();
virtual ~MockEmptyIO();
// for protocol
public:
virtual bool is_never_timeout(int64_t timeout_us);
// for handshake.
public:
virtual int read_fully(const void* buf, size_t size, ssize_t* nread);
virtual int write(const void* buf, size_t size, ssize_t* nwrite);
// for protocol
public:
virtual void set_recv_timeout(int64_t timeout_us);
virtual int64_t get_recv_timeout();
virtual int64_t get_recv_bytes();
virtual int get_recv_kbps();
// for protocol
public:
virtual void set_send_timeout(int64_t timeout_us);
virtual int64_t get_send_timeout();
virtual int64_t get_send_bytes();
virtual int get_send_kbps();
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
// for protocol/amf0/msg-codec
public:
virtual int read(const void* buf, size_t size, ssize_t* nread);
};
#endif
... ...