xbmc
ssl.h
1 /*
2  * Copyright (c) 2007, Cameron Rich
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * * Neither the name of the axTLS project nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
63 #ifndef HEADER_SSL_H
64 #define HEADER_SSL_H
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 #include <time.h>
71 #include "os_port.h"
72 
73 /* need to predefine before ssl_lib.h gets to it */
74 #define SSL_SESSION_ID_SIZE 32
75 
76 #include "tls1.h"
77 
78 /* The optional parameters that can be given to the client/server SSL engine */
79 #define SSL_CLIENT_AUTHENTICATION 0x00010000
80 #define SSL_SERVER_VERIFY_LATER 0x00020000
81 #define SSL_NO_DEFAULT_KEY 0x00040000
82 #define SSL_DISPLAY_STATES 0x00080000
83 #define SSL_DISPLAY_BYTES 0x00100000
84 #define SSL_DISPLAY_CERTS 0x00200000
85 #define SSL_DISPLAY_RSA 0x00400000
86 #define SSL_CONNECT_IN_PARTS 0x00800000
87 
88 /* errors that can be generated */
89 #define SSL_OK 0
90 #define SSL_NOT_OK -1
91 #define SSL_ERROR_DEAD -2
92 #define SSL_CLOSE_NOTIFY -3
93 #define SSL_ERROR_CONN_LOST -256
94 #define SSL_ERROR_SOCK_SETUP_FAILURE -258
95 #define SSL_ERROR_INVALID_HANDSHAKE -260
96 #define SSL_ERROR_INVALID_PROT_MSG -261
97 #define SSL_ERROR_INVALID_HMAC -262
98 #define SSL_ERROR_INVALID_VERSION -263
99 #define SSL_ERROR_INVALID_SESSION -265
100 #define SSL_ERROR_NO_CIPHER -266
101 #define SSL_ERROR_BAD_CERTIFICATE -268
102 #define SSL_ERROR_INVALID_KEY -269
103 #define SSL_ERROR_FINISHED_INVALID -271
104 #define SSL_ERROR_NO_CERT_DEFINED -272
105 #define SSL_ERROR_NO_CLIENT_RENOG -273
106 #define SSL_ERROR_NOT_SUPPORTED -274
107 #define SSL_ERROR_TIMEOUT -275 /* GBG */
108 #define SSL_ERROR_EOS -276 /* GBG */
109 #define SSL_X509_OFFSET -512
110 #define SSL_X509_ERROR(A) (SSL_X509_OFFSET+A)
111 
112 /* alert types that are recognized */
113 #define SSL_ALERT_TYPE_WARNING 1
114 #define SLL_ALERT_TYPE_FATAL 2
115 
116 /* these are all the alerts that are recognized */
117 #define SSL_ALERT_CLOSE_NOTIFY 0
118 #define SSL_ALERT_UNEXPECTED_MESSAGE 10
119 #define SSL_ALERT_BAD_RECORD_MAC 20
120 #define SSL_ALERT_HANDSHAKE_FAILURE 40
121 #define SSL_ALERT_BAD_CERTIFICATE 42
122 #define SSL_ALERT_ILLEGAL_PARAMETER 47
123 #define SSL_ALERT_DECODE_ERROR 50
124 #define SSL_ALERT_DECRYPT_ERROR 51
125 #define SSL_ALERT_INVALID_VERSION 70
126 #define SSL_ALERT_NO_RENEGOTIATION 100
127 
128 /* The ciphers that are supported */
129 #define SSL_AES128_SHA 0x2f
130 #define SSL_AES256_SHA 0x35
131 #define SSL_RC4_128_SHA 0x05
132 #define SSL_RC4_128_MD5 0x04
133 
134 /* build mode ids' */
135 #define SSL_BUILD_SKELETON_MODE 0x01
136 #define SSL_BUILD_SERVER_ONLY 0x02
137 #define SSL_BUILD_ENABLE_VERIFICATION 0x03
138 #define SSL_BUILD_ENABLE_CLIENT 0x04
139 #define SSL_BUILD_FULL_MODE 0x05
140 
141 /* offsets to retrieve configuration information */
142 #define SSL_BUILD_MODE 0
143 #define SSL_MAX_CERT_CFG_OFFSET 1
144 #define SSL_MAX_CA_CERT_CFG_OFFSET 2
145 #define SSL_HAS_PEM 3
146 
147 /* default session sizes */
148 #define SSL_DEFAULT_SVR_SESS 5
149 #define SSL_DEFAULT_CLNT_SESS 1
150 
151 /* X.509/X.520 distinguished name types */
152 #define SSL_X509_CERT_COMMON_NAME 0
153 #define SSL_X509_CERT_ORGANIZATION 1
154 #define SSL_X509_CERT_ORGANIZATIONAL_NAME 2
155 #define SSL_X509_CA_CERT_COMMON_NAME 3
156 #define SSL_X509_CA_CERT_ORGANIZATION 4
157 #define SSL_X509_CA_CERT_ORGANIZATIONAL_NAME 5
158 
159 /* SSL object loader types */
160 #define SSL_OBJ_X509_CERT 1
161 #define SSL_OBJ_X509_CACERT 2
162 #define SSL_OBJ_RSA_KEY 3
163 #define SSL_OBJ_PKCS8 4
164 #define SSL_OBJ_PKCS12 5
165 
210 EXP_FUNC SSL_CTX * STDCALL ssl_ctx_new(uint32_t options, int num_sessions);
211 
219 EXP_FUNC void STDCALL ssl_ctx_free(SSL_CTX *ssl_ctx);
220 
230 EXP_FUNC SSL * STDCALL ssl_server_new(SSL_CTX *ssl_ctx, SSL_SOCKET* client_fd);
231 
250 EXP_FUNC SSL * STDCALL ssl_client_new(SSL_CTX *ssl_ctx, SSL_SOCKET* client_fd, const uint8_t *session_id, uint8_t sess_id_size);
251 
259 EXP_FUNC void STDCALL ssl_free(SSL *ssl);
260 
277 EXP_FUNC int STDCALL ssl_read(SSL *ssl, uint8_t **in_data);
278 
289 EXP_FUNC int STDCALL ssl_write(SSL *ssl, const uint8_t *out_data, int out_len);
290 
301 EXP_FUNC SSL * STDCALL ssl_find(SSL_CTX *ssl_ctx, SSL_SOCKET* client_fd);
302 
312 EXP_FUNC const uint8_t * STDCALL ssl_get_session_id(const SSL *ssl);
313 
321 EXP_FUNC uint8_t STDCALL ssl_get_session_id_size(const SSL *ssl);
322 
332 EXP_FUNC uint8_t STDCALL ssl_get_cipher_id(const SSL *ssl);
333 
340 EXP_FUNC int STDCALL ssl_handshake_status(const SSL *ssl);
341 
356 EXP_FUNC int STDCALL ssl_get_config(int offset);
357 
365 EXP_FUNC void STDCALL ssl_display_error(int error_code);
366 
375 EXP_FUNC int STDCALL ssl_verify_cert(const SSL *ssl);
376 
397 /* GBG: modified */
398 EXP_FUNC const char * STDCALL ssl_cert_get_dn(const SSL_X509_CERT *cert, int component);
399 
414 /* GBG: modified */
415 EXP_FUNC const char * STDCALL ssl_cert_get_subject_alt_dnsname(const SSL_X509_CERT *cert, int dnsindex);
416 
417 /* GBG added */
418 EXP_FUNC const SSL_X509_CERT* ssl_get_peer_cert(const SSL* ssl, unsigned int position);
419 EXP_FUNC void ssl_cert_get_fingerprints(const SSL_X509_CERT *cert, unsigned char* md5, unsigned char* sha1);
420 EXP_FUNC void ssl_cert_get_validity_dates(const SSL_X509_CERT *cert, SSL_DateTime* not_before, SSL_DateTime* not_after);
421 
433 EXP_FUNC int STDCALL ssl_renegotiate(SSL *ssl);
434 
455 EXP_FUNC int STDCALL ssl_obj_load(SSL_CTX *ssl_ctx, int obj_type, const char *filename, const char *password);
456 
470 EXP_FUNC int STDCALL ssl_obj_memory_load(SSL_CTX *ssl_ctx, int obj_type, const uint8_t *data, int len, const char *password);
471 
472 #ifdef CONFIG_SSL_GENERATE_X509_CERT
473 
495 EXP_FUNC int STDCALL ssl_x509_create(SSL_CTX *ssl_ctx, uint32_t options, const char * dn[], uint8_t **cert_data);
496 #endif
497 
501 EXP_FUNC const char * STDCALL ssl_version(void);
502 
503 EXP_FUNC void ssl_mem_free(void* mem); /* GBG */
504 
507 #ifdef __cplusplus
508 }
509 #endif
510 
511 #endif
EXP_FUNC void STDCALL ssl_display_error(int error_code)
Display why the handshake failed.
Definition: tls1.c:2235
Definition: tls1.h:162
EXP_FUNC SSL *STDCALL ssl_server_new(SSL_CTX *ssl_ctx, SSL_SOCKET *client_fd)
(server only) Establish a new SSL connection to an SSL client.
Definition: tls1_svr.c:52
EXP_FUNC int STDCALL ssl_get_config(int offset)
Retrieve various parameters about the axTLS engine.
EXP_FUNC const char *STDCALL ssl_cert_get_subject_alt_dnsname(const SSL_X509_CERT *cert, int dnsindex)
Retrieve a Subject Alternative DNSName.
EXP_FUNC const char *STDCALL ssl_cert_get_dn(const SSL_X509_CERT *cert, int component)
Retrieve an X.509 distinguished name component.
EXP_FUNC int STDCALL ssl_read(SSL *ssl, uint8_t **in_data)
Read the SSL data stream.
Definition: tls1.c:304
Definition: crypto_misc.h:68
EXP_FUNC const char *STDCALL ssl_version(void)
Return the axTLS library version as a string.
Definition: tls1.c:2219
EXP_FUNC int STDCALL ssl_obj_memory_load(SSL_CTX *ssl_ctx, int obj_type, const uint8_t *data, int len, const char *password)
Process binary data.
Definition: loader.c:108
Definition: tls1.h:204
EXP_FUNC void STDCALL ssl_ctx_free(SSL_CTX *ssl_ctx)
Remove a client/server context.
Definition: tls1.c:208
EXP_FUNC uint8_t STDCALL ssl_get_session_id_size(const SSL *ssl)
Get the session id size for a handshake.
Definition: tls1.c:1835
EXP_FUNC SSL *STDCALL ssl_find(SSL_CTX *ssl_ctx, SSL_SOCKET *client_fd)
Find an ssl object based on a file descriptor.
Definition: tls1.c:580
EXP_FUNC void STDCALL ssl_free(SSL *ssl)
Free any used resources on this connection.
Definition: tls1.c:261
EXP_FUNC int STDCALL ssl_obj_load(SSL_CTX *ssl_ctx, int obj_type, const char *filename, const char *password)
Process a file that is in binary DER or ASCII PEM format.
EXP_FUNC int STDCALL ssl_verify_cert(const SSL *ssl)
Authenticate a received certificate.
Definition: os_port.h:58
The definitions for the TLS library.
EXP_FUNC int STDCALL ssl_renegotiate(SSL *ssl)
Force the client to perform its handshake again.
Definition: tls1.c:606
EXP_FUNC SSL *STDCALL ssl_client_new(SSL_CTX *ssl_ctx, SSL_SOCKET *client_fd, const uint8_t *session_id, uint8_t sess_id_size)
(client only) Establish a new SSL connection to an SSL server.
EXP_FUNC const uint8_t *STDCALL ssl_get_session_id(const SSL *ssl)
Get the session id for a handshake.
Definition: tls1.c:1827
EXP_FUNC int STDCALL ssl_write(SSL *ssl, const uint8_t *out_data, int out_len)
Write to the SSL data stream.
Definition: tls1.c:329
EXP_FUNC SSL_CTX *STDCALL ssl_ctx_new(uint32_t options, int num_sessions)
Establish a new client/server context.
Definition: tls1.c:174
Definition: os_port.h:63
EXP_FUNC int STDCALL ssl_handshake_status(const SSL *ssl)
Return the status of the handshake.
Definition: tls1.c:1851
EXP_FUNC uint8_t STDCALL ssl_get_cipher_id(const SSL *ssl)
Return the cipher id (in the SSL form).
Definition: tls1.c:1843