57#if !defined(MBEDTLS_CONFIG_FILE)
60#include MBEDTLS_CONFIG_FILE
63#if defined(MBEDTLS_X509_CSR_PARSE_C)
71#if defined(MBEDTLS_PEM_PARSE_C)
75#if defined(MBEDTLS_PLATFORM_C)
80#define mbedtls_free free
81#define mbedtls_calloc calloc
82#define mbedtls_snprintf snprintf
85#if defined(MBEDTLS_FS_IO) || defined(EFIX64) || defined(EFI32)
92static int x509_csr_get_version(
unsigned char **
p,
93 const unsigned char *
end,
116 const unsigned char *
buf,
size_t buflen )
120 unsigned char *
p, *
end;
131 mbedtls_x509_csr_init( csr );
157 mbedtls_x509_csr_free( csr );
161 if(
len != (
size_t) (
end -
p ) )
163 mbedtls_x509_csr_free( csr );
176 mbedtls_x509_csr_free( csr );
186 if( (
ret = x509_csr_get_version( &
p,
end, &csr->
version ) ) != 0 )
188 mbedtls_x509_csr_free( csr );
194 mbedtls_x509_csr_free( csr );
208 mbedtls_x509_csr_free( csr );
214 mbedtls_x509_csr_free( csr );
225 mbedtls_x509_csr_free( csr );
242 mbedtls_x509_csr_free( csr );
256 mbedtls_x509_csr_free( csr );
264 mbedtls_x509_csr_free( csr );
270 mbedtls_x509_csr_free( csr );
276 mbedtls_x509_csr_free( csr );
287int mbedtls_x509_csr_parse(
mbedtls_x509_csr *csr,
const unsigned char *
buf,
size_t buflen )
289#if defined(MBEDTLS_PEM_PARSE_C)
292 mbedtls_pem_context pem;
301#if defined(MBEDTLS_PEM_PARSE_C)
303 if(
buf[buflen - 1] ==
'\0' )
305 mbedtls_pem_init( &pem );
306 ret = mbedtls_pem_read_buffer( &pem,
307 "-----BEGIN CERTIFICATE REQUEST-----",
308 "-----END CERTIFICATE REQUEST-----",
312 ret = mbedtls_pem_read_buffer( &pem,
313 "-----BEGIN NEW CERTIFICATE REQUEST-----",
314 "-----END NEW CERTIFICATE REQUEST-----",
323 ret = mbedtls_x509_csr_parse_der( csr, pem.buf, pem.buflen );
326 mbedtls_pem_free( &pem );
331 return( mbedtls_x509_csr_parse_der( csr,
buf, buflen ) );
334#if defined(MBEDTLS_FS_IO)
344 if( (
ret = mbedtls_pk_load_file(
path, &
buf, &
n ) ) != 0 )
347 ret = mbedtls_x509_csr_parse( csr,
buf,
n );
356#define BEFORE_COLON 14
361int mbedtls_x509_csr_info(
char *
buf,
size_t size,
const char *prefix,
367 char key_size_str[BEFORE_COLON];
398 return( (
int) (
size -
n ) );
422#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
427 while( name_cur !=
NULL )
430 name_cur = name_cur->
next;
GLenum GLuint GLenum GLsizei const GLchar * buf
struct mbedtls_asn1_named_data * next
#define MBEDTLS_ASN1_SEQUENCE
int mbedtls_asn1_get_int(unsigned char **p, const unsigned char *end, int *val)
Retrieve an integer ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
#define MBEDTLS_ASN1_CONTEXT_SPECIFIC
#define MBEDTLS_ASN1_CONSTRUCTED
#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH
int mbedtls_asn1_get_tag(unsigned char **p, const unsigned char *end, size_t *len, int tag)
Get the tag and length of the tag. Check for the requested tag. Updates the pointer to immediately be...
mbedtls_x509_name subject
int mbedtls_x509_get_name(unsigned char **p, const unsigned char *end, mbedtls_x509_name *cur)
#define MBEDTLS_ERR_X509_INVALID_FORMAT
#define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG
#define MBEDTLS_ERR_X509_INVALID_VERSION
int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
Store the certificate DN in printable form into buf; no more than size characters will be written.
#define MBEDTLS_X509_SAFE_SNPRINTF
int mbedtls_x509_get_sig_alg(const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params, mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg, void **sig_opts)
int mbedtls_x509_get_alg(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *alg, mbedtls_x509_buf *params)
#define MBEDTLS_ERR_X509_UNKNOWN_VERSION
int mbedtls_x509_key_size_helper(char *buf, size_t buf_size, const char *name)
int mbedtls_x509_sig_alg_gets(char *buf, size_t size, const mbedtls_x509_buf *sig_oid, mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg, const void *sig_opts)
#define MBEDTLS_ERR_X509_ALLOC_FAILED
int mbedtls_x509_get_sig(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig)
mbedtls_x509_buf subject_raw
#define MBEDTLS_ERR_X509_BAD_INPUT_DATA
#define memcpy(s1, s2, n)
Object Identifier (OID) database.
Privacy Enhanced Mail (PEM) decoding.
#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT
int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end, mbedtls_pk_context *pk)
Parse a SubjectPublicKeyInfo DER structure.
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
#define mbedtls_pk_get_bitlen
Configuration options (set of defines)
X.509 certificate signing request parsing and writing.