/home/dko/Projects/mobilec/src/security/xyssl-0.9/library/x509parse.c File Reference

#include "xyssl/config.h"
#include "xyssl/x509.h"
#include "xyssl/base64.h"
#include "xyssl/des.h"
#include "xyssl/md2.h"
#include "xyssl/md4.h"
#include "xyssl/md5.h"
#include "xyssl/sha1.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "xyssl/certs.h"

Go to the source code of this file.

Functions

static int asn1_get_len (unsigned char **p, unsigned char *end, int *len)
static int asn1_get_tag (unsigned char **p, unsigned char *end, int *len, int tag)
static int asn1_get_bool (unsigned char **p, unsigned char *end, int *val)
static int asn1_get_int (unsigned char **p, unsigned char *end, int *val)
static int asn1_get_mpi (unsigned char **p, unsigned char *end, mpi *X)
static int x509_get_version (unsigned char **p, unsigned char *end, int *ver)
static int x509_get_serial (unsigned char **p, unsigned char *end, x509_buf *serial)
static int x509_get_alg (unsigned char **p, unsigned char *end, x509_buf *alg)
static int x509_get_name (unsigned char **p, unsigned char *end, x509_name *cur)
static int x509_get_dates (unsigned char **p, unsigned char *end, x509_time *from, x509_time *to)
static int x509_get_pubkey (unsigned char **p, unsigned char *end, x509_buf *pk_alg_oid, mpi *N, mpi *E)
static int x509_get_sig (unsigned char **p, unsigned char *end, x509_buf *sig)
static int x509_get_uid (unsigned char **p, unsigned char *end, x509_buf *uid, int n)
static int x509_get_ext (unsigned char **p, unsigned char *end, x509_buf *ext, int *ca_istrue, int *max_pathlen)
int x509parse_crt (x509_cert *chain, unsigned char *buf, int buflen)
 Parse one or more certificates and add them to the chained list.
int x509parse_crtfile (x509_cert *chain, char *path)
 Load one or more certificates and add them to the chained list.
static int x509_get_iv (unsigned char *s, unsigned char iv[8])
static void x509_des3_decrypt (unsigned char des3_iv[8], unsigned char *buf, int buflen, unsigned char *pwd, int pwdlen)
int x509parse_key (rsa_context *rsa, unsigned char *buf, int buflen, unsigned char *pwd, int pwdlen)
 Parse a private RSA key.
int x509parse_keyfile (rsa_context *rsa, char *path, char *pwd)
 Load and parse a private RSA key.
int x509parse_dn_gets (char *buf, char *end, x509_name *dn)
 Store the certificate DN in printable form into buf; no more than (end - buf) characters will be written.
char * x509parse_cert_info (char *prefix, x509_cert *crt)
 Returns an informational string about the certificate.
int x509parse_expired (x509_cert *crt)
 Return 0 if the certificate is still valid, or BADCERT_EXPIRED.
static void x509_hash (unsigned char *in, int len, int alg, unsigned char *out)
int x509parse_verify (x509_cert *crt, x509_cert *trust_ca, char *cn, int *flags)
 Verify the certificate signature.
void x509_free (x509_cert *crt)
 Unallocate all certificate data.
int x509_self_test (int verbose)
 Checkup routine.

Function Documentation

static int asn1_get_bool ( unsigned char **  p,
unsigned char *  end,
int val 
) [static]

Definition at line 108 of file x509parse.c.

References ASN1_BOOLEAN, asn1_get_tag(), and XYSSL_ERR_ASN1_INVALID_LENGTH.

Referenced by x509_get_ext().

static int asn1_get_int ( unsigned char **  p,
unsigned char *  end,
int val 
) [static]
static int asn1_get_len ( unsigned char **  p,
unsigned char *  end,
int len 
) [static]
static int asn1_get_mpi ( unsigned char **  p,
unsigned char *  end,
mpi X 
) [static]

Definition at line 149 of file x509parse.c.

References asn1_get_tag(), ASN1_INTEGER, and mpi_read_binary().

Referenced by x509_get_pubkey(), and x509parse_key().

static int asn1_get_tag ( unsigned char **  p,
unsigned char *  end,
int len,
int  tag 
) [static]
static void x509_des3_decrypt ( unsigned char  des3_iv[8],
unsigned char *  buf,
int  buflen,
unsigned char *  pwd,
int  pwdlen 
) [static]

Definition at line 1042 of file x509parse.c.

References des3_crypt_cbc(), des3_set3key_dec(), DES_DECRYPT, md5_finish(), md5_starts(), and md5_update().

Referenced by x509parse_key().

void x509_free ( x509_cert crt  ) 
static int x509_get_alg ( unsigned char **  p,
unsigned char *  end,
x509_buf alg 
) [static]
static int x509_get_dates ( unsigned char **  p,
unsigned char *  end,
x509_time from,
x509_time to 
) [static]
static int x509_get_ext ( unsigned char **  p,
unsigned char *  end,
x509_buf ext,
int ca_istrue,
int max_pathlen 
) [static]
static int x509_get_iv ( unsigned char *  s,
unsigned char  iv[8] 
) [static]

