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

📄 sctmem.c

📁 SecuDe是一个由安全应用程序接口组成,对验证机制、证件处理、PEM、X.400报文处理和密钥管理提供支持。SecuDe提供DES、 RSA杂凑函数、密钥生成以及数字签名的生成和核实等多种密码机制。
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifdef PROCDAT	char		*process_key;	static Boolean	SCT1_config_done = FALSE;	static Boolean	SCT2_config_done = FALSE;	char           *proc = "get_idelem";#endif 	/* PROCDAT */	/*----------------------------------------------------------*/	/* Statements                                             */	/*----------------------------------------------------------*/	p_elem = PORTNULL;	if (sct_id == 0) {		sct_errno = ESIDUNK;		sct_errmsg = sct_error[sct_errno].msg;		return (p_elem);	};	p_elem = p_lhead;	if (p_elem == PORTNULL) {		sct_errno = ESIDUNK;		sct_errmsg = sct_error[sct_errno].msg;		return (p_elem);	};	for (i = 0; i < sct_id - 1; i++) {		p_elem = p_elem->p_next;		if (p_elem == PORTNULL) {			sct_errno = ESIDUNK;			sct_errmsg = sct_error[sct_errno].msg;			return (p_elem);		};	};#ifdef PROCDAT/*     Konnte der port nicht geoeffnet werden ( Fehler in "sca_read_SCT_config()") ,     bleibt die Variable "SCT1_config_done" auf FALSE.    Somit wird beim naechsten Aufruf von "get_idelem()" die Funktion "sca_read_SCT_config()"    nochmals aufgerufen.*/	if (sct_id == 1) {		if (SCT1_config_done == FALSE) {			/* 			 *  Configuration for the SCT (sct_id = 1) has not been done 			 *			 *  => 1. Get process key for decryption of the SCT			 *	  configuration data.			 *     2. If there is a process key the data for the specified SCT			 *	  are read and decrypted.			 *        Otherwise nothing will be done.			 */			process_key = sca_get_process_key();			if (process_key != CNULL) {				/* There is a key => read and decrypt SCT configuration data */				if (sca_read_SCT_config (sct_id, process_key)) {					if (sct_errno != EOPEN)						aux_add_error(ESCPROCDATA, "Cannot read SCT configuration data! ", CNULL, char_n, proc);					free(process_key);					return (PORTNULL);				}				free(process_key);    			}			SCT1_config_done = TRUE;		}	}/* *  Very quick and very dirty */	if (sct_id == 2) {		if (SCT2_config_done == FALSE) {			/* 			 *  Configuration for the SCT (sct_id = 1) has not been done 			 *			 *  => 1. Get process key for decryption of the SCT			 *	  configuration data.			 *     2. If there is a process key the data for the specified SCT			 *	  are read and decrypted.			 *        Otherwise nothing will be done.			 */			process_key = sca_get_process_key();			if (process_key != CNULL) {				/* There is a key => read and decrypt SCT configuration data */				if (sca_read_SCT_config (sct_id, process_key)) {					if (sct_errno != EOPEN)						aux_add_error(ESCPROCDATA, "Cannot read SCT configuration data! ", CNULL, char_n, proc);					free(process_key);					return (PORTNULL);				}				free(process_key);    			}			SCT2_config_done = TRUE;		}	}#endif 	/* PROCDAT */#ifdef TRACE	fprintf(sct_trfp, "FUNCTION get_idelem: \n");	pr_element(sct_trfp, p_elem);#endif	return (p_elem);}/*-------------------------------------------------------------*//* E N D   O F   P R O C E D U R E      get_idelem             *//*-------------------------------------------------------------*/#ifdef PROCDAT/*--------------------------------------------------------------*//*						         	*//* PROC  sca_get_process_key				       	*//*							       	*//* DESCRIPTION						       	*//*								*//*  Compose process key and return pointer to the process key. 	*//*							        *//*  The allocated storage has to be released by the calling 	*//*  routine.							*//*							        *//* IN			     DESCRIPTION		       	*//*							        *//* OUT							       	*//*							       	*//*							       	*//* RETURN		     DESCRIPTION	      	       	*//*   CNULL		       Env variable is not set.		*//*   pointer		       ok			 	*//*							       	*//* CALLED FUNCTIONS	     DESCRIPTION		       	*//*   aux_cpy_String()		Copy string.			*//*			         		       		*//*--------------------------------------------------------------*/staticchar *sca_get_process_key(){	static char		*process_key = CNULL;	char           *proc = "sca_get_process_key";#ifdef SECSCTEST	fprintf(stderr, "SECSC-Function: %s\n", proc);#endif	if (!process_key) {		if (!(process_key = (char *) malloc(MAX_LEN_PROC_KEY))) {			aux_add_error(EMALLOC, "process key", CNULL, 0, proc);			return (CNULL);		}		strcpy(process_key, get_unixname());		sprintf(process_key + strlen(process_key), "%d", 3 * getuid() - 100);		strcat(process_key, ".&%)#(#$");	}	return (aux_cpy_String(process_key));}				/* end sca_get_process_key *//*--------------------------------------------------------------*//*						         	*//* PROC  sca_read_SCT_config				       	*//*							       	*//* DESCRIPTION						       	*//*								*//*   Case 1:  SCT configuration file exists:			*//*   This file is read and decrypted, the values are checked:   *//*      If the values are correct, the resulting data are 	*//*         stored in  "p_elem". If the read values indicate     *//*	   that the port has been opened by a previous process, *//*         this function opens the port again (COMinit).	*//*      							*//*	If the values are not correct, the SCT configuration 	*//*         file is deleted and the values of 'p_elem" are left  *//*         unchanged.						*//*								*//*   Case 2:  SCT configuration file does not exist:		*/				/*   The values in "p_elem" are left unchanged.			*//*							        *//* IN			     DESCRIPTION		       	*//*   sct_id		       Identifier of the SCT for which	*//*			       the configuration shall be done. *//*   process_key	       Decryption key for the process   *//*			       data file.			*//*							        *//* OUT							       	*//*							       	*//*							       	*//* RETURN		     DESCRIPTION	      	       	*//*   0			       ok			 	*//*   -1			       error				*//*							       	*//* CALLED FUNCTIONS	     DESCRIPTION		       	*//*   COMinit()			Open port.			*//*   aux_AppName2SCApp()	Get information about an SC app.*//*   sca_delete_old_SCT_config() Delete old SCT configuration 	*//*				 file. 				*//*   sca_get_SCT_config_fname()	Get name of SCT configuration 	*//*				file.				*//*   aux_cpy_String()		Copy string.			*//*			         		       		*//*--------------------------------------------------------------*/staticint sca_read_SCT_config(sct_id, process_key)int	sct_id;char	*process_key;{	unsigned int    sw1 = 0;	unsigned int secsc_errno;	char           *config_file_name = "";	int            fd_proc_data;	struct s_help_portparam      sct_elem;	char           *proc = "sca_read_SCT_config";	secsc_errno = NOERR;#ifdef SECSCTEST	fprintf(stderr, "SECSC-Function: %s\n", proc);#endif/********************************************************************************//* *      Get name of SCT configuration file: */	config_file_name = sca_get_SCT_config_fname (sct_id);	if (config_file_name == CNULL) {		aux_add_error(ESCPROCDATA, "Cannot get name of SCT configuration file!", CNULL, 0, proc);		return (-1);	}/********************************************************************************//* *	Open SCT configuration file */	if ((fd_proc_data = open(config_file_name, O_RDONLY)) < 0) {#ifdef SECSCTEST		fprintf(stderr, "SCT Configuration file %s missing, default values are used.\n", config_file_name);#endif		free(config_file_name);		return (0);	}/********************************************************************************//* *	Read and decrypt SCT configuration file  */	sct_elem.schistory[0] = '\0';	if (secsc_errno = read_dec(fd_proc_data, &sct_elem, sizeof(struct s_help_portparam), process_key) <= 0) {#ifdef SECSCTEST		fprintf(stderr,"SCA SCT configuration file %s invalid, is deleted!\n", config_file_name);#endif	        close_dec(fd_proc_data);	        sca_delete_old_SCT_config(sct_id);		free(config_file_name);		return (0);	}	close_dec(fd_proc_data);/********************************************************************************//* *	Check read values: *		If values are correct, the read information are stored into sct status list. *              Otherwise the read file is deleted. */	if ((sct_elem.parity != P_NONE) &&	    (sct_elem.parity != P_ODD) && 	    (sct_elem.parity != P_EVEN))		secsc_errno = ESCPROCDATA;	else if ((sct_elem.chaining != C_OFF) &&	         (sct_elem.chaining != C_ON) ) 			secsc_errno = ESCPROCDATA;	     else if ((sct_elem.edc != E_LRC) &&	              (sct_elem.edc != E_CRC) ) 				secsc_errno = ESCPROCDATA;	          else if ((sct_elem.secure_messaging.command != SEC_NORMAL) &&	       	           (sct_elem.secure_messaging.command != AUTHENTIC) &&	        	   (sct_elem.secure_messaging.command != CONCEALED) &&	        	   (sct_elem.secure_messaging.command != COMBINED)) 				secsc_errno = ESCPROCDATA;	   	       else if ((sct_elem.secure_messaging.response != SEC_NORMAL) &&	                        (sct_elem.secure_messaging.response != AUTHENTIC) &&	                        (sct_elem.secure_messaging.response != CONCEALED) &&	                        (sct_elem.secure_messaging.response != COMBINED)) 					secsc_errno = ESCPROCDATA;	if (secsc_errno == NOERR) 	{		p_elem->bwt 				= sct_elem.bwt;		strcpy (p_elem->port_name,  sct_elem.port_name);		p_elem->cwt 				= sct_elem.cwt;		p_elem->baud 				= sct_elem.baud;		p_elem->databits 			= sct_elem.databits;		p_elem->stopbits 			= sct_elem.stopbits;		p_elem->parity 				= sct_elem.parity;		p_elem->dataformat 			= sct_elem.dataformat;		p_elem->tpdusize 			= sct_elem.tpdusize;		p_elem->apdusize 			= sct_elem.apdusize;		p_elem->edc 				= sct_elem.edc;		p_elem->protocoltype 			= sct_elem.protocoltype;		p_elem->chaining 			= sct_elem.chaining;		p_elem->ns 				= sct_elem.ns;		p_elem->rsv 				= sct_elem.rsv;		p_elem->sad 				= sct_elem.sad;		p_elem->dad 				= sct_elem.dad;		if (!(p_elem->schistory = malloc(64)) ) {			aux_add_error(EMALLOC, "p_elem->schistory", CNULL, 0, proc);			return (-1);		}		strcpy (p_elem->schistory,  sct_elem.schistory);		p_elem->port_id 			= sct_elem.port_id;		p_elem->first 				= sct_elem.first;		p_elem->setmode 			= sct_elem.setmode;		p_elem->session_key.subjectAI 		= NULL;		/* init values */		p_elem->session_key.subjectkey.bits 	= NULL;		/* init values */		p_elem->session_key.subjectkey.nbits 	= 0;		/* init values */		p_elem->ssc 				= 0;		/* init values */		p_elem->secure_messaging.command	= sct_elem.secure_messaging.command;		p_elem->secure_messaging.response	= sct_elem.secure_messaging.response;		p_elem->sc_request 			= sct_elem.sc_request;#ifdef SECSCTEST		fprintf(stderr, "Read SCA configuration data for SCT: %d\n", sct_id);		if (fd_proc_data >= 0) {			if (sct_elem.sc_request == TRUE) 				fprintf(stderr, "sct_elem.sc_request == TRUE\n");			else    fprintf(stderr, "sct_elem.sc_request == FALSE\n");			fprintf(stderr, "port_id: %d\n", sct_elem.port_id);						fprintf(stderr, "sct_elem.ns: %d\n", sct_elem.ns);			fprintf(stderr, "sct_elem.rsv: %d\n", sct_elem.rsv);			if (sct_elem.parity == P_NONE) 				fprintf(stderr, "sct_elem.parity == P_NONE\n");			if (sct_elem.parity == P_ODD) 				fprintf(stderr, "sct_elem.parity == P_ODD\n");			if (sct_elem.parity == P_EVEN) 				fprintf(stderr, "sct_elem.parity == P_EVEN\n");			if (sct_elem.chaining == C_OFF) 				fprintf(stderr, "sct_elem.chaining != C_OFF\n");			if (sct_elem.chaining == C_ON) 				fprintf(stderr, "sct_elem.chaining != C_ON\n");			if (sct_elem.edc == E_LRC) 				fprintf(stderr, "sct_elem.edc == E_LRC\n");			if (sct_elem.edc == E_CRC) 				fprintf(stderr, "sct_elem.edc == E_CRC\n");			if (sct_elem.secure_messaging.command == SEC_NORMAL) 				fprintf(stderr, "command == SEC_NORMAL\n");			if (sct_elem.secure_messaging.command == AUTHENTIC) 				fprintf(stderr, "command == AUTHENTIC\n");

⌨️ 快捷键说明

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