Example web server using SSL connection. It will always send the same web. It's just a test to stablish a secure connection and send some data This server cannot attend simultaneous connections. More...
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <netinet/in.h>
#include <resolv.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
Go to the source code of this file.
Classes | |
struct | Sslc |
Macros | |
#define | PORT 1430 |
#define | BUFFERSIZE 16384 |
#define | CRLF "\r\n" |
#define | RESPONSE |
#define | CERTFILE "sslserverchain.pem" |
#define | KEYFILE "sslserver.key" |
Functions | |
int | TCP_Server (Sslc *h, int port) |
int | TCP_select (Sslc *h, double timeout) |
int | SSL_init (Sslc *h) |
int | SSL_load_certificates (Sslc *h, char *cert, char *key) |
int | TCP_acceptClient (Sslc *h) |
int | TCP_clientDialog (Sslc *h) |
int | SSL_clientDialog (Sslc *h) |
void | panic (char *msg) |
void | aclock (int loop) |
int | main (int argv, char **argc) |
Example web server using SSL connection. It will always send the same web. It's just a test to stablish a secure connection and send some data This server cannot attend simultaneous connections.
Changelog: 20150422 - Some more doc.
To compile $ gcc -o serverssl serverssl.c -lcrypto -lssl
Definition in file serverssl.c.
#define BUFFERSIZE 16384 |
Buffer Size to use
Definition at line 42 of file serverssl.c.
Referenced by SSL_clientDialog(), and TCP_clientDialog().
#define CERTFILE "sslserverchain.pem" |
Certificate file, or certificate chain file
Definition at line 55 of file serverssl.c.
#define CRLF "\r\n" |
CRLF
Definition at line 45 of file serverssl.c.
#define KEYFILE "sslserver.key" |
Key file
Definition at line 57 of file serverssl.c.
#define PORT 1430 |
Port
Definition at line 39 of file serverssl.c.
#define RESPONSE |
The only response of this server
Definition at line 48 of file serverssl.c.
Referenced by SSL_clientDialog(), and TCP_clientDialog().
void aclock | ( | int | loop | ) |
ASCII clock to wait for clients
loop | Just a number, when it changes, it draws a new character. If loop == 0, restarts |
Definition at line 339 of file serverssl.c.
void panic | ( | char * | msg | ) |
Prints a tragic error and exit
msg | Error text |
Definition at line 359 of file serverssl.c.
int SSL_clientDialog | ( | Sslc * | h | ) |
It's everything we're here for. SSL dialog with the clients
h | Our struct |
Definition at line 274 of file serverssl.c.
References BUFFERSIZE, Sslc::client_skt, Sslc::ctx, RESPONSE, and Sslc::ssl.
Referenced by TCP_acceptClient().
int SSL_init | ( | Sslc * | h | ) |
Initializes SSL connection and creates the SSL Context
h | Our struct to store everything |
Definition at line 303 of file serverssl.c.
References Sslc::ctx.
int SSL_load_certificates | ( | Sslc * | h, |
char * | cert, | ||
char * | key | ||
) |
Loads certificates in the context.
h | Our struct to store everything |
cert | PEM certificate file or chain (we can store several certificates in one file, just concatenating them. |
key | Encryption key |
Definition at line 320 of file serverssl.c.
References Sslc::ctx.
int TCP_acceptClient | ( | Sslc * | h | ) |
Accepts client and start dialog
h | Our struct |
Definition at line 238 of file serverssl.c.
References Sslc::client_skt, Sslc::skt, and SSL_clientDialog().
int TCP_clientDialog | ( | Sslc * | h | ) |
Just a test, replace SSL_clientDialog() in acceptClient() by TCP_clientDialog() to create an insecure web server.
h | Our struct |
Definition at line 259 of file serverssl.c.
References BUFFERSIZE, Sslc::client_skt, and RESPONSE.
int TCP_select | ( | Sslc * | h, |
double | timeout | ||
) |
Uses select to test if there is anything waiting to be read. The same function as myssl.c
h | Our structure. Only the socket will be used |
timeout | Timeout before giving up |
Definition at line 222 of file serverssl.c.
References Sslc::skt.
int TCP_Server | ( | Sslc * | h, |
int | port | ||
) |
h | Our struct |
port | Por to listen to |
Definition at line 201 of file serverssl.c.
References Sslc::skt.