default ocsp lookup callback returns an error if unable to connect to a responder

This commit is contained in:
John Safranek 2013-01-04 10:34:29 -08:00
parent a695599667
commit 3b6ba7935d

View File

@ -474,14 +474,14 @@ int EmbedGenerateCookie(byte *buf, int sz, void *ctx)
#endif #endif
static INLINE void tcp_socket(SOCKET_T* sockfd, SOCKADDR_IN_T* addr, static INLINE int tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port)
const char* peer, word16 port)
{ {
const char* host = peer; SOCKADDR_IN_T addr;
const char* host = ip;
/* peer could be in human readable form */ /* peer could be in human readable form */
if (peer != INADDR_ANY && isalpha(peer[0])) { if (ip != INADDR_ANY && isalpha(ip[0])) {
struct hostent* entry = gethostbyname(peer); struct hostent* entry = gethostbyname(ip);
if (entry) { if (entry) {
struct sockaddr_in tmp; struct sockaddr_in tmp;
@ -491,30 +491,27 @@ static INLINE void tcp_socket(SOCKET_T* sockfd, SOCKADDR_IN_T* addr,
host = inet_ntoa(tmp.sin_addr); host = inet_ntoa(tmp.sin_addr);
} }
else { else {
CYASSL_MSG("no entry for host"); CYASSL_MSG("no addr entry for OCSP responder");
return -1;
} }
} }
*sockfd = socket(AF_INET_V, SOCK_STREAM, 0); *sockfd = socket(AF_INET_V, SOCK_STREAM, 0);
XMEMSET(addr, 0, sizeof(SOCKADDR_IN_T)); XMEMSET(&addr, 0, sizeof(SOCKADDR_IN_T));
addr->sin_family = AF_INET_V; addr.sin_family = AF_INET_V;
addr->sin_port = htons(port); addr.sin_port = htons(port);
if (host == INADDR_ANY) if (host == INADDR_ANY)
addr->sin_addr.s_addr = INADDR_ANY; addr.sin_addr.s_addr = INADDR_ANY;
else else
addr->sin_addr.s_addr = inet_addr(host); addr.sin_addr.s_addr = inet_addr(host);
}
static INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port)
{
SOCKADDR_IN_T addr;
tcp_socket(sockfd, &addr, ip, port);
if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) { if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) {
CYASSL_MSG("tcp connect failed"); CYASSL_MSG("OCSP responder tcp connect failed");
return -1;
} }
return 0;
} }
@ -699,8 +696,7 @@ int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
httpBufSz = build_http_request(domainName, path, ocspReqSz, httpBufSz = build_http_request(domainName, path, ocspReqSz,
httpBuf, httpBufSz); httpBuf, httpBufSz);
tcp_connect(&sfd, domainName, port); if ((tcp_connect(&sfd, domainName, port) == 0) && (sfd > 0)) {
if (sfd > 0) {
int written; int written;
written = (int)write(sfd, httpBuf, httpBufSz); written = (int)write(sfd, httpBuf, httpBufSz);
if (written == httpBufSz) { if (written == httpBufSz) {