Skip to content

Commit a37336b

Browse files
committed
pkey: fix compilation with OpenSSL 4.1
Avoid deprecated OpenSSL functions, add fallback defines for older versions: src/tpm2-provider-pkey.c:91:5: error: 'ASN1_STRING_set' is deprecated: Since OpenSSL 4.1; use ASN1_STRING_set1_data() or ASN1_STRING_set1_string() [-Werror,-Wdeprecated-declarations] src/tpm2-provider-pkey.c:165:41: error: 'ASN1_STRING_length' is deprecated: Since OpenSSL 4.1; use ASN1_STRING_get_length() [-Werror,-Wdeprecated-declarations] Add missing header: src/tpm2-provider-pkey.c:32:1: error: call to undeclared function 'ERR_raise'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] Signed-off-by: Moritz Buhl <moritz.buhl@infineon.com>
1 parent f03f7b3 commit a37336b

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

‎src/tpm2-provider-pkey.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22

33
#include <string.h>
44

5+
#include <openssl/err.h>
6+
#include <openssl/opensslv.h>
57
#include <openssl/pem.h>
68
#include <openssl/rand.h>
79

810
#include <tss2/tss2_mu.h>
911

1012
#include "tpm2-provider-pkey.h"
1113

14+
#if OPENSSL_VERSION_NUMBER >= 0x40100000
15+
#define TPM2_ASN1_STRING_get_length(x) ASN1_STRING_get_length(x)
16+
#define TPM2_ASN1_STRING_set1_data(s, d, l) ASN1_STRING_set1_data(s, d, l)
17+
#else
18+
#define TPM2_ASN1_STRING_get_length(x) ASN1_STRING_length(x)
19+
#define TPM2_ASN1_STRING_set1_data(s, d, l) ASN1_STRING_set(s, d, l)
20+
#endif
21+
1222
typedef struct {
1323
ASN1_OBJECT *type;
1424
ASN1_BOOLEAN emptyAuth;
@@ -88,8 +98,8 @@ tpm2_keydata_write(const TPM2_KEYDATA *keydata, BIO *bout, TPM2_PKEY_FORMAT form
8898
BN_set_word(bn_parent, TPM2_RH_OWNER);
8999

90100
BN_to_ASN1_INTEGER(bn_parent, tpk->parent);
91-
ASN1_STRING_set(tpk->privkey, &privbuf[0], privbuf_len);
92-
ASN1_STRING_set(tpk->pubkey, &pubbuf[0], pubbuf_len);
101+
TPM2_ASN1_STRING_set1_data(tpk->privkey, &privbuf[0], privbuf_len);
102+
TPM2_ASN1_STRING_set1_data(tpk->pubkey, &pubbuf[0], pubbuf_len);
93103

94104
switch (format) {
95105
case KEY_FORMAT_PEM:
@@ -162,13 +172,13 @@ tpm2_keydata_read(BIO *bin, TPM2_KEYDATA *keydata, TPM2_PKEY_FORMAT format)
162172
goto error;
163173

164174
if (Tss2_MU_TPM2B_PRIVATE_Unmarshal(ASN1_STRING_get0_data(tpk->privkey),
165-
ASN1_STRING_length(tpk->privkey), NULL,
166-
&keydata->priv))
175+
TPM2_ASN1_STRING_get_length(tpk->privkey),
176+
NULL, &keydata->priv))
167177
goto error;
168178

169179
if (Tss2_MU_TPM2B_PUBLIC_Unmarshal(ASN1_STRING_get0_data(tpk->pubkey),
170-
ASN1_STRING_length(tpk->pubkey), NULL,
171-
&keydata->pub))
180+
TPM2_ASN1_STRING_get_length(tpk->pubkey),
181+
NULL, &keydata->pub))
172182
goto error;
173183

174184
res = 1;

0 commit comments

Comments
 (0)