From 5adc661d05ea0ab75e68674aae3ba6b2a7795824 Mon Sep 17 00:00:00 2001 From: dongheng Date: Wed, 21 Sep 2016 09:23:29 +0800 Subject: [PATCH] components/openssl: add more interface for application --- components/openssl/Makefile | 50 ------------- components/openssl/Makefile.projbuild | 4 ++ components/openssl/component.mk | 9 +++ components/openssl/include/internal/ssl_lib.h | 5 -- .../openssl/include/internal/ssl_pkey.h | 2 + components/openssl/include/platform/ssl_pm.h | 3 +- components/openssl/library/Makefile | 46 ------------ components/openssl/library/ssl_cert.c | 1 + components/openssl/library/ssl_lib.c | 72 ++++++++++++++++++- components/openssl/platform/Makefile | 46 ------------ components/openssl/platform/ssl_pm.c | 6 +- 11 files changed, 92 insertions(+), 152 deletions(-) delete mode 100644 components/openssl/Makefile create mode 100644 components/openssl/Makefile.projbuild create mode 100644 components/openssl/component.mk delete mode 100644 components/openssl/library/Makefile delete mode 100644 components/openssl/platform/Makefile diff --git a/components/openssl/Makefile b/components/openssl/Makefile deleted file mode 100644 index bdd8a0e932..0000000000 --- a/components/openssl/Makefile +++ /dev/null @@ -1,50 +0,0 @@ - -############################################################# -# Required variables for each makefile -# Discard this section from all parent makefiles -# Expected variables (with automatic defaults): -# CSRCS (all "C" files in the dir) -# SUBDIRS (all subdirs with a Makefile) -# GEN_LIBS - list of libs to be generated () -# GEN_IMAGES - list of images to be generated () -# COMPONENTS_xxx - a list of libs/objs in the form -# subdir/lib to be extracted and rolled up into -# a generated lib/image xxx.a () -# -ifndef PDIR - -UP_EXTRACT_DIR = .. -GEN_LIBS = libopenssl.a -COMPONENTS_libopenssl = library/liblibrary.a platform/libplatform.a - -endif - - -############################################################# -# Configuration i.e. compile options etc. -# Target specific stuff (defines etc.) goes in here! -# Generally values applying to a tree are captured in the -# makefile at its root level - these are then overridden -# for a subtree within the makefile rooted therein -# -#DEFINES += - -############################################################# -# Recursion Magic - Don't touch this!! -# -# Each subtree potentially has an include directory -# corresponding to the common APIs applicable to modules -# rooted at that subtree. Accordingly, the INCLUDE PATH -# of a module can only contain the include directories up -# its parent path, and not its siblings -# -# Required for each makefile to inherit from the parent -# - -INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)include/platform -I $(PDIR)include/internal -INCLUDES += -I ./inlcude -INCLUDES += -I $(SDK_PATH)/include/openssl/internal -INCLUDES += -I ./ -PDIR := ../$(PDIR) -sinclude $(PDIR)Makefile - diff --git a/components/openssl/Makefile.projbuild b/components/openssl/Makefile.projbuild new file mode 100644 index 0000000000..51300efd11 --- /dev/null +++ b/components/openssl/Makefile.projbuild @@ -0,0 +1,4 @@ +# Anyone compiling mbedTLS code needs the name of the +# alternative config file +CFLAGS += -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' + diff --git a/components/openssl/component.mk b/components/openssl/component.mk new file mode 100644 index 0000000000..97de6975c9 --- /dev/null +++ b/components/openssl/component.mk @@ -0,0 +1,9 @@ +# +# Component Makefile +# + +COMPONENT_ADD_INCLUDEDIRS := include include/internal include/platform include/oepnssl + +COMPONENT_SRCDIRS := library platform + +include $(IDF_PATH)/make/component_common.mk diff --git a/components/openssl/include/internal/ssl_lib.h b/components/openssl/include/internal/ssl_lib.h index d95d219556..0881fbbfdb 100644 --- a/components/openssl/include/internal/ssl_lib.h +++ b/components/openssl/include/internal/ssl_lib.h @@ -3,9 +3,4 @@ #include "ssl_types.h" -#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING) -#define SSL_want_read(s) (SSL_want(s) == SSL_READING) -#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING) -#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_WRITING) - #endif diff --git a/components/openssl/include/internal/ssl_pkey.h b/components/openssl/include/internal/ssl_pkey.h index cc870e18ed..c7170244a6 100644 --- a/components/openssl/include/internal/ssl_pkey.h +++ b/components/openssl/include/internal/ssl_pkey.h @@ -8,4 +8,6 @@ EVP_PKEY *d2i_PrivateKey(int type, const unsigned char **pp, long length); +void EVP_PKEY_free(EVP_PKEY *x); + #endif diff --git a/components/openssl/include/platform/ssl_pm.h b/components/openssl/include/platform/ssl_pm.h index c75ae95af5..a6731cff7f 100644 --- a/components/openssl/include/platform/ssl_pm.h +++ b/components/openssl/include/platform/ssl_pm.h @@ -2,7 +2,8 @@ #define _SSL_PM_H_ #include "ssl_types.h" -#include "esp_common.h" +#include "esp_types.h" +#include "esp_system.h" void* ssl_zalloc(size_t size); void *ssl_malloc(size_t size); diff --git a/components/openssl/library/Makefile b/components/openssl/library/Makefile deleted file mode 100644 index 10f4067c64..0000000000 --- a/components/openssl/library/Makefile +++ /dev/null @@ -1,46 +0,0 @@ - -############################################################# -# Required variables for each makefile -# Discard this section from all parent makefiles -# Expected variables (with automatic defaults): -# CSRCS (all "C" files in the dir) -# SUBDIRS (all subdirs with a Makefile) -# GEN_LIBS - list of libs to be generated () -# GEN_IMAGES - list of images to be generated () -# COMPONENTS_xxx - a list of libs/objs in the form -# subdir/lib to be extracted and rolled up into -# a generated lib/image xxx.a () -# -ifndef PDIR - -GEN_LIBS = liblibrary.a - -endif - - -############################################################# -# Configuration i.e. compile options etc. -# Target specific stuff (defines etc.) goes in here! -# Generally values applying to a tree are captured in the -# makefile at its root level - these are then overridden -# for a subtree within the makefile rooted therein -# -#DEFINES += - -############################################################# -# Recursion Magic - Don't touch this!! -# -# Each subtree potentially has an include directory -# corresponding to the common APIs applicable to modules -# rooted at that subtree. Accordingly, the INCLUDE PATH -# of a module can only contain the include directories up -# its parent path, and not its siblings -# -# Required for each makefile to inherit from the parent -# - -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -PDIR := ../$(PDIR) -sinclude $(PDIR)Makefile - diff --git a/components/openssl/library/ssl_cert.c b/components/openssl/library/ssl_cert.c index 10f723bfcb..5332592460 100644 --- a/components/openssl/library/ssl_cert.c +++ b/components/openssl/library/ssl_cert.c @@ -1,4 +1,5 @@ #include "ssl_cert.h" +#include "ssl_dbg.h" #include "ssl_pm.h" CERT *ssl_cert_new(void) diff --git a/components/openssl/library/ssl_lib.c b/components/openssl/library/ssl_lib.c index ad78f3961a..e1e112cc7b 100644 --- a/components/openssl/library/ssl_lib.c +++ b/components/openssl/library/ssl_lib.c @@ -6,7 +6,7 @@ #define SSL_SEND_DATA_MAX_LENGTH 1460 -static int ossl_statem_in_error(const SSL *ssl) +int ossl_statem_in_error(const SSL *ssl) { if (ssl->statem.state == MSG_FLOW_ERROR) return 1; @@ -14,6 +14,74 @@ static int ossl_statem_in_error(const SSL *ssl) return 0; } +/* + * SSL_want - get the SSL specifical statement + * + * @param ssl - SSL point + * + * @return specifical statement + */ +int SSL_want(const SSL *ssl) +{ + return 0; +} + +/* + * SSL_want_nothing - check if SSL want nothing + * + * @param ssl - SSL point + * + * @return + * 1 : yes + * 0 : no + */ +int SSL_want_nothing(const SSL *ssl) +{ + return (SSL_want(ssl) == SSL_NOTHING); +} + +/* + * SSL_want_read - check if SSL want to read + * + * @param ssl - SSL point + * + * @return + * 1 : yes + * 0 : no + */ +int SSL_want_read(const SSL *ssl) +{ + return (SSL_want(ssl) == SSL_READING); +} + +/* + * SSL_want_read - check if SSL want to write + * + * @param ssl - SSL point + * + * @return + * 1 : yes + * 0 : no + */ +int SSL_want_write(const SSL *ssl) +{ + return (SSL_want(ssl) == SSL_WRITING); +} + +/* + * SSL_want_read - check if SSL want to lookup X509 certification + * + * @param ssl - SSL point + * + * @return + * 1 : yes + * 0 : no + */ +int SSL_want_x509_lookup(const SSL *ssl) +{ + return (SSL_want(ssl) == SSL_WRITING); +} + /* * SSL_get_error - get SSL error code * @@ -1153,7 +1221,7 @@ char *SSL_state_string(const SSL *ssl) SSL_ASSERT(ssl); - if (ossl_state_in_error(ssl)) + if (ossl_statem_in_error(ssl)) str = "SSLERR"; else { diff --git a/components/openssl/platform/Makefile b/components/openssl/platform/Makefile deleted file mode 100644 index 749b4787ca..0000000000 --- a/components/openssl/platform/Makefile +++ /dev/null @@ -1,46 +0,0 @@ - -############################################################# -# Required variables for each makefile -# Discard this section from all parent makefiles -# Expected variables (with automatic defaults): -# CSRCS (all "C" files in the dir) -# SUBDIRS (all subdirs with a Makefile) -# GEN_LIBS - list of libs to be generated () -# GEN_IMAGES - list of images to be generated () -# COMPONENTS_xxx - a list of libs/objs in the form -# subdir/lib to be extracted and rolled up into -# a generated lib/image xxx.a () -# -ifndef PDIR - -GEN_LIBS = libplatform.a - -endif - - -############################################################# -# Configuration i.e. compile options etc. -# Target specific stuff (defines etc.) goes in here! -# Generally values applying to a tree are captured in the -# makefile at its root level - these are then overridden -# for a subtree within the makefile rooted therein -# -#DEFINES += - -############################################################# -# Recursion Magic - Don't touch this!! -# -# Each subtree potentially has an include directory -# corresponding to the common APIs applicable to modules -# rooted at that subtree. Accordingly, the INCLUDE PATH -# of a module can only contain the include directories up -# its parent path, and not its siblings -# -# Required for each makefile to inherit from the parent -# - -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -PDIR := ../$(PDIR) -sinclude $(PDIR)Makefile - diff --git a/components/openssl/platform/ssl_pm.c b/components/openssl/platform/ssl_pm.c index 831420180c..9d207b3a0e 100644 --- a/components/openssl/platform/ssl_pm.c +++ b/components/openssl/platform/ssl_pm.c @@ -1,6 +1,8 @@ #include "ssl_pm.h" #include "ssl_dbg.h" +#include + /* mbedtls include */ #include "mbedtls/platform.h" #include "mbedtls/net.h" @@ -55,7 +57,7 @@ void* ssl_zalloc(size_t size) void *ssl_malloc(size_t size) { - return zalloc(size); + return ssl_zalloc(size); } void ssl_free(void *p) @@ -140,7 +142,7 @@ int ssl_pm_new(SSL *ssl) ret = mbedtls_ssl_conf_own_cert(&ssl_pm->conf, &x509_pm->x509_crt, &pkey_pm->pkey); if (ret) - SSL_ERR(ret, failed4, "mbedtls_ssl_conf_own_cert:[%d]\n", ret); + SSL_ERR(ret, failed3, "mbedtls_ssl_conf_own_cert:[%d]\n", ret); } ret = mbedtls_ssl_setup(&ssl_pm->ssl, &ssl_pm->conf);