Bonjour,

Je dois me connecter à un serveur distant à partir d'un application écrite en C++.
Après de multiples recherches j'ai compris que je dois utiliser OpenSSL, mais je n'ai pas trouvé une documentation détaillé sur ce sujet !
Voila le bout de code que j'ai écrit:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
    WSADATA WSAData;
    int erreur = WSAStartup(MAKEWORD(2,2), &WSAData);
    long rc;
    SOCKET socket1 = NULL;
    SOCKET sock;
    SOCKADDR_IN sin;
    int err;
 
     rc=startWinsock();
     if(rc!=0)
	{
		printf("Fehler: startWinsock, fehler code: %d\n",rc);
	}
	else
	{
		printf("Winsock gestartet!\n");
	}
 
        /* Création de la socket */
        sock = socket(AF_INET, SOCK_STREAM, 0);
	if(sock==INVALID_SOCKET)
	{
		printf("Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\n",WSAGetLastError());
	}
	else
	{
		printf("Socket erstellt!\n");
	}
	/* Configuration de la connexion */
        sin.sin_addr.s_addr = inet_addr("localhost");
        sin.sin_family = AF_INET;
        sin.sin_port = htons(PORT);
 
        /* Si le client arrive à se connecter */
	if(connect(sock, (SOCKADDR*)&sin, sizeof(sin)) != SOCKET_ERROR)
            printf("Connexion à %s sur le port %d\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
        else
            printf("Impossible de se connecter\n");
 
	rc=bind(sock, (SOCKADDR*)&sin, sizeof(SOCKADDR_IN));
	if(rc==SOCKET_ERROR)
	{
		printf("Fehler: bind, fehler code: %d\n",WSAGetLastError());
	}
 
	/*Initializing OpenSSL*/
	SSL_load_error_strings();
	ERR_load_BIO_strings();
	OpenSSL_add_all_algorithms();
	SSL_library_init();
	SSL *ssl1;
 
	SSL_CTX *_ctx = SSL_CTX_new(SSLv23_client_method());
	if(!_ctx) 
	{
		ERR_print_errors_fp(stderr);
	}
 
	ssl1 = SSL_new(_ctx);
	if(!ssl1) 
	{
		closesocket(sock);
		printf("SSL creation error\n");
	}
 
	SSL_set_fd(ssl1, sock);
	err = SSL_accept(ssl1);
	printf("SSL accept error: %d",SSL_get_error(ssl1, err));
 
	if(err == 1)
	{
	   printf("The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been established\n");
	}
	else if(err == 0)
	{
	   printf("The TLS/SSL handshake was not successful but was shut down controlled and by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the return value ret to find out the reason.\n");
	}
	else if(err < 0)
	{
	   printf("The TLS/SSL handshake was not successful because a fatal error occurred either at the protocol level or a connection failure occurred. The shutdown was not clean. It can also occur of action is need to continue the operation for non-blocking BIOs. Call SSL_get_error() with the return value ret to find out the reason.\n");
	}
	else
	{
	   printf("Je ne sais pas quoi penser\n");
	}
En exécutant le code SSL_accept() retourne une erreur 0, et je ne comprend pas ce que je dois faire pour résoudre ce problème