21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

server name, starting with the forward slash and ending before the query string<br />

(which starts with a question mark). Specifying lpszAcceptTypes as 0 tells the server<br />

that we can accept any kind of text document; it is equivalent to a MIME type of<br />

“text/*”.<br />

The most interesting argument passed to HttpOpenRequest( ) is dwFlags. A large number<br />

of flags are defined, but only five deal specifically with HTTP over SSL:<br />

INTERNET_FLAG_IGNORE_CERT_CN_INVALID<br />

Normally, as part of verification of the server’s certificate, WinInet will verify<br />

that the hostname is contained in the certificate’s commonName field or<br />

subjectAltName extension. If this flag is specified, the hostname check will not be<br />

performed. (See Recipes 10.4 and 10.8 for discussions of the importance of performing<br />

hostname checks on certificates.)<br />

INTERNET_FLAG_IGNORE_CERT_DATE_INVALID<br />

An important part of verifying the validity of an X.509 certificate involves checking<br />

the dates for which a certificate is valid. If the current date is outside the certificate’s<br />

valid date range, the certificate should be considered invalid. If this flag<br />

is specified, the certificate’s validity dates are not checked. This option should<br />

never be used in a released version of a product.<br />

INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP<br />

If this flag is specified and the server attempts to redirect the client to a non-SSL<br />

URL, the redirection will be ignored. You should always include this flag so you<br />

can be sure you are not transferring in the clear data that you expect to be protected.<br />

INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS<br />

If this flag is specified and the server attempts to redirect the client to an SSLprotected<br />

URL, the redirection will be ignored. If you’re expecting to be communicating<br />

only with servers under your own control, it’s safe to omit this flag; if<br />

not, you might want to consider including it so you’re not transferred somewhere<br />

other than expected.<br />

INTERNET_FLAG_SECURE<br />

This is the all-important flag. When this flag is included, the use of SSLon the<br />

connection is enabled. Without it, SSLis not used, and all data is transferred in<br />

the clear. Obviously, you want to include this flag.<br />

Once the request object has been constructed, the request needs to be sent to the<br />

server. This is done by calling HttpSendRequest( ) with the request object. Additional<br />

headers can be included with the request submission, as well as any optional data to<br />

be sent after the headers. You will want to send optional data when performing a<br />

POST operation. Additional headers and optional data are both specified as strings<br />

and the lengths of the strings.<br />

BOOL bResult;<br />

LPSTR lpszHeaders = 0;<br />

466 | Chapter 9: Networking<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!