Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <openssl/err.h>
- #include <openssl/ssl.h>
- #include <openssl/rand.h>
- #include <string.h>
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- __attribute__((constructor)) void construct_ssl()
- {
- SSL_load_error_strings();
- SSL_library_init();
- OpenSSL_add_all_algorithms();
- }
- __attribute__((destructor)) void destruct_ssl()
- {
- ERR_free_strings();
- EVP_cleanup();
- }
- int main(int argc, char *argv[])
- {
- BIO *acc, *client;
- SSL *ssl;
- SSL_CTX *ctx;
- // init_OpenSSL();
- // seed_prng();
- ctx = SSL_CTX_new( TLSv1_server_method());
- // tlsctx = SSL_CTX_new( SSLv3_server_method() );
- SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE);
- SSL_CTX_use_certificate_file(ctx, "server.crt" , SSL_FILETYPE_PEM);
- SSL_CTX_use_PrivateKey_file(ctx, "server.key", SSL_FILETYPE_PEM);
- // ctx = setup_server_ctx();
- acc = BIO_new_accept("12120");
- if (!acc)
- cout << "Error creating server socket\n";
- // if (BIO_do_accept(acc) <= 0)
- // cout << "Error binding server socket\n";
- for (;;)
- {
- if (BIO_do_accept(acc) <= 0)
- cout << "Error accepting connection\n";
- client = BIO_pop(acc);
- if (!(ssl = SSL_new(ctx)))
- cout << "Error creating SSL context\n";
- SSL_set_accept_state(ssl);
- SSL_set_bio(ssl, client, client);
- if (SSL_accept(ssl) <= 0)
- cout << "Error accepting SSL connection\n";
- }
- SSL_CTX_free(ctx);
- BIO_free(acc);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement