ESYAE-imza Kütüphaneleri

User Tools

Site Tools


en:esya:applet:applet-kodlari:appletin-calismasi

Applet Source

2. Running the Applet

After the preparaton steps explained in Introduction, “main.jsp” is opened. This page is the mainpage for the web interface and does not include any graphical component. This method is used in order to prevent the applet from getting affected by the page refreshes. Other pages are embedded in this page as iframe.

After “main.jsp” is opened and the applet is loaded successfully, an HTML form appears. Applet opens sessions to the card readers and finds the certificates. Then it fills these certificates into the HTML form by using javascript..

Besides, a session variable to be signed at server is embedded into the HTML.

The code for reading the certificates from the cards and filling them into the HTML form is as follows:

scManager = SmartCardManager.getInstance();
scManager.listCertificatesOfTerminals();

loginFormCerts = loginFormCerts.concat("<option value=\"NoCert\">Please Select Certificate</option>");

for(ECertificate cert : scManager.mSignatureCerts) {

	String certName = cert.getSubject().getCommonNameAttribute();
	String certSerialHex = cert.getSerialNumberHex();
	loginFormCerts = loginFormCerts.concat("<option value=\""+certSerialHex+"\">"+certName+"</option>");
}

The certificates are read from the smartcard in the smartcard class.

cardIndex = -1;
int certNo = -1;

for (String terminal : mTerminals) {

	cardIndex++;
	try {
		boolean APDUSupport;

		try {

			APDUSupport = APDUSmartCard.isSupported(terminal);

		} catch (NoClassDefFoundError ex) {
			logger.error("APDU smartcard cannot be created. Probably AkisCIF.jar is missing");
			APDUSupport = false;
		}

		logger.debug("Smartcard index:" + cardIndex);

		if (useAPDU == true && APDUSupport) {
			logger.debug("APDU Smartcard will be created");
			APDUSmartCard asc = new APDUSmartCard();
			CardTerminal ct = TerminalFactory.getDefault().terminals().getTerminal(terminal);
			asc.openSession(ct);
			smartCards.add(asc);
		} else {
			logger.debug("PKCS11 Smartcard will be created");
			Pair<Long, CardType> slotAndCardType = SmartOp.getSlotAndCardType(terminal);
			P11SmartCard p11SmartCard = new P11SmartCard(slotAndCardType.getObject2());
			smartCards.add(p11SmartCard);
			smartCards.get(cardIndex).openSession(slotAndCardType.getObject1());
		}

		// take the certs of a terminal
		List<ECertificate> certsOfATerminal = getCertificates(cardIndex);

		// for each cert, save to hashmap which cert belongs to which terminal
		for (ECertificate certificate : certsOfATerminal) {
			certNo++;
			mSCManager.certTerminalMap.put(certNo, terminal);
		}

		mSignatureCerts.addAll(certsOfATerminal);
	}
	catch (Exception e) {
		logger.error("Error in listing certificates of terminals", e);
	}
}

en/esya/applet/applet-kodlari/appletin-calismasi.txt · Son değiştirilme: 2013/09/12 12:56 Değiştiren: Dindar Öz