forked from wolfSSL/wolfssl
implement WOLFSSL get app data and set app data functions
This commit is contained in:
37
src/ssl.c
37
src/ssl.c
@@ -28694,14 +28694,6 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl)
|
||||
}
|
||||
#endif
|
||||
|
||||
void* wolfSSL_get_app_data( const WOLFSSL *ssl) {
|
||||
/* checkout exdata stuff... */
|
||||
return wolfSSL_get_ex_data(ssl,0);
|
||||
}
|
||||
|
||||
int wolfSSL_set_app_data(WOLFSSL *ssl, void *arg) {
|
||||
return wolfSSL_set_ex_data(ssl,0,(char *)arg);
|
||||
}
|
||||
|
||||
#ifndef NO_WOLFSSL_STUB
|
||||
WOLFSSL_ASN1_OBJECT * wolfSSL_X509_NAME_ENTRY_get_object(WOLFSSL_X509_NAME_ENTRY *ne) {
|
||||
@@ -28898,6 +28890,33 @@ int wolfSSL_CTX_set_ex_data(WOLFSSL_CTX* ctx, int idx, void* data)
|
||||
}
|
||||
|
||||
|
||||
/* Returns char* to app data stored in ex[0].
|
||||
*
|
||||
* ssl WOLFSSL structure to get app data from
|
||||
*/
|
||||
void* wolfSSL_get_app_data(const WOLFSSL *ssl)
|
||||
{
|
||||
/* checkout exdata stuff... */
|
||||
WOLFSSL_ENTER("wolfSSL_get_app_data");
|
||||
|
||||
return wolfSSL_get_ex_data(ssl, 0);
|
||||
}
|
||||
|
||||
|
||||
/* Set ex array 0 to have app data
|
||||
*
|
||||
* ssl WOLFSSL struct to set app data in
|
||||
* arg data to be stored
|
||||
*
|
||||
* Returns SSL_SUCCESS on sucess and SSL_FAILURE on failure
|
||||
*/
|
||||
int wolfSSL_set_app_data(WOLFSSL *ssl, void* arg) {
|
||||
WOLFSSL_ENTER("wolfSSL_set_app_data");
|
||||
|
||||
return wolfSSL_set_ex_data(ssl, 0, arg);
|
||||
}
|
||||
|
||||
|
||||
int wolfSSL_set_ex_data(WOLFSSL* ssl, int idx, void* data)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_set_ex_data");
|
||||
@@ -28908,6 +28927,7 @@ int wolfSSL_set_ex_data(WOLFSSL* ssl, int idx, void* data)
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
#else
|
||||
WOLFSSL_MSG("HAVE_EX_DATA macro is not defined");
|
||||
(void)ssl;
|
||||
(void)idx;
|
||||
(void)data;
|
||||
@@ -28924,6 +28944,7 @@ void* wolfSSL_get_ex_data(const WOLFSSL* ssl, int idx)
|
||||
if (ssl != NULL && idx < MAX_EX_DATA && idx >= 0)
|
||||
return ssl->ex_data[idx];
|
||||
#else
|
||||
WOLFSSL_MSG("HAVE_EX_DATA macro is not defined");
|
||||
(void)ssl;
|
||||
(void)idx;
|
||||
#endif
|
||||
|
10
tests/api.c
10
tests/api.c
@@ -14781,6 +14781,7 @@ static void test_wolfSSL_set_options(void)
|
||||
!defined(NO_FILESYSTEM) && !defined(NO_RSA)
|
||||
SSL* ssl;
|
||||
SSL_CTX* ctx;
|
||||
char appData[] = "extra msg";
|
||||
|
||||
unsigned char protos[] = {
|
||||
7, 't', 'l', 's', '/', '1', '.', '2',
|
||||
@@ -14817,6 +14818,15 @@ static void test_wolfSSL_set_options(void)
|
||||
AssertTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
|
||||
|
||||
AssertNotNull(ssl = SSL_new(ctx));
|
||||
#if defined(HAVE_EX_DATA) || defined(FORTRESS)
|
||||
AssertIntEQ(SSL_set_app_data(ssl, (void*)appData), SSL_SUCCESS);
|
||||
AssertNotNull(SSL_get_app_data((const WOLFSSL*)ssl));
|
||||
AssertIntEQ(XMEMCMP(SSL_get_app_data((const WOLFSSL*)ssl),
|
||||
appData, sizeof(appData)), 0);
|
||||
#else
|
||||
AssertIntEQ(SSL_set_app_data(ssl, (void*)appData), SSL_FAILURE);
|
||||
AssertNull(SSL_get_app_data((const WOLFSSL*)ssl));
|
||||
#endif
|
||||
|
||||
AssertTrue(SSL_set_options(ssl, SSL_OP_NO_TLSv1) == SSL_OP_NO_TLSv1);
|
||||
AssertTrue(SSL_get_options(ssl) == SSL_OP_NO_TLSv1);
|
||||
|
Reference in New Issue
Block a user