Example #1
0
bool
init_agents()
/*
 * Here we create all of the individual agents
 */
{
	bool	ok;				 /* Status of last operation  */

	agents_sc = sc_init();			 /* Create sync controller    */

	if(!agents_sc)				 /* Failed ?		      */
		return FALSE;

	sc_begin(agents_sc);			 /* Start synchronisation     */

#ifdef DEBUG
	ok = try_each_obj(qsheets, (t_try_obj)db_new_agent,
			GINT_TO_POINTER(atype_cue))
		&& new_agent(NULL, GINT_TO_POINTER(atype_dek), "Decks")
		&& new_agent(NULL, GINT_TO_POINTER(atype_mxr), "Mixers");
#else
	ok = try_each_obj(qsheets, (t_try_obj)new_agent,
			GINT_TO_POINTER(atype_cue))
		&& new_agent(NULL, GINT_TO_POINTER(atype_dek))
		&& new_agent(NULL, GINT_TO_POINTER(atype_mxr));
#endif

	new_am_pool();				 /* Create pool of msg args   */

	sc_ready(agents_sc);			 /* Signal we are ready	      */

	if(ok)					 /* Everything OK?	      */
		sc_wait(agents_sc);		 /* Wait for agents to start  */
	else
	{
		E("Startup failed, killing agents...");
		sc_wait(agents_sc);		 /* Wait for agents to start  */
		term_agents();			 /* Terminate all agents      */
	}

	sc_reset(agents_sc);			 /* Kill sync controller      */

	return ok;
}						 /* init_agents()	      */
Example #2
0
static int mcrd_init(sc_card_t * card)
{
	unsigned long flags;
	struct mcrd_priv_data *priv;
	int r;
	sc_path_t tmppath;
	sc_apdu_t apdu;

	priv = calloc(1, sizeof *priv);
	if (!priv)
		return SC_ERROR_OUT_OF_MEMORY;
	card->drv_data = priv;
	card->cla = 0x00;
	card->caps = SC_CARD_CAP_RNG;


	if (is_esteid_card(card)) {
		/* Reset the MULTOS card to get to a known state */
		if (card->type == SC_CARD_TYPE_MCRD_ESTEID_V11)
			sc_reset(card, 0);

		/* Select the EstEID AID to get to a known state.
		 * For some reason a reset is required as well... */
		if (card->type == SC_CARD_TYPE_MCRD_ESTEID_V30) {
			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_SHA1 | SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_SHA256;
			/* EstEID v3.0 has 2048 bit keys */
			_sc_card_add_rsa_alg(card, 2048, flags, 0);
			sc_reset(card, 0);

			sc_format_apdu(card, &apdu, SC_APDU_CASE_3, 0xA4, 0x04, 0x00);
			apdu.lc = sizeof(EstEID_v3_AID);
			apdu.data = EstEID_v3_AID;
			apdu.datalen = sizeof(EstEID_v3_AID);
			apdu.resplen = 0;
			apdu.le = 0;
			r = sc_transmit_apdu(card, &apdu);
			SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "SELECT AID: %02X%02X", apdu.sw1, apdu.sw2);
			if(apdu.sw1 != 0x90 && apdu.sw2 != 0x00)
			{
				sc_format_apdu(card, &apdu, SC_APDU_CASE_3, 0xA4, 0x04, 0x00);
	                        apdu.lc = sizeof(EstEID_v35_AID);
        	                apdu.data = EstEID_v35_AID;
                	        apdu.datalen = sizeof(EstEID_v35_AID);
                        	apdu.resplen = 0;
	                        apdu.le = 0;
				r = sc_transmit_apdu(card, &apdu);
	                        SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
        	                sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "SELECT AID: %02X%02X", apdu.sw1, apdu.sw2);
				if (apdu.sw1 != 0x90 && apdu.sw2 != 0x00) {
					sc_format_apdu(card, &apdu, SC_APDU_CASE_3, 0xA4, 0x04, 0x00);
					apdu.lc = sizeof(AzeDIT_v35_AID);
					apdu.data = AzeDIT_v35_AID;
					apdu.datalen = sizeof(AzeDIT_v35_AID);
					apdu.resplen = 0;
					apdu.le = 0;
					r = sc_transmit_apdu(card, &apdu);
					SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
					sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "SELECT AID: %02X%02X", apdu.sw1, apdu.sw2);
					if (apdu.sw1 != 0x90 && apdu.sw2 != 0x00)
						SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,  SC_ERROR_CARD_CMD_FAILED);
				}
			}
		} else {
			/* EstEID v1.0 and 1.1 have 1024 bit keys */
			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_SHA1;
			_sc_card_add_rsa_alg(card, 1024, flags, 0);
		}
	} else {
		flags = SC_ALGORITHM_RSA_RAW |SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
		_sc_card_add_rsa_alg(card, 512, flags, 0);
		_sc_card_add_rsa_alg(card, 768, flags, 0);
		_sc_card_add_rsa_alg(card, 1024, flags, 0);
	}

	priv->curpath[0] = MFID;
	priv->curpathlen = 1;

	sc_format_path ("3f00", &tmppath);
	r = sc_select_file (card, &tmppath, NULL);

	/* Not needed for the fixed EstEID profile */
	if (!is_esteid_card(card))
		load_special_files(card);

	return r;
}