14 #include <sys/types.h>
15 #include <sys/socket.h>
16 #include <netinet/in.h>
17 #include <arpa/inet.h>
31 #define CERTF HOME "foo-cert.pem"
32 #define KEYF HOME "foo-cert.pem"
35 #define CHK_NULL(x) if ((x)==NULL) exit (1)
36 #define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
37 #define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); }
44 struct sockaddr_in sa_serv;
45 struct sockaddr_in sa_cli;
75 fprintf(stderr,
"Private key does not match the certificate public key\n");
82 listen_sd = socket (AF_INET, SOCK_STREAM, 0);
CHK_ERR(listen_sd,
"socket");
84 memset (&sa_serv,
'\0',
sizeof(sa_serv));
85 sa_serv.sin_family = AF_INET;
86 sa_serv.sin_addr.s_addr = INADDR_ANY;
87 sa_serv.sin_port = htons (1111);
89 err = bind(listen_sd, (
struct sockaddr*) &sa_serv,
90 sizeof (sa_serv));
CHK_ERR(err,
"bind");
94 err = listen (listen_sd, 5);
CHK_ERR(err,
"listen");
96 client_len =
sizeof(sa_cli);
97 sd = accept (listen_sd, (
struct sockaddr*) &sa_cli, &client_len);
101 printf (
"Connection from %lx, port %x\n",
102 sa_cli.sin_addr.s_addr, sa_cli.sin_port);
118 if (client_cert != NULL) {
119 printf (
"Client certificate:\n");
123 printf (
"\t subject: %s\n", str);
128 printf (
"\t issuer: %s\n", str);
134 X509_free (client_cert);
136 printf (
"Client does not have certificate.\n");
142 printf (
"Got %d chars:'%s'\n", err, buf);