yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2007, Cameron Rich |
| 3 | * |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are met: |
| 8 | * |
| 9 | * * Redistributions of source code must retain the above copyright notice, |
| 10 | * this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above copyright notice, |
| 12 | * this list of conditions and the following disclaimer in the documentation |
| 13 | * and/or other materials provided with the distribution. |
| 14 | * * Neither the name of the axTLS project nor the names of its contributors |
| 15 | * may be used to endorse or promote products derived from this software |
| 16 | * without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __HEADER_X509_H__ |
| 32 | #define __HEADER_X509_H__ |
| 33 | |
| 34 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | |
| 38 | #include <time.h> |
| 39 | #include "cust_chl_interface.h" |
| 40 | #include "kal_public_api.h" |
| 41 | #include "kal_public_defs.h" |
| 42 | #include "ps_public_struct.h" |
| 43 | |
| 44 | #define malloc get_ctrl_buffer |
| 45 | #define free free_ctrl_buffer |
| 46 | |
| 47 | /************************************************************************** |
| 48 | * X509 declarations |
| 49 | **************************************************************************/ |
| 50 | #define X509_OK 0 |
| 51 | #define X509_NOT_OK -1 |
| 52 | #define X509_VFY_ERROR_NO_TRUSTED_CERT -2 |
| 53 | #define X509_VFY_ERROR_BAD_SIGNATURE -3 |
| 54 | #define X509_VFY_ERROR_NOT_YET_VALID -4 |
| 55 | #define X509_VFY_ERROR_EXPIRED -5 |
| 56 | #define X509_VFY_ERROR_SELF_SIGNED -6 |
| 57 | #define X509_VFY_ERROR_INVALID_CHAIN -7 |
| 58 | #define X509_VFY_ERROR_UNSUPPORTED_DIGEST -8 |
| 59 | #define X509_UNRECOGNISED_SIG_TYPE -9 |
| 60 | #define X509_VFY_ERROR_NO_UNTRUSTED_CERT -10 |
| 61 | #define X509_VFY_ERROR_GET_CA_DN -11 |
| 62 | #define X509_VFY_ERROR_GET_CERT_DN -12 |
| 63 | #define X509_VFY_ERROR_GET_TIME -13 |
| 64 | #define X509_VFY_ERROR_GET_PUB_KEY -14 |
| 65 | #define X509_VFY_ERROR_INOUT_NULL_PTR -15 |
| 66 | /* |
| 67 | * The Distinguished Name |
| 68 | */ |
| 69 | #define X509_NUM_DN_TYPES 3 |
| 70 | |
| 71 | struct _x509_ctx |
| 72 | { |
| 73 | char *ca_cert_dn[X509_NUM_DN_TYPES]; |
| 74 | char *cert_dn[X509_NUM_DN_TYPES]; |
| 75 | kal_uint32 not_before; |
| 76 | kal_uint32 not_after; |
| 77 | kal_uint8 *tbs; |
| 78 | kal_uint32 tbs_len; |
| 79 | t_cust_chl_asym_key key; |
| 80 | kal_uint8 *signature; |
| 81 | kal_uint16 sig_len; |
| 82 | kal_uint8 sig_type; |
| 83 | struct _x509_ctx *next; |
| 84 | }; |
| 85 | |
| 86 | typedef struct _x509_ctx X509_CTX; |
| 87 | |
| 88 | #define CONFIG_X509_MAX_CA_CERTS 150 |
| 89 | |
| 90 | typedef struct |
| 91 | { |
| 92 | X509_CTX *cert[CONFIG_X509_MAX_CA_CERTS]; |
| 93 | } CA_CERT_CTX; |
| 94 | |
| 95 | int x509_new(const kal_uint8 *cert, int *len, X509_CTX **ctx); |
| 96 | void x509_free(X509_CTX *x509_ctx); |
| 97 | int x509_verify(const CA_CERT_CTX *ca_cert_ctx, const X509_CTX *cert); |
| 98 | |
| 99 | #ifdef __cplusplus |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | #endif |