mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
openssl_mbedtls_wrapper: add ssl wrapper from libwebsockets
Signed-off-by: makejian <makejian@xiaomi.com>
This commit is contained in:
parent
f1ace3774f
commit
f7582e34e5
28 changed files with 4329 additions and 10 deletions
|
|
@ -57,11 +57,9 @@ typedef struct BN_CTX BN_CTX;
|
|||
typedef struct EC_GROUP EC_GROUP;
|
||||
typedef struct EC_KEY EC_KEY;
|
||||
typedef struct EC_POINT EC_POINT;
|
||||
typedef struct EVP_PKEY EVP_PKEY;
|
||||
typedef struct evp_pkey_st EVP_PKEY;
|
||||
typedef struct EVP_PKEY_CTX EVP_PKEY_CTX;
|
||||
typedef struct PKCS8_PRIV_KEY_INFO PKCS8_PRIV_KEY_INFO;
|
||||
typedef struct RSA RSA;
|
||||
typedef struct X509 X509;
|
||||
typedef struct X509_ALGOR X509_ALGOR;
|
||||
typedef struct X509_EXTENSION X509_EXTENSION;
|
||||
typedef struct X509_NAME X509_NAME;
|
||||
|
|
@ -74,6 +72,7 @@ typedef struct sha256_state_st SHA256_CTX;
|
|||
typedef struct sha_state_st SHA_CTX;
|
||||
typedef struct cbb_st CBB;
|
||||
typedef struct ecdsa_sig_st ECDSA_SIG;
|
||||
typedef void RSA;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ extern "C"
|
|||
|
||||
unsigned long ERR_peek_last_error(void);
|
||||
void ERR_error_string_n(unsigned long e, char *buf, size_t len);
|
||||
void ERR_free_strings(void);
|
||||
char *ERR_error_string(unsigned long e, char *buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include <openssl/ec_key.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/nid.h>
|
||||
#include <openssl/types.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
|
@ -41,6 +42,12 @@
|
|||
|
||||
#define EVP_PKEY_X25519 NID_X25519
|
||||
|
||||
struct evp_pkey_st
|
||||
{
|
||||
void *pkey_pm;
|
||||
const PKEY_METHOD *method;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
|
@ -56,6 +63,8 @@ RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey);
|
|||
|
||||
int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key);
|
||||
|
||||
EVP_PKEY *__EVP_PKEY_new(EVP_PKEY *ipk);
|
||||
|
||||
EVP_PKEY *EVP_PKEY_new(void);
|
||||
|
||||
void EVP_PKEY_free(EVP_PKEY *pkey);
|
||||
|
|
@ -153,6 +162,8 @@ int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len,
|
|||
unsigned iterations, const EVP_MD *digest,
|
||||
size_t key_len, uint8_t *out_key);
|
||||
|
||||
const PKEY_METHOD *EVP_PKEY_method(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
305
crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h
Normal file
305
crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h
Normal file
|
|
@ -0,0 +1,305 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_SSL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/x509_vfy.h>
|
||||
#include <openssl/tls1.h>
|
||||
|
||||
/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
|
||||
#define SSL_SENT_SHUTDOWN 1
|
||||
#define SSL_RECEIVED_SHUTDOWN 2
|
||||
|
||||
#define SSL_VERIFY_NONE 0x00
|
||||
#define SSL_VERIFY_PEER 0x01
|
||||
#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
|
||||
#define SSL_VERIFY_CLIENT_ONCE 0x04
|
||||
|
||||
/* The following 3 states are kept in ssl->rlayer.rstate when reads fail, you
|
||||
* should not need these
|
||||
*/
|
||||
#define SSL_ST_READ_HEADER 0xF0
|
||||
#define SSL_ST_READ_BODY 0xF1
|
||||
#define SSL_ST_READ_DONE 0xF2
|
||||
|
||||
#define SSL_NOTHING 1
|
||||
#define SSL_WRITING 2
|
||||
#define SSL_READING 3
|
||||
#define SSL_X509_LOOKUP 4
|
||||
#define SSL_ASYNC_PAUSED 5
|
||||
#define SSL_ASYNC_NO_JOBS 6
|
||||
|
||||
#define SSL_ERROR_NONE 0
|
||||
#define SSL_ERROR_SSL 1
|
||||
#define SSL_ERROR_WANT_READ 2
|
||||
#define SSL_ERROR_WANT_WRITE 3
|
||||
#define SSL_ERROR_WANT_X509_LOOKUP 4
|
||||
#define SSL_ERROR_SYSCALL 5/* look at error stack/return value/errno */
|
||||
#define SSL_ERROR_ZERO_RETURN 6
|
||||
#define SSL_ERROR_WANT_CONNECT 7
|
||||
#define SSL_ERROR_WANT_ACCEPT 8
|
||||
#define SSL_ERROR_WANT_ASYNC 9
|
||||
#define SSL_ERROR_WANT_ASYNC_JOB 10
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TLS_ST_BEFORE,
|
||||
TLS_ST_OK,
|
||||
DTLS_ST_CR_HELLO_VERIFY_REQUEST,
|
||||
TLS_ST_CR_SRVR_HELLO,
|
||||
TLS_ST_CR_CERT,
|
||||
TLS_ST_CR_CERT_STATUS,
|
||||
TLS_ST_CR_KEY_EXCH,
|
||||
TLS_ST_CR_CERT_REQ,
|
||||
TLS_ST_CR_SRVR_DONE,
|
||||
TLS_ST_CR_SESSION_TICKET,
|
||||
TLS_ST_CR_CHANGE,
|
||||
TLS_ST_CR_FINISHED,
|
||||
TLS_ST_CW_CLNT_HELLO,
|
||||
TLS_ST_CW_CERT,
|
||||
TLS_ST_CW_KEY_EXCH,
|
||||
TLS_ST_CW_CERT_VRFY,
|
||||
TLS_ST_CW_CHANGE,
|
||||
TLS_ST_CW_NEXT_PROTO,
|
||||
TLS_ST_CW_FINISHED,
|
||||
TLS_ST_SW_HELLO_REQ,
|
||||
TLS_ST_SR_CLNT_HELLO,
|
||||
DTLS_ST_SW_HELLO_VERIFY_REQUEST,
|
||||
TLS_ST_SW_SRVR_HELLO,
|
||||
TLS_ST_SW_CERT,
|
||||
TLS_ST_SW_KEY_EXCH,
|
||||
TLS_ST_SW_CERT_REQ,
|
||||
TLS_ST_SW_SRVR_DONE,
|
||||
TLS_ST_SR_CERT,
|
||||
TLS_ST_SR_KEY_EXCH,
|
||||
TLS_ST_SR_CERT_VRFY,
|
||||
TLS_ST_SR_NEXT_PROTO,
|
||||
TLS_ST_SR_CHANGE,
|
||||
TLS_ST_SR_FINISHED,
|
||||
TLS_ST_SW_SESSION_TICKET,
|
||||
TLS_ST_SW_CERT_STATUS,
|
||||
TLS_ST_SW_CHANGE,
|
||||
TLS_ST_SW_FINISHED
|
||||
}
|
||||
OSSL_HANDSHAKE_STATE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl);
|
||||
|
||||
int X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param,
|
||||
unsigned long flags);
|
||||
|
||||
int X509_VERIFY_PARAM_clear_hostflags(X509_VERIFY_PARAM *param,
|
||||
unsigned long flags);
|
||||
|
||||
int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);
|
||||
|
||||
int SSL_CTX_add_client_CA_ASN1(SSL_CTX *ssl, int len,
|
||||
const unsigned char *d);
|
||||
|
||||
int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
|
||||
|
||||
int SSL_use_certificate(SSL *ssl, X509 *x);
|
||||
|
||||
X509 *SSL_get_certificate(const SSL *ssl);
|
||||
|
||||
int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len,
|
||||
const unsigned char *d);
|
||||
|
||||
int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
|
||||
|
||||
int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
|
||||
|
||||
int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
|
||||
|
||||
X509 *SSL_get_peer_certificate(const SSL *ssl);
|
||||
|
||||
int SSL_want(const SSL *ssl);
|
||||
|
||||
int SSL_want_nothing(const SSL *ssl);
|
||||
|
||||
int SSL_want_read(const SSL *ssl);
|
||||
|
||||
int SSL_want_write(const SSL *ssl);
|
||||
|
||||
int SSL_want_x509_lookup(const SSL *ssl);
|
||||
|
||||
void _ssl_set_alpn_list(const SSL *ssl);
|
||||
|
||||
int SSL_get_error(const SSL *ssl, int ret_code);
|
||||
|
||||
OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl);
|
||||
|
||||
SSL_CTX *SSL_CTX_new(const SSL_METHOD *method, void *rngctx);
|
||||
|
||||
void SSL_CTX_free(SSL_CTX *ctx);
|
||||
|
||||
int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
|
||||
|
||||
const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx);
|
||||
|
||||
SSL *SSL_new(SSL_CTX *ctx);
|
||||
|
||||
void SSL_free(SSL *ssl);
|
||||
|
||||
int SSL_do_handshake(SSL *ssl);
|
||||
|
||||
int SSL_connect(SSL *ssl);
|
||||
|
||||
int SSL_accept(SSL *ssl);
|
||||
|
||||
int SSL_shutdown(SSL *ssl);
|
||||
|
||||
int SSL_clear(SSL *ssl);
|
||||
|
||||
int SSL_read(SSL *ssl, void *buffer, int len);
|
||||
|
||||
int SSL_write(SSL *ssl, const void *buffer, int len);
|
||||
|
||||
SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
|
||||
|
||||
const SSL_METHOD *SSL_get_ssl_method(SSL *ssl);
|
||||
|
||||
int SSL_set_ssl_method(SSL *ssl, const SSL_METHOD *method);
|
||||
|
||||
int SSL_get_shutdown(const SSL *ssl);
|
||||
|
||||
void SSL_set_shutdown(SSL *ssl, int mode);
|
||||
|
||||
int SSL_pending(const SSL *ssl);
|
||||
|
||||
int SSL_has_pending(const SSL *ssl);
|
||||
|
||||
unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op);
|
||||
|
||||
unsigned long SSL_CTX_get_options(SSL_CTX *ctx);
|
||||
|
||||
unsigned long SSL_clear_options(SSL *ssl, unsigned long op);
|
||||
|
||||
unsigned long SSL_get_options(SSL *ssl);
|
||||
|
||||
unsigned long SSL_set_options(SSL *ssl, unsigned long op);
|
||||
|
||||
int SSL_get_fd(const SSL *ssl);
|
||||
|
||||
int SSL_get_rfd(const SSL *ssl);
|
||||
|
||||
int SSL_get_wfd(const SSL *ssl);
|
||||
|
||||
int SSL_set_fd(SSL *ssl, int fd);
|
||||
|
||||
int SSL_set_rfd(SSL *ssl, int fd);
|
||||
|
||||
int SSL_set_wfd(SSL *ssl, int fd);
|
||||
|
||||
int SSL_version(const SSL *ssl);
|
||||
|
||||
const char *SSL_alert_type_string(int value);
|
||||
|
||||
void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len);
|
||||
|
||||
void SSL_set_default_read_buffer_len(SSL *ssl, size_t len);
|
||||
|
||||
void SSL_set_info_callback(SSL *ssl,
|
||||
void (*cb) (const SSL *ssl, int type, int val));
|
||||
|
||||
int SSL_CTX_up_ref(SSL_CTX *ctx);
|
||||
|
||||
void SSL_set_security_level(SSL *ssl, int level);
|
||||
|
||||
int SSL_get_security_level(const SSL *ssl);
|
||||
|
||||
int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
|
||||
|
||||
long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
|
||||
|
||||
long SSL_CTX_get_timeout(const SSL_CTX *ctx);
|
||||
|
||||
void SSL_set_read_ahead(SSL *ssl, int yes);
|
||||
|
||||
void SSL_CTX_set_read_ahead(SSL_CTX *ctx, int yes);
|
||||
|
||||
int SSL_get_read_ahead(const SSL *ssl);
|
||||
|
||||
long SSL_CTX_get_read_ahead(SSL_CTX *ctx);
|
||||
|
||||
long SSL_CTX_get_default_read_ahead(SSL_CTX *ctx);
|
||||
|
||||
long SSL_set_time(SSL *ssl, long t);
|
||||
|
||||
long SSL_set_timeout(SSL *ssl, long t);
|
||||
|
||||
long SSL_get_verify_result(const SSL *ssl);
|
||||
|
||||
int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
|
||||
|
||||
void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
|
||||
|
||||
int SSL_get_verify_depth(const SSL *ssl);
|
||||
|
||||
void SSL_set_verify_depth(SSL *ssl, int depth);
|
||||
|
||||
void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
|
||||
int (*verify_callback)(int, X509_STORE_CTX *));
|
||||
|
||||
void SSL_set_verify(SSL *ssl, int mode,
|
||||
int (*verify_callback)(int, X509_STORE_CTX *));
|
||||
|
||||
void *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx);
|
||||
|
||||
void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, next_proto_cb cb, void *arg);
|
||||
|
||||
void SSL_set_alpn_select_cb(SSL *ssl, void *arg);
|
||||
|
||||
int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
|
||||
|
||||
int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
|
||||
|
||||
int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx,
|
||||
const unsigned char *d, long len);
|
||||
|
||||
int SSL_use_PrivateKey_ASN1(int type, SSL *ssl,
|
||||
const unsigned char *d, long len);
|
||||
|
||||
int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
|
||||
|
||||
int SSL_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
|
||||
|
||||
int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d,
|
||||
long len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_H */
|
||||
49
crypto/openssl_mbedtls_wrapper/include/openssl/ssl3.h
Normal file
49
crypto/openssl_mbedtls_wrapper/include/openssl/ssl3.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl3.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_SSL3_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_SSL_SSL3_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define SSL3_AD_CLOSE_NOTIFY 0
|
||||
#define SSL3_AD_UNEXPECTED_MESSAGE 10/* fatal */
|
||||
#define SSL3_AD_BAD_RECORD_MAC 20/* fatal */
|
||||
#define SSL3_AD_DECOMPRESSION_FAILURE 30/* fatal */
|
||||
#define SSL3_AD_HANDSHAKE_FAILURE 40/* fatal */
|
||||
#define SSL3_AD_NO_CERTIFICATE 41
|
||||
#define SSL3_AD_BAD_CERTIFICATE 42
|
||||
#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
|
||||
#define SSL3_AD_CERTIFICATE_REVOKED 44
|
||||
#define SSL3_AD_CERTIFICATE_EXPIRED 45
|
||||
#define SSL3_AD_CERTIFICATE_UNKNOWN 46
|
||||
#define SSL3_AD_ILLEGAL_PARAMETER 47/* fatal */
|
||||
|
||||
#define SSL3_AL_WARNING 1
|
||||
#define SSL3_AL_FATAL 2
|
||||
|
||||
#define SSL3_VERSION 0x0300
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_SSL3_H */
|
||||
211
crypto/openssl_mbedtls_wrapper/include/openssl/ssl_dbg.h
Normal file
211
crypto/openssl_mbedtls_wrapper/include/openssl/ssl_dbg.h
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_dbg.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_DBG_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_SSL_DBG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_OPENSSL_DEBUG_LEVEL
|
||||
# define SSL_DEBUG_LEVEL CONFIG_OPENSSL_DEBUG_LEVEL
|
||||
#else
|
||||
# define SSL_DEBUG_LEVEL 0
|
||||
#endif
|
||||
|
||||
#define SSL_DEBUG_ON (SSL_DEBUG_LEVEL + 1)
|
||||
#define SSL_DEBUG_OFF (SSL_DEBUG_LEVEL - 1)
|
||||
|
||||
#ifdef CONFIG_OPENSSL_DEBUG
|
||||
# ifndef SSL_DEBUG_LOG
|
||||
# error "SSL_DEBUG_LOG is not defined"
|
||||
# endif
|
||||
|
||||
# ifndef SSL_DEBUG_FL
|
||||
# define SSL_DEBUG_FL "\n"
|
||||
# endif
|
||||
|
||||
# define SSL_SHOW_LOCATION() \
|
||||
SSL_DEBUG_LOG("SSL assert : %s %d\n", \
|
||||
__FILE__, __LINE__)
|
||||
|
||||
# define SSL_DEBUG(level, fmt, ...) \
|
||||
{ \
|
||||
if (level > SSL_DEBUG_LEVEL) \
|
||||
{ \
|
||||
SSL_DEBUG_LOG(fmt SSL_DEBUG_FL, ##__VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#else /* CONFIG_OPENSSL_DEBUG */
|
||||
# define SSL_SHOW_LOCATION()
|
||||
|
||||
# define SSL_DEBUG(level, fmt, ...)
|
||||
#endif /* CONFIG_OPENSSL_DEBUG */
|
||||
|
||||
/* OpenSSL assert function
|
||||
*
|
||||
* if select "CONFIG_OPENSSL_ASSERT_DEBUG", SSL_ASSERT* will show error
|
||||
* file name and line
|
||||
* if select "CONFIG_OPENSSL_ASSERT_EXIT", SSL_ASSERT* will just return
|
||||
* error code.
|
||||
* if select "CONFIG_OPENSSL_ASSERT_DEBUG_EXIT" SSL_ASSERT* will show error
|
||||
* file name and line, then return error code.
|
||||
* if select "CONFIG_OPENSSL_ASSERT_DEBUG_BLOCK", SSL_ASSERT* will show error
|
||||
* file name and line, then block here with "while (1)"
|
||||
*
|
||||
* SSL_ASSERT1 may will return "-1", so function's return argument is
|
||||
* integer.
|
||||
* SSL_ASSERT2 may will return "NULL", so function's return argument is a
|
||||
* point.
|
||||
* SSL_ASSERT2 may will return nothing, so function's return argument is
|
||||
* "void".
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_OPENSSL_ASSERT_DEBUG)
|
||||
# define SSL_ASSERT1(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
SSL_SHOW_LOCATION(); \
|
||||
} \
|
||||
}
|
||||
|
||||
# define SSL_ASSERT2(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
SSL_SHOW_LOCATION(); \
|
||||
} \
|
||||
}
|
||||
|
||||
# define SSL_ASSERT3(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
SSL_SHOW_LOCATION(); \
|
||||
} \
|
||||
}
|
||||
#elif defined(CONFIG_OPENSSL_ASSERT_EXIT)
|
||||
# define SSL_ASSERT1(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
return -1; \
|
||||
} \
|
||||
}
|
||||
|
||||
# define SSL_ASSERT2(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
return NULL; \
|
||||
} \
|
||||
}
|
||||
|
||||
# define SSL_ASSERT3(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
return ; \
|
||||
} \
|
||||
}
|
||||
#elif defined(CONFIG_OPENSSL_ASSERT_DEBUG_EXIT)
|
||||
# define SSL_ASSERT1(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
SSL_SHOW_LOCATION(); \
|
||||
return -1; \
|
||||
} \
|
||||
}
|
||||
|
||||
# define SSL_ASSERT2(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
SSL_SHOW_LOCATION(); \
|
||||
return NULL; \
|
||||
} \
|
||||
}
|
||||
|
||||
# define SSL_ASSERT3(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
SSL_SHOW_LOCATION(); \
|
||||
return ; \
|
||||
} \
|
||||
}
|
||||
#elif defined(CONFIG_OPENSSL_ASSERT_DEBUG_BLOCK)
|
||||
# define SSL_ASSERT1(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
SSL_SHOW_LOCATION(); \
|
||||
while (1); \
|
||||
} \
|
||||
}
|
||||
|
||||
# define SSL_ASSERT2(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
SSL_SHOW_LOCATION(); \
|
||||
while (1); \
|
||||
} \
|
||||
}
|
||||
|
||||
# define SSL_ASSERT3(s) \
|
||||
{ \
|
||||
if (!(s)) \
|
||||
{ \
|
||||
SSL_SHOW_LOCATION(); \
|
||||
while (1); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
# define SSL_ASSERT1(s)
|
||||
# define SSL_ASSERT2(s)
|
||||
# define SSL_ASSERT3(s)
|
||||
#endif
|
||||
|
||||
#define SSL_PLATFORM_DEBUG_LEVEL SSL_DEBUG_OFF
|
||||
#define SSL_PLATFORM_ERROR_LEVEL SSL_DEBUG_ON
|
||||
|
||||
#define SSL_CERT_DEBUG_LEVEL SSL_DEBUG_OFF
|
||||
#define SSL_CERT_ERROR_LEVEL SSL_DEBUG_ON
|
||||
|
||||
#define SSL_PKEY_DEBUG_LEVEL SSL_DEBUG_OFF
|
||||
#define SSL_PKEY_ERROR_LEVEL SSL_DEBUG_ON
|
||||
|
||||
#define SSL_X509_DEBUG_LEVEL SSL_DEBUG_OFF
|
||||
#define SSL_X509_ERROR_LEVEL SSL_DEBUG_ON
|
||||
|
||||
#define SSL_LIB_DEBUG_LEVEL SSL_DEBUG_OFF
|
||||
#define SSL_LIB_ERROR_LEVEL SSL_DEBUG_ON
|
||||
|
||||
#define SSL_STACK_DEBUG_LEVEL SSL_DEBUG_OFF
|
||||
#define SSL_STACK_ERROR_LEVEL SSL_DEBUG_ON
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_DBG_H */
|
||||
148
crypto/openssl_mbedtls_wrapper/include/openssl/ssl_local.h
Normal file
148
crypto/openssl_mbedtls_wrapper/include/openssl/ssl_local.h
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl_local.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_LOCAL_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_SSL_LOCAL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/statem.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509_local.h>
|
||||
#include <openssl/x509_vfy.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct record_layer_st
|
||||
{
|
||||
int rstate;
|
||||
int read_ahead;
|
||||
};
|
||||
|
||||
struct ssl_ctx_st
|
||||
{
|
||||
int version;
|
||||
int references;
|
||||
unsigned long options;
|
||||
const SSL_METHOD *method;
|
||||
CERT *cert;
|
||||
X509 *client_CA;
|
||||
const char **alpn_protos;
|
||||
next_proto_cb alpn_cb;
|
||||
int verify_mode;
|
||||
int (*default_verify_callback) (int ok, X509_STORE_CTX *ctx);
|
||||
long session_timeout;
|
||||
int read_ahead;
|
||||
int read_buffer_len;
|
||||
X509_VERIFY_PARAM param;
|
||||
};
|
||||
|
||||
struct ssl_method_func_st
|
||||
{
|
||||
int (*ssl_new)(SSL *ssl);
|
||||
void (*ssl_free)(SSL *ssl);
|
||||
int (*ssl_handshake)(SSL *ssl);
|
||||
int (*ssl_shutdown)(SSL *ssl);
|
||||
int (*ssl_clear)(SSL *ssl);
|
||||
int (*ssl_read)(SSL *ssl, void *buffer, int len);
|
||||
int (*ssl_send)(SSL *ssl, const void *buffer, int len);
|
||||
int (*ssl_pending)(const SSL *ssl);
|
||||
void (*ssl_set_fd)(SSL *ssl, int fd, int mode);
|
||||
int (*ssl_get_fd)(const SSL *ssl, int mode);
|
||||
void (*ssl_set_bufflen)(SSL *ssl, int len);
|
||||
long (*ssl_get_verify_result)(const SSL *ssl);
|
||||
OSSL_HANDSHAKE_STATE (*ssl_get_state)(const SSL *ssl);
|
||||
};
|
||||
|
||||
struct ssl_method_st
|
||||
{
|
||||
/* protocol version(one of SSL3.0, TLS1.0, etc.) */
|
||||
|
||||
int version;
|
||||
|
||||
/* SSL mode(client(0) , server(1), not known(-1)) */
|
||||
|
||||
int endpoint;
|
||||
const SSL_METHOD_FUNC *func;
|
||||
};
|
||||
|
||||
struct ssl_session_st
|
||||
{
|
||||
long timeout;
|
||||
long time;
|
||||
X509 *peer;
|
||||
};
|
||||
|
||||
struct ssl_st
|
||||
{
|
||||
/* protocol version(one of SSL3.0, TLS1.0, etc.) */
|
||||
|
||||
int version;
|
||||
unsigned long options;
|
||||
|
||||
/* shut things down(0x01 : sent, 0x02 : received) */
|
||||
|
||||
int shutdown;
|
||||
CERT *cert;
|
||||
X509 *client_CA;
|
||||
SSL_CTX *ctx;
|
||||
const SSL_METHOD *method;
|
||||
const char **alpn_protos;
|
||||
RECORD_LAYER rlayer;
|
||||
|
||||
/* where we are */
|
||||
|
||||
OSSL_STATEM statem;
|
||||
SSL_SESSION *session;
|
||||
int verify_mode;
|
||||
int (*verify_callback) (int ok, X509_STORE_CTX *ctx);
|
||||
int rwstate;
|
||||
int interrupted_remaining_write;
|
||||
long verify_result;
|
||||
X509_VERIFY_PARAM param;
|
||||
int err;
|
||||
void (*info_callback) (const SSL *ssl, int type, int val);
|
||||
|
||||
/* SSL low-level system arch point */
|
||||
|
||||
void *ssl_pm;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
CERT *__ssl_cert_new(CERT *ic);
|
||||
CERT *ssl_cert_new(void);
|
||||
void ssl_cert_free(CERT *cert);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_LOCAL_H */
|
||||
|
|
@ -24,17 +24,32 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <openssl/base.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
#include <openssl/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct stack_st
|
||||
{
|
||||
char **data;
|
||||
int num_alloc;
|
||||
OPENSSL_sk_compfunc c;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c);
|
||||
OPENSSL_STACK *OPENSSL_sk_new_null(void);
|
||||
void OPENSSL_sk_free(OPENSSL_STACK *stack);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
82
crypto/openssl_mbedtls_wrapper/include/openssl/statem.h
Normal file
82
crypto/openssl_mbedtls_wrapper/include/openssl/statem.h
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/statem.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_STATEM_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_STATEM_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <openssl/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* No handshake in progress */
|
||||
|
||||
MSG_FLOW_UNINITED,
|
||||
|
||||
/* A permanent error with this connection */
|
||||
|
||||
MSG_FLOW_ERROR,
|
||||
|
||||
/* We are about to renegotiate */
|
||||
|
||||
MSG_FLOW_RENEGOTIATE,
|
||||
|
||||
/* We are reading messages */
|
||||
|
||||
MSG_FLOW_READING,
|
||||
|
||||
/* We are writing messages */
|
||||
|
||||
MSG_FLOW_WRITING,
|
||||
|
||||
/* Handshake has finished */
|
||||
|
||||
MSG_FLOW_FINISHED
|
||||
}
|
||||
MSG_FLOW_STATE;
|
||||
|
||||
struct ossl_statem_st
|
||||
{
|
||||
MSG_FLOW_STATE state;
|
||||
int hand_state;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
int ossl_statem_in_error(const SSL *ssl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_STACK_H */
|
||||
63
crypto/openssl_mbedtls_wrapper/include/openssl/tls1.h
Normal file
63
crypto/openssl_mbedtls_wrapper/include/openssl/tls1.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/tls1.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_TLS1_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_TLS1_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define TLS1_AD_DECRYPTION_FAILED 21
|
||||
#define TLS1_AD_RECORD_OVERFLOW 22
|
||||
#define TLS1_AD_UNKNOWN_CA 48/* fatal */
|
||||
#define TLS1_AD_ACCESS_DENIED 49/* fatal */
|
||||
#define TLS1_AD_DECODE_ERROR 50/* fatal */
|
||||
#define TLS1_AD_DECRYPT_ERROR 51
|
||||
#define TLS1_AD_EXPORT_RESTRICTION 60/* fatal */
|
||||
#define TLS1_AD_PROTOCOL_VERSION 70/* fatal */
|
||||
#define TLS1_AD_INSUFFICIENT_SECURITY 71/* fatal */
|
||||
#define TLS1_AD_INTERNAL_ERROR 80/* fatal */
|
||||
#define TLS1_AD_INAPPROPRIATE_FALLBACK 86/* fatal */
|
||||
#define TLS1_AD_USER_CANCELLED 90
|
||||
#define TLS1_AD_NO_RENEGOTIATION 100
|
||||
/* codes 110-114 are from RFC3546 */
|
||||
#define TLS1_AD_UNSUPPORTED_EXTENSION 110
|
||||
#define TLS1_AD_CERTIFICATE_UNOBTAINABLE 111
|
||||
#define TLS1_AD_UNRECOGNIZED_NAME 112
|
||||
#define TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE 113
|
||||
#define TLS1_AD_BAD_CERTIFICATE_HASH_VALUE 114
|
||||
#define TLS1_AD_UNKNOWN_PSK_IDENTITY 115/* fatal */
|
||||
#define TLS1_AD_NO_APPLICATION_PROTOCOL 120/* fatal */
|
||||
|
||||
/* Special value for method supporting multiple versions */
|
||||
#define TLS_ANY_VERSION 0x10000
|
||||
|
||||
#define TLS1_VERSION 0x0301
|
||||
#define TLS1_1_VERSION 0x0302
|
||||
#define TLS1_2_VERSION 0x0303
|
||||
|
||||
#define SSL_TLSEXT_ERR_OK 0
|
||||
#define SSL_TLSEXT_ERR_NOACK 3
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_TLS1_H */
|
||||
72
crypto/openssl_mbedtls_wrapper/include/openssl/types.h
Normal file
72
crypto/openssl_mbedtls_wrapper/include/openssl/types.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/types.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_TYPES_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void SSL_CIPHER;
|
||||
typedef void X509_STORE;
|
||||
|
||||
typedef void RSA;
|
||||
typedef void BIO;
|
||||
|
||||
typedef int (*OPENSSL_sk_compfunc)(const void *, const void *);
|
||||
|
||||
typedef struct stack_st OPENSSL_STACK;
|
||||
typedef struct ssl_method_st SSL_METHOD;
|
||||
typedef struct ssl_method_func_st SSL_METHOD_FUNC;
|
||||
typedef struct record_layer_st RECORD_LAYER;
|
||||
typedef struct ossl_statem_st OSSL_STATEM;
|
||||
typedef struct ssl_session_st SSL_SESSION;
|
||||
typedef struct ssl_ctx_st SSL_CTX;
|
||||
typedef struct ssl_st SSL;
|
||||
typedef struct cert_st CERT;
|
||||
typedef struct x509_st X509;
|
||||
typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM;
|
||||
typedef struct evp_pkey_st EVP_PKEY;
|
||||
typedef struct x509_method_st X509_METHOD;
|
||||
typedef struct pkey_method_st PKEY_METHOD;
|
||||
|
||||
#define ossl_inline inline
|
||||
#define OPENSSL_NPN_NEGOTIATED 1
|
||||
|
||||
#define SSL_METHOD_CALL(f, s, ...) s->method->func->ssl_##f(s, ##__VA_ARGS__)
|
||||
#define X509_METHOD_CALL(f, x, ...) x->method->x509_##f(x, ##__VA_ARGS__)
|
||||
#define EVP_PKEY_METHOD_CALL(f, k, ...) k->method->pkey_##f(k, ##__VA_ARGS__)
|
||||
|
||||
typedef int (*next_proto_cb)(SSL *ssl, unsigned char **out,
|
||||
unsigned char *outlen, const unsigned char *in,
|
||||
unsigned int inlen, void *arg);
|
||||
|
||||
struct pkey_method_st
|
||||
{
|
||||
int (*pkey_new)(EVP_PKEY *pkey, EVP_PKEY *m_pkey);
|
||||
void (*pkey_free)(EVP_PKEY *pkey);
|
||||
int (*pkey_load)(EVP_PKEY *pkey, const unsigned char *buf, int len);
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_TYPES_H */
|
||||
|
|
@ -24,16 +24,46 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <openssl/base.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/ecdsa.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct x509_st
|
||||
{
|
||||
/* X509 certification platform private point */
|
||||
|
||||
void *x509_pm;
|
||||
const X509_METHOD *method;
|
||||
};
|
||||
|
||||
struct x509_method_st
|
||||
{
|
||||
int (*x509_new)(X509 *x, X509 *m_x);
|
||||
void (*x509_free)(X509 *x);
|
||||
int (*x509_load)(X509 *x, const unsigned char *buf, int len);
|
||||
int (*x509_show_info)(X509 *x);
|
||||
};
|
||||
|
||||
struct cert_st
|
||||
{
|
||||
int sec_level;
|
||||
X509 *x509;
|
||||
EVP_PKEY *pkey;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
|
@ -103,6 +133,10 @@ PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *info,
|
|||
|
||||
X509 *d2i_X509(X509 **out, const uint8_t **inp, long len);
|
||||
|
||||
const char *X509_verify_cert_error_string(long n);
|
||||
|
||||
X509 *__X509_new(X509 *ix);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
36
crypto/openssl_mbedtls_wrapper/include/openssl/x509_local.h
Normal file
36
crypto/openssl_mbedtls_wrapper/include/openssl/x509_local.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/x509_local.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_X509_LOCAL_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_X509_LOCAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct X509_VERIFY_PARAM_st
|
||||
{
|
||||
int depth;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_X509_LOCAL_H */
|
||||
120
crypto/openssl_mbedtls_wrapper/include/openssl/x509_vfy.h
Normal file
120
crypto/openssl_mbedtls_wrapper/include/openssl/x509_vfy.h
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/x509_vfy.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_X509_VFY_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_X509_VFY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define X509_V_OK 0
|
||||
#define X509_V_ERR_UNSPECIFIED 1
|
||||
#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
|
||||
#define X509_V_ERR_UNABLE_TO_GET_CRL 3
|
||||
#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4
|
||||
#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5
|
||||
#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6
|
||||
#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7
|
||||
#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8
|
||||
#define X509_V_ERR_CERT_NOT_YET_VALID 9
|
||||
#define X509_V_ERR_CERT_HAS_EXPIRED 10
|
||||
#define X509_V_ERR_CRL_NOT_YET_VALID 11
|
||||
#define X509_V_ERR_CRL_HAS_EXPIRED 12
|
||||
#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13
|
||||
#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14
|
||||
#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15
|
||||
#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16
|
||||
#define X509_V_ERR_OUT_OF_MEM 17
|
||||
#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18
|
||||
#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19
|
||||
#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20
|
||||
#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21
|
||||
#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22
|
||||
#define X509_V_ERR_CERT_REVOKED 23
|
||||
#define X509_V_ERR_INVALID_CA 24
|
||||
#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25
|
||||
#define X509_V_ERR_INVALID_PURPOSE 26
|
||||
#define X509_V_ERR_CERT_UNTRUSTED 27
|
||||
#define X509_V_ERR_CERT_REJECTED 28
|
||||
/* These are 'informational' when looking for issuer cert */
|
||||
#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29
|
||||
#define X509_V_ERR_AKID_SKID_MISMATCH 30
|
||||
#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31
|
||||
#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32
|
||||
#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33
|
||||
#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34
|
||||
#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35
|
||||
#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36
|
||||
#define X509_V_ERR_INVALID_NON_CA 37
|
||||
#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38
|
||||
#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39
|
||||
#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40
|
||||
#define X509_V_ERR_INVALID_EXTENSION 41
|
||||
#define X509_V_ERR_INVALID_POLICY_EXTENSION 42
|
||||
#define X509_V_ERR_NO_EXPLICIT_POLICY 43
|
||||
#define X509_V_ERR_DIFFERENT_CRL_SCOPE 44
|
||||
#define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45
|
||||
#define X509_V_ERR_UNNESTED_RESOURCE 46
|
||||
#define X509_V_ERR_PERMITTED_VIOLATION 47
|
||||
#define X509_V_ERR_EXCLUDED_VIOLATION 48
|
||||
#define X509_V_ERR_SUBTREE_MINMAX 49
|
||||
/* The application is not happy */
|
||||
#define X509_V_ERR_APPLICATION_VERIFICATION 50
|
||||
#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51
|
||||
#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52
|
||||
#define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53
|
||||
#define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54
|
||||
/* Another issuer check debug option */
|
||||
#define X509_V_ERR_PATH_LOOP 55
|
||||
/* Suite B mode algorithm violation */
|
||||
#define X509_V_ERR_SUITE_B_INVALID_VERSION 56
|
||||
#define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57
|
||||
#define X509_V_ERR_SUITE_B_INVALID_CURVE 58
|
||||
#define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59
|
||||
#define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60
|
||||
#define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61
|
||||
/* Host, email and IP check errors */
|
||||
#define X509_V_ERR_HOSTNAME_MISMATCH 62
|
||||
#define X509_V_ERR_EMAIL_MISMATCH 63
|
||||
#define X509_V_ERR_IP_ADDRESS_MISMATCH 64
|
||||
/* DANE TLSA errors */
|
||||
#define X509_V_ERR_DANE_NO_MATCH 65
|
||||
/* security level errors */
|
||||
#define X509_V_ERR_EE_KEY_TOO_SMALL 66
|
||||
#define X509_V_ERR_CA_KEY_TOO_SMALL 67
|
||||
#define X509_V_ERR_CA_MD_TOO_WEAK 68
|
||||
/* Caller error */
|
||||
#define X509_V_ERR_INVALID_CALL 69
|
||||
/* Issuer lookup error */
|
||||
#define X509_V_ERR_STORE_LOOKUP 70
|
||||
/* Certificate transparency */
|
||||
#define X509_V_ERR_NO_VALID_SCTS 71
|
||||
|
||||
#define X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION 72
|
||||
|
||||
typedef void X509_STORE_CTX;
|
||||
int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
|
||||
int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_X509_VFY_H */
|
||||
|
|
@ -15,7 +15,6 @@
|
|||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -24,13 +23,57 @@
|
|||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/cipher.h>
|
||||
#include <openssl/ssl_dbg.h>
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/types.h>
|
||||
#include "ssl_port.h"
|
||||
|
||||
#include <mbedtls/md.h>
|
||||
#include <mbedtls/pk.h>
|
||||
#include <mbedtls/rsa.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
EVP_PKEY *__EVP_PKEY_new(EVP_PKEY *ipk)
|
||||
{
|
||||
int ret;
|
||||
EVP_PKEY *pkey;
|
||||
|
||||
pkey = ssl_mem_zalloc(sizeof(EVP_PKEY));
|
||||
if (!pkey)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "no enough memory > (pkey)");
|
||||
goto no_mem;
|
||||
}
|
||||
|
||||
if (ipk)
|
||||
{
|
||||
pkey->method = ipk->method;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkey->method = EVP_PKEY_method();
|
||||
}
|
||||
|
||||
ret = EVP_PKEY_METHOD_CALL(new, pkey, ipk);
|
||||
if (ret)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL,
|
||||
"EVP_PKEY_METHOD_CALL(new) return %d", ret);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
return pkey;
|
||||
|
||||
failed:
|
||||
ssl_mem_free(pkey);
|
||||
no_mem:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
|
@ -55,6 +98,11 @@ RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey)
|
|||
|
||||
void EVP_PKEY_free(EVP_PKEY *pkey)
|
||||
{
|
||||
SSL_ASSERT3(pkey);
|
||||
|
||||
EVP_PKEY_METHOD_CALL(free, pkey);
|
||||
|
||||
ssl_mem_free(pkey);
|
||||
}
|
||||
|
||||
int EVP_PKEY_type(int nid)
|
||||
|
|
@ -69,7 +117,7 @@ EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey)
|
|||
|
||||
EVP_PKEY *EVP_PKEY_new(void)
|
||||
{
|
||||
return NULL;
|
||||
return __EVP_PKEY_new(NULL);
|
||||
}
|
||||
|
||||
int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
|
||||
|
|
|
|||
139
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_cert.c
Normal file
139
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_cert.c
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_cert.c
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/ssl_dbg.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/ssl_local.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509_vfy.h>
|
||||
#include "ssl_port.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
CERT *__ssl_cert_new(CERT *ic)
|
||||
{
|
||||
CERT *cert;
|
||||
|
||||
X509 *ix;
|
||||
EVP_PKEY *ipk;
|
||||
|
||||
cert = ssl_mem_zalloc(sizeof(CERT));
|
||||
if (!cert)
|
||||
{
|
||||
SSL_DEBUG(SSL_CERT_ERROR_LEVEL, "no enough memory > (cert)");
|
||||
goto no_mem;
|
||||
}
|
||||
|
||||
if (ic)
|
||||
{
|
||||
ipk = ic->pkey;
|
||||
ix = ic->x509;
|
||||
}
|
||||
else
|
||||
{
|
||||
ipk = NULL;
|
||||
ix = NULL;
|
||||
}
|
||||
|
||||
cert->pkey = __EVP_PKEY_new(ipk);
|
||||
if (!cert->pkey)
|
||||
{
|
||||
SSL_DEBUG(SSL_CERT_ERROR_LEVEL, "__EVP_PKEY_new() return NULL");
|
||||
goto pkey_err;
|
||||
}
|
||||
|
||||
cert->x509 = __X509_new(ix);
|
||||
if (!cert->x509)
|
||||
{
|
||||
SSL_DEBUG(SSL_CERT_ERROR_LEVEL, "__X509_new() return NULL");
|
||||
goto x509_err;
|
||||
}
|
||||
|
||||
return cert;
|
||||
|
||||
x509_err:
|
||||
EVP_PKEY_free(cert->pkey);
|
||||
pkey_err:
|
||||
ssl_mem_free(cert);
|
||||
no_mem:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x)
|
||||
{
|
||||
SSL_ASSERT1(ctx);
|
||||
SSL_ASSERT1(x);
|
||||
assert(ctx);
|
||||
if (ctx->client_CA == x)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
X509_free(ctx->client_CA);
|
||||
ctx->client_CA = x;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SSL_CTX_add_client_CA_ASN1(SSL_CTX *ctx, int len,
|
||||
const unsigned char *d)
|
||||
{
|
||||
X509 *x;
|
||||
|
||||
x = d2i_X509(NULL, &d, len);
|
||||
if (!x)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_X509() return NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SSL_ASSERT1(ctx);
|
||||
X509_free(ctx->client_CA);
|
||||
ctx->client_CA = x;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
CERT *ssl_cert_new(void)
|
||||
{
|
||||
return __ssl_cert_new(NULL);
|
||||
}
|
||||
|
||||
void ssl_cert_free(CERT *cert)
|
||||
{
|
||||
SSL_ASSERT3(cert);
|
||||
|
||||
X509_free(cert->x509);
|
||||
|
||||
EVP_PKEY_free(cert->pkey);
|
||||
|
||||
ssl_mem_free(cert);
|
||||
}
|
||||
1015
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_lib.c
Normal file
1015
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_lib.c
Normal file
File diff suppressed because it is too large
Load diff
105
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.c
Normal file
105
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.c
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.c
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <openssl/tls1.h>
|
||||
#include <openssl/ssl_local.h>
|
||||
#include <openssl/ssl3.h>
|
||||
#include "ssl_methods.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* TLS method function collection
|
||||
*/
|
||||
|
||||
IMPLEMENT_TLS_METHOD_FUNC(TLS_method_func,
|
||||
ssl_pm_new, ssl_pm_free,
|
||||
ssl_pm_handshake, ssl_pm_shutdown, ssl_pm_clear,
|
||||
ssl_pm_read, ssl_pm_send, ssl_pm_pending,
|
||||
ssl_pm_set_fd, ssl_pm_get_fd,
|
||||
ssl_pm_set_bufflen,
|
||||
ssl_pm_get_verify_result,
|
||||
ssl_pm_get_state);
|
||||
|
||||
/**
|
||||
* TLS or SSL client method collection
|
||||
*/
|
||||
|
||||
IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, 0, TLS_method_func, TLS_client_method);
|
||||
|
||||
IMPLEMENT_TLS_METHOD(TLS1_2_VERSION, 0,
|
||||
TLS_method_func, TLSv1_2_client_method);
|
||||
|
||||
IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, 0,
|
||||
TLS_method_func, TLSv1_1_client_method);
|
||||
|
||||
IMPLEMENT_TLS_METHOD(TLS1_VERSION, 0, TLS_method_func, TLSv1_client_method);
|
||||
|
||||
IMPLEMENT_SSL_METHOD(SSL3_VERSION, 0, TLS_method_func, SSLv3_client_method);
|
||||
|
||||
/**
|
||||
* TLS or SSL server method collection
|
||||
*/
|
||||
|
||||
IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, 1, TLS_method_func, TLS_server_method);
|
||||
|
||||
IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, 1,
|
||||
TLS_method_func, TLSv1_1_server_method);
|
||||
|
||||
IMPLEMENT_TLS_METHOD(TLS1_2_VERSION, 1,
|
||||
TLS_method_func, TLSv1_2_server_method);
|
||||
|
||||
IMPLEMENT_TLS_METHOD(TLS1_VERSION, 0, TLS_method_func, TLSv1_server_method);
|
||||
|
||||
IMPLEMENT_SSL_METHOD(SSL3_VERSION, 1, TLS_method_func, SSLv3_server_method);
|
||||
|
||||
/**
|
||||
* TLS or SSL method collection
|
||||
*/
|
||||
|
||||
IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, -1, TLS_method_func, TLS_method);
|
||||
|
||||
IMPLEMENT_SSL_METHOD(TLS1_2_VERSION, -1, TLS_method_func, TLSv1_2_method);
|
||||
|
||||
IMPLEMENT_SSL_METHOD(TLS1_1_VERSION, -1, TLS_method_func, TLSv1_1_method);
|
||||
|
||||
IMPLEMENT_SSL_METHOD(TLS1_VERSION, -1, TLS_method_func, TLSv1_method);
|
||||
|
||||
IMPLEMENT_SSL_METHOD(SSL3_VERSION, -1, TLS_method_func, SSLv3_method);
|
||||
|
||||
/**
|
||||
* @brief get X509 object method
|
||||
*/
|
||||
|
||||
IMPLEMENT_X509_METHOD(X509_method,
|
||||
x509_pm_new, x509_pm_free,
|
||||
x509_pm_load, x509_pm_show_info);
|
||||
|
||||
/**
|
||||
* @brief get private key object method
|
||||
*/
|
||||
|
||||
IMPLEMENT_PKEY_METHOD(EVP_PKEY_method,
|
||||
pkey_pm_new, pkey_pm_free,
|
||||
pkey_pm_load);
|
||||
141
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.h
Normal file
141
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.h
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_methods.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_METHODS_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_SSL_METHODS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include "ssl_pm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* TLS method function implement */
|
||||
|
||||
#define IMPLEMENT_TLS_METHOD_FUNC(func_name, \
|
||||
new, free, \
|
||||
handshake, shutdown, clear, \
|
||||
read, send, pending, \
|
||||
set_fd, get_fd, \
|
||||
set_bufflen, \
|
||||
get_verify_result, \
|
||||
get_state) \
|
||||
static const SSL_METHOD_FUNC func_name LOCAL_ATRR = \
|
||||
{ \
|
||||
new, \
|
||||
free, \
|
||||
handshake, \
|
||||
shutdown, \
|
||||
clear, \
|
||||
read, \
|
||||
send, \
|
||||
pending, \
|
||||
set_fd, \
|
||||
get_fd, \
|
||||
set_bufflen, \
|
||||
get_verify_result, \
|
||||
get_state \
|
||||
};
|
||||
|
||||
#define IMPLEMENT_TLS_METHOD(ver, mode, fun, func_name) \
|
||||
const SSL_METHOD* func_name(void) \
|
||||
{ \
|
||||
static const SSL_METHOD func_name##_data LOCAL_ATRR = \
|
||||
{ \
|
||||
ver, \
|
||||
mode, \
|
||||
&(fun), \
|
||||
}; \
|
||||
return &func_name##_data; \
|
||||
}
|
||||
|
||||
#define IMPLEMENT_SSL_METHOD(ver, mode, fun, func_name) \
|
||||
const SSL_METHOD* func_name(void) \
|
||||
{ \
|
||||
static const SSL_METHOD func_name##_data LOCAL_ATRR = \
|
||||
{ \
|
||||
ver, \
|
||||
mode, \
|
||||
&(fun), \
|
||||
}; \
|
||||
return &func_name##_data; \
|
||||
}
|
||||
|
||||
#define IMPLEMENT_X509_METHOD(func_name, \
|
||||
new, \
|
||||
free, \
|
||||
load, \
|
||||
show_info) \
|
||||
const X509_METHOD* func_name(void) \
|
||||
{ \
|
||||
static const X509_METHOD func_name##_data LOCAL_ATRR = \
|
||||
{ \
|
||||
new, \
|
||||
free, \
|
||||
load, \
|
||||
show_info \
|
||||
}; \
|
||||
return &func_name##_data; \
|
||||
}
|
||||
|
||||
#define IMPLEMENT_PKEY_METHOD(func_name, \
|
||||
new, \
|
||||
free, \
|
||||
load) \
|
||||
const PKEY_METHOD* func_name(void) \
|
||||
{ \
|
||||
static const PKEY_METHOD func_name##_data LOCAL_ATRR = \
|
||||
{ \
|
||||
new, \
|
||||
free, \
|
||||
load \
|
||||
}; \
|
||||
return &func_name##_data; \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get X509 object method
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return X509 object method point
|
||||
*/
|
||||
|
||||
const X509_METHOD *X509_method(void);
|
||||
|
||||
/**
|
||||
* @brief get private key object method
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return private key object method point
|
||||
*/
|
||||
|
||||
const PKEY_METHOD *EVP_PKEY_method(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_METHODS_H */
|
||||
1076
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.c
Normal file
1076
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.c
Normal file
File diff suppressed because it is too large
Load diff
70
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.h
Normal file
70
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_PM_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_SSL_PM_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include "ssl_port.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define LOCAL_ATRR
|
||||
|
||||
int ssl_pm_new(SSL *ssl);
|
||||
void ssl_pm_free(SSL *ssl);
|
||||
|
||||
int ssl_pm_handshake(SSL *ssl);
|
||||
int ssl_pm_shutdown(SSL *ssl);
|
||||
int ssl_pm_clear(SSL *ssl);
|
||||
|
||||
int ssl_pm_read(SSL *ssl, void *buffer, int len);
|
||||
int ssl_pm_send(SSL *ssl, const void *buffer, int len);
|
||||
int ssl_pm_pending(const SSL *ssl);
|
||||
|
||||
void ssl_pm_set_fd(SSL *ssl, int fd, int mode);
|
||||
int ssl_pm_get_fd(const SSL *ssl, int mode);
|
||||
|
||||
OSSL_HANDSHAKE_STATE ssl_pm_get_state(const SSL *ssl);
|
||||
|
||||
void ssl_pm_set_bufflen(SSL *ssl, int len);
|
||||
|
||||
int x509_pm_show_info(X509 *x);
|
||||
int x509_pm_new(X509 *x, X509 *m_x);
|
||||
void x509_pm_free(X509 *x);
|
||||
int x509_pm_load(X509 *x, const unsigned char *buffer, int len);
|
||||
|
||||
int pkey_pm_new(EVP_PKEY *pk, EVP_PKEY *m_pk);
|
||||
void pkey_pm_free(EVP_PKEY *pk);
|
||||
int pkey_pm_load(EVP_PKEY *pk, const unsigned char *buffer, int len);
|
||||
|
||||
long ssl_pm_get_verify_result(const SSL *ssl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_PM_H */
|
||||
39
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.c
Normal file
39
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.c
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "ssl_port.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void *ssl_mem_zalloc(size_t size)
|
||||
{
|
||||
void *p = malloc(size);
|
||||
|
||||
if (p)
|
||||
{
|
||||
memset(p, 0, size);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
55
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.h
Normal file
55
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_port.h
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_PORT_H
|
||||
#define OPENSSL_MBEDTLS_WRAPPER_SSL_PORT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#if defined(LWS_HAVE_MALLOC_H)
|
||||
#include "malloc.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void *ssl_mem_zalloc(size_t size);
|
||||
|
||||
#define ssl_mem_malloc malloc
|
||||
#define ssl_mem_free free
|
||||
|
||||
#define ssl_memcpy memcpy
|
||||
#define ssl_strlen strlen
|
||||
|
||||
#define ssl_speed_up_enter()
|
||||
#define ssl_speed_up_exit()
|
||||
|
||||
#define SSL_DEBUG_FL
|
||||
#define SSL_DEBUG_LOG(fmt, ...) ESP_LOGI("openssl", fmt, ##__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_PORT_H */
|
||||
242
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_rsa.c
Normal file
242
crypto/openssl_mbedtls_wrapper/mbedtls/ssl_rsa.c
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/ssl_rsa.c
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <openssl/ssl_dbg.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/ssl_local.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)
|
||||
{
|
||||
SSL_ASSERT1(ctx);
|
||||
SSL_ASSERT1(x);
|
||||
|
||||
if (ctx->cert->x509 == x)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
X509_free(ctx->cert->x509);
|
||||
ctx->cert->x509 = x;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SSL_use_certificate(SSL *ssl, X509 *x)
|
||||
{
|
||||
SSL_ASSERT1(ssl);
|
||||
SSL_ASSERT1(x);
|
||||
|
||||
if (ssl->cert->x509 == x)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
X509_free(ssl->cert->x509);
|
||||
ssl->cert->x509 = x;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len,
|
||||
const unsigned char *d)
|
||||
{
|
||||
int ret;
|
||||
X509 *x;
|
||||
|
||||
x = d2i_X509(NULL, &d, len);
|
||||
if (!x)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_X509() return NULL");
|
||||
goto failed1;
|
||||
}
|
||||
|
||||
ret = SSL_CTX_use_certificate(ctx, x);
|
||||
if (!ret)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL,
|
||||
"SSL_CTX_use_certificate() return %d", ret);
|
||||
goto failed2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
failed2:
|
||||
X509_free(x);
|
||||
failed1:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len)
|
||||
{
|
||||
int ret;
|
||||
X509 *x;
|
||||
|
||||
x = d2i_X509(NULL, &d, len);
|
||||
if (!x)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_X509() return NULL");
|
||||
goto failed1;
|
||||
}
|
||||
|
||||
ret = SSL_use_certificate(ssl, x);
|
||||
if (!ret)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL,
|
||||
"SSL_use_certificate() return %d", ret);
|
||||
goto failed2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
failed2:
|
||||
X509_free(x);
|
||||
failed1:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SSL_use_certificate_file(SSL *ssl, const char *file, int type)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey)
|
||||
{
|
||||
SSL_ASSERT1(ctx);
|
||||
SSL_ASSERT1(pkey);
|
||||
|
||||
if (ctx->cert->pkey == pkey)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ctx->cert->pkey)
|
||||
{
|
||||
EVP_PKEY_free(ctx->cert->pkey);
|
||||
}
|
||||
|
||||
ctx->cert->pkey = pkey;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey)
|
||||
{
|
||||
SSL_ASSERT1(ssl);
|
||||
SSL_ASSERT1(pkey);
|
||||
|
||||
if (ssl->cert->pkey == pkey)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ssl->cert->pkey)
|
||||
{
|
||||
EVP_PKEY_free(ssl->cert->pkey);
|
||||
}
|
||||
|
||||
ssl->cert->pkey = pkey;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx,
|
||||
const unsigned char *d, long len)
|
||||
{
|
||||
int ret;
|
||||
EVP_PKEY *pk;
|
||||
|
||||
pk = d2i_PrivateKey(0, NULL, &d, len);
|
||||
if (!pk)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_PrivateKey() return NULL");
|
||||
goto failed1;
|
||||
}
|
||||
|
||||
ret = SSL_CTX_use_PrivateKey(ctx, pk);
|
||||
if (!ret)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL,
|
||||
"SSL_CTX_use_PrivateKey() return %d", ret);
|
||||
goto failed2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
failed2:
|
||||
EVP_PKEY_free(pk);
|
||||
failed1:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SSL_use_PrivateKey_ASN1(int type, SSL *ssl,
|
||||
const unsigned char *d, long len)
|
||||
{
|
||||
int ret;
|
||||
EVP_PKEY *pk;
|
||||
|
||||
pk = d2i_PrivateKey(0, NULL, &d, len);
|
||||
if (!pk)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "d2i_PrivateKey() return NULL");
|
||||
goto failed1;
|
||||
}
|
||||
|
||||
ret = SSL_use_PrivateKey(ssl, pk);
|
||||
if (!ret)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "SSL_use_PrivateKey() return %d", ret);
|
||||
goto failed2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
failed2:
|
||||
EVP_PKEY_free(pk);
|
||||
failed1:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SSL_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d,
|
||||
long len)
|
||||
{
|
||||
return SSL_CTX_use_PrivateKey_ASN1(0, ctx, d, len);
|
||||
}
|
||||
79
crypto/openssl_mbedtls_wrapper/mbedtls/stack.c
Normal file
79
crypto/openssl_mbedtls_wrapper/mbedtls/stack.c
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/stack.c
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <openssl/stack.h>
|
||||
#include <openssl/ssl_dbg.h>
|
||||
#include "ssl_port.h"
|
||||
|
||||
#ifndef CONFIG_MIN_NODES
|
||||
#define MIN_NODES 4
|
||||
#else
|
||||
#define MIN_NODES CONFIG_MIN_NODES
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c)
|
||||
{
|
||||
OPENSSL_STACK *stack;
|
||||
char **data;
|
||||
|
||||
stack = ssl_mem_zalloc(sizeof(OPENSSL_STACK));
|
||||
if (!stack)
|
||||
{
|
||||
SSL_DEBUG(SSL_STACK_ERROR_LEVEL, "no enough memory > (stack)");
|
||||
goto no_mem1;
|
||||
}
|
||||
|
||||
data = ssl_mem_zalloc(sizeof(*data) * MIN_NODES);
|
||||
if (!data)
|
||||
{
|
||||
SSL_DEBUG(SSL_STACK_ERROR_LEVEL, "no enough memory > (data)");
|
||||
goto no_mem2;
|
||||
}
|
||||
|
||||
stack->data = data;
|
||||
stack->num_alloc = MIN_NODES;
|
||||
stack->c = c;
|
||||
|
||||
return stack;
|
||||
|
||||
no_mem2:
|
||||
ssl_mem_free(stack);
|
||||
no_mem1:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_STACK *OPENSSL_sk_new_null(void)
|
||||
{
|
||||
return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL);
|
||||
}
|
||||
|
||||
void OPENSSL_sk_free(OPENSSL_STACK *stack)
|
||||
{
|
||||
SSL_ASSERT3(stack);
|
||||
|
||||
ssl_mem_free(stack->data);
|
||||
ssl_mem_free(stack);
|
||||
}
|
||||
39
crypto/openssl_mbedtls_wrapper/mbedtls/statem.c
Normal file
39
crypto/openssl_mbedtls_wrapper/mbedtls/statem.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/statem.c
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <openssl/ssl_dbg.h>
|
||||
#include <openssl/ssl_local.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl)
|
||||
{
|
||||
OSSL_HANDSHAKE_STATE state;
|
||||
|
||||
SSL_ASSERT1(ssl);
|
||||
|
||||
state = SSL_METHOD_CALL(get_state, ssl);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
|
@ -22,7 +22,10 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <openssl/ssl_dbg.h>
|
||||
#include <openssl/x509.h>
|
||||
#include "ssl_port.h"
|
||||
#include "ssl_methods.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
|
@ -161,3 +164,85 @@ EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8)
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
X509 *d2i_X509(X509 **out, const unsigned char **inp, long len)
|
||||
{
|
||||
int m = 0;
|
||||
int ret;
|
||||
X509 *x;
|
||||
|
||||
SSL_ASSERT2(inp);
|
||||
SSL_ASSERT2(len);
|
||||
|
||||
if (out && *out)
|
||||
{
|
||||
x = *out;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = X509_new();
|
||||
if (!x)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "X509_new() return NULL");
|
||||
goto failed1;
|
||||
}
|
||||
|
||||
m = 1;
|
||||
}
|
||||
|
||||
ret = X509_METHOD_CALL(load, x, *inp, (int)len);
|
||||
if (ret)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL,
|
||||
"X509_METHOD_CALL(load) return %d", ret);
|
||||
goto failed2;
|
||||
}
|
||||
|
||||
return x;
|
||||
|
||||
failed2:
|
||||
if (m)
|
||||
{
|
||||
X509_free(x);
|
||||
}
|
||||
|
||||
failed1:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
X509 *__X509_new(X509 *ix)
|
||||
{
|
||||
int ret;
|
||||
X509 *x;
|
||||
|
||||
x = ssl_mem_zalloc(sizeof(X509));
|
||||
if (!x)
|
||||
{
|
||||
SSL_DEBUG(SSL_X509_ERROR_LEVEL, "no enough memory > (x)");
|
||||
goto no_mem;
|
||||
}
|
||||
|
||||
if (ix)
|
||||
{
|
||||
x->method = ix->method;
|
||||
}
|
||||
else
|
||||
{
|
||||
x->method = X509_method();
|
||||
}
|
||||
|
||||
ret = X509_METHOD_CALL(new, x, ix);
|
||||
if (ret)
|
||||
{
|
||||
SSL_DEBUG(SSL_PKEY_ERROR_LEVEL,
|
||||
"X509_METHOD_CALL(new) return %d", ret);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
return x;
|
||||
|
||||
failed:
|
||||
ssl_mem_free(x);
|
||||
no_mem:
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
39
crypto/openssl_mbedtls_wrapper/mbedtls/x509_vpm.c
Normal file
39
crypto/openssl_mbedtls_wrapper/mbedtls/x509_vpm.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
* apps/crypto/openssl_mbedtls_wrapper/mbedtls/x509_vpm.c
|
||||
*
|
||||
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <openssl/types.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param,
|
||||
unsigned long flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int X509_VERIFY_PARAM_clear_hostflags(X509_VERIFY_PARAM *param,
|
||||
unsigned long flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue