switch (err) {
case ERR_PACK(ERR_LIB_RSA, RSA_F_PKEY_RSA_CTRL, RSA_R_INVALID_KEYBITS):
case ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED):
+ case ERR_PACK(ERR_LIB_PEM, PEM_F_PEM_READ_BIO, PEM_R_NO_START_LINE):
+ case ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG):
ret = YACA_ERROR_INVALID_PARAMETER;
break;
- case ERR_PACK(ERR_LIB_PEM, PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT):
case ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT):
+ case ERR_PACK(ERR_LIB_PEM, PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT):
ret = YACA_ERROR_INVALID_PASSWORD;
break;
}
return ret;
}
-bool check_import_wrong_pass()
-{
- unsigned long err = ERR_peek_error();
- unsigned long err_bad_password_1 = ERR_PACK(ERR_LIB_PEM, PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT);
- unsigned long err_bad_password_2 = ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT);
-
- if (err == err_bad_password_1 || err == err_bad_password_2)
- return true;
-
- return false;
-}
-
int import_evp(yaca_key_h *key,
yaca_key_type_e key_type,
const char *password,
if (pkey == NULL && !wrong_pass) {
BIO_reset(src);
pkey = PEM_read_bio_PrivateKey(src, NULL, cb, (void*)password);
- if (check_import_wrong_pass())
+ if (ERROR_HANDLE() == YACA_ERROR_INVALID_PASSWORD)
wrong_pass = true;
private = true;
- ERROR_CLEAR();
}
if (pkey == NULL && !wrong_pass) {
BIO_reset(src);
pkey = PEM_read_bio_PUBKEY(src, NULL, cb, (void*)password);
- if (check_import_wrong_pass())
+ if (ERROR_HANDLE() == YACA_ERROR_INVALID_PASSWORD)
wrong_pass = true;
private = false;
- ERROR_CLEAR();
}
if (pkey == NULL && !wrong_pass) {
BIO_reset(src);
X509 *x509 = PEM_read_bio_X509(src, NULL, cb, (void*)password);
- if (check_import_wrong_pass())
+ if (ERROR_HANDLE() == YACA_ERROR_INVALID_PASSWORD)
wrong_pass = true;
if (x509 != NULL)
pkey = X509_get_pubkey(x509);
X509_free(x509);
private = false;
- ERROR_CLEAR();
}
}
/* Possible DER */
if (pkey == NULL && !wrong_pass) {
BIO_reset(src);
pkey = d2i_PKCS8PrivateKey_bio(src, NULL, cb, (void*)password);
- if (check_import_wrong_pass())
+ if (ERROR_HANDLE() == YACA_ERROR_INVALID_PASSWORD)
wrong_pass = true;
private = true;
- ERROR_CLEAR();
}
if (pkey == NULL && !wrong_pass) {
BIO_reset(src);
pkey = d2i_PrivateKey_bio(src, NULL);
- private = true;
ERROR_CLEAR();
+ private = true;
}
if (pkey == NULL && !wrong_pass) {
BIO_reset(src);
pkey = d2i_PUBKEY_bio(src, NULL);
- private = false;
ERROR_CLEAR();
+ private = false;
}
}