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

📄 stadev.c

📁 SecuDe是一个由安全应用程序接口组成,对验证机制、证件处理、PEM、X.400报文处理和密钥管理提供支持。SecuDe提供DES、 RSA杂凑函数、密钥生成以及数字签名的生成和核实等多种密码机制。
💻 C
📖 第 1 页 / 共 5 页
字号:
/*---------------------------------------------------------------------------+-----*//*							                     | GMD *//*   SYSTEM   STAPAC  -  Version 1.0		                             +-----*//*							                           *//*---------------------------------------------------------------------------------*//*							                           *//*    PACKAGE	STAMOD-stadevice                            VERSION 1.0	           *//*					                       DATE Januar 1992    *//*					                         BY Ursula Viebeg  *//*					                            Levona Eckstein*//*			       				                           *//*    FILENAME     					                           *//*	stadevice.c                       		         		   *//*							                           *//*    DESCRIPTION	   				                           *//*      This modul provides all functions for device handling, the                 *//*      SCT display  and secure messaging between DTE and SCT                      *//*      of the smartcard application interface                                     *//*							                           *//*    EXPORT		    DESCRIPTION 		                           *//*      Functions for Device Handling						   *//*	sca_init_sc()	      Request and initialize a smartcard	           *//*							                           *//*	sca_get_sc_info()     Get information about smartcard                      *//*							                           *//*	sca_get_sct_info()    Get information about registered SCTs 	           *//*							                           *//*	sca_eject_sc()	      Eject smartcard	                                   *//*							                           *//*      Function for SCT-Display						   *//*	sca_display()	      Print text on SCT display                            *//*      									   *//*      Function for Secure Messaging						   *//*	sca_set_mode()	      Set security mode                                    *//*                                                                                 *//*									           *//*      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()          sets sca_errmsg                                      *//*                                                                                 *//*      err_analyse()         error analyse and handling                           *//*                                                                                 *//*      sca_errno             global error variable                                *//*                                                                                 *//*      sca_errmsg            global pointer to error message                      *//*							                           *//*    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      *//*                                                                                 *//*                                 -  aux_util.c (libcrypt)                        *//*                                                                                 *//*	aux_cmp_ObjId()               compare two object_ids (part of alg_id)      *//*                                                                                 *//*							                           *//*				   -  sctint.c (libsm)                             *//*							                           *//*      sct_reset()                   Reset Smartcard Terminal                     *//*							                           *//*      sct_interface()               Send SCT command / receive SCT response      *//*							                           *//*      sct_perror()                  Print error message                          *//*							                           *//*      sct_get_errmsg()              Set sct_errmsg according to error number     *//*							                           *//*      sct_info()                    information about sct/sc                     *//*							                           *//*      sct_list()                    list of installed sct's                      *//*                                                                                 *//*      sct_errno                     global error variable set by SCT-interface   *//*							                           *//*      sct_errmsg                    global pointer to error message set by       *//*                                    SCT-interface                                *//*                                                                                 *//*                                                                                 *//*    INTERNAL                                                                     *//*                                                                                 *//*                                                                                 *//*                                                                                 *//*---------------------------------------------------------------------------------*//*-------------------------------------------------------------*//*   include-Files					       *//*-------------------------------------------------------------*/#include "stamod.h"#include "stamsg.h"#include "sctint.h"#include "sccom.h"#ifndef MAC#include <sys/types.h>#include <sys/stat.h>#else#include <stdlib.h>#endif /* !MAC */#include <stdio.h>#include <fcntl.h>#include <string.h>/*-------------------------------------------------------------*//*   extern declarations				       *//*-------------------------------------------------------------*/extern int      sct_reset();extern int      sct_interface();extern int      sct_perror();extern void     sct_get_errmsg();extern int      sct_info();extern int      sct_list();extern int      aux_cmp_ObjId();extern void     sta_aux_bytestr_free();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                    *//*-------------------------------------------------------------*//*   forward global declarations			       *//*-------------------------------------------------------------*/char            get_sct_keyid();char            get_sct_algid();void            err_analyse();/*-------------------------------------------------------------*//*   globale variable definitions			       *//*-------------------------------------------------------------*/unsigned int    sca_errno;	/* error number set by STAMOD       */char           *sca_errmsg;	/* pointer to error message set by  */ /* STAMOD                           *//*-------------------------------------------------------------*//*   type definitions					       *//*-------------------------------------------------------------*/#define BITNULL		(BitString *)0/*-------------------------------------------------------------*//*   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 SCTInfo  sctinfo;	/* structure of sct_info-parameter  */static Boolean  sc_expect;	/* = TRUE indicates: SC expected    */ /* = FALSE indicates: SC not needed */static Boolean  first_call = TRUE;	/* In case of first_call = TRUE     */ /* sct_reset will be called         *//*-------------------------------------------------------------*//*						         | GMD *//*						         +-----*//* PROC  sca_init_sc	          VERSION   1.0	    	       *//*				     DATE   Januar 1992	       *//*			      	       BY   U.Viebeg           *//*							       *//* DESCRIPTION						       *//*  Request and initialize a smartcard.		               *//*  Sca_init_sc has to be the first function to be called      *//*  before the communication with the smartcard is             *//*  possible.                                                  *//*							       *//*							       *//* IN			     DESCRIPTION		       *//*   sct_id		       SCT identifier		       *//*                                                             *//*   display_text              text which shall be             *//*                             displayed on the SCT-           *//*                             display or the NULL-Pointer     *//*   time_out                  Time-out in seconds             *//*							       *//* OUT							       *//*							       *//*							       *//* RETURN		     DESCRIPTION	      	       *//*   0	         	       o.k			       *//*  -1			       error			       *//*				 EEXECDEN		       *//*                               M_ETIME		       *//*                               M_ETEXT		       *//*							       *//* CALLED FUNCTIONS					       *//*  sct_info                   ERROR-Codes		       *//*			         ESIDUNK		       *//*							       *//*  sct_reset		       ERROR-Codes		       *//*			 	 ENOSHELL		       *//*                               EOPERR                        *//*			         EEMPTY                        *//*                               EMEMAVAIL                     *//*                               ECLERR                        *//*                               ESIDUNK                       *//*                               ERDERR                        *//*                               EINVARG		       *//*                               ETOOLONG		       *//*                               sw1/sw2 from SCT response     *//*                               T1 - ERROR                    *//*							       *//*  sct_interface	       ERROR-Codes	               *//*                               EINVARG		       *//*                               ETOOLONG		       *//*                               EMEMAVAIL		       *//*                               ESIDUNK                       *//*                               EPARMISSED                    *//*                               INVPAR                        *//*                               EINVINS                       *//*                               sw1/sw2 from SCT response     *//*                               T1 - ERROR                    *//*							       *//*  sta_aux_bytestr_free				       *//*							       *//*  err_analyse		      ERROR_Codes	               *//*				ENOSHELL		       *//*                              EOPERR                         *//*			        EEMPTY                         *//*                              ECLERR                         *//*                              ESIDUNK                        *//*                              ERDERR                         *//*							       *//*							       *//*  set_errmsg						       *//*							       *//*-------------------------------------------------------------*/intsca_init_sc(sct_id, display_text, time_out)	int             sct_id;	char           *display_text;	int             time_out;{	/*----------------------------------------------------------*/	/* Definitions					       */	/*----------------------------------------------------------*/	int             rc;	Bytestring      bstring;	/*----------------------------------------------------------*/	/* Statements					       */	/*----------------------------------------------------------*/	rc = 0;	sca_errno = M_NOERR;	sca_errmsg = NULL;#ifdef TEST	fprintf(stdout, "\n***** STAMOD-Routine sca_init_sc *********************************************\n\n");	fprintf(stdout, "input-parameters:\n");	fprintf(stdout, "sct_id:     %d\n", sct_id);	fprintf(stdout, "display_text: %s\n", display_text);	fprintf(stdout, "time_out(sec): %d\n", time_out);	fprintf(stdout, "\n\n");#endif	/*-----------------------------------------------------*/	/* Check input parameters			       */	/*-----------------------------------------------------*/	if (display_text != NULL) {		if (strlen(display_text) > MAXL_SCT_DISPLAY) {			sca_errno = M_ETEXT;			set_errmsg();			return (-1);		}	}	if ((time_out < 0) || (time_out > MAX_TIME)) {		sca_errno = M_ETIME;		set_errmsg();		return (-1);	}	/*-----------------------------------------------------*/	/* If first call == TRUE			       */	/* then reset SCT				       */	/*-----------------------------------------------------*/	if (first_call == TRUE) {		rc = sct_reset(sct_id);		if (rc < 0) {			sca_errno = sct_errno;			sca_errmsg = sct_errmsg;			err_analyse(sct_id);			return (-1);		}		first_call = FALSE;	}	/*-----------------------------------------------------*/	/* If SCT not initialized			       */	/* then reset SCT				       */	/* else if SC already inserted		       */	/* then return(EEXECDEN).                 */	/*-----------------------------------------------------*/	rc = sct_info(sct_id, &sctinfo);	if (rc < 0) {		sca_errno = sct_errno;		sca_errmsg = sct_errmsg;		return (-1);	}	if (sctinfo.port_open == FALSE) {	/* if port not open       */		rc = sct_reset(sct_id);	/* then reset port        */		if (rc < 0) {			sca_errno = sct_errno;			sca_errmsg = sct_errmsg;			err_analyse(sct_id);			return (-1);		}	}	/* end if */	else {		if (sctinfo.sc_request == TRUE) {	/* if sc already							 * inserted */			sca_errno = EEXECDEN;	/* then execution denied  */			set_errmsg();			return (-1);		}	}			/* end else */	/*-----------------------------------------------------*/	/* Prepare parameters for the SCT Interface          */	/*-----------------------------------------------------*/	command = S_REQUEST_SC;	request.rq_p2.time = time_out;	if (display_text == NULL)		request.rq_datafield.outtext = BYTENULL;	else {		bstring.nbytes = strlen(display_text);		bstring.bytes = display_text;		request.rq_datafield.outtext = &bstring;	}	/*-----------------------------------------------------*/	/* Call SCT Interface     			       */

⌨️ 快捷键说明

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