x509.c File Reference

#include "polarssl/config.h"
#include "polarssl/x509.h"
#include "polarssl/asn1.h"
#include "polarssl/oid.h"
#include "polarssl/pem.h"
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include "polarssl/x509_crt.h"
#include "polarssl/certs.h"
Include dependency graph for x509.c:

Go to the source code of this file.

Defines

#define polarssl_malloc   malloc
#define polarssl_free   free
#define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL   -2
#define SAFE_SNPRINTF()

Functions

int x509_get_serial (unsigned char **p, const unsigned char *end, x509_buf *serial)
int x509_get_alg_null (unsigned char **p, const unsigned char *end, x509_buf *alg)
static int x509_get_attr_type_value (unsigned char **p, const unsigned char *end, x509_name *cur)
int x509_get_name (unsigned char **p, const unsigned char *end, x509_name *cur)
int x509_get_time (unsigned char **p, const unsigned char *end, x509_time *time)
int x509_get_sig (unsigned char **p, const unsigned char *end, x509_buf *sig)
int x509_get_sig_alg (const x509_buf *sig_oid, md_type_t *md_alg, pk_type_t *pk_alg)
int x509_get_ext (unsigned char **p, const unsigned char *end, x509_buf *ext, int tag)
int x509_load_file (const char *path, unsigned char **buf, size_t *n)
int x509_dn_gets (char *buf, size_t size, const x509_name *dn)
 Store the certificate DN in printable form into buf; no more than size characters will be written.
int x509_serial_gets (char *buf, size_t size, const x509_buf *serial)
 Store the certificate serial in printable form into buf; no more than size characters will be written.
int x509_key_size_helper (char *buf, size_t size, const char *name)
const char * x509_oid_get_description (x509_buf *oid)
 Give an known OID, return its descriptive string.
int x509_oid_get_numeric_string (char *buf, size_t size, x509_buf *oid)
 Give an OID, return a string version of its OID number.
int x509_time_expired (const x509_time *to)
 Check a given x509_time against the system time and check if it is valid.
int x509_self_test (int verbose)
 Checkup routine.

Define Documentation

#define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL   -2

Definition at line 468 of file x509.c.

#define polarssl_free   free

Definition at line 52 of file x509.c.

#define polarssl_malloc   malloc

Definition at line 51 of file x509.c.

 
#define SAFE_SNPRINTF (  ) 
Value:
{                                               \
    if( ret == -1 )                             \
        return( -1 );                           \
                                                \
    if ( (unsigned int) ret > n ) {             \
        p[n - 1] = '\0';                        \
        return POLARSSL_ERR_DEBUG_BUF_TOO_SMALL;\
    }                                           \
                                                \
    n -= (unsigned int) ret;                    \
    p += (unsigned int) ret;                    \
}

Definition at line 470 of file x509.c.


Function Documentation

int x509_dn_gets ( char *  buf,
size_t  size,
const x509_name dn 
)

Store the certificate DN in printable form into buf; no more than size characters will be written.

Parameters:
buf Buffer to write to
size Maximum size of buffer
dn The X509 name to represent
Returns:
The amount of data written to the buffer, or -1 in case of an error.

Definition at line 488 of file x509.c.

References _asn1_buf::len, _asn1_named_data::next, _asn1_named_data::oid, oid_get_attr_short_name(), _asn1_buf::p, SAFE_SNPRINTF, and _asn1_named_data::val.

Referenced by test_suite_x509_dn_gets(), x509_crl_info(), x509_crt_info(), and x509_csr_info().

int x509_get_alg_null ( unsigned char **  p,
const unsigned char *  end,
x509_buf alg 
)
static int x509_get_attr_type_value ( unsigned char **  p,
const unsigned char *  end,
x509_name cur 
) [static]
int x509_get_ext ( unsigned char **  p,
const unsigned char *  end,
x509_buf ext,
int  tag 
)
int x509_get_name ( unsigned char **  p,
const unsigned char *  end,
x509_name cur 
)
int x509_get_serial ( unsigned char **  p,
const unsigned char *  end,
x509_buf serial 
)
int x509_get_sig ( unsigned char **  p,
const unsigned char *  end,
x509_buf sig 
)
int x509_get_sig_alg ( const x509_buf sig_oid,
md_type_t md_alg,
pk_type_t pk_alg 
)
int x509_get_time ( unsigned char **  p,
const unsigned char *  end,
x509_time time 
)
int x509_key_size_helper ( char *  buf,
size_t  size,
const char *  name 
)

Definition at line 582 of file x509.c.

References POLARSSL_ERR_DEBUG_BUF_TOO_SMALL, and SAFE_SNPRINTF.

Referenced by x509_crt_info(), and x509_csr_info().

int x509_load_file ( const char *  path,
unsigned char **  buf,
size_t *  n 
)
const char* x509_oid_get_description ( x509_buf oid  ) 

Give an known OID, return its descriptive string.

Parameters:
oid buffer containing the oid
Returns:
Return a string if the OID is known, or NULL otherwise.

Definition at line 600 of file x509.c.

References oid_get_extended_key_usage().

int x509_oid_get_numeric_string ( char *  buf,
size_t  size,
x509_buf oid 
)

Give an OID, return a string version of its OID number.

(Deprecated. Use oid_get_numeric_string() instead)

Parameters:
buf Buffer to write to
size Maximum size of buffer
oid Buffer containing the OID
Returns:
The amount of data written to the buffer, or -1 in case of an error.

Definition at line 614 of file x509.c.

References oid_get_numeric_string().

int x509_self_test ( int  verbose  ) 

Checkup routine.

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

Definition at line 705 of file x509.c.

References POLARSSL_ERR_X509_FEATURE_UNAVAILABLE, test_ca_crt, test_cli_crt, x509_crt_free(), x509_crt_init(), x509_crt_parse(), and x509_crt_verify().

Referenced by test_suite_x509_selftest().

int x509_serial_gets ( char *  buf,
size_t  size,
const x509_buf serial 
)

Store the certificate serial in printable form into buf; no more than size characters will be written.

Parameters:
buf Buffer to write to
size Maximum size of buffer
serial The X509 serial to represent
Returns:
The amount of data written to the buffer, or -1 in case of an error.

Definition at line 548 of file x509.c.

References _asn1_buf::len, _asn1_buf::p, and SAFE_SNPRINTF.

Referenced by x509_crl_info(), and x509_crt_info().

int x509_time_expired ( const x509_time time  ) 

Check a given x509_time against the system time and check if it is valid.

Parameters:
time x509_time to check
Returns:
Return 0 if the x509_time is still valid, or 1 otherwise.

Definition at line 623 of file x509.c.

References _x509_time::day, _x509_time::hour, _x509_time::min, _x509_time::mon, _x509_time::sec, and _x509_time::year.

Referenced by test_suite_x509_time_expired(), x509_crt_revoked(), x509_crt_verify_child(), x509_crt_verify_top(), and x509_crt_verifycrl().


Generated on 9 Apr 2014 for PolarSSL v1.3.2 by  doxygen 1.6.1