summarylogtreecommitdiffstats
path: root/218c0da8.patch
blob: 085aa75d25d03265530eb27f8496d31ba9d1c44e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
From 218c0da8d9f675766b1de502a52e23a3aa52648e Mon Sep 17 00:00:00 2001
From: Juergen Repp <juergen_repp@web.de>
Date: Wed, 22 Mar 2023 10:54:59 +0100
Subject: [PATCH] FAPI: Skip test fapi-fix-provisioning-with template if no
 certificate is available.

If the configure option --enable-self-generated-certificate is not used this
test can't be executed because no certificate will be stored in NV ram. The
test will be skipped if no certificate is available.
Fixes: #2558

Signed-off-by: Juergen Repp <juergen_repp@web.de>
---
 .../fapi-provisioning-with-template.int.c     | 40 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/test/integration/fapi-provisioning-with-template.int.c b/test/integration/fapi-provisioning-with-template.int.c
index 54c724f5d..74184cdc8 100644
--- a/test/integration/fapi-provisioning-with-template.int.c
+++ b/test/integration/fapi-provisioning-with-template.int.c
@@ -4,6 +4,8 @@
 #endif
 
 #include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
 
 #include "tss2_esys.h"
 #include "tss2_fapi.h"
@@ -31,6 +33,39 @@
  * @retval EXIT_SKIP
  *
  */
+static bool
+fapi_ek_certless()
+{
+    FILE *stream = NULL;
+    long config_size;
+    char *config = NULL;
+    char *fapi_config_file = getenv("TSS2_FAPICONF");
+
+    stream = fopen(fapi_config_file, "r");
+    if (!stream) {
+        LOG_ERROR("File %s does not exist", fapi_config_file);
+        return NULL;
+    }
+    fseek(stream, 0L, SEEK_END);
+    config_size = ftell(stream);
+    fclose(stream);
+    config = malloc(config_size + 1);
+    stream = fopen(fapi_config_file, "r");
+    ssize_t ret = read(fileno(stream), config, config_size);
+    if (ret != config_size) {
+        LOG_ERROR("IO error %s.", fapi_config_file);
+        return NULL;
+    }
+    config[config_size] = '\0';
+    if (strstr(config, "\"ek_cert_less\": \"yes\"") == NULL) {
+        SAFE_FREE(config);
+        return false;
+    } else {
+        SAFE_FREE(config);
+        return true;
+    }
+}
+
 int
 test_fapi_provision_template(FAPI_CONTEXT *context)
 {
@@ -151,6 +186,9 @@ test_fapi_provision_template(FAPI_CONTEXT *context)
     TPM2B_AUTH auth = { .size = 0, .buffer = {} };
     TPM2B_MAX_NV_BUFFER nv_data;
 
+    if (fapi_ek_certless())
+        return EXIT_SKIP;
+
     if (strcmp(FAPI_PROFILE, "P_ECC") == 0) {
         nv_template_idx = ecc_nv_template_idx;
         nv_nonce_idx = ecc_nv_nonce_idx;
@@ -169,7 +207,7 @@ test_fapi_provision_template(FAPI_CONTEXT *context)
     r = Esys_Initialize(&esys_ctx, tcti, NULL);
     goto_if_error(r, "Error Esys_Initialize", error);
 
-     /*
+    /*
      * Store template (marshaled TPMT_PUBLIC) in NV ram.
      */
     r = Tss2_MU_TPMT_PUBLIC_Marshal(&in_public, &nv_data.buffer[0],