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.

Once we have the URLof the CRLwe want, it is a simple matter to retrieve it using<br />

the HTTP protocol. OpenSSLdoes not provide even the simplest of HTTP clients, so<br />

we must speak the bare minimum ourselves to connect to the server and retrieve the<br />

data.<br />

static void *retrieve_webdata(char *uri, int *datalen, spc_x509store_t *store) {<br />

int bytes, content_length = 0, headerlen = 0, sd, ssl;<br />

BIO *conn = 0;<br />

SSL *ssl_ptr;<br />

char buffer[1024];<br />

char *headers = 0, *host = 0, *path = 0, *port = 0, *tmp;<br />

void *data = 0;<br />

fd_set rmask, wmask;<br />

SSL_CTX *ctx = 0;<br />

*datalen = 0;<br />

if (!OCSP_parse_url(uri, &host, &port, &path, &ssl)) goto end_error;<br />

if (!(conn = spc_connect(host, atoi(port), ssl, store, &ctx))) goto end_error;<br />

/* Send the request for the data */<br />

BIO_printf(conn, "GET %s HTTP/1.0\r\nConnection: close\r\n\r\n", path);<br />

/* Put the socket into non-blocking mode */<br />

BIO_get_fd(conn, &sd);<br />

BIO_socket_nbio(sd, 1);<br />

if (ssl) {<br />

BIO_get_ssl(conn, &ssl_ptr);<br />

SSL_set_mode(ssl_ptr, SSL_MODE_ENABLE_PARTIAL_WRITE |<br />

SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);<br />

}<br />

/* Loop reading data from the socket until we've got all of the headers */<br />

for (;;) {<br />

FD_ZERO(&rmask);<br />

FD_SET(sd, &rmask);<br />

FD_ZERO(&wmask);<br />

if (BIO_should_write(conn)) FD_SET(sd, &wmask);<br />

if (select(FD_SETSIZE, &rmask, &wmask, 0, 0)

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

Saved successfully!

Ooh no, something went wrong!