Coverage Report

Created: 2025-08-28 07:07

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