Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added certs/ecc-privkeyPkcs8.der
Binary file not shown.
9 changes: 8 additions & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/



#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
Expand Down Expand Up @@ -13680,6 +13679,7 @@ int ProcessReply(WOLFSSL* ssl)
}
else {
#ifdef WOLFSSL_TLS13
ssl->msgsReceived.got_change_cipher = 0;
ret = DoTls13HandShakeMsg(ssl,
ssl->buffers.inputBuffer.buffer,
&ssl->buffers.inputBuffer.idx,
Expand Down Expand Up @@ -13742,6 +13742,13 @@ int ProcessReply(WOLFSSL* ssl)
return UNKNOWN_RECORD_TYPE;
}
ssl->buffers.inputBuffer.idx++;
if (!ssl->msgsReceived.got_change_cipher) {
ssl->msgsReceived.got_change_cipher = 1;
}
else {
SendAlert(ssl, alert_fatal, illegal_parameter);
return UNKNOWN_RECORD_TYPE;
}
break;
}
#endif
Expand Down
20 changes: 14 additions & 6 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -29420,21 +29420,29 @@ WOLFSSL_EVP_PKEY* wolfSSL_PEM_read_bio_PrivateKey(WOLFSSL_BIO* bio,
{
WOLFSSL_EVP_PKEY* pkey = NULL;
DerBuffer* der = NULL;
int eccFlag = 0;
int keyFormat = 0;
int type = -1;

WOLFSSL_ENTER("wolfSSL_PEM_read_bio_PrivateKey");

if (bio == NULL)
return pkey;

if (pem_read_bio_key(bio, cb, pass, PRIVATEKEY_TYPE, &eccFlag, &der) >= 0) {
int type;
if (pem_read_bio_key(bio, cb, pass, PRIVATEKEY_TYPE, &keyFormat, &der) >= 0) {
const unsigned char* ptr = der->buffer;

if (eccFlag)
type = EVP_PKEY_EC;
else
if (keyFormat) {
/* keyFormat is Key_Sum enum */
if (keyFormat == RSAk)
type = EVP_PKEY_RSA;
else if (keyFormat == ECDSAk)
type = EVP_PKEY_EC;
else if (keyFormat == DSAk)
type = EVP_PKEY_DSA;
} else {
/* Default to RSA if format is not set */
type = EVP_PKEY_RSA;
}

/* handle case where reuse is attempted */
if (key != NULL && *key != NULL)
Expand Down
19 changes: 17 additions & 2 deletions src/tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -5992,6 +5992,10 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,

/* Advance state and proceed */
ssl->options.asyncState = TLS_ASYNC_END;
#if !defined(NO_WOLFSSL_CLIENT)
if (ssl->options.side == WOLFSSL_CLIENT_END)
ssl->options.serverState = SERVER_CERT_VERIFY_COMPLETE;
#endif
} /* case TLS_ASYNC_FINALIZE */

case TLS_ASYNC_END:
Expand Down Expand Up @@ -7142,16 +7146,27 @@ static int SanityCheckTls13MsgReceived(WOLFSSL* ssl, byte type)
WOLFSSL_MSG("Finished received out of order");
return OUT_OF_ORDER_E;
}
if (ssl->options.serverState <
/* Must have seen certificate and verify from server except when
* using PSK. */
#if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
if (ssl->arrays->psk_keySz != 0) {
if (ssl->options.serverState !=
SERVER_ENCRYPTED_EXTENSIONS_COMPLETE) {
WOLFSSL_MSG("Finished received out of order");
return OUT_OF_ORDER_E;
}
}
else
#endif
if (ssl->options.serverState != SERVER_CERT_VERIFY_COMPLETE) {
WOLFSSL_MSG("Finished received out of order");
return OUT_OF_ORDER_E;
}
}
#endif
#ifndef NO_WOLFSSL_SERVER
if (ssl->options.side == WOLFSSL_SERVER_END) {
if (ssl->options.serverState < SERVER_FINISHED_COMPLETE) {
if (ssl->options.serverState != SERVER_FINISHED_COMPLETE) {
WOLFSSL_MSG("Finished received out of order");
return OUT_OF_ORDER_E;
}
Expand Down
32 changes: 19 additions & 13 deletions src/wolfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, word16 port, int to_sec)
SOCKADDR_IN *sin;
#endif

if (sockfd == NULL || ip == NULL) {
return -1;
}

XMEMSET(&addr, 0, sizeof(addr));

#ifdef WOLFIO_DEBUG
Expand Down Expand Up @@ -801,16 +805,14 @@ int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, word16 port, int to_sec)
*sockfd = (SOCKET_T)socket(addr.ss_family, SOCK_STREAM, 0);

#ifdef USE_WINDOWS_API
if (*sockfd == INVALID_SOCKET) {
if (*sockfd == SOCKET_INVALID)
#else
if (*sockfd <= SOCKET_INVALID)
#endif
{
WOLFSSL_MSG("bad socket fd, out of fds?");
return -1;
}
#else
if (*sockfd < 0) {
WOLFSSL_MSG("bad socket fd, out of fds?");
return -1;
}
#endif

#ifdef HAVE_IO_TIMEOUT
/* if timeout value provided then set socket non-blocking */
Expand All @@ -835,6 +837,8 @@ int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, word16 port, int to_sec)
#endif
if (ret != 0) {
WOLFSSL_MSG("Responder tcp connect failed");
CloseSocket(*sockfd);
*sockfd = SOCKET_INVALID;
return -1;
}
return ret;
Expand Down Expand Up @@ -1283,7 +1287,7 @@ int wolfIO_HttpProcessResponseOcsp(int sfd, byte** respBuf,
int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
{
SOCKET_T sfd = 0;
SOCKET_T sfd = SOCKET_INVALID;
word16 port;
int ret = -1;
#ifdef WOLFSSL_SMALL_STACK
Expand Down Expand Up @@ -1329,7 +1333,7 @@ int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
httpBuf, httpBufSz);

ret = wolfIO_TcpConnect(&sfd, domainName, port, io_timeout_sec);
if ((ret != 0) || ((int)sfd < 0)) {
if (ret != 0) {
WOLFSSL_MSG("OCSP Responder connection failed");
}
else if (wolfIO_Send(sfd, (char*)httpBuf, httpBufSz, 0) !=
Expand All @@ -1345,7 +1349,8 @@ int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
HTTP_SCRATCH_BUFFER_SIZE, ctx);
}

CloseSocket(sfd);
if (sfd != SOCKET_INVALID)
CloseSocket(sfd);
XFREE(httpBuf, ctx, DYNAMIC_TYPE_OCSP);
}
}
Expand Down Expand Up @@ -1403,7 +1408,7 @@ int wolfIO_HttpProcessResponseCrl(WOLFSSL_CRL* crl, int sfd, byte* httpBuf,

int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, int urlSz)
{
SOCKET_T sfd = 0;
SOCKET_T sfd = SOCKET_INVALID;
word16 port;
int ret = -1;
#ifdef WOLFSSL_SMALL_STACK
Expand Down Expand Up @@ -1435,7 +1440,7 @@ int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, int urlSz)
httpBuf, httpBufSz);

ret = wolfIO_TcpConnect(&sfd, domainName, port, io_timeout_sec);
if ((ret != 0) || (sfd < 0)) {
if (ret != 0) {
WOLFSSL_MSG("CRL connection failed");
}
else if (wolfIO_Send(sfd, (char*)httpBuf, httpBufSz, 0)
Expand All @@ -1447,7 +1452,8 @@ int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, int urlSz)
HTTP_SCRATCH_BUFFER_SIZE);
}

CloseSocket(sfd);
if (sfd != SOCKET_INVALID)
CloseSocket(sfd);
XFREE(httpBuf, crl->heap, DYNAMIC_TYPE_CRL);
}
}
Expand Down
Loading