|
|
a23473 |
From 9ca735ab8f71a6b64f31867e55d43f3f5a51bfec Mon Sep 17 00:00:00 2001
|
|
|
a23473 |
From: Petr Gotthard <petr.gotthard@centrum.cz>
|
|
|
a23473 |
Date: Sun, 18 Jul 2021 11:54:50 +0200
|
|
|
a23473 |
Subject: FAPI Test: Change RSA_sign to EVP_PKEY_sign
|
|
|
a23473 |
MIME-Version: 1.0
|
|
|
a23473 |
Content-Type: text/plain; charset=UTF-8
|
|
|
a23473 |
Content-Transfer-Encoding: 8bit
|
|
|
a23473 |
|
|
|
a23473 |
The EVP_PKEY_sign functions are available since OpenSSL 1.0.0.
|
|
|
a23473 |
The RSA_sign function is deprecated in OpenSSL 3.0.0.
|
|
|
a23473 |
|
|
|
a23473 |
This PR should work with OpenSSL 1.0.0 through 3.0.0.
|
|
|
a23473 |
|
|
|
a23473 |
Signed-off-by: Petr Gotthard <petr.gotthard@centrum.cz>
|
|
|
a23473 |
---
|
|
|
a23473 |
test/integration/fapi-ext-public-key.int.c | 38 +++++++++++-----------
|
|
|
a23473 |
1 file changed, 19 insertions(+), 19 deletions(-)
|
|
|
a23473 |
|
|
|
a23473 |
diff --git a/test/integration/fapi-ext-public-key.int.c b/test/integration/fapi-ext-public-key.int.c
|
|
|
a23473 |
index 363c58b7..971d7897 100644
|
|
|
a23473 |
--- a/test/integration/fapi-ext-public-key.int.c
|
|
|
a23473 |
+++ b/test/integration/fapi-ext-public-key.int.c
|
|
|
a23473 |
@@ -49,7 +49,7 @@ test_fapi_ext_public_key(FAPI_CONTEXT *context)
|
|
|
a23473 |
BIO *bufio = NULL;
|
|
|
a23473 |
|
|
|
a23473 |
EVP_PKEY *evp_key = NULL;
|
|
|
a23473 |
- RSA *rsa_key = NULL;
|
|
|
a23473 |
+ EVP_PKEY_CTX *ctx = NULL;
|
|
|
a23473 |
|
|
|
a23473 |
/* Key will be used for non TPM signature verfication. */
|
|
|
a23473 |
char *pubkey_pem =
|
|
|
a23473 |
@@ -186,10 +186,8 @@ test_fapi_ext_public_key(FAPI_CONTEXT *context)
|
|
|
a23473 |
|
|
|
a23473 |
bufio = BIO_new_mem_buf((void *)priv_pem, strlen(priv_pem));
|
|
|
a23473 |
evp_key = PEM_read_bio_PrivateKey(bufio, NULL, NULL, NULL);
|
|
|
a23473 |
- rsa_key = EVP_PKEY_get1_RSA(evp_key);
|
|
|
a23473 |
|
|
|
a23473 |
-
|
|
|
a23473 |
- if (!bufio || !evp_key || !rsa_key) {
|
|
|
a23473 |
+ if (!bufio || !evp_key) {
|
|
|
a23473 |
LOG_ERROR("Generation of test key failed.");
|
|
|
a23473 |
goto error;
|
|
|
a23473 |
}
|
|
|
a23473 |
@@ -199,10 +197,20 @@ test_fapi_ext_public_key(FAPI_CONTEXT *context)
|
|
|
a23473 |
0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d
|
|
|
a23473 |
};
|
|
|
a23473 |
uint8_t signature[256];
|
|
|
a23473 |
- unsigned int signatureLength = 256;
|
|
|
a23473 |
+ size_t signatureLength = 256;
|
|
|
a23473 |
|
|
|
a23473 |
- if (!RSA_sign(NID_sha1, digest, 20, signature, &signatureLength, rsa_key)) {
|
|
|
a23473 |
- LOG_ERROR("Test RSA_sign failed.");
|
|
|
a23473 |
+ if ((ctx = EVP_PKEY_CTX_new(evp_key, NULL)) == NULL) {
|
|
|
a23473 |
+ LOG_ERROR("Test EVP_PKEY_CTX_new failed.");
|
|
|
a23473 |
+ goto error;
|
|
|
a23473 |
+ }
|
|
|
a23473 |
+ if (EVP_PKEY_sign_init(ctx) <= 0
|
|
|
a23473 |
+ || EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0
|
|
|
a23473 |
+ || EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha1()) <= 0) {
|
|
|
a23473 |
+ LOG_ERROR("Test EVP_PKEY_sign_init failed.");
|
|
|
a23473 |
+ goto error;
|
|
|
a23473 |
+ }
|
|
|
a23473 |
+ if (EVP_PKEY_sign(ctx, signature, &signatureLength, digest, 20) <= 0) {
|
|
|
a23473 |
+ LOG_ERROR("Test EVP_PKEY_sign failed.");
|
|
|
a23473 |
goto error;
|
|
|
a23473 |
}
|
|
|
a23473 |
|
|
|
a23473 |
@@ -243,12 +251,8 @@ test_fapi_ext_public_key(FAPI_CONTEXT *context)
|
|
|
a23473 |
if (bufio) {
|
|
|
a23473 |
BIO_free(bufio);
|
|
|
a23473 |
}
|
|
|
a23473 |
- if (evp_key) {
|
|
|
a23473 |
- EVP_PKEY_free(evp_key);
|
|
|
a23473 |
- }
|
|
|
a23473 |
- if (rsa_key) {
|
|
|
a23473 |
- RSA_free(rsa_key);
|
|
|
a23473 |
- }
|
|
|
a23473 |
+ EVP_PKEY_CTX_free(ctx);
|
|
|
a23473 |
+ EVP_PKEY_free(evp_key);
|
|
|
a23473 |
SAFE_FREE(path_list);
|
|
|
a23473 |
SAFE_FREE(cert2);
|
|
|
a23473 |
return EXIT_SUCCESS;
|
|
|
a23473 |
@@ -258,12 +262,8 @@ error:
|
|
|
a23473 |
if (bufio) {
|
|
|
a23473 |
BIO_free(bufio);
|
|
|
a23473 |
}
|
|
|
a23473 |
- if (evp_key) {
|
|
|
a23473 |
- EVP_PKEY_free(evp_key);
|
|
|
a23473 |
- }
|
|
|
a23473 |
- if (rsa_key) {
|
|
|
a23473 |
- RSA_free(rsa_key);
|
|
|
a23473 |
- }
|
|
|
a23473 |
+ EVP_PKEY_CTX_free(ctx);
|
|
|
a23473 |
+ EVP_PKEY_free(evp_key);
|
|
|
a23473 |
SAFE_FREE(path_list);
|
|
|
a23473 |
SAFE_FREE(cert2);
|
|
|
a23473 |
return EXIT_FAILURE;
|
|
|
a23473 |
--
|
|
|
a23473 |
2.26.3
|
|
|
a23473 |
|