qemu_plat_attest_token.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2024, Linaro Limited and Contributors. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <errno.h>
  8. #include <string.h>
  9. #include <plat/common/platform.h>
  10. /*
  11. * This is the CBOR serialization of the CCA platform token described at
  12. * https://git.trustedfirmware.org/TF-M/tf-m-tools/+/refs/heads/main/iat-verifier/tests/data/cca_example_platform_token.yaml
  13. */
  14. static const uint8_t sample_platform_token[] = {
  15. 0xd2, 0x84, 0x44, 0xa1, 0x01, 0x38, 0x22, 0xa0,
  16. 0x59, 0x05, 0x81, 0xa9, 0x19, 0x01, 0x09, 0x78,
  17. 0x23, 0x74, 0x61, 0x67, 0x3a, 0x61, 0x72, 0x6d,
  18. 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x32, 0x30, 0x32,
  19. 0x33, 0x3a, 0x63, 0x63, 0x61, 0x5f, 0x70, 0x6c,
  20. 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x23, 0x31,
  21. 0x2e, 0x30, 0x2e, 0x30, 0x0a, 0x58, 0x20, 0x0d,
  22. 0x22, 0xe0, 0x8a, 0x98, 0x46, 0x90, 0x58, 0x48,
  23. 0x63, 0x18, 0x28, 0x34, 0x89, 0xbd, 0xb3, 0x6f,
  24. 0x09, 0xdb, 0xef, 0xeb, 0x18, 0x64, 0xdf, 0x43,
  25. 0x3f, 0xa6, 0xe5, 0x4e, 0xa2, 0xd7, 0x11, 0x19,
  26. 0x09, 0x5c, 0x58, 0x20, 0x7f, 0x45, 0x4c, 0x46,
  27. 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  28. 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x3e, 0x00,
  29. 0x01, 0x00, 0x00, 0x00, 0x50, 0x58, 0x00, 0x00,
  30. 0x00, 0x00, 0x00, 0x00, 0x19, 0x01, 0x00, 0x58,
  31. 0x21, 0x01, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02,
  32. 0x01, 0x00, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a,
  33. 0x09, 0x08, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12,
  34. 0x11, 0x10, 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a,
  35. 0x19, 0x18, 0x19, 0x09, 0x61, 0x44, 0xcf, 0xcf,
  36. 0xcf, 0xcf, 0x19, 0x09, 0x5b, 0x19, 0x30, 0x03,
  37. 0x19, 0x09, 0x62, 0x67, 0x73, 0x68, 0x61, 0x2d,
  38. 0x32, 0x35, 0x36, 0x19, 0x09, 0x60, 0x78, 0x3a,
  39. 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,
  40. 0x76, 0x65, 0x72, 0x61, 0x69, 0x73, 0x6f, 0x6e,
  41. 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
  42. 0x2f, 0x2e, 0x77, 0x65, 0x6c, 0x6c, 0x2d, 0x6b,
  43. 0x6e, 0x6f, 0x77, 0x6e, 0x2f, 0x76, 0x65, 0x72,
  44. 0x61, 0x69, 0x73, 0x6f, 0x6e, 0x2f, 0x76, 0x65,
  45. 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
  46. 0x6f, 0x6e, 0x19, 0x09, 0x5f, 0x8d, 0xa4, 0x01,
  47. 0x69, 0x52, 0x53, 0x45, 0x5f, 0x42, 0x4c, 0x31,
  48. 0x5f, 0x32, 0x05, 0x58, 0x20, 0x53, 0x78, 0x79,
  49. 0x63, 0x07, 0x53, 0x5d, 0xf3, 0xec, 0x8d, 0x8b,
  50. 0x15, 0xa2, 0xe2, 0xdc, 0x56, 0x41, 0x41, 0x9c,
  51. 0x3d, 0x30, 0x60, 0xcf, 0xe3, 0x22, 0x38, 0xc0,
  52. 0xfa, 0x97, 0x3f, 0x7a, 0xa3, 0x02, 0x58, 0x20,
  53. 0x9a, 0x27, 0x1f, 0x2a, 0x91, 0x6b, 0x0b, 0x6e,
  54. 0xe6, 0xce, 0xcb, 0x24, 0x26, 0xf0, 0xb3, 0x20,
  55. 0x6e, 0xf0, 0x74, 0x57, 0x8b, 0xe5, 0x5d, 0x9b,
  56. 0xc9, 0x4f, 0x6f, 0x3f, 0xe3, 0xab, 0x86, 0xaa,
  57. 0x06, 0x67, 0x73, 0x68, 0x61, 0x2d, 0x32, 0x35,
  58. 0x36, 0xa4, 0x01, 0x67, 0x52, 0x53, 0x45, 0x5f,
  59. 0x42, 0x4c, 0x32, 0x05, 0x58, 0x20, 0x53, 0x78,
  60. 0x79, 0x63, 0x07, 0x53, 0x5d, 0xf3, 0xec, 0x8d,
  61. 0x8b, 0x15, 0xa2, 0xe2, 0xdc, 0x56, 0x41, 0x41,
  62. 0x9c, 0x3d, 0x30, 0x60, 0xcf, 0xe3, 0x22, 0x38,
  63. 0xc0, 0xfa, 0x97, 0x3f, 0x7a, 0xa3, 0x02, 0x58,
  64. 0x20, 0x53, 0xc2, 0x34, 0xe5, 0xe8, 0x47, 0x2b,
  65. 0x6a, 0xc5, 0x1c, 0x1a, 0xe1, 0xca, 0xb3, 0xfe,
  66. 0x06, 0xfa, 0xd0, 0x53, 0xbe, 0xb8, 0xeb, 0xfd,
  67. 0x89, 0x77, 0xb0, 0x10, 0x65, 0x5b, 0xfd, 0xd3,
  68. 0xc3, 0x06, 0x67, 0x73, 0x68, 0x61, 0x2d, 0x32,
  69. 0x35, 0x36, 0xa4, 0x01, 0x65, 0x52, 0x53, 0x45,
  70. 0x5f, 0x53, 0x05, 0x58, 0x20, 0x53, 0x78, 0x79,
  71. 0x63, 0x07, 0x53, 0x5d, 0xf3, 0xec, 0x8d, 0x8b,
  72. 0x15, 0xa2, 0xe2, 0xdc, 0x56, 0x41, 0x41, 0x9c,
  73. 0x3d, 0x30, 0x60, 0xcf, 0xe3, 0x22, 0x38, 0xc0,
  74. 0xfa, 0x97, 0x3f, 0x7a, 0xa3, 0x02, 0x58, 0x20,
  75. 0x11, 0x21, 0xcf, 0xcc, 0xd5, 0x91, 0x3f, 0x0a,
  76. 0x63, 0xfe, 0xc4, 0x0a, 0x6f, 0xfd, 0x44, 0xea,
  77. 0x64, 0xf9, 0xdc, 0x13, 0x5c, 0x66, 0x63, 0x4b,
  78. 0xa0, 0x01, 0xd1, 0x0b, 0xcf, 0x43, 0x02, 0xa2,
  79. 0x06, 0x67, 0x73, 0x68, 0x61, 0x2d, 0x32, 0x35,
  80. 0x36, 0xa4, 0x01, 0x66, 0x41, 0x50, 0x5f, 0x42,
  81. 0x4c, 0x31, 0x05, 0x58, 0x20, 0x53, 0x78, 0x79,
  82. 0x63, 0x07, 0x53, 0x5d, 0xf3, 0xec, 0x8d, 0x8b,
  83. 0x15, 0xa2, 0xe2, 0xdc, 0x56, 0x41, 0x41, 0x9c,
  84. 0x3d, 0x30, 0x60, 0xcf, 0xe3, 0x22, 0x38, 0xc0,
  85. 0xfa, 0x97, 0x3f, 0x7a, 0xa3, 0x02, 0x58, 0x20,
  86. 0x15, 0x71, 0xb5, 0xec, 0x78, 0xbd, 0x68, 0x51,
  87. 0x2b, 0xf7, 0x83, 0x0b, 0xb6, 0xa2, 0xa4, 0x4b,
  88. 0x20, 0x47, 0xc7, 0xdf, 0x57, 0xbc, 0xe7, 0x9e,
  89. 0xb8, 0xa1, 0xc0, 0xe5, 0xbe, 0xa0, 0xa5, 0x01,
  90. 0x06, 0x67, 0x73, 0x68, 0x61, 0x2d, 0x32, 0x35,
  91. 0x36, 0xa4, 0x01, 0x66, 0x41, 0x50, 0x5f, 0x42,
  92. 0x4c, 0x32, 0x05, 0x58, 0x20, 0x53, 0x78, 0x79,
  93. 0x63, 0x07, 0x53, 0x5d, 0xf3, 0xec, 0x8d, 0x8b,
  94. 0x15, 0xa2, 0xe2, 0xdc, 0x56, 0x41, 0x41, 0x9c,
  95. 0x3d, 0x30, 0x60, 0xcf, 0xe3, 0x22, 0x38, 0xc0,
  96. 0xfa, 0x97, 0x3f, 0x7a, 0xa3, 0x02, 0x58, 0x20,
  97. 0x10, 0x15, 0x9b, 0xaf, 0x26, 0x2b, 0x43, 0xa9,
  98. 0x2d, 0x95, 0xdb, 0x59, 0xda, 0xe1, 0xf7, 0x2c,
  99. 0x64, 0x51, 0x27, 0x30, 0x16, 0x61, 0xe0, 0xa3,
  100. 0xce, 0x4e, 0x38, 0xb2, 0x95, 0xa9, 0x7c, 0x58,
  101. 0x06, 0x67, 0x73, 0x68, 0x61, 0x2d, 0x32, 0x35,
  102. 0x36, 0xa4, 0x01, 0x67, 0x53, 0x43, 0x50, 0x5f,
  103. 0x42, 0x4c, 0x31, 0x05, 0x58, 0x20, 0x53, 0x78,
  104. 0x79, 0x63, 0x07, 0x53, 0x5d, 0xf3, 0xec, 0x8d,
  105. 0x8b, 0x15, 0xa2, 0xe2, 0xdc, 0x56, 0x41, 0x41,
  106. 0x9c, 0x3d, 0x30, 0x60, 0xcf, 0xe3, 0x22, 0x38,
  107. 0xc0, 0xfa, 0x97, 0x3f, 0x7a, 0xa3, 0x02, 0x58,
  108. 0x20, 0x10, 0x12, 0x2e, 0x85, 0x6b, 0x3f, 0xcd,
  109. 0x49, 0xf0, 0x63, 0x63, 0x63, 0x17, 0x47, 0x61,
  110. 0x49, 0xcb, 0x73, 0x0a, 0x1a, 0xa1, 0xcf, 0xaa,
  111. 0xd8, 0x18, 0x55, 0x2b, 0x72, 0xf5, 0x6d, 0x6f,
  112. 0x68, 0x06, 0x67, 0x73, 0x68, 0x61, 0x2d, 0x32,
  113. 0x35, 0x36, 0xa4, 0x01, 0x67, 0x53, 0x43, 0x50,
  114. 0x5f, 0x42, 0x4c, 0x32, 0x05, 0x58, 0x20, 0xf1,
  115. 0x4b, 0x49, 0x87, 0x90, 0x4b, 0xcb, 0x58, 0x14,
  116. 0xe4, 0x45, 0x9a, 0x05, 0x7e, 0xd4, 0xd2, 0x0f,
  117. 0x58, 0xa6, 0x33, 0x15, 0x22, 0x88, 0xa7, 0x61,
  118. 0x21, 0x4d, 0xcd, 0x28, 0x78, 0x0b, 0x56, 0x02,
  119. 0x58, 0x20, 0xaa, 0x67, 0xa1, 0x69, 0xb0, 0xbb,
  120. 0xa2, 0x17, 0xaa, 0x0a, 0xa8, 0x8a, 0x65, 0x34,
  121. 0x69, 0x20, 0xc8, 0x4c, 0x42, 0x44, 0x7c, 0x36,
  122. 0xba, 0x5f, 0x7e, 0xa6, 0x5f, 0x42, 0x2c, 0x1f,
  123. 0xe5, 0xd8, 0x06, 0x67, 0x73, 0x68, 0x61, 0x2d,
  124. 0x32, 0x35, 0x36, 0xa4, 0x01, 0x67, 0x41, 0x50,
  125. 0x5f, 0x42, 0x4c, 0x33, 0x31, 0x05, 0x58, 0x20,
  126. 0x53, 0x78, 0x79, 0x63, 0x07, 0x53, 0x5d, 0xf3,
  127. 0xec, 0x8d, 0x8b, 0x15, 0xa2, 0xe2, 0xdc, 0x56,
  128. 0x41, 0x41, 0x9c, 0x3d, 0x30, 0x60, 0xcf, 0xe3,
  129. 0x22, 0x38, 0xc0, 0xfa, 0x97, 0x3f, 0x7a, 0xa3,
  130. 0x02, 0x58, 0x20, 0x2e, 0x6d, 0x31, 0xa5, 0x98,
  131. 0x3a, 0x91, 0x25, 0x1b, 0xfa, 0xe5, 0xae, 0xfa,
  132. 0x1c, 0x0a, 0x19, 0xd8, 0xba, 0x3c, 0xf6, 0x01,
  133. 0xd0, 0xe8, 0xa7, 0x06, 0xb4, 0xcf, 0xa9, 0x66,
  134. 0x1a, 0x6b, 0x8a, 0x06, 0x67, 0x73, 0x68, 0x61,
  135. 0x2d, 0x32, 0x35, 0x36, 0xa4, 0x01, 0x63, 0x52,
  136. 0x4d, 0x4d, 0x05, 0x58, 0x20, 0x53, 0x78, 0x79,
  137. 0x63, 0x07, 0x53, 0x5d, 0xf3, 0xec, 0x8d, 0x8b,
  138. 0x15, 0xa2, 0xe2, 0xdc, 0x56, 0x41, 0x41, 0x9c,
  139. 0x3d, 0x30, 0x60, 0xcf, 0xe3, 0x22, 0x38, 0xc0,
  140. 0xfa, 0x97, 0x3f, 0x7a, 0xa3, 0x02, 0x58, 0x20,
  141. 0xa1, 0xfb, 0x50, 0xe6, 0xc8, 0x6f, 0xae, 0x16,
  142. 0x79, 0xef, 0x33, 0x51, 0x29, 0x6f, 0xd6, 0x71,
  143. 0x34, 0x11, 0xa0, 0x8c, 0xf8, 0xdd, 0x17, 0x90,
  144. 0xa4, 0xfd, 0x05, 0xfa, 0xe8, 0x68, 0x81, 0x64,
  145. 0x06, 0x67, 0x73, 0x68, 0x61, 0x2d, 0x32, 0x35,
  146. 0x36, 0xa4, 0x01, 0x69, 0x48, 0x57, 0x5f, 0x43,
  147. 0x4f, 0x4e, 0x46, 0x49, 0x47, 0x05, 0x58, 0x20,
  148. 0x53, 0x78, 0x79, 0x63, 0x07, 0x53, 0x5d, 0xf3,
  149. 0xec, 0x8d, 0x8b, 0x15, 0xa2, 0xe2, 0xdc, 0x56,
  150. 0x41, 0x41, 0x9c, 0x3d, 0x30, 0x60, 0xcf, 0xe3,
  151. 0x22, 0x38, 0xc0, 0xfa, 0x97, 0x3f, 0x7a, 0xa3,
  152. 0x02, 0x58, 0x20, 0x1a, 0x25, 0x24, 0x02, 0x97,
  153. 0x2f, 0x60, 0x57, 0xfa, 0x53, 0xcc, 0x17, 0x2b,
  154. 0x52, 0xb9, 0xff, 0xca, 0x69, 0x8e, 0x18, 0x31,
  155. 0x1f, 0xac, 0xd0, 0xf3, 0xb0, 0x6e, 0xca, 0xae,
  156. 0xf7, 0x9e, 0x17, 0x06, 0x67, 0x73, 0x68, 0x61,
  157. 0x2d, 0x32, 0x35, 0x36, 0xa4, 0x01, 0x69, 0x46,
  158. 0x57, 0x5f, 0x43, 0x4f, 0x4e, 0x46, 0x49, 0x47,
  159. 0x05, 0x58, 0x20, 0x53, 0x78, 0x79, 0x63, 0x07,
  160. 0x53, 0x5d, 0xf3, 0xec, 0x8d, 0x8b, 0x15, 0xa2,
  161. 0xe2, 0xdc, 0x56, 0x41, 0x41, 0x9c, 0x3d, 0x30,
  162. 0x60, 0xcf, 0xe3, 0x22, 0x38, 0xc0, 0xfa, 0x97,
  163. 0x3f, 0x7a, 0xa3, 0x02, 0x58, 0x20, 0x9a, 0x92,
  164. 0xad, 0xbc, 0x0c, 0xee, 0x38, 0xef, 0x65, 0x8c,
  165. 0x71, 0xce, 0x1b, 0x1b, 0xf8, 0xc6, 0x56, 0x68,
  166. 0xf1, 0x66, 0xbf, 0xb2, 0x13, 0x64, 0x4c, 0x89,
  167. 0x5c, 0xcb, 0x1a, 0xd0, 0x7a, 0x25, 0x06, 0x67,
  168. 0x73, 0x68, 0x61, 0x2d, 0x32, 0x35, 0x36, 0xa4,
  169. 0x01, 0x6c, 0x54, 0x42, 0x5f, 0x46, 0x57, 0x5f,
  170. 0x43, 0x4f, 0x4e, 0x46, 0x49, 0x47, 0x05, 0x58,
  171. 0x20, 0x53, 0x78, 0x79, 0x63, 0x07, 0x53, 0x5d,
  172. 0xf3, 0xec, 0x8d, 0x8b, 0x15, 0xa2, 0xe2, 0xdc,
  173. 0x56, 0x41, 0x41, 0x9c, 0x3d, 0x30, 0x60, 0xcf,
  174. 0xe3, 0x22, 0x38, 0xc0, 0xfa, 0x97, 0x3f, 0x7a,
  175. 0xa3, 0x02, 0x58, 0x20, 0x23, 0x89, 0x03, 0x18,
  176. 0x0c, 0xc1, 0x04, 0xec, 0x2c, 0x5d, 0x8b, 0x3f,
  177. 0x20, 0xc5, 0xbc, 0x61, 0xb3, 0x89, 0xec, 0x0a,
  178. 0x96, 0x7d, 0xf8, 0xcc, 0x20, 0x8c, 0xdc, 0x7c,
  179. 0xd4, 0x54, 0x17, 0x4f, 0x06, 0x67, 0x73, 0x68,
  180. 0x61, 0x2d, 0x32, 0x35, 0x36, 0xa4, 0x01, 0x6d,
  181. 0x53, 0x4f, 0x43, 0x5f, 0x46, 0x57, 0x5f, 0x43,
  182. 0x4f, 0x4e, 0x46, 0x49, 0x47, 0x05, 0x58, 0x20,
  183. 0x53, 0x78, 0x79, 0x63, 0x07, 0x53, 0x5d, 0xf3,
  184. 0xec, 0x8d, 0x8b, 0x15, 0xa2, 0xe2, 0xdc, 0x56,
  185. 0x41, 0x41, 0x9c, 0x3d, 0x30, 0x60, 0xcf, 0xe3,
  186. 0x22, 0x38, 0xc0, 0xfa, 0x97, 0x3f, 0x7a, 0xa3,
  187. 0x02, 0x58, 0x20, 0xe6, 0xc2, 0x1e, 0x8d, 0x26,
  188. 0x0f, 0xe7, 0x18, 0x82, 0xde, 0xbd, 0xb3, 0x39,
  189. 0xd2, 0x40, 0x2a, 0x2c, 0xa7, 0x64, 0x85, 0x29,
  190. 0xbc, 0x23, 0x03, 0xf4, 0x86, 0x49, 0xbc, 0xe0,
  191. 0x38, 0x00, 0x17, 0x06, 0x67, 0x73, 0x68, 0x61,
  192. 0x2d, 0x32, 0x35, 0x36, 0x58, 0x60, 0x31, 0xd0,
  193. 0x4d, 0x52, 0xcc, 0xde, 0x95, 0x2c, 0x1e, 0x32,
  194. 0xcb, 0xa1, 0x81, 0x88, 0x5a, 0x40, 0xb8, 0xcc,
  195. 0x38, 0xe0, 0x52, 0x8c, 0x1e, 0x89, 0x58, 0x98,
  196. 0x07, 0x64, 0x2a, 0xa5, 0xe3, 0xf2, 0xbc, 0x37,
  197. 0xf9, 0x53, 0x74, 0x50, 0x6b, 0xff, 0x4d, 0x2e,
  198. 0x4b, 0xe7, 0x06, 0x3c, 0x4d, 0x72, 0x41, 0x92,
  199. 0x70, 0xc7, 0x22, 0xe8, 0xd4, 0xd9, 0x3e, 0xe8,
  200. 0xb6, 0xc9, 0xfa, 0xce, 0x3b, 0x43, 0xc9, 0x76,
  201. 0x1a, 0x49, 0x94, 0x1a, 0xb6, 0xf3, 0x8f, 0xfd,
  202. 0xff, 0x49, 0x6a, 0xd4, 0x63, 0xb4, 0xcb, 0xfa,
  203. 0x11, 0xd8, 0x3e, 0x23, 0xe3, 0x1f, 0x7f, 0x62,
  204. 0x32, 0x9d, 0xe3, 0x0c, 0x1c, 0xc8
  205. };
  206. /*
  207. * Get the hardcoded platform attestation token as QEMU does not support
  208. * RSE.
  209. */
  210. int plat_rmmd_get_cca_attest_token(uintptr_t buf, size_t *len,
  211. uintptr_t hash, size_t hash_size,
  212. size_t *remaining_len)
  213. {
  214. const size_t token_size = sizeof(sample_platform_token);
  215. (void)hash;
  216. (void)hash_size;
  217. /* Shouldn't happen because RMM uses the whole 4kB shared buffer */
  218. if (*len < token_size) {
  219. return -EINVAL;
  220. }
  221. memcpy((void *)buf, sample_platform_token, token_size);
  222. *len = token_size;
  223. *remaining_len = 0;
  224. return 0;
  225. }