Hello Douglas,

Le 05/04/2011 15:36, Douglas E. Engert a écrit :
I would the serialized, so some cards do not have to follow the GUID format. 
This could eliminate
the need to have a hash function for OpenSSL.

I've committed the common routines to get the 'classic' serialized form of GUID.

In attachment there is proposal for the PIV specific implementation.
Will you agree?

This PIV specific routine returns the hexadecimal presentation of the object ID 
concatenated to the serial --
like it was originally implemented by François .

Kind wishes,
Viktor.

--
Viktor Tarasov  <viktor.tara...@opentrust.com>

Index: src/libopensc/pkcs15-piv.c
===================================================================
--- src/libopensc/pkcs15-piv.c  (révision 5301)
+++ src/libopensc/pkcs15-piv.c  (copie de travail)
@@ -105,6 +105,45 @@
        int not_present;
 } common_key_info;
 
+
+static int piv_get_guid(struct sc_pkcs15_card *p15card, const struct 
sc_pkcs15_object *obj,
+               char *out, size_t out_size)
+{
+       struct sc_serial_number serialnr;
+       struct sc_pkcs15_id  id;
+       unsigned char guid_bin[SC_PKCS15_MAX_ID_SIZE + SC_MAX_SERIALNR];
+       size_t bin_size, offs;
+       int r, i;
+
+       if (!p15card || !obj || !out || out_size < 3)
+               return SC_ERROR_INCORRECT_PARAMETERS;
+
+       r = sc_pkcs15_get_object_id(obj, &id);
+       if (r)
+               return r;
+
+       r = sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &serialnr);
+       if (r)
+               return r;
+
+       memset(guid_bin, 0, sizeof(guid_bin));
+       memcpy(guid_bin, serialnr.value, serialnr.len);
+       memcpy(guid_bin + serialnr.len, id.value, id.len);
+
+       /* reserve one byte for the 'C' line ending */
+       bin_size = (out_size - 1)/2;
+       if (bin_size > id.len + serialnr.len)
+               bin_size = id.len + serialnr.len;
+
+       offs = id.len + serialnr.len - bin_size;
+
+       for (i=0; i<bin_size; i++)
+               sprintf(out + i*2, "%02x", guid_bin[offs + i]);
+
+       return SC_SUCCESS;
+}
+
+
 static int piv_detect_card(sc_pkcs15_card_t *p15card)
 {
        sc_card_t *card = p15card->card;
@@ -878,6 +917,8 @@
                        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, r);
        }
 
+       p15card->ops.get_guid = piv_get_guid;
+
        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_SUCCESS);
 }
 
_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to