From 86112a574f86b4023940ce4353f56afbfc1f66ce Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Tue, 2 May 2017 09:32:35 -0600 Subject: [PATCH] implement X509 store ctx get ssl idx --- src/ssl.c | 13 ++++++---- tests/api.c | 68 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index c7e4b6dbe..3a6bedafd 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -18766,14 +18766,19 @@ void* wolfSSL_X509_STORE_CTX_get_ex_data(WOLFSSL_X509_STORE_CTX* ctx, int idx) return 0; } -#ifndef NO_WOLFSSL_STUB + +/* Gets an index to store SSL structure at. + * + * Returns positive index on success and negative values on failure + */ int wolfSSL_get_ex_data_X509_STORE_CTX_idx(void) { - WOLFSSL_ENTER("SSL_get_ex_data_X509_STORE_CTX_idx"); - WOLFSSL_STUB("SSL_get_ex_data_X509_STORE_CTX_idx"); + WOLFSSL_ENTER("wolfSSL_get_ex_data_X509_STORE_CTX_idx"); + + /* store SSL at index 0 */ return 0; } -#endif + /* Sets a function callback that will send information about the state of all * WOLFSSL objects that have been created by the WOLFSSL_CTX structure passed diff --git a/tests/api.c b/tests/api.c index 76b05a8c8..0d506b4a1 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14325,6 +14325,47 @@ static void test_wolfSSL_ERR_peek_last_error_line(void) !defined(NO_FILESYSTEM) && !defined(DEBUG_WOLFSSL) */ } +#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \ + !defined(NO_FILESYSTEM) && !defined(NO_RSA) +static int verify_cb(int ok, X509_STORE_CTX *ctx) +{ + (void) ok; + (void) ctx; + printf("ENTER verify_cb\n"); + return SSL_SUCCESS; +} +#endif + + + +static void test_wolfSSL_X509_STORE_CTX(void) +{ + #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \ + !defined(NO_FILESYSTEM) && !defined(NO_RSA) + + X509_STORE_CTX* ctx; + X509_STORE* str; + X509* x509; + + printf(testingFmt, "wolfSSL_X509_STORE_CTX()"); + AssertNotNull(ctx = X509_STORE_CTX_new()); + AssertNotNull((str = wolfSSL_X509_STORE_new())); + AssertNotNull((x509 = + wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM))); + AssertIntEQ(X509_STORE_add_cert(str, x509), SSL_SUCCESS); + AssertIntEQ(X509_STORE_CTX_init(ctx, str, x509, NULL), SSL_SUCCESS); + AssertIntEQ(SSL_get_ex_data_X509_STORE_CTX_idx(), 0); + + X509_STORE_CTX_free(ctx); + + AssertNotNull(ctx = X509_STORE_CTX_new()); + X509_STORE_CTX_set_verify_cb(ctx, (void *)verify_cb); + X509_STORE_CTX_free(ctx); + + printf(resultFmt, passed); + #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \ + !defined(NO_FILESYSTEM) && !defined(NO_RSA) */ +} static void test_wolfSSL_X509_STORE_set_flags(void) { @@ -14334,7 +14375,7 @@ static void test_wolfSSL_X509_STORE_set_flags(void) X509_STORE* store; X509* x509; - printf(testingFmt, "wolfSSL_ERR_peek_last_error_line()"); + printf(testingFmt, "wolfSSL_X509_STORE_set_flags()"); AssertNotNull((store = wolfSSL_X509_STORE_new())); AssertNotNull((x509 = wolfSSL_X509_load_certificate_file(svrCertFile, WOLFSSL_FILETYPE_PEM))); @@ -14860,29 +14901,6 @@ static void test_wolfSSL_set_options(void) !defined(NO_FILESYSTEM) && !defined(NO_RSA) */ } -#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) -static int verify_cb(int ok, X509_STORE_CTX *ctx) -{ - (void) ok; - (void) ctx; - printf("ENTER verify_cb\n"); - return SSL_SUCCESS; -} -#endif - -static void test_wolfSSL_X509_STORE_CTX(void) -{ -#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) - X509_STORE_CTX *ctx = NULL ; - - printf(testingFmt, "test_wolfSSL_X509_STORE_CTX(()"); - AssertNotNull(ctx = X509_STORE_CTX_new()); - X509_STORE_CTX_set_verify_cb(ctx, (void *)verify_cb); - X509_STORE_CTX_free(ctx); - printf(resultFmt, passed); - #endif -} - /* Testing wolfSSL_set_tlsext_status_type funciton. * PRE: OPENSSL and HAVE_CERTIFICATE_STATUS_REQUEST defined. */ @@ -16790,8 +16808,6 @@ void ApiTest(void) test_wolfSSL_X509_NID(); test_wolfSSL_X509_STORE_CTX_set_time(); test_wolfSSL_BN(); - test_wolfSSL_set_options(); - test_wolfSSL_X509_STORE_CTX(); test_wolfSSL_PEM_read_bio(); test_wolfSSL_BIO(); test_wolfSSL_ASN1_STRING();