mirror of
https://github.com/polhenarejos/pico-openpgp.git
synced 2026-08-22 20:47:32 +01:00
Validate algorithm attributes before key creation
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -141,6 +141,9 @@ int cmd_import_data(void) {
|
||||
if (algo_len == 0 || algo_len > OPENPGP_MAX_ALGORITHM_ATTR_SIZE) {
|
||||
return SW_WRONG_DATA();
|
||||
}
|
||||
if (!openpgp_algorithm_attr_supported(algo, algo_len)) {
|
||||
return SW_WRONG_DATA();
|
||||
}
|
||||
int r = 0;
|
||||
if (algo[0] == ALGO_RSA) {
|
||||
if (algo_len < 3) {
|
||||
|
||||
@@ -60,6 +60,9 @@ int cmd_keypair_gen(void) {
|
||||
if (algo_len == 0 || algo_len > OPENPGP_MAX_ALGORITHM_ATTR_SIZE) {
|
||||
return SW_WRONG_DATA();
|
||||
}
|
||||
if (!openpgp_algorithm_attr_supported(algo, algo_len)) {
|
||||
return SW_WRONG_DATA();
|
||||
}
|
||||
if (P1(apdu) == 0x80) { //generate
|
||||
if (algo[0] == ALGO_RSA) {
|
||||
if (algo_len < 3) {
|
||||
|
||||
@@ -1441,6 +1441,24 @@ mbedtls_ecp_group_id get_ec_group_id_from_attr(const uint8_t *algo, size_t algo_
|
||||
return MBEDTLS_ECP_DP_NONE;
|
||||
}
|
||||
|
||||
bool openpgp_algorithm_attr_supported(const uint8_t *algo, size_t algo_len) {
|
||||
if (!algo || algo_len < 2 || algo_len > OPENPGP_MAX_ALGORITHM_ATTR_SIZE) {
|
||||
return false;
|
||||
}
|
||||
if (algo[0] == ALGO_RSA) {
|
||||
uint16_t modulus_bits;
|
||||
if (algo_len != 6 || algo[3] != 0 || algo[4] != 0x20 || algo[5] != 0) {
|
||||
return false;
|
||||
}
|
||||
modulus_bits = ((uint16_t)algo[1] << 8) | algo[2];
|
||||
return modulus_bits == 1024 || modulus_bits == 2048 || modulus_bits == 3072 || modulus_bits == 4096;
|
||||
}
|
||||
if (algo[0] == ALGO_ECDH || algo[0] == ALGO_ECDSA || algo[0] == ALGO_EDDSA) {
|
||||
return get_ec_group_id_from_attr(algo + 1, algo_len - 1) != MBEDTLS_ECP_DP_NONE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void make_rsa_response(mbedtls_rsa_context *rsa) {
|
||||
memcpy(res_APDU, "\x7f\x49\x82\x00\x00", 5);
|
||||
res_APDU_size = 5;
|
||||
|
||||
@@ -76,6 +76,7 @@ extern int openpgp_adminless_disable(void);
|
||||
extern int openpgp_adminless_reset(void);
|
||||
#endif
|
||||
extern mbedtls_ecp_group_id get_ec_group_id_from_attr(const uint8_t *algo, size_t algo_len);
|
||||
extern bool openpgp_algorithm_attr_supported(const uint8_t *algo, size_t algo_len);
|
||||
extern int reset_sig_count(void);
|
||||
extern uint16_t algo_dec, algo_aut, pk_dec, pk_aut;
|
||||
extern bool wait_button_pressed_fid(uint16_t fid);
|
||||
|
||||
Reference in New Issue
Block a user