OCSP, CRL request with "Cache-Control: no-cache" for proxy

This commit is contained in:
Takashi Kojo
2019-02-22 09:23:06 +09:00
parent 25dd5882f8
commit 7b44fbe265
2 changed files with 29 additions and 6 deletions

View File

@@ -1142,9 +1142,9 @@ int wolfIO_HttpProcessResponse(int sfd, const char** appStrList,
int wolfIO_HttpBuildRequest(const char* reqType, const char* domainName,
const char* path, int pathLen, int reqSz, const char* contentType,
byte* buf, int bufSize)
const char* exHdrs, byte* buf, int bufSize)
{
word32 reqTypeLen, domainNameLen, reqSzStrLen, contentTypeLen, maxLen;
word32 reqTypeLen, domainNameLen, reqSzStrLen, contentTypeLen, exHdrsLen, maxLen;
char reqSzStr[6];
char* req = (char*)buf;
const char* blankStr = " ";
@@ -1152,9 +1152,10 @@ int wolfIO_HttpBuildRequest(const char* reqType, const char* domainName,
const char* hostStr = "\r\nHost: ";
const char* contentLenStr = "\r\nContent-Length: ";
const char* contentTypeStr = "\r\nContent-Type: ";
const char *singleCrLfStr = "\r\n";
const char* doubleCrLfStr = "\r\n\r\n";
word32 blankStrLen, http11StrLen, hostStrLen, contentLenStrLen,
contentTypeStrLen, doubleCrLfStrLen;
contentTypeStrLen, singleCrLfStrLen, doubleCrLfStrLen;
reqTypeLen = (word32)XSTRLEN(reqType);
domainNameLen = (word32)XSTRLEN(domainName);
@@ -1166,6 +1167,15 @@ int wolfIO_HttpBuildRequest(const char* reqType, const char* domainName,
hostStrLen = (word32)XSTRLEN(hostStr);
contentLenStrLen = (word32)XSTRLEN(contentLenStr);
contentTypeStrLen = (word32)XSTRLEN(contentTypeStr);
if(exHdrs){
singleCrLfStrLen = (word32)XSTRLEN(singleCrLfStr);
exHdrsLen = (word32)XSTRLEN(exHdrs);
} else {
singleCrLfStrLen = 0;
exHdrsLen = 0;
}
doubleCrLfStrLen = (word32)XSTRLEN(doubleCrLfStr);
/* determine max length and check it */
@@ -1180,6 +1190,8 @@ int wolfIO_HttpBuildRequest(const char* reqType, const char* domainName,
reqSzStrLen +
contentTypeStrLen +
contentTypeLen +
singleCrLfStrLen +
exHdrsLen +
doubleCrLfStrLen +
1 /* null term */;
if (maxLen > (word32)bufSize)
@@ -1211,6 +1223,15 @@ int wolfIO_HttpBuildRequest(const char* reqType, const char* domainName,
XSTRNCPY((char*)buf, contentType, bufSize);
buf += contentTypeLen; bufSize -= contentTypeLen;
}
if (exHdrsLen > 0)
{
XSTRNCPY((char *)buf, singleCrLfStr, bufSize);
buf += singleCrLfStrLen;
bufSize -= singleCrLfStrLen;
XSTRNCPY((char *)buf, exHdrs, bufSize);
buf += exHdrsLen;
bufSize -= exHdrsLen;
}
XSTRNCPY((char*)buf, doubleCrLfStr, bufSize);
buf += doubleCrLfStrLen;
@@ -1228,8 +1249,9 @@ int wolfIO_HttpBuildRequest(const char* reqType, const char* domainName,
int wolfIO_HttpBuildRequestOcsp(const char* domainName, const char* path,
int ocspReqSz, byte* buf, int bufSize)
{
const char *cacheCtl = "Cache-Control: no-cache";
return wolfIO_HttpBuildRequest("POST", domainName, path, (int)XSTRLEN(path),
ocspReqSz, "application/ocsp-request", buf, bufSize);
ocspReqSz, "application/ocsp-request", cacheCtl, buf, bufSize);
}
/* return: >0 OCSP Response Size
@@ -1341,7 +1363,8 @@ void EmbedOcspRespFree(void* ctx, byte *resp)
int wolfIO_HttpBuildRequestCrl(const char* url, int urlSz,
const char* domainName, byte* buf, int bufSize)
{
return wolfIO_HttpBuildRequest("GET", domainName, url, urlSz, 0, "",
const char *cacheCtl = "Cache-Control: no-cache";
return wolfIO_HttpBuildRequest("GET", domainName, url, urlSz, cacheCtl, 0, "",
buf, bufSize);
}

View File

@@ -392,7 +392,7 @@ WOLFSSL_API int BioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
WOLFSSL_API int wolfIO_HttpBuildRequest(const char* reqType,
const char* domainName, const char* path, int pathLen, int reqSz,
const char* contentType, unsigned char* buf, int bufSize);
const char* contentType, const char* exHdrs, unsigned char* buf, int bufSize);
WOLFSSL_API int wolfIO_HttpProcessResponse(int sfd, const char** appStrList,
unsigned char** respBuf, unsigned char* httpBuf, int httpBufSz,
int dynType, void* heap);