blob: 668d8fba0e28252a6535c9f830a541fd26d7313c [file] [log] [blame]
Hanno Beckerf6bc8882019-05-02 13:05:58 +01001/**
2 * \file x509_internal.h
3 *
4 * \brief Internal X.509 functions
5 */
6/*
7 * Copyright (C) 2006-2019, ARM Limited, All Rights Reserved
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 * This file is part of Mbed TLS (https://tls.mbed.org)
23 *
24 */
25#ifndef MBEDTLS_X509_INTERNAL_H
26#define MBEDTLS_X509_INTERNAL_H
27
Andrzej Kurek220e6142020-05-19 07:13:26 -040028#if defined(MBEDTLS_X509_USE_C)
29
Hanno Beckerf6bc8882019-05-02 13:05:58 +010030#include "x509.h"
Hanno Becker00d39032019-05-13 12:39:44 +010031#include "threading.h"
32
33/* Internal structure used for caching parsed data from an X.509 CRT. */
34
35struct mbedtls_x509_crt;
36struct mbedtls_pk_context;
37struct mbedtls_x509_crt_frame;
Hanno Becker2ba9fbd2019-05-28 16:11:43 +010038#define MBEDTLS_X509_CACHE_PK_READERS_MAX ((uint32_t) -1)
39#define MBEDTLS_X509_CACHE_FRAME_READERS_MAX ((uint32_t) -1)
Hanno Beckerf6bc8882019-05-02 13:05:58 +010040
Hanno Beckera4dfc0d2019-05-13 13:45:11 +010041/* Internal X.509 CRT cache handling functions. */
Teppo Järvelinf69e6412019-09-03 16:50:17 +030042#if defined(MBEDTLS_X509_CRT_PARSE_C)
43static int mbedtls_x509_crt_flush_cache_frame( struct mbedtls_x509_crt const *crt );
44static int mbedtls_x509_crt_flush_cache_pk( struct mbedtls_x509_crt const *crt );
Hanno Beckera4dfc0d2019-05-13 13:45:11 +010045
Teppo Järvelinf69e6412019-09-03 16:50:17 +030046static int mbedtls_x509_crt_cache_provide_frame( struct mbedtls_x509_crt const *crt );
47static int mbedtls_x509_crt_cache_provide_pk( struct mbedtls_x509_crt const *crt );
48#endif /* MBEDTLS_X509_CRT_PARSE_C */
Hanno Beckera4dfc0d2019-05-13 13:45:11 +010049
50/* Uncategorized internal X.509 functions */
Teppo Järvelinf69e6412019-09-03 16:50:17 +030051static int mbedtls_x509_get_name( unsigned char *p, size_t len,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010052 mbedtls_x509_name *cur );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030053
54#if defined(MBEDTLS_X509_CRL_PARSE_C) || defined(MBEDTLS_X509_CSR_PARSE_C) || \
55 ( !defined(MBEDTLS_X509_ON_DEMAND_PARSING) && defined(MBEDTLS_X509_CRT_PARSE_C) )
56static int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010057 mbedtls_x509_buf *alg, mbedtls_x509_buf *params );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030058#endif /* defined(MBEDTLS_X509_CRL_PARSE_C) || defined(MBEDTLS_X509_CSR_PARSE_C) ||
59 ( !defined(MBEDTLS_X509_ON_DEMAND_PARSING) && defined(MBEDTLS_X509_CRT_PARSE_C) ) */
60
Hanno Beckerf6bc8882019-05-02 13:05:58 +010061#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
Teppo Järvelinf69e6412019-09-03 16:50:17 +030062static int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end,
63 mbedtls_x509_buf *alg );
64static int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010065 mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
66 int *salt_len );
67#endif
Teppo Järvelinf69e6412019-09-03 16:50:17 +030068static int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig );
69static int mbedtls_x509_get_sig_alg_raw( unsigned char **p, unsigned char const *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010070 mbedtls_md_type_t *md_alg,
71 mbedtls_pk_type_t *pk_alg,
72 void **sig_opts );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030073static int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010074 mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg,
75 void **sig_opts );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030076
77#if ( !defined(MBEDTLS_X509_CRT_REMOVE_TIME) && defined(MBEDTLS_X509_CRT_PARSE_C) ) || \
78 defined(MBEDTLS_X509_CRL_PARSE_C)
79static int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010080 mbedtls_x509_time *t );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030081#endif /* ( !defined(MBEDTLS_X509_CRT_REMOVE_TIME) && defined(MBEDTLS_X509_CRT_PARSE_C) ) ||
82 defined(MBEDTLS_X509_CRL_PARSE_C) */
83
84static int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010085 mbedtls_x509_buf *serial );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030086static int mbedtls_x509_name_cmp_raw( mbedtls_x509_buf_raw const *a,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010087 mbedtls_x509_buf_raw const *b,
88 int (*check)( void *ctx,
89 mbedtls_x509_buf *oid,
90 mbedtls_x509_buf *val,
91 int next_merged ),
92 void *check_ctx );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030093static int mbedtls_x509_memcasecmp( const void *s1, const void *s2,
Hanno Becker2656bfe2019-06-25 09:44:56 +010094 size_t len1, size_t len2 );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030095
96#if defined(MBEDTLS_X509_CRL_PARSE_C)
97static int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010098 mbedtls_x509_buf *ext, int tag );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030099#endif /* defined(MBEDTLS_X509_CRL_PARSE_C) */
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100100
101#if !defined(MBEDTLS_X509_REMOVE_INFO)
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300102static int mbedtls_x509_sig_alg_gets( char *buf, size_t size,
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100103 mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
104 const void *sig_opts );
105#endif
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300106#if !defined(MBEDTLS_X509_REMOVE_INFO)
107static int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name );
108#endif /* !defined(MBEDTLS_X509_REMOVE_INFO) */
109
110#if defined(MBEDTLS_X509_CREATE_C)
111static int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name );
112static int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100113 int critical, const unsigned char *val,
114 size_t val_len );
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300115static int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start,
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100116 mbedtls_asn1_named_data *first );
117int mbedtls_x509_write_names( unsigned char **p, unsigned char *start,
118 mbedtls_asn1_named_data *first );
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300119static int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100120 const char *oid, size_t oid_len,
121 unsigned char *sig, size_t size );
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300122#endif /* MBEDTLS_X509_CREATE_C */
Andrzej Kurek220e6142020-05-19 07:13:26 -0400123#endif /* MBEDTLS_X509_USE_C */
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100124#endif /* MBEDTLS_X509_INTERNAL_H */