Skip to content

Commit

Permalink
Further fixes with NO_TLS to support use with compatibility layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Dec 17, 2024
1 parent a2b5da8 commit 6151160
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 107 deletions.
16 changes: 10 additions & 6 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ int wolfSSL_BIO_method_type(const WOLFSSL_BIO *b)
}

#ifndef WOLFCRYPT_ONLY
#ifndef NO_TLS
/* Helper function to read from WOLFSSL_BIO_SSL type
*
* returns the number of bytes read on success
Expand Down Expand Up @@ -231,6 +232,7 @@ static int wolfSSL_BIO_SSL_read(WOLFSSL_BIO* bio, void* buf,

return ret;
}
#endif /* !NO_TLS */

static int wolfSSL_BIO_MD_read(WOLFSSL_BIO* bio, void* buf, int sz)
{
Expand All @@ -249,7 +251,7 @@ static int wolfSSL_BIO_MD_read(WOLFSSL_BIO* bio, void* buf, int sz)
}
return sz;
}
#endif /* WOLFCRYPT_ONLY */
#endif /* !WOLFCRYPT_ONLY */


/* Used to read data from a WOLFSSL_BIO structure
Expand Down Expand Up @@ -331,7 +333,7 @@ int wolfSSL_BIO_read(WOLFSSL_BIO* bio, void* buf, int len)
#endif /* !NO_FILESYSTEM */
break;
case WOLFSSL_BIO_SSL:
#ifndef WOLFCRYPT_ONLY
#if !defined(WOLFCRYPT_ONLY) && !defined(NO_TLS)
ret = wolfSSL_BIO_SSL_read(bio, buf, len, front);
#else
WOLFSSL_MSG("WOLFSSL_BIO_SSL used with WOLFCRYPT_ONLY");
Expand Down Expand Up @@ -500,7 +502,7 @@ static int wolfSSL_BIO_BASE64_write(WOLFSSL_BIO* bio, const void* data,
}
#endif /* WOLFSSL_BASE64_ENCODE */

#ifndef WOLFCRYPT_ONLY
#if !defined(WOLFCRYPT_ONLY) && !defined(NO_TLS)
/* Helper function for writing to a WOLFSSL_BIO_SSL type
*
* returns the amount written in bytes on success
Expand Down Expand Up @@ -531,7 +533,7 @@ static int wolfSSL_BIO_SSL_write(WOLFSSL_BIO* bio, const void* data,
}
return ret;
}
#endif /* WOLFCRYPT_ONLY */
#endif /* !WOLFCRYPT_ONLY && !NO_TLS */

/* Writes to a WOLFSSL_BIO_BIO type.
*
Expand Down Expand Up @@ -746,7 +748,7 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
#endif /* !NO_FILESYSTEM */
break;
case WOLFSSL_BIO_SSL:
#ifndef WOLFCRYPT_ONLY
#if !defined(WOLFCRYPT_ONLY) && !defined(NO_TLS)
/* already got eof, again is error */
if (front->eof) {
ret = WOLFSSL_FATAL_ERROR;
Expand Down Expand Up @@ -823,7 +825,7 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
bio = bio->next;
}

#ifndef WOLFCRYPT_ONLY
#if !defined(WOLFCRYPT_ONLY) && !defined(NO_TLS)
exit_chain:
#endif

Expand Down Expand Up @@ -2560,6 +2562,7 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
return ret;
}

#ifndef NO_TLS
long wolfSSL_BIO_do_handshake(WOLFSSL_BIO *b)
{
WOLFSSL_ENTER("wolfSSL_BIO_do_handshake");
Expand Down Expand Up @@ -2605,6 +2608,7 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
WOLFSSL_MSG("BIO has no SSL pointer set.");
}
}
#endif

