xref: /freebsd-src/crypto/openssl/test/ssl_cert_table_internal_test.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert  * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert  *
4*e0c4386eSCy Schubert  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*e0c4386eSCy Schubert  * this file except in compliance with the License.  You can obtain a copy
6*e0c4386eSCy Schubert  * in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert  * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert  */
9*e0c4386eSCy Schubert 
10*e0c4386eSCy Schubert /* Internal tests for the x509 and x509v3 modules */
11*e0c4386eSCy Schubert 
12*e0c4386eSCy Schubert #include <stdio.h>
13*e0c4386eSCy Schubert #include <string.h>
14*e0c4386eSCy Schubert 
15*e0c4386eSCy Schubert #include <openssl/ssl.h>
16*e0c4386eSCy Schubert #include "testutil.h"
17*e0c4386eSCy Schubert #include "internal/nelem.h"
18*e0c4386eSCy Schubert #include "../ssl/ssl_local.h"
19*e0c4386eSCy Schubert #include "../ssl/ssl_cert_table.h"
20*e0c4386eSCy Schubert 
21*e0c4386eSCy Schubert #define test_cert_table(nid, amask, idx) \
22*e0c4386eSCy Schubert     do_test_cert_table(nid, amask, idx, #idx)
23*e0c4386eSCy Schubert 
do_test_cert_table(int nid,uint32_t amask,size_t idx,const char * idxname)24*e0c4386eSCy Schubert static int do_test_cert_table(int nid, uint32_t amask, size_t idx,
25*e0c4386eSCy Schubert                               const char *idxname)
26*e0c4386eSCy Schubert {
27*e0c4386eSCy Schubert     const SSL_CERT_LOOKUP *clu = &ssl_cert_info[idx];
28*e0c4386eSCy Schubert 
29*e0c4386eSCy Schubert     if (clu->nid == nid && clu->amask == amask)
30*e0c4386eSCy Schubert         return 1;
31*e0c4386eSCy Schubert 
32*e0c4386eSCy Schubert     TEST_error("Invalid table entry for certificate type %s, index %zu",
33*e0c4386eSCy Schubert                idxname, idx);
34*e0c4386eSCy Schubert     if (clu->nid != nid)
35*e0c4386eSCy Schubert         TEST_note("Expected %s, got %s\n", OBJ_nid2sn(nid),
36*e0c4386eSCy Schubert                   OBJ_nid2sn(clu->nid));
37*e0c4386eSCy Schubert     if (clu->amask != amask)
38*e0c4386eSCy Schubert         TEST_note("Expected auth mask 0x%x, got 0x%x\n", amask, clu->amask);
39*e0c4386eSCy Schubert     return 0;
40*e0c4386eSCy Schubert }
41*e0c4386eSCy Schubert 
42*e0c4386eSCy Schubert /* Sanity check of ssl_cert_table */
43*e0c4386eSCy Schubert 
test_ssl_cert_table(void)44*e0c4386eSCy Schubert static int test_ssl_cert_table(void)
45*e0c4386eSCy Schubert {
46*e0c4386eSCy Schubert     return TEST_size_t_eq(OSSL_NELEM(ssl_cert_info), SSL_PKEY_NUM)
47*e0c4386eSCy Schubert            && test_cert_table(EVP_PKEY_RSA, SSL_aRSA, SSL_PKEY_RSA)
48*e0c4386eSCy Schubert            && test_cert_table(EVP_PKEY_DSA, SSL_aDSS, SSL_PKEY_DSA_SIGN)
49*e0c4386eSCy Schubert            && test_cert_table(EVP_PKEY_EC, SSL_aECDSA, SSL_PKEY_ECC)
50*e0c4386eSCy Schubert            && test_cert_table(NID_id_GostR3410_2001, SSL_aGOST01,
51*e0c4386eSCy Schubert                               SSL_PKEY_GOST01)
52*e0c4386eSCy Schubert            && test_cert_table(NID_id_GostR3410_2012_256, SSL_aGOST12,
53*e0c4386eSCy Schubert                               SSL_PKEY_GOST12_256)
54*e0c4386eSCy Schubert            && test_cert_table(NID_id_GostR3410_2012_512, SSL_aGOST12,
55*e0c4386eSCy Schubert                               SSL_PKEY_GOST12_512)
56*e0c4386eSCy Schubert            && test_cert_table(EVP_PKEY_ED25519, SSL_aECDSA, SSL_PKEY_ED25519)
57*e0c4386eSCy Schubert            && test_cert_table(EVP_PKEY_ED448, SSL_aECDSA, SSL_PKEY_ED448);
58*e0c4386eSCy Schubert }
59*e0c4386eSCy Schubert 
setup_tests(void)60*e0c4386eSCy Schubert int setup_tests(void)
61*e0c4386eSCy Schubert {
62*e0c4386eSCy Schubert     ADD_TEST(test_ssl_cert_table);
63*e0c4386eSCy Schubert     return 1;
64*e0c4386eSCy Schubert }
65