fapi-check-wrong-paths.int.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /*******************************************************************************
  3. * Copyright 2017-2018, Fraunhofer SIT sponsored by Infineon Technologies AG
  4. * All rights reserved.
  5. *******************************************************************************/
  6. #ifdef HAVE_CONFIG_H
  7. #include <config.h>
  8. #endif
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <errno.h>
  12. #include <unistd.h>
  13. #include <errno.h>
  14. #include <string.h>
  15. #include <json-c/json.h>
  16. #include <json-c/json_util.h>
  17. #include <json-c/json_tokener.h>
  18. #include "tss2_fapi.h"
  19. #include "test-fapi.h"
  20. #define LOGMODULE test
  21. #include "util/log.h"
  22. #include "util/aux_util.h"
  23. #define EVENT_SIZE 10
  24. /** Test the wrong paths for object creation functions.
  25. *
  26. * Tested FAPI commands:
  27. * - Fapi_Provision()
  28. * - Fapi_CreateKey()
  29. * - Fapi_Delete()
  30. *
  31. * @param[in,out] context The FAPI_CONTEXT.
  32. * @retval EXIT_FAILURE
  33. * @retval EXIT_SUCCESS
  34. */
  35. int
  36. test_fapi_wrong_path(FAPI_CONTEXT *context)
  37. {
  38. TSS2_RC r;
  39. r = Fapi_Provision(context, NULL, NULL, NULL);
  40. goto_if_error(r, "Error Fapi_Provision", error);
  41. r = Fapi_CreateKey(context, "myKey", "sign,noDa", "", NULL);
  42. if (r == TSS2_RC_SUCCESS) {
  43. LOG_ERROR( "Wrong key path not detected");
  44. goto error;
  45. }
  46. if (r != TSS2_FAPI_RC_BAD_PATH) {
  47. goto_if_error(r, "Wrong return code", error);
  48. }
  49. r = Fapi_CreateKey(context, "/HE/SRK/myKey", "sign,noDa", "", NULL);
  50. if (r == TSS2_RC_SUCCESS) {
  51. LOG_ERROR( "Wrong key path not detected");
  52. goto error;
  53. }
  54. if (r != TSS2_FAPI_RC_BAD_PATH) {
  55. goto_if_error(r, "Wrong return code", error);
  56. }
  57. r = Fapi_CreateKey(context, "/HS/EK/Key", "sign,noDa", "", NULL);
  58. if (r == TSS2_RC_SUCCESS) {
  59. LOG_ERROR( "Wrong key path not detected");
  60. goto error;
  61. }
  62. if (r != TSS2_FAPI_RC_BAD_PATH) {
  63. goto_if_error(r, "Error Fapi_CreateKey", error);
  64. }
  65. r = Fapi_CreateNv(context, "myNv", "noda", 10, "", "");
  66. if (r == TSS2_RC_SUCCESS) {
  67. LOG_ERROR( "Wrong key path not detected");
  68. goto error;
  69. }
  70. if (r != TSS2_FAPI_RC_BAD_PATH) {
  71. goto_if_error(r, "Error Fapi_CreateNv", error);
  72. }
  73. r = Fapi_CreateNv(context, "/nv/../Owner/myNv", "noda,0xff", 10, "", "");
  74. if (r == TSS2_RC_SUCCESS) {
  75. goto_if_error(r, "Bad character in path was not detected.", error);
  76. }
  77. if (r != TSS2_FAPI_RC_BAD_PATH) {
  78. goto_if_error(r, "Wrong return code for bad characters in path.", error);
  79. }
  80. r = Fapi_CreateKey(context, "/HS/../EK/Key", "sign,noDa", "", NULL);
  81. if (r == TSS2_RC_SUCCESS) {
  82. goto_if_error(r, "Bad character in path was not detected.", error);
  83. }
  84. if (r != TSS2_FAPI_RC_BAD_PATH) {
  85. goto_if_error(r, "Wrong return code for bad characters in path.", error);
  86. }
  87. r = Fapi_Delete(context, "/HS/../EK/Key");
  88. if (r == TSS2_RC_SUCCESS) {
  89. goto_if_error(r, "Bad character in path was not detected.", error);
  90. }
  91. if (r != TSS2_FAPI_RC_BAD_PATH) {
  92. goto_if_error(r, "Wrong return code for bad characters in path.", error);
  93. }
  94. Fapi_Delete(context, "/");
  95. return EXIT_SUCCESS;
  96. error:
  97. Fapi_Delete(context, "/");
  98. return EXIT_FAILURE;
  99. }
  100. int
  101. test_invoke_fapi(FAPI_CONTEXT *fapi_context)
  102. {
  103. return test_fapi_wrong_path(fapi_context);
  104. }