2 /* demos/bio/server-cmod.c */
5 * A minimal TLS server it ses SSL_CTX_config and a configuration file to
6 * set most server parameters.
11 #include <openssl/err.h>
12 #include <openssl/ssl.h>
13 #include <openssl/conf.h>
15 int main(int argc, char *argv[])
17 unsigned char buf[512];
18 char *port = "*:4433";
24 SSL_load_error_strings();
26 /* Add ciphers and message digests */
27 OpenSSL_add_ssl_algorithms();
29 if (CONF_modules_load_file("cmod.cnf", "testapp", 0) <= 0) {
30 fprintf(stderr, "Error processing config file\n");
34 ctx = SSL_CTX_new(TLS_server_method());
36 if (SSL_CTX_config(ctx, "server") == 0) {
37 fprintf(stderr, "Error configuring server.\n");
41 /* Setup server side SSL bio */
42 ssl_bio = BIO_new_ssl(ctx, 0);
44 if ((in = BIO_new_accept(port)) == NULL)
48 * This means that when a new connection is accepted on 'in', The ssl_bio
49 * will be 'duplicated' and have the new socket BIO push into it.
50 * Basically it means the SSL BIO will be automatically setup
52 BIO_set_accept_bios(in, ssl_bio);
56 * The first call will setup the accept socket, and the second will get a
57 * socket. In this loop, the first actual accept will occur in the
58 * BIO_read() function.
61 if (BIO_do_accept(in) <= 0)
65 i = BIO_read(in, buf, sizeof(buf));
68 * If we have finished, remove the underlying BIO stack so the
69 * next time we call any function for this BIO, it will attempt
78 if (BIO_should_retry(in))
82 fwrite(buf, 1, i, stdout);
89 ERR_print_errors_fp(stderr);