Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arm64 openssl programm is blocking when i call SSL_connect #9641

Closed
andermirik opened this issue Aug 19, 2019 · 3 comments
Closed

arm64 openssl programm is blocking when i call SSL_connect #9641

andermirik opened this issue Aug 19, 2019 · 3 comments
Labels
triaged: question The issue contains a question

Comments

@andermirik
Copy link

snapdragon 636
strace http://prntscr.com/ouujos

it runs perfectly by windows. but on my linux(Termux) arm64 snapdragon 636 its blocking when i call SSL_connect.

headers

#include <openssl/ssl.h>
#include <openssl/err.h>

#ifndef _WIN32
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h> 
#include <unistd.h>
#else
#include "winsock2.h"
#include "windows.h"
#include "ws2tcpip.h"
#pragma comment(lib, "ws2_32.lib")
#pragma warning(disable:4996)
#endif

code

    Response sendHTTPS(Request& request) {
    #ifdef _WIN32
		WSADATA wsaData;
		WORD DllVersion = MAKEWORD(2, 2);
		if (WSAStartup(DllVersion, &wsaData)) {
			return Response();
		}
    #endif 
		std::string req = request.to_string();
		addrinfo* pAddrInfo;
		getaddrinfo(request.uri.host.c_str(), "443", 0, &pAddrInfo);

		SOCKET connection = socket(
			pAddrInfo->ai_family,
			pAddrInfo->ai_socktype,
			pAddrInfo->ai_protocol
		);
		if (!connection)
			return Response();

		int error = connect(connection, pAddrInfo->ai_addr, pAddrInfo->ai_addrlen);
		if (error)
			return Response();

		SSL_library_init();
		SSLeay_add_ssl_algorithms();
		SSL_load_error_strings();
		
		SSL_CTX* ctx = SSL_CTX_new(TLS_method());

		SSL *ssl = SSL_new(ctx);
		if (!ssl)
			return Response();

		SSL_set_connect_state(ssl);
		SSL_set_tlsext_host_name(ssl, request.uri.host.c_str());

		int sock = SSL_get_fd(ssl);
		SSL_set_fd(ssl, connection);
               
                std::cout<<"trying to connect\n";
		error = SSL_connect(ssl); // здесь блокируется
		if (error <= 0) {
			/*int err;
			std::string what;
			while ((err = ERR_get_error())) {
				char *str = ERR_error_string(err, 0);
				if (!str)
					break;
				what.append(str);
				what.append("\n");
			}
			throw std::exception(what.c_str());*/
		}

		int len = SSL_write(ssl, req.c_str(), req.size());
		if (len <= 0)
			return Response();

		std::string result = "";
		char buffer[16384] = { 0 };//16 kib
		int bytes_recv = 0;

		do {
			bytes_recv = SSL_read(ssl, buffer, sizeof(buffer));
			if (bytes_recv > 0)
				result.append(buffer, bytes_recv);
		} while (bytes_recv > 0);

		closesocket(connection);
		SSL_shutdown(ssl);
		SSL_free(ssl);
		SSL_CTX_free(ctx);

		return Response(result);
}
@andermirik andermirik added the issue: bug report The issue was opened to report a bug label Aug 19, 2019
@nitinmaru
Copy link

facing same issue for working on LEX11 device (64bit ver) to connect using SSL_connect device getting core dump with following backtrace.

backtrace:
08-19 11:52:48.709 15242 15242 F DEBUG : #00 pc ***.apk (offset 0xddf000) (BN_CTX_end+28)
08-19 11:52:48.709 15242 15242 F DEBUG : #1 pc ***.apk (offset 0xddf000)
08-19 11:52:48.709 15242 15242 F DEBUG : #2 pc ***.apk (offset 0xddf000) (ECDH_compute_key+68)
08-19 11:52:48.709 15242 15242 F DEBUG : #3 pc ***.apk (offset 0xddf000) (ssl3_send_client_key_exchange+576)
08-19 11:52:48.709 15242 15242 F DEBUG : #4 pc ***.apk (offset 0xddf000) (ssl3_connect+1892)
08-19 11:52:48.709 15242 15242 F DEBUG : #5 pc ***.apk (offset 0xddf000) (SSL_connect+32)
08-19 11:52:48.709 15242 15242 F DEBUG : #6 pc ***.apk (offset 0xddf000) (ssl23_connect+1712)
08-19 11:52:48.709 15242 15242 F DEBUG : #7 pc ***.apk (offset 0xddf000) (SSL_connect+32)

@mattcaswell mattcaswell added triaged: question The issue contains a question and removed issue: bug report The issue was opened to report a bug labels Nov 26, 2019
@mattcaswell
Copy link
Member

Is this still an issue?

What version of OpenSSL are you using?

@andermirik
Copy link
Author

Is this still an issue?

What version of OpenSSL are you using?

All is ok. Sorry :c

SOCKET connection = socket(
pAddrInfo->ai_family, //AF_INET
pAddrInfo->ai_socktype, //SOCK_STREAM
pAddrInfo->ai_protocol //IPPROTO_TCP
);

I have to replace these parameters with constants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged: question The issue contains a question
Projects
None yet
Development

No branches or pull requests

3 participants