00001 /* ssl.h 00002 * 00003 * Copyright (C) 2003 Sawtooth Consulting Ltd. 00004 * 00005 * This file is part of yaSSL. 00006 * 00007 * yaSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * There are special exceptions to the terms and conditions of the GPL as it 00013 * is applied to yaSSL. View the full text of the exception in the file 00014 * FLOSS-EXCEPTIONS in the directory of this software distribution. 00015 * 00016 * yaSSL is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00024 */ 00025 00026 /* ssl.h defines openssl compatibility layer 00027 * 00028 */ 00029 00030 00031 00032 #ifndef yaSSL_openssl_h__ 00033 #define yaSSL_openssl_h__ 00034 00035 #ifdef YASSL_PREFIX 00036 #include "prefix_ssl.h" 00037 #endif 00038 00039 #include <stdio.h> /* ERR_print fp */ 00040 #include "opensslv.h" /* for version number */ 00041 #include "rsa.h" 00042 00043 00044 #define YASSL_VERSION "1.3.7" 00045 00046 00047 #if defined(__cplusplus) 00048 extern "C" { 00049 #endif 00050 00051 void yaSSL_CleanUp(); /* call once at end of application use to 00052 free static singleton memory holders, 00053 not a leak per se, but helpful when 00054 looking for them */ 00055 00056 #if defined(__cplusplus) 00057 } // extern 00058 #endif 00059 00060 #if defined(__cplusplus) && !defined(YASSL_MYSQL_COMPATIBLE) 00061 namespace yaSSL { 00062 extern "C" { 00063 #endif 00064 00065 #undef X509_NAME /* wincrypt.h clash */ 00066 00067 #if defined(__cplusplus) && !defined(YASSL_MYSQL_COMPATIBLE) 00068 class SSL; 00069 class SSL_SESSION; 00070 class SSL_METHOD; 00071 class SSL_CTX; 00072 class SSL_CIPHER; 00073 00074 class RSA; 00075 00076 class X509; 00077 class X509_NAME; 00078 #else 00079 typedef struct SSL SSL; 00080 typedef struct SSL_SESSION SSL_SESSION; 00081 typedef struct SSL_METHOD SSL_METHOD; 00082 typedef struct SSL_CTX SSL_CTX; 00083 typedef struct SSL_CIPHER SSL_CIPHER; 00084 00085 typedef struct RSA RSA; 00086 00087 typedef struct X509 X509; 00088 typedef struct X509_NAME X509_NAME; 00089 #endif 00090 00091 00092 /* Big Number stuff, different file? */ 00093 typedef struct BIGNUM BIGNUM; 00094 00095 BIGNUM *BN_bin2bn(const unsigned char*, int, BIGNUM*); 00096 00097 00098 /* Diffie-Hellman stuff, different file? */ 00099 /* mySQL deferences to set group parameters */ 00100 typedef struct DH { 00101 BIGNUM* p; 00102 BIGNUM* g; 00103 } DH; 00104 00105 DH* DH_new(void); 00106 void DH_free(DH*); 00107 00108 /* RSA stuff */ 00109 00110 void RSA_free(RSA*); 00111 RSA* RSA_generate_key(int, unsigned long, void(*)(int, int, void*), void*); 00112 00113 00114 /* X509 stuff, different file? */ 00115 00116 typedef struct X509_STORE X509_STORE; 00117 typedef struct X509_LOOKUP X509_LOOKUP; 00118 typedef struct X509_OBJECT { char c; } X509_OBJECT; 00119 typedef struct X509_CRL X509_CRL; 00120 typedef struct X509_REVOKED X509_REVOKED; 00121 typedef struct X509_LOOKUP_METHOD X509_LOOKUP_METHOD; 00122 00123 00124 void X509_free(X509*); 00125 00126 00127 /* bio stuff */ 00128 typedef struct BIO BIO; 00129 00130 /* ASN stuff */ 00131 00132 00133 00134 /* because mySQL dereferences to use error and current_cert, even after calling 00135 * get functions for local references */ 00136 typedef struct X509_STORE_CTX { 00137 int error; 00138 int error_depth; 00139 X509* current_cert; 00140 } X509_STORE_CTX; 00141 00142 00143 00144 X509* X509_STORE_CTX_get_current_cert(X509_STORE_CTX*); 00145 int X509_STORE_CTX_get_error(X509_STORE_CTX*); 00146 int X509_STORE_CTX_get_error_depth(X509_STORE_CTX*); 00147 00148 char* X509_NAME_oneline(X509_NAME*, char*, int); 00149 X509_NAME* X509_get_issuer_name(X509*); 00150 X509_NAME* X509_get_subject_name(X509*); 00151 const char* X509_verify_cert_error_string(long); 00152 00153 int X509_LOOKUP_add_dir(X509_LOOKUP*, const char*, long); 00154 int X509_LOOKUP_load_file(X509_LOOKUP*, const char*, long); 00155 X509_LOOKUP_METHOD* X509_LOOKUP_hash_dir(void); 00156 X509_LOOKUP_METHOD* X509_LOOKUP_file(void); 00157 00158 X509_LOOKUP* X509_STORE_add_lookup(X509_STORE*, X509_LOOKUP_METHOD*); 00159 X509_STORE* X509_STORE_new(void); 00160 int X509_STORE_get_by_subject(X509_STORE_CTX*, int, X509_NAME*, 00161 X509_OBJECT*); 00162 00163 00164 00165 00166 enum { /* X509 Constants */ 00167 X509_V_OK = 0, 00168 X509_V_ERR_CERT_CHAIN_TOO_LONG = 1, 00169 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2, 00170 X509_V_ERR_CERT_NOT_YET_VALID = 3, 00171 X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD = 4, 00172 X509_V_ERR_CERT_HAS_EXPIRED = 5, 00173 X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD = 6, 00174 X509_FILETYPE_PEM = 7, 00175 X509_LU_X509 = 8, 00176 X509_LU_CRL = 9, 00177 X509_V_ERR_CRL_SIGNATURE_FAILURE = 10, 00178 X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 11, 00179 X509_V_ERR_CRL_HAS_EXPIRED = 12, 00180 X509_V_ERR_CERT_REVOKED = 13 00181 00182 }; 00183 00184 00185 /* Error stuff, could move to yassl_error */ 00186 unsigned long ERR_get_error_line_data(const char**, int*, const char**, int *); 00187 void ERR_print_errors_fp(FILE*); 00188 char* ERR_error_string(unsigned long,char*); 00189 void ERR_remove_state(unsigned long); 00190 unsigned long ERR_get_error(void); 00191 unsigned long ERR_peek_error(void); 00192 int ERR_GET_REASON(int); 00193 00194 00195 enum { /* ERR Constants */ 00196 ERR_TXT_STRING = 1, 00197 EVP_R_BAD_DECRYPT = 2 00198 }; 00199 00200 00201 00202 SSL_CTX* SSL_CTX_new(SSL_METHOD*); 00203 SSL* SSL_new(SSL_CTX*); 00204 int SSL_set_fd (SSL*, int); 00205 int SSL_connect(SSL*); 00206 int SSL_write(SSL*, const void*, int); 00207 int SSL_read(SSL*, void*, int); 00208 int SSL_accept(SSL*); 00209 void SSL_CTX_free(SSL_CTX*); 00210 void SSL_free(SSL*); 00211 int SSL_clear(SSL*); 00212 int SSL_shutdown(SSL*); 00213 00214 void SSL_set_connect_state(SSL*); 00215 void SSL_set_accept_state(SSL*); 00216 int SSL_do_handshake(SSL*); 00217 00218 const char* SSL_get_cipher(SSL*); 00219 const char* SSL_get_cipher_name(SSL*); /* uses SSL_get_cipher */ 00220 char* SSL_get_shared_ciphers(SSL*, char*, int); 00221 const char* SSL_get_cipher_list(SSL*, int); 00222 const char* SSL_get_version(SSL*); 00223 const char* SSLeay_version(int); 00224 00225 int SSL_get_error(SSL*, int); 00226 void SSL_load_error_strings(void); 00227 00228 int SSL_set_session(SSL *ssl, SSL_SESSION *session); 00229 SSL_SESSION* SSL_get_session(SSL* ssl); 00230 long SSL_SESSION_set_timeout(SSL_SESSION*, long); 00231 X509* SSL_get_peer_certificate(SSL*); 00232 long SSL_get_verify_result(SSL*); 00233 00234 00235 typedef int (*VerifyCallback)(int, X509_STORE_CTX*); 00236 typedef int (*pem_password_cb)(char*, int, int, void*); 00237 00238 void SSL_CTX_set_verify(SSL_CTX*, int, VerifyCallback verify_callback); 00239 int SSL_CTX_load_verify_locations(SSL_CTX*, const char*, const char*); 00240 int SSL_CTX_set_default_verify_paths(SSL_CTX*); 00241 int SSL_CTX_check_private_key(SSL_CTX*); 00242 int SSL_CTX_set_session_id_context(SSL_CTX*, const unsigned char*, 00243 unsigned int); 00244 00245 void SSL_CTX_set_tmp_rsa_callback(SSL_CTX*, RSA*(*)(SSL*, int, int)); 00246 long SSL_CTX_set_options(SSL_CTX*, long); 00247 long SSL_CTX_set_session_cache_mode(SSL_CTX*, long); 00248 long SSL_CTX_set_timeout(SSL_CTX*, long); 00249 int SSL_CTX_use_certificate_chain_file(SSL_CTX*, const char*); 00250 void SSL_CTX_set_default_passwd_cb(SSL_CTX*, pem_password_cb); 00251 int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX*, const char*, int); 00252 void SSL_CTX_set_info_callback(SSL_CTX*, void (*)()); 00253 00254 long SSL_CTX_sess_accept(SSL_CTX*); 00255 long SSL_CTX_sess_connect(SSL_CTX*); 00256 long SSL_CTX_sess_accept_good(SSL_CTX*); 00257 long SSL_CTX_sess_connect_good(SSL_CTX*); 00258 long SSL_CTX_sess_accept_renegotiate(SSL_CTX*); 00259 long SSL_CTX_sess_connect_renegotiate(SSL_CTX*); 00260 long SSL_CTX_sess_hits(SSL_CTX*); 00261 long SSL_CTX_sess_cb_hits(SSL_CTX*); 00262 long SSL_CTX_sess_cache_full(SSL_CTX*); 00263 long SSL_CTX_sess_misses(SSL_CTX*); 00264 long SSL_CTX_sess_timeouts(SSL_CTX*); 00265 long SSL_CTX_sess_number(SSL_CTX*); 00266 long SSL_CTX_sess_get_cache_size(SSL_CTX*); 00267 00268 int SSL_CTX_get_verify_mode(SSL_CTX*); 00269 int SSL_get_verify_mode(SSL*); 00270 int SSL_CTX_get_verify_depth(SSL_CTX*); 00271 int SSL_get_verify_depth(SSL*); 00272 00273 long SSL_get_default_timeout(SSL*); 00274 long SSL_CTX_get_session_cache_mode(SSL_CTX*); 00275 int SSL_session_reused(SSL*); 00276 00277 int SSL_set_rfd(SSL*, int); 00278 int SSL_set_wfd(SSL*, int); 00279 void SSL_set_shutdown(SSL*, int); 00280 00281 int SSL_want_read(SSL*); 00282 int SSL_want_write(SSL*); 00283 00284 int SSL_pending(SSL*); 00285 00286 00287 enum { /* ssl Constants */ 00288 SSL_WOULD_BLOCK = -8, 00289 SSL_BAD_STAT = -7, 00290 SSL_BAD_PATH = -6, 00291 SSL_BAD_FILETYPE = -5, 00292 SSL_BAD_FILE = -4, 00293 SSL_NOT_IMPLEMENTED = -3, 00294 SSL_UNKNOWN = -2, 00295 SSL_FATAL_ERROR = -1, 00296 SSL_NORMAL_SHUTDOWN = 0, 00297 SSL_ERROR_NONE = 0, /* for most functions */ 00298 SSL_FAILURE = 0, /* for some functions */ 00299 SSL_SUCCESS = 1, 00300 00301 SSL_FILETYPE_ASN1 = 10, 00302 SSL_FILETYPE_PEM = 11, 00303 SSL_FILETYPE_DEFAULT = 10, /* ASN1 */ 00304 00305 SSL_VERIFY_NONE = 0, 00306 SSL_VERIFY_PEER = 1, 00307 SSL_VERIFY_FAIL_IF_NO_PEER_CERT = 2, 00308 SSL_VERIFY_CLIENT_ONCE = 4, 00309 00310 SSL_SESS_CACHE_OFF = 30, 00311 SSL_SESS_CACHE_CLIENT = 31, 00312 SSL_SESS_CACHE_SERVER = 32, 00313 SSL_SESS_CACHE_BOTH = 33, 00314 SSL_SESS_CACHE_NO_AUTO_CLEAR = 34, 00315 SSL_SESS_CACHE_NO_INTERNAL_LOOKUP = 35, 00316 00317 SSL_OP_MICROSOFT_SESS_ID_BUG = 50, 00318 SSL_OP_NETSCAPE_CHALLENGE_BUG = 51, 00319 SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG = 52, 00320 SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG = 53, 00321 SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER = 54, 00322 SSL_OP_MSIE_SSLV2_RSA_PADDING = 55, 00323 SSL_OP_SSLEAY_080_CLIENT_DH_BUG = 56, 00324 SSL_OP_TLS_D5_BUG = 57, 00325 SSL_OP_TLS_BLOCK_PADDING_BUG = 58, 00326 SSL_OP_TLS_ROLLBACK_BUG = 59, 00327 SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS = 60, 00328 SSL_OP_ALL = 61, 00329 SSL_OP_SINGLE_DH_USE = 62, 00330 SSL_OP_EPHEMERAL_RSA = 63, 00331 SSL_OP_NO_SSLv2 = 64, 00332 SSL_OP_NO_SSLv3 = 65, 00333 SSL_OP_NO_TLSv1 = 66, 00334 SSL_OP_PKCS1_CHECK_1 = 67, 00335 SSL_OP_PKCS1_CHECK_2 = 68, 00336 SSL_OP_NETSCAPE_CA_DN_BUG = 69, 00337 SSL_OP_NON_EXPORT_FIRST = 70, 00338 SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG = 71, 00339 00340 SSL_ERROR_WANT_READ = 80, 00341 SSL_ERROR_WANT_WRITE = 81, 00342 SSL_ERROR_SYSCALL = 82, 00343 SSL_ERROR_WANT_X509_LOOKUP = 83, 00344 SSL_ERROR_ZERO_RETURN = 84, 00345 SSL_ERROR_SSL = 85, 00346 00347 SSL_SENT_SHUTDOWN = 90, 00348 SSL_RECEIVED_SHUTDOWN = 91, 00349 SSL_CB_LOOP = 92, 00350 SSL_ST_CONNECT = 93, 00351 SSL_ST_ACCEPT = 94, 00352 SSL_CB_ALERT = 95, 00353 SSL_CB_READ = 96, 00354 SSL_CB_HANDSHAKE_DONE = 97 00355 00356 }; 00357 00358 00359 SSL_METHOD *SSLv3_method(void); 00360 SSL_METHOD *SSLv3_server_method(void); 00361 SSL_METHOD *SSLv3_client_method(void); 00362 SSL_METHOD *TLSv1_server_method(void); 00363 SSL_METHOD *TLSv1_client_method(void); 00364 SSL_METHOD *SSLv23_server_method(void); 00365 00366 int SSL_CTX_use_certificate_file(SSL_CTX*, const char*, int); 00367 int SSL_CTX_use_PrivateKey_file(SSL_CTX*, const char*, int); 00368 int SSL_CTX_set_cipher_list(SSL_CTX*, const char*); 00369 00370 long SSL_CTX_sess_set_cache_size(SSL_CTX*, long); 00371 long SSL_CTX_set_tmp_dh(SSL_CTX*, DH*); 00372 00373 void OpenSSL_add_all_algorithms(void); 00374 int SSL_library_init(); 00375 int SSLeay_add_ssl_algorithms(void); 00376 00377 00378 SSL_CIPHER* SSL_get_current_cipher(SSL*); 00379 char* SSL_CIPHER_description(SSL_CIPHER*, char*, int); 00380 00381 00382 char* SSL_alert_type_string_long(int); 00383 char* SSL_alert_desc_string_long(int); 00384 char* SSL_state_string_long(SSL*); 00385 00386 00387 /* EVP stuff, des and md5, different file? */ 00388 typedef char EVP_MD; 00389 00390 typedef char EVP_CIPHER; 00391 00392 typedef struct EVP_PKEY EVP_PKEY; 00393 00394 typedef unsigned char DES_cblock[8]; 00395 typedef const DES_cblock const_DES_cblock; 00396 typedef DES_cblock DES_key_schedule; 00397 00398 enum { 00399 DES_ENCRYPT = 1, 00400 DES_DECRYPT = 0 00401 }; 00402 00403 const EVP_MD* EVP_md5(void); 00404 const EVP_CIPHER* EVP_des_ede3_cbc(void); 00405 00406 typedef unsigned char opaque; 00407 00408 int EVP_BytesToKey(const EVP_CIPHER*, const EVP_MD*, const opaque*, 00409 const opaque*, int, int, opaque*, opaque*); 00410 00411 void DES_set_key_unchecked(const_DES_cblock*, DES_key_schedule*); 00412 void DES_ede3_cbc_encrypt(const opaque*, opaque*, long, DES_key_schedule*, 00413 DES_key_schedule*, DES_key_schedule*, DES_cblock*, int); 00414 00415 00416 /* RAND stuff */ 00417 void RAND_screen(void); 00418 const char* RAND_file_name(char*, size_t); 00419 int RAND_write_file(const char*); 00420 int RAND_load_file(const char*, long); 00421 00422 00423 /* for libcurl */ 00424 int RAND_status(void); 00425 int RAND_bytes(unsigned char* buf, int num); 00426 00427 int DES_set_key(const_DES_cblock*, DES_key_schedule*); 00428 void DES_set_odd_parity(DES_cblock*); 00429 void DES_ecb_encrypt(DES_cblock*, DES_cblock*, DES_key_schedule*, int); 00430 00431 void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX*, void* userdata); 00432 void SSL_SESSION_free(SSL_SESSION* session); 00433 int SSL_peek(SSL* ssl, void* buf, int num); 00434 00435 X509* SSL_get_certificate(SSL* ssl); 00436 EVP_PKEY* SSL_get_privatekey(SSL* ssl); 00437 EVP_PKEY* X509_get_pubkey(X509* x); 00438 00439 int EVP_PKEY_copy_parameters(EVP_PKEY* to, const EVP_PKEY* from); 00440 void EVP_PKEY_free(EVP_PKEY* pkey); 00441 void ERR_error_string_n(unsigned long e, char *buf, size_t len); 00442 void ERR_free_strings(void); 00443 void EVP_cleanup(void); 00444 00445 void* X509_get_ext_d2i(X509* x, int nid, int* crit, int* idx); 00446 00447 #define GEN_IPADD 7 00448 #define NID_subject_alt_name 85 00449 #define STACK_OF(x) x 00450 00451 00452 /* defined here because libcurl dereferences */ 00453 typedef struct ASN1_STRING { 00454 int type; 00455 int length; 00456 unsigned char* data; 00457 } ASN1_STRING; 00458 00459 00460 typedef struct GENERAL_NAME { 00461 int type; 00462 union { 00463 ASN1_STRING* ia5; 00464 } d; 00465 } GENERAL_NAME; 00466 00467 void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *x); 00468 00469 int sk_GENERAL_NAME_num(STACK_OF(GENERAL_NAME) *x); 00470 GENERAL_NAME* sk_GENERAL_NAME_value(STACK_OF(GENERAL_NAME) *x, int i); 00471 00472 00473 unsigned char* ASN1_STRING_data(ASN1_STRING* x); 00474 int ASN1_STRING_length(ASN1_STRING* x); 00475 int ASN1_STRING_type(ASN1_STRING *x); 00476 00477 typedef ASN1_STRING X509_NAME_ENTRY; 00478 00479 int X509_NAME_get_index_by_NID(X509_NAME* name,int nid, int lastpos); 00480 00481 ASN1_STRING* X509_NAME_ENTRY_get_data(X509_NAME_ENTRY* ne); 00482 X509_NAME_ENTRY* X509_NAME_get_entry(X509_NAME* name, int loc); 00483 00484 #define OPENSSL_malloc(x) malloc(x) 00485 #define OPENSSL_free(x) free(x) 00486 00487 int ASN1_STRING_to_UTF8(unsigned char** out, ASN1_STRING* in); 00488 00489 SSL_METHOD* SSLv23_client_method(void); /* doesn't actually roll back */ 00490 SSL_METHOD* SSLv2_client_method(void); /* will never work, no v 2 */ 00491 00492 00493 SSL_SESSION* SSL_get1_session(SSL* ssl); /* what's ref count */ 00494 00495 00496 #define CRYPTO_free(x) free(x) 00497 #define ASN1_TIME ASN1_STRING 00498 00499 ASN1_TIME* X509_get_notBefore(X509* x); 00500 ASN1_TIME* X509_get_notAfter(X509* x); 00501 00502 00503 #define ASN1_UTCTIME ASN1_STRING 00504 #define NID_commonName 13 00505 #define V_ASN1_UTF8STRING 12 00506 #define GEN_DNS 2 00507 00508 00509 typedef struct MD4_CTX { 00510 int buffer[32]; /* big enough to hold, check size in Init */ 00511 } MD4_CTX; 00512 00513 void MD4_Init(MD4_CTX*); 00514 void MD4_Update(MD4_CTX*, const void*, unsigned long); 00515 void MD4_Final(unsigned char*, MD4_CTX*); 00516 00517 00518 typedef struct MD5_CTX { 00519 int buffer[32]; /* big enough to hold, check size in Init */ 00520 } MD5_CTX; 00521 00522 void MD5_Init(MD5_CTX*); 00523 void MD5_Update(MD5_CTX*, const void*, unsigned long); 00524 void MD5_Final(unsigned char*, MD5_CTX*); 00525 00526 #define MD5_DIGEST_LENGTH 16 00527 00528 00529 #define SSL_DEFAULT_CIPHER_LIST "" /* default all */ 00530 00531 00532 00533 00534 #if defined(__cplusplus) && !defined(YASSL_MYSQL_COMPATIBLE) 00535 } /* namespace */ 00536 } /* extern "C" */ 00537 #endif 00538 00539 00540 #endif /* yaSSL_openssl_h__ */
1.4.7

