@ -200,7 +200,7 @@ static int SSHParserTest01(void)
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF_NULL ( tx ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) ! = SshState BannerDone ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) ! = SshState Kex ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOSERVER ) ) ;
FLOW_DESTROY ( & f ) ;
@ -244,7 +244,7 @@ static int SSHParserTest02(void)
}
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) ! = SshState BannerDone ) {
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) ! = SshState Kex ) {
printf ( " Client version string not parsed: " ) ;
goto end ;
}
@ -295,7 +295,7 @@ static int SSHParserTest03(void)
}
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) = = SshState BannerDone ) {
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) = = SshState Kex ) {
printf ( " Client version string parsed? It's not a valid string: " ) ;
goto end ;
}
@ -348,7 +348,7 @@ static int SSHParserTest04(void)
}
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) ! = SshState BannerDone ) {
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) ! = SshState Kex ) {
printf ( " Client version string not parsed: " ) ;
goto end ;
}
@ -399,7 +399,7 @@ static int SSHParserTest05(void)
}
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) ! = SshState BannerDone ) {
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) ! = SshState Kex ) {
printf ( " Client version string not parsed: " ) ;
goto end ;
}
@ -450,7 +450,7 @@ static int SSHParserTest06(void)
}
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) = = SshState BannerDone ) {
if ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) = = SshState Kex ) {
printf ( " Client version string parsed? It's not a valid string: " ) ;
goto end ;
}
@ -511,7 +511,7 @@ static int SSHParserTest07(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) ! = SshState BannerDone ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) ! = SshState Kex ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOSERVER ) ) ;
@ -562,7 +562,7 @@ static int SSHParserTest08(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) ! = SshState BannerDone ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) ! = SshState Kex ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOSERVER ) ) ;
@ -612,7 +612,7 @@ static int SSHParserTest09(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) ! = SshState BannerDone ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) ! = SshState Kex ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOCLIENT ) ) ;
@ -663,7 +663,7 @@ static int SSHParserTest10(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) ! = SshState BannerDone ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) ! = SshState Kex ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOCLIENT ) ) ;
@ -714,7 +714,7 @@ static int SSHParserTest11(void)
goto end ;
}
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
if ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Finished ) {
if ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Session ) {
printf ( " Didn't detect the msg code of new keys (ciphered data starts): " ) ;
goto end ;
}
@ -778,7 +778,7 @@ static int SSHParserTest12(void)
goto end ;
}
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
if ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Finished ) {
if ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Session ) {
printf ( " Didn't detect the msg code of new keys (ciphered data starts): " ) ;
goto end ;
}
@ -839,7 +839,7 @@ static int SSHParserTest13(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Session ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOSERVER ) ) ;
@ -898,7 +898,7 @@ static int SSHParserTest14(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Session ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOSERVER ) ) ;
@ -956,7 +956,7 @@ static int SSHParserTest15(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Session ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOSERVER ) ) ;
@ -1012,7 +1012,7 @@ static int SSHParserTest16(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Session ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOCLIENT ) ) ;
@ -1069,7 +1069,7 @@ static int SSHParserTest17(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Session ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " MySSHClient-0.5.1 " , tx , STREAM_TOCLIENT ) ) ;
@ -1136,7 +1136,7 @@ static int SSHParserTest18(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Session ) ;
FAIL_IF ( ! ( SCAppLayerParserStateIssetFlag ( f - > alparser , APP_LAYER_PARSER_NO_INSPECTION ) ) ) ;
@ -1202,7 +1202,7 @@ static int SSHParserTest19(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Session ) ;
sshbuf3 [ sizeof ( sshbuf3 ) - 2 ] = 0 ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , ( char * ) sshbuf3 , tx , STREAM_TOCLIENT ) ) ;
@ -1271,7 +1271,7 @@ static int SSHParserTest20(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Session ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , NULL , tx , STREAM_TOCLIENT ) ) ;
@ -1338,7 +1338,7 @@ static int SSHParserTest21(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Session ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , NULL , tx , STREAM_TOCLIENT ) ) ;
@ -1429,7 +1429,7 @@ static int SSHParserTest22(void)
void * ssh_state = f - > alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Finished ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOCLIENT ) ! = SshState Session ) ;
FAIL_IF ( SSHParserTestUtilCheck ( " 2.0 " , " libssh " , tx , STREAM_TOCLIENT ) ) ;
@ -1507,7 +1507,7 @@ static int SSHParserTest24(void)
goto end ;
}
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
if ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState BannerDone ) {
if ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) ! = SshState Kex ) {
printf ( " Didn't detect the msg code of new keys (ciphered data starts): " ) ;
goto end ;
}
@ -1549,7 +1549,7 @@ static int SSHParserTest25(void)
void * ssh_state = f . alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) = = SshState BannerDone ) ;
FAIL_IF ( SCSshTxGetFlags ( tx , STREAM_TOSERVER ) = = SshState Kex ) ;
const uint8_t * dummy = NULL ;
uint32_t dummy_len = 0 ;
FAIL_IF ( SCSshTxGetSoftware ( tx , STREAM_TOCLIENT , & dummy , & dummy_len ) ! = 0 ) ;
@ -1560,6 +1560,108 @@ static int SSHParserTest25(void)
PASS ;
}
/** \test State name table: new names, legacy aliases, the unhookable
* completion state and the id - to - name mapping . */
static int SSHParserTest26 ( void )
{
/* new names */
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " request_banner " , STREAM_TOSERVER ) ! = SshStateBanner ) ;
FAIL_IF ( AppLayerParserGetStateIdByName ( IPPROTO_TCP , ALPROTO_SSH , " request_banner_wait_eol " ,
STREAM_TOSERVER ) ! = SshStateBannerWaitEol ) ;
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " request_kex " , STREAM_TOSERVER ) ! = SshStateKex ) ;
FAIL_IF ( AppLayerParserGetStateIdByName ( IPPROTO_TCP , ALPROTO_SSH , " request_session " ,
STREAM_TOSERVER ) ! = SshStateSession ) ;
FAIL_IF ( AppLayerParserGetStateIdByName ( IPPROTO_TCP , ALPROTO_SSH , " response_banner " ,
STREAM_TOCLIENT ) ! = SshStateBanner ) ;
FAIL_IF ( AppLayerParserGetStateIdByName ( IPPROTO_TCP , ALPROTO_SSH , " response_session " ,
STREAM_TOCLIENT ) ! = SshStateSession ) ;
/* legacy names are rejected: no backward-compat aliases
* ( pre - production — breaking changes are allowed ) */
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " request_in_progress " , STREAM_TOSERVER ) ! = - 1 ) ;
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " request_banner_done " , STREAM_TOSERVER ) ! = - 1 ) ;
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " request_finished " , STREAM_TOSERVER ) ! = - 1 ) ;
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " response_finished " , STREAM_TOCLIENT ) ! = - 1 ) ;
/* the completion state is registered but not hookable */
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " request_done " , STREAM_TOSERVER ) ! = - 1 ) ;
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " response_done " , STREAM_TOCLIENT ) ! = - 1 ) ;
/* unknown name, and wrong direction prefix */
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " request_nosuchstate " , STREAM_TOSERVER ) ! = - 1 ) ;
FAIL_IF ( AppLayerParserGetStateIdByName (
IPPROTO_TCP , ALPROTO_SSH , " response_banner " , STREAM_TOSERVER ) ! = - 1 ) ;
/* id to name */
FAIL_IF ( strcmp ( AppLayerParserGetStateNameById (
IPPROTO_TCP , ALPROTO_SSH , SshStateBanner , STREAM_TOSERVER ) ,
" request_banner " ) ! = 0 ) ;
FAIL_IF ( strcmp ( AppLayerParserGetStateNameById (
IPPROTO_TCP , ALPROTO_SSH , SshStateKex , STREAM_TOSERVER ) ,
" request_kex " ) ! = 0 ) ;
FAIL_IF ( strcmp ( AppLayerParserGetStateNameById (
IPPROTO_TCP , ALPROTO_SSH , SshStateSession , STREAM_TOSERVER ) ,
" request_session " ) ! = 0 ) ;
/* the completion state is out of the id-to-name table: the hook
* listing and the policy key walk must not offer it */
FAIL_IF ( AppLayerParserGetStateNameById (
IPPROTO_TCP , ALPROTO_SSH , SshStateDone , STREAM_TOSERVER ) ! = NULL ) ;
FAIL_IF ( AppLayerParserGetStateNameById (
IPPROTO_TCP , ALPROTO_SSH , SshStateDone , STREAM_TOCLIENT ) ! = NULL ) ;
FAIL_IF ( AppLayerParserGetStateNameById ( IPPROTO_TCP , ALPROTO_SSH , 9 , STREAM_TOSERVER ) ! = NULL ) ;
PASS ;
}
/** \test Per-direction session state: the toserver direction reports
* session after its own NewKeys while the toclient direction has not
* seen anything yet . */
static int SSHParserTest27 ( void )
{
Flow f ;
uint8_t sshbuf1 [ ] = " SSH-2.0-MySSHClient-0.5.1 \r \n " ;
uint32_t sshlen1 = sizeof ( sshbuf1 ) - 1 ;
uint8_t sshbuf2 [ ] = { 0x00 , 0x00 , 0x00 , 0x03 , 0x01 , 21 , 0x00 } ;
uint32_t sshlen2 = sizeof ( sshbuf2 ) ;
TcpSession ssn ;
AppLayerParserThreadCtx * alp_tctx = AppLayerParserThreadCtxAlloc ( ) ;
FAIL_IF_NULL ( alp_tctx ) ;
memset ( & f , 0 , sizeof ( f ) ) ;
memset ( & ssn , 0 , sizeof ( ssn ) ) ;
FLOW_INITIALIZE ( & f ) ;
f . protoctx = ( void * ) & ssn ;
f . proto = IPPROTO_TCP ;
f . alproto = ALPROTO_SSH ;
StreamTcpInitConfig ( true ) ;
int r = AppLayerParserParse ( NULL , alp_tctx , & f , ALPROTO_SSH , STREAM_TOSERVER , sshbuf1 , sshlen1 ) ;
FAIL_IF ( r ! = 0 ) ;
r = AppLayerParserParse ( NULL , alp_tctx , & f , ALPROTO_SSH , STREAM_TOSERVER , sshbuf2 , sshlen2 ) ;
FAIL_IF ( r ! = 0 ) ;
void * ssh_state = f . alstate ;
FAIL_IF_NULL ( ssh_state ) ;
void * tx = SCSshStateGetTx ( ssh_state , 0 ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOSERVER ) ! = SshStateSession ) ;
FAIL_IF ( SCSshTxGetAlStateProgress ( tx , STREAM_TOCLIENT ) ! = SshStateBanner ) ;
FLOW_DESTROY ( & f ) ;
AppLayerParserThreadCtxFree ( alp_tctx ) ;
StreamTcpFreeConfig ( true ) ;
PASS ;
}
# endif /* UNITTESTS */
void SSHParserRegisterTests ( void )
@ -1590,6 +1692,8 @@ void SSHParserRegisterTests(void)
UtRegisterTest ( " SSHParserTest23 " , SSHParserTest23 ) ;
UtRegisterTest ( " SSHParserTest24 " , SSHParserTest24 ) ;
UtRegisterTest ( " SSHParserTest25 " , SSHParserTest25 ) ;
UtRegisterTest ( " SSHParserTest26 - State name table " , SSHParserTest26 ) ;
UtRegisterTest ( " SSHParserTest27 - Per-direction session state " , SSHParserTest27 ) ;
# endif /* UNITTESTS */
}