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/crypttoken.h> 29 #include <gwenhywfar/ct.h> 30 #include <gwenhywfar/ctplugin.h> 31 #include <gwenhywfar/text.h> 32 #include <gwenhywfar/mdigest.h> 48 #define GCT_LOGDOMAIN "GCT" 72 "User context id (0 for any)",
73 "User context id (0 for any)" 83 "Specify the crypt token type",
84 "Specify the crypt token type" 94 "Specify the crypt token name",
95 "Specify the crypt token name" 105 "Show this help screen",
106 "Show this help screen" 116 fprintf(stderr,
"ERROR: Could not parse arguments\n");
124 fprintf(stderr,
"ERROR: Could not create help string\n");
142 DBG_ERROR(0,
"Plugin manager not found");
153 ct=GWEN_CryptToken_Plugin_CreateToken(pl, 0, tname);
155 DBG_ERROR(0,
"Could not create crypt token");
160 GWEN_CryptToken_AddModes(ct, GWEN_CRYPTTOKEN_MODES_FORCE_PIN_ENTRY);
163 rv=GWEN_CryptToken_Open(ct, 0);
170 const GWEN_CRYPTTOKEN_CONTEXT *octx;
171 GWEN_CRYPTTOKEN_CONTEXT *ctx;
172 GWEN_CRYPTTOKEN_SIGNINFO *si;
173 uint8_t clearText[96]= {
174 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
175 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
176 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
177 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
178 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
179 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
180 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
181 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
182 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
183 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
184 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
185 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
188 octx=GWEN_CryptToken_GetContextById(ct, 0x01);
195 ctx=GWEN_CryptToken_Context_dup(octx);
196 si=GWEN_CryptToken_Context_GetSignInfo(ctx);
197 GWEN_CryptToken_SignInfo_SetHashAlgo(si, GWEN_CryptToken_HashAlgo_None);
198 GWEN_CryptToken_SignInfo_SetPaddAlgo(si, GWEN_CryptToken_PaddAlgo_None);
201 rv=GWEN_CryptToken_Sign(ct, ctx, (
const char *)clearText, 96, dstBuf);
203 DBG_ERROR(0,
"Could not sign data (%d)", rv);
206 fprintf(stderr,
"Signature is:\n");
215 rv=GWEN_CryptToken_Close(ct);
246 "Context id (0 for any)",
247 "Context id (0 for any)" 257 "Specify the crypt token type",
258 "Specify the crypt token type" 268 "Specify the crypt token name",
269 "Specify the crypt token name" 279 "Show this help screen",
280 "Show this help screen" 290 fprintf(stderr,
"ERROR: Could not parse arguments\n");
298 fprintf(stderr,
"ERROR: Could not create help string\n");
316 DBG_ERROR(0,
"Plugin manager not found");
329 DBG_ERROR(0,
"Could not create crypt token");
343 uint8_t clearText[96]= {
344 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
345 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
346 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
347 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
348 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
349 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
350 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
351 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
352 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
353 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
354 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
355 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
357 uint8_t signature[256];
362 signLen=
sizeof(signature);
373 DBG_ERROR(0,
"Could not sign data (%d)", rv);
377 fprintf(stderr,
"Signature is:\n");
389 DBG_ERROR(0,
"Could not verify data (%d)", rv);
392 fprintf(stderr,
"Signature is ok.\n");
427 "User context id (0 for any)",
428 "User context id (0 for any)" 438 "Specify the crypt token type",
439 "Specify the crypt token type" 449 "Specify the crypt token name",
450 "Specify the crypt token name" 460 "Show this help screen",
461 "Show this help screen" 471 fprintf(stderr,
"ERROR: Could not parse arguments\n");
479 fprintf(stderr,
"ERROR: Could not create help string\n");
497 DBG_ERROR(0,
"Plugin manager not found");
508 ct=GWEN_CryptToken_Plugin_CreateToken(pl, 0, tname);
510 DBG_ERROR(0,
"Could not create crypt token");
515 GWEN_CryptToken_AddModes(ct, GWEN_CRYPTTOKEN_MODES_FORCE_PIN_ENTRY);
518 rv=GWEN_CryptToken_Open(ct, 0);
525 const GWEN_CRYPTTOKEN_CONTEXT *octx;
526 GWEN_CRYPTTOKEN_CONTEXT *ctx;
527 GWEN_CRYPTTOKEN_CRYPTINFO *ci;
529 uint8_t clearText[96]= {
530 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
531 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
532 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
533 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
534 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
535 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
536 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
537 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
538 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
539 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
540 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
541 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
544 octx=GWEN_CryptToken_GetContextById(ct, 0x01);
551 ctx=GWEN_CryptToken_Context_dup(octx);
552 ci=GWEN_CryptToken_Context_GetCryptInfo(ctx);
553 GWEN_CryptToken_CryptInfo_SetPaddAlgo(ci, GWEN_CryptToken_PaddAlgo_None);
558 rv=GWEN_CryptToken_Encrypt(ct, ctx, (
const char *)clearText, 96, dstBuf);
560 DBG_ERROR(0,
"Could not encrypt data (%d)", rv);
563 fprintf(stderr,
"Result is:\n");
572 rv=GWEN_CryptToken_Close(ct);
602 "Context id (0 for any)",
603 "Context id (0 for any)" 613 "Specify the crypt token type",
614 "Specify the crypt token type" 624 "Specify the crypt token name",
625 "Specify the crypt token name" 635 "Show this help screen",
636 "Show this help screen" 646 fprintf(stderr,
"ERROR: Could not parse arguments\n");
654 fprintf(stderr,
"ERROR: Could not create help string\n");
672 DBG_ERROR(0,
"Plugin manager not found");
685 DBG_ERROR(0,
"Could not create crypt token");
699 uint8_t clearText[96]= {
700 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
701 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
702 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
703 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
704 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
705 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
706 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
707 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
708 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
709 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
710 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
711 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
713 uint8_t encrypted[128];
718 elen=
sizeof(encrypted);
728 DBG_ERROR(0,
"Could not encipher data (%d)", rv);
732 fprintf(stderr,
"Encrypted data is:\n");
767 "Context id (0 for any)",
768 "Context id (0 for any)" 778 "Specify the crypt token type",
779 "Specify the crypt token type" 789 "Specify the crypt token name",
790 "Specify the crypt token name" 800 "Show this help screen",
801 "Show this help screen" 811 fprintf(stderr,
"ERROR: Could not parse arguments\n");
819 fprintf(stderr,
"ERROR: Could not create help string\n");
837 DBG_ERROR(0,
"Plugin manager not found");
850 DBG_ERROR(0,
"Could not create crypt token");
864 uint8_t clearText[96]= {
865 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
866 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
867 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
868 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
869 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
870 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
871 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
872 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
873 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
874 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
875 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
876 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
878 uint8_t encrypted[128];
880 uint8_t decrypted[128];
885 elen=
sizeof(encrypted);
895 DBG_ERROR(0,
"Could not encipher data (%d)", rv);
899 fprintf(stderr,
"Encrypted data is:\n");
902 dlen=
sizeof(decrypted);
912 DBG_ERROR(0,
"Could not decipher data (%d)", rv);
916 if (memcmp(clearText, decrypted, dlen)) {
917 DBG_ERROR(0,
"Deciphered data does not equal clear text(%d)", rv);
920 fprintf(stderr,
"Deciphered data is ok.\n");
941 int main(
int argc,
char **argv)
948 const char *localedir;
959 "Specify the configuration file",
960 "Specify the configuration file" 971 "force pin entry even if the error counter is not zero" 981 "Show this help screen",
982 "Show this help screen" 988 fprintf(stderr,
"Could not initialize Gwenhywfar.\n");
1001 setlocale(LC_ALL,
"");
1002 if (bindtextdomain(PACKAGE, localedir)==0)
1003 fprintf(stderr,
"Error binding locale\n");
1011 #ifdef DEBUG_GCT_TOOL 1021 #ifdef GCT_IS_EXPERIMENTAL 1022 fprintf(stderr,
"\n");
1023 fprintf(stderr,
"\n");
1024 fprintf(stderr,
"=================== WARNING ===================\n");
1025 fprintf(stderr,
"This tool is still EXPERIMENTAL !!!\n");
1026 fprintf(stderr,
"Please DON'T USE it with your daily key files !\n");
1027 fprintf(stderr,
"===============================================\n");
1028 fprintf(stderr,
"\n");
1029 fprintf(stderr,
"\n");
1039 fprintf(stderr,
"ERROR: Could not parse arguments main\n");
1050 I18N(
" [GLOBAL OPTIONS] COMMAND " 1051 "[LOCAL OPTIONS]\n"));
1053 I18N(
"\nGlobal Options:\n"));
1055 fprintf(stderr,
"ERROR: Could not create help string\n");
1059 I18N(
"\nCommands:\n\n"));
1062 " This command creates a crypt token" 1066 " Display user data stored on the " 1080 fprintf(stderr,
"ERROR: Command needed.\n");
1084 if (strcasecmp(cmd,
"sign1")==0) {
1087 else if (strcasecmp(cmd,
"sign2")==0) {
1090 else if (strcasecmp(cmd,
"crypt1")==0) {
1093 else if (strcasecmp(cmd,
"crypt2")==0) {
1096 else if (strcasecmp(cmd,
"crypt3")==0) {
1100 fprintf(stderr,
"ERROR: Unknown command \"%s\".\n", cmd);
1107 "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)
int signWithOld(GWEN_DB_NODE *dbArgs, int argc, char **argv)
struct GWEN_DB_NODE GWEN_DB_NODE
struct GWEN_PLUGIN GWEN_PLUGIN
uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf)
void GWEN_Logger_SetLevel(const char *logDomain, GWEN_LOGGER_LEVEL l)
int cryptWithNew2(GWEN_DB_NODE *dbArgs, int argc, char **argv)
void GWEN_Text_DumpString(const char *s, unsigned int l, unsigned int insert)
int signWithNew(GWEN_DB_NODE *dbArgs, int argc, char **argv)
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 main(int argc, char **argv)
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)
int cryptWithOld(GWEN_DB_NODE *dbArgs, int argc, char **argv)
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)
int cryptWithNew(GWEN_DB_NODE *dbArgs, int argc, char **argv)
#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)