/* writekey [-s $slot] [-p $pin] -l $label -i $id -f $filename */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#ifndef OPENCRYPTOKI
#include <security/cryptoki.h>
#else
#include <opencryptoki/pkcs11.h>
#endif
/* Define static key template values */
int
{
ENGINE *e;
int id = 0;
int error = 0;
int c, errflg = 0;
extern char *optarg;
extern int optopt;
switch (c) {
case 's':
break;
case 'l':
break;
case 'i':
id &= 0xffff;
break;
case 'p':
break;
case 'f':
break;
case ':':
errflg++;
break;
case '?':
default:
errflg++;
}
}
"usage: writekey [-s slot] [-p pin] -l label -i id "
"-f filename\n");
exit(2);
}
/* Load the config file */
/* Register engine */
e = ENGINE_by_id("pkcs11");
if (!e) {
/* the engine isn't available */
printf("The engine isn't available\n");
exit(1);
}
if (!ENGINE_init(e)) {
/* the engine couldn't initialise, release 'e' */
printf("The engine couldn't initialise\n");
ENGINE_free(e);
exit(1);
}
/* Read the key */
printf("Error opening input file.\n");
ENGINE_free(e);
exit(1);
}
printf("Error reading input file.\n");
ENGINE_free(e);
exit(1);
}
/* Initialize the CRYPTOKI library */
ENGINE_free(e);
exit(1);
}
/* Open a session on the slot found */
error = 1;
goto exit_program;
}
/* Login to the Token (Keystore) */
if (!pin)
#ifndef OPENCRYPTOKI
#else
#endif
error = 1;
goto exit_session;
}
/* fill the search template */
/* check if a key with the same label already exists */
error = 1;
goto exit_session;
}
error = 1;
goto exit_search;
}
if (ulObjectCount != 0) {
error = 1;
goto exit_search;
}
/* fill attributes for the public key */
error = 1;
goto exit_search;
}
error = 1;
goto exit_search;
}
error = 1;
goto exit_search;
}
error = 1;
goto exit_search;
}
error = 1;
goto exit_search;
}
error = 1;
goto exit_search;
}
error = 1;
goto exit_search;
}
error = 1;
goto exit_search;
}
error = 1;
goto exit_search;
}
/* fill attributes for the private key */
error = 1;
goto exit_search;
}
error = 1;
}
(void) C_CloseSession(hSession);
(void) C_Finalize(NULL_PTR);
ENGINE_free(e);
}