blob: c69c5421c726c236be955f297fe440ce6a222191 [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
28#include "x509.h"
Hanno Becker00d39032019-05-13 12:39:44 +010029#include "threading.h"
30
31/* Internal structure used for caching parsed data from an X.509 CRT. */
32
33struct mbedtls_x509_crt;
34struct mbedtls_pk_context;
35struct mbedtls_x509_crt_frame;
Hanno Becker2ba9fbd2019-05-28 16:11:43 +010036#define MBEDTLS_X509_CACHE_PK_READERS_MAX ((uint32_t) -1)
37#define MBEDTLS_X509_CACHE_FRAME_READERS_MAX ((uint32_t) -1)
Hanno Beckerf6bc8882019-05-02 13:05:58 +010038
Hanno Beckera4dfc0d2019-05-13 13:45:11 +010039/* Internal X.509 CRT cache handling functions. */
Teppo Järvelinf69e6412019-09-03 16:50:17 +030040#if defined(MBEDTLS_X509_CRT_PARSE_C)
41static int mbedtls_x509_crt_flush_cache_frame( struct mbedtls_x509_crt const *crt );
42static int mbedtls_x509_crt_flush_cache_pk( struct mbedtls_x509_crt const *crt );
Hanno Beckera4dfc0d2019-05-13 13:45:11 +010043
Teppo Järvelinf69e6412019-09-03 16:50:17 +030044static int mbedtls_x509_crt_cache_provide_frame( struct mbedtls_x509_crt const *crt );
45static int mbedtls_x509_crt_cache_provide_pk( struct mbedtls_x509_crt const *crt );
46#endif /* MBEDTLS_X509_CRT_PARSE_C */
Hanno Beckera4dfc0d2019-05-13 13:45:11 +010047
48/* Uncategorized internal X.509 functions */
Teppo Järvelinf69e6412019-09-03 16:50:17 +030049static int mbedtls_x509_get_name( unsigned char *p, size_t len,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010050 mbedtls_x509_name *cur );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030051
52#if defined(MBEDTLS_X509_CRL_PARSE_C) || defined(MBEDTLS_X509_CSR_PARSE_C) || \
53 ( !defined(MBEDTLS_X509_ON_DEMAND_PARSING) && defined(MBEDTLS_X509_CRT_PARSE_C) )
54static int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010055 mbedtls_x509_buf *alg, mbedtls_x509_buf *params );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030056#endif /* defined(MBEDTLS_X509_CRL_PARSE_C) || defined(MBEDTLS_X509_CSR_PARSE_C) ||
57 ( !defined(MBEDTLS_X509_ON_DEMAND_PARSING) && defined(MBEDTLS_X509_CRT_PARSE_C) ) */
58
Hanno Beckerf6bc8882019-05-02 13:05:58 +010059#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
Teppo Järvelinf69e6412019-09-03 16:50:17 +030060static int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end,
61 mbedtls_x509_buf *alg );
62static int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010063 mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
64 int *salt_len );
65#endif
Teppo Järvelinf69e6412019-09-03 16:50:17 +030066static int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig );
67static int mbedtls_x509_get_sig_alg_raw( unsigned char **p, unsigned char const *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010068 mbedtls_md_type_t *md_alg,
69 mbedtls_pk_type_t *pk_alg,
70 void **sig_opts );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030071static 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 +010072 mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg,
73 void **sig_opts );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030074
75#if ( !defined(MBEDTLS_X509_CRT_REMOVE_TIME) && defined(MBEDTLS_X509_CRT_PARSE_C) ) || \
76 defined(MBEDTLS_X509_CRL_PARSE_C)
77static int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010078 mbedtls_x509_time *t );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030079#endif /* ( !defined(MBEDTLS_X509_CRT_REMOVE_TIME) && defined(MBEDTLS_X509_CRT_PARSE_C) ) ||
80 defined(MBEDTLS_X509_CRL_PARSE_C) */
81
82static int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010083 mbedtls_x509_buf *serial );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030084static int mbedtls_x509_name_cmp_raw( mbedtls_x509_buf_raw const *a,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010085 mbedtls_x509_buf_raw const *b,
86 int (*check)( void *ctx,
87 mbedtls_x509_buf *oid,
88 mbedtls_x509_buf *val,
89 int next_merged ),
90 void *check_ctx );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030091static int mbedtls_x509_memcasecmp( const void *s1, const void *s2,
Hanno Becker2656bfe2019-06-25 09:44:56 +010092 size_t len1, size_t len2 );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030093
94#if defined(MBEDTLS_X509_CRL_PARSE_C)
95static int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
Hanno Beckerf6bc8882019-05-02 13:05:58 +010096 mbedtls_x509_buf *ext, int tag );
Teppo Järvelinf69e6412019-09-03 16:50:17 +030097#endif /* defined(MBEDTLS_X509_CRL_PARSE_C) */
Hanno Beckerf6bc8882019-05-02 13:05:58 +010098
99#if !defined(MBEDTLS_X509_REMOVE_INFO)
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300100static int mbedtls_x509_sig_alg_gets( char *buf, size_t size,
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100101 mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
102 const void *sig_opts );
103#endif
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300104#if !defined(MBEDTLS_X509_REMOVE_INFO)
105static int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name );
106#endif /* !defined(MBEDTLS_X509_REMOVE_INFO) */
107
108#if defined(MBEDTLS_X509_CREATE_C)
109static int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name );
110static int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100111 int critical, const unsigned char *val,
112 size_t val_len );
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300113static int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start,
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100114 mbedtls_asn1_named_data *first );
115int mbedtls_x509_write_names( unsigned char **p, unsigned char *start,
116 mbedtls_asn1_named_data *first );
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300117static int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100118 const char *oid, size_t oid_len,
119 unsigned char *sig, size_t size );
Teppo Järvelinf69e6412019-09-03 16:50:17 +0300120#endif /* MBEDTLS_X509_CREATE_C */
Hanno Beckerf6bc8882019-05-02 13:05:58 +0100121#endif /* MBEDTLS_X509_INTERNAL_H */