Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-03-19 23:34:50 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a470330383d8ec17f44fd667865fb63a003a7f14
a4703303
1 parent
6b84a5e1
finish utest for handshake.
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
157 行增加
和
105 行删除
trunk/src/rtmp/srs_protocol_handshake.cpp
trunk/src/utest/srs_utest.cpp
trunk/src/utest/srs_utest.hpp
trunk/src/utest/srs_utest_handshake.cpp
trunk/src/utest/srs_utest_handshake.hpp
trunk/src/rtmp/srs_protocol_handshake.cpp
查看文件 @
a470330
...
...
@@ -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
;
...
...
trunk/src/utest/srs_utest.cpp
查看文件 @
a470330
...
...
@@ -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
)
{
...
...
trunk/src/utest/srs_utest.hpp
查看文件 @
a470330
...
...
@@ -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
...
...
trunk/src/utest/srs_utest_handshake.cpp
查看文件 @
a470330
...
...
@@ -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
));
}
...
...
trunk/src/utest/srs_utest_handshake.hpp
查看文件 @
a470330
...
...
@@ -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
...
...
请
注册
或
登录
后发表评论