|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-01-20 15:32 UTC] rebe at unit01 dot net
Description:
------------
Ftp ssl/tls connection fails after login function. I checked on ftp client program supporting ssl (lftp) and everything works fine there. Server is linux Proftpd 1.3.0
Reproduce code:
---------------
$conn_id = ftp_ssl_connect('192.168.10.120');
$lr = ftp_login($conn_id,'login','pass');
if ($lr) {
echo ftp_pwd($conn_id)."\n";
} else {
echo "login failed\n";
}
ftp_close($conn_id);
Expected result:
----------------
/
Actual result:
--------------
Warning: ftp_login(): SSL/TLS handshake failed in /test.php on line 8
Warning: ftp_login(): AUTH TLS successful in /test.php on line 8
login failed
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 20:00:01 2025 UTC |
OK here's what we figured out with a friend of mine. Login function in ext/ftp.c treat all errors (also "want_more..." ) as login fail but it is not true. A patch below is fixing problem and makes everything working fine: @@ -243,6 +243,7 @@ { #if HAVE_OPENSSL_EXT SSL_CTX *ctx = NULL; + int err,errs; #endif if (ftp == NULL) { return 0; @@ -291,13 +292,24 @@ } SSL_set_fd(ftp->ssl_handle, ftp->fd); - +/* if (SSL_connect(ftp->ssl_handle) <= 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS handshake failed"); SSL_shutdown(ftp->ssl_handle); return 0; } - +*/ +err=SSL_connect(ftp->ssl_handle); +while (err <= 0) { + errs = SSL_get_error(ftp->fd, err); + if ((errs != SSL_ERROR_WANT_READ) && (errs != SSL_ERROR_WANT_WRITE) && (errs != SSL_ERROR_WANT_X509_LOOKUP)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS handshake failed"); + SSL_shutdown(ftp->ssl_handle); + return 0; + } + err = SSL_connect(ftp->ssl_handle); +} +Frankly - your patch is doing 99% percent the same thing but is not fixing problem :) I checked that twice cause I didn't believe it but still getting "handshake failed". The only difference I see is : }while(errcode == 0 && !SSL_is_init_finished(ftp-ssl_handle)); ^^^^^^^^^^^^^^ we didn't use that in our fix.we still have this issue on windows php build 5.3.19 and 5.4.9 so we implemented this patch which solve the issue. please see if you can add to future versions. diff -ruN php-5.3.19.orig/ext/ftp/ftp.c php-5.3.19/ext/ftp/ftp.c --- php-5.3.19.orig/ext/ftp/ftp.c 2012-11-21 22:07:23.000000000 +0200 +++ php-5.3.19/ext/ftp/ftp.c 2012-12-11 16:49:21.359682714 +0200 @@ -241,6 +241,7 @@ int ftp_login(ftpbuf_t *ftp, const char *user, const char *pass TSRMLS_DC) { + int errcode; #if HAVE_OPENSSL_EXT SSL_CTX *ctx = NULL; #endif @@ -289,13 +290,27 @@ } SSL_set_fd(ftp->ssl_handle, ftp->fd); - - if (SSL_connect(ftp->ssl_handle) <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS handshake failed"); - SSL_shutdown(ftp->ssl_handle); - return 0; - } - + + do { + errcode = SSL_connect(ftp->ssl_handle); + switch (SSL_get_error (ftp->ssl_handle, errcode)) { + case SSL_ERROR_NONE: + errcode = 1; + break; + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_X509_LOOKUP: + errcode = 0; + break; + default: + /* true error happened */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS handshake failed"); + SSL_shutdown(ftp->ssl_handle); + return 0; + break; + } + } while(errcode == 0 && !SSL_is_init_finished(ftp- >ssl_handle)); + ftp->ssl_active = 1; if (!ftp->old_ssl) { @@ -1493,6 +1508,7 @@ php_sockaddr_storage addr; socklen_t size; + int errcode; #if HAVE_OPENSSL_EXT SSL_CTX *ctx; #endif @@ -1537,11 +1553,26 @@ SSL_copy_session_id(data->ssl_handle, ftp->ssl_handle); } - if (SSL_connect(data->ssl_handle) <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_accept: SSL/TLS handshake failed"); - SSL_shutdown(data->ssl_handle); - return 0; - } + + do { + errcode = SSL_connect(data->ssl_handle); + switch (SSL_get_error (data->ssl_handle, errcode)) { + case SSL_ERROR_NONE: + errcode = 1; + break; + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_X509_LOOKUP: + errcode = 0; + break; + default: + /* true error happened */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_accept: SSL/TLS handshake failed"); + SSL_shutdown(data->ssl_handle); + return 0; + break; + } + } while(errcode == 0 && !SSL_is_init_finished(data- >ssl_handle)); data->ssl_active = 1; }