Restructured pk_parse_key_pkcs8_encrypted_der() to prevent unreachable code

This commit is contained in:
Paul Bakker 2014-04-17 17:19:56 +02:00
parent 03b6a46353
commit f4cf80b86f

View File

@ -921,7 +921,7 @@ static int pk_parse_key_pkcs8_encrypted_der(
const unsigned char *key, size_t keylen, const unsigned char *key, size_t keylen,
const unsigned char *pwd, size_t pwdlen ) const unsigned char *pwd, size_t pwdlen )
{ {
int ret; int ret, decrypted = 0;
size_t len; size_t len;
unsigned char buf[2048]; unsigned char buf[2048];
unsigned char *p, *end; unsigned char *p, *end;
@ -985,6 +985,8 @@ static int pk_parse_key_pkcs8_encrypted_der(
return( ret ); return( ret );
} }
decrypted = 1;
} }
else if( OID_CMP( OID_PKCS12_PBE_SHA1_RC4_128, &pbe_alg_oid ) ) else if( OID_CMP( OID_PKCS12_PBE_SHA1_RC4_128, &pbe_alg_oid ) )
{ {
@ -1001,6 +1003,8 @@ static int pk_parse_key_pkcs8_encrypted_der(
// //
if( *buf != ( ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) if( *buf != ( ASN1_CONSTRUCTED | ASN1_SEQUENCE ) )
return( POLARSSL_ERR_PK_PASSWORD_MISMATCH ); return( POLARSSL_ERR_PK_PASSWORD_MISMATCH );
decrypted = 1;
} }
else else
#endif /* POLARSSL_PKCS12_C */ #endif /* POLARSSL_PKCS12_C */
@ -1015,14 +1019,18 @@ static int pk_parse_key_pkcs8_encrypted_der(
return( ret ); return( ret );
} }
decrypted = 1;
} }
else else
#endif /* POLARSSL_PKCS5_C */ #endif /* POLARSSL_PKCS5_C */
{ {
((void) pwd); ((void) pwd);
return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE );
} }
if( decrypted == 0 )
return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE );
return( pk_parse_key_pkcs8_unencrypted_der( pk, buf, len ) ); return( pk_parse_key_pkcs8_unencrypted_der( pk, buf, len ) );
} }