⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profile.c

📁 读写Smart卡加解密接口的程序
💻 C
📖 第 1 页 / 共 3 页
字号:
do_pin_offset(struct state *cur, int argc, char **argv){	return get_uint(cur, argv[0], &cur->pin->file_offset);}static intdo_pin_attempts(struct state *cur, int argc, char **argv){	struct pin_info	*pi = cur->pin;	unsigned int	count;	if (get_uint(cur, argv[0], &count))		return 1;	pi->pin.tries_left = count;	return 0;}static intdo_pin_type(struct state *cur, int argc, char **argv){	unsigned int	type;	if (map_str2int(cur, argv[0], &type, pinTypeNames))		return 1;	cur->pin->pin.type = type;	return 0;}static intdo_pin_reference(struct state *cur, int argc, char **argv){	unsigned int	reference;	if (get_uint(cur, argv[0], &reference))		return 1;	cur->pin->pin.reference = reference;	return 0;}static intdo_pin_authid(struct state *cur, int argc, char **argv){	sc_pkcs15_format_id(argv[0], &cur->pin->pin.auth_id);	return 0;}static intdo_pin_minlength(struct state *cur, int argc, char **argv){	unsigned int	len;	if (get_uint(cur, argv[0], &len))		return 1;	cur->pin->pin.min_length = len;	return 0;}static intdo_pin_maxlength(struct state *cur, int argc, char **argv){	unsigned int	len;	if (get_uint(cur, argv[0], &len))		return 1;	cur->pin->pin.stored_length = len;	return 0;}static intdo_pin_flags(struct state *cur, int argc, char **argv){	unsigned int	flags;	if (map_str2int(cur, argv[0], &flags, pinTypeNames))		return 1;	cur->pin->pin.flags = flags;	return 0;}/* * Key section */static struct command	key_commands[] = { { "value",		1,	1,	do_key_value	}, { NULL }};/* * Cardinfo section */static struct command	ci_commands[] = { { "driver",		1,	1,	do_card_driver	}, { "max-pin-length",	1,	1,	do_maxpinlength	}, { "min-pin-length",	1,	1,	do_minpinlength	}, { "pin-encoding",	1,	1,	do_default_pin_type }, { "pin-pad-char",	1,	1,	do_pin_pad_char }, { "label",		1,	1,	do_card_label	}, { "manufacturer",	1,	1,	do_card_manufacturer}, { NULL, 0, 0, NULL }};static struct block	ci_blocks[] = { { "key",		process_key,	key_commands,	NULL	}, { NULL }};/* * Filesystem section */static struct command	fs_commands[] = { { "type",		1,	1,	do_file_type	}, { "path",		1,	1,	do_file_path	}, { "file-id",		1,	1,	do_fileid	}, { "structure",		1,	1,	do_structure	}, { "size",		1,	1,	do_size		}, { "record-length",	1,	1,	do_reclength	}, { "AID",		1,	1,	do_aid		}, { "ACL",		1,	-1,	do_acl		}, { NULL, 0, 0, NULL }};static struct block	fs_blocks[] = { { "DF",		process_df,	fs_commands,	fs_blocks }, { "EF",		process_ef,	fs_commands,	fs_blocks }, { NULL, NULL, NULL, NULL }};/* * Pin section */static struct command	pi_commands[] = { { "file",		1,	1,	do_pin_file	}, { "offset",		1,	1,	do_pin_offset	}, { "attempts",		1,	2,	do_pin_attempts	}, { "encoding",		1,	1,	do_pin_type	}, { "reference",		1,	1,	do_pin_reference}, { "auth-id",		1,	1,	do_pin_authid	}, { "max-length",	1,	1,	do_pin_maxlength}, { "min-length",	1,	1,	do_pin_minlength}, { "flags",		1,	1,	do_pin_flags	}, { NULL, 0, 0, NULL }};static struct block	root_blocks[] = { { "filesystem",	process_block,	NULL,		fs_blocks }, { "cardinfo",		process_block,	ci_commands,	ci_blocks }, { "pin",		process_pin,	pi_commands,	NULL	}, { NULL, NULL , NULL }};static struct block	root_ops = {   "root",		process_block,	NULL,		root_blocks};static intprocess_command(struct state *cur, struct command *cmd_info, scconf_list *list){	const char	*cmd = cmd_info->name;	char		*argv[16];	unsigned int	argc, max = 16;	/* count arguments first */	for (argc = 0; list; list = list->next) {		if (argc >= max)			goto toomany;		argv[argc++] = list->data;	}	if (argc < cmd_info->min_args) {		parse_error(cur, "%s: not enough arguments\n", cmd);		return 1;	}	if (0 <= cmd_info->max_args && cmd_info->max_args < argc) {toomany:	parse_error(cur, "%s: too many arguments\n", cmd);		return 1;	}	return cmd_info->func(cur, argc, argv);}static struct block *find_block_handler(struct block *bp, const char *name){	if (bp == NULL)		return NULL;	for (; bp->name; bp++) {		if (!strcasecmp(bp->name, name))			return bp;	}	return NULL;}static struct command *find_cmd_handler(struct command *cp, const char *name){	if (cp == NULL)		return NULL;	for (; cp->name; cp++) {		if (!strcasecmp(cp->name, name))			return cp;	}	return NULL;}static intprocess_block(struct state *cur, struct block *info,		const char *name, scconf_block *blk){	scconf_item	*item;	struct command	*cp;	struct block	*bp;	const char	*cmd, *ident;	int		res = 0;	for (item = blk->items; res == 0 && item; item = item->next) {		cmd = item->key;		if (item->type == SCCONF_ITEM_TYPE_COMMENT)			continue;		if (item->type == SCCONF_ITEM_TYPE_BLOCK) {			scconf_list *nlist;			ident = NULL;			if ((nlist = item->value.block->name) != NULL) {				if (nlist->next) {					parse_error(cur,						"Too many name components "						"in block name.");					return SC_ERROR_SYNTAX_ERROR;				}				ident = nlist->data;			}#if 0			printf("Processing %s %s\n",				cmd, ident? ident : "");#endif			if ((bp = find_block_handler(info->blk_info, cmd))) {				res = bp->handler(cur, bp, ident,						item->value.block);				continue;			}		} else		if (item->type == SCCONF_ITEM_TYPE_VALUE) {			if ((cp = find_cmd_handler(info->cmd_info, cmd))) {				res = process_command(cur, cp,						item->value.list);				continue;			}		}		parse_error(cur,			"Command \"%s\" not understood in this context.", cmd);		return SC_ERROR_SYNTAX_ERROR;	}	if (res > 0)		res = SC_ERROR_SYNTAX_ERROR;	return res;}static intprocess_conf(struct sc_profile *profile, scconf_context *conf){	struct state	state;	memset(&state, 0, sizeof(state));	state.filename = conf->filename;	state.profile = profile;	return process_block(&state, &root_ops, "root", conf->root);}static struct file_info *sc_profile_find_file(struct sc_profile *pro, const char *name){	struct file_info	*fi;	for (fi = pro->ef_list; fi; fi = fi->next) {		if (!strcasecmp(fi->ident, name)) 			return fi;	}	return NULL;}struct file_info *sc_profile_find_file_by_path(struct sc_profile *pro, const struct sc_path *path){	struct file_info *fi;	struct sc_file	*fp;	for (fi = pro->ef_list; fi; fi = fi->next) {		fp = fi->file;		if (fp->path.len == path->len		 && !memcmp(fp->path.value, path->value, path->len))			return fi;	}	return NULL;}voidsc_profile_set_secret(struct sc_profile *profile,		unsigned int type, unsigned int ref,		const u8 *key, size_t key_len){	struct auth_info *ai;	ai = new_key(profile, type, ref);	if (key_len)		memcpy(ai->key, key, key_len);	ai->key_len = key_len;}intsc_profile_get_secret(struct sc_profile *profile,		unsigned int type, unsigned int ref,		u8 *key, size_t *len){	struct auth_info *ai, **aip;	for (aip = &profile->auth_list; (ai = *aip); aip = &ai->next) {		if (ai->type == type && ai->ref == ref) {			if (ai->key_len > *len)				return SC_ERROR_BUFFER_TOO_SMALL;			memcpy(key, ai->key, ai->key_len);			*len = ai->key_len;			return 0;		}	}	return SC_ERROR_OBJECT_NOT_FOUND;}voidsc_profile_forget_secrets(struct sc_profile *profile,		unsigned int type, int ref){	struct auth_info *ai, **aip;	aip = &profile->auth_list;	while ((ai = *aip) != NULL) {		if (ai->type == type		 && (ref < 0 || ai->ref == (unsigned int) ref)) {			*aip = ai->next;			free(ai);		} else {			aip = &ai->next;		}	}}voidsc_profile_set_so_pin(struct sc_profile *profile, const char *value){	if (!value)		return;	sc_profile_set_secret(profile, SC_AC_SYMBOLIC,			SC_PKCS15INIT_SO_PIN, (u8 *) value, strlen(value));}voidsc_profile_set_user_pin(struct sc_profile *profile, const char *value){	if (!value)		return;	sc_profile_set_secret(profile, SC_AC_SYMBOLIC,			SC_PKCS15INIT_USER_PIN, (u8 *) value, strlen(value));}/* * Split up KEY0 or CHV1 into SC_AC_XXX and a number */static intget_authid(struct state *cur, const char *value,		unsigned int *type, unsigned int *num){	char	temp[16];	int	n;	if (isdigit((int) *value)) {		*num = 0;		return get_uint(cur, value, type);	}	n = strcspn(value, "0123456789");	strncpy(temp, value, n);	temp[n] = '\0';	if (map_str2int(cur, temp, type, aclNames))		return 1;	if (value[n])		return get_uint(cur, value + n, num);	*num = 0;	return 0;}static intget_uint(struct state *cur, const char *value, unsigned int *vp){	const char	*ep;	*vp = strtoul(value, (char **) &ep, 0);	if (*ep != '\0') {		parse_error(cur, 			"invalid integer argument \"%s\"\n", value);		return 1;	}	return 0;}static intmap_str2int(struct state *cur, const char *value,		unsigned int *vp, struct map *map){	unsigned int	n;	const char	*what;	if (isdigit((int) *value))		return get_uint(cur, value, vp);	for (n = 0; map[n].name; n++) {		if (!strcasecmp(value, map[n].name)) {			*vp = map[n].val;			return 0;		}	}	/* Try to print a meaningful error message */	what = "argument";	for (n = 0; mapNames[n].name; n++) {		if (mapNames[n].addr == map) {			what = mapNames[n].name;			break;		}	}	parse_error(cur, "invalid %s \"%s\"\n", what, value);	return 1;}static intsetstr(char **strp, const char *value){	if (*strp)		free(*strp);	*strp = strdup(value);	return 0;}static voidparse_error(struct state *cur, const char *fmt, ...){	char	buffer[1024], *sp;	va_list	ap;	va_start(ap, fmt);	vsnprintf(buffer, sizeof(buffer), fmt, ap);	va_end(ap);	if ((sp = strchr(buffer, '\n')) != NULL)		*sp = '\0';	if (cur->profile->cbs)		cur->profile->cbs->error("%s: %s",			cur->filename, buffer);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -