-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_tls_server.cpp
More file actions
53 lines (36 loc) · 1.12 KB
/
test_tls_server.cpp
File metadata and controls
53 lines (36 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "make_tls_server.h"
#include "tls_common_lib.h"
#include <stdio.h>
#define PORTNUM 5001
#define KEY_FNAME "alex.key"
#define CERT_FNAME "alex.crt"
#define CA_CERT_FNAME "signing.pem"
#define CLIENT_NAME "grp1b_alex_laptop"
// We are making an echo server. So we
// just echo back whatever we read.
void *worker(void *conn) {
int exit = 0;
while(!exit) {
int count;
char buffer[128];
count = sslRead(conn, buffer, sizeof(buffer));
if(count > 0) {
printf("Read %s. Echoing.\n", buffer);
count = sslWrite(conn, buffer, sizeof(buffer));
if(count < 0) {
perror("Error writing to network: " );
}
}
else if(count < 0) {
perror("Error reading from network: ");
}
// Exit of we have an error or the connection has closed.
exit = (count <= 0);
}
printf("\nConnection closed. Exiting.\n\n");
EXIT_THREAD(conn);
}
int main() {
createServer(KEY_FNAME, CERT_FNAME, PORTNUM, &worker, CA_CERT_FNAME, CLIENT_NAME, 1);
while(server_is_running());
}