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

📄 sctint.c

📁 SecuDe是一个由安全应用程序接口组成,对验证机制、证件处理、PEM、X.400报文处理和密钥管理提供支持。SecuDe提供DES、 RSA杂凑函数、密钥生成以及数字签名的生成和核实等多种密码机制。
💻 C
📖 第 1 页 / 共 4 页
字号:
		COMclose(p_elem->port_id);#ifdef TRACE		fprintf(sct_trfp, "CALL get_orgelem in sct_reset after p_elem->baud < 2400 \n");#endif		if (get_orgelem(sct_id, p_elem) == -1)			return (S_ERR);		sct_errno = EBAUD;		sct_errmsg = sct_error[sct_errno].msg;		return (S_ERR);	}	index = 0;	resetbaud = p_elem->baud;	while ((div / resetbaud) != 1) {		resetbaud = resetbaud * 2;		index++;	}	p_elem->baud = B19200 - index;#endif#ifdef SYSTEMV	/*------------------------------------*/	/* test baudrate			 */	/*------------------------------------*/	if (p_elem->baud < 2400) {		COMclose(p_elem->port_id);#ifdef TRACE		fprintf(sct_trfp, "CALL get_orgelem in sct_reset after p_elem->baud < 2400 \n");#endif		if (get_orgelem(sct_id, p_elem) == -1)			return (-1);		sct_errno = EBAUD;		sct_errmsg = sct_error[sct_errno].msg;		return (S_ERR);	}	index = 0;	resetbaud = p_elem->baud;	while ((div / resetbaud) != 1) {		resetbaud = resetbaud * 2;		index++;	}	p_elem->baud = B19200 - index;#endif#ifdef MAC   /* Baudrate zu klein? */   if (p_elem->baud < 2400)      {      COMclose(p_elem->port_id);      if (get_orgelem(sct_id,p_elem) == -1)         return(-1);      sct_errno = EBAUD;      sct_errmsg = sct_error[sct_errno].msg;      return(S_ERR);      }      /* Baudrate wieder in's System umrechnen */      p_elem->baud = MacBaud(p_elem->baud);      #endif /* MAC */	if (*p++ == 0x07)		p_elem->databits = DATA_7;	else		p_elem->databits = DATA_8;	if (*p++ == 0x01)		p_elem->stopbits = STOP_1;	else		p_elem->stopbits = STOP_2;	p_elem->edc = (EdcType) * p++;	p_elem->tpdusize = SCTcheck(&p);	/* apdusize = tpdusize - length of TPDU-Header - Length of EDC */	p_elem->apdusize = p_elem->tpdusize - 3 - ((p_elem->edc == E_LRC) ? 1 : 2);	/*------------------------------------*/	/* if baud / databits / stopbits	 */	/* changed, then call COMreset	 */	/*------------------------------------*/	if ((baud != p_elem->baud) || (databits != p_elem->databits) ||	    (stopbits != p_elem->stopbits)) {		if (COMreset(p_elem) == -1) {			COMclose(p_elem->port_id);#ifdef TRACE			fprintf(sct_trfp, "CALL get_orgelem in sct_reset after COMreset with ERROR \n");#endif			if (get_orgelem(sct_id, p_elem) == -1)				return (S_ERR);			return (SCTerr(sw1, tp1_err));		}	}	/*------------------------------------*/	/* set secure messaging       	 */	/*------------------------------------*/	if ((p_elem->setmode == 1) &&	    ((p_elem->secure_messaging.command != SEC_NORMAL) ||	     (p_elem->secure_messaging.response != SEC_NORMAL))) {		if (sct_secure(sct_id) == -1)			return (S_ERR);	}#ifdef MEMTRACE	pr_element(sct_trfp, p_elem);	fprintf(sct_trfp, "END of sct_reset\n");#endif#ifdef PROCDAT	if ((sca_write_SCT_config(sct_id, p_elem)) < 0) {		aux_add_error(ESCPROCDATA, "Cannot write SCT configuration data!", CNULL, 0, proc);		return (S_ERR);	}#endif	/*PROCDAT */	return (S_NOERR);}/*-------------------------------------------------------------*//* E N D   O F	 P R O C E D U R E	sct_reset	       *//*-------------------------------------------------------------*//*--------------------------------------------------------*//*						    | GMD *//*						    +-----*//* PROC  sct_interface	     VERSION   2.0		  *//*				DATE   November 1991	  *//*				  BY   L.Eckstein,GMD	  *//*							  *//* DESCRIPTION						  *//*  Creat the s_apdu.					  *//*  The sct_interface checks the mandatory parameter	  *//*  in the body and the validity of the Instruction-Code. *//*  It constructs the CLASS-Byte and executes the secure  *//*  messaging functions.				  *//*  The memory for the s_apdu is provided by this program.*//*  Send the s_apdu to the SCT. 			  *//*  Receive the response from the SCT.			  *//*  The memory for the response-apdu is provided by this  *//*  program (response.bytes);				  *//*  Execute the secure messaging functions.		  *//*  Check the SW1 / SW2 - Byte. 			  *//*  In case of O.K., sct_interface returns a pointer to   *//*  the response-buffer response.bytes. 		  *//*  The response-buffer contains only the datafield	  *//*  without SW1 / SW2.					  *//*  If SW1/SW2 indicates an error, sct_interface returns  *//*  the value -1 and in sct_errno the error number.	  *//*							  *//*							  *//*  Aenderungen Viebeg Beginn				  *//*							  *//*  Save SCT configuration data in a file.		  *//*  Aenderungen Viebeg Ende				  *//*							  *//*							  *//* IN			     DESCRIPTION		  *//*   int sct_id 	       SCT-Identifier		  *//*							  *//*   command		       instruction code 	  *//*							  *//*   pointer		       request structure	  *//*							  *//*   pointer		       response structure	  *//*							  *//* OUT							  *//*   pointer		       response.bytes		  *//*			       will be allocated by this  *//*			       procedure and must be set  *//*			       free by the calling proc.  *//*			       but only in case of no err.*//*							  *//*							  *//*							  *//* RETURN		     DESCRIPTION		  *//*   0			       o.k.			  *//*   1			       SCT waiting	          *//*   2			       Key in SCT replaced	  *//*   3			       Signature correct, but	  *//*			       key to short		  *//*   4			       PIN-CHECK off from SC	  *//*   5			       PIN-CHECK on  from SC	  *//*  -1			       error			  *//*                             EINVARG			  *//*                             ETOOLONG		          *//*                             EMEMAVAIL		  *//*                             ESIDUNK                    *//*                             EPARMISSED                 *//*                             EINVPAR                    *//*                             EINVINS                    *//*                             sw1/sw2 from SCT response  *//*                             T1 - ERROR                 *//*							  *//* CALLED FUNCTIONS					  *//*  get_idelem						  *//*  SCTcreate						  *//*  SCTresponse						  *//*  SCTstatus						  *//*  sta_aux_bytestr_free				  *//*  COMtrans						  *//*  Aenderungen Viebeg Beginn				       *//*   sca_write_SCT_config()	Encrypt and write configuration *//*				data for the specified SCT.     *//*  Aenderungen Viebeg Ende				       *//*							  *//*--------------------------------------------------------*/intsct_interface(sct_id, command, request, response)	int             sct_id;	/* sct_identifier   */	unsigned int    command;/* instruction code */	Request        *request;/* IN  - Puffer     */	Bytestring     *response;	/* Pointer of OUT - Puffer     */{	/*----------------------------------------------------------*/	/* Definitions					       */	/*----------------------------------------------------------*/	char           *s_apdu;	unsigned int    lapdu;	unsigned int    sw1;	unsigned int    sw2;	int             i;	struct s_portparam *p_elem;	BOOL            flag = FALSE;	/* FLAG, if S_STATUS must be send */#ifdef PROCDAT	char           *proc = "sct_interface";#ifdef SECSCTEST	fprintf(stderr, "SECSC-Function: %s\n", proc);#endif#endif 	/* PROCDAT */	/*----------------------------------------------------------*/	/* Statements					       */	/*----------------------------------------------------------*/	/*------------------------------------*/	/* Initialisation			 */	/*------------------------------------*/	sct_errno = 0;	response->bytes = NULL;#ifdef STREAM	if (!first) {		sct_trfp = fopen("SCTINT.TRC", "wt");		first = TRUE;	};#endif	/*------------------------------------*/	/* test sct_id  in sct_list		 */	/*------------------------------------*/	if ((p_elem = get_idelem(sct_id)) == PORTNULL)		return (-1);	/* ERROR: sct_id not in sct-list */#ifdef MEMTRACE	fprintf(sct_trfp, "Element after get_idelem in sct_interface\n");	pr_element(sct_trfp, p_elem);#endif	/*------------------------------------*/	/* test request argument		 */	/*------------------------------------*/	if (request == REQNULL) {		sct_errno = EINVARG;		sct_errmsg = sct_error[sct_errno].msg;		return (S_ERR);	};	/*------------------------------------*/	/* Create s_apdu			 */	/*------------------------------------*/	if ((s_apdu = SCTcreate(p_elem, command, request, &lapdu, &flag)) == NULL)		return (S_ERR);	if (lapdu > p_elem->apdusize) {	/* test apdusize */		sct_errno = ETOOLONG;		sct_errmsg = sct_error[sct_errno].msg;		free(s_apdu);		return (S_ERR);	};	/*------------------------------------*/	/* allocate response-buffer		 */	/*------------------------------------*/#ifdef MALLOC	response->bytes = malloc(p_elem->apdusize);#endif	if (response->bytes == NULL) {		sct_errno = EMEMAVAIL;		sct_errmsg = sct_error[sct_errno].msg;		free(s_apdu);		return (S_ERR);	};	response->nbytes = 0;	for (i = 0; i < p_elem->apdusize; i++)		*(response->bytes + i) = 0x00;	/*------------------------------------*/	/* call transmission-procedure	 */	/*------------------------------------*/	if (COMtrans(p_elem, s_apdu, lapdu, response->bytes, &response->nbytes) == -1) {		free(s_apdu);		sta_aux_bytestr_free(response);		return (SCTerr(0, tp1_err));	}	/*------------------------------------*/	/* release s_apdu			 */	/*------------------------------------*/	free(s_apdu);	/*------------------------------------*/	/* analyse response                   */	/*------------------------------------*/	if (SCTresponse(p_elem, command, response, &sw1, &sw2) == -1)		return (S_ERR);	/*------------------------------------*/	/* if flag = TRUE, then send S_STATUS */	/*------------------------------------*/	if (flag) {		sta_aux_bytestr_free(response);		i = SCTstatus(command, p_elem, response);		/* close port in case of a local error of SCTdec */		if ((command == S_REQUEST_SC) &&		    ((sct_errno == EDESDEC) ||		     (sct_errno == ESCT_SSC)))			sct_close(sct_id);#ifdef PROCDAT		if ((sca_write_SCT_config(sct_id, p_elem)) < 0) {			aux_add_error(ESCPROCDATA, "Cannot write SCT configuration data!", CNULL, 0, proc);			return (S_ERR);		}#endif	/*PROCDAT */		return (i);	};	/*--------------------------------------------------------------*/	/* if command = S_EJECT_SC, then set p_elem->sc_request = FALSE */	/*--------------------------------------------------------------*/	if (command == S_EJECT_SC)		p_elem->sc_request = FALSE;#ifdef MEMTRACE	pr_element(sct_trfp, p_elem);	fprintf(sct_trfp, "END of sct_interface\n");#endif#ifdef PROCDAT	if ((sca_write_SCT_config(sct_id, p_elem)) < 0) {		aux_add_error(ESCPROCDATA, "Cannot write SCT configuration data!", CNULL, 0, proc);		return (S_ERR);	}#endif	/*PROCDAT */	/*------------------------------------*/	/* no error => set sw2, if > 0        */	/*------------------------------------*/	if (sw2 == S_NOERR)		return (sw2);	if (sw1 == OKSC)		sw2 += 3;	return (sw2);}/*-------------------------------------------------------------*//* E N D   O F	 P R O C E D U R E	sct_interface	       *//*-------------------------------------------------------------*//*--------------------------------------------------------*/

⌨️ 快捷键说明

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