Home | History | Annotate | Line # | Download | only in ssl
      1      1.1  christos /*
      2      1.1  christos  * Copyright 2016-2025 The OpenSSL Project Authors. All Rights Reserved.
      3      1.1  christos  *
      4      1.1  christos  * Licensed under the Apache License 2.0 (the "License").  You may not use
      5      1.1  christos  * this file except in compliance with the License.  You can obtain a copy
      6      1.1  christos  * in the file LICENSE in the source distribution or at
      7      1.1  christos  * https://www.openssl.org/source/license.html
      8      1.1  christos  */
      9      1.1  christos 
     10      1.1  christos #include "internal/e_os.h"
     11      1.1  christos 
     12      1.1  christos #include "internal/err.h"
     13      1.1  christos #include <openssl/crypto.h>
     14      1.1  christos #include <openssl/evp.h>
     15      1.1  christos #include <openssl/trace.h>
     16      1.1  christos #include "ssl_local.h"
     17      1.1  christos #include "internal/thread_once.h"
     18  1.1.1.2  christos #include "internal/rio_notifier.h" /* for ossl_wsa_cleanup() */
     19      1.1  christos 
     20      1.1  christos static int stopped;
     21      1.1  christos 
     22      1.1  christos static CRYPTO_ONCE ssl_base = CRYPTO_ONCE_STATIC_INIT;
     23      1.1  christos static int ssl_base_inited = 0;
     24      1.1  christos DEFINE_RUN_ONCE_STATIC(ossl_init_ssl_base)
     25      1.1  christos {
     26      1.1  christos #ifndef OPENSSL_NO_COMP
     27      1.1  christos     OSSL_TRACE(INIT, "ossl_init_ssl_base: "
     28  1.1.1.2  christos                      "SSL_COMP_get_compression_methods()\n");
     29      1.1  christos     /*
     30      1.1  christos      * This will initialise the built-in compression algorithms. The value
     31      1.1  christos      * returned is a STACK_OF(SSL_COMP), but that can be discarded safely
     32      1.1  christos      */
     33      1.1  christos     SSL_COMP_get_compression_methods();
     34      1.1  christos #endif
     35      1.1  christos     ssl_sort_cipher_list();
     36      1.1  christos     OSSL_TRACE(INIT, "ossl_init_ssl_base: SSL_add_ssl_module()\n");
     37      1.1  christos     ssl_base_inited = 1;
     38      1.1  christos     return 1;
     39      1.1  christos }
     40      1.1  christos 
     41      1.1  christos /*
     42      1.1  christos  * If this function is called with a non NULL settings value then it must be
     43      1.1  christos  * called prior to any threads making calls to any OpenSSL functions,
     44      1.1  christos  * i.e. passing a non-null settings value is assumed to be single-threaded.
     45      1.1  christos  */
     46      1.1  christos int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
     47      1.1  christos {
     48      1.1  christos     static int stoperrset = 0;
     49      1.1  christos 
     50      1.1  christos     if (stopped) {
     51      1.1  christos         if (!stoperrset) {
     52      1.1  christos             /*
     53      1.1  christos              * We only ever set this once to avoid getting into an infinite
     54      1.1  christos              * loop where the error system keeps trying to init and fails so
     55      1.1  christos              * sets an error etc
     56      1.1  christos              */
     57      1.1  christos             stoperrset = 1;
     58      1.1  christos             ERR_raise(ERR_LIB_SSL, ERR_R_INIT_FAIL);
     59      1.1  christos         }
     60      1.1  christos         return 0;
     61      1.1  christos     }
     62      1.1  christos 
     63      1.1  christos     opts |= OPENSSL_INIT_ADD_ALL_CIPHERS
     64  1.1.1.2  christos         | OPENSSL_INIT_ADD_ALL_DIGESTS;
     65      1.1  christos #ifndef OPENSSL_NO_AUTOLOAD_CONFIG
     66      1.1  christos     if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG) == 0)
     67      1.1  christos         opts |= OPENSSL_INIT_LOAD_CONFIG;
     68      1.1  christos #endif
     69      1.1  christos 
     70      1.1  christos     if (!OPENSSL_init_crypto(opts, settings))
     71      1.1  christos         return 0;
     72      1.1  christos 
     73      1.1  christos     if (!RUN_ONCE(&ssl_base, ossl_init_ssl_base))
     74      1.1  christos         return 0;
     75      1.1  christos 
     76      1.1  christos     return 1;
     77      1.1  christos }
     78