gwenhywfar 5.10.1
setsignseq.c
Go to the documentation of this file.
1/***************************************************************************
2 $RCSfile$
3 -------------------
4 cvs : $Id: create.c 892 2005-11-03 00:20:45Z aquamaniac $
5 begin : Tue May 03 2005
6 copyright : (C) 2005 by Martin Preuss
7 email : martin@libchipcard.de
8
9 ***************************************************************************
10 * Please see toplevel file COPYING for license details *
11 ***************************************************************************/
12
13#ifdef HAVE_CONFIG_H
14# include <config.h>
15#endif
16
17#include "globals.h"
18
19#include <gwenhywfar/debug.h>
20#include <gwenhywfar/ct.h>
21#include <gwenhywfar/ctplugin.h>
22#include <gwenhywfar/text.h>
23
24
25
26
27
28
29int setSignSeq(GWEN_DB_NODE *dbArgs, int argc, char **argv)
30{
31 GWEN_DB_NODE *db;
32 const char *ttype;
33 const char *tname;
35 unsigned int keyId;
36 unsigned int seq;
37 int rv;
38 const GWEN_ARGS args[]= {
39 {
41 GWEN_ArgsType_Int, /* type */
42 "keyId", /* name */
43 1, /* minnum */
44 1, /* maxnum */
45 "k", /* short option */
46 "key", /* long option */
47 "Key id (0 for any)", /* short description */
48 "Key id (0 for any)" /* long description */
49 },
50 {
52 GWEN_ArgsType_Int, /* type */
53 "seq", /* name */
54 1, /* minnum */
55 1, /* maxnum */
56 "s", /* short option */
57 "seq", /* long option */
58 "New sequence counter value", /* short description */
59 "New sequence counter value" /* long description */
60 },
61 {
63 GWEN_ArgsType_Char, /* type */
64 "tokenType", /* name */
65 1, /* minnum */
66 1, /* maxnum */
67 "t", /* short option */
68 "ttype", /* long option */
69 "Specify the crypt token type", /* short description */
70 "Specify the crypt token type" /* long description */
71 },
72 {
74 GWEN_ArgsType_Char, /* type */
75 "tokenName", /* name */
76 0, /* minnum */
77 1, /* maxnum */
78 "n", /* short option */
79 "tname", /* long option */
80 "Specify the crypt token name", /* short description */
81 "Specify the crypt token name" /* long description */
82 },
83 {
85 GWEN_ArgsType_Int, /* type */
86 "help", /* name */
87 0, /* minnum */
88 0, /* maxnum */
89 "h", /* short option */
90 "help", /* long option */
91 "Show this help screen", /* short description */
92 "Show this help screen" /* long description */
93 }
94 };
95
96 db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
97 rv=GWEN_Args_Check(argc, argv, 1,
99 args,
100 db);
101 if (rv==GWEN_ARGS_RESULT_ERROR) {
102 fprintf(stderr, "ERROR: Could not parse arguments\n");
103 return 1;
104 }
105 else if (rv==GWEN_ARGS_RESULT_HELP) {
106 GWEN_BUFFER *ubuf;
107
108 ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
109 if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
110 fprintf(stderr, "ERROR: Could not create help string\n");
111 return 1;
112 }
113 fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
114 GWEN_Buffer_free(ubuf);
115 return 0;
116 }
117
118 keyId=GWEN_DB_GetIntValue(db, "keyId", 0, 0);
119 seq=GWEN_DB_GetIntValue(db, "seq", 0, 0);
120
121 ttype=GWEN_DB_GetCharValue(db, "tokenType", 0, 0);
122 assert(ttype);
123
124 tname=GWEN_DB_GetCharValue(db, "tokenName", 0, 0);
125
126 /* get crypt token */
127 ct=getCryptToken(ttype, tname);
128 if (ct==0)
129 return 3;
130
131 if (GWEN_DB_GetIntValue(dbArgs, "forcePin", 0, 0))
133
134 /* open crypt token for use */
135 rv=GWEN_Crypt_Token_Open(ct, 0, 0);
136 if (rv) {
137 DBG_ERROR(0, "Could not open token");
138 return 3;
139 }
140 else {
141 const GWEN_CRYPT_TOKEN_KEYINFO *ki;
142
143 ki=GWEN_Crypt_Token_GetKeyInfo(ct, keyId,
145 0);
146 if (ki) {
148
151 rv=GWEN_Crypt_Token_SetKeyInfo(ct, keyId, nki, 0);
153 if (rv) {
154 DBG_ERROR(GWEN_LOGDOMAIN, "Unable to set sign counter (%d)", rv);
155 return 4;
156 }
157 }
158 }
159
160 /* close crypt token */
161 rv=GWEN_Crypt_Token_Close(ct, 0, 0);
162 if (rv) {
163 DBG_ERROR(0, "Could not close token");
164 return 3;
165 }
166
167 return 0;
168}
169
170
171
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
int GWEN_Crypt_Token_SetKeyInfo(GWEN_CRYPT_TOKEN *ct, uint32_t id, const GWEN_CRYPT_TOKEN_KEYINFO *ki, uint32_t gid)
Definition: ct.c:341
const GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_GetKeyInfo(GWEN_CRYPT_TOKEN *ct, uint32_t id, uint32_t flags, uint32_t gid)
Definition: ct.c:320
int GWEN_Crypt_Token_Open(GWEN_CRYPT_TOKEN *ct, int admin, uint32_t gid)
Definition: ct.c:222
int GWEN_Crypt_Token_Close(GWEN_CRYPT_TOKEN *ct, int abandon, uint32_t gid)
Definition: ct.c:265
void GWEN_Crypt_Token_AddModes(GWEN_CRYPT_TOKEN *ct, uint32_t f)
Definition: ct.c:202
#define GWEN_CRYPT_TOKEN_MODE_FORCE_PIN_ENTRY
Definition: ct.h:59
struct GWEN_CRYPT_TOKEN GWEN_CRYPT_TOKEN
Definition: ct.h:19
GWEN_CRYPT_TOKEN_KEYINFO * GWEN_Crypt_Token_KeyInfo_dup(const GWEN_CRYPT_TOKEN_KEYINFO *p_src)
Definition: ct_keyinfo.c:109
void GWEN_Crypt_Token_KeyInfo_free(GWEN_CRYPT_TOKEN_KEYINFO *p_struct)
Definition: ct_keyinfo.c:78
void GWEN_Crypt_Token_KeyInfo_SetSignCounter(GWEN_CRYPT_TOKEN_KEYINFO *p_struct, uint32_t p_src)
Definition: ct_keyinfo.c:371
struct GWEN_CRYPT_TOKEN_KEYINFO GWEN_CRYPT_TOKEN_KEYINFO
Definition: ct_keyinfo.h:127
#define GWEN_CRYPT_TOKEN_KEYFLAGS_HASSIGNCOUNTER
Definition: ct_keyinfo.h:104
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition: db.c:971
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
Definition: db.c:1381
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition: db.c:1163
#define GWEN_DB_FLAGS_DEFAULT
Definition: db.h:168
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
GWEN_CRYPT_TOKEN * getCryptToken(const char *ttype, const char *tname)
Definition: gcttool/main.c:71
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
#define GWEN_LOGDOMAIN
Definition: logger.h:35
int setSignSeq(GWEN_DB_NODE *dbArgs, int argc, char **argv)
Definition: setsignseq.c:29
int GWEN_Args_Check(int argc, char **argv, int startAt, uint32_t mode, const GWEN_ARGS *args, GWEN_DB_NODE *db)
Definition: src/base/args.c:45
int GWEN_Args_Usage(const GWEN_ARGS *args, GWEN_BUFFER *ubuf, GWEN_ARGS_OUTTYPE ot)
#define GWEN_ARGS_FLAGS_HAS_ARGUMENT
Definition: src/base/args.h:50
#define GWEN_ARGS_RESULT_ERROR
Definition: src/base/args.h:57
#define GWEN_ARGS_MODE_ALLOW_FREEPARAM
Definition: src/base/args.h:54
#define GWEN_ARGS_FLAGS_HELP
Definition: src/base/args.h:52
#define GWEN_ARGS_FLAGS_LAST
Definition: src/base/args.h:51
@ GWEN_ArgsOutType_Txt
Definition: src/base/args.h:68
@ GWEN_ArgsType_Int
Definition: src/base/args.h:63
@ GWEN_ArgsType_Char
Definition: src/base/args.h:62
#define GWEN_ARGS_RESULT_HELP
Definition: src/base/args.h:58