Home > Software engineering >  MFC using openssl ssl_accept return 1
MFC using openssl ssl_accept return 1

Time:10-14

In win32 console operation no problem, I according to the original directly copied, modified the variable to be modified, above all run to come over, but the ssl_accept return 1 trouble great god help have a look, if use must pay attention to the time between the MFC and the win32 what, whether to add something, code directly copied to the compiled win32 console operation no problem ~
Attach the code
SOCKADDR_IN serverin;//server information
SOCKADDR_IN clientin;//client information
Int len=sizeof (clientin);
The SOCKET m_socket_server;//the server socket
The SOCKET m_socket_Client;//client socket
Int err;//return error message

SSL * SSLS;
An SSL_CTX * CTXS;
SSL_METHOD * meths;

OpenSSL_add_ssl_algorithms ();//initialize the SSL
OpenSSL_add_all_algorithms ();//initialize all algorithm
SSL_load_error_strings ();//SSL initialization error information

//create the protocol used by the
Meths=(SSL_METHOD *) TLSv1_server_method ();
Apply for SSL session//
CTXS=SSL_CTX_new (meths);
If (CTXS==NULL)
{
return false;
}
//set the handshake session and load the Ca certificate
SSL_CTX_set_verify (CTXS, SSL_VERIFY_PEER, NULL);//set the handshake
SSL_CTX_load_verify_locations (CTXS, VERIFYCA, NULL);

//load the certificate to use
//the server certificate
If (SSL_CTX_use_certificate_file (CTXS, VERIFYSERVER SSL_FILETYPE_PEM) & lt; 0)
{
return false;
}
//the server key
If (SSL_CTX_use_PrivateKey_file (CTXS, VERIFYSERVERKEY SSL_FILETYPE_PEM) & lt; 0)
{
return false;
}
//inspection certificate and the secret key matches the
if (! SSL_CTX_check_private_key (CTXS))
{
return false;
}

//set the encryption mode
If (SSL_CTX_set_cipher_list (CTXS, "RC5 - MD5") & lt; 0)
{
return false;
}

//handle many handshakes
SSL_CTX_set_mode (CTXS, SSL_MODE_AUTO_RETRY);

USES_CONVERSION;
//create a socket
M_socket_server=: : WSASocket (AF_INET, SOCK_STREAM, 0, NULL, 0, NULL);
If (m_socket_server==INVALID_SOCKET)
{
TRACE (" Create Socket fail, Code: % s \ r \ n ", GetLastError ());
return false;
}
Serverin. Sin_addr. S_un. S_addr=htonl (INADDR_ANY);
Serverin. Sin_family=AF_INET;
Serverin. Sin_port=htons (8866);
//bind
Err=: : bind (m_socket_server, (SOCKADDR *) & amp; Serverin, sizeof (serverin));
If (err<0)
{
return false;
}
//listen
Err=: : listen (m_socket_server, 5);
If (err<0)
{
return false;
}
M_socket_Client=: : accept (m_socket_server, (SOCKADDR *) & amp; Clientin, & amp; Len);
If (m_socket_Client==INVALID_SOCKET)
{
Return FALSE;
}
Closesocket (m_socket_server);//remove the socket, use a new socket
//bind socket
SSLS=SSL_new (CTXS);
If (SSLS==NULL)
{
return false;
}
//apply for a SSL socket connection
Err=SSL_set_fd (SSLS m_socket_Client);
If (err<0)
{
return false;
}
//SSL handshake
Err=SSL_accept (SSLS);///is here, return 1 ported to run the console, there is no any problem
If (err<0)
{
Int ret=SSL_get_error (SSLS, 1);
TRACE (" error code: % s \ r \ n ", SSL_state_string_long (SSLS));
return false;
}
The following code is not offered, because here is wrong!!!!!!

CodePudding user response:

Their top once, trouble don't sink ah, the great god, help me have a look at, thank you!

CodePudding user response:

Reply, ssl_accept return 1 here I use TRACE (error code: "" % s \ r \ n", SSL_state_string_long (SSL)); Get the error code: SSLv3 read client hello C what reason is this excuse me?

CodePudding user response:

Have you solved? Also encountered similar problems,

CodePudding user response:

You this is a certificate error, the client can not use the certificate file
  • Related