Commit cac31eed authored by Manuel Pégourié-Gonnard's avatar Manuel Pégourié-Gonnard
Browse files

Factor common code for printing sig_alg

parent cf975a38
......@@ -293,6 +293,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,
......
......@@ -815,6 +815,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
*/
......
......@@ -631,8 +631,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;
......@@ -688,35 +692,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();
......
......@@ -1258,8 +1258,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;
......@@ -1301,35 +1305,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 */
/* Key size */
if( ( ret = x509_key_size_helper( key_size_str, BEFORE_COLON,
pk_get_name( &crt->pk ) ) ) != 0 )
......
......@@ -366,8 +366,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;
......@@ -384,35 +388,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 )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment