1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "ssl_methods.h"
16 #include "ssl_pm.h"
17
18 /**
19 * TLS method function collection
20 */
21 IMPLEMENT_TLS_METHOD_FUNC(TLS_method_func,
22 ssl_pm_new, ssl_pm_free,
23 ssl_pm_handshake, ssl_pm_shutdown, ssl_pm_clear,
24 ssl_pm_read, ssl_pm_send, ssl_pm_pending,
25 ssl_pm_set_fd, ssl_pm_set_hostname, ssl_pm_get_fd,
26 ssl_pm_set_bufflen,
27 ssl_pm_get_verify_result,
28 ssl_pm_get_state);
29
30 /**
31 * TLS or SSL client method collection
32 */
33 IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, 0, TLS_method_func, TLS_client_method);
34
35 IMPLEMENT_TLS_METHOD(TLS1_2_VERSION, 0, TLS_method_func, TLSv1_2_client_method);
36
37 IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, 0, TLS_method_func, TLSv1_1_client_method);
38
39 IMPLEMENT_TLS_METHOD(TLS1_VERSION, 0, TLS_method_func, TLSv1_client_method);
40
41 IMPLEMENT_SSL_METHOD(SSL3_VERSION, 0, TLS_method_func, SSLv3_client_method);
42
43 /**
44 * TLS or SSL server method collection
45 */
46 IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, 1, TLS_method_func, TLS_server_method);
47
48 IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, 1, TLS_method_func, TLSv1_1_server_method);
49
50 IMPLEMENT_TLS_METHOD(TLS1_2_VERSION, 1, TLS_method_func, TLSv1_2_server_method);
51
52 IMPLEMENT_TLS_METHOD(TLS1_VERSION, 1, TLS_method_func, TLSv1_server_method);
53
54 IMPLEMENT_SSL_METHOD(SSL3_VERSION, 1, TLS_method_func, SSLv3_server_method);
55
56 /**
57 * TLS or SSL method collection
58 */
59 IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, -1, TLS_method_func, TLS_method);
60
61 IMPLEMENT_TLS_METHOD(TLS1_2_VERSION, -1, TLS_method_func, TLSv1_2_method);
62
63 IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, -1, TLS_method_func, TLSv1_1_method);
64
65 IMPLEMENT_TLS_METHOD(TLS1_VERSION, -1, TLS_method_func, TLSv1_method);
66
67 IMPLEMENT_SSL_METHOD(SSL3_VERSION, -1, TLS_method_func, SSLv3_method);
68
69 /**
70 * @brief get X509 object method
71 */
72 IMPLEMENT_X509_METHOD(X509_method,
73 x509_pm_new, x509_pm_free,
74 x509_pm_load, x509_pm_show_info);
75
76 /**
77 * @brief get private key object method
78 */
79 IMPLEMENT_PKEY_METHOD(EVP_PKEY_method,
80 pkey_pm_new, pkey_pm_free,
81 pkey_pm_load);
82
83 /**
84 * @brief Generic SSL/TLS methods
85 */
SSLv23_method(void)86 const SSL_METHOD *SSLv23_method(void)
87 {
88 return TLS_method();
89 }
90
SSLv23_server_method(void)91 const SSL_METHOD *SSLv23_server_method(void)
92 {
93 return TLS_server_method();
94 }
95
SSLv23_client_method(void)96 const SSL_METHOD *SSLv23_client_method(void)
97 {
98 return TLS_client_method();
99 }
100
SSL_CTX_set_min_proto_version(SSL_CTX * ctx,int version)101 int SSL_CTX_set_min_proto_version(SSL_CTX *ctx, int version)
102 {
103 ctx->min_version = version;
104 return 1;
105 }
106
SSL_CTX_set_max_proto_version(SSL_CTX * ctx,int version)107 int SSL_CTX_set_max_proto_version(SSL_CTX *ctx, int version)
108 {
109 ctx->max_version = version;
110 return 1;
111 }
112