Export or Import Chip (Meta)Data

Example

from optigatrust import port
import json

dump = port.to_json()
json.dumps(dump, indent=4)

API

This module implements data/metadata import and export functions

optigatrust.port.from_json(data=None)

This function will take as an input your data and populate the chip with it, whatever is possible

Parameters:

data – JSON string with the dump of the data. Should be a valid dict structure

{
    "e0f1":
    {
        "metadata":'200fc00101d001ffd301ffe00103e10121',
        "pretty_metadata":
        {
            "lcso": "creation",
            "change": "never",
            "execute": "never",
            "algorithm": "secp256r1",
            "key_usage": ['authentication', 'key_agreement']
        }
    },
    "e0c2":
    {
        "metadata":"2009c4011bd001ffd10100",
        "pretty_metadata":
        {
            "max_size": 27,
            "change": "never",
            "read": "always"
        }
        "data":"cd16338201001c000500000a091b5c0007006200ad801010710809"
    }
}
Raises:
  • ValueError - when any of the parameters contain an invalid value

  • TypeError - when any of the parameters are of the wrong type

  • OSError - when an error is returned by the chip initialisation library

optigatrust.port.from_json_path(path)

This function will take as an input your data and populate the chip with it, whatever is possible

Parameters:

path – path to the json file. The content should be formed like the following

{
    "e0f1":
    {
        "metadata":'200fc00101d001ffd301ffe00103e10121',
        "pretty_metadata":
        {
            "lcso": "creation",
            "change": "never",
            "execute": "never",
            "algorithm": "secp256r1",
            "key_usage": ['authentication', 'key_agreement']
        }
    },
    "e0c2":
    {
        "metadata":"2009c4011bd001ffd10100",
        "pretty_metadata":
        {
            "max_size": 27,
            "change": "never",
            "read": "always"
        }
        "data":"cd16338201001c000500000a091b5c0007006200ad801010710809"
    }
}
Raises:
  • ValueError - when any of the parameters contain an invalid value

  • TypeError - when any of the parameters are of the wrong type

  • OSError - when an error is returned by the chip initialisation library

optigatrust.port.to_json()

This function will secentially read all metadata from all available OIDs and return a dictionary with all entrie

Raises:
  • ValueError - when any of the parameters contain an invalid value

  • TypeError - when any of the parameters are of the wrong type

  • OSError - when an error is returned by the chip initialisation library

Returns:

a dictionary will all available metadata per object; e.g.

{
    "e0f1":
    {
        "metadata":'200fc00101d001ffd301ffe00103e10121',
        "pretty_metadata":
        {
            "lcso": "creation",
            "change": "never",
            "execute": "never",
            "algorithm": "secp256r1",
            "key_usage": ['authentication', 'key_agreement']
        }
    },
    "e0c2":
    {
        "metadata":"2009c4011bd001ffd10100",
        "pretty_metadata":
        {
            "max_size": 27,
            "change": "never",
            "read": "always"
        }
        "data":"cd16338201001c000500000a091b5c0007006200ad801010710809"
    }
}

optigatrust.port.to_otc(path)

This function exports the whole available dump of the chip in the format compatible with the OPTIGA Trust Configurator. Two things will be exported. Data in .dat file format from available objects and an xml file with metadata stored. The function uses optigatrust/enums/conf_template.xml and add sequentially all objects found on the chip. There are exceptions, objects [“f1c1”, “e0c2”, “e0c0”, “e0c1”, “e0c5”, “e0c6”] are excluded and Objects which don’t have ‘used_size’ metatag defined are excluded

Param:

path Path to the folder where to store the resulting data.

Raises:
  • ValueError - when any of the parameters contain an invalid value

  • TypeError - when any of the parameters are of the wrong type

  • OSError - when an error is returned by the chip initialisation library

Returns:

an xml string according to the template optigatrust/enums/conf_template.xml

<objects>
<!--OPTIGA Objects Metadata and Data-->
    <oid id="E0F0">
        <metadata value="Updated_Tags">C00101D001FFD30100E00103E10101</metadata>
        <data
            data_from="Infineon"
            value="Default"
            type="Plain"
            chip_individual="false">
        </data>
    </oid>
    ...
</objects>