MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ssl.h
1 /*
2  Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; see the file COPYING. If not, write to the
15  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
16  MA 02110-1301 USA.
17  */
18 
19 /* ssl.h defines openssl compatibility layer
20  *
21  */
22 
23 
24 
25 #ifndef yaSSL_openssl_h__
26 #define yaSSL_openssl_h__
27 
28 #ifdef YASSL_PREFIX
29 #include "prefix_ssl.h"
30 #endif
31 
32 #include <stdio.h> /* ERR_print fp */
33 #include "opensslv.h" /* for version number */
34 #include "rsa.h"
35 
36 
37 #define YASSL_VERSION "2.2.2"
38 
39 
40 #if defined(__cplusplus)
41 extern "C" {
42 #endif
43 
44  void yaSSL_CleanUp(); /* call once at end of application use to
45  free static singleton memory holders,
46  not a leak per se, but helpful when
47  looking for them */
48 
49 #if defined(__cplusplus)
50 } // extern
51 #endif
52 
53 #if defined(__cplusplus) && !defined(YASSL_MYSQL_COMPATIBLE)
54 namespace yaSSL {
55 extern "C" {
56 #endif
57 
58 #undef X509_NAME /* wincrypt.h clash */
59 
60 #if defined(__cplusplus) && !defined(YASSL_MYSQL_COMPATIBLE)
61  class SSL;
62  class SSL_SESSION;
63  class SSL_METHOD;
64  class SSL_CTX;
65  class SSL_CIPHER;
66 
67  class RSA;
68 
69  class X509;
70  class X509_NAME;
71 #else
72  typedef struct SSL SSL;
73  typedef struct SSL_SESSION SSL_SESSION;
74  typedef struct SSL_METHOD SSL_METHOD;
75  typedef struct SSL_CTX SSL_CTX;
76  typedef struct SSL_CIPHER SSL_CIPHER;
77 
78  typedef struct RSA RSA;
79 
80  typedef struct X509 X509;
81  typedef struct X509_NAME X509_NAME;
82 #endif
83 
84 
85 /* Big Number stuff, different file? */
86 typedef struct BIGNUM BIGNUM;
87 
88 BIGNUM *BN_bin2bn(const unsigned char*, int, BIGNUM*);
89 
90 
91 /* Diffie-Hellman stuff, different file? */
92 /* mySQL deferences to set group parameters */
93 typedef struct DH {
94  BIGNUM* p;
95  BIGNUM* g;
96 } DH;
97 
98 DH* DH_new(void);
99 void DH_free(DH*);
100 
101 /* RSA stuff */
102 
103 void RSA_free(RSA*);
104 RSA* RSA_generate_key(int, unsigned long, void(*)(int, int, void*), void*);
105 
106 
107 /* X509 stuff, different file? */
108 
109 /* because mySQL dereferences to use error and current_cert, even after calling
110  * get functions for local references */
111 typedef struct X509_STORE_CTX {
112  int error;
113  int error_depth;
114  X509* current_cert;
116 
117 
118 typedef struct X509_STORE X509_STORE;
119 typedef struct X509_LOOKUP X509_LOOKUP;
120 typedef struct X509_OBJECT { char c; } X509_OBJECT;
121 typedef struct X509_CRL X509_CRL;
122 typedef struct X509_REVOKED X509_REVOKED;
123 typedef struct X509_LOOKUP_METHOD X509_LOOKUP_METHOD;
124 
125 
126 void X509_free(X509*);
127 
128 
129 /* bio stuff */
130 typedef struct BIO BIO;
131 
132 /* ASN stuff */
133 
134 
135 
136 X509* X509_STORE_CTX_get_current_cert(X509_STORE_CTX*);
137 int X509_STORE_CTX_get_error(X509_STORE_CTX*);
138 int X509_STORE_CTX_get_error_depth(X509_STORE_CTX*);
139 
140 char* X509_NAME_oneline(X509_NAME*, char*, int);
141 X509_NAME* X509_get_issuer_name(X509*);
142 X509_NAME* X509_get_subject_name(X509*);
143 const char* X509_verify_cert_error_string(long);
144 
145 int X509_LOOKUP_add_dir(X509_LOOKUP*, const char*, long);
146 int X509_LOOKUP_load_file(X509_LOOKUP*, const char*, long);
147 X509_LOOKUP_METHOD* X509_LOOKUP_hash_dir(void);
148 X509_LOOKUP_METHOD* X509_LOOKUP_file(void);
149 
150 X509_LOOKUP* X509_STORE_add_lookup(X509_STORE*, X509_LOOKUP_METHOD*);
151 X509_STORE* X509_STORE_new(void);
152 int X509_STORE_get_by_subject(X509_STORE_CTX*, int, X509_NAME*,
153  X509_OBJECT*);
154 
155 
156 
157 
158 enum { /* X509 Constants */
159  X509_V_OK = 0,
160  X509_V_ERR_CERT_CHAIN_TOO_LONG = 1,
161  X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2,
162  X509_V_ERR_CERT_NOT_YET_VALID = 3,
163  X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD = 4,
164  X509_V_ERR_CERT_HAS_EXPIRED = 5,
165  X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD = 6,
166  X509_FILETYPE_PEM = 7,
167  X509_LU_X509 = 8,
168  X509_LU_CRL = 9,
169  X509_V_ERR_CRL_SIGNATURE_FAILURE = 10,
170  X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 11,
171  X509_V_ERR_CRL_HAS_EXPIRED = 12,
172  X509_V_ERR_CERT_REVOKED = 13,
173  X509_V_FLAG_CRL_CHECK = 14,
174  X509_V_FLAG_CRL_CHECK_ALL = 15
175 };
176 
177 
178 /* Error stuff, could move to yassl_error */
179 unsigned long ERR_get_error_line_data(const char**, int*, const char**, int *);
180 void ERR_print_errors_fp(FILE*);
181 char* ERR_error_string(unsigned long,char*);
182 void ERR_remove_state(unsigned long);
183 unsigned long ERR_get_error(void);
184 unsigned long ERR_peek_error(void);
185 int ERR_GET_REASON(int);
186 
187 
188 enum { /* ERR Constants */
189  ERR_TXT_STRING = 1,
190  EVP_R_BAD_DECRYPT = 2
191 };
192 
193 /*
194  Allow type used by SSL_set_fd to be changed, default to int
195  in order to be compatible with OpenSSL
196  */
197 #ifndef YASSL_SOCKET_T_DEFINED
198 typedef int YASSL_SOCKET_T;
199 #endif
200 
201 SSL_CTX* SSL_CTX_new(SSL_METHOD*);
202 SSL* SSL_new(SSL_CTX*);
203 int SSL_set_fd (SSL*, YASSL_SOCKET_T);
204 YASSL_SOCKET_T SSL_get_fd(const SSL*);
205 int SSL_connect(SSL*); /* if you get an error from connect
206  see note at top of README */
207 int SSL_write(SSL*, const void*, int);
208 int SSL_read(SSL*, void*, int);
209 int SSL_accept(SSL*);
210 void SSL_CTX_free(SSL_CTX*);
211 void SSL_free(SSL*);
212 int SSL_clear(SSL*);
213 int SSL_shutdown(SSL*);
214 
215 void SSL_set_connect_state(SSL*);
216 void SSL_set_accept_state(SSL*);
217 int SSL_do_handshake(SSL*);
218 
219 const char* SSL_get_cipher(SSL*);
220 const char* SSL_get_cipher_name(SSL*); /* uses SSL_get_cipher */
221 char* SSL_get_shared_ciphers(SSL*, char*, int);
222 const char* SSL_get_cipher_list(SSL*, int);
223 const char* SSL_get_version(SSL*);
224 const char* SSLeay_version(int);
225 
226 int SSL_get_error(SSL*, int);
227 void SSL_load_error_strings(void);
228 
229 int SSL_set_session(SSL *ssl, SSL_SESSION *session);
230 SSL_SESSION* SSL_get_session(SSL* ssl);
231 void SSL_flush_sessions(SSL_CTX *ctx, long tm);
232 long SSL_SESSION_set_timeout(SSL_SESSION*, long);
233 long SSL_CTX_set_session_cache_mode(SSL_CTX* ctx, long mode);
234 X509* SSL_get_peer_certificate(SSL*);
235 long SSL_get_verify_result(SSL*);
236 
237 
238 typedef int (*VerifyCallback)(int, X509_STORE_CTX*);
239 typedef int (*pem_password_cb)(char*, int, int, void*);
240 
241 void SSL_CTX_set_verify(SSL_CTX*, int, VerifyCallback verify_callback);
242 int SSL_CTX_load_verify_locations(SSL_CTX*, const char*, const char*);
243 int SSL_CTX_set_default_verify_paths(SSL_CTX*);
244 int SSL_CTX_check_private_key(SSL_CTX*);
245 int SSL_CTX_set_session_id_context(SSL_CTX*, const unsigned char*,
246  unsigned int);
247 
248 void SSL_CTX_set_tmp_rsa_callback(SSL_CTX*, RSA*(*)(SSL*, int, int));
249 long SSL_CTX_set_options(SSL_CTX*, long);
250 long SSL_CTX_set_session_cache_mode(SSL_CTX*, long);
251 long SSL_CTX_set_timeout(SSL_CTX*, long);
252 int SSL_CTX_use_certificate_chain_file(SSL_CTX*, const char*);
253 void SSL_CTX_set_default_passwd_cb(SSL_CTX*, pem_password_cb);
254 int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX*, const char*, int);
255 void SSL_CTX_set_info_callback(SSL_CTX*, void (*)());
256 
257 long SSL_CTX_sess_accept(SSL_CTX*);
258 long SSL_CTX_sess_connect(SSL_CTX*);
259 long SSL_CTX_sess_accept_good(SSL_CTX*);
260 long SSL_CTX_sess_connect_good(SSL_CTX*);
261 long SSL_CTX_sess_accept_renegotiate(SSL_CTX*);
262 long SSL_CTX_sess_connect_renegotiate(SSL_CTX*);
263 long SSL_CTX_sess_hits(SSL_CTX*);
264 long SSL_CTX_sess_cb_hits(SSL_CTX*);
265 long SSL_CTX_sess_cache_full(SSL_CTX*);
266 long SSL_CTX_sess_misses(SSL_CTX*);
267 long SSL_CTX_sess_timeouts(SSL_CTX*);
268 long SSL_CTX_sess_number(SSL_CTX*);
269 long SSL_CTX_sess_get_cache_size(SSL_CTX*);
270 
271 int SSL_CTX_get_verify_mode(SSL_CTX*);
272 int SSL_get_verify_mode(SSL*);
273 int SSL_CTX_get_verify_depth(SSL_CTX*);
274 int SSL_get_verify_depth(SSL*);
275 
276 long SSL_get_default_timeout(SSL*);
277 long SSL_CTX_get_session_cache_mode(SSL_CTX*);
278 int SSL_session_reused(SSL*);
279 
280 int SSL_set_rfd(SSL*, int);
281 int SSL_set_wfd(SSL*, int);
282 void SSL_set_shutdown(SSL*, int);
283 void SSL_set_quiet_shutdown(SSL *ssl,int mode);
284 int SSL_get_quiet_shutdown(SSL *ssl);
285 
286 int SSL_want_read(SSL*);
287 int SSL_want_write(SSL*);
288 
289 int SSL_pending(SSL*);
290 
291 
292 enum { /* ssl Constants */
293  SSL_WOULD_BLOCK = -8,
294  SSL_BAD_STAT = -7,
295  SSL_BAD_PATH = -6,
296  SSL_BAD_FILETYPE = -5,
297  SSL_BAD_FILE = -4,
298  SSL_NOT_IMPLEMENTED = -3,
299  SSL_UNKNOWN = -2,
300  SSL_FATAL_ERROR = -1,
301  SSL_NORMAL_SHUTDOWN = 0,
302  SSL_ERROR_NONE = 0, /* for most functions */
303  SSL_FAILURE = 0, /* for some functions */
304  SSL_SUCCESS = 1,
305 
306  SSL_FILETYPE_ASN1 = 10,
307  SSL_FILETYPE_PEM = 11,
308  SSL_FILETYPE_DEFAULT = 10, /* ASN1 */
309 
310  SSL_VERIFY_NONE = 0,
311  SSL_VERIFY_PEER = 1,
312  SSL_VERIFY_FAIL_IF_NO_PEER_CERT = 2,
313  SSL_VERIFY_CLIENT_ONCE = 4,
314 
315  SSL_SESS_CACHE_OFF = 30,
316  SSL_SESS_CACHE_CLIENT = 31,
317  SSL_SESS_CACHE_SERVER = 32,
318  SSL_SESS_CACHE_BOTH = 33,
319  SSL_SESS_CACHE_NO_AUTO_CLEAR = 34,
320  SSL_SESS_CACHE_NO_INTERNAL_LOOKUP = 35,
321 
322  SSL_OP_MICROSOFT_SESS_ID_BUG = 50,
323  SSL_OP_NETSCAPE_CHALLENGE_BUG = 51,
324  SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG = 52,
325  SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG = 53,
326  SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER = 54,
327  SSL_OP_MSIE_SSLV2_RSA_PADDING = 55,
328  SSL_OP_SSLEAY_080_CLIENT_DH_BUG = 56,
329  SSL_OP_TLS_D5_BUG = 57,
330  SSL_OP_TLS_BLOCK_PADDING_BUG = 58,
331  SSL_OP_TLS_ROLLBACK_BUG = 59,
332  SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS = 60,
333  SSL_OP_ALL = 61,
334  SSL_OP_SINGLE_DH_USE = 62,
335  SSL_OP_EPHEMERAL_RSA = 63,
336  SSL_OP_NO_SSLv2 = 64,
337  SSL_OP_NO_SSLv3 = 65,
338  SSL_OP_NO_TLSv1 = 66,
339  SSL_OP_PKCS1_CHECK_1 = 67,
340  SSL_OP_PKCS1_CHECK_2 = 68,
341  SSL_OP_NETSCAPE_CA_DN_BUG = 69,
342  SSL_OP_NON_EXPORT_FIRST = 70,
343  SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG = 71,
344 
345  SSL_ERROR_WANT_READ = 80,
346  SSL_ERROR_WANT_WRITE = 81,
347  SSL_ERROR_SYSCALL = 82,
348  SSL_ERROR_WANT_X509_LOOKUP = 83,
349  SSL_ERROR_ZERO_RETURN = 84,
350  SSL_ERROR_SSL = 85,
351 
352  SSL_ST_CONNECT = 90,
353  SSL_ST_ACCEPT = 91,
354  SSL_CB_LOOP = 92,
355  SSL_SENT_SHUTDOWN = 93,
356  SSL_RECEIVED_SHUTDOWN = 94,
357  SSL_CB_ALERT = 95,
358  SSL_CB_READ = 96,
359  SSL_CB_HANDSHAKE_DONE = 97
360 
361 };
362 
363 
364 SSL_METHOD *SSLv3_method(void);
365 SSL_METHOD *SSLv3_server_method(void);
366 SSL_METHOD *SSLv3_client_method(void);
367 SSL_METHOD *TLSv1_server_method(void);
368 SSL_METHOD *TLSv1_client_method(void);
369 SSL_METHOD *TLSv1_1_server_method(void);
370 SSL_METHOD *TLSv1_1_client_method(void);
371 SSL_METHOD *SSLv23_server_method(void);
372 
373 int SSL_CTX_use_certificate_file(SSL_CTX*, const char*, int);
374 int SSL_CTX_use_PrivateKey_file(SSL_CTX*, const char*, int);
375 int SSL_CTX_set_cipher_list(SSL_CTX*, const char*);
376 
377 long SSL_CTX_sess_set_cache_size(SSL_CTX*, long);
378 long SSL_CTX_set_tmp_dh(SSL_CTX*, DH*);
379 
380 void OpenSSL_add_all_algorithms(void);
381 int SSL_library_init();
382 int SSLeay_add_ssl_algorithms(void);
383 
384 
385 SSL_CIPHER* SSL_get_current_cipher(SSL*);
386 char* SSL_CIPHER_description(SSL_CIPHER*, char*, int);
387 
388 
389 char* SSL_alert_type_string_long(int);
390 char* SSL_alert_desc_string_long(int);
391 char* SSL_state_string_long(SSL*);
392 
393 
394 /* EVP stuff, des and md5, different file? */
395 typedef char EVP_MD;
396 
397 typedef char EVP_CIPHER;
398 
399 typedef struct EVP_PKEY EVP_PKEY;
400 
401 typedef unsigned char DES_cblock[8];
402 typedef const DES_cblock const_DES_cblock;
403 typedef DES_cblock DES_key_schedule;
404 
405 enum {
406  DES_ENCRYPT = 1,
407  DES_DECRYPT = 0
408 };
409 
410 const EVP_MD* EVP_md5(void);
411 const EVP_CIPHER* EVP_des_ede3_cbc(void);
412 
413 typedef unsigned char opaque;
414 
415 int EVP_BytesToKey(const EVP_CIPHER*, const EVP_MD*, const opaque*,
416  const opaque*, int, int, opaque*, opaque*);
417 
418 void DES_set_key_unchecked(const_DES_cblock*, DES_key_schedule*);
419 void DES_ede3_cbc_encrypt(const opaque*, opaque*, long, DES_key_schedule*,
420  DES_key_schedule*, DES_key_schedule*, DES_cblock*, int);
421 
422 
423 /* RAND stuff */
424 void RAND_screen(void);
425 const char* RAND_file_name(char*, size_t);
426 int RAND_write_file(const char*);
427 int RAND_load_file(const char*, long);
428 
429 
430 /* for libcurl */
431 int RAND_status(void);
432 int RAND_bytes(unsigned char* buf, int num);
433 
434 int DES_set_key(const_DES_cblock*, DES_key_schedule*);
435 void DES_set_odd_parity(DES_cblock*);
436 void DES_ecb_encrypt(DES_cblock*, DES_cblock*, DES_key_schedule*, int);
437 
438 void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX*, void* userdata);
439 void SSL_SESSION_free(SSL_SESSION* session);
440 int SSL_peek(SSL* ssl, void* buf, int num);
441 
442 X509* SSL_get_certificate(SSL* ssl);
443 EVP_PKEY* SSL_get_privatekey(SSL* ssl);
444 EVP_PKEY* X509_get_pubkey(X509* x);
445 
446 int EVP_PKEY_copy_parameters(EVP_PKEY* to, const EVP_PKEY* from);
447 void EVP_PKEY_free(EVP_PKEY* pkey);
448 void ERR_error_string_n(unsigned long e, char *buf, size_t len);
449 void ERR_free_strings(void);
450 void EVP_cleanup(void);
451 
452 void* X509_get_ext_d2i(X509* x, int nid, int* crit, int* idx);
453 
454 #define GEN_IPADD 7
455 #define NID_subject_alt_name 85
456 #define STACK_OF(x) x
457 
458 
459 /* defined here because libcurl dereferences */
460 typedef struct ASN1_STRING {
461  int type;
462  int length;
463  unsigned char* data;
464 } ASN1_STRING;
465 
466 
467 typedef struct GENERAL_NAME {
468  int type;
469  union {
470  ASN1_STRING* ia5;
471  } d;
472 } GENERAL_NAME;
473 
474 void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *x);
475 
476 int sk_GENERAL_NAME_num(STACK_OF(GENERAL_NAME) *x);
477 GENERAL_NAME* sk_GENERAL_NAME_value(STACK_OF(GENERAL_NAME) *x, int i);
478 
479 
480 unsigned char* ASN1_STRING_data(ASN1_STRING* x);
481 int ASN1_STRING_length(ASN1_STRING* x);
482 int ASN1_STRING_type(ASN1_STRING *x);
483 
485 
486 int X509_NAME_get_index_by_NID(X509_NAME* name,int nid, int lastpos);
487 
488 ASN1_STRING* X509_NAME_ENTRY_get_data(X509_NAME_ENTRY* ne);
489 X509_NAME_ENTRY* X509_NAME_get_entry(X509_NAME* name, int loc);
490 
491 #define OPENSSL_malloc(x) malloc(x)
492 #define OPENSSL_free(x) free(x)
493 
494 int ASN1_STRING_to_UTF8(unsigned char** out, ASN1_STRING* in);
495 
496 SSL_METHOD* SSLv23_client_method(void); /* doesn't actually roll back */
497 SSL_METHOD* SSLv2_client_method(void); /* will never work, no v 2 */
498 
499 
500 SSL_SESSION* SSL_get1_session(SSL* ssl); /* what's ref count */
501 
502 
503 #define CRYPTO_free(x) free(x)
504 #define ASN1_TIME ASN1_STRING
505 
506 ASN1_TIME* X509_get_notBefore(X509* x);
507 ASN1_TIME* X509_get_notAfter(X509* x);
508 
509 
510 #define ASN1_UTCTIME ASN1_STRING
511 #define NID_commonName 13
512 #define V_ASN1_UTF8STRING 12
513 #define GEN_DNS 2
514 
515 #define CERTFICATE_ERROR 0x14090086 /* SSLv3 error */
516 
517 
518 typedef struct MD4_CTX {
519  int buffer[32]; /* big enough to hold, check size in Init */
520 } MD4_CTX;
521 
522 void MD4_Init(MD4_CTX*);
523 void MD4_Update(MD4_CTX*, const void*, unsigned long);
524 void MD4_Final(unsigned char*, MD4_CTX*);
525 
526 
527 typedef struct MD5_CTX {
528  int buffer[32]; /* big enough to hold, check size in Init */
529 } MD5_CTX;
530 
531 void MD5_Init(MD5_CTX*);
532 void MD5_Update(MD5_CTX*, const void*, unsigned long);
533 void MD5_Final(unsigned char*, MD5_CTX*);
534 
535 #define MD5_DIGEST_LENGTH 16
536 
537 
538 #define SSL_DEFAULT_CIPHER_LIST "" /* default all */
539 
540 
541 /* yaSSL extensions */
542 int SSL_set_compression(SSL*); /* turn on yaSSL zlib compression */
543 char *yaSSL_ASN1_TIME_to_string(ASN1_TIME *time, char *buf, size_t len);
544 
545 #include "transport_types.h"
546 
547 /*
548  Set functions for yaSSL to use in order to send and receive data.
549 
550  These hooks are offered in order to enable non-blocking I/O. If
551  not set, yaSSL defaults to using send() and recv().
552 
553  @todo Remove hooks and accompanying code when yaSSL is fixed.
554 */
555 void yaSSL_transport_set_ptr(SSL *, void *);
556 void yaSSL_transport_set_recv_function(SSL *, yaSSL_recv_func_t);
557 void yaSSL_transport_set_send_function(SSL *, yaSSL_send_func_t);
558 
559 #if defined(__cplusplus) && !defined(YASSL_MYSQL_COMPATIBLE)
560 } /* namespace */
561 } /* extern "C" */
562 #endif
563 
564 
565 #endif /* yaSSL_openssl_h__ */