39 #if defined(POLARSSL_X509_CSR_PARSE_C)
43 #if defined(POLARSSL_PEM_PARSE_C)
47 #if defined(POLARSSL_MEMORY_C)
50 #define polarssl_malloc malloc
51 #define polarssl_free free
57 #if defined(POLARSSL_FS_IO) || defined(EFIX64) || defined(EFI32)
64 static int x509_csr_get_version(
unsigned char **p,
65 const unsigned char *end,
91 unsigned char *p, *end;
92 #if defined(POLARSSL_PEM_PARSE_C)
100 if( csr == NULL || buf == NULL )
105 #if defined(POLARSSL_PEM_PARSE_C)
107 ret = pem_read_buffer( &pem,
108 "-----BEGIN CERTIFICATE REQUEST-----",
109 "-----END CERTIFICATE REQUEST-----",
110 buf, NULL, 0, &use_len );
144 memcpy( p, buf, buflen );
167 if( len != (
size_t) ( end - p ) )
192 if( ( ret = x509_csr_get_version( &p, end, &csr->
version ) ) != 0 )
283 #if defined(POLARSSL_FS_IO)
298 memset( buf, 0, n + 1 );
305 #if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
309 #if !defined vsnprintf
310 #define vsnprintf _vsnprintf
320 static int compat_snprintf(
char *str,
size_t size,
const char *format, ...)
325 va_start( ap, format );
327 res = vsnprintf( str, size, format, ap );
333 return( (
int) size + 20 );
338 #define snprintf compat_snprintf
341 #define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL -2
343 #define SAFE_SNPRINTF() \
348 if ( (unsigned int) ret > n ) { \
350 return POLARSSL_ERR_DEBUG_BUF_TOO_SMALL;\
353 n -= (unsigned int) ret; \
354 p += (unsigned int) ret; \
357 #define BEFORE_COLON 14
362 int x509_csr_info(
char *buf,
size_t size,
const char *prefix,
369 char key_size_str[BEFORE_COLON];
374 ret = snprintf( p, n,
"%sCSR version : %d",
378 ret = snprintf( p, n,
"\n%ssubject name : ", prefix );
383 ret = snprintf( p, n,
"\n%ssigned using : ", prefix );
388 ret = snprintf( p, n,
"???" );
390 ret = snprintf( p, n,
"%s", desc );
399 ret = snprintf( p, n,
"\n%s%-" BC
"s: %d bits\n", prefix, key_size_str,
403 return( (
int) ( size - n ) );
428 while( name_cur != NULL )
431 name_cur = name_cur->
next;
432 memset( name_prv, 0,
sizeof(
x509_name ) );
436 if( csr->
raw.
p != NULL )
442 memset( csr, 0,
sizeof(
x509_csr ) );
void *(* polarssl_malloc)(size_t len)
int x509_get_name(unsigned char **p, const unsigned char *end, x509_name *cur)
#define POLARSSL_ERR_ASN1_LENGTH_MISMATCH
Actual length differs from expected length.
size_t pk_get_size(const pk_context *ctx)
Get the size in bits of the underlying key.
#define POLARSSL_ERR_X509_INVALID_FORMAT
The CRT/CRL/CSR format is invalid, e.g.
int x509_key_size_helper(char *buf, size_t size, const char *name)
int asn1_get_int(unsigned char **p, const unsigned char *end, int *val)
Retrieve an integer ASN.1 tag and its value.
int x509_get_alg_null(unsigned char **p, const unsigned char *end, x509_buf *alg)
Configuration options (set of defines)
#define POLARSSL_ERR_X509_UNKNOWN_SIG_ALG
Signature algorithm (oid) is unsupported.
int x509_get_sig(unsigned char **p, const unsigned char *end, x509_buf *sig)
const char * pk_get_name(const pk_context *ctx)
Access the type name.
#define POLARSSL_ERR_X509_UNKNOWN_VERSION
CRT/CRL/CSR has an unsupported version number.
x509_name subject
The parsed subject data (named information object).
Object Identifier (OID) database.
x509_buf cri
The raw CertificateRequestInfo body (DER).
Privacy Enhanced Mail (PEM) decoding.
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...
void(* polarssl_free)(void *ptr)
unsigned char * p
ASN1 data, e.g.
int oid_get_sig_alg_desc(const asn1_buf *oid, const char **desc)
Translate SignatureAlgorithm OID into description.
X.509 certificate signing request parsing and writing.
void x509_csr_free(x509_csr *csr)
Unallocate all CSR data.
int x509_get_sig_alg(const x509_buf *sig_oid, md_type_t *md_alg, pk_type_t *pk_alg)
int pk_parse_subpubkey(unsigned char **p, const unsigned char *end, pk_context *pk)
Parse a SubjectPublicKeyInfo DER structure.
int x509_load_file(const char *path, unsigned char **buf, size_t *n)
#define ASN1_CONTEXT_SPECIFIC
pk_type_t sig_pk
< Internal representation of the Public Key algorithm of the signature algorithm, e...
pk_context pk
Container for the public key context.
int x509_csr_parse(x509_csr *csr, const unsigned char *buf, size_t buflen)
Load a Certificate Signing Request (CSR)
Container for a sequence or list of 'named' ASN.1 data items.
size_t len
ASN1 length, e.g.
x509_buf raw
The raw CSR data (DER).
void pk_free(pk_context *ctx)
Free a pk_context.
int asn1_get_tag(unsigned char **p, const unsigned char *end, size_t *len, int tag)
Get the tag and length of the tag.
#define POLARSSL_ERR_X509_INVALID_VERSION
The CRT/CRL/CSR version element is invalid.
int x509_csr_info(char *buf, size_t size, const char *prefix, const x509_csr *csr)
Returns an informational string about the CSR.
struct _asn1_named_data * next
The next entry in the sequence.
Certificate Signing Request (CSR) structure.
#define POLARSSL_ERR_X509_BAD_INPUT_DATA
Input invalid.
int x509_csr_parse_file(x509_csr *csr, const char *path)
Load a Certificate Signing Request (CSR)
#define POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT
No PEM header or footer found.
md_type_t sig_md
Internal representation of the MD algorithm of the signature algorithm, e.g.
#define POLARSSL_ERR_X509_MALLOC_FAILED
Allocation of memory failed.
void x509_csr_init(x509_csr *csr)
Initialize a CSR.
#define POLARSSL_ERR_ASN1_UNEXPECTED_TAG
ASN1 tag was of an unexpected value.
x509_buf subject_raw
The raw subject data (DER).