Merge branch 'master' into ti
This commit is contained in:
commit
0c6a961e35
92
src/io.c
92
src/io.c
@ -477,7 +477,6 @@ int EmbedGenerateCookie(CYASSL* ssl, byte *buf, int sz, void *ctx)
|
|||||||
int sd = ssl->wfd;
|
int sd = ssl->wfd;
|
||||||
struct sockaddr_storage peer;
|
struct sockaddr_storage peer;
|
||||||
XSOCKLENT peerSz = sizeof(peer);
|
XSOCKLENT peerSz = sizeof(peer);
|
||||||
Sha sha;
|
|
||||||
byte digest[SHA_DIGEST_SIZE];
|
byte digest[SHA_DIGEST_SIZE];
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
@ -489,11 +488,9 @@ int EmbedGenerateCookie(CYASSL* ssl, byte *buf, int sz, void *ctx)
|
|||||||
return GEN_COOKIE_E;
|
return GEN_COOKIE_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = InitSha(&sha);
|
ret = ShaHash((byte*)&peer, peerSz, digest);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
ShaUpdate(&sha, (byte*)&peer, peerSz);
|
|
||||||
ShaFinal(&sha, digest);
|
|
||||||
|
|
||||||
if (sz > SHA_DIGEST_SIZE)
|
if (sz > SHA_DIGEST_SIZE)
|
||||||
sz = SHA_DIGEST_SIZE;
|
sz = SHA_DIGEST_SIZE;
|
||||||
@ -841,68 +838,81 @@ static int process_http_response(int sfd, byte** respBuf,
|
|||||||
int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
|
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];
|
|
||||||
int httpBufSz;
|
|
||||||
SOCKET_T sfd = 0;
|
SOCKET_T sfd = 0;
|
||||||
word16 port;
|
word16 port;
|
||||||
int ocspRespSz = 0;
|
int ret = -1;
|
||||||
byte* httpBuf = NULL;
|
#ifdef CYASSL_SMALL_STACK
|
||||||
|
char* path;
|
||||||
|
char* domainName;
|
||||||
|
#else
|
||||||
|
char path[80];
|
||||||
|
char domainName[80];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CYASSL_SMALL_STACK
|
||||||
|
path = (char*)XMALLOC(80, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
if (path == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
domainName = (char*)XMALLOC(80, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
if (domainName == NULL) {
|
||||||
|
XFREE(path, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
(void)ctx;
|
(void)ctx;
|
||||||
|
|
||||||
if (ocspReqBuf == NULL || ocspReqSz == 0) {
|
if (ocspReqBuf == NULL || ocspReqSz == 0) {
|
||||||
CYASSL_MSG("OCSP request is required for lookup");
|
CYASSL_MSG("OCSP request is required for lookup");
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
else if (ocspRespBuf == NULL) {
|
||||||
if (ocspRespBuf == NULL) {
|
|
||||||
CYASSL_MSG("Cannot save OCSP response");
|
CYASSL_MSG("Cannot save OCSP response");
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
else if (decode_url(url, urlSz, domainName, path, &port) < 0) {
|
||||||
if (decode_url(url, urlSz, domainName, path, &port) < 0) {
|
|
||||||
CYASSL_MSG("Unable to decode OCSP URL");
|
CYASSL_MSG("Unable to decode OCSP URL");
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
/* Note, the library uses the EmbedOcspRespFree() callback to
|
/* Note, the library uses the EmbedOcspRespFree() callback to
|
||||||
* free this buffer. */
|
* free this buffer. */
|
||||||
httpBufSz = SCRATCH_BUFFER_SIZE;
|
int httpBufSz = SCRATCH_BUFFER_SIZE;
|
||||||
httpBuf = (byte*)XMALLOC(httpBufSz, NULL, DYNAMIC_TYPE_IN_BUFFER);
|
byte* httpBuf = (byte*)XMALLOC(httpBufSz, NULL,
|
||||||
|
DYNAMIC_TYPE_IN_BUFFER);
|
||||||
|
|
||||||
if (httpBuf == NULL) {
|
if (httpBuf == NULL) {
|
||||||
CYASSL_MSG("Unable to create OCSP response buffer");
|
CYASSL_MSG("Unable to create OCSP response buffer");
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
httpBufSz = build_http_request(domainName, path, ocspReqSz,
|
httpBufSz = build_http_request(domainName, path, ocspReqSz,
|
||||||
httpBuf, httpBufSz);
|
httpBuf, httpBufSz);
|
||||||
|
|
||||||
if ((tcp_connect(&sfd, domainName, port) == 0) && (sfd > 0)) {
|
if ((tcp_connect(&sfd, domainName, port) != 0) || (sfd <= 0)) {
|
||||||
int written;
|
|
||||||
written = (int)send(sfd, (char*)httpBuf, httpBufSz, 0);
|
|
||||||
if (written == httpBufSz) {
|
|
||||||
written = (int)send(sfd, (char*)ocspReqBuf, ocspReqSz, 0);
|
|
||||||
if (written == ocspReqSz) {
|
|
||||||
ocspRespSz = process_http_response(sfd, ocspRespBuf,
|
|
||||||
httpBuf, SCRATCH_BUFFER_SIZE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(sfd);
|
|
||||||
if (ocspRespSz == 0) {
|
|
||||||
CYASSL_MSG("OCSP response was not OK, no OCSP response");
|
|
||||||
XFREE(httpBuf, NULL, DYNAMIC_TYPE_IN_BUFFER);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
CYASSL_MSG("OCSP Responder connection failed");
|
CYASSL_MSG("OCSP Responder connection failed");
|
||||||
close(sfd);
|
}
|
||||||
XFREE(httpBuf, NULL, DYNAMIC_TYPE_IN_BUFFER);
|
else if ((int)send(sfd, (char*)httpBuf, httpBufSz, 0) !=
|
||||||
return -1;
|
httpBufSz) {
|
||||||
|
CYASSL_MSG("OCSP http request failed");
|
||||||
|
}
|
||||||
|
else if ((int)send(sfd, (char*)ocspReqBuf, ocspReqSz, 0) !=
|
||||||
|
ocspReqSz) {
|
||||||
|
CYASSL_MSG("OCSP ocsp request failed");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = process_http_response(sfd, ocspRespBuf, httpBuf,
|
||||||
|
SCRATCH_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(sfd);
|
||||||
XFREE(httpBuf, NULL, DYNAMIC_TYPE_IN_BUFFER);
|
XFREE(httpBuf, NULL, DYNAMIC_TYPE_IN_BUFFER);
|
||||||
return ocspRespSz;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CYASSL_SMALL_STACK
|
||||||
|
XFREE(path, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
XFREE(domainName, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user