Skip to content

Commit f7582e3

Browse files
ThePassionatexiaoxiang781216
authored andcommitted
openssl_mbedtls_wrapper: add ssl wrapper from libwebsockets
Signed-off-by: makejian <makejian@xiaomi.com>
1 parent f1ace37 commit f7582e3

28 files changed

+4329
-10
lines changed

crypto/openssl_mbedtls_wrapper/include/openssl/base.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ typedef struct BN_CTX BN_CTX;
5757
typedef struct EC_GROUP EC_GROUP;
5858
typedef struct EC_KEY EC_KEY;
5959
typedef struct EC_POINT EC_POINT;
60-
typedef struct EVP_PKEY EVP_PKEY;
60+
typedef struct evp_pkey_st EVP_PKEY;
6161
typedef struct EVP_PKEY_CTX EVP_PKEY_CTX;
6262
typedef struct PKCS8_PRIV_KEY_INFO PKCS8_PRIV_KEY_INFO;
63-
typedef struct RSA RSA;
64-
typedef struct X509 X509;
6563
typedef struct X509_ALGOR X509_ALGOR;
6664
typedef struct X509_EXTENSION X509_EXTENSION;
6765
typedef struct X509_NAME X509_NAME;
@@ -74,6 +72,7 @@ typedef struct sha256_state_st SHA256_CTX;
7472
typedef struct sha_state_st SHA_CTX;
7573
typedef struct cbb_st CBB;
7674
typedef struct ecdsa_sig_st ECDSA_SIG;
75+
typedef void RSA;
7776

7877
#ifdef __cplusplus
7978
}

crypto/openssl_mbedtls_wrapper/include/openssl/err.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ extern "C"
4545

4646
unsigned long ERR_peek_last_error(void);
4747
void ERR_error_string_n(unsigned long e, char *buf, size_t len);
48+
void ERR_free_strings(void);
49+
char *ERR_error_string(unsigned long e, char *buf);
4850

4951
#ifdef __cplusplus
5052
}

crypto/openssl_mbedtls_wrapper/include/openssl/evp.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <openssl/ec_key.h>
3131
#include <openssl/mem.h>
3232
#include <openssl/nid.h>
33+
#include <openssl/types.h>
3334

