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"
71 "User context id (0 for any)",
72 "User 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");
152 ct=GWEN_CryptToken_Plugin_CreateToken(pl, 0, tname);
154 DBG_ERROR(0,
"Could not create crypt token");
159 GWEN_CryptToken_AddModes(ct, GWEN_CRYPTTOKEN_MODES_FORCE_PIN_ENTRY);
162 rv=GWEN_CryptToken_Open(ct, 0);
169 const GWEN_CRYPTTOKEN_CONTEXT *octx;
170 GWEN_CRYPTTOKEN_CONTEXT *ctx;
171 GWEN_CRYPTTOKEN_SIGNINFO *si;
172 uint8_t clearText[96]={
173 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
174 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
175 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
176 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
177 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
178 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
179 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
180 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
181 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
182 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
183 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
184 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
187 octx=GWEN_CryptToken_GetContextById(ct, 0x01);
194 ctx=GWEN_CryptToken_Context_dup(octx);
195 si=GWEN_CryptToken_Context_GetSignInfo(ctx);
196 GWEN_CryptToken_SignInfo_SetHashAlgo(si, GWEN_CryptToken_HashAlgo_None);
197 GWEN_CryptToken_SignInfo_SetPaddAlgo(si, GWEN_CryptToken_PaddAlgo_None);
200 rv=GWEN_CryptToken_Sign(ct, ctx, (
const char*)clearText, 96, dstBuf);
202 DBG_ERROR(0,
"Could not sign data (%d)", rv);
205 fprintf(stderr,
"Signature is:\n");
214 rv=GWEN_CryptToken_Close(ct);
244 "Context id (0 for any)",
245 "Context id (0 for any)"
255 "Specify the crypt token type",
256 "Specify the crypt token type"
266 "Specify the crypt token name",
267 "Specify the crypt token name"
277 "Show this help screen",
278 "Show this help screen"
288 fprintf(stderr,
"ERROR: Could not parse arguments\n");
296 fprintf(stderr,
"ERROR: Could not create help string\n");
314 DBG_ERROR(0,
"Plugin manager not found");
327 DBG_ERROR(0,
"Could not create crypt token");
341 uint8_t clearText[96]={
342 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
343 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
344 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
345 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
346 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
347 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
348 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
349 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
350 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
351 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
352 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
353 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
355 uint8_t signature[256];
360 signLen=
sizeof(signature);
371 DBG_ERROR(0,
"Could not sign data (%d)", rv);
375 fprintf(stderr,
"Signature is:\n");
387 DBG_ERROR(0,
"Could not verify data (%d)", rv);
390 fprintf(stderr,
"Signature is ok.\n");
424 "User context id (0 for any)",
425 "User context id (0 for any)"
435 "Specify the crypt token type",
436 "Specify the crypt token type"
446 "Specify the crypt token name",
447 "Specify the crypt token name"
457 "Show this help screen",
458 "Show this help screen"
468 fprintf(stderr,
"ERROR: Could not parse arguments\n");
476 fprintf(stderr,
"ERROR: Could not create help string\n");
494 DBG_ERROR(0,
"Plugin manager not found");
505 ct=GWEN_CryptToken_Plugin_CreateToken(pl, 0, tname);
507 DBG_ERROR(0,
"Could not create crypt token");
512 GWEN_CryptToken_AddModes(ct, GWEN_CRYPTTOKEN_MODES_FORCE_PIN_ENTRY);
515 rv=GWEN_CryptToken_Open(ct, 0);
522 const GWEN_CRYPTTOKEN_CONTEXT *octx;
523 GWEN_CRYPTTOKEN_CONTEXT *ctx;
524 GWEN_CRYPTTOKEN_CRYPTINFO *ci;
526 uint8_t clearText[96]={
527 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
528 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
529 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
530 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
531 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
532 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
533 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
534 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
535 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
536 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
537 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
538 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
541 octx=GWEN_CryptToken_GetContextById(ct, 0x01);
548 ctx=GWEN_CryptToken_Context_dup(octx);
549 ci=GWEN_CryptToken_Context_GetCryptInfo(ctx);
550 GWEN_CryptToken_CryptInfo_SetPaddAlgo(ci, GWEN_CryptToken_PaddAlgo_None);
555 rv=GWEN_CryptToken_Encrypt(ct, ctx, (
const char*)clearText, 96, dstBuf);
557 DBG_ERROR(0,
"Could not encrypt data (%d)", rv);
560 fprintf(stderr,
"Result is:\n");
569 rv=GWEN_CryptToken_Close(ct);
598 "Context id (0 for any)",
599 "Context id (0 for any)"
609 "Specify the crypt token type",
610 "Specify the crypt token type"
620 "Specify the crypt token name",
621 "Specify the crypt token name"
631 "Show this help screen",
632 "Show this help screen"
642 fprintf(stderr,
"ERROR: Could not parse arguments\n");
650 fprintf(stderr,
"ERROR: Could not create help string\n");
668 DBG_ERROR(0,
"Plugin manager not found");
681 DBG_ERROR(0,
"Could not create crypt token");
695 uint8_t clearText[96]={
696 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
697 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
698 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
699 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
700 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
701 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
702 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
703 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
704 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
705 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
706 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
707 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
709 uint8_t encrypted[128];
714 elen=
sizeof(encrypted);
724 DBG_ERROR(0,
"Could not encipher data (%d)", rv);
728 fprintf(stderr,
"Encrypted data is:\n");
762 "Context id (0 for any)",
763 "Context id (0 for any)"
773 "Specify the crypt token type",
774 "Specify the crypt token type"
784 "Specify the crypt token name",
785 "Specify the crypt token name"
795 "Show this help screen",
796 "Show this help screen"
806 fprintf(stderr,
"ERROR: Could not parse arguments\n");
814 fprintf(stderr,
"ERROR: Could not create help string\n");
832 DBG_ERROR(0,
"Plugin manager not found");
845 DBG_ERROR(0,
"Could not create crypt token");
859 uint8_t clearText[96]={
860 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
861 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
862 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
863 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
864 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
865 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
866 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
867 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
868 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
869 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
870 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
871 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60
873 uint8_t encrypted[128];
875 uint8_t decrypted[128];
880 elen=
sizeof(encrypted);
890 DBG_ERROR(0,
"Could not encipher data (%d)", rv);
894 fprintf(stderr,
"Encrypted data is:\n");
897 dlen=
sizeof(decrypted);
907 DBG_ERROR(0,
"Could not decipher data (%d)", rv);
911 if (memcmp(clearText, decrypted, dlen)) {
912 DBG_ERROR(0,
"Deciphered data does not equal clear text(%d)", rv);
915 fprintf(stderr,
"Deciphered data is ok.\n");
936 int main(
int argc,
char **argv) {
942 const char *localedir;
953 "Specify the configuration file",
954 "Specify the configuration file"
965 "force pin entry even if the error counter is not zero"
975 "Show this help screen",
976 "Show this help screen"
982 fprintf(stderr,
"Could not initialize Gwenhywfar.\n");
995 setlocale(LC_ALL,
"");
996 if (bindtextdomain(PACKAGE, localedir)==0)
997 fprintf(stderr,
"Error binding locale\n");
1005 #ifdef DEBUG_GCT_TOOL
1015 #ifdef GCT_IS_EXPERIMENTAL
1016 fprintf(stderr,
"\n");
1017 fprintf(stderr,
"\n");
1018 fprintf(stderr,
"=================== WARNING ===================\n");
1019 fprintf(stderr,
"This tool is still EXPERIMENTAL !!!\n");
1020 fprintf(stderr,
"Please DON'T USE it with your daily key files !\n");
1021 fprintf(stderr,
"===============================================\n");
1022 fprintf(stderr,
"\n");
1023 fprintf(stderr,
"\n");
1033 fprintf(stderr,
"ERROR: Could not parse arguments main\n");
1044 I18N(
" [GLOBAL OPTIONS] COMMAND "
1045 "[LOCAL OPTIONS]\n"));
1047 I18N(
"\nGlobal Options:\n"));
1049 fprintf(stderr,
"ERROR: Could not create help string\n");
1053 I18N(
"\nCommands:\n\n"));
1056 " This command creates a crypt token"
1060 " Display user data stored on the "
1074 fprintf(stderr,
"ERROR: Command needed.\n");
1078 if (strcasecmp(cmd,
"sign1")==0) {
1081 else if (strcasecmp(cmd,
"sign2")==0) {
1084 else if (strcasecmp(cmd,
"crypt1")==0) {
1087 else if (strcasecmp(cmd,
"crypt2")==0) {
1090 else if (strcasecmp(cmd,
"crypt3")==0) {
1094 fprintf(stderr,
"ERROR: Unknown command \"%s\".\n", cmd);
1101 "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)