2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
* \file x509.h
|
2009-01-04 17:27:10 +01:00
|
|
|
*
|
2011-01-06 13:28:03 +01:00
|
|
|
* \brief X.509 certificate and private key decoding
|
|
|
|
*
|
2010-07-18 12:13:04 +02:00
|
|
|
* Copyright (C) 2006-2010, Brainspark B.V.
|
2010-07-18 22:36:00 +02:00
|
|
|
*
|
|
|
|
* This file is part of PolarSSL (http://www.polarssl.org)
|
2010-07-18 12:13:04 +02:00
|
|
|
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
2010-07-18 22:36:00 +02:00
|
|
|
*
|
2009-07-28 19:23:11 +02:00
|
|
|
* All rights reserved.
|
2009-01-04 17:27:10 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
2009-01-03 22:51:57 +01:00
|
|
|
#ifndef POLARSSL_X509_H
|
|
|
|
#define POLARSSL_X509_H
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2009-01-03 22:24:11 +01:00
|
|
|
#include "polarssl/rsa.h"
|
2011-01-06 16:48:19 +01:00
|
|
|
#include "polarssl/dhm.h"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/**
|
|
|
|
* @addtogroup x509_module
|
|
|
|
* @{
|
2009-07-28 09:18:38 +02:00
|
|
|
*/
|
2011-01-06 13:28:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name ASN1 Error codes
|
|
|
|
* These error codes are OR'ed to X509 error codes for
|
|
|
|
* higher error granularity.
|
|
|
|
* ASN1 is a standard to specify data structures.
|
|
|
|
* @{
|
2009-07-28 09:18:38 +02:00
|
|
|
*/
|
2011-01-06 13:28:03 +01:00
|
|
|
#define POLARSSL_ERR_ASN1_OUT_OF_DATA 0x0014 /**< Out of data when parsing an ASN1 data structure. */
|
|
|
|
#define POLARSSL_ERR_ASN1_UNEXPECTED_TAG 0x0016 /**< ASN1 tag was of an unexpected value. */
|
|
|
|
#define POLARSSL_ERR_ASN1_INVALID_LENGTH 0x0018 /**< Error when trying to determine the length or invalid length. */
|
|
|
|
#define POLARSSL_ERR_ASN1_LENGTH_MISMATCH 0x001A /**< Actual length differs from expected length. */
|
|
|
|
#define POLARSSL_ERR_ASN1_INVALID_DATA 0x001C /**< Data is invalid. (not used) */
|
|
|
|
/* @} name */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name X509 Error codes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x0020 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_PEM -0x0040 /**< The PEM-encoded certificate contains invalid elements, e.g. invalid character. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_FORMAT -0x0060 /**< The certificate format is invalid, e.g. different type expected. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_VERSION -0x0080 /**< The certificate version element is invalid. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_SERIAL -0x00A0 /**< The serial tag or value is invalid. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_ALG -0x00C0 /**< The algorithm tag or value is invalid. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_NAME -0x00E0 /**< The name tag or value is invalid. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_DATE -0x0100 /**< The date tag or value is invalid. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY -0x0120 /**< The pubkey tag or value is invalid (only RSA is supported). */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE -0x0140 /**< The signature tag or value invalid. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS -0x0160 /**< The extension tag or value is invalid. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION -0x0180 /**< Certificate or CRL has an unsupported version number. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG -0x01A0 /**< Signature algorithm (oid) is unsupported. */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_UNKNOWN_PK_ALG -0x01C0 /**< Public key algorithm is unsupported (only RSA is supported). */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_SIG_MISMATCH -0x01E0 /**< Certificate signature algorithms do not match. (see \c ::x509_cert sig_oid) */
|
|
|
|
#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x0200 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
|
|
|
|
#define POLARSSL_ERR_X509_KEY_INVALID_PEM -0x0220 /**< PEM key string is not as expected. */
|
|
|
|
#define POLARSSL_ERR_X509_KEY_INVALID_VERSION -0x0240 /**< Unsupported RSA key version */
|
|
|
|
#define POLARSSL_ERR_X509_KEY_INVALID_FORMAT -0x0260 /**< Invalid RSA key tag or value. */
|
|
|
|
#define POLARSSL_ERR_X509_KEY_INVALID_ENC_IV -0x0280 /**< RSA IV is not in hex-format. */
|
|
|
|
#define POLARSSL_ERR_X509_KEY_UNKNOWN_ENC_ALG -0x02A0 /**< Unsupported key encryption algorithm. */
|
|
|
|
#define POLARSSL_ERR_X509_KEY_PASSWORD_REQUIRED -0x02C0 /**< Private key password can't be empty. */
|
|
|
|
#define POLARSSL_ERR_X509_KEY_PASSWORD_MISMATCH -0x02E0 /**< Given private key password does not allow for correct decryption. */
|
|
|
|
#define POLARSSL_ERR_X509_POINT_ERROR -0x0300 /**< Not used. */
|
|
|
|
#define POLARSSL_ERR_X509_VALUE_TO_LENGTH -0x0320 /**< Not used. */
|
|
|
|
/* @} name */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name X509 Verify codes
|
|
|
|
* @{
|
2009-07-28 09:18:38 +02:00
|
|
|
*/
|
2011-01-06 13:28:03 +01:00
|
|
|
#define BADCERT_EXPIRED 1 /**< The certificate validity has expired. */
|
|
|
|
#define BADCERT_REVOKED 2 /**< The certificate has been revoked (is on a CRL). */
|
|
|
|
#define BADCERT_CN_MISMATCH 4 /**< The certificate Common Name (CN) does not match with the expected CN. */
|
|
|
|
#define BADCERT_NOT_TRUSTED 8 /**< The certificate is not correctly signed by the trusted CA. */
|
|
|
|
#define BADCRL_NOT_TRUSTED 16 /**< CRL is not correctly signed by the trusted CA. */
|
|
|
|
#define BADCRL_EXPIRED 32 /**< CRL is expired. */
|
|
|
|
/* @} name */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name DER constants
|
|
|
|
* These constants comply with DER encoded the ANS1 type tags.
|
|
|
|
* DER encoding uses hexadecimal representation.
|
|
|
|
* An example DER sequence is:\n
|
|
|
|
* - 0x02 -- tag indicating INTEGER
|
|
|
|
* - 0x01 -- length in octets
|
|
|
|
* - 0x05 -- value
|
|
|
|
* Such sequences are typically read into \c ::x509_buf.
|
|
|
|
* @{
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
|
|
|
#define ASN1_BOOLEAN 0x01
|
|
|
|
#define ASN1_INTEGER 0x02
|
|
|
|
#define ASN1_BIT_STRING 0x03
|
|
|
|
#define ASN1_OCTET_STRING 0x04
|
|
|
|
#define ASN1_NULL 0x05
|
|
|
|
#define ASN1_OID 0x06
|
|
|
|
#define ASN1_UTF8_STRING 0x0C
|
|
|
|
#define ASN1_SEQUENCE 0x10
|
|
|
|
#define ASN1_SET 0x11
|
|
|
|
#define ASN1_PRINTABLE_STRING 0x13
|
|
|
|
#define ASN1_T61_STRING 0x14
|
|
|
|
#define ASN1_IA5_STRING 0x16
|
|
|
|
#define ASN1_UTC_TIME 0x17
|
2010-02-18 22:26:15 +01:00
|
|
|
#define ASN1_GENERALIZED_TIME 0x18
|
2009-01-03 22:22:43 +01:00
|
|
|
#define ASN1_UNIVERSAL_STRING 0x1C
|
|
|
|
#define ASN1_BMP_STRING 0x1E
|
|
|
|
#define ASN1_PRIMITIVE 0x00
|
|
|
|
#define ASN1_CONSTRUCTED 0x20
|
|
|
|
#define ASN1_CONTEXT_SPECIFIC 0x80
|
2011-01-06 13:28:03 +01:00
|
|
|
/* @} name */
|
|
|
|
/* @} addtogroup x509_module */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* various object identifiers
|
|
|
|
*/
|
|
|
|
#define X520_COMMON_NAME 3
|
|
|
|
#define X520_COUNTRY 6
|
|
|
|
#define X520_LOCALITY 7
|
|
|
|
#define X520_STATE 8
|
|
|
|
#define X520_ORGANIZATION 10
|
|
|
|
#define X520_ORG_UNIT 11
|
|
|
|
#define PKCS9_EMAIL 1
|
|
|
|
|
|
|
|
#define X509_OUTPUT_DER 0x01
|
|
|
|
#define X509_OUTPUT_PEM 0x02
|
|
|
|
#define PEM_LINE_LENGTH 72
|
|
|
|
#define X509_ISSUER 0x01
|
|
|
|
#define X509_SUBJECT 0x02
|
|
|
|
|
|
|
|
#define OID_X520 "\x55\x04"
|
|
|
|
#define OID_CN "\x55\x04\x03"
|
|
|
|
#define OID_PKCS1 "\x2A\x86\x48\x86\xF7\x0D\x01\x01"
|
|
|
|
#define OID_PKCS1_RSA "\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01"
|
|
|
|
#define OID_PKCS1_RSA_SHA "\x2A\x86\x48\x86\xF7\x0D\x01\x01\x05"
|
|
|
|
#define OID_PKCS9 "\x2A\x86\x48\x86\xF7\x0D\x01\x09"
|
|
|
|
#define OID_PKCS9_EMAIL "\x2A\x86\x48\x86\xF7\x0D\x01\x09\x01"
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/**
|
|
|
|
* @addtogroup x509_module
|
|
|
|
* @{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Structures for parsing X.509 certificates and CRLs
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type-length-value structure that allows for ASN1 using DER.
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
|
|
|
typedef struct _x509_buf
|
|
|
|
{
|
2011-01-06 13:28:03 +01:00
|
|
|
int tag; /**< ASN1 type, e.g. ASN1_UTF8_STRING. */
|
|
|
|
int len; /**< ASN1 length, e.g. in octets. */
|
|
|
|
unsigned char *p; /**< ASN1 data, e.g. in ASCII. */
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
x509_buf;
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/**
|
|
|
|
* Container for ASN1 named information objects.
|
|
|
|
* It allows for Relative Distinguished Names (e.g. cn=polarssl,ou=code,etc.).
|
|
|
|
*/
|
2009-01-03 22:22:43 +01:00
|
|
|
typedef struct _x509_name
|
|
|
|
{
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_buf oid; /**< The object identifier. */
|
|
|
|
x509_buf val; /**< The named value. */
|
|
|
|
struct _x509_name *next; /**< The next named information object. */
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
x509_name;
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/** Container for date and time (precision in seconds). */
|
2009-01-03 22:22:43 +01:00
|
|
|
typedef struct _x509_time
|
|
|
|
{
|
2011-01-06 13:28:03 +01:00
|
|
|
int year, mon, day; /**< Date. */
|
|
|
|
int hour, min, sec; /**< Time. */
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
x509_time;
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/**
|
|
|
|
* Container for an X.509 certificate. The certificate may be chained.
|
|
|
|
*/
|
2009-01-03 22:22:43 +01:00
|
|
|
typedef struct _x509_cert
|
|
|
|
{
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_buf raw; /**< The raw certificate data (DER). */
|
|
|
|
x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
int version; /**< The X.509 version. (0=v1, 1=v2, 2=v3) */
|
|
|
|
x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
|
|
|
|
x509_buf sig_oid1; /**< Signature algorithm, e.g. sha1RSA */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
|
|
|
|
x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_name issuer; /**< The parsed issuer data (named information object). */
|
|
|
|
x509_name subject; /**< The parsed subject data (named information object). */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_time valid_from; /**< Start time of certificate validity. */
|
|
|
|
x509_time valid_to; /**< End time of certificate validity. */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_buf pk_oid; /**< Subject public key info. Includes the public key algorithm and the key itself. */
|
|
|
|
rsa_context rsa; /**< Container for the RSA context. Only RSA is supported for public keys at this time. */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
|
|
|
|
x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
|
|
|
|
x509_buf v3_ext; /**< Optional X.509 v3 extensions. Only Basic Contraints are supported at this time. */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
|
|
|
|
int max_pathlen; /**< Optional Basic Constraint extension value: The maximum path length to the root certificate. */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_buf sig_oid2; /**< Signature algorithm. Must match sig_oid1. */
|
|
|
|
x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
|
|
|
|
int sig_alg; /**< Internal representation of the signature algorithm, e.g. SIG_RSA_MD2 */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
struct _x509_cert *next; /**< Next certificate in the CA-chain. */
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
x509_cert;
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/**
|
|
|
|
* Certificate revocation list entry.
|
|
|
|
* Contains the CA-specific serial numbers and revocation dates.
|
|
|
|
*/
|
2009-05-02 17:13:40 +02:00
|
|
|
typedef struct _x509_crl_entry
|
|
|
|
{
|
|
|
|
x509_buf raw;
|
|
|
|
|
|
|
|
x509_buf serial;
|
|
|
|
|
|
|
|
x509_time revocation_date;
|
|
|
|
|
|
|
|
x509_buf entry_ext;
|
|
|
|
|
|
|
|
struct _x509_crl_entry *next;
|
|
|
|
}
|
|
|
|
x509_crl_entry;
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/**
|
|
|
|
* Certificate revocation list structure.
|
|
|
|
* Every CRL may have multiple entries.
|
|
|
|
*/
|
2009-05-02 17:13:40 +02:00
|
|
|
typedef struct _x509_crl
|
|
|
|
{
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_buf raw; /**< The raw certificate data (DER). */
|
|
|
|
x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
|
2009-05-02 17:13:40 +02:00
|
|
|
|
|
|
|
int version;
|
|
|
|
x509_buf sig_oid1;
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_buf issuer_raw; /**< The raw issuer data (DER). */
|
2009-05-02 17:13:40 +02:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_name issuer; /**< The parsed issuer data (named information object). */
|
2009-05-02 17:13:40 +02:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_time this_update;
|
2009-05-02 17:13:40 +02:00
|
|
|
x509_time next_update;
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
|
2009-05-02 17:13:40 +02:00
|
|
|
|
|
|
|
x509_buf crl_ext;
|
|
|
|
|
|
|
|
x509_buf sig_oid2;
|
|
|
|
x509_buf sig;
|
2010-03-17 07:56:01 +01:00
|
|
|
int sig_alg;
|
2009-05-02 17:13:40 +02:00
|
|
|
|
|
|
|
struct _x509_crl *next;
|
|
|
|
}
|
|
|
|
x509_crl;
|
2011-01-06 13:28:03 +01:00
|
|
|
/** @} name Structures for parsing X.509 certificates and CRLs */
|
|
|
|
/** @} addtogroup x509_module */
|
2009-05-02 17:13:40 +02:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/**
|
|
|
|
* @name Structures for writing X.509 certificates.
|
|
|
|
* XvP: commented out as they are not used.
|
|
|
|
* - <tt>typedef struct _x509_node x509_node;</tt>
|
|
|
|
* - <tt>typedef struct _x509_raw x509_raw;</tt>
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
2011-01-06 13:28:03 +01:00
|
|
|
/*
|
2009-01-03 22:22:43 +01:00
|
|
|
typedef struct _x509_node
|
|
|
|
{
|
|
|
|
unsigned char *data;
|
|
|
|
unsigned char *p;
|
|
|
|
unsigned char *end;
|
|
|
|
|
|
|
|
size_t len;
|
|
|
|
}
|
|
|
|
x509_node;
|
|
|
|
|
|
|
|
typedef struct _x509_raw
|
|
|
|
{
|
|
|
|
x509_node raw;
|
|
|
|
x509_node tbs;
|
|
|
|
|
|
|
|
x509_node version;
|
|
|
|
x509_node serial;
|
|
|
|
x509_node tbs_signalg;
|
|
|
|
x509_node issuer;
|
|
|
|
x509_node validity;
|
|
|
|
x509_node subject;
|
|
|
|
x509_node subpubkey;
|
|
|
|
|
|
|
|
x509_node signalg;
|
|
|
|
x509_node sign;
|
|
|
|
}
|
|
|
|
x509_raw;
|
2011-01-06 13:28:03 +01:00
|
|
|
*/
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/**
|
2011-01-06 16:48:19 +01:00
|
|
|
* @name Functions to read in DHM parameters, a certificate, CRL or private RSA key
|
2011-01-06 13:28:03 +01:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @ingroup x509_module */
|
2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
* \brief Parse one or more certificates and add them
|
|
|
|
* to the chained list
|
|
|
|
*
|
|
|
|
* \param chain points to the start of the chain
|
|
|
|
* \param buf buffer holding the certificate data
|
|
|
|
* \param buflen size of the buffer
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a specific X509 error code
|
|
|
|
*/
|
2010-03-16 22:09:09 +01:00
|
|
|
int x509parse_crt( x509_cert *chain, const unsigned char *buf, int buflen );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/** @ingroup x509_module */
|
2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
* \brief Load one or more certificates and add them
|
|
|
|
* to the chained list
|
|
|
|
*
|
|
|
|
* \param chain points to the start of the chain
|
|
|
|
* \param path filename to read the certificates from
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a specific X509 error code
|
|
|
|
*/
|
2010-03-16 22:09:09 +01:00
|
|
|
int x509parse_crtfile( x509_cert *chain, const char *path );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/** @ingroup x509_module */
|
2009-05-02 17:13:40 +02:00
|
|
|
/**
|
|
|
|
* \brief Parse one or more CRLs and add them
|
|
|
|
* to the chained list
|
|
|
|
*
|
|
|
|
* \param chain points to the start of the chain
|
|
|
|
* \param buf buffer holding the CRL data
|
|
|
|
* \param buflen size of the buffer
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a specific X509 error code
|
|
|
|
*/
|
2010-03-16 22:09:09 +01:00
|
|
|
int x509parse_crl( x509_crl *chain, const unsigned char *buf, int buflen );
|
2009-05-02 17:13:40 +02:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/** @ingroup x509_module */
|
2009-05-02 17:13:40 +02:00
|
|
|
/**
|
|
|
|
* \brief Load one or more CRLs and add them
|
|
|
|
* to the chained list
|
|
|
|
*
|
|
|
|
* \param chain points to the start of the chain
|
|
|
|
* \param path filename to read the CRLs from
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a specific X509 error code
|
|
|
|
*/
|
2010-03-16 22:09:09 +01:00
|
|
|
int x509parse_crlfile( x509_crl *chain, const char *path );
|
2009-05-02 17:13:40 +02:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/** @ingroup x509_module */
|
2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
* \brief Parse a private RSA key
|
|
|
|
*
|
|
|
|
* \param rsa RSA context to be initialized
|
2010-03-16 22:09:09 +01:00
|
|
|
* \param key input buffer
|
|
|
|
* \param keylen size of the buffer
|
2009-01-03 22:22:43 +01:00
|
|
|
* \param pwd password for decryption (optional)
|
|
|
|
* \param pwdlen size of the password
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a specific X509 error code
|
|
|
|
*/
|
|
|
|
int x509parse_key( rsa_context *rsa,
|
2010-03-16 22:09:09 +01:00
|
|
|
const unsigned char *key, int keylen,
|
|
|
|
const unsigned char *pwd, int pwdlen );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/** @ingroup x509_module */
|
2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
* \brief Load and parse a private RSA key
|
|
|
|
*
|
|
|
|
* \param rsa RSA context to be initialized
|
|
|
|
* \param path filename to read the private key from
|
2011-01-06 13:28:03 +01:00
|
|
|
* \param password password to decrypt the file (can be NULL)
|
2009-01-03 22:22:43 +01:00
|
|
|
*
|
|
|
|
* \return 0 if successful, or a specific X509 error code
|
|
|
|
*/
|
2010-03-16 22:09:09 +01:00
|
|
|
int x509parse_keyfile( rsa_context *rsa, const char *path,
|
|
|
|
const char *password );
|
2011-01-06 16:48:19 +01:00
|
|
|
|
|
|
|
/** @ingroup x509_module */
|
|
|
|
/**
|
|
|
|
* \brief Parse DHM parameters
|
|
|
|
*
|
|
|
|
* \param dhm DHM context to be initialized
|
|
|
|
* \param dhmin input buffer
|
|
|
|
* \param dhminlen size of the buffer
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a specific X509 error code
|
|
|
|
*/
|
|
|
|
int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, int dhminlen );
|
|
|
|
|
|
|
|
/** @ingroup x509_module */
|
|
|
|
/**
|
|
|
|
* \brief Load and parse DHM parameters
|
|
|
|
*
|
|
|
|
* \param dhm DHM context to be initialized
|
|
|
|
* \param path filename to read the DHM Parameters from
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or a specific X509 error code
|
|
|
|
*/
|
|
|
|
int x509parse_dhmfile( dhm_context *rsa, const char *path );
|
|
|
|
|
|
|
|
/** @} name Functions to read in DHM parameters, a certificate, CRL or private RSA key */
|
2011-01-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Store the certificate DN in printable form into buf;
|
2009-05-02 17:13:40 +02:00
|
|
|
* no more than size characters will be written.
|
2009-07-28 09:18:38 +02:00
|
|
|
*
|
|
|
|
* \param buf Buffer to write to
|
|
|
|
* \param size Maximum size of buffer
|
|
|
|
* \param dn The X509 name to represent
|
|
|
|
*
|
|
|
|
* \return The amount of data written to the buffer, or -1 in
|
|
|
|
* case of an error.
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
2010-03-16 22:09:09 +01:00
|
|
|
int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Returns an informational string about the
|
|
|
|
* certificate.
|
2009-07-28 09:18:38 +02:00
|
|
|
*
|
|
|
|
* \param buf Buffer to write to
|
|
|
|
* \param size Maximum size of buffer
|
|
|
|
* \param prefix A line prefix
|
|
|
|
* \param crt The X509 certificate to represent
|
|
|
|
*
|
|
|
|
* \return The amount of data written to the buffer, or -1 in
|
|
|
|
* case of an error.
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
2010-03-16 22:09:09 +01:00
|
|
|
int x509parse_cert_info( char *buf, size_t size, const char *prefix,
|
|
|
|
const x509_cert *crt );
|
2009-05-02 17:13:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Returns an informational string about the
|
|
|
|
* CRL.
|
2009-07-28 09:18:38 +02:00
|
|
|
*
|
|
|
|
* \param buf Buffer to write to
|
|
|
|
* \param size Maximum size of buffer
|
|
|
|
* \param prefix A line prefix
|
2011-01-06 13:28:03 +01:00
|
|
|
* \param crl The X509 CRL to represent
|
2009-07-28 09:18:38 +02:00
|
|
|
*
|
|
|
|
* \return The amount of data written to the buffer, or -1 in
|
|
|
|
* case of an error.
|
2009-05-02 17:13:40 +02:00
|
|
|
*/
|
2010-03-16 22:09:09 +01:00
|
|
|
int x509parse_crl_info( char *buf, size_t size, const char *prefix,
|
|
|
|
const x509_crl *crl );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
/**
|
2009-07-28 09:18:38 +02:00
|
|
|
* \brief Check a given x509_time against the system time and check
|
|
|
|
* if it is valid.
|
|
|
|
*
|
|
|
|
* \param time x509_time to check
|
|
|
|
*
|
|
|
|
* \return Return 0 if the x509_time is still valid,
|
2009-05-03 12:18:48 +02:00
|
|
|
* or 1 otherwise.
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
2010-03-16 22:09:09 +01:00
|
|
|
int x509parse_time_expired( const x509_time *time );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/**
|
|
|
|
* @name Functions to verify a certificate
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/** @ingroup x509_module */
|
2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
* \brief Verify the certificate signature
|
|
|
|
*
|
|
|
|
* \param crt a certificate to be verified
|
|
|
|
* \param trust_ca the trusted CA chain
|
2009-05-03 12:18:48 +02:00
|
|
|
* \param ca_crl the CRL chain for trusted CA's
|
2009-01-03 22:22:43 +01:00
|
|
|
* \param cn expected Common Name (can be set to
|
|
|
|
* NULL if the CN must not be verified)
|
|
|
|
* \param flags result of the verification
|
2011-01-13 18:54:59 +01:00
|
|
|
* \param f_vrfy verification function
|
|
|
|
* \param p_vrfy verification parameter
|
2009-01-03 22:22:43 +01:00
|
|
|
*
|
2009-01-03 22:51:57 +01:00
|
|
|
* \return 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED,
|
2009-01-03 22:22:43 +01:00
|
|
|
* in which case *flags will have one or more of
|
|
|
|
* the following values set:
|
|
|
|
* BADCERT_EXPIRED --
|
|
|
|
* BADCERT_REVOKED --
|
|
|
|
* BADCERT_CN_MISMATCH --
|
|
|
|
* BADCERT_NOT_TRUSTED
|
|
|
|
*
|
|
|
|
* \note TODO: add two arguments, depth and crl
|
|
|
|
*/
|
|
|
|
int x509parse_verify( x509_cert *crt,
|
|
|
|
x509_cert *trust_ca,
|
2009-05-03 12:18:48 +02:00
|
|
|
x509_crl *ca_crl,
|
2011-01-13 18:54:59 +01:00
|
|
|
const char *cn, int *flags,
|
|
|
|
int (*f_vrfy)(void *, x509_cert *, int, int),
|
|
|
|
void *p_vrfy );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/** @} name Functions to verify a certificate */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Functions to clear a certificate, CRL or private RSA key
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/** @ingroup x509_module */
|
2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
* \brief Unallocate all certificate data
|
2009-07-28 09:18:38 +02:00
|
|
|
*
|
|
|
|
* \param crt Certificate chain to free
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
|
|
|
void x509_free( x509_cert *crt );
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/** @ingroup x509_module */
|
2009-05-02 17:13:40 +02:00
|
|
|
/**
|
|
|
|
* \brief Unallocate all CRL data
|
2009-07-28 09:18:38 +02:00
|
|
|
*
|
2011-01-06 13:28:03 +01:00
|
|
|
* \param crl CRL chain to free
|
2009-05-02 17:13:40 +02:00
|
|
|
*/
|
|
|
|
void x509_crl_free( x509_crl *crl );
|
|
|
|
|
2011-01-06 13:28:03 +01:00
|
|
|
/** @} name Functions to clear a certificate, CRL or private RSA key */
|
|
|
|
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
* \brief Checkup routine
|
|
|
|
*
|
|
|
|
* \return 0 if successful, or 1 if the test failed
|
|
|
|
*/
|
|
|
|
int x509_self_test( int verbose );
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* x509.h */
|