Definition at line 1018 of file x509parse.c.

References XYSSL_ERR_X509_KEY_INVALID_ENC_IV.

Referenced by x509parse_key().

static int x509_get_name ( unsigned char **  p,
unsigned char *  end,
x509_name cur 
) [static]
static int x509_get_pubkey ( unsigned char **  p,
unsigned char *  end,
x509_buf pk_alg_oid,
mpi N,
mpi E 
) [static]
static int x509_get_serial ( unsigned char **  p,
unsigned char *  end,
x509_buf serial 
) [static]
static int x509_get_sig ( unsigned char **  p,
unsigned char *  end,
x509_buf sig 
) [static]
static int x509_get_uid ( unsigned char **  p,
unsigned char *  end,
x509_buf uid,
int  n 
) [static]
static int x509_get_version ( unsigned char **  p,
unsigned char *  end,
int ver 
) [static]
static void x509_hash ( unsigned char *  in,
int  len,
int  alg,
unsigned char *  out 
) [static]

Definition at line 1481 of file x509parse.c.

References md2(), md4(), md5(), RSA_MD2, RSA_MD4, RSA_MD5, RSA_SHA1, and sha1().

Referenced by x509parse_verify().

int x509_self_test ( int  verbose  ) 

Checkup routine.

Returns:
0 if successful, or 1 if the test failed

Definition at line 1675 of file x509parse.c.

References rsa_free(), test_ca_crt, test_ca_key, test_ca_pwd, test_cli_crt, x509_free(), x509parse_crt(), x509parse_key(), and x509parse_verify().

Referenced by main().

char* x509parse_cert_info ( char *  prefix,
x509_cert crt 
)
int x509parse_crt ( x509_cert crt,
unsigned char *  buf,
int  buflen 
)
int x509parse_crtfile ( x509_cert crt,
char *  path 
)

Load one or more certificates and add them to the chained list.

Parameters:
chain points to the start of the chain
path filename to read the certificates from
Returns:
0 if successful, or a specific X509 error code

Definition at line 979 of file x509parse.c.

References buf, f, and x509parse_crt().

int x509parse_dn_gets ( char *  buf,
char *  end,
x509_name dn 
)

Store the certificate DN in printable form into buf; no more than (end - buf) characters will be written.

Definition at line 1316 of file x509parse.c.

References _x509_buf::len, _x509_name::next, _x509_name::oid, OID_PKCS9, OID_X520, _x509_buf::p, PKCS9_EMAIL, _x509_name::val, X520_COMMON_NAME, X520_COUNTRY, X520_LOCALITY, X520_ORG_UNIT, X520_ORGANIZATION, and X520_STATE.

Referenced by x509parse_cert_info().

int x509parse_expired ( x509_cert crt  ) 

Return 0 if the certificate is still valid, or BADCERT_EXPIRED.

Definition at line 1458 of file x509parse.c.

References BADCERT_EXPIRED, _x509_time::day, _x509_time::mon, _x509_cert::valid_to, and _x509_time::year.

Referenced by x509parse_verify().

int x509parse_key ( rsa_context rsa,
unsigned char *  buf,
int  buflen,
unsigned char *  pwd,
int  pwdlen 
)
int x509parse_keyfile ( rsa_context rsa,
char *  path,
char *  password 
)

Load and parse a private RSA key.

Parameters:
rsa RSA context to be initialized
path filename to read the private key from
pwd password to decrypt the file (can be NULL)
Returns:
0 if successful, or a specific X509 error code

Definition at line 1269 of file x509parse.c.

References buf, f, and x509parse_key().

int x509parse_verify ( x509_cert crt,
x509_cert trust_ca,
char *  cn,
int flags 
)

Verify the certificate signature.

Parameters:
crt a certificate to be verified
trust_ca the trusted CA chain
cn expected Common Name (can be set to NULL if the CN must not be verified)
flags result of the verification
Returns:
0 if successful or XYSSL_ERR_X509_SIG_VERIFY_FAILED, 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

Definition at line 1503 of file x509parse.c.

References BADCERT_CN_MISMATCH, BADCERT_NOT_TRUSTED, _x509_cert::ca_istrue, cur, _x509_cert::issuer_raw, _x509_buf::len, _x509_cert::max_pathlen, _x509_cert::next, _x509_name::next, _x509_name::oid, OID_CN, _x509_buf::p, _x509_cert::rsa, rsa_pkcs1_verify(), RSA_PUBLIC, _x509_cert::sig, _x509_cert::sig_oid1, _x509_cert::subject, _x509_cert::subject_raw, _x509_cert::tbs, _x509_name::val, _x509_cert::version, x509_hash(), x509parse_expired(), and XYSSL_ERR_X509_CERT_VERIFY_FAILED.

Referenced by ssl_parse_certificate(), and x509_self_test().

Generated on Tue Dec 28 15:15:29 2010 for Mobile-C by  doxygen 1.6.3