Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ePass2003 support(3nd edtion). #12

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libopensc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ libopensc_la_SOURCES = \
card-cardos.c card-tcos.c card-default.c \
card-mcrd.c card-starcos.c card-openpgp.c card-jcop.c \
card-oberthur.c card-belpic.c card-atrust-acos.c card-entersafe.c \
card-epass2003.c \
card-incrypto34.c card-piv.c card-muscle.c card-acos5.c \
card-asepcos.c card-akis.c card-gemsafeV1.c card-rutoken.c \
card-rtecp.c card-westcos.c card-myeid.c card-ias.c \
Expand Down
1 change: 1 addition & 0 deletions src/libopensc/Makefile.mak
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ OBJECTS = \
card-cardos.obj card-tcos.obj card-default.obj \
card-mcrd.obj card-starcos.obj card-openpgp.obj card-jcop.obj \
card-oberthur.obj card-belpic.obj card-atrust-acos.obj card-entersafe.obj \
card-epass2003.obj \
card-incrypto34.obj card-piv.obj card-muscle.obj card-acos5.obj \
card-asepcos.obj card-akis.obj card-gemsafeV1.obj card-rutoken.obj \
card-rtecp.obj card-westcos.obj card-myeid.obj card-ias.obj \
Expand Down
51 changes: 50 additions & 1 deletion src/libopensc/apdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ static int do_single_transmit(sc_card_t *card, sc_apdu_t *apdu)
return SC_SUCCESS;
}

int sc_transmit_apdu(sc_card_t *card, sc_apdu_t *apdu)
static int _sc_transmit_apdu(sc_card_t *card, sc_apdu_t *apdu)
{
int r = SC_SUCCESS;

Expand Down Expand Up @@ -608,6 +608,55 @@ int sc_transmit_apdu(sc_card_t *card, sc_apdu_t *apdu)
return r;
}

/*
* Wrap/Unwrap APDU when requested before sending to reader driver
* Needed (un)wrapping apdu is noticed by a non-null
* card->ops->(un)wrap_apdu() function pointer
* (eg: for Secure Messaging)
* @param card sc_card_t object for the smartcard
* @param apdu APDU to be sent
* @return SC_SUCCESS on success and an error value otherwise
*/
int sc_transmit_apdu(sc_card_t *card, sc_apdu_t *apdu) {
int r;
sc_context_t *ctx = card->ctx;

if (ctx->use_sm != 0) {
//construct new SM apdu from original apdu
u8 data[SC_MAX_EXT_APDU_BUFFER_SIZE] = {0};
u8 resp[SC_MAX_EXT_APDU_BUFFER_SIZE] = {0};
sc_apdu_t wrapped_apdu;
wrapped_apdu.data = &data[0];
wrapped_apdu.datalen = SC_MAX_EXT_APDU_BUFFER_SIZE;
wrapped_apdu.resp = &resp[0];
wrapped_apdu.resplen = SC_MAX_EXT_APDU_BUFFER_SIZE;

/* wrap apdu */
r = card->ops->sm_wrap_apdu(card, apdu, &wrapped_apdu);
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "sm_wrap_apdu error");

/* determine the APDU type if necessary, i.e. to use
* short or extended APDUs */
sc_detect_apdu_cse(card, apdu);

/* check wrapped apdu */
r = sc_check_apdu(card, &wrapped_apdu);
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "wrapped APDU is invalid");

r = _sc_transmit_apdu(card, &wrapped_apdu);
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "unable to transmit wrapped APDU");

/* unwrap apdu */
r = card->ops->sm_unwrap_apdu(card, &wrapped_apdu, apdu);
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "sm_unwrap_apdu error");

} else {
/* no wrap needed, just call reader driver */
r = _sc_transmit_apdu(card, apdu);
}
return r;
}

int sc_bytes2apdu(sc_context_t *ctx, const u8 *buf, size_t len, sc_apdu_t *apdu)
{
const u8 *p;
Expand Down
1 change: 1 addition & 0 deletions src/libopensc/card-entersafe.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ static int entersafe_init(sc_card_t *card)
_sc_card_add_rsa_alg(card,2048, flags, 0);

card->caps = SC_CARD_CAP_RNG;
card->ctx->use_sm = 0;

/* we need read_binary&friends with max 224 bytes per read */
card->max_send_size = 224;
Expand Down
Loading