@@ -62,8 +62,21 @@ static struct {
6262} server ;
6363
6464/* External functions from wolfssh_io.c */
65+ extern void wolfSSH_CTX_SetIO_wolfIP (WOLFSSH_CTX * ctx );
6566extern int wolfSSH_SetIO_wolfIP (WOLFSSH * ssh , struct wolfIP * stack , int fd );
6667
68+ #ifdef DEBUG_WOLFSSH
69+ /* wolfSSH logging callback */
70+ static void ssh_log_cb (enum wolfSSH_LogLevel level , const char * msg )
71+ {
72+ (void )level ;
73+ if (server .debug_cb && msg ) {
74+ server .debug_cb (msg );
75+ server .debug_cb ("\n" );
76+ }
77+ }
78+ #endif
79+
6780/* Debug output helper */
6881static void debug_print (const char * msg )
6982{
@@ -82,16 +95,16 @@ static int ssh_userauth_cb(byte authType, WS_UserAuthData *authData, void *ctx)
8295 }
8396
8497 /* Check username */
85- if (authData -> usernameLen != strlen (SSH_USERNAME ) ||
86- memcmp (authData -> username , SSH_USERNAME , authData -> usernameLen ) != 0 ) {
98+ if (authData -> usernameSz != strlen (SSH_USERNAME ) ||
99+ memcmp (authData -> username , SSH_USERNAME , authData -> usernameSz ) != 0 ) {
87100 debug_print ("SSH: Invalid username\n" );
88101 return WOLFSSH_USERAUTH_INVALID_USER ;
89102 }
90103
91104 /* Check password */
92- if (authData -> sf .password .passwordLen != strlen (SSH_PASSWORD ) ||
105+ if (authData -> sf .password .passwordSz != strlen (SSH_PASSWORD ) ||
93106 memcmp (authData -> sf .password .password , SSH_PASSWORD ,
94- authData -> sf .password .passwordLen ) != 0 ) {
107+ authData -> sf .password .passwordSz ) != 0 ) {
95108 debug_print ("SSH: Invalid password\n" );
96109 return WOLFSSH_USERAUTH_INVALID_PASSWORD ;
97110 }
@@ -212,13 +225,22 @@ int ssh_server_init(struct wolfIP *stack, uint16_t port, ssh_debug_cb debug)
212225 return -1 ;
213226 }
214227
228+ #ifdef DEBUG_WOLFSSH
229+ /* Enable wolfSSH debug logging */
230+ wolfSSH_Debugging_ON ();
231+ wolfSSH_SetLoggingCb (ssh_log_cb );
232+ #endif
233+
215234 /* Create SSH server context */
216235 server .ctx = wolfSSH_CTX_new (WOLFSSH_ENDPOINT_SERVER , NULL );
217236 if (server .ctx == NULL ) {
218237 debug_print ("SSH: CTX_new failed\n" );
219238 return -1 ;
220239 }
221240
241+ /* Set I/O callbacks on context */
242+ wolfSSH_CTX_SetIO_wolfIP (server .ctx );
243+
222244 /* Set user authentication callback */
223245 wolfSSH_SetUserAuth (server .ctx , ssh_userauth_cb );
224246
@@ -235,7 +257,6 @@ int ssh_server_init(struct wolfIP *stack, uint16_t port, ssh_debug_cb debug)
235257 }
236258
237259 /* Create listen socket */
238- debug_print ("SSH: Creating listen socket\n" );
239260 server .listen_fd = wolfIP_sock_socket (stack , AF_INET , IPSTACK_SOCK_STREAM , 0 );
240261 if (server .listen_fd < 0 ) {
241262 debug_print ("SSH: socket() failed\n" );
0 commit comments