@@ -820,33 +820,43 @@ nc_sshcb_auth_password(struct nc_session *session, ssh_message msg)
820820static void
821821nc_sshcb_auth_kbdint (struct nc_session * session , ssh_message msg )
822822{
823+ int auth_ret = 1 ;
823824 char * pass_hash ;
824-
825+ // Print message for interactive SSH
825826 if (!ssh_message_auth_kbdint_is_response (msg )) {
826827 const char * prompts [] = {"Password: " };
827828 char echo [] = {0 };
828829
829830 ssh_message_auth_interactive_request (msg , "Interactive SSH Authentication" , "Type your password:" , 1 , prompts , echo );
830831 } else {
831- if (ssh_userauth_kbdint_getnanswers (session -> ti .libssh .session ) != 1 ) {
832+ if (ssh_userauth_kbdint_getnanswers (session -> ti .libssh .session ) != 1 ) {// failed session
832833 ssh_message_reply_default (msg );
833- return ;
834+ return auth_ret ;
834835 }
835- pass_hash = auth_password_get_pwd_hash ( session -> username );
836- if (! pass_hash ) {
837- ssh_message_reply_default ( msg );
838- return ;
836+ // Check the authentication type
837+ if (server_opts . interactive_auth_clb )
838+ {
839+ auth_ret = server_opts . interactive_auth_clb ( session , ssh_message_auth_password ( msg ), server_opts . interactive_auth_clb );
839840 }
840- if (!auth_password_compare_pwd (pass_hash , ssh_userauth_kbdint_getanswer (session -> ti .libssh .session , 0 ))) {
841- VRB ("User \"%s\" authenticated." , session -> username );
841+ else {
842+ pass_hash = auth_password_get_pwd_hash (session -> username );// get hashed password
843+ if (pass_hash ) {
844+ auth_ret = auth_password_compare_pwd (pass_hash , ssh_userauth_kbdint_getanswer (session -> ti .libssh .session , 0 ));
845+ free (pass_hash );// free hashed password
846+ }
847+ }
848+ // Authenticate message based on outcome
849+ if (!auth_ret )
850+ {
842851 session -> flags |= NC_SESSION_SSH_AUTHENTICATED ;
852+ VRB ("User \"%s\" authenticated." , session -> username );
843853 ssh_message_auth_reply_success (msg , 0 );
844- } else {
854+ }
855+ else {
845856 ++ session -> opts .server .ssh_auth_attempts ;
846857 VRB ("Failed user \"%s\" authentication attempt (#%d)." , session -> username , session -> opts .server .ssh_auth_attempts );
847858 ssh_message_reply_default (msg );
848859 }
849- free (pass_hash );
850860 }
851861}
852862
@@ -909,12 +919,19 @@ nc_sshcb_auth_pubkey(struct nc_session *session, ssh_message msg)
909919 const char * username ;
910920 int signature_state ;
911921
912- if ((username = auth_pubkey_compare_key (ssh_message_auth_pubkey (msg ))) == NULL ) {
913- VRB ("User \"%s\" tried to use an unknown (unauthorized) public key." , session -> username );
914- goto fail ;
915- } else if (strcmp (session -> username , username )) {
916- VRB ("User \"%s\" is not the username identified with the presented public key." , session -> username );
917- goto fail ;
922+ if (server_opts .pubkey_auth_clb ){
923+ if (server_opts .pubkey_auth_clb (session , ssh_message_auth_pubkey (msg ), server_opts .pubkey_auth_data )){
924+ goto fail ;
925+ }
926+ }
927+ else {
928+ if ((username = auth_pubkey_compare_key (ssh_message_auth_pubkey (msg ))) == NULL ) {
929+ VRB ("User \"%s\" tried to use an unknown (unauthorized) public key." , session -> username );
930+ goto fail ;
931+ } else if (strcmp (session -> username , username )) {
932+ VRB ("User \"%s\" is not the username identified with the presented public key." , session -> username );
933+ goto fail ;
934+ }
918935 }
919936
920937 signature_state = ssh_message_auth_publickey_state (msg );
0 commit comments