17 #include <gwenhywfar/debug.h>
18 #include <gwenhywfar/pathmanager.h>
19 #include <gwenhywfar/cgui.h>
21 #include <gwenhywfar/gwenhywfar.h>
22 #include <gwenhywfar/args.h>
23 #include <gwenhywfar/logger.h>
24 #include <gwenhywfar/db.h>
25 #include <gwenhywfar/misc.h>
26 #include <gwenhywfar/misc2.h>
27 #include <gwenhywfar/inherit.h>
28 #include <gwenhywfar/ct.h>
29 #include <gwenhywfar/ctplugin.h>
30 #include <gwenhywfar/text.h>
31 #include <gwenhywfar/mdigest.h>
47 #define GCT_LOGDOMAIN "GCT"
71 "Context id (0 for any)",
72 "Context id (0 for any)"
82 "Specify the crypt token type",
83 "Specify the crypt token type"
93 "Specify the crypt token name",
94 "Specify the crypt token name"
104 "Show this help screen",
105 "Show this help screen"
115 fprintf(stderr,
"ERROR: Could not parse arguments\n");
123 fprintf(stderr,
"ERROR: Could not create help string\n");
141 DBG_ERROR(0,
"Plugin manager not found");
154 DBG_ERROR(0,
"Could not create crypt token");
168 uint8_t clearText[20]={
169 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
170 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
171 0x11, 0x12, 0x13, 0x14
173 uint8_t signature[256];
178 signLen=
sizeof(signature);
189 DBG_ERROR(0,
"Could not sign data (%d)", rv);
193 fprintf(stderr,
"Signature is:\n");
205 DBG_ERROR(0,
"Could not verify data (%d)", rv);
208 fprintf(stderr,
"Signature is ok.\n");
242 "Context id (0 for any)",
243 "Context id (0 for any)"
253 "Specify the crypt token type",
254 "Specify the crypt token type"
264 "Specify the crypt token name",
265 "Specify the crypt token name"
275 "Show this help screen",
276 "Show this help screen"
286 fprintf(stderr,
"ERROR: Could not parse arguments\n");
294 fprintf(stderr,
"ERROR: Could not create help string\n");
312 DBG_ERROR(0,
"Plugin manager not found");
325 DBG_ERROR(0,
"Could not create crypt token");
339 uint8_t clearText[16]={
340 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
341 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10
343 uint8_t encrypted[128];
345 uint8_t decrypted[128];
350 elen=
sizeof(encrypted);
360 DBG_ERROR(0,
"Could not encipher data (%d)", rv);
364 fprintf(stderr,
"Encrypted data is:\n");
367 dlen=
sizeof(decrypted);
377 DBG_ERROR(0,
"Could not decipher data (%d)", rv);
381 if (memcmp(clearText, decrypted, dlen)) {
382 DBG_ERROR(0,
"Deciphered data does not equal clear text(%d)", rv);
385 fprintf(stderr,
"Deciphered data is ok.\n");
406 int main(
int argc,
char **argv) {
412 const char *localedir;
423 "Specify the configuration file",
424 "Specify the configuration file"
435 "force pin entry even if the error counter is not zero"
445 "Show this help screen",
446 "Show this help screen"
452 fprintf(stderr,
"Could not initialize Gwenhywfar.\n");
465 setlocale(LC_ALL,
"");
466 if (bindtextdomain(PACKAGE, localedir)==0)
467 fprintf(stderr,
"Error binding locale\n");
475 #ifdef DEBUG_GCT_TOOL
485 #ifdef GCT_IS_EXPERIMENTAL
486 fprintf(stderr,
"\n");
487 fprintf(stderr,
"\n");
488 fprintf(stderr,
"=================== WARNING ===================\n");
489 fprintf(stderr,
"This tool is still EXPERIMENTAL !!!\n");
490 fprintf(stderr,
"Please DON'T USE it with your daily key files !\n");
491 fprintf(stderr,
"===============================================\n");
492 fprintf(stderr,
"\n");
493 fprintf(stderr,
"\n");
503 fprintf(stderr,
"ERROR: Could not parse arguments main\n");
514 I18N(
" [GLOBAL OPTIONS] COMMAND "
515 "[LOCAL OPTIONS]\n"));
517 I18N(
"\nGlobal Options:\n"));
519 fprintf(stderr,
"ERROR: Could not create help string\n");
523 I18N(
"\nCommands:\n\n"));
526 " This command creates a crypt token"
530 " Display user data stored on the "
544 fprintf(stderr,
"ERROR: Command needed.\n");
548 if (strcasecmp(cmd,
"sign")==0) {
551 else if (strcasecmp(cmd,
"crypt")==0) {
555 fprintf(stderr,
"ERROR: Unknown command \"%s\".\n", cmd);
562 "WARNING: Could not deinitialize Gwenhywfar.\n");
#define GWEN_CRYPT_TOKEN_MODE_FORCE_PIN_ENTRY
struct GWEN_PLUGIN_MANAGER GWEN_PLUGIN_MANAGER
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
struct GWEN_DB_NODE GWEN_DB_NODE
struct GWEN_PLUGIN GWEN_PLUGIN
void GWEN_Logger_SetLevel(const char *logDomain, GWEN_LOGGER_LEVEL l)
void GWEN_Text_DumpString(const char *s, unsigned int l, unsigned int insert)
int GWEN_Crypt_Token_Sign(GWEN_CRYPT_TOKEN *ct, uint32_t keyId, GWEN_CRYPT_PADDALGO *a, const uint8_t *pInData, uint32_t inLen, uint8_t *pSignatureData, uint32_t *pSignatureLen, uint32_t *pSeqCounter, uint32_t gid)
GWEN_CRYPT_PADDALGO * GWEN_Crypt_PaddAlgo_new(GWEN_CRYPT_PADDALGOID id)
int GWEN_Crypt_Token_Encipher(GWEN_CRYPT_TOKEN *ct, uint32_t keyId, GWEN_CRYPT_PADDALGO *a, const uint8_t *pInData, uint32_t inLen, uint8_t *pOutData, uint32_t *pOutLen, uint32_t gid)
int GWEN_Crypt_Token_Close(GWEN_CRYPT_TOKEN *ct, int abandon, uint32_t gid)
int GWEN_Crypt_Token_Verify(GWEN_CRYPT_TOKEN *ct, uint32_t keyId, GWEN_CRYPT_PADDALGO *a, const uint8_t *pInData, uint32_t inLen, const uint8_t *pSignatureData, uint32_t signatureLen, uint32_t seqCounter, uint32_t gid)
struct GWEN_CRYPT_PADDALGO GWEN_CRYPT_PADDALGO
GWEN_PLUGIN * GWEN_PluginManager_GetPlugin(GWEN_PLUGIN_MANAGER *pm, const char *s)
GWEN_CRYPT_TOKEN * GWEN_Crypt_Token_Plugin_CreateToken(GWEN_PLUGIN *pl, const char *name)
#define GWEN_ARGS_FLAGS_HELP
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
GWEN_PLUGIN_MANAGER * GWEN_PluginManager_FindPluginManager(const char *s)
#define GWEN_ARGS_RESULT_HELP
#define GWEN_ARGS_RESULT_ERROR
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
#define GWEN_ARGS_MODE_STOP_AT_FREEPARAM
int GWEN_Args_Usage(const GWEN_ARGS *args, GWEN_BUFFER *ubuf, GWEN_ARGS_OUTTYPE ot)
struct GWEN_STRINGLISTSTRUCT GWEN_STRINGLIST
#define GWEN_ARGS_MODE_ALLOW_FREEPARAM
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
GWEN_STRINGLIST * GWEN_PathManager_GetPaths(const char *destLib, const char *pathName)
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
void GWEN_Buffer_free(GWEN_BUFFER *bf)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
struct GWEN_CRYPT_TOKEN GWEN_CRYPT_TOKEN
#define GWEN_ARGS_FLAGS_LAST
int GWEN_Crypt_Token_Open(GWEN_CRYPT_TOKEN *ct, int admin, uint32_t gid)
int GWEN_Logger_Open(const char *logDomain, const char *ident, const char *file, GWEN_LOGGER_LOGTYPE logtype, GWEN_LOGGER_FACILITY facility)
unsigned int GWEN_StringList_Count(const GWEN_STRINGLIST *sl)
#define DBG_ERROR(dbg_logger, format, args...)
const char * GWEN_StringList_FirstString(const GWEN_STRINGLIST *l)
int GWEN_Args_Check(int argc, char **argv, int startAt, uint32_t mode, const GWEN_ARGS *args, GWEN_DB_NODE *db)
#define GWEN_PM_LOCALEDIR
#define DBG_INFO(dbg_logger, format, args...)
int GWEN_Crypt_Token_Decipher(GWEN_CRYPT_TOKEN *ct, uint32_t keyId, GWEN_CRYPT_PADDALGO *a, const uint8_t *pInData, uint32_t inLen, uint8_t *pOutData, uint32_t *pOutLen, uint32_t gid)
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
void GWEN_Gui_SetGui(GWEN_GUI *gui)
GWEN_GUI * GWEN_Gui_CGui_new(void)
#define GWEN_ARGS_FLAGS_HAS_ARGUMENT
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
#define GWEN_DB_FLAGS_DEFAULT
void GWEN_Crypt_Token_AddModes(GWEN_CRYPT_TOKEN *ct, uint32_t f)