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
| /*Initializing OpenSSL*/
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
SSL_library_init();
printf("Initialisation SSL : OK\n");
/*SSL Context*/
ctx = SSL_CTX_new(SSLv23_client_method());
printf("SSL Context : OK\n");
/*CREATION DE LA SOCKET*/
sock_descriptor = socket(AF_INET, SOCK_STREAM, 0);
if (sock_descriptor ==-1)
{
perror("call to socket\n");
exit(1);
}
printf("socket ok\n");
/*initialisation*/
bzero(&sin,sizeof(sin));
sin.sin_family=AF_INET;
sin.sin_addr.s_addr=INADDR_ANY;
sin.sin_port=htons(port);
/*BIND*/
if (bind(sock_descriptor, (struct sockaddr*)&sin, sizeof(sin))==-1)
{
perror("call to bind\n");
exit(1);
}
printf("bind ok\n");
/*LISTEN*/
if (listen(sock_descriptor, 20)==-1)
{
perror("call to listen\n");
exit(1);
}
printf("Accepting connections...\n");
/**/
while(1)
{
address_size=sizeof(struct sockaddr_in);
if ((temp_sock_descriptor=accept(sock_descriptor, (struct sockaddr *)&pin,
&address_size))==-1)
{
perror("call to accept\n");
exit(1);
}
printf("accept ok\n");
sbio=BIO_new_socket(temp_sock_descriptor,BIO_NOCLOSE);
ssl=SSL_new(ctx);
SSL_set_bio(ssl,sbio,sbio);
if((r=SSL_accept(ssl)<=0))
{
perror("SSL accept error\n");
ERR_print_errors_fp(stderr);
//exit(1);
}
}
/* Close the connection and free the context */
BIO_free_all(sbio);
SSL_CTX_free(ctx);
return 0; |
Partager