The example code below illustrates the use of GTA API to implement the scenario outlined in section 5.2.3.1, Figure 12.

The following assumptions apply:

  • Identifier used for the DCA Personality Set isurn:manufacturer.com:2024-10:myproduct:SN51235
  • Name used for the DCA Identity Personality isurn:manufacturer.com:2024-10:myproduct:SN51235?cg=DefaultApplicationGroup&ct=EccNistP256&ix=1
  • Name used for the DCA TrustList Personality isurn:manufacturer.com:2024-10:myproduct:SN51235?cg=DefaultApplicationGroup

Note that the example can be easily adjusted for any other profile by just switching to another profile (e.g., org.opcfoundation.Aes256-Sha256-RsaPss) and adjusting the identifier and personality names as desired.

  1. gta_errinfo_t errinfo = 0;
  2. char identifier_value[]
  3. = "urn:manufacturer.com:2024-10:myproduct:SN51235";
  4. char personality_name[]
  5. = "urn:manufacturer.com:2024-10:myproduct:SN51235?"
  6. "cg=DefaultApplicationGroup&ct=EccNistP256&ix=1";
  7. char identity_profile[]
  8. = "org.opcfoundation.ECC-nistP256";
  9. char application[] = "DCA Identity";
  10. char trustlist_personality_name[]
  11. = "urn:manufacturer.com:2024-10:myproduct:SN51235?"
  12. "cg=DefaultApplicationGroup";
  13. char trustlist_application[] = "DCA TrustList";
  14. char trustlist_profile[]
  15. = "ch.iec.30168.basic.local_data_integrity_only";
  16. /* Assign identifier */
  17. gta_identifier_assign(
  18. h_inst,
  19. "org.opcfoundation.application_instance_uri",
  20. identifier_value,
  21. &errinfo);
  22. /* Create DCA Identity Personality */
  23. gta_access_policy_handle_t h_auth_use = GTA_HANDLE_INVALID;
  24. h_auth_use = gta_access_policy_simple(
  25. h_inst,
  26. GTA_ACCESS_DESCRIPTOR_TYPE_INITIAL,
  27. &errinfo);
  28. gta_access_policy_handle_t h_auth_use = GTA_HANDLE_INVALID;
  29. h_auth_admin = gta_access_policy_simple(
  30. h_inst,
  31. GTA_ACCESS_DESCRIPTOR_TYPE_INITIAL,
  32. &errinfo);
  33. struct gta_protection_properties_t protection_props = {0};
  34. gta_personality_create(
  35. h_inst,
  36. identifier_value,
  37. personality_name,
  38. application,
  39. identity_profile,
  40. h_auth_use,
  41. h_auth_admin,
  42. protection_props,
  43. &errinfo);
  44. /* Generate CSR */
  45. gta_context_handle_t h_ctx = GTA_HANDLE_INVALID;
  46. h_ctx = gta_context_open(
  47. h_inst,
  48. personality_name,
  49. "com.github.generic-trust-anchor-api.basic.enroll",
  50. &errinfo);
  51. /* Set context attribute org.opcfoundation.csr.subject */
  52. const char subject_der[] = {…};
  53. size_t subject_der_len = …;
  54. myio_ibufstream_t istream_subject = { 0 };
  55. myio_open_ibufstream(
  56. &istream_subject,
  57. subject_der, subject_der_len,
  58. &errinfo);
  59. gta_context_set_attribute(
  60. h_ctx,
  61. "org.opcfoundation.csr.subject",
  62. (gtaio_istream_t*)&istream_subject,
  63. &errinfo);
  64. myio_close_ibufstream(&istream_subject, &errinfo);
  65. /* Set context attribute org.opcfoundation.csr.subjectAltName */
  66. const char subject_alt_name_der[] = {…};
  67. size_t subject_alt_name_der_len = …;
  68. myio_ibufstream_t istream_subject_alt_name = { 0 };
  69. myio_open_ibufstream(
  70. &istream_subject_alt_name,
  71. subject_alt_name_der, subject_alt_name_der_len,
  72. &errinfo);
  73. gta_context_set_attribute(
  74. h_ctx,
  75. "org.opcfoundation.csr.subjectAltName",
  76. (gtaio_istream_t*)&istream_subject_alt_name,
  77. &errinfo);
  78. myio_close_ibufstream(&istream_subject_alt_name, &errinfo);
  79. char csr_buffer[CSR_SIZE];
  80. myio_obufstream_t ostream_csr = { 0 };
  81. myio_open_obufstream(
  82. &ostream_csr,
  83. csr_buffer, sizeof(csr_buffer),
  84. &errinfo);
  85. gta_personality_enroll(
  86. h_ctx,
  87. (gtaio_ostream_t*)&ostream_csr,
  88. &errinfo);
  89. myio_close_obufstream(&ostream_csr, &errinfo);
  90. /* Send CSR and receive certificate */
  91. char cert_buffer[] = {…};
  92. size_t cert_len = …;
  93. /* Store DCA certificate (optional) */
  94. myio_ibufstream_t istream_cert = { 0 };
  95. myio_open_ibufstream(
  96. &istream_cert,
  97. cert_buffer, cert_len,
  98. &errinfo);
  99. gta_personality_add_attribute(
  100. h_ctx,
  101. "ch.iec.30168.trustlist.certificate.self.x509",
  102. "DCA certificate",
  103. (gtaio_istream_t*)&istream_cert,
  104. &errinfo);
  105. myio_close_ibufstream(&istream_cert, &errinfo);
  106. gta_context_close(h_ctx, &errinfo);
  107. /* Receive TrustList */
  108. char trustlist_buffer[] = {…};
  109. size_t trustlist_len = …;
  110. /* Create DCA TrustList Personality */
  111. gta_personality_create(
  112. h_inst,
  113. identifier_value,
  114. trustlist_personality_name,
  115. trustlist_application,
  116. trustlist_profile,
  117. h_auth_use,
  118. h_auth_admin,
  119. protection_props,
  120. &errinfo);
  121. /* Protect DCA TrustList objects */
  122. gta_context_handle_t h_ctx_seal = GTA_HANDLE_INVALID;
  123. h_ctx_seal = gta_context_open(
  124. h_inst,
  125. trustlist_personality_name,
  126. trustlist_profile,
  127. &errinfo);
  128. myio_ibufstream_t istream_trustlist = { 0 };
  129. myio_open_ibufstream(
  130. &istream_trustlist,
  131. trustlist_buffer, trustlist_len,
  132. &errinfo);
  133. #define INTEGRITY_PROTECTION_SEAL_LENGTH 32
  134. char seal_buffer[INTEGRITY_PROTECTION_SEAL_LENGTH];
  135. myio_obufstream_t ostream_seal = { 0 };
  136. myio_open_obufstream(
  137. &ostream_seal,
  138. seal_buffer, sizeof(seal_buffer),
  139. &errinfo);
  140. gta_authenticate_data_detached(
  141. h_ctx_seal,
  142. (gtaio_istream_t*)&istream_trustlist,
  143. (gtaio_ostream_t*)&ostream_seal,
  144. &errinfo);
  145. myio_close_ibufstream(&istream_trustlist, &errinfo);
  146. myio_close_obufstream(&ostream_seal, &errinfo);
  147. gta_context_close(h_ctx_seal, &errinfo);