@@ -598,34 +598,43 @@ static void HandshakeInfoFree(HandshakeInfo* hs, void* heap)
598598#ifndef NO_WOLFSSH_SERVER
599599INLINE static int IsMessageAllowedServer(WOLFSSH *ssh, byte msg)
600600{
601+ /* Transport Layer Generic messages are always allowed. */
602+ if (MSGIDLIMIT_TRANS_GEN(msg)) {
603+ return 1;
604+ }
605+
601606 /* Has client userauth started? */
607+ /* Allows the server to receive up to KEXDH GEX Request during KEX. */
602608 if (ssh->acceptState < ACCEPT_KEYED) {
603- if (msg > MSGID_KEXDH_LIMIT ) {
609+ if (msg > MSGID_KEXDH_GEX_REQUEST ) {
604610 return 0;
605611 }
606612 }
607613 /* Is server userauth complete? */
608614 if (ssh->acceptState < ACCEPT_SERVER_USERAUTH_SENT) {
615+ /* The server should only receive the user auth request message,
616+ * it should not accept the other user auth messages, it sends
617+ * them. (>50) */
609618 /* Explicitly check for messages not allowed before user
610619 * authentication has comleted. */
611- if (msg >= MSGID_USERAUTH_LIMIT ) {
612- WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by server "
613- " before user authentication is complete", msg );
620+ if (MSGIDLIMIT_POST_USERAUTH( msg) ) {
621+ WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
622+ msg, "server", " before user authentication is complete");
614623 return 0;
615624 }
616625 /* Explicitly check for the user authentication messages that
617626 * only the server sends, it shouldn't receive them. */
618- if ((msg > MSGID_USERAUTH_RESTRICT ) &&
627+ if ((msg > MSGID_USERAUTH_REQUEST ) &&
619628 (msg != MSGID_USERAUTH_INFO_RESPONSE)) {
620- WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by server "
621- " during user authentication", msg );
629+ WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
630+ msg, "server", " during user authentication");
622631 return 0;
623632 }
624633 }
625634 else {
626- if (msg >= MSGID_USERAUTH_RESTRICT && msg < MSGID_USERAUTH_LIMIT ) {
627- WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by server "
628- " after user authentication", msg );
635+ if (msg >= MSGID_USERAUTH_REQUEST && msg < MSGID_GLOBAL_REQUEST ) {
636+ WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
637+ msg, "server", " after user authentication");
629638 return 0;
630639 }
631640 }
@@ -638,6 +647,19 @@ INLINE static int IsMessageAllowedServer(WOLFSSH *ssh, byte msg)
638647#ifndef NO_WOLFSSH_CLIENT
639648INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
640649{
650+ /* Transport Layer Generic messages are always allowed. */
651+ if (MSGIDLIMIT_TRANS_GEN(msg)) {
652+ return 1;
653+ }
654+
655+ /* The client should only send the user auth request message
656+ * (50), it should not accept it. The server should only receive
657+ * the user auth request message, it should not accept the other
658+ * user auth messages, it sends them. (>50) */
659+ if (msg == MSGID_USERAUTH_REQUEST) {
660+ return 0;
661+ }
662+
641663 /* Is KEX complete? */
642664 if (ssh->connectState < CONNECT_KEYED && ssh->handshake) {
643665 /* If expecting a specific message, and didn't receive it, error. */
@@ -648,35 +670,37 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
648670 return 0;
649671 }
650672 ssh->handshake->expectMsgId = MSGID_NONE;
673+ return 1;
651674 }
652675 }
653676 /* Has client userauth started? */
654677 if (ssh->connectState < CONNECT_CLIENT_KEXDH_INIT_SENT) {
655- if (msg >= MSGID_KEXDH_LIMIT ) {
678+ if (msg >= MSGID_KEXDH_GEX_REQUEST ) {
656679 return 0;
657680 }
658681 }
659682 /* Is client userauth complete? */
660683 if (ssh->connectState < CONNECT_SERVER_USERAUTH_ACCEPT_DONE) {
661- /* Explicitly check for messages not allowed before user
662- * authentication has comleted. */
663- if (msg >= MSGID_USERAUTH_LIMIT) {
664- WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by client "
665- "before user authentication is complete", msg);
684+ /* The endpoints should not allow message IDs greater than or
685+ * equal to msgid 80 before user authentication is complete.
686+ * Per RFC 4252 section 6. */
687+ if (MSGIDLIMIT_POST_USERAUTH(msg)) {
688+ WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
689+ msg, "client", "before user authentication is complete");
666690 return 0;
667691 }
668- /* Explicitly check for the user authentication message that
669- * only the client sends, it shouldn't receive it. */
670- if (msg == MSGID_USERAUTH_RESTRICT ) {
671- WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by client "
672- " during user authentication", msg );
692+ /* Explicitly check for the user authentication request message.
693+ * The client only sends the message , it shouldn't receive it. */
694+ if (msg == MSGID_USERAUTH_REQUEST ) {
695+ WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
696+ msg, "client", " during user authentication");
673697 return 0;
674698 }
675699 }
676700 else {
677- if (msg >= MSGID_USERAUTH_RESTRICT && msg < MSGID_USERAUTH_LIMIT ) {
678- WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by client "
679- " after user authentication", msg );
701+ if (MSGIDLIMIT_AUTH( msg) ) {
702+ WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
703+ msg, "client", " after user authentication");
680704 return 0;
681705 }
682706 }
0 commit comments