long wolfSSL_BIO_set_ssl(WOLFSSL_BIO* b, WOLFSSL* ssl, int closeF)
{
Expand Down
8 changes: 4 additions & 4 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ WOLFSSL_CALLBACKS needs LARGE_STATIC_BUFFERS, please add LARGE_STATIC_BUFFERS
#else
#define SSL_TICKET_CTX(ssl) ssl->ctx->ticketEncCtx
#endif
#if !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
#if !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_TLS)
static int TicketEncCbCtx_Init(WOLFSSL_CTX* ctx,
TicketEncCbCtx* keyCtx);
static void TicketEncCbCtx_Free(TicketEncCbCtx* keyCtx);
Expand Down Expand Up @@ -2493,7 +2493,7 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap)
#endif /* HAVE_EXTENDED_MASTER && !NO_WOLFSSL_CLIENT */

#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
#ifndef WOLFSSL_NO_DEF_TICKET_ENC_CB
#if !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_TLS)
ret = TicketEncCbCtx_Init(ctx, &ctx->ticketKeyCtx);
if (ret != 0) return ret;
ctx->ticketEncCb = DefTicketEncCb;
Expand Down Expand Up @@ -2798,7 +2798,7 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx)

SSL_CtxResourceFree(ctx);
#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
!defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
!defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_TLS)
TicketEncCbCtx_Free(&ctx->ticketKeyCtx);
#endif
wolfSSL_RefFree(&ctx->ref);
Expand Down Expand Up @@ -39292,7 +39292,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
return ret;
}

#ifndef WOLFSSL_NO_DEF_TICKET_ENC_CB
#if !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_TLS)

/* Initialize the context for session ticket encryption.
*
Expand Down
26 changes: 15 additions & 11 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4136,7 +4136,7 @@ int wolfSSL_shutdown(WOLFSSL* ssl)

return ret;
}

#endif /* !NO_TLS */

/* get current error state value */
int wolfSSL_state(WOLFSSL* ssl)
Expand Down Expand Up @@ -4213,7 +4213,6 @@ int wolfSSL_want_read(WOLFSSL* ssl)
return 0;
}


/* return TRUE if current error is want write */
int wolfSSL_want_write(WOLFSSL* ssl)
{
Expand All @@ -4224,8 +4223,6 @@ int wolfSSL_want_write(WOLFSSL* ssl)
return 0;
}

#endif /* !NO_TLS */

char* wolfSSL_ERR_error_string(unsigned long errNumber, char* data)
{
WOLFSSL_ENTER("wolfSSL_ERR_error_string");
Expand Down Expand Up @@ -9307,7 +9304,7 @@ int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,


/* EITHER SIDE METHODS */
#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
#if !defined(NO_TLS) && (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE))
WOLFSSL_METHOD* wolfSSLv23_method(void)
{
return wolfSSLv23_method_ex(NULL);
Expand Down Expand Up @@ -9353,7 +9350,7 @@ int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
}
#endif
#endif
#endif /* OPENSSL_EXTRA || WOLFSSL_EITHER_SIDE */
#endif /* !NO_TLS && (OPENSSL_EXTRA || WOLFSSL_EITHER_SIDE) */

/* client only parts */
#if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS)
Expand Down Expand Up @@ -11409,6 +11406,8 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
}
return WOLFSSL_FAILURE;
}

#ifndef NO_TLS
WOLFSSL_CIPHERSUITE_INFO wolfSSL_get_ciphersuite_info(byte first,
byte second)
{
Expand All @@ -11424,6 +11423,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
info.psk = (byte)CipherRequires(first, second, REQUIRES_PSK);
return info;
}
#endif

/**
* @param first First byte of the hash and signature algorithm
Expand Down Expand Up @@ -15853,6 +15853,7 @@ int wolfSSL_ERR_GET_REASON(unsigned long err)
return ret;
}

#ifndef NO_TLS
/* returns a string that describes the alert
*
* alertID the alert value to look up
Expand All @@ -15864,13 +15865,13 @@ const char* wolfSSL_alert_type_string_long(int alertID)
return AlertTypeToString(alertID);
}


const char* wolfSSL_alert_desc_string_long(int alertID)
{
WOLFSSL_ENTER("wolfSSL_alert_desc_string_long");

return AlertTypeToString(alertID);
}
#endif /* !NO_TLS */

