diff --git a/npa/src/npa-tool.c b/npa/src/npa-tool.c index 3e48c25..e54e833 100644 --- a/npa/src/npa-tool.c +++ b/npa/src/npa-tool.c @@ -211,60 +211,52 @@ int npa_translate_apdus(sc_card_t *card, FILE *input) } static int add_to_ASN1_AUXILIARY_DATA( - ASN1_AUXILIARY_DATA **templates, + ASN1_AUXILIARY_DATA **auxiliary_data, int nid, const unsigned char *data, size_t data_len) { int r; - CVC_DISCRETIONARY_DATA_TEMPLATE **template; + CVC_DISCRETIONARY_DATA_TEMPLATE *template = NULL; - if (!templates) { + if (!auxiliary_data) { r = SC_ERROR_INVALID_ARGUMENTS; goto err; } - if (!*templates) { - *templates = ASN1_AUXILIARY_DATA_new(); - if (!*templates) { + if (!*auxiliary_data) { + *auxiliary_data = ASN1_AUXILIARY_DATA_new(); + if (!*auxiliary_data) { r = SC_ERROR_INTERNAL; goto err; } } - if (!(*templates)->template1) - template = &(*templates)->template1; - else if (!(*templates)->template2) - template = &(*templates)->template2; - else if (!(*templates)->template3) - template = &(*templates)->template3; - else { - fprintf(stderr, - "Choose at most three nPA operations.\n"); - r = SC_ERROR_INVALID_ARGUMENTS; - goto err; - } - - *template = CVC_DISCRETIONARY_DATA_TEMPLATE_new(); - if (!*template) { + template = CVC_DISCRETIONARY_DATA_TEMPLATE_new(); + if (!template) { r = SC_ERROR_INTERNAL; goto err; } - (*template)->type = OBJ_nid2obj(nid); - if (!(*template)->type) { + template->type = OBJ_nid2obj(nid); + if (!template->type) { r = SC_ERROR_INTERNAL; goto err; } if (data && data_len) { - (*template)->discretionary_data3 = ASN1_OCTET_STRING_new(); - if (!(*template)->discretionary_data3 + template->discretionary_data3 = ASN1_OCTET_STRING_new(); + if (!template->discretionary_data3 || !M_ASN1_OCTET_STRING_set( - (*template)->discretionary_data3, data, data_len)) { + template->discretionary_data3, data, data_len)) { r = SC_ERROR_INTERNAL; goto err; } } + if (!sk_push((_STACK*) (*auxiliary_data), template)) { + r = SC_ERROR_INTERNAL; + goto err; + } + r = SC_SUCCESS; err: diff --git a/npa/src/npa.c b/npa/src/npa.c index 09e4086..544b719 100644 --- a/npa/src/npa.c +++ b/npa/src/npa.c @@ -47,13 +47,14 @@ /* 0x67 * Auxiliary authenticated data */ -ASN1_ITEM_TEMPLATE(ASN1_AUXILIARY_DATA) = +ASN1_ITEM_TEMPLATE(ASN1_AUXILIARY_DATA) = ASN1_EX_TEMPLATE_TYPE( - ASN1_TFLG_IMPTAG|ASN1_TFLG_APPLICATION, - 7, ASN1_AUXILIARY_DATA, CVC_DISCRETIONARY_DATA_TEMPLATES) + ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_IMPTAG|ASN1_TFLG_APPLICATION, + 7, AuxiliaryAuthenticatedData, CVC_DISCRETIONARY_DATA_TEMPLATE) ASN1_ITEM_TEMPLATE_END(ASN1_AUXILIARY_DATA) IMPLEMENT_ASN1_FUNCTIONS(ASN1_AUXILIARY_DATA) + /* * MSE:Set AT */ @@ -73,7 +74,7 @@ typedef struct npa_mse_cd_st { * * NPA_MSE_C->auxiliary_data = d2i_ASN1_AUXILIARY_DATA(...) * - * because they both use the same underlieing struct. + * because they both use the same underlying struct. * * See also openssl/crypto/asn1/tasn_dec.c:183 */ @@ -92,7 +93,7 @@ ASN1_SEQUENCE(NPA_MSE_C) = { ASN1_IMP_OPT(NPA_MSE_C, eph_pub_key, ASN1_OCTET_STRING, 0x11), /* 0x67 * Auxiliary authenticated data. See note above. */ - ASN1_APP_IMP_OPT(NPA_MSE_C, auxiliary_data, CVC_DISCRETIONARY_DATA_TEMPLATES, 7), + ASN1_APP_IMP_SEQUENCE_OF_OPT(NPA_MSE_C, auxiliary_data, CVC_DISCRETIONARY_DATA_TEMPLATE, 7), /* Certificate Holder Authorization Template */ ASN1_OPT(NPA_MSE_C, chat, CVC_CHAT), } ASN1_SEQUENCE_END(NPA_MSE_C) diff --git a/npa/src/npa/npa.h b/npa/src/npa/npa.h index 9902e79..d1a64d3 100644 --- a/npa/src/npa/npa.h +++ b/npa/src/npa/npa.h @@ -225,7 +225,7 @@ int npa_reset_retry_counter(sc_card_t *card, extern char npa_default_flags; /** @brief ASN.1 type for authenticated auxiliary data for terminal authentication */ -typedef CVC_DISCRETIONARY_DATA_TEMPLATES ASN1_AUXILIARY_DATA; +typedef STACK_OF(CVC_DISCRETIONARY_DATA_TEMPLATE) ASN1_AUXILIARY_DATA; DECLARE_ASN1_FUNCTIONS(ASN1_AUXILIARY_DATA) #ifdef __cplusplus