Hello,
Ludovic Rousseau:
maybe we can obsolete some of those card specific implementations,
if the only difference was this value?
Maybe. I had a look at card-setcos.c and the two
iso7816_set_security_env() functions are very similar. And they are
even more similar with the patch applied.
Any volunteer?
Patch for card-gemsafeV1.c is in attachment, but unfortunately I can't
test it. I don't have this device.
Thanks
diff -u -r opensc-trunk-r3698/src/libopensc/card-gemsafeV1.c
new/opensc-trunk-r3698/src/libopensc/card-gemsafeV1.c
--- opensc-trunk-r3698/src/libopensc/card-gemsafeV1.c 2008-09-10
17:50:39.000000000 +0400
+++ new/opensc-trunk-r3698/src/libopensc/card-gemsafeV1.c 2009-06-26
16:02:48.000000000 +0400
@@ -380,61 +380,25 @@
const struct sc_security_env *env,
int se_num)
{
- int r;
- struct sc_apdu apdu;
- u8 sbuf[SC_MAX_APDU_BUFFER_SIZE], *p = sbuf;
- u8 alg_ref = 0;
+ u8 alg_ref;
+ struct sc_security_env se_env = *env;
struct sc_context *ctx = card->ctx;
SC_FUNC_CALLED(ctx, 1);
- sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0);
- switch (env->operation) {
- case SC_SEC_OPERATION_DECIPHER:
- apdu.p2 = 0xB8;
- break;
- case SC_SEC_OPERATION_SIGN:
- apdu.p2 = 0xB6;
- break;
- default:
- return SC_ERROR_INVALID_ARGUMENTS;
- }
- apdu.le = 0;
-
- /* first step: set the algorithm reference */
- if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT)
- alg_ref = env->algorithm_ref & 0xFF;
- else
- alg_ref = gemsafe_flags2algref(env);
- if (alg_ref) {
- /* set the algorithm reference */
- *p++ = 0x80;
- *p++ = 0x01;
- *p++ = alg_ref;
- } else
- sc_debug(ctx, "unknown algorithm flags '%x'\n",
env->algorithm_flags);
- /* second step: set the key reference */
- if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
- /* set the key reference */
- if (env->flags & SC_SEC_ENV_KEY_REF_ASYMMETRIC)
- *p++ = 0x83;
- else
- *p++ = 0x84;
- *p++ = env->key_ref_len;
- memcpy(p, env->key_ref, env->key_ref_len);
- p += env->key_ref_len;
+ if (!(se_env.flags & SC_SEC_ENV_ALG_REF_PRESENT)) {
+ /* set the algorithm reference */
+ alg_ref = gemsafe_flags2algref(&se_env);
+ if (alg_ref) {
+ se_env.algorithm_ref = alg_ref;
+ se_env.flags |= SC_SEC_ENV_ALG_REF_PRESENT;
+ }
}
+ if (!(se_env.flags & SC_SEC_ENV_ALG_REF_PRESENT))
+ sc_debug(ctx, "unknown algorithm flags '%x'\n",
se_env.algorithm_flags);
-
- r = p - sbuf;
- apdu.lc = r;
- apdu.datalen = r;
- apdu.data = sbuf;
- apdu.resplen = 0;
-
- r = sc_transmit_apdu(card, &apdu);
- SC_TEST_RET(card->ctx, r, "APDU transmit failed");
- return sc_check_sw(card, apdu.sw1, apdu.sw2);
+ se_env.flags &= ~SC_SEC_ENV_FILE_REF_PRESENT;
+ return iso_ops->set_security_env(card, &se_env, se_num);
}
static int gemsafe_compute_signature(struct sc_card *card, const u8 * data,
_______________________________________________
opensc-devel mailing list
[email protected]
http://www.opensc-project.org/mailman/listinfo/opensc-devel