clean up Windows build issues with OCSP

This commit is contained in:
John Safranek
2013-09-18 14:47:51 -07:00
parent 49d3e74fde
commit 5e4ca53496
3 changed files with 22 additions and 12 deletions

View File

@@ -5020,13 +5020,13 @@ static int SetSerialNumber(const byte* sn, word32 snSz, byte* output)
* INTEGER, if the MSB is 1, add a padding zero to keep the * INTEGER, if the MSB is 1, add a padding zero to keep the
* number positive. */ * number positive. */
if (sn[0] & 0x80) { if (sn[0] & 0x80) {
output[1] = snSz + 1; output[1] = (byte)snSz + 1;
output[2] = 0; output[2] = 0;
XMEMCPY(&output[3], sn, snSz); XMEMCPY(&output[3], sn, snSz);
result = snSz + 3; result = snSz + 3;
} }
else { else {
output[1] = snSz; output[1] = (byte)snSz;
XMEMCPY(&output[2], sn, snSz); XMEMCPY(&output[2], sn, snSz);
result = snSz + 2; result = snSz + 2;
} }

View File

@@ -189,7 +189,13 @@ enum {
#define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n)) #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
#define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n)) #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
#define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n)) #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
#define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n)) #ifndef USE_WINDOWS_API
#define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
#define XSNPRINTF snprintf
#else
#define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
#define XSNPRINTF _snprintf
#endif
#endif #endif
#if defined(HAVE_ECC) || defined(HAVE_OCSP) #if defined(HAVE_ECC) || defined(HAVE_OCSP)

View File

@@ -107,6 +107,7 @@
#define SOCKET_EPIPE WSAEPIPE #define SOCKET_EPIPE WSAEPIPE
#define SOCKET_ECONNREFUSED WSAENOTCONN #define SOCKET_ECONNREFUSED WSAENOTCONN
#define SOCKET_ECONNABORTED WSAECONNABORTED #define SOCKET_ECONNABORTED WSAECONNABORTED
#define close(s) closesocket(s)
#elif defined(__PPU) #elif defined(__PPU)
#define SOCKET_EWOULDBLOCK SYS_NET_EWOULDBLOCK #define SOCKET_EWOULDBLOCK SYS_NET_EWOULDBLOCK
#define SOCKET_EAGAIN SYS_NET_EAGAIN #define SOCKET_EAGAIN SYS_NET_EAGAIN
@@ -552,7 +553,7 @@ static INLINE int tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port)
static int build_http_request(const char* domainName, const char* path, static int build_http_request(const char* domainName, const char* path,
int ocspReqSz, byte* buf, int bufSize) int ocspReqSz, byte* buf, int bufSize)
{ {
return snprintf((char*)buf, bufSize, return XSNPRINTF((char*)buf, bufSize,
"POST %s HTTP/1.1\r\n" "POST %s HTTP/1.1\r\n"
"Host: %s\r\n" "Host: %s\r\n"
"Content-Length: %d\r\n" "Content-Length: %d\r\n"
@@ -563,7 +564,7 @@ static int build_http_request(const char* domainName, const char* path,
static int decode_url(const char* url, int urlSz, static int decode_url(const char* url, int urlSz,
char* outName, char* outPath, int* outPort) char* outName, char* outPath, word16* outPort)
{ {
int result = -1; int result = -1;
@@ -596,6 +597,7 @@ static int decode_url(const char* url, int urlSz,
if (cur < urlSz && url[cur] == ':') { if (cur < urlSz && url[cur] == ':') {
char port[6]; char port[6];
int j; int j;
word32 bigPort = 0;
i = 0; i = 0;
cur++; cur++;
while (cur < urlSz && url[cur] != 0 && url[cur] != '/' && while (cur < urlSz && url[cur] != 0 && url[cur] != '/' &&
@@ -603,11 +605,11 @@ static int decode_url(const char* url, int urlSz,
port[i++] = url[cur++]; port[i++] = url[cur++];
} }
*outPort = 0;
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
if (port[j] < '0' || port[j] > '9') return -1; if (port[j] < '0' || port[j] > '9') return -1;
*outPort = (*outPort * 10) + (port[j] - '0'); bigPort = (bigPort * 10) + (port[j] - '0');
} }
*outPort = (word16)bigPort;
} }
else else
*outPort = 80; *outPort = 80;
@@ -648,7 +650,7 @@ static int process_http_response(int sfd, byte** respBuf,
start = end = NULL; start = end = NULL;
do { do {
if (end == NULL) { if (end == NULL) {
result = (int)recv(sfd, httpBuf+len, httpBufSz-len-1, 0); result = (int)recv(sfd, (char*)httpBuf+len, httpBufSz-len-1, 0);
if (result > 0) { if (result > 0) {
len += result; len += result;
start = (char*)httpBuf; start = (char*)httpBuf;
@@ -735,7 +737,7 @@ static int process_http_response(int sfd, byte** respBuf,
/* receive the OCSP response data */ /* receive the OCSP response data */
do { do {
result = (int)recv(sfd, recvBuf+len, recvBufSz-len, 0); result = (int)recv(sfd, (char*)recvBuf+len, recvBufSz-len, 0);
if (result > 0) if (result > 0)
len += result; len += result;
else { else {
@@ -755,7 +757,9 @@ int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf) byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
{ {
char domainName[80], path[80]; char domainName[80], path[80];
int port, httpBufSz, sfd = -1; int httpBufSz;
SOCKET_T sfd;
word16 port;
int ocspRespSz = 0; int ocspRespSz = 0;
byte* httpBuf = NULL; byte* httpBuf = NULL;
@@ -791,9 +795,9 @@ int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
if ((tcp_connect(&sfd, domainName, port) == 0) && (sfd > 0)) { if ((tcp_connect(&sfd, domainName, port) == 0) && (sfd > 0)) {
int written; int written;
written = (int)send(sfd, httpBuf, httpBufSz, 0); written = (int)send(sfd, (char*)httpBuf, httpBufSz, 0);
if (written == httpBufSz) { if (written == httpBufSz) {
written = (int)send(sfd, ocspReqBuf, ocspReqSz, 0); written = (int)send(sfd, (char*)ocspReqBuf, ocspReqSz, 0);
if (written == ocspReqSz) { if (written == ocspReqSz) {
ocspRespSz = process_http_response(sfd, ocspRespBuf, ocspRespSz = process_http_response(sfd, ocspRespBuf,
httpBuf, SCRATCH_BUFFER_SIZE); httpBuf, SCRATCH_BUFFER_SIZE);