21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

servers. In particular, you need to create an spc_x509store_t object (see Recipe 10.5)<br />

with a certificate and a private key. The information contained in this object is sent<br />

to clients during the initial handshake. In addition, the SPC_X509STORE_USE_<br />

CERTIFICATE flag needs to be set in the spc_x509store_t object. With the spc_<br />

x509store_t created, calls need to be made to create the listening BIO object, put it<br />

into a listening state, and accept new connections. (See Recipe 9.1 for a brief discussion<br />

regarding BIO objects.)<br />

Discussion<br />

Once an spc_x509store_t object has been created and fully initialized, the first step in<br />

creating an SSLserver is to call spc_listen( ). The hostname may be specified as<br />

NULL, which indicates that the created socket should be bound to all interfaces. Anything<br />

else should be specified in string form as an IP address for the interface to bind<br />

to. For example, “127.0.0.1” would cause the server BIO object to bind only to the<br />

local loopback interface.<br />

#include <br />

#include <br />

#include <br />

#include <br />

BIO *spc_listen(char *host, int port) {<br />

BIO *acpt = 0;<br />

int addr_length;<br />

char *addr;<br />

if (port < 1 || port > 65535) return 0;<br />

if (!host) host = "*";<br />

addr_length = strlen(host) + 6; /* 5 for int, 1 for colon */<br />

if (!(addr = (char *)malloc(addr_length + 1))) return 0;<br />

snprintf(addr, addr_length + 1, "%s:%d", host, port);<br />

if ((acpt = BIO_new(BIO_s_accept( ))) != 0) {<br />

BIO_set_accept_port(acpt, addr);<br />

if (BIO_do_accept(acpt)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!