Hello,
I wrote a small, dirty patch for the pkcs11-tool (0.11.1) do be able to write
data objects to a smartcard.
...if it is of any interest:
It would be invoked like this to write the contents of the file "test":
./pkcs11-tool -w test -y data --application-id TEST --label CORNY -l
(My pkcs11-provider does not know the OBJECT_ID yet :-( )
Kind regards
Cornelius
--- pkcs11-tool.c.orig 2006-09-06 17:38:14.000000000 +0200
+++ pkcs11-tool.c 2006-09-06 17:50:35.000000000 +0200
@@ -110,7 +110,7 @@
"Write an object (key, cert) to the card",
"Get object's CKA_VALUE attribute (use with --type)",
"Specify the application id of the data object (use with --type data)",
- "Specify the type of object (e.g. cert, privkey, pubkey)",
+ "Specify the type of object (e.g. cert, privkey, pubkey,data)",
"Specify the id of the object",
"Specify the label of the object",
"Specify number of the slot to use",
@@ -1159,13 +1159,15 @@
{
CK_BBOOL _true = TRUE;
unsigned char contents[MAX_OBJECT_SIZE];
+ unsigned char data[MAX_OBJECT_SIZE];
int contents_len = 0;
+ int data_len = 0;
unsigned char certdata[MAX_OBJECT_SIZE];
int certdata_len = 0;
FILE *f;
- CK_OBJECT_HANDLE cert_obj, privkey_obj;
- CK_ATTRIBUTE cert_templ[20], privkey_templ[20];
- int n_cert_attr = 0, n_privkey_attr = 0;
+ CK_OBJECT_HANDLE cert_obj, privkey_obj, data_obj;
+ CK_ATTRIBUTE cert_templ[20], privkey_templ[20], data_templ[20];
+ int n_cert_attr = 0, n_privkey_attr = 0, n_data_attr;
#if 0
CK_ATTRIBUTE pubkey_templ[20];
CK_OBJECT_HANDLE pubkey_obj;
@@ -1307,8 +1309,43 @@
#endif
}
else
+ if (opt_object_class == CKO_DATA) {
+
+ memcpy(data, contents, MAX_OBJECT_SIZE);
+ data_len = contents_len;
+
+ CK_OBJECT_CLASS clazz = CKO_DATA;
+ FILL_ATTR(data_templ[0], CKA_CLASS, &clazz, sizeof(clazz));
+ // At the moment only PRIVTATE OBJECTs
+ FILL_ATTR(data_templ[1], CKA_PRIVATE, &_true, sizeof(_true));
+ FILL_ATTR(data_templ[2], CKA_TOKEN, &_true, sizeof(_true));
+ FILL_ATTR(data_templ[3], CKA_VALUE, &data, data_len);
+
+ n_data_attr = 4;
+
+ if (opt_application_id != NULL) {
+ FILL_ATTR(data_templ[n_data_attr], CKA_APPLICATION,
+ opt_application_id, strlen(opt_application_id));
+ n_data_attr++;
+ }
+ if (opt_object_label != NULL) {
+ FILL_ATTR(data_templ[n_data_attr], CKA_LABEL,
+ opt_object_label, strlen(opt_object_label));
+ n_data_attr++;
+ }
+
+ }
+ else
fatal("Writing of a \"%s\" type not (yet) supported\n", opt_object_class_str);
+ if (n_data_attr) {
+ rv = p11->C_CreateObject(session, data_templ, n_data_attr, &data_obj);
+ if (rv != CKR_OK)
+ p11_fatal("C_CreateObject", rv);
+
+ printf("Generated Data Object:\n");
+ show_dobj(session, data_obj);
+ }
if (n_cert_attr) {
rv = p11->C_CreateObject(session, cert_templ, n_cert_attr, &cert_obj);
if (rv != CKR_OK)
_______________________________________________
opensc-devel mailing list
[email protected]
http://www.opensc-project.org/mailman/listinfo/opensc-devel