Skip to content

Conversation

@popovec
Copy link
Member

@popovec popovec commented May 5, 2023

This patch introduces basic verification of data coming from the token in the secure messaging mode:

  1. compare raw SW and SW encoded in SM
  2. verify MAC

MAC verification is working only for DES and AES-CBC-MAC. Code for checking MAC in FIPS mode is still missing.

modified:   src/libopensc/card-epass2003.c

@popovec
Copy link
Member Author

popovec commented May 5, 2023

Just for completeness: AES-CBC-MAC was tested on a real epass2003 token. I don't have a real token using DES, so the code for DES was written according to the construct_mac_tlv() function. This code was verified only in the simulation -
https://github.com/popovec/epass2003_sim

(the simulator could be used as part of OpenSC CI tests, functionality example: https://github.com/popovec/OpenSC/actions/runs/4891381567)


/* copy response to buffer and append padding */
memcpy(data, in, mac_len);
memset(data + mac_len, 0, blocksize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use calloc instead of malloc above and you don't need to memset here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be best to use alloca (let's save free maintenance). However, I did not find `alloc' anywhere in the OpenSC code, I understand that there may be a problem with portability.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alloca is not supported on Windows, afaik. Also, I don't like it personally because you can't do any error handling (a failure in memory allocation with alloca is just undefined behavior).

This patch introduces basic verification of data coming from the token in
the secure messaging mode:

1. compare raw SW and SW encoded in SM
2. verify MAC

MAC verification is working only for DES and AES-CBC-MAC.  Code for checking
MAC in FIPS mode is still missing.

	modified:   src/libopensc/card-epass2003.c
@popovec popovec force-pushed the epass2003_SM_mac_check branch from cb81904 to 2d2f57f Compare May 15, 2023 06:58
@popovec
Copy link
Member Author

popovec commented May 15, 2023

Rebased. Access outside the input buffer fixed by checking the inlen variable. malloc + memset replaced by calloc. Thanks again for the review.

@frankmorgner frankmorgner merged commit 6341c19 into OpenSC:master Jun 6, 2023
@xhanulik xhanulik mentioned this pull request Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants