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.
1 change: 1 addition & 0 deletions certs/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ EXTRA_DIST += \
certs/ecc-key.pem \
certs/ecc-privkey.pem \
certs/ecc-privkeyPkcs8.pem \
certs/ecc-privkeyPkcs8.der \
certs/ecc-keyPkcs8Enc.pem \
certs/ecc-keyPkcs8Enc.der \
certs/ecc-key-comp.pem \
Expand Down
25 changes: 18 additions & 7 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4917,6 +4917,7 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
{
DerBuffer* der = NULL; /* holds DER or RAW (for NTRU) */
int ret = 0;
int keyFormat = 0;
int eccKey = 0;
int ed25519Key = 0;
int rsaKey = 0;
Expand Down Expand Up @@ -4964,7 +4965,9 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,

if (format == WOLFSSL_FILETYPE_PEM) {
#ifdef WOLFSSL_PEM_TO_DER
ret = PemToDer(buff, sz, type, &der, heap, info, &eccKey);
ret = PemToDer(buff, sz, type, &der, heap, info, &keyFormat);
if (keyFormat == ECDSAk)
eccKey = 1;
#else
ret = NOT_COMPILED_IN;
#endif
Expand Down Expand Up @@ -29420,21 +29423,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
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