Check-in [26acceb6f2]
Overview
Comment:Updated PC/SC identity member of cackey identity name to be more descriptive

Added more sanity checks

Updated to populate pcsc_identity structure of cackey identity from certificate information

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:26acceb6f2061800f15ba4ef9201cb04afd8ce48
User & Date: rkeene on 2010-05-17 07:19:02
Other Links: manifest | tags
Context
2010-05-17
14:44
Updated version-script detection macro check-in: 3dee1a5953 user: rkeene tags: trunk
07:19
Updated PC/SC identity member of cackey identity name to be more descriptive

Added more sanity checks

Updated to populate pcsc_identity structure of cackey identity from certificate information check-in: 26acceb6f2 user: rkeene tags: trunk

06:00
Added missing file from last commit check-in: 70222fd9bf user: rkeene tags: trunk
Changes

Modified cackey.c from [ddbf6476ef] to [9bef8e6303].

   464    464   	unsigned char *label;
   465    465   
   466    466   	size_t certificate_len;
   467    467   	unsigned char *certificate;
   468    468   };
   469    469   
   470    470   struct cackey_identity {
   471         -	struct cackey_pcsc_identity *identity;
          471  +	struct cackey_pcsc_identity *pcsc_identity;
   472    472   
   473    473   	CK_ATTRIBUTE *attributes;
   474    474   	CK_ULONG attributes_count;
   475    475   };
   476    476   
   477    477   struct cackey_session {
   478    478   	int active;
................................................................................
  1863   1863   	}
  1864   1864   
  1865   1865   	if (outbuf == NULL) {
  1866   1866   		CACKEY_DEBUG_PRINTF("Error.  outbuf is NULL");
  1867   1867   
  1868   1868   		return(-1);
  1869   1869   	}
         1870  +
         1871  +	if (identity == NULL) {
         1872  +		CACKEY_DEBUG_PRINTF("Error.  identity is NULL");
         1873  +
         1874  +		return(-1);
         1875  +	}
         1876  +
         1877  +	if (identity->pcsc_identity == NULL) {
         1878  +		CACKEY_DEBUG_PRINTF("Error.  identity->pcsc_identity is NULL");
         1879  +
         1880  +		return(-1);
         1881  +	}
  1870   1882   
  1871   1883   	/* Begin transaction */
  1872   1884   	cackey_begin_transaction(slot);
  1873   1885   
  1874   1886   	/* Select correct applet */
  1875         -	CACKEY_DEBUG_PRINTF("Selecting applet found at %p ...", identity->identity->applet);
  1876         -	cackey_select_applet(slot, identity->identity->applet, sizeof(identity->identity->applet));
         1887  +	CACKEY_DEBUG_PRINTF("Selecting applet found at %p ...", identity->pcsc_identity->applet);
         1888  +	cackey_select_applet(slot, identity->pcsc_identity->applet, sizeof(identity->pcsc_identity->applet));
  1877   1889   
  1878   1890   	/* Select correct file */
  1879         -	cackey_select_file(slot, identity->identity->file);
         1891  +	cackey_select_file(slot, identity->pcsc_identity->file);
  1880   1892   
  1881   1893   	send_ret = cackey_send_apdu(slot, GSCIS_CLASS_GLOBAL_PLATFORM, GSCIS_INSTR_SIGNDECRYPT, 0x00, 0x00, buflen, buf, le, NULL, outbuf, &outbuflen);
  1882   1894   	if (send_ret != CACKEY_PCSC_S_OK) {
  1883   1895   		CACKEY_DEBUG_PRINTF("ADPU Sending Failed -- returning in error.");
  1884   1896   
  1885   1897   		/* End transaction */
  1886   1898   		cackey_end_transaction(slot);
................................................................................
  2514   2526   				curr_attr = &identities[id_idx].attributes[attr_idx];
  2515   2527   
  2516   2528   				if (curr_attr->pValue) {
  2517   2529   					free(curr_attr->pValue);
  2518   2530   				}
  2519   2531   			}
  2520   2532   
  2521         -			free(identities[id_idx].attributes);
         2533  +			if (identities[id_idx].attributes) {
         2534  +				free(identities[id_idx].attributes);
         2535  +			}
         2536  +
         2537  +			cackey_free_certs(identities[id_idx].pcsc_identity, 1, 1);
  2522   2538   		}
  2523   2539   	}
  2524   2540   
  2525   2541   	free(identities);
  2526   2542   }
  2527   2543   
  2528   2544   static struct cackey_identity *cackey_read_identities(struct cackey_slot *slot, unsigned long *ids_found) {
................................................................................
  2551   2567   			for (curr_id_type = CKO_CERTIFICATE; curr_id_type <= CKO_PRIVATE_KEY; curr_id_type++) {
  2552   2568   				identities[id_idx].attributes = cackey_get_attributes(curr_id_type, &pcsc_identities[cert_idx], cert_idx, &identities[id_idx].attributes_count);
  2553   2569   
  2554   2570   				if (identities[id_idx].attributes == NULL) {
  2555   2571   					identities[id_idx].attributes_count = 0;
  2556   2572   				}
  2557   2573   
         2574  +				identities[id_idx].pcsc_identity = malloc(sizeof(*identities[id_idx].pcsc_identity));
         2575  +				memcpy(identities[id_idx].pcsc_identity, &pcsc_identities[cert_idx], sizeof(*identities[id_idx].pcsc_identity));
         2576  +
         2577  +				identities[id_idx].pcsc_identity->certificate = malloc(pcsc_identities[cert_idx].certificate_len);
         2578  +				memcpy(identities[id_idx].pcsc_identity->certificate, pcsc_identities[cert_idx].certificate, pcsc_identities[cert_idx].certificate_len);
         2579  +
  2558   2580   				id_idx++;
  2559   2581   			}
  2560   2582   		}
  2561   2583   
  2562   2584   		cackey_free_certs(pcsc_identities, num_certs, 1);
  2563   2585   
  2564   2586   		*ids_found = num_ids;
................................................................................
  4602   4624   
  4603   4625   	cackey_sessions[hSession].sign_mechanism = pMechanism->mechanism;
  4604   4626   
  4605   4627   	cackey_sessions[hSession].sign_buflen = 128;
  4606   4628   	cackey_sessions[hSession].sign_bufused = 0;
  4607   4629   	cackey_sessions[hSession].sign_buf = malloc(sizeof(*cackey_sessions[hSession].sign_buf) * cackey_sessions[hSession].sign_buflen);
  4608   4630   
  4609         -	CACKEY_DEBUG_PRINTF("Session %lu sign_identity is %p (identitie #%lu)", (unsigned long) hSession, &cackey_sessions[hSession].identities[hKey], (unsigned long) hKey);
         4631  +	CACKEY_DEBUG_PRINTF("Session %lu sign_identity is %p (identity #%lu)", (unsigned long) hSession, &cackey_sessions[hSession].identities[hKey], (unsigned long) hKey);
  4610   4632   	cackey_sessions[hSession].sign_identity = &cackey_sessions[hSession].identities[hKey];
  4611   4633   
  4612   4634   	mutex_retval = cackey_mutex_unlock(cackey_biglock);
  4613   4635   	if (mutex_retval != 0) {
  4614   4636   		CACKEY_DEBUG_PRINTF("Error.  Unlocking failed.");
  4615   4637   
  4616   4638   		return(CKR_GENERAL_ERROR);