3435
/****************************************************************************
3536
* Pre-processor Definitions
@@ -41,6 +42,12 @@
4142

4243
#define EVP_PKEY_X25519 NID_X25519
4344

45+
struct evp_pkey_st
46+
{
47+
void *pkey_pm;
48+
const PKEY_METHOD *method;
49+
};
50+
4451
#ifdef __cplusplus
4552
extern "C"
4653
{
@@ -56,6 +63,8 @@ RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey);
5663

5764
int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key);
5865

66+
EVP_PKEY *__EVP_PKEY_new(EVP_PKEY *ipk);
67+
5968
EVP_PKEY *EVP_PKEY_new(void);
6069

6170
void EVP_PKEY_free(EVP_PKEY *pkey);
@@ -153,6 +162,8 @@ int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len,
153162
unsigned iterations, const EVP_MD *digest,
154163
size_t key_len, uint8_t *out_key);
155164

165+
const PKEY_METHOD *EVP_PKEY_method(void);
166+
156167
#ifdef __cplusplus
157168
}
158169
#endif
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
/****************************************************************************
2+
* apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h
3+
*
4+
* Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
****************************************************************************/
18+
19+
#ifndef OPENSSL_MBEDTLS_WRAPPER_SSL_H
20+
#define OPENSSL_MBEDTLS_WRAPPER_SSL_H
21+
22+
/****************************************************************************
23+
* Included Files
24+
****************************************************************************/
25+
26+
#include <stddef.h>
27+
#include <openssl/types.h>
28+
#include <openssl/x509_vfy.h>
29+
#include <openssl/tls1.h>
30+
31+
/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
32+
#define SSL_SENT_SHUTDOWN 1
33+
#define SSL_RECEIVED_SHUTDOWN 2
34+
35+
#define SSL_VERIFY_NONE 0x00
36+
#define SSL_VERIFY_PEER 0x01
37+
#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
38+
#define SSL_VERIFY_CLIENT_ONCE 0x04
39+
40+
/* The following 3 states are kept in ssl->rlayer.rstate when reads fail, you
41+
* should not need these
42+
*/
43+
#define SSL_ST_READ_HEADER 0xF0
44+
#define SSL_ST_READ_BODY 0xF1
45+
#define SSL_ST_READ_DONE 0xF2
46+
47+
#define SSL_NOTHING 1
48+
#define SSL_WRITING 2
49+
#define SSL_READING 3
50+
#define SSL_X509_LOOKUP 4
51+
#define SSL_ASYNC_PAUSED 5
52+
#define SSL_ASYNC_NO_JOBS 6
53+
54+
#define SSL_ERROR_NONE 0
55+
#define SSL_ERROR_SSL 1
56+
#define SSL_ERROR_WANT_READ 2
57+
#define SSL_ERROR_WANT_WRITE 3
58+
#define SSL_ERROR_WANT_X509_LOOKUP 4
59+
#define SSL_ERROR_SYSCALL 5/* look at error stack/return value/errno */
60+
#define SSL_ERROR_ZERO_RETURN 6
61+
#define SSL_ERROR_WANT_CONNECT 7
62+
#define SSL_ERROR_WANT_ACCEPT 8
63+
#define SSL_ERROR_WANT_ASYNC 9
64+
#define SSL_ERROR_WANT_ASYNC_JOB 10
65+
66+
typedef enum
67+
{
68+
TLS_ST_BEFORE,
69+
TLS_ST_OK,
70+
DTLS_ST_CR_HELLO_VERIFY_REQUEST,
71+
TLS_ST_CR_SRVR_HELLO,
72+
TLS_ST_CR_CERT,
73+
TLS_ST_CR_CERT_STATUS,
74+
TLS_ST_CR_KEY_EXCH,
75+
TLS_ST_CR_CERT_REQ,
76+
TLS_ST_CR_SRVR_DONE,
77+
TLS_ST_CR_SESSION_TICKET,
78+
TLS_ST_CR_CHANGE,
79+
TLS_ST_CR_FINISHED,
80+
TLS_ST_CW_CLNT_HELLO,
81+
TLS_ST_CW_CERT,
82+
TLS_ST_CW_KEY_EXCH,
83+
TLS_ST_CW_CERT_VRFY,
84+
TLS_ST_CW_CHANGE,
85+
TLS_ST_CW_NEXT_PROTO,
86+
TLS_ST_CW_FINISHED,
87+
TLS_ST_SW_HELLO_REQ,
88+
TLS_ST_SR_CLNT_HELLO,
89+
DTLS_ST_SW_HELLO_VERIFY_REQUEST,
90+
TLS_ST_SW_SRVR_HELLO,
91+
TLS_ST_SW_CERT,
92+
TLS_ST_SW_KEY_EXCH,
93+
TLS_ST_SW_CERT_REQ,
94+
TLS_ST_SW_SRVR_DONE,
95+
TLS_ST_SR_CERT,
96+
TLS_ST_SR_KEY_EXCH,
97+
TLS_ST_SR_CERT_VRFY,
98+
TLS_ST_SR_NEXT_PROTO,
99+
TLS_ST_SR_CHANGE,
100+
TLS_ST_SR_FINISHED,
101+
TLS_ST_SW_SESSION_TICKET,
102+
TLS_ST_SW_CERT_STATUS,
103+
TLS_ST_SW_CHANGE,
104+
TLS_ST_SW_FINISHED
105+
}
106+
OSSL_HANDSHAKE_STATE;
107+
108+
#ifdef __cplusplus
109+
extern "C"
110+
{
111+
#endif
112+
113+
/****************************************************************************
114+
* Public Function Prototypes
115+
****************************************************************************/
116+
117+
X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl);
118+
119+
int X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param,
120+
unsigned long flags);
121+
122+
int X509_VERIFY_PARAM_clear_hostflags(X509_VERIFY_PARAM *param,
123+
unsigned long flags);
124+
125+
int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);
126+
127+
int SSL_CTX_add_client_CA_ASN1(SSL_CTX *ssl, int len,
128+
const unsigned char *d);
129+
130+
int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
131+
132+
int SSL_use_certificate(SSL *ssl, X509 *x);
133+
134+
X509 *SSL_get_certificate(const SSL *ssl);
135+
136+
int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len,
137+
const unsigned char *d);
138+
139+
int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
140+
141+
int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
142+
143+
int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
144+
145+
X509 *SSL_get_peer_certificate(const SSL *ssl);
146+
147+
int SSL_want(const SSL *ssl);
148+
149+
int SSL_want_nothing(const SSL *ssl);
150+
151+
int SSL_want_read(const SSL *ssl);
152+
153+
int SSL_want_write(const SSL *ssl);
154+
155+
int SSL_want_x509_lookup(const SSL *ssl);
156+
157+
void _ssl_set_alpn_list(const SSL *ssl);
158+
159+
int SSL_get_error(const SSL *ssl, int ret_code);
160+
161+
OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl);
162+
163+
SSL_CTX *SSL_CTX_new(const SSL_METHOD *method, void *rngctx);
164+
165+
void SSL_CTX_free(SSL_CTX *ctx);
166+
167+
int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
168+
169+
const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx);
170+
171+
SSL *SSL_new(SSL_CTX *ctx);
172+
173+
void SSL_free(SSL *ssl);
174+
175+
int SSL_do_handshake(SSL *ssl);
176+
177+
int SSL_connect(SSL *ssl);
178+
179+
int SSL_accept(SSL *ssl);
180+
181+
int SSL_shutdown(SSL *ssl);
182+
183+
int SSL_clear(SSL *ssl);
184+
185+
int SSL_read(SSL *ssl, void *buffer, int len);
186+
187+
int SSL_write(SSL *ssl, const void *buffer, int len);
188+
189+
SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
190+
191+
const SSL_METHOD *SSL_get_ssl_method(SSL *ssl);
192+
193+
int SSL_set_ssl_method(SSL *ssl, const SSL_METHOD *method);
194+
195+
int SSL_get_shutdown(const SSL *ssl);
196+
197+
void SSL_set_shutdown(SSL *ssl, int mode);
198+
199+
int SSL_pending(const SSL *ssl);
200+
201+
int SSL_has_pending(const SSL *ssl);
202+
203+
unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op);
204+
205+
unsigned long SSL_CTX_get_options(SSL_CTX *ctx);
206+
207+
unsigned long SSL_clear_options(SSL *ssl, unsigned long op);
208+
209+
unsigned long SSL_get_options(SSL *ssl);
210+
211+
unsigned long SSL_set_options(SSL *ssl, unsigned long op);
212+
213+
int SSL_get_fd(const SSL *ssl);
214+
215+
int SSL_get_rfd(const SSL *ssl);
216+
217+
int SSL_get_wfd(const SSL *ssl);
218+
219+
int SSL_set_fd(SSL *ssl, int fd);
220+
221+
int SSL_set_rfd(SSL *ssl, int fd);
222+
223+
int SSL_set_wfd(SSL *ssl, int fd);
224+
225+
int SSL_version(const SSL *ssl);
226+
227+
const char *SSL_alert_type_string(int value);
228+
229+
void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len);
230+
231+
void SSL_set_default_read_buffer_len(SSL *ssl, size_t len);
232+
233+
void SSL_set_info_callback(SSL *ssl,
234+
void (*cb) (const SSL *ssl, int type, int val));
235+
236+
int SSL_CTX_up_ref(SSL_CTX *ctx);
237+
238+
void SSL_set_security_level(SSL *ssl, int level);
239+
240+
int SSL_get_security_level(const SSL *ssl);
241+
242+
int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
243+
244+
long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
245+
246+
long SSL_CTX_get_timeout(const SSL_CTX *ctx);
247+
248+
void SSL_set_read_ahead(SSL *ssl, int yes);
249+
250+
void SSL_CTX_set_read_ahead(SSL_CTX *ctx, int yes);
251+
252+
int SSL_get_read_ahead(const SSL *ssl);
253+
254+
long SSL_CTX_get_read_ahead(SSL_CTX *ctx);
255+
256+
long SSL_CTX_get_default_read_ahead(SSL_CTX *ctx);
257+
258+
long SSL_set_time(SSL *ssl, long t);
259+
260+
long SSL_set_timeout(SSL *ssl, long t);
261+
262+
long SSL_get_verify_result(const SSL *ssl);
263+
264+
int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
265+
266+
void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
267+
268+
int SSL_get_verify_depth(const SSL *ssl);
269+
270+
void SSL_set_verify_depth(SSL *ssl, int depth);
271+
272+
void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
273+
int (*verify_callback)(int, X509_STORE_CTX *));
274+
275+
void SSL_set_verify(SSL *ssl, int mode,
276+
int (*verify_callback)(int, X509_STORE_CTX *));
277+
278+
void *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx);
279+
280+
void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, next_proto_cb cb, void *arg);
281+
282+
void SSL_set_alpn_select_cb(SSL *ssl, void *arg);
283+
284+
int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
285+
286+
int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
287+
288+
int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx,
289+
const unsigned char *d, long len);
290+
291+
int SSL_use_PrivateKey_ASN1(int type, SSL *ssl,
292+
const unsigned char *d, long len);
293+
294+
int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
295+
296+
int SSL_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
297+
298+
int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d,
299+
long len);
300+
301+
#ifdef __cplusplus
302+
}
303+
#endif
304+
305+
#endif /* OPENSSL_MBEDTLS_WRAPPER_SSL_H */

0 commit comments

Comments
 (0)