mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
POLARSSL_PEM_C split into POLARSSL_PEM_PARSE_C and POLARSSL_PEM_WRITE_C
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
|
||||
#include "polarssl/dhm.h"
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
@@ -397,7 +397,7 @@ int dhm_parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen
|
||||
int ret;
|
||||
size_t len;
|
||||
unsigned char *p, *end;
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
pem_context pem;
|
||||
|
||||
pem_init( &pem );
|
||||
@@ -456,7 +456,7 @@ int dhm_parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
pem_free( &pem );
|
||||
#endif
|
||||
if( ret != 0 )
|
||||
|
@@ -109,7 +109,7 @@
|
||||
#include "polarssl/pbkdf2.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
@@ -238,7 +238,7 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
|
||||
snprintf( buf, buflen, "MD - Opening or reading of file failed" );
|
||||
#endif /* POLARSSL_MD_C */
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
|
||||
if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
|
||||
snprintf( buf, buflen, "PEM - No PEM header or footer found" );
|
||||
if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
|
||||
@@ -257,7 +257,7 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
|
||||
snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
|
||||
if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
|
||||
snprintf( buf, buflen, "PEM - Bad input parameters to function" );
|
||||
#endif /* POLARSSL_PEM_C */
|
||||
#endif /* POLARSSL_PEM_PARSE_C || POLARSSL_PEM_WRITE_C */
|
||||
|
||||
#if defined(POLARSSL_PK_C)
|
||||
if( use_ret == -(POLARSSL_ERR_PK_MALLOC_FAILED) )
|
||||
|
@@ -25,8 +25,7 @@
|
||||
|
||||
#include "polarssl/config.h"
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
|
||||
#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
|
||||
#include "polarssl/pem.h"
|
||||
#include "polarssl/base64.h"
|
||||
#include "polarssl/des.h"
|
||||
@@ -43,6 +42,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
void pem_init( pem_context *ctx )
|
||||
{
|
||||
memset( ctx, 0, sizeof( pem_context ) );
|
||||
@@ -285,7 +285,7 @@ int pem_read_buffer( pem_context *ctx, const char *header, const char *footer,
|
||||
s1 += 32;
|
||||
}
|
||||
#endif /* POLARSSL_AES_C */
|
||||
|
||||
|
||||
if( enc_alg == POLARSSL_CIPHER_NONE )
|
||||
return( POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG );
|
||||
|
||||
@@ -312,7 +312,7 @@ int pem_read_buffer( pem_context *ctx, const char *header, const char *footer,
|
||||
polarssl_free( buf );
|
||||
return( POLARSSL_ERR_PEM_INVALID_DATA + ret );
|
||||
}
|
||||
|
||||
|
||||
if( enc != 0 )
|
||||
{
|
||||
#if defined(POLARSSL_MD5_C) && defined(POLARSSL_CIPHER_MODE_CBC) && \
|
||||
@@ -363,6 +363,19 @@ int pem_read_buffer( pem_context *ctx, const char *header, const char *footer,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
void pem_free( pem_context *ctx )
|
||||
{
|
||||
if( ctx->buf )
|
||||
polarssl_free( ctx->buf );
|
||||
|
||||
if( ctx->info )
|
||||
polarssl_free( ctx->info );
|
||||
|
||||
memset( ctx, 0, sizeof( pem_context ) );
|
||||
}
|
||||
#endif /* POLARSSL_PEM_PARSE_C */
|
||||
|
||||
#if defined(POLARSSL_PEM_WRITE_C)
|
||||
int pem_write_buffer( const char *header, const char *footer,
|
||||
const unsigned char *der_data, size_t der_len,
|
||||
unsigned char *buf, size_t buf_len, size_t *olen )
|
||||
@@ -412,16 +425,5 @@ int pem_write_buffer( const char *header, const char *footer,
|
||||
polarssl_free( encode_buf );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
void pem_free( pem_context *ctx )
|
||||
{
|
||||
if( ctx->buf )
|
||||
polarssl_free( ctx->buf );
|
||||
|
||||
if( ctx->info )
|
||||
polarssl_free( ctx->info );
|
||||
|
||||
memset( ctx, 0, sizeof( pem_context ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* POLARSSL_PEM_WRITE_C */
|
||||
#endif /* POLARSSL_PEM_PARSE_C || POLARSSL_PEM_WRITE_C */
|
||||
|
@@ -40,7 +40,7 @@
|
||||
#if defined(POLARSSL_ECDSA_C)
|
||||
#include "polarssl/ecdsa.h"
|
||||
#endif
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
#if defined(POLARSSL_PKCS5_C)
|
||||
@@ -754,7 +754,7 @@ int pk_parse_key( pk_context *pk,
|
||||
int ret;
|
||||
const pk_info_t *pk_info;
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
size_t len;
|
||||
pem_context pem;
|
||||
|
||||
@@ -855,7 +855,7 @@ int pk_parse_key( pk_context *pk,
|
||||
#else
|
||||
((void) pwd);
|
||||
((void) pwdlen);
|
||||
#endif /* POLARSSL_PEM_C */
|
||||
#endif /* POLARSSL_PEM_PARSE_C */
|
||||
|
||||
/*
|
||||
* At this point we only know it's not a PEM formatted key. Could be any
|
||||
@@ -919,7 +919,7 @@ int pk_parse_public_key( pk_context *ctx,
|
||||
{
|
||||
int ret;
|
||||
unsigned char *p;
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
size_t len;
|
||||
pem_context pem;
|
||||
|
||||
@@ -947,7 +947,7 @@ int pk_parse_public_key( pk_context *ctx,
|
||||
|
||||
ret = pk_parse_get_pubkey( &p, p + keylen, ctx );
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
pem_free( &pem );
|
||||
#endif
|
||||
|
||||
|
@@ -40,7 +40,7 @@
|
||||
#if defined(POLARSSL_ECDSA_C)
|
||||
#include "polarssl/ecdsa.h"
|
||||
#endif
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_WRITE_C)
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
@@ -276,7 +276,7 @@ int pk_write_key_der( pk_context *key, unsigned char *buf, size_t size )
|
||||
return( len );
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_WRITE_C)
|
||||
|
||||
#define PEM_BEGIN_PUBLIC_KEY "-----BEGIN PUBLIC KEY-----\n"
|
||||
#define PEM_END_PUBLIC_KEY "-----END PUBLIC KEY-----\n"
|
||||
@@ -345,6 +345,6 @@ int pk_write_key_pem( pk_context *key, unsigned char *buf, size_t size )
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* POLARSSL_PEM_C */
|
||||
#endif /* POLARSSL_PEM_WRITE_C */
|
||||
|
||||
#endif /* POLARSSL_PK_WRITE_C */
|
||||
|
@@ -41,8 +41,9 @@
|
||||
#include "polarssl/x509.h"
|
||||
#include "polarssl/asn1.h"
|
||||
#include "polarssl/oid.h"
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
#include "polarssl/pem.h"
|
||||
#include "polarssl/dhm.h"
|
||||
#endif
|
||||
#if defined(POLARSSL_PKCS5_C)
|
||||
#include "polarssl/pkcs5.h"
|
||||
#endif
|
||||
@@ -1344,7 +1345,7 @@ int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen )
|
||||
* Determine buffer content. Buffer contains either one DER certificate or
|
||||
* one or more PEM certificates.
|
||||
*/
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
if( strstr( (const char *) buf, "-----BEGIN CERTIFICATE-----" ) != NULL )
|
||||
buf_format = X509_FORMAT_PEM;
|
||||
#endif
|
||||
@@ -1352,7 +1353,7 @@ int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen )
|
||||
if( buf_format == X509_FORMAT_DER )
|
||||
return x509parse_crt_der( chain, buf, buflen );
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
if( buf_format == X509_FORMAT_PEM )
|
||||
{
|
||||
int ret;
|
||||
@@ -1438,7 +1439,7 @@ int x509parse_csr( x509_csr *csr, const unsigned char *buf, size_t buflen )
|
||||
int ret;
|
||||
size_t len;
|
||||
unsigned char *p, *end;
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
size_t use_len;
|
||||
pem_context pem;
|
||||
#endif
|
||||
@@ -1451,7 +1452,7 @@ int x509parse_csr( x509_csr *csr, const unsigned char *buf, size_t buflen )
|
||||
|
||||
memset( csr, 0, sizeof( x509_csr ) );
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
pem_init( &pem );
|
||||
ret = pem_read_buffer( &pem,
|
||||
"-----BEGIN CERTIFICATE REQUEST-----",
|
||||
@@ -1638,7 +1639,7 @@ int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen )
|
||||
size_t len;
|
||||
unsigned char *p, *end;
|
||||
x509_crl *crl;
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
size_t use_len;
|
||||
pem_context pem;
|
||||
#endif
|
||||
@@ -1671,7 +1672,7 @@ int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen )
|
||||
memset( crl, 0, sizeof( x509_crl ) );
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_PARSE_C)
|
||||
pem_init( &pem );
|
||||
ret = pem_read_buffer( &pem,
|
||||
"-----BEGIN X509 CRL-----",
|
||||
|
@@ -42,7 +42,7 @@
|
||||
|
||||
#include "polarssl/sha1.h"
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_WRITE_C)
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
@@ -816,7 +816,7 @@ int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size,
|
||||
#define PEM_BEGIN_CSR "-----BEGIN CERTIFICATE REQUEST-----\n"
|
||||
#define PEM_END_CSR "-----END CERTIFICATE REQUEST-----\n"
|
||||
|
||||
#if defined(POLARSSL_PEM_C)
|
||||
#if defined(POLARSSL_PEM_WRITE_C)
|
||||
int x509write_crt_pem( x509write_cert *crt, unsigned char *buf, size_t size,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng )
|
||||
|
Reference in New Issue
Block a user