#define STATE_STRINGS_PROTO(s) \
{ \
Expand Down Expand Up @@ -16663,7 +16664,7 @@ long wolfSSL_set_tlsext_status_ocsp_resp(WOLFSSL *s, unsigned char *resp,
#endif /* HAVE_OCSP */

#ifdef HAVE_MAX_FRAGMENT
#ifndef NO_WOLFSSL_CLIENT
#if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS)
/**
* Set max fragment tls extension
* @param c a pointer to WOLFSSL_CTX object
Expand Down Expand Up @@ -16691,7 +16692,7 @@ int wolfSSL_set_tlsext_max_fragment_length(WOLFSSL *s, unsigned char mode)

return wolfSSL_UseMaxFragment(s, mode);
}
#endif /* NO_WOLFSSL_CLIENT */
#endif /* !NO_WOLFSSL_CLIENT && !NO_TLS */
#endif /* HAVE_MAX_FRAGMENT */

#endif /* OPENSSL_EXTRA */
Expand Down Expand Up @@ -21317,6 +21318,7 @@ WOLFSSL_BIO *wolfSSL_SSL_get_wbio(const WOLFSSL *s)
}
#endif /* !NO_BIO */

#ifndef NO_TLS
int wolfSSL_SSL_do_handshake_internal(WOLFSSL *s)
{
WOLFSSL_ENTER("wolfSSL_SSL_do_handshake_internal");
Expand Down Expand Up @@ -21350,6 +21352,7 @@ int wolfSSL_SSL_do_handshake(WOLFSSL *s)
#endif
return wolfSSL_SSL_do_handshake_internal(s);
}
#endif /* !NO_TLS */

#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
int wolfSSL_SSL_in_init(const WOLFSSL *ssl)
Expand Down Expand Up @@ -22205,7 +22208,7 @@ int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names,
else {
disabled &= ~(1U << curve);
}
#ifdef HAVE_SUPPORTED_CURVES
#if defined(HAVE_SUPPORTED_CURVES) && !defined(NO_TLS)
#if !defined(WOLFSSL_OLD_SET_CURVES_LIST)
/* using the wolfSSL API to set the groups, this will populate
* (ssl|ctx)->groups and reset any TLSX_SUPPORTED_GROUPS.
Expand All @@ -22228,7 +22231,7 @@ int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names,
goto leave;
}
#endif
#endif /* HAVE_SUPPORTED_CURVES */
#endif /* HAVE_SUPPORTED_CURVES && !NO_TLS */
}

if (ssl != NULL)
Expand Down Expand Up @@ -22267,6 +22270,7 @@ int wolfSSL_set1_curves_list(WOLFSSL* ssl, const char* names)
#endif /* (HAVE_ECC || HAVE_CURVE25519 || HAVE_CURVE448) */
#endif /* OPENSSL_EXTRA || HAVE_CURL */


#ifdef OPENSSL_EXTRA
/* Sets a callback for when sending and receiving protocol messages.
* This callback is copied to all WOLFSSL objects created from the ctx.
Expand Down
4 changes: 2 additions & 2 deletions src/ssl_sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ int wolfSSL_set_timeout(WOLFSSL* ssl, unsigned int to)
return WOLFSSL_SUCCESS;
}


#ifndef NO_TLS
/**
* Sets ctx session timeout in seconds.
* The timeout value set here should be reflected in the
Expand Down Expand Up @@ -932,7 +932,7 @@ int wolfSSL_CTX_set_timeout(WOLFSSL_CTX* ctx, unsigned int to)
return ret;
#endif /* WOLFSSL_ERROR_CODE_OPENSSL */
}

#endif /* !NO_TLS */

#ifndef NO_CLIENT_CACHE

Expand Down
Loading

0 comments on commit 6151160

Please sign in to comment.