| /* |
| * Copyright (c) 2007, Cameron Rich |
| * |
| * All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are met: |
| * |
| * * Redistributions of source code must retain the above copyright notice, |
| * this list of conditions and the following disclaimer. |
| * * Redistributions in binary form must reproduce the above copyright notice, |
| * this list of conditions and the following disclaimer in the documentation |
| * and/or other materials provided with the distribution. |
| * * Neither the name of the axTLS project nor the names of its contributors |
| * may be used to endorse or promote products derived from this software |
| * without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #ifndef __HEADER_X509_H__ |
| #define __HEADER_X509_H__ |
| |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
| |
| #include <time.h> |
| #include "cust_chl_interface.h" |
| #include "kal_public_api.h" |
| #include "kal_public_defs.h" |
| #include "ps_public_struct.h" |
| |
| #define malloc get_ctrl_buffer |
| #define free free_ctrl_buffer |
| |
| /************************************************************************** |
| * X509 declarations |
| **************************************************************************/ |
| #define X509_OK 0 |
| #define X509_NOT_OK -1 |
| #define X509_VFY_ERROR_NO_TRUSTED_CERT -2 |
| #define X509_VFY_ERROR_BAD_SIGNATURE -3 |
| #define X509_VFY_ERROR_NOT_YET_VALID -4 |
| #define X509_VFY_ERROR_EXPIRED -5 |
| #define X509_VFY_ERROR_SELF_SIGNED -6 |
| #define X509_VFY_ERROR_INVALID_CHAIN -7 |
| #define X509_VFY_ERROR_UNSUPPORTED_DIGEST -8 |
| #define X509_UNRECOGNISED_SIG_TYPE -9 |
| #define X509_VFY_ERROR_NO_UNTRUSTED_CERT -10 |
| #define X509_VFY_ERROR_GET_CA_DN -11 |
| #define X509_VFY_ERROR_GET_CERT_DN -12 |
| #define X509_VFY_ERROR_GET_TIME -13 |
| #define X509_VFY_ERROR_GET_PUB_KEY -14 |
| #define X509_VFY_ERROR_INOUT_NULL_PTR -15 |
| /* |
| * The Distinguished Name |
| */ |
| #define X509_NUM_DN_TYPES 3 |
| |
| struct _x509_ctx |
| { |
| char *ca_cert_dn[X509_NUM_DN_TYPES]; |
| char *cert_dn[X509_NUM_DN_TYPES]; |
| kal_uint32 not_before; |
| kal_uint32 not_after; |
| kal_uint8 *tbs; |
| kal_uint32 tbs_len; |
| t_cust_chl_asym_key key; |
| kal_uint8 *signature; |
| kal_uint16 sig_len; |
| kal_uint8 sig_type; |
| struct _x509_ctx *next; |
| }; |
| |
| typedef struct _x509_ctx X509_CTX; |
| |
| #define CONFIG_X509_MAX_CA_CERTS 150 |
| |
| typedef struct |
| { |
| X509_CTX *cert[CONFIG_X509_MAX_CA_CERTS]; |
| } CA_CERT_CTX; |
| |
| int x509_new(const kal_uint8 *cert, int *len, X509_CTX **ctx); |
| void x509_free(X509_CTX *x509_ctx); |
| int x509_verify(const CA_CERT_CTX *ca_cert_ctx, const X509_CTX *cert); |
| |
| #ifdef __cplusplus |
| } |
| #endif |
| |
| #endif |