123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- #include "e_os.h"
- #include "internal/err.h"
- #include <openssl/crypto.h>
- #include <openssl/evp.h>
- #include "ssl_local.h"
- #include "internal/thread_once.h"
- static int stopped;
- static void ssl_library_stop(void);
- static CRYPTO_ONCE ssl_base = CRYPTO_ONCE_STATIC_INIT;
- static int ssl_base_inited = 0;
- DEFINE_RUN_ONCE_STATIC(ossl_init_ssl_base)
- {
- #ifdef OPENSSL_INIT_DEBUG
- fprintf(stderr, "OPENSSL_INIT: ossl_init_ssl_base: "
- "Adding SSL ciphers and digests\n");
- #endif
- #ifndef OPENSSL_NO_DES
- EVP_add_cipher(EVP_des_cbc());
- EVP_add_cipher(EVP_des_ede3_cbc());
- #endif
- #ifndef OPENSSL_NO_IDEA
- EVP_add_cipher(EVP_idea_cbc());
- #endif
- #ifndef OPENSSL_NO_RC4
- EVP_add_cipher(EVP_rc4());
- # ifndef OPENSSL_NO_MD5
- EVP_add_cipher(EVP_rc4_hmac_md5());
- # endif
- #endif
- #ifndef OPENSSL_NO_RC2
- EVP_add_cipher(EVP_rc2_cbc());
-
- EVP_add_cipher(EVP_rc2_40_cbc());
- #endif
- EVP_add_cipher(EVP_aes_128_cbc());
- EVP_add_cipher(EVP_aes_192_cbc());
- EVP_add_cipher(EVP_aes_256_cbc());
- EVP_add_cipher(EVP_aes_128_gcm());
- EVP_add_cipher(EVP_aes_256_gcm());
- EVP_add_cipher(EVP_aes_128_ccm());
- EVP_add_cipher(EVP_aes_256_ccm());
- EVP_add_cipher(EVP_aes_128_cbc_hmac_sha1());
- EVP_add_cipher(EVP_aes_256_cbc_hmac_sha1());
- EVP_add_cipher(EVP_aes_128_cbc_hmac_sha256());
- EVP_add_cipher(EVP_aes_256_cbc_hmac_sha256());
- #ifndef OPENSSL_NO_ARIA
- EVP_add_cipher(EVP_aria_128_gcm());
- EVP_add_cipher(EVP_aria_256_gcm());
- #endif
- #ifndef OPENSSL_NO_CAMELLIA
- EVP_add_cipher(EVP_camellia_128_cbc());
- EVP_add_cipher(EVP_camellia_256_cbc());
- #endif
- #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
- EVP_add_cipher(EVP_chacha20_poly1305());
- #endif
- #ifndef OPENSSL_NO_SEED
- EVP_add_cipher(EVP_seed_cbc());
- #endif
- #ifndef OPENSSL_NO_MD5
- EVP_add_digest(EVP_md5());
- EVP_add_digest_alias(SN_md5, "ssl3-md5");
- EVP_add_digest(EVP_md5_sha1());
- #endif
- EVP_add_digest(EVP_sha1());
- EVP_add_digest_alias(SN_sha1, "ssl3-sha1");
- EVP_add_digest_alias(SN_sha1WithRSAEncryption, SN_sha1WithRSA);
- EVP_add_digest(EVP_sha224());
- EVP_add_digest(EVP_sha256());
- EVP_add_digest(EVP_sha384());
- EVP_add_digest(EVP_sha512());
- #ifndef OPENSSL_NO_COMP
- # ifdef OPENSSL_INIT_DEBUG
- fprintf(stderr, "OPENSSL_INIT: ossl_init_ssl_base: "
- "SSL_COMP_get_compression_methods()\n");
- # endif
-
- SSL_COMP_get_compression_methods();
- #endif
-
- if (!ssl_load_ciphers())
- return 0;
- #ifdef OPENSSL_INIT_DEBUG
- fprintf(stderr, "OPENSSL_INIT: ossl_init_ssl_base: "
- "SSL_add_ssl_module()\n");
- #endif
-
- OPENSSL_atexit(ssl_library_stop);
- ssl_base_inited = 1;
- return 1;
- }
- static CRYPTO_ONCE ssl_strings = CRYPTO_ONCE_STATIC_INIT;
- static int ssl_strings_inited = 0;
- DEFINE_RUN_ONCE_STATIC(ossl_init_load_ssl_strings)
- {
-
- #if !defined(OPENSSL_NO_ERR) && !defined(OPENSSL_NO_AUTOERRINIT)
- # ifdef OPENSSL_INIT_DEBUG
- fprintf(stderr, "OPENSSL_INIT: ossl_init_load_ssl_strings: "
- "ERR_load_SSL_strings()\n");
- # endif
- ERR_load_SSL_strings();
- ssl_strings_inited = 1;
- #endif
- return 1;
- }
- DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_load_ssl_strings,
- ossl_init_load_ssl_strings)
- {
-
- return 1;
- }
- static void ssl_library_stop(void)
- {
-
- if (stopped)
- return;
- stopped = 1;
- if (ssl_base_inited) {
- #ifndef OPENSSL_NO_COMP
- # ifdef OPENSSL_INIT_DEBUG
- fprintf(stderr, "OPENSSL_INIT: ssl_library_stop: "
- "ssl_comp_free_compression_methods_int()\n");
- # endif
- ssl_comp_free_compression_methods_int();
- #endif
- }
- if (ssl_strings_inited) {
- #ifdef OPENSSL_INIT_DEBUG
- fprintf(stderr, "OPENSSL_INIT: ssl_library_stop: "
- "err_free_strings_int()\n");
- #endif
-
- err_free_strings_int();
- }
- }
- int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS * settings)
- {
- static int stoperrset = 0;
- if (stopped) {
- if (!stoperrset) {
-
- stoperrset = 1;
- SSLerr(SSL_F_OPENSSL_INIT_SSL, ERR_R_INIT_FAIL);
- }
- return 0;
- }
- opts |= OPENSSL_INIT_ADD_ALL_CIPHERS
- | OPENSSL_INIT_ADD_ALL_DIGESTS;
- #ifndef OPENSSL_NO_AUTOLOAD_CONFIG
- if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG) == 0)
- opts |= OPENSSL_INIT_LOAD_CONFIG;
- #endif
- if (!OPENSSL_init_crypto(opts, settings))
- return 0;
- if (!RUN_ONCE(&ssl_base, ossl_init_ssl_base))
- return 0;
- if ((opts & OPENSSL_INIT_NO_LOAD_SSL_STRINGS)
- && !RUN_ONCE_ALT(&ssl_strings, ossl_init_no_load_ssl_strings,
- ossl_init_load_ssl_strings))
- return 0;
- if ((opts & OPENSSL_INIT_LOAD_SSL_STRINGS)
- && !RUN_ONCE(&ssl_strings, ossl_init_load_ssl_strings))
- return 0;
- return 1;
- }
|