@@ -450,6 +450,9 @@ const char* GetErrorString(int err)
450450 case WS_ED25519_E :
451451 return "Ed25519 buffer error" ;
452452
453+ case WS_AUTH_PENDING :
454+ return "userauth is still pending (callback would block)" ;
455+
453456 default :
454457 return "Unknown error code" ;
455458 }
@@ -6111,6 +6114,10 @@ static int DoUserAuthRequestNone(WOLFSSH* ssh, WS_UserAuthData* authData,
61116114 ret = WS_USER_AUTH_E ;
61126115 #endif
61136116 }
6117+ else if (ret == WOLFSSH_USERAUTH_WOULD_BLOCK ) {
6118+ WLOG (WS_LOG_DEBUG , "DUARN: userauth callback would block" );
6119+ ret = WS_AUTH_PENDING ;
6120+ }
61146121 else {
61156122 WLOG (WS_LOG_DEBUG , "DUARN: none check failed, retry" );
61166123 ret = SendUserAuthFailure (ssh , 0 );
@@ -6196,6 +6203,10 @@ static int DoUserAuthRequestPassword(WOLFSSH* ssh, WS_UserAuthData* authData,
61966203 #endif
61976204 ret = WS_USER_AUTH_E ;
61986205 }
6206+ else if (ret == WOLFSSH_USERAUTH_WOULD_BLOCK ) {
6207+ WLOG (WS_LOG_DEBUG , "DUARPW: userauth callback would block" );
6208+ ret = WS_AUTH_PENDING ;
6209+ }
61996210 else {
62006211 WLOG (WS_LOG_DEBUG , "DUARPW: password check failed, retry" );
62016212 authFailure = 1 ;
@@ -6214,7 +6225,7 @@ static int DoUserAuthRequestPassword(WOLFSSH* ssh, WS_UserAuthData* authData,
62146225 if (authFailure || partialSuccess ) {
62156226 ret = SendUserAuthFailure (ssh , partialSuccess );
62166227 }
6217- else {
6228+ else if ( ret == WS_SUCCESS ) {
62186229 ssh -> clientState = CLIENT_USERAUTH_DONE ;
62196230 }
62206231
@@ -7102,6 +7113,7 @@ static int DoUserAuthRequestPublicKey(WOLFSSH* ssh, WS_UserAuthData* authData,
71027113 ret = ssh -> ctx -> userAuthCb (WOLFSSH_USERAUTH_PUBLICKEY ,
71037114 authData , ssh -> userAuthCtx );
71047115 WLOG (WS_LOG_DEBUG , "DUARPK: callback result = %d" , ret );
7116+
71057117 #ifdef DEBUG_WOLFSSH
71067118 switch (ret ) {
71077119 case WOLFSSH_USERAUTH_SUCCESS :
@@ -7131,20 +7143,29 @@ static int DoUserAuthRequestPublicKey(WOLFSSH* ssh, WS_UserAuthData* authData,
71317143 case WOLFSSH_USERAUTH_PARTIAL_SUCCESS :
71327144 WLOG (WS_LOG_DEBUG , "DUARPK: user auth partial success" );
71337145 break ;
7146+
7147+ case WOLFSSH_USERAUTH_WOULD_BLOCK :
7148+ WLOG (WS_LOG_DEBUG , "DUARPK: userauth callback would block" );
7149+ break ;
71347150
71357151 default :
71367152 WLOG (WS_LOG_DEBUG ,
71377153 "Unexpected return value from Auth callback" );
71387154 }
71397155 #endif
71407156
7141- if (ret == WOLFSSH_USERAUTH_PARTIAL_SUCCESS ) {
7142- partialSuccess = 1 ;
7157+ if (ret == WOLFSSH_USERAUTH_WOULD_BLOCK ) {
7158+ ret = WS_AUTH_PENDING ;
71437159 }
7144- else if (ret != WOLFSSH_USERAUTH_SUCCESS ) {
7145- authFailure = 1 ;
7160+ else {
7161+ if (ret == WOLFSSH_USERAUTH_PARTIAL_SUCCESS ) {
7162+ partialSuccess = 1 ;
7163+ }
7164+ else if (ret != WOLFSSH_USERAUTH_SUCCESS ) {
7165+ authFailure = 1 ;
7166+ }
7167+ ret = WS_SUCCESS ;
71467168 }
7147- ret = WS_SUCCESS ;
71487169 }
71497170 else {
71507171 WLOG (WS_LOG_DEBUG , "DUARPK: no userauth callback set" );
@@ -8843,18 +8864,21 @@ static int DoPacket(WOLFSSH* ssh, byte* bufferConsumed)
88438864 ret = SendUnimplemented (ssh );
88448865 }
88458866
8846- if (payloadSz > 0 ) {
8847- idx += payloadIdx ;
8848- if (idx + padSz > len ) {
8849- WLOG (WS_LOG_DEBUG , "Not enough data in buffer for pad." );
8850- ret = WS_BUFFER_E ;
8867+ /* if the auth is still pending, don't discard the packet data */
8868+ if (ret != WS_AUTH_PENDING ) {
8869+ if (payloadSz > 0 ) {
8870+ idx += payloadIdx ;
8871+ if (idx + padSz > len ) {
8872+ WLOG (WS_LOG_DEBUG , "Not enough data in buffer for pad." );
8873+ ret = WS_BUFFER_E ;
8874+ }
88518875 }
8852- }
88538876
8854- idx += padSz ;
8855- ssh -> inputBuffer .idx = idx ;
8856- ssh -> peerSeq ++ ;
8857- * bufferConsumed = 1 ;
8877+ idx += padSz ;
8878+ ssh -> inputBuffer .idx = idx ;
8879+ ssh -> peerSeq ++ ;
8880+ * bufferConsumed = 1 ;
8881+ }
88588882
88598883 return ret ;
88608884}
0 commit comments