Coverage Report

Created: 2026-03-21 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opensc/openpace/src/x509_lookup.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2010-2012 Frank Morgner and Dominik Oepen
3
 *
4
 * This file is part of OpenPACE.
5
 *
6
 * OpenPACE is free software: you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free
8
 * Software Foundation, either version 3 of the License, or (at your option)
9
 * any later version.
10
 *
11
 * OpenPACE is distributed in the hope that it will be useful, but WITHOUT ANY
12
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * OpenPACE.  If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * Additional permission under GNU GPL version 3 section 7
20
 *
21
 * If you modify this Program, or any covered work, by linking or combining it
22
 * with OpenSSL (or a modified version of that library), containing
23
 * parts covered by the terms of OpenSSL's license, the licensors of
24
 * this Program grant you additional permission to convey the resulting work.
25
 * Corresponding Source for a non-source form of such a combination shall include
26
 * the source code for the parts of OpenSSL used as well as that of the
27
 * covered work.
28
 *
29
 * If you modify this Program, or any covered work, by linking or combining it
30
 * with OpenSC (or a modified version of that library), containing
31
 * parts covered by the terms of OpenSC's license, the licensors of
32
 * this Program grant you additional permission to convey the resulting work. 
33
 * Corresponding Source for a non-source form of such a combination shall include
34
 * the source code for the parts of OpenSC used as well as that of the
35
 * covered work.
36
 */
37
38
/**
39
 * @file x509_lookup.c
40
 * @brief
41
 *
42
 * @author Frank Morgner <frankmorgner@gmail.com>
43
 */
44
45
#ifdef HAVE_CONFIG_H
46
#include "config.h"
47
#endif
48
49
#include "eac_err.h"
50
#include <eac/cv_cert.h>
51
#include <eac/eac.h>
52
#include <openssl/bio.h>
53
#include <openssl/x509.h>
54
55
#ifndef PATH_MAX
56
#define PATH_MAX 1024 /* # chars in a path name including nul */
57
#endif
58
59
/** @brief Directory for \c EAC_get_default_csca_lookup() */
60
static char x509_default_dir[PATH_MAX];
61
62
void EAC_set_x509_default_dir(const char *default_dir)
63
255
{
64
255
    if (default_dir) {
65
255
        strncpy(x509_default_dir, default_dir, (sizeof x509_default_dir) - 1);
66
255
        x509_default_dir[(sizeof x509_default_dir) - 1] = '\0';
67
255
    }
68
255
}
69
70
static X509_STORE *X509_default_lookup(unsigned long issuer_name_hash)
71
0
{
72
0
    static X509_STORE *store = NULL;
73
74
0
    if (!store)
75
0
       store = X509_STORE_new();
76
0
    check(store, "Failed to create trust store");
77
78
0
    if (!X509_STORE_load_locations(store, NULL, x509_default_dir)) {
79
0
            log_err("Failed to load trusted certificates");
80
0
            X509_STORE_free(store);
81
0
            store = NULL;
82
0
    }
83
84
0
err:
85
0
    return store;
86
0
}
87
88
X509_lookup_csca_cert EAC_get_default_csca_lookup(void)
89
0
{
90
0
    return X509_default_lookup;
91
0
}
92
93
int EAC_CTX_set_csca_lookup(EAC_CTX *ctx, X509_lookup_csca_cert lookup_csca_cert)
94
0
{
95
0
    int ok = 0;
96
97
0
    check (ctx && ctx->ca_ctx, "Invalid EAC context");
98
0
    ctx->ca_ctx->lookup_csca_cert = lookup_csca_cert;
99
0
    ok = 1;
100
101
0
err:
102
0
    return ok;
103
0
}
104
105
int EAC_CTX_get_csca_lookup(const EAC_CTX *ctx, X509_lookup_csca_cert *lookup_csca_cert)
106
0
{
107
0
    int ok = 0;
108
109
0
    check (lookup_csca_cert && ctx && ctx->ca_ctx, "Invalid parameters");
110
0
    *lookup_csca_cert = ctx->ca_ctx->lookup_csca_cert;
111
0
    ok = 1;
112
113
0
err:
114
0
    return ok;
115
0
}