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

sc-hsm: Can't force card driver for non-builtin ATR #1042

Closed
frankmorgner opened this issue May 4, 2017 · 1 comment
Closed

sc-hsm: Can't force card driver for non-builtin ATR #1042

frankmorgner opened this issue May 4, 2017 · 1 comment

Comments

@frankmorgner
Copy link
Member

Expected behaviour

A Smartcard-HSM installed into a token with an ATR unknown to OpenSC should be possible. Card recognition should be based on Applet selection instead of ATR restrictions.

Actual behaviour

OpenSC limits Smartcard HSMs to the following ATRs, because it leaves card->type uninitialized:

/* Known ATRs for SmartCard-HSMs */
static struct sc_atr_table sc_hsm_atrs[] = {
	/* standard version */
	{"3B:FE:18:00:00:81:31:FE:45:80:31:81:54:48:53:4D:31:73:80:21:40:81:07:FA", NULL, NULL, SC_CARD_TYPE_SC_HSM, 0, NULL},
	{"3B:8E:80:01:80:31:81:54:48:53:4D:31:73:80:21:40:81:07:18", NULL, NULL, SC_CARD_TYPE_SC_HSM, 0, NULL},
	{NULL, NULL, NULL, 0, 0, NULL}
};

/* Known ATRs for JavaCards that qualify for SmartCard-HSMs */
static struct sc_atr_table sc_hsm_jc_atrs[] = {
	/* standard version */
	{"3b:f8:13:00:00:81:31:fe:45:4a:43:4f:50:76:32:34:31:b7", NULL, NULL, SC_CARD_TYPE_SC_HSM, 0, NULL},	// JCOP 2.4.1 Default ATR contact based
	{"3b:88:80:01:4a:43:4f:50:76:32:34:31:5e", NULL, NULL, SC_CARD_TYPE_SC_HSM, 0, NULL},	// JCOP 2.4.1 Default ATR contactless
	{NULL, NULL, NULL, 0, 0, NULL}
};

...

static int sc_hsm_match_card(struct sc_card *card)
{
	sc_path_t path;
	int i, r;

	i = _sc_match_atr(card, sc_hsm_atrs, &card->type);
	if (i >= 0)
		return 1;

	i = _sc_match_atr(card, sc_hsm_jc_atrs, &card->type);
	if (i < 0)
		return 0;

This limitation is present at least since 0.16.0. When forcing the card driver in 0.16.0 for a non-builtin ATR, initialization of the sc-hsm PKCS#15 emulator fails.

frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue May 7, 2017
allows cards with non-default ATRs to be identified as sc-hsm
Fixes OpenSC#1042
@frankmorgner
Copy link
Member Author

frankmorgner commented May 7, 2017

fixed with d07ecd8 in #1004

frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue May 15, 2017
- don't use private data on card matching
- instead, return 1 for every known ATR and only select the applet if the ATR is unknown.
- card initialization always selects the applet.

Advantage: decouples memeory management in matching from initializing the card.
Disadvantage: Applet is selected twice in case of an unknown ATR (once for matching and a second time for initializing the card).

Fixes OpenSC#1042
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

No branches or pull requests

1 participant