Factor common code for printing sig_alg
This commit is contained in:
parent
5cac583482
commit
27b93ade6e
5 changed files with 66 additions and 84 deletions
|
@ -271,6 +271,8 @@ int x509_get_serial( unsigned char **p, const unsigned char *end,
|
|||
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_sig_alg_gets( char *buf, size_t size, const x509_buf *sig_oid,
|
||||
pk_type_t pk_alg, const x509_buf *sig_params );
|
||||
int x509_key_size_helper( char *buf, size_t size, const char *name );
|
||||
int x509_string_to_names( asn1_named_data **head, const char *name );
|
||||
int x509_set_extension( asn1_named_data **head, const char *oid, size_t oid_len, int critical, const unsigned char *val, size_t val_len );
|
||||
|
|
|
@ -810,6 +810,52 @@ int x509_serial_gets( char *buf, size_t size, const x509_buf *serial )
|
|||
return( (int) ( size - n ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper for writing signature alrogithms
|
||||
*/
|
||||
int x509_sig_alg_gets( char *buf, size_t size, const x509_buf *sig_oid,
|
||||
pk_type_t pk_alg, const x509_buf *sig_params )
|
||||
{
|
||||
int ret;
|
||||
char *p = buf;
|
||||
size_t n = size;
|
||||
const char *desc = NULL;
|
||||
|
||||
ret = oid_get_sig_alg_desc( sig_oid, &desc );
|
||||
if( ret != 0 )
|
||||
ret = snprintf( p, n, "???" );
|
||||
else
|
||||
ret = snprintf( p, n, "%s", desc );
|
||||
SAFE_SNPRINTF();
|
||||
|
||||
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
|
||||
if( pk_alg == POLARSSL_PK_RSASSA_PSS )
|
||||
{
|
||||
md_type_t md_alg, mgf_md;
|
||||
const md_info_t *md_info, *mgf_md_info;
|
||||
int salt_len, trailer_field;
|
||||
|
||||
if( ( ret = x509_get_rsassa_pss_params( sig_params,
|
||||
&md_alg, &mgf_md, &salt_len, &trailer_field ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
md_info = md_info_from_type( md_alg );
|
||||
mgf_md_info = md_info_from_type( mgf_md );
|
||||
|
||||
ret = snprintf( p, n, " (%s, MGF1-%s, 0x%02X, %d)",
|
||||
md_info ? md_info->name : "???",
|
||||
mgf_md_info ? mgf_md_info->name : "???",
|
||||
salt_len, trailer_field );
|
||||
SAFE_SNPRINTF();
|
||||
}
|
||||
#else
|
||||
((void) pk_alg);
|
||||
((void) sig_params);
|
||||
#endif /* POLARSSL_RSASSA_PSS_CERTIFICATES */
|
||||
|
||||
return( (int) size - n );
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper for writing "RSA key size", "EC key size", etc
|
||||
*/
|
||||
|
|
|
@ -625,8 +625,12 @@ int x509_crl_info( char *buf, size_t size, const char *prefix,
|
|||
int ret;
|
||||
size_t n;
|
||||
char *p;
|
||||
const char *desc;
|
||||
const x509_crl_entry *entry;
|
||||
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
|
||||
const x509_buf *sig_params = &crl->sig_params;
|
||||
#else
|
||||
const x509_buf *sig_params = NULL;
|
||||
#endif
|
||||
|
||||
p = buf;
|
||||
n = size;
|
||||
|
@ -682,35 +686,9 @@ int x509_crl_info( char *buf, size_t size, const char *prefix,
|
|||
ret = snprintf( p, n, "\n%ssigned using : ", prefix );
|
||||
SAFE_SNPRINTF();
|
||||
|
||||
ret = oid_get_sig_alg_desc( &crl->sig_oid1, &desc );
|
||||
if( ret != 0 )
|
||||
ret = snprintf( p, n, "???" );
|
||||
else
|
||||
ret = snprintf( p, n, "%s", desc );
|
||||
ret = x509_sig_alg_gets( p, n, &crl->sig_oid1, crl->sig_pk, sig_params );
|
||||
SAFE_SNPRINTF();
|
||||
|
||||
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
|
||||
if( crl->sig_pk == POLARSSL_PK_RSASSA_PSS )
|
||||
{
|
||||
md_type_t md_alg, mgf_md;
|
||||
const md_info_t *md_info, *mgf_md_info;
|
||||
int salt_len, trailer_field;
|
||||
|
||||
if( ( ret = x509_get_rsassa_pss_params( &crl->sig_params,
|
||||
&md_alg, &mgf_md, &salt_len, &trailer_field ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
md_info = md_info_from_type( md_alg );
|
||||
mgf_md_info = md_info_from_type( mgf_md );
|
||||
|
||||
ret = snprintf( p, n, " (%s, MGF1-%s, 0x%02X, %d)",
|
||||
md_info ? md_info->name : "???",
|
||||
mgf_md_info ? mgf_md_info->name : "???",
|
||||
salt_len, trailer_field );
|
||||
SAFE_SNPRINTF();
|
||||
}
|
||||
#endif /* POLARSSL_RSASSA_PSS_CERTIFICATES */
|
||||
|
||||
ret = snprintf( p, n, "\n" );
|
||||
SAFE_SNPRINTF();
|
||||
|
||||
|
|
|
@ -1124,8 +1124,12 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
|
|||
int ret;
|
||||
size_t n;
|
||||
char *p;
|
||||
const char *desc = NULL;
|
||||
char key_size_str[BEFORE_COLON];
|
||||
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
|
||||
const x509_buf *sig_params = &crt->sig_params;
|
||||
#else
|
||||
const x509_buf *sig_params = NULL;
|
||||
#endif
|
||||
|
||||
p = buf;
|
||||
n = size;
|
||||
|
@ -1167,35 +1171,9 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
|
|||
ret = snprintf( p, n, "\n%ssigned using : ", prefix );
|
||||
SAFE_SNPRINTF();
|
||||
|
||||
ret = oid_get_sig_alg_desc( &crt->sig_oid1, &desc );
|
||||
if( ret != 0 )
|
||||
ret = snprintf( p, n, "???" );
|
||||
else
|
||||
ret = snprintf( p, n, "%s", desc );
|
||||
ret = x509_sig_alg_gets( p, n, &crt->sig_oid1, crt->sig_pk, sig_params );
|
||||
SAFE_SNPRINTF();
|
||||
|
||||
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
|
||||
if( crt->sig_pk == POLARSSL_PK_RSASSA_PSS )
|
||||
{
|
||||
md_type_t md_alg, mgf_md;
|
||||
const md_info_t *md_info, *mgf_md_info;
|
||||
int salt_len, trailer_field;
|
||||
|
||||
if( ( ret = x509_get_rsassa_pss_params( &crt->sig_params,
|
||||
&md_alg, &mgf_md, &salt_len, &trailer_field ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
md_info = md_info_from_type( md_alg );
|
||||
mgf_md_info = md_info_from_type( mgf_md );
|
||||
|
||||
ret = snprintf( p, n, " (%s, MGF1-%s, 0x%02X, %d)",
|
||||
md_info ? md_info->name : "???",
|
||||
mgf_md_info ? mgf_md_info->name : "???",
|
||||
salt_len, trailer_field );
|
||||
SAFE_SNPRINTF();
|
||||
}
|
||||
#endif /* POLARSSL_RSASSA_PSS_CERTIFICATES */
|
||||
|
||||
if( ( ret = x509_key_size_helper( key_size_str, BEFORE_COLON,
|
||||
pk_get_name( &crt->pk ) ) ) != 0 )
|
||||
{
|
||||
|
|
|
@ -362,8 +362,12 @@ int x509_csr_info( char *buf, size_t size, const char *prefix,
|
|||
int ret;
|
||||
size_t n;
|
||||
char *p;
|
||||
const char *desc;
|
||||
char key_size_str[BEFORE_COLON];
|
||||
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
|
||||
const x509_buf *sig_params = &csr->sig_params;
|
||||
#else
|
||||
const x509_buf *sig_params = NULL;
|
||||
#endif
|
||||
|
||||
p = buf;
|
||||
n = size;
|
||||
|
@ -380,35 +384,9 @@ int x509_csr_info( char *buf, size_t size, const char *prefix,
|
|||
ret = snprintf( p, n, "\n%ssigned using : ", prefix );
|
||||
SAFE_SNPRINTF();
|
||||
|
||||
ret = oid_get_sig_alg_desc( &csr->sig_oid, &desc );
|
||||
if( ret != 0 )
|
||||
ret = snprintf( p, n, "???" );
|
||||
else
|
||||
ret = snprintf( p, n, "%s", desc );
|
||||
ret = x509_sig_alg_gets( p, n, &csr->sig_oid, csr->sig_pk, sig_params );
|
||||
SAFE_SNPRINTF();
|
||||
|
||||
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
|
||||
if( csr->sig_pk == POLARSSL_PK_RSASSA_PSS )
|
||||
{
|
||||
md_type_t md_alg, mgf_md;
|
||||
const md_info_t *md_info, *mgf_md_info;
|
||||
int salt_len, trailer_field;
|
||||
|
||||
if( ( ret = x509_get_rsassa_pss_params( &csr->sig_params,
|
||||
&md_alg, &mgf_md, &salt_len, &trailer_field ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
md_info = md_info_from_type( md_alg );
|
||||
mgf_md_info = md_info_from_type( mgf_md );
|
||||
|
||||
ret = snprintf( p, n, " (%s, MGF1-%s, 0x%02X, %d)",
|
||||
md_info ? md_info->name : "???",
|
||||
mgf_md_info ? mgf_md_info->name : "???",
|
||||
salt_len, trailer_field );
|
||||
SAFE_SNPRINTF();
|
||||
}
|
||||
#endif /* POLARSSL_RSASSA_PSS_CERTIFICATES */
|
||||
|
||||
if( ( ret = x509_key_size_helper( key_size_str, BEFORE_COLON,
|
||||
pk_get_name( &csr->pk ) ) ) != 0 )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue