35 #ifndef HEADER_CRYPTO_MISC_H 36 #define HEADER_CRYPTO_MISC_H 49 #define X509_NOT_OK -1 50 #define X509_VFY_ERROR_NO_TRUSTED_CERT -2 51 #define X509_VFY_ERROR_BAD_SIGNATURE -3 52 #define X509_VFY_ERROR_NOT_YET_VALID -4 53 #define X509_VFY_ERROR_EXPIRED -5 54 #define X509_VFY_ERROR_SELF_SIGNED -6 55 #define X509_VFY_ERROR_INVALID_CHAIN -7 56 #define X509_VFY_ERROR_UNSUPPORTED_DIGEST -8 57 #define X509_INVALID_PRIV_KEY -9 62 #define X509_NUM_DN_TYPES 4 63 #define X509_COMMON_NAME 0 64 #define X509_ORGANIZATION 1 65 #define X509_ORGANIZATIONAL_UNIT 2 66 #define X509_GENERIC 3 70 char *ca_cert_dn[X509_NUM_DN_TYPES];
71 char *cert_dn[X509_NUM_DN_TYPES];
72 char **subject_alt_dnsnames;
81 unsigned char md5[MD5_SIZE];
82 unsigned char sha1[SHA1_SIZE];
89 #ifdef CONFIG_SSL_CERT_VERIFICATION 93 X509_CTX *cert[CONFIG_X509_MAX_CA_CERTS];
98 int x509_new(
const uint8_t *cert,
int *len, X509_CTX **ctx);
100 #ifdef CONFIG_SSL_CERT_VERIFICATION 101 int x509_verify(X509_CTX* ca_certs ,
const X509_CTX *cert,
const SSL_DateTime* now);
103 #ifdef CONFIG_SSL_FULL_MODE 104 void x509_print(
const X509_CTX *cert, CA_CERT_CTX *ca_cert_ctx);
105 const char * x509_display_error(
int error);
111 #define ASN1_INTEGER 0x02 112 #define ASN1_BIT_STRING 0x03 113 #define ASN1_OCTET_STRING 0x04 114 #define ASN1_NULL 0x05 115 #define ASN1_PRINTABLE_STR2 0x0C 116 #define ASN1_OID 0x06 117 #define ASN1_UNIVERSAL_STR 0x1C 118 #define ASN1_PRINTABLE_STR 0x13 119 #define ASN1_TELETEX_STR 0x14 120 #define ASN1_IA5_STR 0x16 121 #define ASN1_UTC_TIME 0x17 122 #define ASN1_GENERALIZED_TIME 0x18 123 #define ASN1_UNICODE_STR 0x1e 124 #define ASN1_SEQUENCE 0x30 125 #define ASN1_CONTEXT_DNSNAME 0x82 126 #define ASN1_SET 0x31 127 #define ASN1_V3_DATA 0xa3 128 #define ASN1_IMPLICIT_TAG 0x80 129 #define ASN1_CONTEXT_DNSNAME 0x82 130 #define ASN1_EXPLICIT_TAG 0xa0 131 #define ASN1_V3_DATA 0xa3 133 #define SIG_TYPE_MD2 0x02 134 #define SIG_TYPE_MD5 0x04 135 #define SIG_TYPE_SHA1 0x05 136 #define SIG_TYPE_SHA256 0x0B 138 int get_asn1_length(
const uint8_t *buf,
int *offset);
140 int asn1_next_obj(
const uint8_t *buf,
int *offset,
int obj_type);
141 int asn1_skip_obj(
const uint8_t *buf,
int *offset,
int obj_type);
142 int asn1_get_int(
const uint8_t *buf,
int *offset, uint8_t **
object);
143 int asn1_version(
const uint8_t *cert,
int *offset, X509_CTX *x509_ctx);
144 int asn1_validity(
const uint8_t *cert,
int *offset, X509_CTX *x509_ctx);
145 int asn1_name(
const uint8_t *cert,
int *offset,
char *dn[]);
146 int asn1_public_key(
const uint8_t *cert,
int *offset, X509_CTX *x509_ctx);
147 #ifdef CONFIG_SSL_CERT_VERIFICATION 148 int asn1_signature(
const uint8_t *cert,
int *offset, X509_CTX *x509_ctx);
149 int asn1_find_subjectaltname(
const uint8_t* cert,
int offset);
150 int asn1_compare_dn(
char *
const dn1[],
char *
const dn2[]);
153 int *offset, X509_CTX *x509_ctx);
160 extern const char *
const unsupported_str;
162 typedef void (*crypt_func)(
void *,
const uint8_t *, uint8_t *, int);
163 typedef void (*hmac_func)(
const uint8_t *msg,
int length,
const uint8_t *key,
164 int key_len, uint8_t *digest);
166 int get_file(
const char *filename, uint8_t **buf);
168 #if defined(CONFIG_SSL_FULL_MODE) || defined(WIN32) || defined(CONFIG_DEBUG) 169 EXP_FUNC
void STDCALL print_blob(
const char *format,
const uint8_t *data,
int size, ...);
172 EXP_FUNC
void STDCALL print_blob(
const char *format,
const uint8_t *data,
int size, ...);
175 EXP_FUNC
int STDCALL base64_decode(
const char *in,
int len,
176 uint8_t *out,
int *outlen);
int asn1_name(const uint8_t *cert, int *offset, char *dn[])
Get the subject name (or the issuer) of a certificate.
Definition: asn1.c:412
int asn1_public_key(const uint8_t *cert, int *offset, X509_CTX *x509_ctx)
Read the modulus and public exponent of a certificate.
Definition: asn1.c:492
int asn1_validity(const uint8_t *cert, int *offset, X509_CTX *x509_ctx)
Retrieve the notbefore and notafter certificate times.
Definition: asn1.c:266
int asn1_skip_obj(const uint8_t *buf, int *offset, int obj_type)
Skip over an ASN.1 object type completely.
Definition: asn1.c:106
int x509_new(const uint8_t *cert, int *len, X509_CTX **ctx)
Construct a new x509 object.
Definition: x509.c:72
void x509_free(X509_CTX *x509_ctx)
Free an X.509 object's resources.
Definition: x509.c:248
int asn1_version(const uint8_t *cert, int *offset, X509_CTX *x509_ctx)
Get the version type of a certificate (which we don't actually care about)
Definition: asn1.c:249
Definition: crypto_misc.h:68
int asn1_signature_type(const uint8_t *cert, int *offset, X509_CTX *x509_ctx)
Read the signature type of the certificate.
Definition: asn1.c:647
int asn1_get_int(const uint8_t *buf, int *offset, uint8_t **object)
Read an integer value for ASN.1 data Note: This function allocates memory which must be freed by the ...
Definition: asn1.c:122
int asn1_get_private_key(const uint8_t *buf, int len, RSA_CTX **rsa_ctx)
Get all the RSA private key specifics from an ASN.1 encoded file.
Definition: asn1.c:146
int asn1_next_obj(const uint8_t *buf, int *offset, int obj_type)
Skip the ASN1.1 object type and its length.
Definition: asn1.c:94
A big integer basic object.
Definition: bigint_impl.h:83