#include <stdio.h>
#include <openssl/ssl.h>
#include <openssl/bio.h>
#include <openssl/err.h>
int main()
{
BIO *s_bio, *bbio, *acpt, *out;
int len;
char tmpbuf[1024];
SSL_CTX *ctx;
SSL *ssl;
ERR_load_crypto_strings();
ERR_load_SSL_strings();
OpenSSL_add_all_algorithms();
/* Might seed PRNG here */
ctx = SSL_CTX_new(SSLv23_server_method());
if (!SSL_CTX_use_certificate_file(ctx,"server.pem",SSL_FILETYPE_PEM))
{
printf("error: %s\n",ERR_reason_error_string(ERR_get_error()));
printf("error setting up SSL_CTX _ SSL_CTX_use_certificate_file _\n");
return 0;
}
if (!SSL_CTX_use_PrivateKey_file(ctx,"server.pem",SSL_FILETYPE_PEM))
{
printf("error: %s\n",ERR_reason_error_string(ERR_get_error()));
printf("error setting up SSL_CTX _ SSL_CTX_use_PrivateKey_file _\n");
return 0;
}
if(!SSL_CTX_check_private_key(ctx))
{
printf("error: %s\n",ERR_reason_error_string(ERR_get_error()));
printf("error setting up SSL_CTX _ SSL_CTX_check_private_key _\n");
return 0;
}
s_bio=BIO_new_ssl(ctx,0);
BIO_get_ssl(s_bio,& ssl);
if (!ssl)
{
printf("couldn't allocate SSL pointer.\n");
}
SSL_set_mode(ssl,SSL_MODE_AUTO_RETRY);
bbio = BIO_new(BIO_f_buffer());
s_bio = BIO_push(bbio,s_bio);
acpt = BIO_new_accept("9292");
BIO_set_accept_bios(acpt,s_bio);
if(BIO_do_accept(acpt) <= 0)
{
printf("error setting up accept.\n");
return 1;
}
for (;;-)
{
printf("waitting for new connection...\n");
if(BIO_do_accept(acpt) <= 0)
{
printf("error in connection\n");
}
s_bio = BIO_pop(acpt);
if (BIO_do_handshake(s_bio) <= 0)
{
printf("error in SSL handshake!\n");
}
else
{
printf("new SSL connection was accepted .... starting transmision...\n");
BIO_gets(s_bio,tmpbuf,1024);
printf("BIO_gets result: %s\n",tmpbuf);
// НЕОБХОДИМО ОПРЕДЕЛИТЬ ХОСТ С КОТОРЫМ УСТАНОВЛЕННО СОЕДИЕНИЕ
}
}
}
Вопрос по OpenSSL
Помогите решить проблему с получение хоста в соединении SSL...