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