|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-04-18 06:27 UTC] a dot guptagoa at gmail dot com
Description: ------------ keyboard_interactive auth not supported. The below patch will fix the issues on FreeBSD as well (Bug #54916). /* Uses the function libssh2_userauth_list to fetch auth modes and if keyboard_interactive is found uses libssh2_userauth_keyboard_interactive method to fill in the response text. Changed function PHP_FUNCTION(ssh2_auth_password).*/ char *password_key = "gbVer4TG"; char *userauthlist; static void kbd_callback(const char *name, int name_len, const char *instruction, int instruction_len, int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, void **abstract) { responses[0].text = password_key; responses[0].length = strlen(password_key); } PHP_FUNCTION(ssh2_auth_password) { LIBSSH2_SESSION *session; zval *zsession; char *username, *password; int username_len, password_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &zsession, &username, &username_len, &password, &password_len) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(session, LIBSSH2_SESSION*, &zsession, -1, PHP_SSH2_SESSION_RES_NAME, le_ssh2_session); userauthlist = libssh2_userauth_list(session, username, username_len); /* TODO: Support password change callback */ password_key = password; if (strstr(userauthlist, "keyboard-interactive") != NULL) { if (libssh2_userauth_keyboard_interactive(session, username, &kbd_callback) == 0) { RETURN_TRUE; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Authentication failed for %s using password", username); RETURN_FALSE; } } else { if (libssh2_userauth_password_ex(session, username, username_len, password_key, strlen(password_key), NULL)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Authentication failed for %s using password", username); RETURN_FALSE; } } RETURN_TRUE; } /* After applying this patch all the SSH auth modes are now supported by the library*/ Test Script remains the same as below. Test script: --------------- <?php /* The SSh server must have keyboard_interactive login only. To check the existing auth types we can use ssh2_auth_none which returns an array of auth types. Without the patch the ssh2_auth_password will return failure*/ function connect() { $host = "192.168.169.100"; //to be replaced with test ip $port = "22"; $username = "username"; $password = "password"; $this->connection = @ssh2_connect($host, $port); if ($this->connection or die("Undefined Host $host")) { if (!@ssh2_auth_password($this->connection, $username, $password)) { $auth_methods = ssh2_auth_none($this->connection, $username); print_r($auth_methods); echo "Auth Failed"; return 0; } else { echo "Auth Suucess"; return 1; } } else { echo "Could not connect to $host on port $port."; return 0; } } Expected result: ---------------- Auth Success Actual result: -------------- Auth failed Patcheskeyboard_interactive_method (last revision 2012-06-14 15:38 UTC by langemeijer@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 03:00:01 2025 UTC |
Hi, The following call to the LIBSSH2 API:- libssh2_userauth_keyboard_interactive(session, username, &kbd_callback) and kbd_callback static void kbd_callback(const char *name, int name_len, const char *instruction, int instruction_len, int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, void **abstract) will take care of the Keyboard authentication. The Purpose of the patch was to authenticate such connection without the user being bothered to know what mode does SSH2 server supports. The pathch checks whether keyboard_authentication is available in the negotiation list and utilize the LIBSSH2 APIs. Regards