2 * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 * A minimal TLS server it ses SSL_CTX_config and a configuration file to
12 * set most server parameters.
17 #include <openssl/err.h>
18 #include <openssl/ssl.h>
19 #include <openssl/conf.h>
21 int main(int argc, char *argv[])
23 unsigned char buf[512];
24 char *port = "*:4433";
30 ctx = SSL_CTX_new(TLS_server_method());
32 if (CONF_modules_load_file("cmod.cnf", "testapp", 0) <= 0) {
33 fprintf(stderr, "Error processing config file\n");
37 if (SSL_CTX_config(ctx, "server") == 0) {
38 fprintf(stderr, "Error configuring server.\n");
42 /* Setup server side SSL bio */
43 ssl_bio = BIO_new_ssl(ctx, 0);
45 if ((in = BIO_new_accept(port)) == NULL)
49 * This means that when a new connection is accepted on 'in', The ssl_bio
50 * will be 'duplicated' and have the new socket BIO push into it.
51 * Basically it means the SSL BIO will be automatically setup
53 BIO_set_accept_bios(in, ssl_bio);
57 * The first call will setup the accept socket, and the second will get a
58 * socket. In this loop, the first actual accept will occur in the
59 * BIO_read() function.
62 if (BIO_do_accept(in) <= 0)
66 i = BIO_read(in, buf, sizeof(buf));
69 * If we have finished, remove the underlying BIO stack so the
70 * next time we call any function for this BIO, it will attempt
79 if (BIO_should_retry(in))
83 fwrite(buf, 1, i, stdout);
90 ERR_print_errors_fp(stderr);