📄 staauth.c
字号:
/*---------------------------------------------------------------------------+-----*//* | GMD *//* SYSTEM STAPAC - Version 1.0 +-----*//* *//*---------------------------------------------------------------------------------*//* *//* PACKAGE STAMOD-staauth VERSION 1.0 *//* DATE Januar 1992 *//* BY Ursula Viebeg *//* Levona Eckstein*//* *//* FILENAME *//* staauth.c *//* *//* DESCRIPTION *//* This modul provides all functions for user authentication and device *//* authentication of the smartcard application interface (SCA-IF). *//* *//* EXPORT DESCRIPTION *//* Functions for User Authentication *//* sca_inst_pin() Install PIN on the smartcard *//* *//* sca_change_pin() Change PIN *//* *//* sca_check_pin() PIN authentication *//* *//* sca_unblock_pin() Unblock a blocked PIN *//* *//* Functions for Device Authentication *//* sca_auth() Device authentication *//* *//* sca_gen_dev_key() Generate device key *//* *//* sca_inst_dev_key() Install device key on user smartcard *//* *//* sca_del_dev_key() Delete device key in SCT *//* *//* sca_read_keycard() Read key(s) from keycard *//* *//* sca_write_keycard() Write key(s) on keycard *//* *//* *//* *//* IMPORT DESCRIPTION *//* - aux_xdmp.c (libcrypt) *//* *//* aux_fxdump() dump buffer in File *//* *//* *//* - sta_free.c (libsm) *//* *//* sta_aux_bytestr_free() set the bytes-buffer in Bytestring free *//* *//* - sctint.c (libsm) *//* sct_interface() Send SCT command / receive SCT response *//* *//* sct_errno global error variable set by SCT-interface *//* *//* sct_errmsg global pointer to error message set by *//* SCT-interface *//* *//* - sta_dev.c (libsm) *//* *//* get_sct_keyid() check key_id and get key_id in char *//* representation *//* *//* get_sct_algid() check alg_id and get SCT specific alg_id *//* *//* check_sct_sc() check SCT and SC *//* *//* check_key_attr_list() check key attribute list *//* *//* check_sec_mess() check security mode(s) for command and response*//* *//* set_errmsg() set sca_errmsg *//* *//* err_analyse() error analyse and handling *//* *//* sca_errno global error variable set by STAMOD *//* *//* sca_errmsg global pointer to error message set by STAMOD*//* *//* *//* - stacrypt.c (libsm) *//* *//* - stasc.c (libsm) *//* *//* get_bits() get bits *//* *//* *//* - staprint.c (libsm) for TEST-output *//* *//* print_keyid() *//* print_keydevpurpose() *//* print_keydevsel() *//* print_keyattrlist() *//* print_pinstruc() *//* print_secmess() *//* *//* *//* *//* *//* *//* INTERNAL *//* *//* get_PIN_PUK_body() compose PIN or PUK body for the PIN installation *//* *//* *//*---------------------------------------------------------------------------------*//*-------------------------------------------------------------*//* include-Files *//*-------------------------------------------------------------*/#include "stamod.h"#include "stamsg.h"#include "sctint.h"#include "sccom.h"#ifndef MAC#include <sys/types.h>#include <sys/stat.h>#endif /* !MAC */#include <stdio.h>#include <fcntl.h>#include <string.h>/*-------------------------------------------------------------*//* extern declarations *//*-------------------------------------------------------------*/extern char get_sct_keyid();extern char get_sct_algid();extern int get_alg_number();extern int check_sct_sc();extern int check_key_attr_list();extern int check_sec_mess();extern int set_errmsg();extern void err_analyse();extern int sct_interface();extern void sta_aux_bytestr_free();extern unsigned int get_bits();extern void aux_fxdump();extern unsigned int sct_errno; /* error number set by SCT-Interface */extern char *sct_errmsg; /* pointer to error msg set by */ /* SCT-Interface */extern unsigned int sca_errno; /* error number set by STAMOD */extern char *sca_errmsg; /* pointer to error msg set by */ /* STAMOD */#ifdef TESTextern void print_keyid();extern void print_keydevpurpose();extern void print_keydevsel();extern void print_keyattrlist();extern void print_pinstruc();extern void print_keydevlist();extern void print_secmess();#endif/*-------------------------------------------------------------*//* globale variable definitions *//*-------------------------------------------------------------*//*-------------------------------------------------------------*//* type definitions *//*-------------------------------------------------------------*//*-------------------------------------------------------------*//* local Variable definitions *//*-------------------------------------------------------------*/static Request request; /* body of the SCT commands */static Bytestring response; /* body of the response of the SCT */static int command; /* INS-Code of the SCT command */static Boolean sc_expect; /* = TRUE indicates: SC expected */ /* = FALSE indicates: SC not needed */static KindOfKey kind_of_key; /* {USER_KEY, PIN_KEY, PUK_KEY, */ /* DEVICE} *//*-------------------------------------------------------------*//* forward global declarations *//*-------------------------------------------------------------*/static int get_PIN_PUK_body();/*-------------------------------------------------------------*//* | GMD *//* +-----*//* PROC sca_inst_pin VERSION 1.0 *//* DATE Januar 1992 *//* BY U.Viebeg *//* *//* DESCRIPTION *//* Install Personal Identification Number (PIN) on the *//* smartcard. *//* A smartcard must be inserted. *//* *//* *//* IN DESCRIPTION *//* sct_id SCT identifier *//* *//* key_id key_id of the PIN to be *//* installed *//* *//* pin Structure which determines the *//* PIN to be installed *//* *//* key_attr_list Structure which contains *//* additional information for *//* storing a PIN on the SC *//* *//* OUT *//* *//* *//* RETURN DESCRIPTION *//* 0 o.k *//* -1 error *//* EINVKID *//* M_EPIN *//* *//* CALLED FUNCTIONS *//* check_sct_sc ERROR-Codes *//* ENOCARD *//* ESIDUNK *//* ENOSHELL *//* EOPERR *//* EEMPTY *//* EMEMAVAIL *//* ECLERR *//* ESIDUNK *//* ERDERR *//* EINVARG *//* ETOOLONG *//* sw1/sw2 from SCT response *//* T1 - ERROR *//* *//* get_sct_keyid ERROR-Codes *//* EINVKID *//* *//* check_key_attr_list ERROR-Codes *//* M_EKEYATTR *//* *//* get_PIN_PUK_body ERROR-Codes *//* M_EMEMORY *//* *//* sct_interface ERROR-Codes *//* EINVARG *//* ETOOLONG *//* EMEMAVAIL *//* ESIDUNK *//* EPARMISSED *//* INVPAR *//* EINVINS *//* sw1/sw2 from SCT response *//* T1 - ERROR *//* *//* err_analyse ERROR_Codes *//* ENOSHELL *//* EOPERR *//* EEMPTY *//* ECLERR *//* ESIDUNK *//* ERDERR *//* *//* set_errmsg *//* *//* sta_aux_bytestr_free *//* *//*-------------------------------------------------------------*/intsca_inst_pin(sct_id, key_id, pin, key_attr_list) int sct_id; KeyId *key_id; PINStruc *pin; KeyAttrList *key_attr_list;{ /*----------------------------------------------------------*/ /* Definitions */ /*----------------------------------------------------------*/ int rc; char sct_keyid; /* char representation of the key_id */ PINRecord pin_record; Bytestring pin_body; /*----------------------------------------------------------*/ /* Statements */ /*----------------------------------------------------------*/ rc = 0; sca_errno = M_NOERR; sca_errmsg = NULL; sc_expect = TRUE;#ifdef TEST fprintf(stdout, "\n***** STAMOD-Routine sca_inst_pin *****\n\n"); fprintf(stdout, "TRACE of the input parameters : \n"); fprintf(stdout, "sct_id : %d\n", sct_id); print_keyid(key_id); print_pinstruc(pin); print_keyattrlist(key_attr_list); fprintf(stdout, "\n\n");#endif /*-----------------------------------------------------*/ /* call check_sct_sc */ /*-----------------------------------------------------*/ if (check_sct_sc(sct_id, sc_expect) == -1) return (-1); /*-----------------------------------------------------*/ /* Check input parameters */ /*-----------------------------------------------------*/ /*-----------------------------------------------------*/ /* Check key_id */ /*-----------------------------------------------------*/ if ((key_id->key_level != SC_MF) && (key_id->key_level != SC_DF) && (key_id->key_level != SC_SF)) { sca_errno = EINVKID; set_errmsg(); return (-1); } if ((key_id->key_number < 1) ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -