Goal:
We have a custom extension that contains some config settings DER encoded.
I would like to use wolfssl to parse this content in an ASN structure using the ASN templating available in wolfssl.
What I'm looking for:
how do I parse the ASN data received via the custom extension callback
What I found:
I found an example on how to add a custom extension callback.
I found some ASN template definitions but not sure how to combine these into valid code that can parse the below ASN.
https://github.com/wolfSSL/wolfssl/blob … /src/asn.c
I assume using a combination of these definitions ASN_SEQUENCE, ASN_CONSTRUCTED, ASN_OCTET_STRING?
Question: Does an ASN templating and parsing example exist? I could not find it in the available examples.
ASN format i want to parse
TOTALCONFIG ::= SEQUENCE {
version OCTET STRING (SIZE(4)),
myconfigs SEQUENCE (SIZE(0..MAX)) OF single-config
}
single-config ::= SEQUENCE {
config-id INTEGER(0..MAX),
config-settings-a [0] SEQUENCE (SIZE(1...MAX)) OF OCTET STRING (SIZE(2..MAX)) OPTIONAL,
config-settings-b [1] SEQUENCE (SIZE(1...MAX)) OF OCTET STRING (SIZE(2..MAX)) OPTIONAL,
config-settings-c [2] SEQUENCE (SIZE(1...MAX)) OF OCTET STRING (SIZE(3)) OPTIONAL
}
other things I searched for
Of course I also used chatgpt but not sure if this code is valid
typedef struct {
int myInteger;
char myString[50]; // Adjust size as needed
} MyCustomData;
static const WOLFSSL_ASN1_TEMPLATE MyCustomTemplate[] = {
{ 0, 0, ASN1_INTEGER, offsetof(MyCustomData, myInteger), 0 },
{ 1, 0, ASN1_UTF8STRING, offsetof(MyCustomData, myString), sizeof(((MyCustomData*)0)->myString) },
{ 0, 0, 0, 0, 0 } // End of template
};