mirror of
https://git.code.sf.net/p/linux-ima/ima-evm-utils
synced 2025-06-30 21:02:33 +02:00
Add support for passing the private key password to sign_hash()
evmctl defines the "--pass | -p" command line option for providing the private key's password. The password is then stored in a global variable accessible by the sign_hash_XXXX() functions. This patch modifies the arguments to the library sign_hash() function to include the password, allowing callers to specify the private key password. Changelog: - add library init to call OpenSSL_add_all_algorithms Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
This commit is contained in:

committed by
Dmitry Kasatkin

parent
17f49a1881
commit
6a712b3b38
@ -53,6 +53,7 @@
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "imaevm.h"
|
||||
|
||||
@ -130,6 +131,8 @@ struct libevm_params params = {
|
||||
.hash_algo = "sha1",
|
||||
};
|
||||
|
||||
static void __attribute__ ((constructor)) libinit(void);
|
||||
|
||||
void do_dump(FILE *fp, const void *ptr, int len, bool cr)
|
||||
{
|
||||
int i;
|
||||
@ -618,9 +621,14 @@ static RSA *read_priv_key(const char *keyfile, char *keypass)
|
||||
log_err("Failed to open keyfile: %s\n", keyfile);
|
||||
return NULL;
|
||||
}
|
||||
ERR_load_crypto_strings();
|
||||
key = PEM_read_RSAPrivateKey(fp, NULL, NULL, keypass);
|
||||
if (!key)
|
||||
log_err("PEM_read_RSAPrivateKey() failed\n");
|
||||
if (!key) {
|
||||
char str[256];
|
||||
|
||||
ERR_error_string(ERR_get_error(), str);
|
||||
log_err("PEM_read_RSAPrivateKey() failed: %s\n", str);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return key;
|
||||
@ -786,8 +794,18 @@ out:
|
||||
return len;
|
||||
}
|
||||
|
||||
int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const char *keyfile, unsigned char *sig)
|
||||
|
||||
int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const char *keyfile, char *keypass, unsigned char *sig)
|
||||
{
|
||||
if (keypass)
|
||||
params.keypass = keypass;
|
||||
|
||||
return params.x509 ? sign_hash_v2(hashalgo, hash, size, keyfile, sig) :
|
||||
sign_hash_v1(hashalgo, hash, size, keyfile, sig);
|
||||
}
|
||||
|
||||
static void libinit()
|
||||
{
|
||||
OpenSSL_add_all_algorithms();
|
||||
ERR_load_crypto_strings();
|
||||
}
|
||||
|
Reference in New Issue
Block a user