hsw-nbt 1.2.0
OPTIGA Authenticate NBT Host Library for C
NDEF brand protection library

‍ C library to encode and decode brand protection NDEF record and messages

The NFC data exchange format (NDEF) specification by NFC Forum defines a common data format to exchange information between NFC Forum devices.

This C library provides support to build and parse the NDEF brand protection messages, with support for common NDEF record type definitions.

Features

  • Build and parse the NDEF brand protection messages
  • Build and parse the NDEF brand protection records

Usage

  1. Include the following headers

    NDEF message encoding/decoding utility.
    Model interface to create record types and set/get record fields.
    Model for the brand protection record.
    Provides utility functions and macros.
  1. Register the brand protection record into the NDEF C library

    ifx_status_t ifx_record_bp_register(void)
    Registers the brand protection record with the NDEF library. Only the registered records are encoded ...
  1. Create a new brand protection record

    ifx_status_t ifx_record_bp_new(ifx_record_handle_t *handle)
    Creates a new brand protection record and the respective handle for the record. This handle can be us...
    Defines the handle for specific record type.
  1. Provide custom implementations to encode and decode the certificates

    Example: Certificate encoder custom implementation

    ifx_status_t x509_certificate_encoder(const void * certificate, ifx_blob_t ** certificate_bytes)
    {
    // Implement code to encode X.509 certificate into byte array
    // Code placeholder
    return IFX_SUCCESS;
    }
    #define IFX_SUCCESS
    Default status code for successful calls to any function.
    Definition ifx-error.h:29
    uint32_t ifx_status_t
    Custom return code type used by all Infineon host software libraries.
    Definition ifx-error.h:91
    Data storage for data and data length where both are required as parameters.
    Definition ifx-utils.h:189

    Example: Certificate decoder custom implementation

    ifx_status_t x509_certificate_decoder(const ifx_blob_t * certificate_bytes, void * certificate)
    {
    // Implement code to decode X.509 certificate from byte array
    // Code placeholder
    return IFX_SUCCESS;
    }
  1. Set the custom certificate encoder and decoder handles

    ifx_record_bp_set_certificate_handlers(&handle, x509_certificate_encoder, x509_certificate_decoder);
    ifx_status_t ifx_record_bp_set_certificate_handlers(ifx_record_handle_t *handle, ifx_record_bp_cert_encoder_t encoder, ifx_record_bp_cert_decoder_t decoder)
    Sets the certificate encoder and decoder callback functions for parsing certificates.
  1. Example for defining the certificate data type

    // Example x509_certificate.
    typedef struct
    {
    char *issuer;
    char *subject;
    char *fingerprint;
    char *authority;
    ifx_blob_t public_key;
    ifx_blob_t signed_data;
    ifx_blob_t signature;
    } ifx_x509_certificate_example_t;
  1. Assign a certificate to the created brand protection record

    // Example: Declare a certificate
    ifx_x509_certificate_example_t certificate;
    // Assign the certificate.
    ifx_record_bp_set_certificate(&handle, (void *)&certificate);
    ifx_status_t ifx_record_bp_set_certificate(ifx_record_handle_t *handle, const void *certificate)
    Sets certificate in the brand protection record for a given record handle.
  1. Use the NDEF C library to encode the brand protection record into an NDEF message

    uint32_t record_count = 0x01;
    ifx_blob_t ndef_message = {0};
    ifx_ndef_message_encode((ifx_record_handle_t *)&handle, record_count, &ndef_message);
    ifx_status_t ifx_ndef_message_encode(const ifx_record_handle_t *record_handles, uint32_t number_of_records, ifx_blob_t *ndef_message)
    Encodes the array of the NDEF record handles into the NDEF message.

    This NDEF message can be written into the NDEF file in the tag.

  1. Use the NDEF C library to decode the brand protection record from an NDEF message

    ifx_record_handle_t get_record_handle;
    uint32_t get_number_of_records = 0x00;
    ifx_ndef_message_decode(&ndef_message, &get_number_of_records, &get_record_handle);
    ifx_status_t ifx_ndef_message_decode(const ifx_blob_t *ndef_message, uint32_t *number_of_records, ifx_record_handle_t *record_handles)
    Decodes the NDEF message buffer to the NDEF records array.
  1. Get the certificate from the record handle

    ifx_record_bp_get_certificate(&get_record_handle, &certificate);
    ifx_status_t ifx_record_bp_get_certificate(const ifx_record_handle_t *handle, void *certificate)
    Gets the certificate from the brand protection record handle.
  1. Release the memory allocated by the library

    // free-up the internally allocated memory.
    ifx_status_t ifx_ndef_record_release_resource(void)
    This method will free-up the internally allocated memory for ndef registered records.

Architecture

Below image described the software architecture of the library.

architecture

Components

  • Brand protection record models This component contains the record models that are in-built supported by the library. These record models provide the structure for the record, which can be used to build the record.
  • Brand protection record payload encoders and decoders This component contains the payload encoders and decoders which can be used to encode and decode the payload details into a byte array.

Interaction

Below UML diagram describes the interaction between the components.

interaction

Directory structure

The library directory is structured according to the Pitchfork Layout.

hsw-ndef-bp
|-- .cmake/ # Includes sources for dependency management
|-- LICENSES/ # Includes list of licenses used for the library
|-- data/ # Includes Doxygen, cppcheck configuration files
|-- docs/ # Includes documentation source files, images, and the generated API reference
|-- include/ # Public Headers(.h) of the library
|-- src/ # Sources(.c) and Private headers(.h) of the library
|-- .clang-format # clang-format configuration file
|-- .gitignore # Library specific gitignore file
|-- CMakeLists.txt # CMake build configurations for the library
`-- README.md # Overview of the hsw-ndef-bp library

Dependencies

  • hsw-error This dependent library is used for creating and parsing an error information.
  • hsw-ndef This dependent library is used for creating the DEF RTDs and parsing the NDEF record information.
  • hsw-utils This dependent library is used for utility functions such as string parsers.

References

  • Infineon Technologies AG: OPTIGA™; Authenticate NBT, Extended Datasheet
  • NFC Data Exchange Format (NDEF), Technical Specification, NFC Forum™, NDEF 1.0
  • NFC Record Type Definition (RTD), Technical Specification, NFC Forum™, RTD 1.0