#include <openssl/provider.h>
#include <openssl/evperr.h>
#include <openssl/ecerr.h>
+#include <openssl/pkcs12err.h>
#include <openssl/x509err.h>
#include <openssl/trace.h>
#include "internal/passphrase.h"
BIO *bio = data->bio;
long loc;
size_t i;
- int err, ok = 0;
+ int err, lib, reason, ok = 0;
/* For recursions */
struct decoder_process_data_st new_data;
const char *data_type = NULL;
* errors, so we preserve them in the error queue and stop.
*/
err = ERR_peek_last_error();
- if ((ERR_GET_LIB(err) == ERR_LIB_EVP
- && ERR_GET_REASON(err) == EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM)
+ lib = ERR_GET_LIB(err);
+ reason = ERR_GET_REASON(err);
+ if ((lib == ERR_LIB_EVP
+ && reason == EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM)
#ifndef OPENSSL_NO_EC
- || (ERR_GET_LIB(err) == ERR_LIB_EC
- && ERR_GET_REASON(err) == EC_R_UNKNOWN_GROUP)
+ || (lib == ERR_LIB_EC && reason == EC_R_UNKNOWN_GROUP)
#endif
- || (ERR_GET_LIB(err) == ERR_LIB_X509
- && ERR_GET_REASON(err) == X509_R_UNSUPPORTED_ALGORITHM))
+ || (lib == ERR_LIB_X509 && reason == X509_R_UNSUPPORTED_ALGORITHM)
+ || (lib == ERR_LIB_PKCS12
+ && reason == PKCS12_R_PKCS12_CIPHERFINAL_ERROR))
goto end;
}
if (!EVP_CipherFinal_ex(ctx, out + i, &i)) {
OPENSSL_free(out);
out = NULL;
- ERR_raise(ERR_LIB_PKCS12, PKCS12_R_PKCS12_CIPHERFINAL_ERROR);
+ ERR_raise_data(ERR_LIB_PKCS12, PKCS12_R_PKCS12_CIPHERFINAL_ERROR,
+ passlen == 0 ? "empty password"
+ : "maybe wrong password");
goto err;
}
outlen += i;
}
pass = tpass;
if (!PKCS12_verify_mac(p12, pass, strlen(pass))) {
- ERR_raise(ERR_LIB_OSSL_STORE,
- OSSL_STORE_R_ERROR_VERIFYING_PKCS12_MAC);
+ ERR_raise_data(ERR_LIB_OSSL_STORE,
+ OSSL_STORE_R_ERROR_VERIFYING_PKCS12_MAC,
+ strlen(pass) == 0 ? "empty password" :
+ "maybe wrong password");
goto p12_end;
}
}
EVP_PKEY *pkey = NULL;
void *key = NULL;
int orig_selection = selection;
+ int dec_err;
int ok = 0;
/*
der = new_der;
der_len = new_der_len;
}
- RESET_ERR_MARK();
+ /* decryption errors are fatal and should be reported */
+ dec_err = ERR_peek_last_error();
+ if (ERR_GET_LIB(dec_err) == ERR_LIB_PROV
+ && ERR_GET_REASON(dec_err) == PROV_R_BAD_DECRYPT)
+ goto end;
+ RESET_ERR_MARK();
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
derp = der;
pkey = evp_privatekey_from_binary(ctx->desc->evp_type, NULL,