The example below searches all attributes of a personality given by its name pers_name for an X.509 DeviceIdentity certificate.

  1. bool b_loop_attr = true;
  2. gta_enum_handle_t h_enum_attr = GTA_HANDLE_ENUM_FIRST;
  3. while (b_loop_attr) {
  4. char attr_name[STR_LEN_MAX];
  5. char attr_type[STR_LEN_MAX];
  6. myio_obufstream_t ostream_attr_name = { 0 };
  7. myio_obufstream_t ostream_attr_type = { 0 };
  8. myio_open_obufstream(&ostream_attr_name, attr_name,
  9. sizeof(attr_name), &errinfo);
  10. myio_open_obufstream(&ostream_attr_type, attr_type,
  11. sizeof(attr_type), &errinfo);
  12. if (gta_personality_attributes_enumerate(h_inst,
  13. pers_name,
  14. h_enum_attr,
  15. (gtaio_ostream_t *)&ostream_attr_name,
  16. (gtaio_ostream_t *)&ostream_attr_type,
  17. &errinfo)) {
  18. /* Get the attribute holding the
  19. DeviceIdentity Certificate */
  20. if (0 == strncmp(attr_type,
  21. "ch.iec.30168.trustlist.certificate.self.x509",
  22. STR_LEN_MAX)) {
  23. h_ctx = gta_context_open(h_inst,
  24. pers_name,
  25. "org.opcfoundation.ECC-nistP256",
  26. &errinfo);
  27. /* get application certificate */
  28. char devid_cert[CERT_SIZE_MAX];
  29. myio_obufstream_t ostream_devid_cert = { 0 };
  30. myio_open_obufstream(&ostream_devid_cert,
  31. devid_cert, sizeof(devid_cert), &errinfo);
  32. gta_personality_get_attribute(h_ctx,
  33. attr_name, (gtaio_ostream_t *)&ostream_devid_cert,
  34. &errinfo);
  35. /* ... make use of this DeviceIdentity Cerficate
  36. (e.g., add it to a list) ... */
  37. gta_context_close(h_ctx, &errinfo);
  38. }
  39. }
  40. else {
  41. b_loop_attr = false;
  42. }
  43. myio_close_obufstream(&ostream_attr_name, &errinfo);
  44. myio_close_obufstream(&ostream_attr_type, &errinfo);
  45. }