Some SlackBuild scripts for Slackware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.0 KiB

  1. commit 6eb5a49a1f55325accb46b51e775857a3ea6ec57
  2. Author: William Roberts <william.c.roberts@intel.com>
  3. Date: Thu Mar 19 19:10:50 2020 -0500
  4. Esys_TestParams: silence expected errors
  5. The TestParams code is used to test paramters against the TPM to
  6. understand if a specific algorithm and scheme is supported. Thus,
  7. certain errors are expected. The expected errors are:
  8. 1. From any layer
  9. 2. Are Format 1 errors
  10. 3. Are P1 or Parameter 1 errors
  11. 4 are one of:
  12. - RC_CURVE
  13. - RC_VALUE
  14. - RC_ASSYMETRIC
  15. - RC_KEY_SIZE
  16. Fixes: #1573
  17. Signed-off-by: William Roberts <william.c.roberts@intel.com>
  18. diff --git a/src/tss2-esys/api/Esys_TestParms.c b/src/tss2-esys/api/Esys_TestParms.c
  19. index e64521e9..9b5bffa8 100644
  20. --- a/src/tss2-esys/api/Esys_TestParms.c
  21. +++ b/src/tss2-esys/api/Esys_TestParms.c
  22. @@ -92,9 +92,11 @@ Esys_TestParms(
  23. /* Restore the timeout value to the original value */
  24. esysContext->timeout = timeouttmp;
  25. - return_if_error(r, "Esys Finish");
  26. + if (!tss2_is_expected_error(r)) {
  27. + return_if_error(r, "Esys Finish");
  28. + }
  29. - return TSS2_RC_SUCCESS;
  30. + return r;
  31. }
  32. /** Asynchronous function for TPM2_TestParms
  33. @@ -266,7 +268,9 @@ Esys_TestParms_Finish(
  34. }
  35. /* The following is the "regular error" handling. */
  36. if (iesys_tpm_error(r)) {
  37. - LOG_WARNING("Received TPM Error");
  38. + if (!tss2_is_expected_error(r)) {
  39. + LOG_WARNING("Received TPM Error");
  40. + }
  41. esysContext->state = _ESYS_STATE_INIT;
  42. return r;
  43. } else if (r != TSS2_RC_SUCCESS) {
  44. diff --git a/src/util/aux_util.h b/src/util/aux_util.h
  45. index 3f9eb841..35deca87 100644
  46. --- a/src/util/aux_util.h
  47. +++ b/src/util/aux_util.h
  48. @@ -6,6 +6,9 @@
  49. #ifndef AUX_UTIL_H
  50. #define AUX_UTIL_H
  51. +#include <stdbool.h>
  52. +
  53. +#include "tss2_tpm2_types.h"
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. @@ -84,6 +87,45 @@ extern "C" {
  58. r_max = r; \
  59. }
  60. +static inline TSS2_RC
  61. +tss2_fmt_p1_error_to_rc(UINT16 err)
  62. +{
  63. + return TPM2_RC_1+TPM2_RC_P+err;
  64. +}
  65. +
  66. +static inline bool
  67. +tss2_is_expected_error(TSS2_RC rc)
  68. +{
  69. + /* Success is always expected */
  70. + if (rc == TSS2_RC_SUCCESS) {
  71. + return true;
  72. + }
  73. +
  74. + /*
  75. + * drop the layer, any part of the TSS stack can gripe about this error
  76. + * if it wants too.
  77. + */
  78. + rc &= ~TSS2_RC_LAYER_MASK;
  79. +
  80. + /*
  81. + * Format 1, parameter 1 errors plus the below RC's
  82. + * contain everything we care about:
  83. + * - TPM2_RC_CURVE
  84. + * - TPM2_RC_HASH
  85. + * - TPM2_RC_ASYMMETRIC
  86. + * - TPM2_RC_KEY_SIZE
  87. + */
  88. + if (rc == tss2_fmt_p1_error_to_rc(TPM2_RC_CURVE)
  89. + || rc == tss2_fmt_p1_error_to_rc(TPM2_RC_VALUE)
  90. + || rc == tss2_fmt_p1_error_to_rc(TPM2_RC_HASH)
  91. + || rc == tss2_fmt_p1_error_to_rc(TPM2_RC_ASYMMETRIC)
  92. + || rc == tss2_fmt_p1_error_to_rc(TPM2_RC_KEY_SIZE)) {
  93. + return true;
  94. + }
  95. +
  96. + return false;
  97. +}
  98. +
  99. #ifdef __cplusplus
  100. } /* extern "C" */
  101. #endif